Skip to content

Commit 3da3439

Browse files
authored
feat(memory): v1.4.0 Memory System (#9)
* feat(memory): v1.4.0 baseline - memory system with explicit recording - Add 'remember' and 'get_memory' tools for team knowledge capture - Auto-surface memories in search_codebase and get_team_patterns - Migrate storage to .codebase-context/ folder (auto-migrates legacy) - Add startup validation for ROOT_PATH before migration - Centralize constants to prevent path drift - Remove auto-created .gitignore (document recommendation instead) - Delete unused generate-assets scripts Breaking: None (additive only) * Fix lint * Fix security audit
1 parent e7ee82c commit 3da3439

File tree

19 files changed

+995
-258
lines changed

19 files changed

+995
-258
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ node_modules/
22
dist/
33
.codebase-index/
44
.codebase-index.json
5+
.codebase-context/
6+
.codebase/
57
*.log
68
.DS_Store
79
.env

CHANGELOG.md

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,71 @@
11
# Changelog
22

3+
## [Unreleased]
4+
5+
## [1.4.0] - 2026-01-28
6+
7+
### Added
8+
9+
- **Memory System**: New `remember` and `get_memory` tools capture team conventions, decisions, and gotchas
10+
- **Types**: `convention` | `decision` | `gotcha`
11+
- **Categories**: `tooling`, `architecture`, `testing`, `dependencies`, `conventions`
12+
- **Storage**: `.codebase-context/memory.json` with content-based hash IDs (commit this)
13+
- **Safety**: `get_memory` truncates unfiltered results to 20 most recent
14+
- **Integration with `get_team_patterns`**: Appends relevant memories when category overlaps
15+
- **Integration with `search_codebase`**: Surfaces `relatedMemories` via keyword match in search results
16+
17+
### Changed
18+
19+
- **File Structure**: All MCP files now organized in `.codebase-context/` folder for cleaner project root
20+
- Vector DB: `.codebase-index/``.codebase-context/index/`
21+
- Intelligence: `.codebase-intelligence.json``.codebase-context/intelligence.json`
22+
- Keyword index: `.codebase-index.json``.codebase-context/index.json`
23+
- **Migration**: Automatic on server startup (legacy JSON preserved; vector DB directory moved)
24+
25+
### Fixed
26+
27+
- **Startup safety**: Validates `ROOT_PATH` before running migration to avoid creating directories on typo paths
28+
29+
### Why This Feature
30+
31+
Patterns show "what" (97% use inject) but not "why" (standalone compatibility). AGENTS.md can't capture every hard-won lesson. Decision memory gives AI agents access to the team's battle-tested rationale.
32+
33+
**Design principle**: Tool must be self-evident without AGENTS.md rules. "Is this about HOW (record) vs WHAT (don't record)"
34+
35+
**Inspired by**: v1.1 Pattern Momentum (temporal dimension) + memory systems research (Copilot Memory, Gemini Memory)
336

437
## [1.3.3] - 2026-01-18
538

639
### Fixed
40+
741
- **Security**: Resolve `pnpm audit` advisories by updating `hono` to 4.11.4 and removing the vulnerable `diff` transitive dependency (replaced `ts-node` with `tsx` for `pnpm dev`).
842

943
### Changed
44+
1045
- **Docs**: Clarify private `internal-docs/` submodule setup, add `npx --yes` tip, document `CODEBASE_ROOT`, and list `get_indexing_status` tool.
1146
- **Submodule**: Disable automatic updates for `internal-docs` (`update = none`).
1247

1348
### Removed
49+
1450
- **Dev**: Remove local-only `test-context.cjs` helper script.
1551

1652
## [1.3.2] - 2026-01-16
1753

1854
### Changed
55+
1956
- **Embeddings**: Batch embedding now uses a single Transformers.js pipeline call per batch for higher throughput.
2057
- **Dependencies**: Bump `@modelcontextprotocol/sdk` to 1.25.2.
2158

2259
## [1.3.1] - 2026-01-05
2360

2461
### Fixed
62+
2563
- **Auto-Heal Semantic Search**: Detects LanceDB schema corruption (missing `vector` column), triggers re-indexing, and retries search instead of silently falling back to keyword-only results.
2664

2765
## [1.3.0] - 2026-01-01
2866

2967
### Added
68+
3069
- **Workspace Detection**: Monorepo support for Nx, Turborepo, Lerna, and pnpm workspaces
3170
- New utility: `src/utils/workspace-detection.ts`
3271
- Functions: `scanWorkspacePackageJsons()`, `detectWorkspaceType()`, `aggregateWorkspaceDependencies()`
@@ -36,13 +75,16 @@
3675
- **Dependency Detection**: Added `@nx/` and `@nrwl/` prefix matching for build tools
3776

3877
### Fixed
78+
3979
- **detectMetadata() bug**: All registered analyzers now contribute to codebase metadata (previously only the first analyzer was called)
4080
- Added `mergeMetadata()` helper with proper array deduplication and layer merging
4181

4282
### Changed
83+
4384
- Updated roadmap: v1.3 is now "Extensible Architecture Foundation"
4485

4586
### Acknowledgements
87+
4688
Thanks to [@aolin480](https://github.com/aolin480) for accelerating the workspace detection roadmap and identifying the detectMetadata() limitation in their fork.
4789

4890
## 1.2.2 (2025-12-31)
@@ -55,7 +97,6 @@ Thanks to [@aolin480](https://github.com/aolin480) for accelerating the workspac
5597

5698
## 1.2.1 (2025-12-31)
5799

58-
59100
### Fixed
60101

61102
- **MCP Protocol Compatibility**: Fixed stderr output during MCP STDIO handshake for strict clients

README.md

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,54 +28,107 @@ If your environment prompts on first run, use `npx --yes ...` (or `npx -y ...`)
2828
- **Testing conventions**`Jest`: 74%, `Playwright`: 6%
2929
- **Framework patterns** → Angular signals, standalone components, etc.
3030
- **Circular dependency detection** → Find toxic import cycles between files
31-
31+
- **Memory system** → Record "why" behind choices so AI doesn't repeat mistakes
3232

3333
## How It Works
3434

3535
When generating code, the agent checks your patterns first:
3636

37-
| Without MCP | With MCP |
38-
|-------------|----------|
39-
| Uses `constructor(private svc: Service)` | Uses `inject()` (97% team adoption) |
40-
| Suggests `primeng/button` directly | Uses `@mycompany/ui-toolkit` wrapper |
41-
| Generic Jest setup | Your team's actual test utilities |
37+
| Without MCP | With MCP |
38+
| ---------------------------------------- | ------------------------------------ |
39+
| Uses `constructor(private svc: Service)` | Uses `inject()` (97% team adoption) |
40+
| Suggests `primeng/button` directly | Uses `@mycompany/ui-toolkit` wrapper |
41+
| Generic Jest setup | Your team's actual test utilities |
4242

4343
### Tip: Auto-invoke in your rules
4444

4545
Add this to your `.cursorrules`, `CLAUDE.md`, or `AGENTS.md`:
4646

4747
```
48-
When generating or reviewing code, use codebase-context tools to check team patterns first.
48+
## Codebase Context
49+
50+
**At start of each task:** Call `get_memory` to load team conventions.
51+
52+
**CRITICAL:** When user says "remember this" or "record this":
53+
- STOP immediately and call `remember` tool FIRST
54+
- DO NOT proceed with other actions until memory is recorded
55+
- This is a blocking requirement, not optional
4956
```
5057

5158
Now the agent checks patterns automatically instead of waiting for you to ask.
5259

5360
## Tools
5461

55-
| Tool | Purpose |
56-
|------|---------|
57-
| `search_codebase` | Semantic + keyword hybrid search |
58-
| `get_component_usage` | Find where a library/component is used |
59-
| `get_team_patterns` | Pattern frequencies + canonical examples |
60-
| `get_codebase_metadata` | Project structure overview |
61-
| `get_indexing_status` | Indexing progress + last stats |
62-
| `get_style_guide` | Query style guide rules |
63-
| `detect_circular_dependencies` | Find import cycles between files |
64-
| `refresh_index` | Re-index the codebase |
62+
| Tool | Purpose |
63+
| ------------------------------ | --------------------------------------------- |
64+
| `search_codebase` | Semantic + keyword hybrid search |
65+
| `get_component_usage` | Find where a library/component is used |
66+
| `get_team_patterns` | Pattern frequencies + canonical examples |
67+
| `get_codebase_metadata` | Project structure overview |
68+
| `get_indexing_status` | Indexing progress + last stats |
69+
| `get_style_guide` | Query style guide rules |
70+
| `detect_circular_dependencies` | Find import cycles between files |
71+
| `remember` | Record memory (conventions/decisions/gotchas) |
72+
| `get_memory` | Query recorded memory by category/keyword |
73+
| `refresh_index` | Re-index the codebase |
74+
75+
## File Structure
76+
77+
The MCP creates the following structure in your project:
78+
79+
```
80+
.codebase-context/
81+
├── memory.json # Team knowledge (commit this)
82+
├── intelligence.json # Pattern analysis (generated)
83+
├── index.json # Keyword index (generated)
84+
└── index/ # Vector database (generated)
85+
```
86+
87+
**Recommended `.gitignore`:** The vector database and generated files can be large. Add this to your `.gitignore` to keep them local while sharing team memory:
6588

89+
```gitignore
90+
# Codebase Context MCP - ignore generated files, keep memory
91+
.codebase-context/*
92+
!.codebase-context/memory.json
93+
```
94+
95+
### Memory System
96+
97+
Patterns tell you _what_ the team does ("97% use inject"), but not _why_ ("standalone compatibility"). Use `remember` to capture rationale that prevents repeated mistakes:
98+
99+
```typescript
100+
// AI won't change this again after recording the decision
101+
remember({
102+
type: 'decision',
103+
category: 'dependencies',
104+
memory: 'Use node-linker: hoisted, not isolated',
105+
reason:
106+
"Some packages don't declare transitive deps. Isolated forces manual package.json additions."
107+
});
108+
```
109+
110+
Memories surface automatically in `search_codebase` results and `get_team_patterns` responses.
111+
112+
**Early baseline — known quirks:**
113+
114+
- Agents may bundle multiple things into one entry
115+
- Duplicates can happen if you record the same thing twice
116+
- Edit `.codebase-context/memory.json` directly to clean up
117+
- Be explicit: "Remember this: use X not Y"
66118

67119
## Configuration
68120

69-
| Variable | Default | Description |
70-
|----------|---------|-------------|
71-
| `EMBEDDING_PROVIDER` | `transformers` | `openai` (fast, cloud) or `transformers` (local, private) |
72-
| `OPENAI_API_KEY` | - | Required if provider is `openai` |
73-
| `CODEBASE_ROOT` | - | Project root to index (CLI arg takes precedence) |
74-
| `CODEBASE_CONTEXT_DEBUG` | - | Set to `1` to enable verbose logging (startup messages, analyzer registration) |
121+
| Variable | Default | Description |
122+
| ------------------------ | -------------- | ------------------------------------------------------------------------------ |
123+
| `EMBEDDING_PROVIDER` | `transformers` | `openai` (fast, cloud) or `transformers` (local, private) |
124+
| `OPENAI_API_KEY` | - | Required if provider is `openai` |
125+
| `CODEBASE_ROOT` | - | Project root to index (CLI arg takes precedence) |
126+
| `CODEBASE_CONTEXT_DEBUG` | - | Set to `1` to enable verbose logging (startup messages, analyzer registration) |
75127

76128
## Performance Note
77129

78130
This tool runs **locally** on your machine using your hardware.
131+
79132
- **Initial Indexing**: The first run works hard. It may take several minutes (e.g., ~2-5 mins for 30k files) to compute embeddings for your entire codebase.
80133
- **Caching**: Subsequent queries are instant (milliseconds).
81134
- **Updates**: Currently, `refresh_index` re-scans the codebase. True incremental indexing (processing only changed files) is on the roadmap.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codebase-context",
3-
"version": "1.3.3",
3+
"version": "1.4.0",
44
"description": "MCP server that helps AI agents understand your codebase - patterns, libraries, architecture, monorepo support",
55
"type": "module",
66
"main": "./dist/lib.js",
@@ -92,7 +92,7 @@
9292
"@xenova/transformers": "^2.17.0",
9393
"fuse.js": "^7.0.0",
9494
"glob": "^10.3.10",
95-
"hono": "4.11.4",
95+
"hono": "4.11.7",
9696
"ignore": "^5.3.1",
9797
"typescript": "^5.3.3",
9898
"uuid": "^9.0.1",

pnpm-lock.yaml

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)