@stackmemoryai/stackmemory 1.5.3 → 1.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.
@@ -21,26 +21,30 @@ docs/ # Documentation
21
21
 
22
22
  ## Key Files
23
23
 
24
- - Entry: src/cli/index.ts
25
- - MCP Server: src/integrations/mcp/server.ts
26
- - Frame Manager: src/core/context/frame-manager.ts
27
- - Database: src/core/database/sqlite-adapter.ts
28
-
29
- ## Documentation
30
-
31
- Quick reference (agent_docs/):
32
- - linear_integration.md - Linear sync
33
- - mcp_server.md - MCP tools
34
- - database_storage.md - Storage
35
- - claude_hooks.md - Hooks
36
-
37
- Full docs (docs/):
38
- - principles.md - Agent programming paradigm
39
- - architecture.md - Extension model and browser sandbox
40
- - SPEC.md - Technical specification
41
- - API_REFERENCE.md - API docs
42
- - DEVELOPMENT.md - Dev guide
43
- - SETUP.md - Installation
24
+ - Entry: `src/cli/index.ts`
25
+ - MCP Server: `src/integrations/mcp/server.ts`
26
+ - Frame Manager: `src/core/context/frame-manager.ts`
27
+ - Database: `src/core/database/sqlite-adapter.ts`
28
+ - Snapshot: `src/core/worktree/capture.ts`
29
+ - Preflight: `src/core/worktree/preflight.ts`
30
+ - Conductor: `src/cli/commands/orchestrator.ts`
31
+ - Shared Utils: `src/core/utils/{git,text,fs}.ts`
32
+
33
+ ## Reference Docs
34
+
35
+ Quick reference (`agent_docs/`):
36
+ - `linear_integration.md` — Linear sync
37
+ - `mcp_server.md` — MCP tools
38
+ - `database_storage.md` Storage
39
+ - `claude_hooks.md` Hooks
40
+
41
+ Full docs (`docs/`):
42
+ - `principles.md` Agent programming paradigm
43
+ - `architecture.md` Extension model and browser sandbox
44
+ - `SPEC.md` — Technical specification
45
+ - `API_REFERENCE.md` — API docs
46
+ - `DEVELOPMENT.md` — Dev guide
47
+ - `SETUP.md` — Installation
44
48
 
45
49
  ## Commands
46
50
 
@@ -53,53 +57,51 @@ npm run test:run # Run tests once
53
57
  npm run linear:sync # Sync with Linear
54
58
 
55
59
  # StackMemory CLI
56
- stackmemory capture # Save session state for handoff
57
- stackmemory restore # Restore from captured state
60
+ stackmemory capture # Save session state for handoff
61
+ stackmemory restore # Restore from captured state
62
+ stackmemory snapshot save # Post-run context snapshot (alias: snap)
63
+ stackmemory snapshot list # List recent snapshots
64
+ stackmemory preflight # File overlap check for parallel tasks (alias: pf)
65
+ stackmemory conductor start # Autonomous Linear→worktree→agent orchestrator
58
66
  ```
59
67
 
60
68
  ## Working Directory
61
69
 
62
- - PRIMARY: /Users/jwu/Dev/stackmemory
70
+ - PRIMARY: `/Users/jwu/Dev/stackmemory`
63
71
  - ALLOWED: All subdirectories
64
- - TEMP: /tmp for temporary operations
72
+ - TEMP: `/tmp`
65
73
 
66
- ## Required Validation
74
+ ## Validation (REQUIRED after every code change)
67
75
 
68
- After every code change:
69
- 1. `npm run lint` - fix all errors AND warnings
70
- 2. `npm run test:run` - verify no regressions
71
- 3. `npm run build` - confirm compilation succeeds
72
- 4. Execute code to confirm functionality
76
+ 1. `npm run lint` — fix all errors and warnings
77
+ 2. `npm run test:run` confirm no regressions
78
+ 3. `npm run build` confirm compilation succeeds
79
+ 4. Run the code to verify behavior
73
80
 
74
- Test coverage requirements:
75
- - Write tests in `src/**/__tests__/` for all new features
76
- - Maintain or improve coverage - no untested code paths
77
- - Critical paths require tests: context management, handoff, Linear sync
81
+ Test coverage rules:
82
+ - New features require tests in `src/**/__tests__/`
83
+ - Maintain or improve coverage no untested code paths
84
+ - Critical paths: context management, handoff, Linear sync
78
85
 
79
- Do NOT: assume success | skip testing | use mock data as fallback
86
+ Do not: assume success | skip testing | use mock data as fallback
80
87
 
81
88
  ## Git Rules (CRITICAL)
82
89
 
83
- NEVER:
84
- - Use `--no-verify` on git push or commit
85
- - Push without fixing lint/test errors
86
- - Skip validation when pre-push hooks fail
87
-
88
- ALWAYS:
89
- - Fix underlying issues when hooks fail
90
- - Run `npm run lint && npm run test:run` before pushing
91
- - Use commit format: `type(scope): message`
92
- - Use branch naming: `feature/STA-XXX-description` | `fix/STA-XXX-description` | `chore/description`
90
+ - NEVER pass `--no-verify` to `git push` or `git commit`
91
+ - Fix lint/test errors before pushing — never bypass pre-push hooks
92
+ - Run `npm run lint && npm run test:run` before every push
93
+ - Commit format: `type(scope): message`
94
+ - Branch format: `feature/STA-XXX-description` | `fix/STA-XXX-description` | `chore/description`
93
95
 
94
96
  ## Task Management
95
97
 
96
- - Create TodoWrite for 3+ steps or multiple requests
97
- - Work on one task at a time (keep one in_progress)
98
- - Update task status immediately on completion
98
+ - Use TodoWrite for tasks with 3+ steps or multiple requests
99
+ - Keep exactly one task `in_progress` at a time
100
+ - Mark tasks complete immediately when done
99
101
 
100
102
  ## Security
101
103
 
102
- NEVER hardcode secrets. Use process.env with dotenv/config:
104
+ Never hardcode secrets. Always use `process.env` with dotenv:
103
105
 
104
106
  ```javascript
105
107
  import 'dotenv/config';
@@ -110,18 +112,18 @@ if (!API_KEY) {
110
112
  }
111
113
  ```
112
114
 
113
- Environment sources (check in order):
114
- 1. .env file
115
- 2. .env.local
116
- 3. ~/.zshrc
115
+ Check env sources in order:
116
+ 1. `.env`
117
+ 2. `.env.local`
118
+ 3. `~/.zshrc`
117
119
  4. Process environment
118
120
 
119
- Block secret patterns: lin_api_* | lin_oauth_* | sk-* | npm_*
121
+ Block these patterns: `lin_api_*` | `lin_oauth_*` | `sk-*` | `npm_*`
120
122
 
121
123
  ## Deploy
122
124
 
123
125
  ```bash
124
- # npm publish (uses NPM_TOKEN from .env, no OTP needed)
126
+ # npm publish (NPM_TOKEN from .env, no OTP required)
125
127
  git stash -- scripts/gepa/ # stash GEPA state (dirties working tree)
126
128
  NPM_TOKEN=$(grep '^NPM_TOKEN=' .env | cut -d= -f2) \
127
129
  npm publish --registry https://registry.npmjs.org/ \
@@ -131,46 +133,44 @@ git stash pop # restore GEPA state
131
133
  # Railway
132
134
  railway up
133
135
 
134
- # Pre-publish checks require clean git status — stash GEPA files first
136
+ # Note: pre-publish checks require clean git status — stash GEPA files first
135
137
  ```
136
138
 
137
139
  ## Task Delegation Model
138
140
 
139
- Match effort to complexity:
141
+ Match scrutiny to complexity:
140
142
 
141
- **AUTOMATE** — Execute immediately, lint+test only:
142
- - CRUD operations, boilerplate, formatting, simple transforms
143
- - Adding tool handler following existing switch/case pattern
144
- - Config additions (env var, feature flag)
143
+ **AUTOMATE** — Run immediately; lint+test is enough:
144
+ - CRUD, boilerplate, formatting, simple transforms
145
+ - Adding a tool handler to an existing switch/case
146
+ - Config additions (env vars, feature flags)
145
147
 
146
- **STANDARD** — Normal workflow, lint+test+build:
147
- - Feature implementation, bug fixes, refactoring
148
- - New test coverage, documentation updates
149
- - Integration wiring (adding handler to server.ts dispatch)
148
+ **STANDARD** — Normal workflow; lint+test+build:
149
+ - Feature work, bug fixes, refactoring
150
+ - New tests, doc updates
151
+ - Integration wiring (e.g., adding handler to `server.ts`)
150
152
 
151
- **CAREFUL** — Review approach before coding:
152
- - API/schema changes, database migrations, auth flows
153
- - New integration patterns (MCP tools, webhook handlers)
154
- - Changes to frame-manager, sqlite-adapter, daemon lifecycle
155
- - Error handling chain modifications
153
+ **CAREFUL** — Confirm approach before implementing:
154
+ - API/schema changes, DB migrations, auth flows
155
+ - New MCP tools or webhook handlers
156
+ - Changes to `frame-manager`, `sqlite-adapter`, or daemon lifecycle
157
+ - Any error handling chain modifications
156
158
 
157
- **ARCHITECT** — Plan mode required, explore patterns first:
158
- - New service boundaries, system integrations
159
+ **ARCHITECT** — Enter plan mode; read existing patterns first:
160
+ - New service boundaries or system integrations
159
161
  - Performance-critical paths (FTS5 queries, search scoring)
160
162
  - Breaking changes to MCP protocol or CLI interface
161
163
 
162
- **HUMAN** — Explicit user approval required:
163
- - Security-critical decisions, secret handling
164
+ **HUMAN** — Get explicit user approval before touching:
165
+ - Security decisions, secret handling
164
166
  - Irreversible operations (data migrations, schema drops)
165
- - Publishing (npm publish, Railway deploy)
166
-
167
- Scale quality gates to tier. Don't over-engineer AUTOMATE tasks or under-review CAREFUL ones.
167
+ - Publishing (`npm publish`, Railway deploy)
168
168
 
169
169
  ## Workflow
170
170
 
171
- - Check .env for API keys before asking user
172
- - Run `npm run linear:sync` after task completion
171
+ - Check `.env` for API keys before asking the user
172
+ - Run `npm run linear:sync` after completing tasks
173
173
  - Use browser MCP for visual testing
174
- - Review recent commits and stackmemory.json at session start
174
+ - On session start: review recent commits and `stackmemory.json`
175
175
  - Use subagents for multi-step tasks
176
- - Ask 1-3 clarifying questions for complex commands (one at a time)
176
+ - Ask at most 13 clarifying questions for complex requests, one at a time
@@ -25,6 +25,10 @@ docs/ # Documentation
25
25
  - MCP Server: src/integrations/mcp/server.ts
26
26
  - Frame Manager: src/core/context/frame-manager.ts
27
27
  - Database: src/core/database/sqlite-adapter.ts
28
+ - Snapshot: src/core/worktree/capture.ts
29
+ - Preflight: src/core/worktree/preflight.ts
30
+ - Conductor: src/cli/commands/orchestrator.ts
31
+ - Shared Utils: src/core/utils/{git,text,fs}.ts
28
32
 
29
33
  ## Detailed Guides
30
34
 
@@ -55,6 +59,10 @@ npm run linear:sync # Sync with Linear
55
59
  # StackMemory CLI
56
60
  stackmemory capture # Save session state for handoff
57
61
  stackmemory restore # Restore from captured state
62
+ stackmemory snapshot save # Post-run context snapshot (alias: snap)
63
+ stackmemory snapshot list # List recent snapshots
64
+ stackmemory preflight # File overlap check for parallel tasks (alias: pf)
65
+ stackmemory conductor start # Autonomous Linear→worktree→agent orchestrator
58
66
  ```
59
67
 
60
68
  ## Working Directory
@@ -72,10 +80,11 @@ After code changes:
72
80
  4. Run code to verify it works
73
81
 
74
82
  <example>
75
- # After adding a new MCP tool handler
76
- npm run lint && npm run test:run && npm run build
77
- # Then test the tool:
78
- echo '{"method":"tools/call","params":{"name":"your_tool"}}' | node dist/integrations/mcp/server.js
83
+ # Correct validation sequence after editing src/core/context/frame-manager.ts:
84
+ $ npm run lint # 0 errors, 0 warnings
85
+ $ npm run test:run # all tests pass (including search-benchmark smoke)
86
+ $ npm run build # → dist/ updated, no TS errors
87
+ $ stackmemory snapshot save # → verify feature works end-to-end
79
88
  </example>
80
89
 
81
90
  Test coverage:
@@ -84,9 +93,14 @@ Test coverage:
84
93
  - Critical paths: context management, handoff, Linear sync
85
94
 
86
95
  <example>
87
- # New feature: src/core/context/frame-deduplicator.ts
88
- # Required: src/core/context/__tests__/frame-deduplicator.test.ts
89
- # Test both happy path and edge cases (empty input, duplicates, conflicts)
96
+ # New feature: adding a getFrameCount() method to FrameManager
97
+ # requires test in src/core/context/__tests__/frame-manager.test.ts
98
+ it('getFrameCount returns correct count after adding frames', () => {
99
+ const mgr = new FrameManager(db);
100
+ mgr.addFrame({ content: 'a' });
101
+ mgr.addFrame({ content: 'b' });
102
+ expect(mgr.getFrameCount()).toBe(2);
103
+ });
90
104
  </example>
91
105
 
92
106
  Never: Assume success | Skip testing | Use mock data as fallback
@@ -101,15 +115,20 @@ Never: Assume success | Skip testing | Use mock data as fallback
101
115
  - Branch naming: `feature/STA-XXX-description` | `fix/STA-XXX-description` | `chore/description`
102
116
 
103
117
  <example>
104
- # Good commits:
105
- feat(mcp): add search_frames tool for context retrieval
106
- fix(linear): handle null assignee in webhook handler
107
- chore(deps): upgrade better-sqlite3 to 11.8.0
108
-
109
- # Good branches:
110
- feature/STA-123-add-digest-export
111
- fix/STA-456-frame-timestamp-parsing
112
- chore/upgrade-typescript-5.3
118
+ # Good commit messages:
119
+ feat(mcp): add get_frame_count tool to server
120
+ fix(sqlite): correct BM25 score negation in hybrid search
121
+ chore(deps): bump better-sqlite3 to 9.4.3
122
+ refactor(context): extract frame deduplication to utils
123
+
124
+ # Good branch names:
125
+ feature/STA-123-fts5-hybrid-search
126
+ fix/STA-456-timer-leak-promise-race
127
+ chore/update-vitest-config
128
+
129
+ # Bad — never do these:
130
+ git commit --no-verify -m "wip"
131
+ git push --force origin main
113
132
  </example>
114
133
 
115
134
  ## Task Management
@@ -119,32 +138,37 @@ chore/upgrade-typescript-5.3
119
138
  - Update task status immediately on completion
120
139
 
121
140
  <example>
122
- # Multi-step task requires TodoWrite:
123
- User: "Add Graphiti integration with Linear bridge"
124
- 1. Create TodoWrite with 4 tasks:
125
- - Research Graphiti API patterns
126
- - Implement LinearGraphitiBridge class
127
- - Add webhook handler for Linear events
128
- - Write integration tests
129
- 2. Mark task 1 in_progress, complete it
130
- 3. Mark task 2 in_progress, etc.
141
+ # User asks: "Add FTS5 search, wire it to MCP, and write tests"
142
+ # 3+ steps: use TodoWrite
143
+ TodoWrite([
144
+ { id: '1', content: 'Add FTS5 search method to sqlite-adapter', status: 'pending' },
145
+ { id: '2', content: 'Wire search to MCP tool handler in server.ts', status: 'pending' },
146
+ { id: '3', content: 'Write tests in __tests__/sqlite-adapter.test.ts', status: 'pending' },
147
+ ])
148
+ # Complete step 1 update status to 'completed' before starting step 2
131
149
  </example>
132
150
 
133
151
  ## Security
134
152
 
135
153
  NEVER hardcode secrets - use process.env with dotenv/config
136
154
 
137
- <example>
138
- // ✓ CORRECT
155
+ ```javascript
139
156
  import 'dotenv/config';
140
157
  const API_KEY = process.env.LINEAR_API_KEY;
141
158
  if (!API_KEY) {
142
159
  console.error('LINEAR_API_KEY not set');
143
160
  process.exit(1);
144
161
  }
162
+ ```
145
163
 
146
- // ✗ WRONG
147
- const API_KEY = 'lin_api_abc123def456';
164
+ <example>
165
+ // BAD never do this:
166
+ const client = new LinearClient({ apiKey: 'lin_api_abc123xyz' });
167
+
168
+ // GOOD:
169
+ const apiKey = process.env.LINEAR_API_KEY;
170
+ if (!apiKey) throw new Error('LINEAR_API_KEY not set');
171
+ const client = new LinearClient({ apiKey });
148
172
  </example>
149
173
 
150
174
  Environment sources (check in order):
@@ -155,13 +179,6 @@ Environment sources (check in order):
155
179
 
156
180
  Secret patterns to block: lin_api_* | lin_oauth_* | sk-* | npm_*
157
181
 
158
- <example>
159
- # If you see this pattern, STOP and use env vars:
160
- const token = 'lin_api_...';
161
- const apiKey = 'sk-...';
162
- const npmToken = 'npm_...';
163
- </example>
164
-
165
182
  ## Deploy
166
183
 
167
184
  ```bash
@@ -188,9 +205,10 @@ Route effort by task complexity — not all code changes deserve equal scrutiny:
188
205
  - Config additions (new env var, feature flag)
189
206
 
190
207
  <example>
191
- # AUTOMATE tier example:
192
- User: "Add a new MCP tool for listing frames by tag"
193
- Action: Add case to server.ts switch, follow existing pattern, lint+test
208
+ # AUTOMATE: adding a new MCP tool that follows the existing switch/case pattern
209
+ case 'get_frame_by_id':
210
+ return { frame: await frameManager.getById(args.id) };
211
+ # → just add the case, lint, test. No design review needed.
194
212
  </example>
195
213
 
196
214
  **STANDARD** — Normal workflow, lint+test+build:
@@ -199,9 +217,8 @@ Action: Add case to server.ts switch, follow existing pattern, lint+test
199
217
  - Integration wiring (adding handler to server.ts dispatch)
200
218
 
201
219
  <example>
202
- # STANDARD tier example:
203
- User: "Fix the digest generation to include frame metadata"
204
- Action: Modify digest-generator.ts, add tests, lint+test+build, verify output
220
+ # STANDARD: fixing a bug where snapshot list shows stale entries
221
+ # read the relevant files, understand root cause, fix, lint+test+build
205
222
  </example>
206
223
 
207
224
  **CAREFUL** — Review approach before implementation:
@@ -211,9 +228,10 @@ Action: Modify digest-generator.ts, add tests, lint+test+build, verify output
211
228
  - Anything touching error handling chains
212
229
 
213
230
  <example>
214
- # CAREFUL tier example:
215
- User: "Add a new column to frames table for priority scoring"
216
- Action: Read schema, check migrations, discuss ALTER TABLE vs rebuild, plan rollback
231
+ # CAREFUL: adding a new column to the frames table
232
+ # read sqlite-adapter.ts and schema_version migration pattern first
233
+ # plan the migration (increment schema_version, ALTER TABLE or recreate)
234
+ # → confirm approach with user if destructive
217
235
  </example>
218
236
 
219
237
  **ARCHITECT** — Plan mode required, explore existing patterns first:
@@ -222,9 +240,10 @@ Action: Read schema, check migrations, discuss ALTER TABLE vs rebuild, plan roll
222
240
  - Breaking changes to MCP protocol or CLI interface
223
241
 
224
242
  <example>
225
- # ARCHITECT tier example:
226
- User: "Integrate Graphiti knowledge graph with existing frame storage"
227
- Action: EnterPlanMode, explore frame-manager.ts, research Graphiti API, design bridge layer
243
+ # ARCHITECT: replacing LIKE-based search with hybrid FTS5+BM25
244
+ # enter plan mode, read sqlite-adapter.ts + search-benchmark.test.ts
245
+ # understand current scoring thresholds, BM25 sign conventions
246
+ # → design schema migration, write plan, get approval before coding
228
247
  </example>
229
248
 
230
249
  **HUMAN** — Explicit user approval before any changes:
@@ -233,9 +252,9 @@ Action: EnterPlanMode, explore frame-manager.ts, research Graphiti API, design b
233
252
  - Publishing (npm publish, Railway deploy)
234
253
 
235
254
  <example>
236
- # HUMAN tier example:
237
- User: "Publish v1.3.0 to npm"
238
- Action: Ask "Ready to publish? This will run npm publish with NPM_TOKEN." Wait for approval.
255
+ # HUMAN: "drop the old digest_cache table and run npm publish"
256
+ # → STOP. Confirm with user: "This will permanently delete digest_cache
257
+ # and publish to npm. Proceed?" wait for explicit yes.
239
258
  </example>
240
259
 
241
260
  Quality gates scale with tier — don't over-engineer AUTOMATE tasks, don't under-review CAREFUL ones.
@@ -250,17 +269,12 @@ Quality gates scale with tier — don't over-engineer AUTOMATE tasks, don't unde
250
269
  - Ask 1-3 clarifying questions for complex commands (one at a time)
251
270
 
252
271
  <example>
253
- # Session start workflow:
254
- 1. Read stackmemory.json for project state
255
- 2. Run: git log --oneline -5
256
- 3. Check git status for uncommitted work
257
- 4. If user mentions Linear task, run: npm run linear:sync
258
- 5. Proceed with user request
259
- </example>
260
-
261
- <example>
262
- # Complex command clarification:
263
- User: "Optimize the search performance"
264
- Response: "Which search path should I focus on? (1) FTS5 queries, (2) Hybrid search scoring, or (3) Database indexes?"
265
- # Wait for answer before proceeding
272
+ # Session start checklist:
273
+ $ git log --oneline -10 # understand recent context
274
+ $ cat stackmemory.json # check current config/state
275
+ $ cat .env | grep -v '^#' # verify which API keys are present
276
+
277
+ # After completing a Linear task:
278
+ $ npm run linear:sync # update issue status in Linear
279
+ $ stackmemory snapshot save # capture context for next session
266
280
  </example>