@stackmemoryai/stackmemory 1.2.1 → 1.2.2

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 (39) hide show
  1. package/dist/src/cli/commands/skills.js +123 -1
  2. package/dist/src/hooks/graphiti-hooks.js +149 -0
  3. package/dist/src/hooks/session-summary.js +30 -0
  4. package/dist/src/integrations/graphiti/linear-graphiti-bridge.js +115 -0
  5. package/dist/src/integrations/greptile/client.js +101 -0
  6. package/dist/src/integrations/greptile/config.js +14 -0
  7. package/dist/src/integrations/greptile/index.js +11 -0
  8. package/dist/src/integrations/greptile/types.js +4 -0
  9. package/dist/src/integrations/linear/webhook.js +16 -0
  10. package/dist/src/integrations/mcp/handlers/greptile-handlers.js +456 -0
  11. package/dist/src/integrations/mcp/server.js +27 -0
  12. package/dist/src/skills/claude-skills.js +46 -1
  13. package/dist/src/skills/parallel-agent-skill.js +514 -0
  14. package/package.json +1 -1
  15. package/scripts/gepa/.before-optimize.md +140 -159
  16. package/scripts/gepa/config.json +7 -1
  17. package/scripts/gepa/evals/fixtures/api-endpoint.ts +31 -0
  18. package/scripts/gepa/evals/fixtures/brittle-integration.ts +38 -0
  19. package/scripts/gepa/evals/fixtures/fts5-triggers.sql +23 -0
  20. package/scripts/gepa/evals/fixtures/leaky-service.ts +70 -0
  21. package/scripts/gepa/evals/fixtures/mcp-dispatch-stub.ts +39 -0
  22. package/scripts/gepa/evals/fixtures/pr-diff.txt +24 -0
  23. package/scripts/gepa/evals/fixtures/unsafe-webhook.ts +34 -0
  24. package/scripts/gepa/evals/fixtures/unwrapped-db-op.ts +42 -0
  25. package/scripts/gepa/evals/stackmemory-tasks.jsonl +8 -0
  26. package/scripts/gepa/generations/gen-000/baseline.md +172 -159
  27. package/scripts/gepa/generations/gen-001/baseline.md +172 -159
  28. package/scripts/gepa/generations/gen-001/variant-a.md +156 -146
  29. package/scripts/gepa/generations/gen-001/variant-b.md +199 -170
  30. package/scripts/gepa/generations/gen-001/variant-c.md +127 -46
  31. package/scripts/gepa/generations/gen-001/variant-d.md +160 -107
  32. package/scripts/gepa/hooks/reflect.js +44 -5
  33. package/scripts/gepa/optimize.js +281 -39
  34. package/scripts/gepa/results/eval-1-baseline.json +187 -10
  35. package/scripts/gepa/results/eval-1-variant-a.json +188 -11
  36. package/scripts/gepa/results/eval-1-variant-b.json +188 -11
  37. package/scripts/gepa/results/eval-1-variant-c.json +168 -11
  38. package/scripts/gepa/results/eval-1-variant-d.json +169 -12
  39. package/scripts/gepa/state.json +18 -18
@@ -1,166 +1,176 @@
1
- # ProvenantAI
1
+ # StackMemory - Project Configuration
2
+
3
+ ## Project Structure
2
4
 
3
- ## Reference Docs
4
5
  ```
5
- AGENTS.md # TDD workflow, checklists, guardrails
6
- PROMPT_PLAN.md # 20 implementation prompts
7
- docs/STYLE.md # Design system (Hatchet + Outliner)
8
- docs/business/ONE_PAGER.md # Executive summary
9
- DEV_SPEC.md # Developer spec
10
- docs/reference/PROJECT.md # Quick reference
11
- docs/business/VISION.md # Product vision + self-learning + model router
12
- docs/architecture/SYSTEM_INTEGRATION.md # System connections (events, flows)
13
- docs/architecture/HEARTBEAT_DESIGN.md # Task health + recovery
14
- docs/nudge-engine-design.md # Proactive scanner alerts
15
- docs/architecture/WEBHOOK_SYSTEM_DESIGN.md # External event publishing
16
- docs/VALUES.md # Company values
6
+ src/
7
+ cli/ # CLI commands and entry point
8
+ core/ # Core business logic
9
+ context/ # Frame and context management
10
+ database/ # Database adapters (SQLite, ParadeDB)
11
+ digest/ # Digest generation
12
+ query/ # Query parsing and routing
13
+ integrations/ # External integrations (Linear, MCP)
14
+ services/ # Business services
15
+ skills/ # Claude Code skills
16
+ utils/ # Shared utilities
17
+ scripts/ # Build and utility scripts
18
+ config/ # Configuration files
19
+ docs/ # Documentation
17
20
  ```
18
21
 
22
+ ## Key Files
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
44
+
19
45
  ## Commands
46
+
20
47
  ```bash
21
- npm run dev|test|lint|migrate # Development tasks
22
- docker-compose up -d # Start local DBs
23
- railway up # Deploy to Railway
48
+ npm run build # Compile TypeScript (esbuild)
49
+ npm run lint # ESLint check
50
+ npm run lint:fix # Auto-fix lint issues
51
+ npm test # Run Vitest (watch)
52
+ npm run test:run # Run tests once
53
+ npm run linear:sync # Sync with Linear
54
+
55
+ # StackMemory CLI
56
+ stackmemory capture # Save session state for handoff
57
+ stackmemory restore # Restore from captured state
24
58
  ```
25
59
 
26
- ## Stack
27
- Node.js + Express + PostgreSQL + Redis | Railway | Stripe + Salesforce + QuickBooks
60
+ ## Working Directory
28
61
 
29
- ## Core Services (src/core/)
30
- monitoring-service | cache-service | queue-service | master-agent | api-validation
62
+ - PRIMARY: /Users/jwu/Dev/stackmemory
63
+ - ALLOWED: All subdirectories
64
+ - TEMP: /tmp for temporary operations
31
65
 
32
- ## Directory Structure
33
- ```
34
- src/
35
- api/ core/ features/ shared/ integrations/
36
- docs/ scripts/ docker/
37
- ```
66
+ ## Required Validation
38
67
 
39
- ## Git Workflow
40
- - **NEVER add Co-Authored-By lines** to commits
41
- - Pre-commit: runs lint + test suite
42
- - Commit format: `type(scope): message`
43
- - Deploy: `railway up --detach`
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
44
73
 
45
- ## Architecture
46
- - **Provenance tracking**: every data point includes source + timestamp + lineage
47
- - **Multi-tenant**: container isolation per org
48
- - **Investigation replays**: stored in `data/investigation-replays/`
49
- - **StackMemory**: session/entity context layer (repurpose when KG lands)
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
50
78
 
51
- ## Key Implementation Files
52
- ```
53
- src/graph/client.ts # MCP client for Graphiti
54
- src/graph/service.ts # Graph ingest + enrich + search
55
- src/llm/adapter.js # LLM streaming + SYSTEM_PROMPT
56
- src/routes/query.js # Query endpoint + KG enrichment
57
- src/auth/auth.middleware.js # Clerk + API key + test mode
58
- src/nudge/rule-engine.js # 13 default rules + CRUD + eval
59
- src/nudge/nudge-engine.js # Lifecycle + state machine + events
60
- src/nudge/delivery.js # Slack Block Kit + delivery
61
- src/integrations/slack/app.js # OAuth v2 + token management
62
- scripts/create-stripe-products.js # Stripe product creation
63
- scripts/seed-demo-data.js # Demo nudge data
64
- dashboard-app/src/pages/pricing/ # 4-tier pricing UI
65
- ```
79
+ Do NOT: assume success | skip testing | use mock data as fallback
66
80
 
67
- ## Current State
68
- - **20 prompts complete** (PROMPT_PLAN.md)
69
- - **80 test suites, 1547 tests** - all passing (37 unit, 30 core, 13 integrations)
70
- - **KG integrated** - commit 917f31e (FalkorDB + Graphiti MCP)
71
- - **Published**: @provenantai/cli@1.0.0
72
- - **Deployed**: Railway (health OK, DB connected)
73
- - **Bundle**: 236KB main + 346KB vendor (lazy routes)
74
- - **Pricing**: Free | Growth $999-1499 | Scale $2999-4499 | Enterprise custom
75
- - **Slack**: wired in index.js (conditional on SLACK_CLIENT_ID)
76
- - **Dashboard**: SlackSettings + Nudges page + E2E smoke tests
77
-
78
- ## Knowledge Graph
79
- - **FalkorDB**: `falkordb/falkordb:latest` port 6380 (Redis-compatible)
80
- - **Graphiti**: `zepai/knowledge-graph-mcp:standalone` port 8100
81
- - **Protocol**: MCP Streamable HTTP (JSON-RPC + SSE) - NOT REST
82
- - **Ingestion**: fire-and-forget via `add_memory`, extraction runs in background
83
- - **Config**: `config/graphiti-falkordb.yaml` - Claude Haiku for LLM
84
- - **Performance**: 34ms avg, $0.00056/event
85
- - **Query integration**: GraphService.enrichRetrieval() when GRAPHITI_URL set
86
- - **Graph context**: prepended as first context_document, graceful fallback
87
-
88
- ## Stripe Products (LIVE)
89
- ```
90
- Growth: prod_TyNYCJmlKbMdlz
91
- Monthly $1,499: price_1T0Qn8BjaxUVbh5VjC7BP0cS
92
- Quarterly $2,997: price_1T0Qn9BjaxUVbh5VYmugdPrF
93
- Scale: prod_TyNY5SGKvVlbpo
94
- Monthly $4,499: price_1T0Qn9BjaxUVbh5ViK6vRmgn
95
- Quarterly $8,997: price_1T0Qn9BjaxUVbh5V1mBcTAJ0
81
+ ## Git Rules (CRITICAL)
82
+
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`
93
+
94
+ ## Task Management
95
+
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
99
+
100
+ ## Security
101
+
102
+ NEVER hardcode secrets. Use process.env with dotenv/config:
103
+
104
+ ```javascript
105
+ import 'dotenv/config';
106
+ const API_KEY = process.env.LINEAR_API_KEY;
107
+ if (!API_KEY) {
108
+ console.error('LINEAR_API_KEY not set');
109
+ process.exit(1);
110
+ }
96
111
  ```
97
- Price IDs in `.env` + `dashboard-app/.env` (VITE_STRIPE_PRICE_*)
98
-
99
- ## Clerk Auth
100
- - **Current**: test keys (pk_test_*, sk_test_*)
101
- - **Production setup**: `bash scripts/setup-clerk-production.sh`
102
- - **Webhook**: /api/webhooks/clerk (Svix verification required in prod)
103
- - **Status**: code production-ready, test mode blocked in production
104
-
105
- ## Dashboard
106
- - **Chat**: `/api/v1/query` with SSE streaming
107
- - **Sidebar**: toggleable, time-grouped, backend persistence
108
- - **localStorage**: `provenantai:conversationId`, `sidebarOpen`, `onboarded`
109
- - **Vite**: `base: '/app/'` + BrowserRouter `basename="/app"`
110
- - **Dev auth**: `X-Test-Mode: true` bypasses Clerk
111
- - **Express**: `node src/index.js` on PORT=8080 (3000 = Rails)
112
- - **Build**: `bash -c 'cd dashboard-app && npx vite build'`
113
-
114
- ## Slack Integration
115
- - **OAuth flow**: GET /api/integrations/slack/install → consent → callback
116
- - **DB**: `slack_installations` table (migration 030) - per-org bot tokens
117
- - **Service**: `src/integrations/slack/app.js` - createSlackAppService
118
- - **Delivery**: `src/nudge/delivery.js` - nudge:created listener, Block Kit formatter
119
- - **Routes**: install, callback, status, channel config, revoke
120
- - **Env**: SLACK_CLIENT_ID, SLACK_CLIENT_SECRET, SLACK_REDIRECT_URI
121
- - **Demo data**: `node scripts/seed-demo-data.js` (10 nudges)
122
-
123
- ## Architecture Patterns
124
- - **DI**: all route factories accept `deps` objects
125
- - **Mocks**: MockPineconeAdapter, MockGmailConnectorClient, stub embeddings
126
- - **Queues**: Bull (not BullMQ)
127
- - **KMS**: AES-256-GCM shim via LOCAL_KMS_KEY
128
- - **Streaming**: adapter.streamLLM() → query/stream → ReadableStream
129
- - **Graph**: optional graphService dep, null when GRAPHITI_URL unset
130
-
131
- ## Testing
132
- - **Framework**: Jest + SWC (`@swc/jest`), `@jest/globals` imports
133
- - **Mocks**: `mockDb = { query: jest.fn() }` via DI
134
- - **Fetch**: `global.fetch = mockFetch` + `jsonResponse()` helper
135
- - **Pre-commit**: lint + parallel test suite via concurrently
136
- - **Timeout guard**: Promise.race + .unref() timer in test/setup.js
137
- - **Supertest**: pass Express app directly (NOT server) - avoids port contention
138
- - **Redis**: skip eager connect in NODE_ENV=test; disconnect in afterAll
139
-
140
- ### Parallel Test Execution
112
+
113
+ Environment sources (check in order):
114
+ 1. .env file
115
+ 2. .env.local
116
+ 3. ~/.zshrc
117
+ 4. Process environment
118
+
119
+ Block secret patterns: lin_api_* | lin_oauth_* | sk-* | npm_*
120
+
121
+ ## Deploy
122
+
141
123
  ```bash
142
- npm test # 3 parallel processes (~9s vs 18s)
143
- test:unit (37 suites, 615 tests) # test/ dir
144
- test:core (30 suites, 643 tests) # src/(api|auth|billing|core|...)
145
- test:integrations (13 suites, 289 tests) # src/integrations/
146
- test:all (single-process, 4 workers) # fallback
147
- ```
148
- **After code changes**: run targeted sub-suite in background via Bash `run_in_background`
124
+ # npm publish (uses NPM_TOKEN from .env, no OTP needed)
125
+ git stash -- scripts/gepa/ # stash GEPA state (dirties working tree)
126
+ NPM_TOKEN=$(grep '^NPM_TOKEN=' .env | cut -d= -f2) \
127
+ npm publish --registry https://registry.npmjs.org/ \
128
+ --//registry.npmjs.org/:_authToken="$NPM_TOKEN"
129
+ git stash pop # restore GEPA state
149
130
 
150
- ## GTM Content
151
- ```
152
- docs/content/linkedin-pillar1-drafts.md # 5 problem posts (ready)
153
- docs/content/gtm-launch-materials.md # Schedule + Loom + outreach
154
- docs/business/CONTENT_INBOUND_STRATEGY.md # Content/inbound playbook
155
- docs/business/FRACTIONAL_CMO_AGENT.md # CMO Agent product brief
131
+ # Railway
132
+ railway up
133
+
134
+ # Pre-publish checks require clean git status — stash GEPA files first
156
135
  ```
157
136
 
158
- ## Next Actions
159
- 1. Commit: SlackSettings, Nudges polish, smoke tests
160
- 2. Clerk: swap to production keys (requires Clerk dashboard action)
161
- 3. Slack: create app at api.slack.com, run migration 030
162
- 4. Content: schedule posts in Typefully, record Loom demo
163
- 5. Design partners: outreach to 3-5 ICP companies
164
- 6. Attribution: add Google Ads + Meta connectors
137
+ ## Task Delegation Model
138
+
139
+ Match effort to complexity:
140
+
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)
145
+
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)
150
+
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
156
+
157
+ **ARCHITECT** — Plan mode required, explore patterns first:
158
+ - New service boundaries, system integrations
159
+ - Performance-critical paths (FTS5 queries, search scoring)
160
+ - Breaking changes to MCP protocol or CLI interface
161
+
162
+ **HUMAN** — Explicit user approval required:
163
+ - Security-critical decisions, secret handling
164
+ - 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.
168
+
169
+ ## Workflow
165
170
 
166
- <!-- Sync docs/reference/PROJECT.md when verbose docs change -->
171
+ - Check .env for API keys before asking user
172
+ - Run `npm run linear:sync` after task completion
173
+ - Use browser MCP for visual testing
174
+ - Review recent commits and stackmemory.json at session start
175
+ - Use subagents for multi-step tasks
176
+ - Ask 1-3 clarifying questions for complex commands (one at a time)