@stackmemoryai/stackmemory 0.1.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.
Files changed (50) hide show
  1. package/README.md +317 -0
  2. package/dist/attention-scoring/src/attention-tracker.d.ts +79 -0
  3. package/dist/attention-scoring/src/attention-tracker.d.ts.map +1 -0
  4. package/dist/attention-scoring/src/attention-tracker.js +488 -0
  5. package/dist/attention-scoring/src/attention-tracker.js.map +1 -0
  6. package/dist/attention-scoring/src/mcp-integration.d.ts +56 -0
  7. package/dist/attention-scoring/src/mcp-integration.d.ts.map +1 -0
  8. package/dist/attention-scoring/src/mcp-integration.js +369 -0
  9. package/dist/attention-scoring/src/mcp-integration.js.map +1 -0
  10. package/dist/p2p-sync/src/p2p-sync.d.ts +81 -0
  11. package/dist/p2p-sync/src/p2p-sync.d.ts.map +1 -0
  12. package/dist/p2p-sync/src/p2p-sync.js +457 -0
  13. package/dist/p2p-sync/src/p2p-sync.js.map +1 -0
  14. package/dist/p2p-sync/src/team-context-sync.d.ts +99 -0
  15. package/dist/p2p-sync/src/team-context-sync.d.ts.map +1 -0
  16. package/dist/p2p-sync/src/team-context-sync.js +491 -0
  17. package/dist/p2p-sync/src/team-context-sync.js.map +1 -0
  18. package/dist/scripts/initialize.d.ts +6 -0
  19. package/dist/scripts/initialize.d.ts.map +1 -0
  20. package/dist/scripts/initialize.js +93 -0
  21. package/dist/scripts/initialize.js.map +1 -0
  22. package/dist/scripts/status.d.ts +6 -0
  23. package/dist/scripts/status.d.ts.map +1 -0
  24. package/dist/scripts/status.js +87 -0
  25. package/dist/scripts/status.js.map +1 -0
  26. package/dist/src/cli.d.ts +7 -0
  27. package/dist/src/cli.d.ts.map +1 -0
  28. package/dist/src/cli.js +73 -0
  29. package/dist/src/cli.js.map +1 -0
  30. package/dist/src/error-handler.d.ts +42 -0
  31. package/dist/src/error-handler.d.ts.map +1 -0
  32. package/dist/src/error-handler.js +155 -0
  33. package/dist/src/error-handler.js.map +1 -0
  34. package/dist/src/frame-manager.d.ts +106 -0
  35. package/dist/src/frame-manager.d.ts.map +1 -0
  36. package/dist/src/frame-manager.js +361 -0
  37. package/dist/src/frame-manager.js.map +1 -0
  38. package/dist/src/index.d.ts +21 -0
  39. package/dist/src/index.d.ts.map +1 -0
  40. package/dist/src/index.js +9 -0
  41. package/dist/src/index.js.map +1 -0
  42. package/dist/src/logger.d.ts +24 -0
  43. package/dist/src/logger.d.ts.map +1 -0
  44. package/dist/src/logger.js +120 -0
  45. package/dist/src/logger.js.map +1 -0
  46. package/dist/src/mcp-server.d.ts +32 -0
  47. package/dist/src/mcp-server.d.ts.map +1 -0
  48. package/dist/src/mcp-server.js +441 -0
  49. package/dist/src/mcp-server.js.map +1 -0
  50. package/package.json +69 -0
package/README.md ADDED
@@ -0,0 +1,317 @@
1
+ # StackMemory
2
+
3
+ **Lossless, project-scoped memory for AI tools**
4
+
5
+ StackMemory is a **memory runtime** for AI coding and writing tools that preserves full project context across:
6
+
7
+ * chat thread resets
8
+ * model switching
9
+ * editor restarts
10
+ * long-running repos with thousands of interactions
11
+
12
+ Instead of a linear chat log, StackMemory organizes memory as a **call stack** of scoped work (frames), allowing context to naturally unwind without lossy compaction.
13
+
14
+ > **Memory is storage. Context is a compiled view.**
15
+
16
+ ---
17
+
18
+ ## Why StackMemory exists
19
+
20
+ Modern AI tools forget:
21
+
22
+ * why decisions were made
23
+ * which constraints still apply
24
+ * what changed earlier in the repo
25
+ * what tools already ran and why
26
+
27
+ StackMemory fixes this by:
28
+
29
+ * storing **everything losslessly** (events, tool calls, decisions)
30
+ * injecting only the **relevant working set** into model context
31
+ * keeping memory **project-scoped**, not chat-scoped
32
+
33
+ ---
34
+
35
+ ## Core concepts (quick mental model)
36
+
37
+ | Concept | Meaning |
38
+ | -------------- | ------------------------------------------------- |
39
+ | **Project** | One GitHub repo (initial scope) |
40
+ | **Frame** | A scoped unit of work (like a function call) |
41
+ | **Call Stack** | Nested frames; only the active path is "hot" |
42
+ | **Event** | Append-only record (message, tool call, decision) |
43
+ | **Digest** | Structured return value when a frame closes |
44
+ | **Anchor** | Pinned fact (DECISION, CONSTRAINT, INTERFACE) |
45
+
46
+ Frames can span:
47
+
48
+ * multiple chat turns
49
+ * multiple tool calls
50
+ * multiple sessions
51
+
52
+ ---
53
+
54
+ ## Hosted vs Open Source
55
+
56
+ ### Hosted (default)
57
+
58
+ * Cloud-backed memory runtime
59
+ * Fast indexing + retrieval
60
+ * Durable storage
61
+ * Per-project pricing
62
+ * Works out-of-the-box
63
+
64
+ ### Open-source local mirror
65
+
66
+ * SQLite-based
67
+ * Fully inspectable
68
+ * Offline / air-gapped
69
+ * Intentionally **N versions behind**
70
+ * No sync, no org features
71
+
72
+ > OSS is for trust and inspection.
73
+ > Hosted is for scale, performance, and teams.
74
+
75
+ ---
76
+
77
+ ## How it integrates
78
+
79
+ StackMemory integrates as an **MCP tool** and is invoked on **every interaction** in:
80
+
81
+ * Claude Code
82
+ * compatible editors
83
+ * future MCP-enabled tools
84
+
85
+ The editor never manages memory directly — it simply asks StackMemory for the **context bundle**.
86
+
87
+ ---
88
+
89
+ # QuickStart
90
+
91
+ ## 1. Hosted (Recommended)
92
+
93
+ ### Step 1: Create a project
94
+
95
+ ```bash
96
+ stackmemory projects create \
97
+ --repo https://github.com/org/repo
98
+ ```
99
+
100
+ This creates a **project-scoped memory space** tied to the repo.
101
+
102
+ ---
103
+
104
+ ### Step 2: Install MCP client
105
+
106
+ ```bash
107
+ npm install -g stackmemory-mcp
108
+ ```
109
+
110
+ or via binary:
111
+
112
+ ```bash
113
+ curl -fsSL https://stackmemory.dev/install | sh
114
+ ```
115
+
116
+ ---
117
+
118
+ ### Step 3: Configure Claude Code / editor
119
+
120
+ Add StackMemory as an MCP tool:
121
+
122
+ ```json
123
+ {
124
+ "tools": {
125
+ "stackmemory": {
126
+ "command": "stackmemory-mcp",
127
+ "args": ["--project", "github:org/repo"]
128
+ }
129
+ }
130
+ }
131
+ ```
132
+
133
+ That's it.
134
+
135
+ Every message now:
136
+
137
+ 1. Gets logged losslessly
138
+ 2. Updates the call stack
139
+ 3. Retrieves the correct context automatically
140
+
141
+ No prompts to manage. No summaries to babysit.
142
+
143
+ ---
144
+
145
+ ## 2. Open-Source Local Mode
146
+
147
+ ### Step 1: Clone
148
+
149
+ ```bash
150
+ git clone https://github.com/stackmemory/stackmemory
151
+ cd stackmemory
152
+ ```
153
+
154
+ ### Step 2: Run local MCP server
155
+
156
+ ```bash
157
+ cargo run --bin stackmemory-mcp
158
+ # or
159
+ npm run dev
160
+ ```
161
+
162
+ This creates:
163
+
164
+ ```
165
+ .memory/
166
+ └── memory.db # SQLite
167
+ ```
168
+
169
+ All project memory lives locally.
170
+
171
+ ---
172
+
173
+ ### Step 3: Point your editor to local MCP
174
+
175
+ ```json
176
+ {
177
+ "tools": {
178
+ "stackmemory": {
179
+ "command": "stackmemory-mcp",
180
+ "args": ["--local"]
181
+ }
182
+ }
183
+ }
184
+ ```
185
+
186
+ ---
187
+
188
+ ## What happens on each interaction
189
+
190
+ On every message/tool call:
191
+
192
+ 1. **Ingest**
193
+
194
+ * New message delta is appended as events
195
+
196
+ 2. **Index**
197
+
198
+ * Anchors updated
199
+ * Digests generated when frames close
200
+
201
+ 3. **Retrieve**
202
+
203
+ * Active call stack (hot)
204
+ * Relevant digests (warm)
205
+ * Pointers to raw data (cold)
206
+
207
+ 4. **Return context bundle**
208
+
209
+ * Sized to token budget
210
+ * No global compaction
211
+
212
+ ---
213
+
214
+ ## Example MCP response (simplified)
215
+
216
+ ```json
217
+ {
218
+ "hot_stack": [
219
+ { "frame": "Debug auth redirect", "constraints": [...] }
220
+ ],
221
+ "anchors": [
222
+ { "type": "DECISION", "text": "Use SameSite=Lax cookies" }
223
+ ],
224
+ "relevant_digests": [
225
+ { "frame": "Initial auth refactor", "summary": "..." }
226
+ ],
227
+ "pointers": [
228
+ "s3://logs/auth-test-0421"
229
+ ]
230
+ }
231
+ ```
232
+
233
+ ---
234
+
235
+ ## Storage & limits
236
+
237
+ ### Free tier (hosted)
238
+
239
+ * 1 project
240
+ * Up to **X MB stored**
241
+ * Up to **Y MB retrieval egress / month**
242
+
243
+ ### Paid tiers
244
+
245
+ * Per-project pricing
246
+ * Higher storage + retrieval
247
+ * Team sharing
248
+ * Org controls
249
+
250
+ **No seat-based pricing.**
251
+
252
+ ---
253
+
254
+ ## Guarantees
255
+
256
+ * ✅ Lossless storage (no destructive compaction)
257
+ * ✅ Project-scoped isolation
258
+ * ✅ Survives new chat threads
259
+ * ✅ Survives model switching
260
+ * ✅ Inspectable local mirror
261
+
262
+ ---
263
+
264
+ ## Non-goals
265
+
266
+ * ❌ Chat UI
267
+ * ❌ Vector DB replacement
268
+ * ❌ Tool execution runtime
269
+ * ❌ Prompt engineering framework
270
+
271
+ ---
272
+
273
+ ## Philosophy
274
+
275
+ > **Frames instead of transcripts.
276
+ > Return values instead of summaries.
277
+ > Storage separate from context.**
278
+
279
+ ---
280
+
281
+ ## Status
282
+
283
+ * Hosted: **Private beta**
284
+ * OSS mirror: **Early preview**
285
+ * MCP integration: **Stable**
286
+
287
+ ---
288
+
289
+ ## Roadmap (high level)
290
+
291
+ * Team / org projects
292
+ * Cross-repo memory
293
+ * Background project compilers
294
+ * Fine-grained retention policies
295
+ * Editor UX surfacing frame boundaries
296
+
297
+ ---
298
+
299
+ ## License
300
+
301
+ * Hosted service: Proprietary
302
+ * Open-source mirror: Apache 2.0 / MIT (TBD)
303
+
304
+ ---
305
+
306
+ ## Additional Resources
307
+
308
+ ### ML System Design
309
+ - [ML System Insights](./ML_SYSTEM_INSIGHTS.md) - Comprehensive analysis of 300+ production ML systems
310
+ - [Agent Instructions](./AGENTS.md) - Specific guidance for AI agents working with ML systems
311
+
312
+ ### Documentation
313
+ - [Product Requirements](./PRD.md) - Detailed product specifications
314
+ - [Technical Architecture](./TECHNICAL_ARCHITECTURE.md) - System design and database schemas
315
+ - [Beads Integration](./BEADS_INTEGRATION.md) - Git-native memory patterns from Beads ecosystem
316
+
317
+ ---
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Attention-Based Importance Scoring System
3
+ *
4
+ * Tracks which context pieces actually influence AI decisions
5
+ * and adjusts their importance scores based on real usage
6
+ */
7
+ import { EventEmitter } from 'events';
8
+ export declare class AttentionTracker extends EventEmitter {
9
+ private db;
10
+ private currentSession;
11
+ private attentionBuffer;
12
+ constructor(dbPath?: string);
13
+ private initDB;
14
+ private createSession;
15
+ startProvision(query: string): ProvisionBuilder;
16
+ trackProvision(contextItems: ContextItem[], provisionId: string): void;
17
+ trackResponse(provisionId: string, query: string, response: string, actionsTaken?: string[]): string;
18
+ private analyzeAttention;
19
+ private calculateInfluence;
20
+ private updateLearnedImportance;
21
+ private detectPatterns;
22
+ reinforcementUpdate(feedback: UserFeedback): Promise<void>;
23
+ getImportanceScore(contextId: string): number;
24
+ getContextRanking(contextType?: string): ContextRanking[];
25
+ getRecommendedContext(query: string, currentContext: string[]): string[];
26
+ getAttentionHeatmap(sessionId?: string): AttentionHeatmap;
27
+ private generateId;
28
+ private hashContent;
29
+ private estimateTokens;
30
+ private extractKeywords;
31
+ private countMentions;
32
+ private getContextContent;
33
+ private correlateWithActions;
34
+ private calculateSimilarity;
35
+ private evaluateSuccess;
36
+ }
37
+ export declare class ProvisionBuilder {
38
+ private tracker;
39
+ private provisionId;
40
+ private query;
41
+ private contexts;
42
+ constructor(tracker: AttentionTracker, provisionId: string, query: string);
43
+ add(context: ContextItem): this;
44
+ addMany(contexts: ContextItem[]): this;
45
+ execute(handler: (contexts: ContextItem[]) => Promise<string>): Promise<TrackedResponse>;
46
+ }
47
+ export interface ContextItem {
48
+ id: string;
49
+ type: string;
50
+ content: string;
51
+ tokenCount: number;
52
+ importance?: number;
53
+ }
54
+ export interface UserFeedback {
55
+ responseId: string;
56
+ helpful: boolean;
57
+ specific?: string;
58
+ }
59
+ export interface ContextRanking {
60
+ contextId: string;
61
+ type: string;
62
+ importance: number;
63
+ influenceRate: number;
64
+ avgInfluence: number;
65
+ lastUsed: number;
66
+ }
67
+ export interface AttentionHeatmap {
68
+ positions: number[];
69
+ influences: number[];
70
+ contextIds: string[];
71
+ }
72
+ interface TrackedResponse {
73
+ responseId: string;
74
+ response: string;
75
+ latency: number;
76
+ contextsUsed: number;
77
+ }
78
+ export default AttentionTracker;
79
+ //# sourceMappingURL=attention-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attention-tracker.d.ts","sourceRoot":"","sources":["../../../attention-scoring/src/attention-tracker.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAMtC,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,EAAE,CAAoB;IAC9B,OAAO,CAAC,cAAc,CAAiB;IACvC,OAAO,CAAC,eAAe,CAAwB;gBAEnC,MAAM,GAAE,MAAoC;IAWxD,OAAO,CAAC,MAAM;IA4Ed,OAAO,CAAC,aAAa;IASd,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAS/C,cAAc,CACnB,YAAY,EAAE,WAAW,EAAE,EAC3B,WAAW,EAAE,MAAM,GAClB,IAAI;IAmCA,aAAa,CAClB,WAAW,EAAE,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,EAChB,YAAY,CAAC,EAAE,MAAM,EAAE,GACtB,MAAM;IA2BT,OAAO,CAAC,gBAAgB;IA0CxB,OAAO,CAAC,kBAAkB;IAsD1B,OAAO,CAAC,uBAAuB;IA+B/B,OAAO,CAAC,cAAc;IAyCT,mBAAmB,CAAC,QAAQ,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BhE,kBAAkB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAa7C,iBAAiB,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,cAAc,EAAE;IAuBzD,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EA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