agent-knowledge 1.0.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.
- package/CHANGELOG.md +77 -0
- package/LICENSE +21 -0
- package/README.md +191 -0
- package/dist/dashboard.d.ts +4 -0
- package/dist/dashboard.d.ts.map +1 -0
- package/dist/dashboard.js +434 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/embeddings/claude.d.ts +21 -0
- package/dist/embeddings/claude.d.ts.map +1 -0
- package/dist/embeddings/claude.js +84 -0
- package/dist/embeddings/claude.js.map +1 -0
- package/dist/embeddings/factory.d.ts +9 -0
- package/dist/embeddings/factory.d.ts.map +1 -0
- package/dist/embeddings/factory.js +60 -0
- package/dist/embeddings/factory.js.map +1 -0
- package/dist/embeddings/gemini.d.ts +21 -0
- package/dist/embeddings/gemini.d.ts.map +1 -0
- package/dist/embeddings/gemini.js +86 -0
- package/dist/embeddings/gemini.js.map +1 -0
- package/dist/embeddings/index.d.ts +4 -0
- package/dist/embeddings/index.d.ts.map +1 -0
- package/dist/embeddings/index.js +3 -0
- package/dist/embeddings/index.js.map +1 -0
- package/dist/embeddings/local.d.ts +20 -0
- package/dist/embeddings/local.d.ts.map +1 -0
- package/dist/embeddings/local.js +73 -0
- package/dist/embeddings/local.js.map +1 -0
- package/dist/embeddings/openai.d.ts +20 -0
- package/dist/embeddings/openai.d.ts.map +1 -0
- package/dist/embeddings/openai.js +84 -0
- package/dist/embeddings/openai.js.map +1 -0
- package/dist/embeddings/types.d.ts +39 -0
- package/dist/embeddings/types.d.ts.map +1 -0
- package/dist/embeddings/types.js +12 -0
- package/dist/embeddings/types.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/distill.d.ts +27 -0
- package/dist/knowledge/distill.d.ts.map +1 -0
- package/dist/knowledge/distill.js +407 -0
- package/dist/knowledge/distill.js.map +1 -0
- package/dist/knowledge/git.d.ts +30 -0
- package/dist/knowledge/git.d.ts.map +1 -0
- package/dist/knowledge/git.js +228 -0
- package/dist/knowledge/git.js.map +1 -0
- package/dist/knowledge/search.d.ts +20 -0
- package/dist/knowledge/search.d.ts.map +1 -0
- package/dist/knowledge/search.js +72 -0
- package/dist/knowledge/search.js.map +1 -0
- package/dist/knowledge/store.d.ts +47 -0
- package/dist/knowledge/store.d.ts.map +1 -0
- package/dist/knowledge/store.js +173 -0
- package/dist/knowledge/store.js.map +1 -0
- package/dist/search/excerpt.d.ts +12 -0
- package/dist/search/excerpt.d.ts.map +1 -0
- package/dist/search/excerpt.js +28 -0
- package/dist/search/excerpt.js.map +1 -0
- package/dist/search/fuzzy.d.ts +15 -0
- package/dist/search/fuzzy.d.ts.map +1 -0
- package/dist/search/fuzzy.js +81 -0
- package/dist/search/fuzzy.js.map +1 -0
- package/dist/search/tfidf.d.ts +19 -0
- package/dist/search/tfidf.d.ts.map +1 -0
- package/dist/search/tfidf.js +200 -0
- package/dist/search/tfidf.js.map +1 -0
- package/dist/search/types.d.ts +19 -0
- package/dist/search/types.d.ts.map +1 -0
- package/dist/search/types.js +2 -0
- package/dist/search/types.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +518 -0
- package/dist/server.js.map +1 -0
- package/dist/sessions/indexer.d.ts +15 -0
- package/dist/sessions/indexer.d.ts.map +1 -0
- package/dist/sessions/indexer.js +182 -0
- package/dist/sessions/indexer.js.map +1 -0
- package/dist/sessions/parser.d.ts +58 -0
- package/dist/sessions/parser.d.ts.map +1 -0
- package/dist/sessions/parser.js +142 -0
- package/dist/sessions/parser.js.map +1 -0
- package/dist/sessions/scopes.d.ts +16 -0
- package/dist/sessions/scopes.d.ts.map +1 -0
- package/dist/sessions/scopes.js +153 -0
- package/dist/sessions/scopes.js.map +1 -0
- package/dist/sessions/search.d.ts +26 -0
- package/dist/sessions/search.d.ts.map +1 -0
- package/dist/sessions/search.js +256 -0
- package/dist/sessions/search.js.map +1 -0
- package/dist/sessions/summary.d.ts +28 -0
- package/dist/sessions/summary.d.ts.map +1 -0
- package/dist/sessions/summary.js +135 -0
- package/dist/sessions/summary.js.map +1 -0
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +109 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/app.js +1029 -0
- package/dist/ui/index.html +373 -0
- package/dist/ui/styles.css +1508 -0
- package/dist/ui/ui/app.js +811 -0
- package/dist/ui/ui/index.html +300 -0
- package/dist/ui/ui/styles.css +1154 -0
- package/dist/validate.d.ts +21 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +86 -0
- package/dist/validate.js.map +1 -0
- package/dist/vectorstore/chunker.d.ts +48 -0
- package/dist/vectorstore/chunker.d.ts.map +1 -0
- package/dist/vectorstore/chunker.js +165 -0
- package/dist/vectorstore/chunker.js.map +1 -0
- package/dist/vectorstore/index.d.ts +5 -0
- package/dist/vectorstore/index.d.ts.map +1 -0
- package/dist/vectorstore/index.js +3 -0
- package/dist/vectorstore/index.js.map +1 -0
- package/dist/vectorstore/store.d.ts +139 -0
- package/dist/vectorstore/store.d.ts.map +1 -0
- package/dist/vectorstore/store.js +500 -0
- package/dist/vectorstore/store.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +2 -0
- package/dist/version.js.map +1 -0
- package/docs/ARCHITECTURE.md +244 -0
- package/docs/DASHBOARD.md +133 -0
- package/docs/SETUP.md +178 -0
- package/package.json +92 -0
- package/scripts/copy-ui.js +6 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
# Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
```mermaid
|
|
6
|
+
graph TB
|
|
7
|
+
Claude[Claude Code] -->|MCP stdio| Server[server.ts]
|
|
8
|
+
Server --> Knowledge[Knowledge Module]
|
|
9
|
+
Server --> Session[Session Module]
|
|
10
|
+
|
|
11
|
+
Knowledge --> Store[store.ts — CRUD]
|
|
12
|
+
Knowledge --> KSearch[search.ts — TF-IDF]
|
|
13
|
+
Knowledge --> Git[git.ts — Sync]
|
|
14
|
+
|
|
15
|
+
Store --> Vault[(~/claude-memory)]
|
|
16
|
+
Git --> Remote[(Git Remote)]
|
|
17
|
+
|
|
18
|
+
Session --> Parser[parser.ts — JSONL + Cache]
|
|
19
|
+
Session --> SSearch[search.ts — TF-IDF Index]
|
|
20
|
+
Session --> Scopes[scopes.ts — 6 Filters]
|
|
21
|
+
Session --> Summary[summary.ts]
|
|
22
|
+
|
|
23
|
+
Parser --> Transcripts[(~/.claude/projects/*.jsonl)]
|
|
24
|
+
|
|
25
|
+
Server --> Dashboard[dashboard.ts — :3423]
|
|
26
|
+
Dashboard --> HTTP[REST API]
|
|
27
|
+
Dashboard --> WS[WebSocket]
|
|
28
|
+
Dashboard --> Watcher[File Watcher]
|
|
29
|
+
HTTP --> Browser[Browser UI]
|
|
30
|
+
WS --> Browser
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## File Structure
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
src/
|
|
37
|
+
index.ts Entry point — MCP stdio + dashboard auto-start
|
|
38
|
+
server.ts 10 tool definitions, request routing, error handling
|
|
39
|
+
dashboard.ts HTTP + WebSocket server, REST API, file watcher
|
|
40
|
+
types.ts KnowledgeConfig interface, getConfig()
|
|
41
|
+
knowledge/
|
|
42
|
+
store.ts CRUD for markdown entries with YAML frontmatter
|
|
43
|
+
search.ts TF-IDF search over knowledge entries
|
|
44
|
+
git.ts git pull/push/sync with execSync + timeouts
|
|
45
|
+
sessions/
|
|
46
|
+
parser.ts JSONL parsing with mtime-based file cache
|
|
47
|
+
search.ts TF-IDF ranked search with 60s global index cache
|
|
48
|
+
scopes.ts 6 search scopes, post-filters cached index results
|
|
49
|
+
summary.ts Topic extraction, tool/file detection
|
|
50
|
+
search/
|
|
51
|
+
tfidf.ts TF-IDF scoring engine (tokenizer, stopwords, index)
|
|
52
|
+
fuzzy.ts Levenshtein distance, sliding window matching
|
|
53
|
+
types.ts SearchResult, SearchOptions interfaces
|
|
54
|
+
ui/
|
|
55
|
+
index.html Dashboard SPA
|
|
56
|
+
styles.css MD3 design tokens (light + dark)
|
|
57
|
+
app.js Client-side JS (WebSocket, tabs, rendering)
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Knowledge Module
|
|
61
|
+
|
|
62
|
+
### store.ts
|
|
63
|
+
|
|
64
|
+
CRUD for markdown files with YAML frontmatter:
|
|
65
|
+
|
|
66
|
+
- **parseFrontmatter()** — splits on `---` delimiters, extracts title/tags/updated
|
|
67
|
+
- **listEntries()** — recursively finds `.md` files, skips dot-directories, filters by category/tag
|
|
68
|
+
- **readEntry()** — reads file with path traversal protection (`path.resolve` must start with base dir)
|
|
69
|
+
- **writeEntry()** — validates category against allowed list, ensures directory exists, auto-adds `.md`
|
|
70
|
+
- **deleteEntry()** — removes file with path traversal protection
|
|
71
|
+
|
|
72
|
+
### git.ts
|
|
73
|
+
|
|
74
|
+
Wraps `execSync` for git operations with timeouts:
|
|
75
|
+
|
|
76
|
+
- `gitPull()` — `git pull --rebase --quiet` (15s timeout)
|
|
77
|
+
- `gitPush()` — `git add -A`, conditional commit (checks `git diff --cached --quiet`), push (5s/5s/15s)
|
|
78
|
+
- `gitSync()` — pull then push, returns both results
|
|
79
|
+
|
|
80
|
+
### search.ts
|
|
81
|
+
|
|
82
|
+
Builds a TF-IDF index from all knowledge entries, searches with ranking, falls back to regex for exact phrases.
|
|
83
|
+
|
|
84
|
+
## Session Module
|
|
85
|
+
|
|
86
|
+
### parser.ts — Mtime Cache
|
|
87
|
+
|
|
88
|
+
Before parsing a JSONL file, checks `fs.statSync` for mtime. If unchanged since last parse, returns cached result. This avoids re-parsing large transcript files on every search.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
parseSessionFile(path)
|
|
92
|
+
→ statSync(path).mtimeMs
|
|
93
|
+
→ if mtime matches cache → return cached entries
|
|
94
|
+
→ else parse JSONL lines → cache with mtime → return
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### search.ts — Global TF-IDF Index
|
|
98
|
+
|
|
99
|
+
Maintains a single TF-IDF index across all sessions with a 60-second TTL:
|
|
100
|
+
|
|
101
|
+
```
|
|
102
|
+
getOrBuildIndex(projects)
|
|
103
|
+
→ if cache exists AND age < 60s → return cached index
|
|
104
|
+
→ else scan all sessions → parse (using mtime cache) → index all messages → cache → return
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Role filtering happens post-search: the index includes all roles, and results are filtered after scoring.
|
|
108
|
+
|
|
109
|
+
### scopes.ts
|
|
110
|
+
|
|
111
|
+
Uses the cached search index from `search.ts` (via `searchSessions`), then post-filters by scope patterns:
|
|
112
|
+
|
|
113
|
+
| Scope | Filter |
|
|
114
|
+
| ----------- | --------------------------------------------------------------- |
|
|
115
|
+
| `errors` | Regex: Error, Exception, failed, crash, ENOENT, TypeError, etc. |
|
|
116
|
+
| `plans` | Regex: plan, step, phase, strategy, TODO, architecture, etc. |
|
|
117
|
+
| `configs` | Regex: config, .env, .json, tsconfig, docker, etc. |
|
|
118
|
+
| `tools` | Role filter: tool_use, tool_result messages only |
|
|
119
|
+
| `files` | Regex: src/, .ts, .js, created, modified, deleted, etc. |
|
|
120
|
+
| `decisions` | Regex: decided, chose, because, tradeoff, opted for, etc. |
|
|
121
|
+
|
|
122
|
+
### summary.ts
|
|
123
|
+
|
|
124
|
+
Extracts session summaries:
|
|
125
|
+
|
|
126
|
+
- **Topics**: user messages filtered to exclude JSON/tool_result/base64/system-reminders
|
|
127
|
+
- **Tools used**: tool names from tool_use entries
|
|
128
|
+
- **Files modified**: file paths detected via regex in tool_result content
|
|
129
|
+
|
|
130
|
+
## Search Engine
|
|
131
|
+
|
|
132
|
+
### tfidf.ts
|
|
133
|
+
|
|
134
|
+
Self-contained TF-IDF implementation:
|
|
135
|
+
|
|
136
|
+
**Tokenization**: lowercase → split on `[^a-z0-9]+` → remove ~100 English stopwords
|
|
137
|
+
|
|
138
|
+
**Scoring**:
|
|
139
|
+
|
|
140
|
+
```
|
|
141
|
+
TF(t, d) = count(t in d) / total_terms(d)
|
|
142
|
+
IDF(t) = log(1 + N / docs_containing(t))
|
|
143
|
+
Score(q, d) = sum(TF(t, d) * IDF(t)) for each term t in query q
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The `1 +` in IDF ensures single-document results still get a positive score.
|
|
147
|
+
|
|
148
|
+
### fuzzy.ts
|
|
149
|
+
|
|
150
|
+
Levenshtein edit distance with two-row DP (O(n\*m) time, O(m) space). Fuzzy matching uses a sliding window of varying size to find approximate substring matches.
|
|
151
|
+
|
|
152
|
+
## Dashboard
|
|
153
|
+
|
|
154
|
+
### dashboard.ts
|
|
155
|
+
|
|
156
|
+
Single HTTP server handles both REST API and static files:
|
|
157
|
+
|
|
158
|
+
- **Static serving**: resolves UI directory (checks `src/ui/` then `dist/ui/`), serves with MIME detection and CSP headers
|
|
159
|
+
- **REST API**: routes for knowledge CRUD/search, session list/search/recall/get/summary, health
|
|
160
|
+
- **WebSocket**: `ws` library with `noServer` mode, heartbeat every 30s, initial state snapshot on connect
|
|
161
|
+
- **File watcher**: `fs.watch` on UI directory, debounced 200ms, broadcasts `{type: "reload"}` to all WS clients
|
|
162
|
+
|
|
163
|
+
### UI Architecture
|
|
164
|
+
|
|
165
|
+
Vanilla JS SPA (no framework, no build step):
|
|
166
|
+
|
|
167
|
+
- WebSocket connects on load, handles `state` and `reload` messages
|
|
168
|
+
- 4 tabs with lazy data loading
|
|
169
|
+
- `marked` + `DOMPurify` + `highlight.js` for markdown rendering
|
|
170
|
+
- Theme persisted in `localStorage('agent-knowledge-theme')`
|
|
171
|
+
|
|
172
|
+
## Caching Strategy
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
Search Request
|
|
176
|
+
│
|
|
177
|
+
▼
|
|
178
|
+
┌─────────────────────┐
|
|
179
|
+
│ TF-IDF index < 60s? │──Yes──► Search cached index (~40ms)
|
|
180
|
+
└─────────────────────┘
|
|
181
|
+
│ No
|
|
182
|
+
▼
|
|
183
|
+
┌─────────────────────┐
|
|
184
|
+
│ Scan session files │
|
|
185
|
+
│ Check mtime cache │──► Parse only changed files
|
|
186
|
+
└─────────────────────┘
|
|
187
|
+
│
|
|
188
|
+
▼
|
|
189
|
+
┌─────────────────────┐
|
|
190
|
+
│ Rebuild index │──► Cache with 60s TTL (~5s cold)
|
|
191
|
+
└─────────────────────┘
|
|
192
|
+
│
|
|
193
|
+
▼
|
|
194
|
+
Search new index
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Data Flow
|
|
198
|
+
|
|
199
|
+
### Session Search
|
|
200
|
+
|
|
201
|
+
```mermaid
|
|
202
|
+
sequenceDiagram
|
|
203
|
+
participant C as Claude Code
|
|
204
|
+
participant S as MCP Server
|
|
205
|
+
participant I as TF-IDF Index
|
|
206
|
+
participant P as Parser Cache
|
|
207
|
+
participant F as File System
|
|
208
|
+
|
|
209
|
+
C->>S: knowledge_search({ query })
|
|
210
|
+
S->>I: search(query)
|
|
211
|
+
alt Index expired
|
|
212
|
+
I->>F: List .jsonl files
|
|
213
|
+
loop Each file
|
|
214
|
+
alt Mtime changed
|
|
215
|
+
I->>P: parse(file)
|
|
216
|
+
P->>F: Read JSONL
|
|
217
|
+
P-->>I: Parsed entries
|
|
218
|
+
else Mtime unchanged
|
|
219
|
+
I->>P: getCached(file)
|
|
220
|
+
P-->>I: Cached entries
|
|
221
|
+
end
|
|
222
|
+
end
|
|
223
|
+
I->>I: Rebuild index
|
|
224
|
+
end
|
|
225
|
+
I-->>S: Ranked results
|
|
226
|
+
S-->>C: SearchResult[]
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
### Knowledge Write
|
|
230
|
+
|
|
231
|
+
```mermaid
|
|
232
|
+
sequenceDiagram
|
|
233
|
+
participant C as Claude Code
|
|
234
|
+
participant S as MCP Server
|
|
235
|
+
participant G as Git
|
|
236
|
+
participant F as File System
|
|
237
|
+
|
|
238
|
+
C->>S: knowledge_write({ category, filename, content })
|
|
239
|
+
S->>G: git pull --rebase
|
|
240
|
+
S->>F: Write markdown file
|
|
241
|
+
S->>G: git add -A && commit && push
|
|
242
|
+
G-->>S: Push result
|
|
243
|
+
S-->>C: { path, git status }
|
|
244
|
+
```
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# Dashboard
|
|
2
|
+
|
|
3
|
+
The dashboard runs at **http://localhost:3423** and auto-starts with the MCP server.
|
|
4
|
+
|
|
5
|
+
## Tabs
|
|
6
|
+
|
|
7
|
+
| Tab | Purpose |
|
|
8
|
+
| ------------- | --------------------------------------------------------------- |
|
|
9
|
+
| **Knowledge** | Browse knowledge base entries by category |
|
|
10
|
+
| **Search** | TF-IDF ranked search across session transcripts |
|
|
11
|
+
| **Sessions** | Browse and read session conversation logs |
|
|
12
|
+
| **Recall** | Scoped search (errors, plans, configs, tools, files, decisions) |
|
|
13
|
+
|
|
14
|
+
## Knowledge Tab
|
|
15
|
+
|
|
16
|
+
Card grid of knowledge entries. Each card shows:
|
|
17
|
+
|
|
18
|
+
- Category badge with color: projects (blue), people (purple), decisions (orange), workflows (green), notes (yellow)
|
|
19
|
+
- Title and tag pills
|
|
20
|
+
- Last updated date
|
|
21
|
+
|
|
22
|
+
Category filter chips at the top: All, Projects, People, Decisions, Workflows, Notes.
|
|
23
|
+
|
|
24
|
+
Click a card to open the side panel with rendered markdown content.
|
|
25
|
+
|
|
26
|
+
## Search Tab
|
|
27
|
+
|
|
28
|
+
Full-text search across all session transcripts.
|
|
29
|
+
|
|
30
|
+
**Controls:**
|
|
31
|
+
|
|
32
|
+
- Search input with debounce (300ms)
|
|
33
|
+
- Role filter chips: All, User, Assistant
|
|
34
|
+
- Mode toggle: Ranked (TF-IDF) vs Regex
|
|
35
|
+
|
|
36
|
+
**Results show:**
|
|
37
|
+
|
|
38
|
+
- Role badge (user/assistant)
|
|
39
|
+
- Project name
|
|
40
|
+
- Relative timestamp
|
|
41
|
+
- Score bar with numeric value
|
|
42
|
+
- Excerpt with highlighted matching terms
|
|
43
|
+
|
|
44
|
+
Click a result to open the session in the side panel.
|
|
45
|
+
|
|
46
|
+
## Sessions Tab
|
|
47
|
+
|
|
48
|
+
Lists all Claude Code sessions with metadata:
|
|
49
|
+
|
|
50
|
+
- Project name
|
|
51
|
+
- Git branch
|
|
52
|
+
- Message count
|
|
53
|
+
- Date
|
|
54
|
+
- Preview of first user message
|
|
55
|
+
|
|
56
|
+
Project filter dropdown at the top.
|
|
57
|
+
|
|
58
|
+
Click a session to open the side panel with the full conversation rendered as chat bubbles.
|
|
59
|
+
|
|
60
|
+
## Recall Tab
|
|
61
|
+
|
|
62
|
+
Scoped search that pre-filters results by category:
|
|
63
|
+
|
|
64
|
+
| Scope | What it finds |
|
|
65
|
+
| ----------- | ----------------------------------------- |
|
|
66
|
+
| `errors` | Stack traces, exceptions, failed commands |
|
|
67
|
+
| `plans` | Architecture, TODOs, implementation steps |
|
|
68
|
+
| `configs` | Settings, env vars, configuration files |
|
|
69
|
+
| `tools` | MCP tool calls, CLI commands |
|
|
70
|
+
| `files` | File paths, modifications |
|
|
71
|
+
| `decisions` | Trade-offs, rationale, choices |
|
|
72
|
+
|
|
73
|
+
Results use the same format as the Search tab.
|
|
74
|
+
|
|
75
|
+
## Side Panel
|
|
76
|
+
|
|
77
|
+
- Width: 560px, resizable by dragging the left edge
|
|
78
|
+
- Close: X button or press Escape
|
|
79
|
+
- Knowledge entries: rendered as markdown via marked + DOMPurify + highlight.js
|
|
80
|
+
- Sessions: chat bubbles (user = right/accent, assistant = left/surface)
|
|
81
|
+
|
|
82
|
+
## Theming
|
|
83
|
+
|
|
84
|
+
- Toggle: sun/moon button in header
|
|
85
|
+
- Persisted in `localStorage('agent-knowledge-theme')`
|
|
86
|
+
- MD3 design tokens matching agent-comm and agent-tasks dashboards
|
|
87
|
+
- CSS custom properties on `:root`, switched via `data-theme` attribute
|
|
88
|
+
|
|
89
|
+
## Live Reload
|
|
90
|
+
|
|
91
|
+
File watcher monitors `src/ui/` for `.html`, `.css`, `.js` changes. On change, broadcasts `{type: "reload"}` via WebSocket. Connected browsers auto-refresh.
|
|
92
|
+
|
|
93
|
+
## Keyboard Shortcuts
|
|
94
|
+
|
|
95
|
+
| Shortcut | Action |
|
|
96
|
+
| --------------- | ------------------ |
|
|
97
|
+
| `/` or `Ctrl+K` | Focus search input |
|
|
98
|
+
| `Escape` | Close side panel |
|
|
99
|
+
|
|
100
|
+
## REST API
|
|
101
|
+
|
|
102
|
+
| Method | Endpoint | Description |
|
|
103
|
+
| ------ | --------------------------------------- | ---------------- |
|
|
104
|
+
| GET | `/api/knowledge` | List entries |
|
|
105
|
+
| GET | `/api/knowledge/search?q=` | Search knowledge |
|
|
106
|
+
| GET | `/api/knowledge/:path` | Read entry |
|
|
107
|
+
| GET | `/api/sessions` | List sessions |
|
|
108
|
+
| GET | `/api/sessions/search?q=&role=&ranked=` | Search sessions |
|
|
109
|
+
| GET | `/api/sessions/recall?scope=&q=` | Scoped recall |
|
|
110
|
+
| GET | `/api/sessions/:id` | Read session |
|
|
111
|
+
| GET | `/api/sessions/:id/summary` | Session summary |
|
|
112
|
+
| GET | `/health` | Health check |
|
|
113
|
+
|
|
114
|
+
## WebSocket
|
|
115
|
+
|
|
116
|
+
Connects to `ws://localhost:3423` on page load.
|
|
117
|
+
|
|
118
|
+
**State message** (on connect):
|
|
119
|
+
|
|
120
|
+
```json
|
|
121
|
+
{
|
|
122
|
+
"type": "state",
|
|
123
|
+
"knowledge": [...],
|
|
124
|
+
"sessions": [...],
|
|
125
|
+
"stats": { "knowledge_entries": 12, "session_count": 247 }
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
**Reload message** (on file change):
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{ "type": "reload" }
|
|
133
|
+
```
|
package/docs/SETUP.md
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
# Setup Guide
|
|
2
|
+
|
|
3
|
+
## Prerequisites
|
|
4
|
+
|
|
5
|
+
- **Node.js 20+** (ES modules and TypeScript features)
|
|
6
|
+
- **Git** (for knowledge base sync)
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
node --version # v20.0.0 or later
|
|
10
|
+
git --version
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
git clone https://github.com/keshrath/agent-knowledge.git
|
|
17
|
+
cd agent-knowledge
|
|
18
|
+
npm install
|
|
19
|
+
npm run build
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
For development with auto-rebuild:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
npm run dev
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Configuration in Claude Code
|
|
29
|
+
|
|
30
|
+
### Register the MCP server
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
claude mcp add agent-knowledge -s user \
|
|
34
|
+
-e KNOWLEDGE_MEMORY_DIR="$HOME/claude-memory" \
|
|
35
|
+
-- node /path/to/agent-knowledge/dist/index.js
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Permissions
|
|
39
|
+
|
|
40
|
+
Add to `~/.claude/settings.json`:
|
|
41
|
+
|
|
42
|
+
```json
|
|
43
|
+
{
|
|
44
|
+
"permissions": {
|
|
45
|
+
"allow": ["mcp__agent-knowledge__*"]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Verify
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
claude mcp list
|
|
54
|
+
# Should show: agent-knowledge ... Connected
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Environment Variables
|
|
58
|
+
|
|
59
|
+
| Variable | Default | Description |
|
|
60
|
+
| ---------------------- | ----------------- | --------------------------------- |
|
|
61
|
+
| `KNOWLEDGE_MEMORY_DIR` | `~/claude-memory` | Path to git-synced knowledge base |
|
|
62
|
+
| `CLAUDE_MEMORY_DIR` | `~/claude-memory` | Alias (backwards compat) |
|
|
63
|
+
| `CLAUDE_DIR` | `~/.claude` | Claude Code data directory |
|
|
64
|
+
| `KNOWLEDGE_PORT` | `3423` | Dashboard HTTP/WebSocket port |
|
|
65
|
+
|
|
66
|
+
Set in your shell profile or pass via MCP config:
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
export KNOWLEDGE_MEMORY_DIR="$HOME/claude-memory"
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
On Windows (PowerShell):
|
|
73
|
+
|
|
74
|
+
```powershell
|
|
75
|
+
$env:KNOWLEDGE_MEMORY_DIR = "$env:USERPROFILE\claude-memory"
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Knowledge Base Setup
|
|
79
|
+
|
|
80
|
+
The knowledge base is a git repository with categorized markdown files.
|
|
81
|
+
|
|
82
|
+
### Clone existing or create new
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Clone existing
|
|
86
|
+
git clone https://your-git-host/claude-memory.git ~/claude-memory
|
|
87
|
+
|
|
88
|
+
# Or create new
|
|
89
|
+
mkdir -p ~/claude-memory && cd ~/claude-memory && git init
|
|
90
|
+
mkdir projects people decisions workflows notes
|
|
91
|
+
git add . && git commit -m "Initialize knowledge base"
|
|
92
|
+
git remote add origin <your-remote-url>
|
|
93
|
+
git push -u origin main
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Directory structure
|
|
97
|
+
|
|
98
|
+
```
|
|
99
|
+
~/claude-memory/
|
|
100
|
+
projects/ # Project context, architecture, tech stacks
|
|
101
|
+
people/ # Team members, contacts, preferences
|
|
102
|
+
decisions/ # Architecture decisions, trade-offs, rationale
|
|
103
|
+
workflows/ # Processes, deployment steps, runbooks
|
|
104
|
+
notes/ # General notes, research, references
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Entry format
|
|
108
|
+
|
|
109
|
+
```markdown
|
|
110
|
+
---
|
|
111
|
+
title: My Project
|
|
112
|
+
tags: [typescript, react, postgres]
|
|
113
|
+
updated: 2026-03-25
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
# My Project
|
|
117
|
+
|
|
118
|
+
Architecture notes, deployment info, etc.
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Dashboard
|
|
122
|
+
|
|
123
|
+
Auto-starts with the MCP server at **http://localhost:3423**.
|
|
124
|
+
|
|
125
|
+
4 tabs: Knowledge, Search, Sessions, Recall. Supports light/dark theme.
|
|
126
|
+
|
|
127
|
+
Live reload: edit files in `src/ui/` and the browser refreshes automatically.
|
|
128
|
+
|
|
129
|
+
## Multi-Machine Sync
|
|
130
|
+
|
|
131
|
+
| Operation | Git Action | When |
|
|
132
|
+
| ------------------------------------- | ------------------------------ | -------------- |
|
|
133
|
+
| `knowledge_read`, `knowledge_list` | `git pull --rebase` | Before reading |
|
|
134
|
+
| `knowledge_write`, `knowledge_delete` | `git add -A && commit && push` | After writing |
|
|
135
|
+
| `knowledge_sync` | `git pull` then `git push` | Manual trigger |
|
|
136
|
+
|
|
137
|
+
Ensure git credentials are configured (SSH key or credential helper):
|
|
138
|
+
|
|
139
|
+
```bash
|
|
140
|
+
cd ~/claude-memory && git pull && git push # Should work without prompts
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
## Troubleshooting
|
|
144
|
+
|
|
145
|
+
### Port already in use
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
# Find the process
|
|
149
|
+
netstat -ano | findstr :3423 # Windows
|
|
150
|
+
lsof -i :3423 # Linux/macOS
|
|
151
|
+
|
|
152
|
+
# Use a different port
|
|
153
|
+
export KNOWLEDGE_PORT=3424
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Git authentication failures
|
|
157
|
+
|
|
158
|
+
Verify credentials work manually:
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
cd ~/claude-memory && git push
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Set up SSH keys or a credential helper if prompted.
|
|
165
|
+
|
|
166
|
+
### MCP server not connecting
|
|
167
|
+
|
|
168
|
+
1. Check path points to `dist/index.js` (not `src/index.ts`)
|
|
169
|
+
2. Verify Node.js 20+ is on your PATH
|
|
170
|
+
3. Try running manually: `node /path/to/agent-knowledge/dist/index.js`
|
|
171
|
+
|
|
172
|
+
### No session results
|
|
173
|
+
|
|
174
|
+
Verify session transcripts exist:
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
ls ~/.claude/projects/ # Should contain project directories with .jsonl files
|
|
178
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "agent-knowledge",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Cross-session memory and recall for AI agents — git-synced knowledge base, hybrid semantic+TF-IDF search, auto-distillation with secrets scrubbing",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"bin": {
|
|
8
|
+
"agent-knowledge": "dist/index.js"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"dist/",
|
|
12
|
+
"scripts/",
|
|
13
|
+
"docs/*.md",
|
|
14
|
+
"README.md",
|
|
15
|
+
"CHANGELOG.md",
|
|
16
|
+
"LICENSE"
|
|
17
|
+
],
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tsc && node scripts/copy-ui.js",
|
|
20
|
+
"start": "node dist/index.js",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest",
|
|
24
|
+
"test:coverage": "vitest run --coverage",
|
|
25
|
+
"lint": "eslint src/ tests/",
|
|
26
|
+
"lint:fix": "eslint src/ tests/ --fix",
|
|
27
|
+
"format": "prettier --write .",
|
|
28
|
+
"format:check": "prettier --check .",
|
|
29
|
+
"typecheck": "tsc --noEmit",
|
|
30
|
+
"check": "npm run typecheck && npm run lint && npm run format:check && npm run test",
|
|
31
|
+
"clean": "rm -rf dist",
|
|
32
|
+
"prepare": "husky"
|
|
33
|
+
},
|
|
34
|
+
"keywords": [
|
|
35
|
+
"mcp",
|
|
36
|
+
"agent",
|
|
37
|
+
"memory",
|
|
38
|
+
"recall",
|
|
39
|
+
"session-search",
|
|
40
|
+
"knowledge-base",
|
|
41
|
+
"tfidf",
|
|
42
|
+
"embeddings",
|
|
43
|
+
"semantic-search",
|
|
44
|
+
"model-context-protocol",
|
|
45
|
+
"ai-agents",
|
|
46
|
+
"claude-code"
|
|
47
|
+
],
|
|
48
|
+
"author": "keshrath",
|
|
49
|
+
"license": "MIT",
|
|
50
|
+
"repository": {
|
|
51
|
+
"type": "git",
|
|
52
|
+
"url": "https://github.com/keshrath/agent-knowledge.git"
|
|
53
|
+
},
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/keshrath/agent-knowledge/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/keshrath/agent-knowledge#readme",
|
|
58
|
+
"dependencies": {
|
|
59
|
+
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
60
|
+
"better-sqlite3": "^11.0.0",
|
|
61
|
+
"sqlite-vec": "^0.1.0",
|
|
62
|
+
"ws": "^8.20.0"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@eslint/js": "^10.0.1",
|
|
66
|
+
"@types/better-sqlite3": "^7.6.0",
|
|
67
|
+
"@types/node": "^25.5.0",
|
|
68
|
+
"@types/ws": "^8.18.1",
|
|
69
|
+
"eslint": "^10.1.0",
|
|
70
|
+
"husky": "^9.0.0",
|
|
71
|
+
"lint-staged": "^16.0.0",
|
|
72
|
+
"prettier": "^3.8.1",
|
|
73
|
+
"typescript": "^5.7.0",
|
|
74
|
+
"typescript-eslint": "^8.57.2",
|
|
75
|
+
"vitest": "^3.0.0"
|
|
76
|
+
},
|
|
77
|
+
"optionalDependencies": {
|
|
78
|
+
"@huggingface/transformers": "^3.0.0"
|
|
79
|
+
},
|
|
80
|
+
"lint-staged": {
|
|
81
|
+
"*.{ts,js}": [
|
|
82
|
+
"prettier --write",
|
|
83
|
+
"eslint --fix"
|
|
84
|
+
],
|
|
85
|
+
"*.{json,md,css,html}": [
|
|
86
|
+
"prettier --write"
|
|
87
|
+
]
|
|
88
|
+
},
|
|
89
|
+
"engines": {
|
|
90
|
+
"node": ">=20.11.0"
|
|
91
|
+
}
|
|
92
|
+
}
|