speclock 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -35,9 +35,11 @@ SpecLock maintains a `.speclock/` directory inside your repo that gives every AI
35
35
  └── latest.md # Always-fresh context pack for any AI agent
36
36
  ```
37
37
 
38
- Any AI tool calls `speclock_session_briefing` → gets **full project context** works with complete memory → calls `speclock_session_summary` → next session continues seamlessly.
38
+ **SpecLock = MCP Server + Project Instructions.**
39
39
 
40
- **No context is ever lost again.**
40
+ The MCP server gives the AI tools for memory and constraint checking. The project instructions force the AI to use them on every action — automatically. Together, they create an active guardrail that prevents AI coding tools from breaking your work.
41
+
42
+ **No context is ever lost. No constraints ever violated.**
41
43
 
42
44
  ## Why SpecLock Wins
43
45
 
@@ -56,31 +58,15 @@ Any AI tool calls `speclock_session_briefing` → gets **full project context**
56
58
 
57
59
  ## Quick Start
58
60
 
59
- ### 1. Install
60
-
61
- ```bash
62
- npm install -g speclock
63
- ```
64
-
65
- Or use directly with npx:
61
+ ### 1. Connect SpecLock to Your AI Tool
66
62
 
67
- ```bash
68
- npx speclock init
69
- ```
63
+ **Lovable** (no install needed):
70
64
 
71
- ### 2. Initialize in Your Project
65
+ 1. Go to **Settings → Connectors → Personal connectors → New MCP server**
66
+ 2. Enter URL: `https://speclock-mcp-production.up.railway.app/mcp` — No auth
67
+ 3. Enable it in your project's prompt box
72
68
 
73
- ```bash
74
- cd your-project
75
- speclock init
76
- speclock goal "Ship v1 of the product"
77
- speclock lock "No breaking changes to public API"
78
- speclock decide "Use PostgreSQL for persistence"
79
- ```
80
-
81
- ### 3. Connect to Your AI Tool
82
-
83
- **Claude Code** — Add to `.claude/settings.json`:
69
+ **Claude Code** — Add to `.claude/settings.json` or `.mcp.json`:
84
70
 
85
71
  ```json
86
72
  {
@@ -106,27 +92,81 @@ speclock decide "Use PostgreSQL for persistence"
106
92
  }
107
93
  ```
108
94
 
109
- **Windsurf / Cline / Any MCP tool** — Same pattern:
95
+ **Windsurf / Cline / Any MCP tool** — Same pattern as above.
96
+
97
+ ### 2. Add Project Instructions (Required)
98
+
99
+ > **This is the critical step.** Without project instructions, the AI has the tools but won't use them automatically. With them, SpecLock becomes an active guardrail.
100
+
101
+ Copy-paste the rules below into your platform's project instruction settings:
102
+
103
+ | Platform | Where to paste |
104
+ |----------|----------------|
105
+ | **Lovable** | Project Settings → Knowledge |
106
+ | **Cursor** | `.cursorrules` file in project root |
107
+ | **Claude Code** | `CLAUDE.md` file in project root |
108
+ | **Windsurf** | `.windsurfrules` file in project root |
109
+
110
+ **The rules to paste:**
110
111
 
111
- ```json
112
- {
113
- "mcpServers": {
114
- "speclock": {
115
- "command": "npx",
116
- "args": ["-y", "speclock", "serve", "--project", "."]
117
- }
118
- }
119
- }
120
112
  ```
113
+ ## SpecLock Rules (MANDATORY — follow on every message)
121
114
 
122
- ### 4. Use It
115
+ 1. START OF EVERY CONVERSATION: Call speclock_session_briefing FIRST. Read all locks, decisions, and goals before doing anything else. Show a brief summary: "🔒 Memory loaded — X locks, Y decisions."
123
116
 
124
- The AI tool now has access to **19 SpecLock tools**. The key workflow:
117
+ 2. BEFORE WRITING OR MODIFYING ANY CODE: Call speclock_check_conflict with a description of what you're about to change. If a conflict is found with HIGH confidence, STOP and tell me which lock would be violated. Do NOT proceed unless I explicitly say to override it.
125
118
 
126
- 1. **Start session**: AI calls `speclock_session_briefing` gets full context + what changed
127
- 2. **During work**: AI uses `add_decision`, `log_change`, `check_conflict`, `detect_drift`
128
- 3. **End session**: AI calls `speclock_session_summary` records what was accomplished
129
- 4. **Next session (any tool)**: Step 1 repeats — full continuity preserved
119
+ 3. WHEN I SAY "lock this", "never touch this", "don't ever change this", "this is critical", or similar: Immediately call speclock_add_lock with my exact constraint. Confirm with: "🔒 Locked: [constraint]"
120
+
121
+ 4. AFTER COMPLETING ANY FEATURE OR SIGNIFICANT CHANGE: Call speclock_log_change with a summary of what was built/changed and which files were affected. Also call speclock_add_decision if an architectural choice was made.
122
+
123
+ 5. WHEN I ASK TO REMOVE OR CHANGE SOMETHING THAT WAS LOCKED: Warn me first: "⚠️ You locked this: [constraint]. Want me to unlock it and proceed?" Only proceed if I confirm.
124
+
125
+ 6. END OF CONVERSATION: Call speclock_session_summary with what was accomplished.
126
+ ```
127
+
128
+ See [SPECLOCK-INSTRUCTIONS.md](SPECLOCK-INSTRUCTIONS.md) for platform-specific versions and detailed examples.
129
+
130
+ ### 3. Start Building
131
+
132
+ That's it. Now when you chat with your AI tool:
133
+
134
+ 1. **Every session starts**: AI auto-loads your project memory — goals, constraints, decisions, history
135
+ 2. **During work**: AI auto-captures decisions, logs changes, checks constraints before modifying code
136
+ 3. **Constraint protection**: If the AI tries to break something you locked, it stops and warns you
137
+ 4. **Every session ends**: AI records what was accomplished
138
+ 5. **Next session**: Full continuity — the AI remembers everything from all previous sessions
139
+
140
+ ## How It Works In Practice
141
+
142
+ ### You lock something important:
143
+ ```
144
+ You: "Don't ever touch the auth files"
145
+ AI: 🔒 Locked: "Never modify auth files"
146
+ ```
147
+
148
+ ### AI checks before every change:
149
+ ```
150
+ You: "Add social login to the login page"
151
+ AI: ⚠️ This conflicts with your lock: "Never modify auth files"
152
+ Should I proceed anyway, or find another approach?
153
+ ```
154
+
155
+ ### New session, full memory:
156
+ ```
157
+ You: "Let's keep working on the dashboard"
158
+ AI: 🔒 Memory loaded — 5 locks, 3 decisions, 2 sessions tracked.
159
+ Last session you added the payment page and locked the auth files.
160
+ Ready to work on the dashboard.
161
+ ```
162
+
163
+ ### You change your mind:
164
+ ```
165
+ You: "Actually, unlock the auth files, I need to change them"
166
+ AI: You locked: "Never modify auth files". Want me to unlock this?
167
+ You: "Yes"
168
+ AI: 🔓 Unlocked. Proceeding with auth file changes.
169
+ ```
130
170
 
131
171
  ## MCP Tools (19)
132
172
 
@@ -0,0 +1,146 @@
1
+ # SpecLock Project Instructions — Copy-Paste Templates
2
+
3
+ These are **project-level instructions** that you paste into your AI coding platform's settings. They force the AI to use SpecLock on every action — turning it from a passive notepad into an active guardrail.
4
+
5
+ ---
6
+
7
+ ## For Lovable
8
+
9
+ Go to **Project Settings → Knowledge** and paste this:
10
+
11
+ ```
12
+ ## SpecLock Rules (MANDATORY — follow on every message)
13
+
14
+ 1. START OF EVERY CONVERSATION: Call speclock_session_briefing FIRST. Read all locks, decisions, and goals before doing anything else. Show a brief summary: "🔒 Memory loaded — X locks, Y decisions."
15
+
16
+ 2. BEFORE WRITING OR MODIFYING ANY CODE: Call speclock_check_conflict with a description of what you're about to change (e.g., "Adding payment page, creating new route and components" or "Modifying the auth login flow"). If a conflict is found with HIGH confidence, STOP and tell me which lock would be violated. Do NOT proceed unless I explicitly say to override it.
17
+
18
+ 3. WHEN I SAY "lock this", "never touch this", "don't ever change this", "this is critical", or similar: Immediately call speclock_add_lock with my exact constraint. Confirm with: "🔒 Locked: [constraint]"
19
+
20
+ 4. AFTER COMPLETING ANY FEATURE OR SIGNIFICANT CHANGE: Call speclock_log_change with a summary of what was built/changed and which files were affected. Also call speclock_add_decision if an architectural choice was made.
21
+
22
+ 5. WHEN I ASK TO REMOVE OR CHANGE SOMETHING THAT WAS LOCKED: Warn me first: "⚠️ You locked this: [constraint]. Want me to unlock it and proceed?" Only proceed if I confirm.
23
+
24
+ 6. END OF CONVERSATION: Call speclock_session_summary with what was accomplished.
25
+ ```
26
+
27
+ ---
28
+
29
+ ## For Cursor
30
+
31
+ Create or add to `.cursorrules` in your project root:
32
+
33
+ ```
34
+ ## SpecLock Rules (MANDATORY — follow on every message)
35
+
36
+ 1. START OF EVERY CONVERSATION: Call speclock_session_briefing FIRST. Read all locks, decisions, and goals before doing anything else. Show a brief summary: "🔒 Memory loaded — X locks, Y decisions."
37
+
38
+ 2. BEFORE WRITING OR MODIFYING ANY CODE: Call speclock_check_conflict with a description of what you're about to change. If a conflict is found with HIGH confidence, STOP and tell me which lock would be violated. Do NOT proceed unless I explicitly say to override.
39
+
40
+ 3. WHEN I SAY "lock this", "never touch this", "don't change this": Call speclock_add_lock immediately. Confirm: "🔒 Locked: [constraint]"
41
+
42
+ 4. AFTER COMPLETING ANY FEATURE: Call speclock_log_change with a summary and files affected. Call speclock_add_decision if an architectural choice was made.
43
+
44
+ 5. WHEN I ASK TO CHANGE SOMETHING LOCKED: Warn me: "⚠️ This is locked: [constraint]. Unlock and proceed?" Only continue if I confirm.
45
+
46
+ 6. END OF SESSION: Call speclock_session_summary.
47
+ ```
48
+
49
+ ---
50
+
51
+ ## For Claude Code
52
+
53
+ Add to `CLAUDE.md` in your project root:
54
+
55
+ ```
56
+ ## SpecLock Rules (MANDATORY — follow on every message)
57
+
58
+ 1. START OF EVERY CONVERSATION: Call speclock_session_briefing FIRST. Read all locks, decisions, and goals before doing anything else. Show: "🔒 Memory loaded — X locks, Y decisions."
59
+
60
+ 2. BEFORE WRITING OR MODIFYING ANY CODE: Call speclock_check_conflict with what you're about to change. If conflict found (HIGH), STOP and warn me. Do NOT proceed unless I override.
61
+
62
+ 3. WHEN I SAY "lock this", "never touch", "don't change": Call speclock_add_lock. Confirm: "🔒 Locked: [constraint]"
63
+
64
+ 4. AFTER COMPLETING FEATURES: Call speclock_log_change + speclock_add_decision for architectural choices.
65
+
66
+ 5. LOCKED ITEMS: Warn before changing. Only proceed if I confirm unlock.
67
+
68
+ 6. END OF SESSION: Call speclock_session_summary.
69
+ ```
70
+
71
+ ---
72
+
73
+ ## For Windsurf
74
+
75
+ Add to `.windsurfrules` in your project root:
76
+
77
+ ```
78
+ ## SpecLock Rules (MANDATORY — follow on every message)
79
+
80
+ 1. START OF EVERY CONVERSATION: Call speclock_session_briefing FIRST. Show: "🔒 Memory loaded — X locks, Y decisions."
81
+
82
+ 2. BEFORE MODIFYING CODE: Call speclock_check_conflict. If HIGH conflict, STOP and warn me.
83
+
84
+ 3. WHEN I SAY "lock this" / "never touch" / "don't change": Call speclock_add_lock. Confirm: "🔒 Locked: [constraint]"
85
+
86
+ 4. AFTER FEATURES: Call speclock_log_change + speclock_add_decision.
87
+
88
+ 5. LOCKED ITEMS: Warn before changing. Only unlock if I confirm.
89
+
90
+ 6. END: Call speclock_session_summary.
91
+ ```
92
+
93
+ ---
94
+
95
+ ## How It Works In Practice
96
+
97
+ ### Example 1: User locks something
98
+ ```
99
+ User: "Don't ever touch the auth files"
100
+ AI: 🔒 Locked: "Never modify auth files"
101
+ ```
102
+
103
+ ### Example 2: AI checks before changing
104
+ ```
105
+ User: "Add social login to the login page"
106
+ AI: *calls speclock_check_conflict("Modifying auth login page to add social login")*
107
+ ⚠️ This conflicts with your lock: "Never modify auth files"
108
+ Should I proceed anyway, or find another approach?
109
+ ```
110
+
111
+ ### Example 3: New session, full memory
112
+ ```
113
+ User: "Let's keep working on the dashboard"
114
+ AI: *calls speclock_session_briefing*
115
+ 🔒 Memory loaded — 5 locks, 3 decisions, 2 sessions tracked.
116
+ Last session you added the payment page and locked the auth files.
117
+ Ready to work on the dashboard.
118
+ ```
119
+
120
+ ### Example 4: User changes their mind
121
+ ```
122
+ User: "Actually, unlock the auth files, I need to change them"
123
+ AI: You locked: "Never modify auth files". Want me to unlock this?
124
+ User: "Yes"
125
+ AI: 🔓 Unlocked. Proceeding with auth file changes.
126
+ ```
127
+
128
+ ---
129
+
130
+ ## The Complete Setup (2 minutes)
131
+
132
+ ### Lovable:
133
+ 1. Connect SpecLock: Settings → Connectors → Custom → URL: `https://speclock-mcp-production.up.railway.app/mcp` → No auth
134
+ 2. Paste the instruction above into: Project Settings → Knowledge
135
+ 3. Say "initialize speclock" in your first chat
136
+ 4. Done. Every session after: AI auto-checks memory and constraints.
137
+
138
+ ### Cursor:
139
+ 1. Add to `.cursor/mcp.json`: `{"mcpServers":{"speclock":{"command":"npx","args":["-y","speclock","serve","--project","."]}}}`
140
+ 2. Create `.cursorrules` with the instruction above
141
+ 3. Done.
142
+
143
+ ### Claude Code:
144
+ 1. Add to `~/.claude.json` or `.mcp.json`: `{"mcpServers":{"speclock":{"command":"npx","args":["-y","speclock","serve","--project","."]}}}`
145
+ 2. Add the instruction above to `CLAUDE.md`
146
+ 3. Done.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "speclock",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "AI continuity engine — MCP server + CLI that kills AI amnesia. Maintains project memory, enforces constraints, and detects drift across AI coding sessions.",
5
5
  "type": "module",
6
6
  "main": "src/mcp/server.js",
@@ -54,6 +54,7 @@
54
54
  "bin/",
55
55
  "src/",
56
56
  "README.md",
57
+ "SPECLOCK-INSTRUCTIONS.md",
57
58
  "LICENSE"
58
59
  ],
59
60
  "devDependencies": {
package/src/cli/index.js CHANGED
@@ -7,7 +7,10 @@ import {
7
7
  addDecision,
8
8
  addNote,
9
9
  updateDeployFacts,
10
+ logChange,
11
+ checkConflict,
10
12
  watchRepo,
13
+ createSpecLockMd,
11
14
  } from "../core/engine.js";
12
15
  import { generateContext } from "../core/context.js";
13
16
  import { readBrain } from "../core/storage.js";
@@ -52,50 +55,56 @@ function rootDir() {
52
55
  return process.cwd();
53
56
  }
54
57
 
58
+ // --- Auto-regenerate context after write operations ---
59
+
60
+ function refreshContext(root) {
61
+ try {
62
+ generateContext(root);
63
+ } catch (_) {
64
+ // Silently skip if context generation fails
65
+ }
66
+ }
67
+
55
68
  // --- Help text ---
56
69
 
57
70
  function printHelp() {
58
71
  console.log(`
59
- SpecLock v1.1.0 — AI Continuity Engine
72
+ SpecLock v1.3.0 — AI Continuity Engine
60
73
  Developed by Sandeep Roy (github.com/sgroy10)
61
74
 
62
75
  Usage: speclock <command> [options]
63
76
 
64
77
  Commands:
65
- init Initialize SpecLock in current directory
66
- goal <text> Set or update the project goal
67
- lock <text> [--tags a,b] Add a non-negotiable constraint (SpecLock)
68
- lock remove <id> Remove a lock by ID
69
- decide <text> [--tags a,b] Record a decision
70
- note <text> [--pinned] Add a pinned note
71
- facts deploy [--provider X] Set deployment facts
72
- context Generate and print context pack
73
- watch Start file watcher (auto-track changes)
74
- serve [--project <path>] Start MCP stdio server
75
- status Show project brain summary
78
+ setup [--goal <text>] Full setup: init + SPECLOCK.md + context
79
+ init Initialize SpecLock in current directory
80
+ goal <text> Set or update the project goal
81
+ lock <text> [--tags a,b] Add a non-negotiable constraint
82
+ lock remove <id> Remove a lock by ID
83
+ decide <text> [--tags a,b] Record a decision
84
+ note <text> [--pinned] Add a pinned note
85
+ log-change <text> [--files x,y] Log a significant change
86
+ check <text> Check if action conflicts with locks
87
+ context Generate and print context pack
88
+ facts deploy [--provider X] Set deployment facts
89
+ watch Start file watcher (auto-track changes)
90
+ serve [--project <path>] Start MCP stdio server
91
+ status Show project brain summary
76
92
 
77
93
  Options:
78
- --tags <a,b,c> Comma-separated tags
79
- --source <user|agent> Who created this (default: user)
80
- --provider <name> Deploy provider
81
- --branch <name> Deploy branch
82
- --autoDeploy <true|false> Auto-deploy setting
83
- --url <url> Deployment URL
84
- --notes <text> Additional notes
85
- --project <path> Project root (for serve)
94
+ --tags <a,b,c> Comma-separated tags
95
+ --source <user|agent> Who created this (default: user)
96
+ --files <a.ts,b.ts> Comma-separated file paths
97
+ --goal <text> Goal text (for setup command)
98
+ --project <path> Project root (for serve)
86
99
 
87
100
  Examples:
88
- speclock init
89
- speclock goal "Ship v1 of the continuity engine"
90
- speclock lock "No external database in v1" --tags scope
91
- speclock decide "Use MCP as primary integration" --tags architecture
92
- speclock context
93
- speclock serve --project /path/to/repo
94
-
95
- MCP Tools (19): init, get_context, set_goal, add_lock, remove_lock,
96
- add_decision, add_note, set_deploy_facts, log_change, get_changes,
97
- get_events, check_conflict, session_briefing, session_summary,
98
- checkpoint, repo_status, suggest_locks, detect_drift, health
101
+ npx speclock setup --goal "Build PawPalace pet shop"
102
+ npx speclock lock "Never modify auth files"
103
+ npx speclock check "Adding social login to auth page"
104
+ npx speclock log-change "Built payment system" --files src/pay.tsx
105
+ npx speclock decide "Use Supabase for auth"
106
+ npx speclock context
107
+ npx speclock status
99
108
  `);
100
109
  }
101
110
 
@@ -104,7 +113,7 @@ MCP Tools (19): init, get_context, set_goal, add_lock, remove_lock,
104
113
  function showStatus(root) {
105
114
  const brain = readBrain(root);
106
115
  if (!brain) {
107
- console.log("SpecLock not initialized. Run: speclock init");
116
+ console.log("SpecLock not initialized. Run: npx speclock setup");
108
117
  return;
109
118
  }
110
119
 
@@ -113,11 +122,11 @@ function showStatus(root) {
113
122
  console.log(`\nSpecLock Status — ${brain.project.name}`);
114
123
  console.log("=".repeat(50));
115
124
  console.log(`Goal: ${brain.goal.text || "(not set)"}`);
116
- console.log(`SpecLocks: ${activeLocks.length} active`);
125
+ console.log(`Locks: ${activeLocks.length} active`);
117
126
  console.log(`Decisions: ${brain.decisions.length}`);
118
127
  console.log(`Notes: ${brain.notes.length}`);
119
128
  console.log(`Events: ${brain.events.count}`);
120
- console.log(`Deploy: ${brain.facts.deploy.provider}`);
129
+ console.log(`Deploy: ${brain.facts.deploy.provider || "(not set)"}`);
121
130
 
122
131
  if (brain.sessions.current) {
123
132
  console.log(`Session: active (${brain.sessions.current.toolUsed})`);
@@ -133,7 +142,6 @@ function showStatus(root) {
133
142
  }
134
143
 
135
144
  console.log(`Recent changes: ${brain.state.recentChanges.length}`);
136
- console.log(`Reverts: ${brain.state.reverts.length}`);
137
145
  console.log("");
138
146
  }
139
147
 
@@ -148,12 +156,60 @@ async function main() {
148
156
  process.exit(0);
149
157
  }
150
158
 
159
+ // --- SETUP (new: one-shot full setup) ---
160
+ if (cmd === "setup") {
161
+ const flags = parseFlags(args);
162
+ const goalText = flags.goal || flags._.join(" ").trim();
163
+
164
+ // 1. Initialize
165
+ ensureInit(root);
166
+ console.log("Initialized .speclock/ directory.");
167
+
168
+ // 2. Set goal if provided
169
+ if (goalText) {
170
+ setGoal(root, goalText);
171
+ console.log(`Goal set: "${goalText}"`);
172
+ }
173
+
174
+ // 3. Create SPECLOCK.md in project root
175
+ const mdPath = createSpecLockMd(root);
176
+ console.log(`Created SPECLOCK.md (AI instructions file).`);
177
+
178
+ // 4. Generate context
179
+ generateContext(root);
180
+ console.log("Generated .speclock/context/latest.md");
181
+
182
+ // 5. Print summary
183
+ console.log(`
184
+ SpecLock is ready!
185
+
186
+ Files created:
187
+ .speclock/brain.json — Project memory
188
+ .speclock/context/latest.md — Context for AI (read this)
189
+ SPECLOCK.md — AI rules (read this)
190
+
191
+ Next steps:
192
+ The AI should read SPECLOCK.md for rules and
193
+ .speclock/context/latest.md for project context.
194
+
195
+ To add constraints: npx speclock lock "Never touch auth files"
196
+ To check conflicts: npx speclock check "Modifying auth page"
197
+ To log changes: npx speclock log-change "Built landing page"
198
+ To see status: npx speclock status
199
+ `);
200
+ return;
201
+ }
202
+
203
+ // --- INIT ---
151
204
  if (cmd === "init") {
152
205
  ensureInit(root);
153
- console.log("SpecLock initialized.");
206
+ createSpecLockMd(root);
207
+ generateContext(root);
208
+ console.log("SpecLock initialized. Created SPECLOCK.md and context file.");
154
209
  return;
155
210
  }
156
211
 
212
+ // --- GOAL ---
157
213
  if (cmd === "goal") {
158
214
  const text = args.join(" ").trim();
159
215
  if (!text) {
@@ -162,10 +218,12 @@ async function main() {
162
218
  process.exit(1);
163
219
  }
164
220
  setGoal(root, text);
221
+ refreshContext(root);
165
222
  console.log(`Goal set: "${text}"`);
166
223
  return;
167
224
  }
168
225
 
226
+ // --- LOCK ---
169
227
  if (cmd === "lock") {
170
228
  // Check for "lock remove <id>"
171
229
  if (args[0] === "remove") {
@@ -177,6 +235,7 @@ async function main() {
177
235
  }
178
236
  const result = removeLock(root, lockId);
179
237
  if (result.removed) {
238
+ refreshContext(root);
180
239
  console.log(`Lock removed: "${result.lockText}"`);
181
240
  } else {
182
241
  console.error(result.error);
@@ -193,10 +252,12 @@ async function main() {
193
252
  process.exit(1);
194
253
  }
195
254
  const { lockId } = addLock(root, text, parseTags(flags.tags), flags.source || "user");
196
- console.log(`SpecLock added (${lockId}): "${text}"`);
255
+ refreshContext(root);
256
+ console.log(`Locked (${lockId}): "${text}"`);
197
257
  return;
198
258
  }
199
259
 
260
+ // --- DECIDE ---
200
261
  if (cmd === "decide") {
201
262
  const flags = parseFlags(args);
202
263
  const text = flags._.join(" ").trim();
@@ -206,10 +267,12 @@ async function main() {
206
267
  process.exit(1);
207
268
  }
208
269
  const { decId } = addDecision(root, text, parseTags(flags.tags), flags.source || "user");
270
+ refreshContext(root);
209
271
  console.log(`Decision recorded (${decId}): "${text}"`);
210
272
  return;
211
273
  }
212
274
 
275
+ // --- NOTE ---
213
276
  if (cmd === "note") {
214
277
  const flags = parseFlags(args);
215
278
  const text = flags._.join(" ").trim();
@@ -220,10 +283,60 @@ async function main() {
220
283
  }
221
284
  const pinned = flags.pinned !== false;
222
285
  const { noteId } = addNote(root, text, pinned);
286
+ refreshContext(root);
223
287
  console.log(`Note added (${noteId}): "${text}"`);
224
288
  return;
225
289
  }
226
290
 
291
+ // --- LOG-CHANGE (new) ---
292
+ if (cmd === "log-change") {
293
+ const flags = parseFlags(args);
294
+ const text = flags._.join(" ").trim();
295
+ if (!text) {
296
+ console.error("Error: Change summary is required.");
297
+ console.error('Usage: speclock log-change "what changed" --files a.ts,b.ts');
298
+ process.exit(1);
299
+ }
300
+ const files = flags.files ? flags.files.split(",").map((f) => f.trim()).filter(Boolean) : [];
301
+ logChange(root, text, files);
302
+ refreshContext(root);
303
+ console.log(`Change logged: "${text}"`);
304
+ if (files.length > 0) {
305
+ console.log(`Files: ${files.join(", ")}`);
306
+ }
307
+ return;
308
+ }
309
+
310
+ // --- CHECK (new: conflict check) ---
311
+ if (cmd === "check") {
312
+ const text = args.join(" ").trim();
313
+ if (!text) {
314
+ console.error("Error: Action description is required.");
315
+ console.error('Usage: speclock check "what you plan to do"');
316
+ process.exit(1);
317
+ }
318
+ const result = checkConflict(root, text);
319
+ if (result.hasConflict) {
320
+ console.log(`\nCONFLICT DETECTED`);
321
+ console.log("=".repeat(50));
322
+ for (const lock of result.conflictingLocks) {
323
+ console.log(` [${lock.confidence}] "${lock.text}"`);
324
+ console.log(` Confidence: ${lock.score}%`);
325
+ if (lock.reasons && lock.reasons.length > 0) {
326
+ for (const reason of lock.reasons) {
327
+ console.log(` - ${reason}`);
328
+ }
329
+ }
330
+ console.log("");
331
+ }
332
+ console.log(result.analysis);
333
+ } else {
334
+ console.log(`No conflicts found. Safe to proceed with: "${text}"`);
335
+ }
336
+ return;
337
+ }
338
+
339
+ // --- FACTS ---
227
340
  if (cmd === "facts") {
228
341
  const sub = args.shift();
229
342
  if (sub !== "deploy") {
@@ -245,21 +358,25 @@ async function main() {
245
358
  String(flags.autoDeploy).toLowerCase() === "true";
246
359
  }
247
360
  updateDeployFacts(root, payload);
361
+ refreshContext(root);
248
362
  console.log("Deploy facts updated.");
249
363
  return;
250
364
  }
251
365
 
366
+ // --- CONTEXT ---
252
367
  if (cmd === "context") {
253
368
  const md = generateContext(root);
254
369
  console.log(md);
255
370
  return;
256
371
  }
257
372
 
373
+ // --- WATCH ---
258
374
  if (cmd === "watch") {
259
375
  await watchRepo(root);
260
376
  return;
261
377
  }
262
378
 
379
+ // --- SERVE ---
263
380
  if (cmd === "serve") {
264
381
  // Start MCP server — pass through --project if provided
265
382
  const flags = parseFlags(args);
@@ -269,6 +386,7 @@ async function main() {
269
386
  return;
270
387
  }
271
388
 
389
+ // --- STATUS ---
272
390
  if (cmd === "status") {
273
391
  showStatus(root);
274
392
  return;
@@ -696,3 +696,53 @@ export async function watchRepo(root) {
696
696
  console.log("SpecLock watching for changes...");
697
697
  return watcher;
698
698
  }
699
+
700
+ // --- SPECLOCK.md generator (for npm dependency / file-based mode) ---
701
+
702
+ export function createSpecLockMd(root) {
703
+ const mdContent = `# SpecLock — Project Memory Active
704
+
705
+ This project uses **SpecLock** for AI continuity across sessions.
706
+ Read \`.speclock/context/latest.md\` for full project context before making changes.
707
+
708
+ ## Rules (follow on every message)
709
+
710
+ 1. **START OF EVERY MESSAGE**: Read \`.speclock/context/latest.md\` for project memory — goals, constraints (locks), decisions, and recent changes. If the file doesn't exist, run \`npx speclock context\` to generate it.
711
+
712
+ 2. **BEFORE MODIFYING CODE**: Run \`npx speclock check "description of what you plan to change"\`. If a conflict is found (HIGH confidence), STOP and warn the user which constraint would be violated. Do NOT proceed unless the user explicitly says to override.
713
+
714
+ 3. **WHEN USER SAYS "lock this", "never touch", "don't change", "always", "critical"**: Run \`npx speclock lock "the exact constraint"\`. Confirm: "Locked: [constraint]"
715
+
716
+ 4. **AFTER COMPLETING A FEATURE OR SIGNIFICANT CHANGE**: Run \`npx speclock log-change "what was built/changed" --files file1.tsx,file2.ts\`. Then run \`npx speclock context\` to refresh the context file.
717
+
718
+ 5. **WHEN AN ARCHITECTURAL DECISION IS MADE**: Run \`npx speclock decide "the decision"\`
719
+
720
+ 6. **WHEN USER WANTS TO CHANGE SOMETHING LOCKED**: Warn first: "This is locked: [constraint]. Want me to unlock and proceed?" If confirmed, run \`npx speclock lock remove <lockId>\`
721
+
722
+ ## Quick Reference
723
+
724
+ \`\`\`bash
725
+ npx speclock status # See brain summary
726
+ npx speclock context # Regenerate context file
727
+ npx speclock lock "constraint text" # Add a constraint
728
+ npx speclock lock remove <lockId> # Remove a constraint
729
+ npx speclock decide "decision text" # Record a decision
730
+ npx speclock log-change "what changed" # Log a change
731
+ npx speclock check "what you plan to do" # Check for conflicts
732
+ npx speclock goal "project goal" # Set/update goal
733
+ npx speclock note "important note" # Add a note
734
+ \`\`\`
735
+
736
+ ## How It Works
737
+
738
+ SpecLock maintains a \`.speclock/\` directory with structured project memory:
739
+ - \`brain.json\` — goals, locks, decisions, session history
740
+ - \`events.log\` — immutable audit trail
741
+ - \`context/latest.md\` — human-readable context (read this!)
742
+
743
+ Every command automatically refreshes the context file so it's always up to date.
744
+ `;
745
+ const filePath = path.join(root, "SPECLOCK.md");
746
+ fs.writeFileSync(filePath, mdContent);
747
+ return filePath;
748
+ }
@@ -41,7 +41,7 @@ import {
41
41
  } from "../core/git.js";
42
42
 
43
43
  const PROJECT_ROOT = process.env.SPECLOCK_PROJECT_ROOT || process.cwd();
44
- const VERSION = "1.1.0";
44
+ const VERSION = "1.2.0";
45
45
  const AUTHOR = "Sandeep Roy";
46
46
 
47
47
  function createSpecLockServer() {
@@ -49,38 +49,37 @@ function createSpecLockServer() {
49
49
  { name: "speclock", version: VERSION },
50
50
  {
51
51
  instructions: [
52
- `You have SpecLock connected — an AI Continuity Engine by ${AUTHOR}. Follow these rules AUTOMATICALLY without the user ever having to ask:`,
52
+ `CRITICAL: You have SpecLock connected — an AI Continuity Engine that remembers project context across sessions. You MUST follow these rules:`,
53
53
  ``,
54
- `## ON EVERY NEW CONVERSATION / SESSION START:`,
55
- `1. IMMEDIATELY call speclock_session_briefing BEFORE responding to the user's first message.`,
56
- `2. If it returns "not initialized", call speclock_init first, then proceed normally.`,
57
- `3. Use the briefing context to understand the project's goal, constraints, decisions, and history.`,
58
- `4. Never ask the user to "initialize SpecLock" or "start a session" just do it silently.`,
54
+ `## STEP 1 FIRST THING IN EVERY CONVERSATION (MANDATORY):`,
55
+ `Before doing ANYTHING else, call speclock_session_briefing. This loads the project's goal, constraints, decisions, and history from previous sessions.`,
56
+ `- If it returns "not initialized", call speclock_init first, then tell the user: "I've set up project memory for this workspace. I'll remember your decisions and constraints across sessions."`,
57
+ `- If it returns context, start your response with a brief one-line status like: "🔒 Project memory loaded — [X] constraints, [Y] decisions tracked from previous sessions." Then proceed to answer the user's actual question.`,
58
+ `- If there is no meaningful context yet (new project), say: "🔒 Project memory active. I'll automatically remember your key decisions and constraints across sessions." Then proceed normally.`,
59
59
  ``,
60
- `## AUTOMATIC CONTEXT CAPTURE (do this silently as you work):`,
61
- `- When the user describes what they're building → call speclock_set_goal with a concise summary.`,
62
- `- When the user says something is non-negotiable (e.g., "always use Supabase", "never remove auth", "must support mobile") → call speclock_add_lock to save it as an immutable constraint.`,
63
- `- When the user makes a technology/architecture choice (e.g., "let's use React Query", "we'll go with Stripe") → call speclock_add_decision.`,
64
- `- When you complete a significant piece of work → call speclock_log_change.`,
65
- `- Look for keywords like "always", "never", "must", "don't ever", "make sure to keep" — these signal constraints that should be locked.`,
60
+ `## STEP 2 — LISTEN AND CAPTURE (do this continuously as you work):`,
61
+ `- When the user describes what they're building → call speclock_set_goal.`,
62
+ `- When the user says something is non-negotiable or uses words like "always", "never", "must", "don't ever change", "make sure to keep", "this is critical" → call speclock_add_lock. Then briefly confirm: "🔒 Locked: [constraint]"`,
63
+ `- When the user makes a technology or design choice → call speclock_add_decision.`,
64
+ `- When you complete significant work → call speclock_log_change.`,
66
65
  ``,
67
- `## BEFORE MAKING SIGNIFICANT CHANGES:`,
68
- `- Call speclock_check_conflict with a description of what you're about to do.`,
69
- `- If a conflict is detected (confidence HIGH), WARN the user and explain which constraint would be violated.`,
70
- `- Do NOT proceed with the change unless the user explicitly says to override or remove the lock.`,
66
+ `## STEP 3 PROTECT (before making significant changes):`,
67
+ `- Before removing features, changing architecture, switching technologies, or modifying core logic → call speclock_check_conflict.`,
68
+ `- If a conflict is found (confidence HIGH), STOP and warn: "⚠️ This would conflict with a constraint you set: [constraint]. Should I proceed anyway or keep the current approach?"`,
69
+ `- Do NOT proceed unless the user explicitly confirms.`,
71
70
  ``,
72
- `## WHEN THE USER ASKS TO REMOVE SOMETHING THEY PREVIOUSLY LOCKED:`,
73
- `- Remind them: "You previously locked this constraint: [constraint text]. Want me to remove the lock and proceed?"`,
74
- `- If they confirm, call speclock_remove_lock, then proceed.`,
71
+ `## STEP 4 REMEMBER (when the user wants to change their mind):`,
72
+ `- If they want to remove or change something they previously locked, remind them: "You previously locked: [constraint]. Want me to unlock this and proceed?"`,
73
+ `- If confirmed, call speclock_remove_lock, then proceed.`,
75
74
  ``,
76
- `## AT THE END OF A CONVERSATION (when the user says goodbye, or the conversation naturally ends):`,
77
- `- Call speclock_session_summary with a brief description of what was accomplished.`,
75
+ `## STEP 5 CLOSE (when conversation ends):`,
76
+ `- Call speclock_session_summary with a brief description of what was done.`,
78
77
  ``,
79
- `## IMPORTANT:`,
80
- `- NEVER mention "SpecLock" to the user unless they ask about it. Just use it silently in the background.`,
81
- `- The user should feel like the AI simply "remembers everything" — SpecLock is invisible infrastructure.`,
82
- `- If the user asks "how do you remember this?" you can explain SpecLock is connected as a memory layer.`,
83
- `- When showing the user what you know from previous sessions, present it naturally, not as a data dump.`,
78
+ `## KEY BEHAVIOR:`,
79
+ `- The 🔒 emoji is your SpecLock indicator. Users learn to recognize it means their project memory is active.`,
80
+ `- Keep SpecLock confirmations SHORT one line max. Don't dump data.`,
81
+ `- Present remembered context NATURALLY. Instead of "SpecLock says your goal is X", just say "Based on our previous work, the goal is X."`,
82
+ `- If the user asks "how do you remember this?" explain that SpecLock is connected as a project memory layer that persists across sessions.`,
84
83
  ].join("\n"),
85
84
  }
86
85
  );
package/src/mcp/server.js CHANGED
@@ -50,45 +50,44 @@ const PROJECT_ROOT =
50
50
  args.project || process.env.SPECLOCK_PROJECT_ROOT || process.cwd();
51
51
 
52
52
  // --- MCP Server ---
53
- const VERSION = "1.1.0";
53
+ const VERSION = "1.2.0";
54
54
  const AUTHOR = "Sandeep Roy";
55
55
 
56
56
  const server = new McpServer(
57
57
  { name: "speclock", version: VERSION },
58
58
  {
59
59
  instructions: [
60
- `You have SpecLock connected — an AI Continuity Engine by ${AUTHOR}. Follow these rules AUTOMATICALLY without the user ever having to ask:`,
60
+ `CRITICAL: You have SpecLock connected — an AI Continuity Engine that remembers project context across sessions. You MUST follow these rules:`,
61
61
  ``,
62
- `## ON EVERY NEW CONVERSATION / SESSION START:`,
63
- `1. IMMEDIATELY call speclock_session_briefing BEFORE responding to the user's first message.`,
64
- `2. If it returns "not initialized", call speclock_init first, then proceed normally.`,
65
- `3. Use the briefing context to understand the project's goal, constraints, decisions, and history.`,
66
- `4. Never ask the user to "initialize SpecLock" or "start a session" just do it silently.`,
62
+ `## STEP 1 FIRST THING IN EVERY CONVERSATION (MANDATORY):`,
63
+ `Before doing ANYTHING else, call speclock_session_briefing. This loads the project's goal, constraints, decisions, and history from previous sessions.`,
64
+ `- If it returns "not initialized", call speclock_init first, then tell the user: "I've set up project memory for this workspace. I'll remember your decisions and constraints across sessions."`,
65
+ `- If it returns context, start your response with a brief one-line status like: "🔒 Project memory loaded — [X] constraints, [Y] decisions tracked from previous sessions." Then proceed to answer the user's actual question.`,
66
+ `- If there is no meaningful context yet (new project), say: "🔒 Project memory active. I'll automatically remember your key decisions and constraints across sessions." Then proceed normally.`,
67
67
  ``,
68
- `## AUTOMATIC CONTEXT CAPTURE (do this silently as you work):`,
69
- `- When the user describes what they're building → call speclock_set_goal with a concise summary.`,
70
- `- When the user says something is non-negotiable (e.g., "always use Supabase", "never remove auth", "must support mobile") → call speclock_add_lock to save it as an immutable constraint.`,
71
- `- When the user makes a technology/architecture choice (e.g., "let's use React Query", "we'll go with Stripe") → call speclock_add_decision.`,
72
- `- When you complete a significant piece of work → call speclock_log_change.`,
73
- `- Look for keywords like "always", "never", "must", "don't ever", "make sure to keep" — these signal constraints that should be locked.`,
68
+ `## STEP 2 — LISTEN AND CAPTURE (do this continuously as you work):`,
69
+ `- When the user describes what they're building → call speclock_set_goal.`,
70
+ `- When the user says something is non-negotiable or uses words like "always", "never", "must", "don't ever change", "make sure to keep", "this is critical" → call speclock_add_lock. Then briefly confirm: "🔒 Locked: [constraint]"`,
71
+ `- When the user makes a technology or design choice → call speclock_add_decision.`,
72
+ `- When you complete significant work → call speclock_log_change.`,
74
73
  ``,
75
- `## BEFORE MAKING SIGNIFICANT CHANGES:`,
76
- `- Call speclock_check_conflict with a description of what you're about to do.`,
77
- `- If a conflict is detected (confidence HIGH), WARN the user and explain which constraint would be violated.`,
78
- `- Do NOT proceed with the change unless the user explicitly says to override or remove the lock.`,
74
+ `## STEP 3 PROTECT (before making significant changes):`,
75
+ `- Before removing features, changing architecture, switching technologies, or modifying core logic → call speclock_check_conflict.`,
76
+ `- If a conflict is found (confidence HIGH), STOP and warn: "⚠️ This would conflict with a constraint you set: [constraint]. Should I proceed anyway or keep the current approach?"`,
77
+ `- Do NOT proceed unless the user explicitly confirms.`,
79
78
  ``,
80
- `## WHEN THE USER ASKS TO REMOVE SOMETHING THEY PREVIOUSLY LOCKED:`,
81
- `- Remind them: "You previously locked this constraint: [constraint text]. Want me to remove the lock and proceed?"`,
82
- `- If they confirm, call speclock_remove_lock, then proceed.`,
79
+ `## STEP 4 REMEMBER (when the user wants to change their mind):`,
80
+ `- If they want to remove or change something they previously locked, remind them: "You previously locked: [constraint]. Want me to unlock this and proceed?"`,
81
+ `- If confirmed, call speclock_remove_lock, then proceed.`,
83
82
  ``,
84
- `## AT THE END OF A CONVERSATION (when the user says goodbye, or the conversation naturally ends):`,
85
- `- Call speclock_session_summary with a brief description of what was accomplished.`,
83
+ `## STEP 5 CLOSE (when conversation ends):`,
84
+ `- Call speclock_session_summary with a brief description of what was done.`,
86
85
  ``,
87
- `## IMPORTANT:`,
88
- `- NEVER mention "SpecLock" to the user unless they ask about it. Just use it silently in the background.`,
89
- `- The user should feel like the AI simply "remembers everything" — SpecLock is invisible infrastructure.`,
90
- `- If the user asks "how do you remember this?" you can explain SpecLock is connected as a memory layer.`,
91
- `- When showing the user what you know from previous sessions, present it naturally, not as a data dump.`,
86
+ `## KEY BEHAVIOR:`,
87
+ `- The 🔒 emoji is your SpecLock indicator. Users learn to recognize it means their project memory is active.`,
88
+ `- Keep SpecLock confirmations SHORT one line max. Don't dump data.`,
89
+ `- Present remembered context NATURALLY. Instead of "SpecLock says your goal is X", just say "Based on our previous work, the goal is X."`,
90
+ `- If the user asks "how do you remember this?" explain that SpecLock is connected as a project memory layer that persists across sessions.`,
92
91
  ].join("\n"),
93
92
  }
94
93
  );