@stackmemoryai/stackmemory 1.5.2 → 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.
@@ -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>
@@ -1,3 +1,4 @@
1
+ ```markdown
1
2
  # StackMemory - Project Configuration
2
3
 
3
4
  ## Project Structure
@@ -5,7 +6,7 @@
5
6
  ```
6
7
  src/
7
8
  cli/ # CLI commands and entry point
8
- core/ # Core business logic
9
+ core/
9
10
  context/ # Frame and context management
10
11
  database/ # Database adapters (SQLite, ParadeDB)
11
12
  digest/ # Digest generation
@@ -15,78 +16,72 @@ src/
15
16
  skills/ # Claude Code skills
16
17
  utils/ # Shared utilities
17
18
  scripts/ # Build and utility scripts
18
- config/ # Configuration files
19
- docs/ # Documentation
20
19
  ```
21
20
 
22
21
  ## Key Files
23
22
 
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
23
+ - Entry: `src/cli/index.ts`
24
+ - MCP Server: `src/integrations/mcp/server.ts`
25
+ - Frame Manager: `src/core/context/frame-manager.ts`
26
+ - Database: `src/core/database/sqlite-adapter.ts`
27
+ - Snapshot: `src/core/worktree/capture.ts`
28
+ - Preflight: `src/core/worktree/preflight.ts`
29
+ - Conductor: `src/cli/commands/orchestrator.ts`
30
+ - Shared Utils: `src/core/utils/{git,text,fs}.ts`
28
31
 
29
- ## Documentation
32
+ ## Docs
30
33
 
31
- Quick reference (agent_docs/): linear_integration.md | mcp_server.md | database_storage.md | claude_hooks.md
32
-
33
- Full docs (docs/): principles.md | architecture.md | SPEC.md | API_REFERENCE.md | DEVELOPMENT.md | SETUP.md
34
+ - `agent_docs/`: linear_integration.md | mcp_server.md | database_storage.md | claude_hooks.md
35
+ - `docs/`: principles.md | architecture.md | SPEC.md | API_REFERENCE.md | DEVELOPMENT.md
34
36
 
35
37
  ## Commands
36
38
 
37
39
  ```bash
38
- npm run build|lint|lint:fix|test|test:run|linear:sync
39
- stackmemory capture|restore # Session state handoff
40
+ npm run build # Compile TypeScript (esbuild)
41
+ npm run lint # ESLint check
42
+ npm run lint:fix # Auto-fix lint issues
43
+ npm run test:run # Run tests once
44
+ npm run linear:sync # Sync with Linear
45
+
46
+ stackmemory capture # Save session state for handoff
47
+ stackmemory restore # Restore from captured state
48
+ stackmemory snapshot save # Post-run context snapshot (alias: snap)
49
+ stackmemory snapshot list # List recent snapshots
50
+ stackmemory preflight # File overlap check for parallel tasks (alias: pf)
51
+ stackmemory conductor start # Autonomous Linear→worktree→agent orchestrator
40
52
  ```
41
53
 
42
- ## Working Directory
43
-
44
- PRIMARY: /Users/jwu/Dev/stackmemory | ALLOWED: All subdirectories | TEMP: /tmp
45
-
46
54
  ## Validation (MUST DO)
47
55
 
48
- After code changes:
49
- 1. `npm run lint` - fix errors AND warnings
50
- 2. `npm run test:run` - verify no regressions
51
- 3. `npm run build` - ensure compilation
52
- 4. Run code to verify it works
56
+ After code changes: `npm run lint && npm run test:run && npm run build`
53
57
 
54
- Test coverage:
55
58
  - New features require tests in `src/**/__tests__/`
56
- - Maintain or improve coverage (no untested code paths)
59
+ - Maintain or improve coverage no untested code paths
57
60
  - Critical paths: context management, handoff, Linear sync
58
-
59
- Never: Assume success | Skip testing | Use mock data as fallback
61
+ - Never assume success | skip testing | use mock data as fallback
60
62
 
61
63
  ## Git Rules (CRITICAL)
62
64
 
63
- - NEVER use `--no-verify` on commit/push
64
- - ALWAYS fix lint/test errors before pushing
65
- - Run `npm run lint && npm run test:run` before pushing
66
- - Commit format: `type(scope): message`
67
- - Branch naming: `feature/STA-XXX-desc` | `fix/STA-XXX-desc` | `chore/desc`
65
+ - NEVER `--no-verify` on push or commit — fix the underlying issue
66
+ - Commit: `type(scope): message` | Branch: `feature/STA-XXX-description` | `fix/` | `chore/`
68
67
 
69
68
  ## Security
70
69
 
71
- NEVER hardcode secrets - use process.env with dotenv/config
70
+ NEVER hardcode secrets use `process.env` with dotenv/config.
72
71
 
73
72
  ```javascript
74
73
  import 'dotenv/config';
75
74
  const API_KEY = process.env.LINEAR_API_KEY;
76
- if (!API_KEY) {
77
- console.error('LINEAR_API_KEY not set');
78
- process.exit(1);
79
- }
75
+ if (!API_KEY) { console.error('LINEAR_API_KEY not set'); process.exit(1); }
80
76
  ```
81
77
 
82
- Environment sources (check in order): .env | .env.local | ~/.zshrc | process.env
83
-
84
- Secret patterns to block: lin_api_* | lin_oauth_* | sk-* | npm_*
78
+ Env sources (order): `.env` `.env.local` `~/.zshrc` process env
79
+ Block patterns: `lin_api_*` | `lin_oauth_*` | `sk-*` | `npm_*`
85
80
 
86
81
  ## Deploy
87
82
 
88
83
  ```bash
89
- # npm publish (uses NPM_TOKEN from .env)
84
+ # npm publish
90
85
  git stash -- scripts/gepa/
91
86
  NPM_TOKEN=$(grep '^NPM_TOKEN=' .env | cut -d= -f2) \
92
87
  npm publish --registry https://registry.npmjs.org/ \
@@ -95,48 +90,33 @@ git stash pop
95
90
 
96
91
  # Railway
97
92
  railway up
98
-
99
- # Pre-publish requires clean git — stash GEPA files first
100
93
  ```
101
94
 
102
- ## Task Delegation Model
103
-
104
- Route effort by complexity:
95
+ Pre-publish requires clean git status — stash GEPA files first.
105
96
 
106
- **AUTOMATE** Execute immediately, lint+test sufficient:
107
- - CRUD, boilerplate, formatting, simple transforms
108
- - Tool handler following existing pattern
109
- - Config additions (env var, feature flag)
97
+ ## Task Delegation Model
110
98
 
111
- **STANDARD** — Normal workflow, lint+test+build:
112
- - Features, bug fixes, refactoring
113
- - Tests, docs, integration wiring
99
+ **AUTOMATE** — lint+test sufficient:
100
+ - CRUD, boilerplate, config additions, simple switch/case handlers
114
101
 
115
- **CAREFUL** — Review approach before implementation:
116
- - API/schema changes, migrations, auth flows
117
- - New integration patterns (MCP, webhooks)
118
- - Changes to frame-manager, sqlite-adapter, daemon lifecycle
119
- - Error handling chains
102
+ **STANDARD** — lint+test+build:
103
+ - Feature impl, bug fixes, refactoring, new tests, integration wiring
120
104
 
121
- **ARCHITECT** — Plan mode required, explore patterns first:
122
- - New service boundaries, system integrations
123
- - Performance-critical paths (FTS5, search scoring)
124
- - Breaking changes to MCP protocol or CLI
105
+ **CAREFUL** — review approach first:
106
+ - API/schema changes, DB migrations, auth flows, MCP/webhook handlers
107
+ - Changes to frame-manager, sqlite-adapter, daemon lifecycle, error chains
125
108
 
126
- **HUMAN** — Explicit approval required:
127
- - Security decisions, secret handling
128
- - Irreversible operations (migrations, schema drops)
129
- - Publishing (npm, Railway)
109
+ **ARCHITECT** — plan mode required:
110
+ - New service boundaries, FTS5/search performance, breaking MCP/CLI changes
130
111
 
131
- Quality gates scale with tier don't over-engineer AUTOMATE, don't under-review CAREFUL.
112
+ **HUMAN**explicit approval required:
113
+ - Secret handling, data migrations/schema drops, npm publish, Railway deploy
132
114
 
133
115
  ## Workflow
134
116
 
135
- - Check .env for API keys before asking
136
- - Run npm run linear:sync after task completion
137
- - Use browser MCP for visual testing
138
- - Review recent commits and stackmemory.json on session start
139
- - Use TodoWrite for 3+ steps or multiple requests
140
- - Keep one task in_progress at a time
141
- - Update task status immediately on completion
142
- - Ask 1-3 clarifying questions for complex commands (one at a time)
117
+ - Check `.env` for API keys before asking
118
+ - Run `npm run linear:sync` after task completion
119
+ - Review recent commits on session start
120
+ - Use subagents for multi-step tasks
121
+ - Ask 1–3 clarifying questions for complex commands (one at a time)
122
+ ```