agent-knowledge 1.2.0 → 1.3.1

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 (78) hide show
  1. package/CHANGELOG.md +94 -13
  2. package/README.md +51 -34
  3. package/dist/dashboard.d.ts +1 -0
  4. package/dist/dashboard.d.ts.map +1 -1
  5. package/dist/dashboard.js +76 -23
  6. package/dist/dashboard.js.map +1 -1
  7. package/dist/embeddings/anthropic.d.ts.map +1 -1
  8. package/dist/embeddings/anthropic.js +2 -1
  9. package/dist/embeddings/anthropic.js.map +1 -1
  10. package/dist/embeddings/gemini.d.ts.map +1 -1
  11. package/dist/embeddings/gemini.js +2 -1
  12. package/dist/embeddings/gemini.js.map +1 -1
  13. package/dist/embeddings/local.d.ts.map +1 -1
  14. package/dist/embeddings/local.js +3 -0
  15. package/dist/embeddings/local.js.map +1 -1
  16. package/dist/knowledge/consolidate.d.ts +46 -0
  17. package/dist/knowledge/consolidate.d.ts.map +1 -0
  18. package/dist/knowledge/consolidate.js +164 -0
  19. package/dist/knowledge/consolidate.js.map +1 -0
  20. package/dist/knowledge/distill.d.ts.map +1 -1
  21. package/dist/knowledge/distill.js +4 -2
  22. package/dist/knowledge/distill.js.map +1 -1
  23. package/dist/knowledge/graph.d.ts.map +1 -1
  24. package/dist/knowledge/graph.js +2 -1
  25. package/dist/knowledge/graph.js.map +1 -1
  26. package/dist/knowledge/reflect.d.ts +33 -0
  27. package/dist/knowledge/reflect.d.ts.map +1 -0
  28. package/dist/knowledge/reflect.js +115 -0
  29. package/dist/knowledge/reflect.js.map +1 -0
  30. package/dist/knowledge/scoring.d.ts.map +1 -1
  31. package/dist/knowledge/scoring.js +2 -1
  32. package/dist/knowledge/scoring.js.map +1 -1
  33. package/dist/knowledge/search.d.ts.map +1 -1
  34. package/dist/knowledge/search.js +4 -7
  35. package/dist/knowledge/search.js.map +1 -1
  36. package/dist/knowledge/store.d.ts.map +1 -1
  37. package/dist/knowledge/store.js +4 -3
  38. package/dist/knowledge/store.js.map +1 -1
  39. package/dist/search/excerpt.d.ts.map +1 -1
  40. package/dist/search/excerpt.js +2 -1
  41. package/dist/search/excerpt.js.map +1 -1
  42. package/dist/search/tfidf.d.ts +1 -0
  43. package/dist/search/tfidf.d.ts.map +1 -1
  44. package/dist/search/tfidf.js +38 -3
  45. package/dist/search/tfidf.js.map +1 -1
  46. package/dist/server.d.ts.map +1 -1
  47. package/dist/server.js +103 -534
  48. package/dist/server.js.map +1 -1
  49. package/dist/sessions/parser.d.ts.map +1 -1
  50. package/dist/sessions/parser.js +33 -60
  51. package/dist/sessions/parser.js.map +1 -1
  52. package/dist/sessions/search.js +17 -3
  53. package/dist/sessions/search.js.map +1 -1
  54. package/dist/sessions/summary.d.ts.map +1 -1
  55. package/dist/sessions/summary.js +6 -3
  56. package/dist/sessions/summary.js.map +1 -1
  57. package/dist/tool-handlers.d.ts +41 -0
  58. package/dist/tool-handlers.d.ts.map +1 -0
  59. package/dist/tool-handlers.js +425 -0
  60. package/dist/tool-handlers.js.map +1 -0
  61. package/dist/types.d.ts.map +1 -1
  62. package/dist/types.js +6 -4
  63. package/dist/types.js.map +1 -1
  64. package/dist/ui/app.js +86 -847
  65. package/dist/ui/index.html +17 -0
  66. package/dist/ui/render-knowledge.js +233 -0
  67. package/dist/ui/render-panel.js +350 -0
  68. package/dist/ui/render-search.js +109 -0
  69. package/dist/ui/render-sessions.js +234 -0
  70. package/dist/ui/styles.css +91 -0
  71. package/dist/ui/ui-utils.js +196 -0
  72. package/dist/vectorstore/store.d.ts +25 -44
  73. package/dist/vectorstore/store.d.ts.map +1 -1
  74. package/dist/vectorstore/store.js +167 -167
  75. package/dist/vectorstore/store.js.map +1 -1
  76. package/docs/ARCHITECTURE.md +29 -1
  77. package/docs/DASHBOARD.md +7 -0
  78. package/package.json +1 -1
@@ -40,7 +40,7 @@ graph TB
40
40
  ```
41
41
  src/
42
42
  index.ts Entry point — MCP stdio + dashboard auto-start
43
- server.ts 16 tool definitions, request routing, error handling
43
+ server.ts 6 tool definitions, request routing, error handling
44
44
  dashboard.ts HTTP + WebSocket server, REST API, file watcher
45
45
  types.ts KnowledgeConfig interface, getConfig()
46
46
  knowledge/
@@ -49,6 +49,8 @@ src/
49
49
  git.ts git pull/push/sync with execSync + timeouts
50
50
  graph.ts Knowledge graph — edges table, link/unlink/BFS traversal
51
51
  scoring.ts Confidence/decay scoring — entry_scores table, auto-promotion
52
+ consolidate.ts Memory consolidation — TF-IDF duplicate detection, cluster grouping
53
+ reflect.ts Reflection cycle — surfaces unconnected entries, generates prompts
52
54
  sessions/
53
55
  parser.ts Multi-format parsing with mtime cache + adapter dispatch
54
56
  search.ts TF-IDF ranked search with 60s global index cache
@@ -122,6 +124,8 @@ CREATE TABLE edges (
122
124
  - **links()** — list edges for a given entry or rel_type
123
125
  - **traverse()** — BFS from a starting entry to configurable depth, returns nodes and edges visited
124
126
 
127
+ All four operations are exposed via the single `knowledge_graph` tool with an `action` parameter (`link`, `unlink`, `list`, `traverse`).
128
+
125
129
  **Auto-linking**: On `knowledge_write`, the top-3 most similar existing entries are found via cosine similarity against the vector store. Entries with similarity > 0.7 get automatic `related_to` edges created.
126
130
 
127
131
  ## Confidence & Decay Scoring
@@ -157,6 +161,30 @@ finalScore = baseRelevance * 0.5^(daysSinceLastAccess / 90) * maturityMultiplier
157
161
 
158
162
  Access count increments on `knowledge_read`. Maturity transitions happen automatically when thresholds are crossed. Search results from `knowledge_search` apply the decay formula to blend relevance with freshness and confidence.
159
163
 
164
+ ## Memory Consolidation
165
+
166
+ ### consolidate.ts
167
+
168
+ Detects near-duplicate knowledge entries using TF-IDF similarity scoring.
169
+
170
+ **`checkDuplicates()`** — called after `knowledge_write`. Builds a TF-IDF index from all entries, queries with the written content, and returns entries exceeding a configurable similarity threshold (default: 0.6). Warnings are included in the write response.
171
+
172
+ **`consolidate()`** — batch scan for `knowledge_consolidate`. Computes pairwise TF-IDF similarities for all entries in a category (or globally), groups entries above threshold (default: 0.5) into clusters using union-find, and returns clusters with representative entries and pairwise similarity scores.
173
+
174
+ ## Reflection Cycle
175
+
176
+ ### reflect.ts
177
+
178
+ Surfaces unconnected knowledge entries and prepares structured prompts for agent-driven graph enrichment.
179
+
180
+ **`reflect()`** — reads all entries, queries the knowledge graph for edges, identifies entries with zero connections, and generates a structured markdown prompt listing:
181
+
182
+ 1. Unconnected entries with titles, categories, tags, and 300-char content summaries
183
+ 2. Connected entries as potential link targets
184
+ 3. Instructions for the agent to call `knowledge_link` with suggested relationships
185
+
186
+ Does NOT call an LLM — the calling agent processes the prompt in its own context and makes `knowledge_graph(action: "link")` calls based on its analysis.
187
+
160
188
  ## Session Module
161
189
 
162
190
  ### Multi-Source Architecture
package/docs/DASHBOARD.md CHANGED
@@ -24,6 +24,11 @@ Card grid of knowledge entries. Each card shows:
24
24
 
25
25
  Category filter chips at the top: All, Projects, People, Decisions, Workflows, Notes. Search bar for filtering entries by title.
26
26
 
27
+ **Header action buttons:**
28
+
29
+ - **Duplicates** — scans all entries for near-duplicates using TF-IDF similarity. Entries in duplicate clusters get a warning icon on their card. Opens a side panel showing clusters with pairwise similarity scores. Click any entry in a cluster to view it.
30
+ - **Reflect** — finds entries with no graph connections. Opens a side panel listing unconnected entries with content summaries and instructions for creating new links.
31
+
27
32
  Click a card to open the side panel with rendered markdown content, score details, and related entries.
28
33
 
29
34
  ## Search Tab
@@ -111,6 +116,8 @@ File watcher monitors `src/ui/` for `.html`, `.css`, `.js` changes. On change, b
111
116
  | GET | `/api/knowledge/search?q=` | Search knowledge |
112
117
  | GET | `/api/knowledge/:path` | Read entry (with score data) |
113
118
  | GET | `/api/knowledge/:path/links` | Graph edges for entry |
119
+ | GET | `/api/knowledge/consolidate?threshold=` | Duplicate cluster analysis |
120
+ | GET | `/api/knowledge/reflect?max_entries=` | Unconnected entries + prompt |
114
121
  | GET | `/api/sessions` | List sessions |
115
122
  | GET | `/api/sessions/search?q=&role=&ranked=` | Search sessions |
116
123
  | GET | `/api/sessions/recall?scope=&q=` | Scoped recall |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "agent-knowledge",
3
- "version": "1.2.0",
3
+ "version": "1.3.1",
4
4
  "description": "Cross-session memory and recall for AI agents — git-synced knowledge base, knowledge graph, confidence scoring, hybrid semantic+TF-IDF search, auto-distillation with secrets scrubbing",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",