@kage-core/kage-graph-mcp 1.0.0 → 1.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.
package/README.md ADDED
@@ -0,0 +1,294 @@
1
+ # Kage Repo-Recall MCP
2
+
3
+ This package exposes two surfaces:
4
+
5
+ - `kage-graph-mcp`: MCP server for the public Kage graph plus repo-local recall.
6
+ - `kage`: CLI for local repo memory packets, indexing, recall, capture, review,
7
+ setup, optional daemon runtime, org/global artifact mode, marketplace packs,
8
+ and validation.
9
+
10
+ ## Build
11
+
12
+ ```bash
13
+ npm install
14
+ npm run build
15
+ ```
16
+
17
+ ## CLI
18
+
19
+ ```bash
20
+ kage setup list
21
+ kage setup codex --project /path/to/repo --write
22
+ kage setup claude-code --project /path/to/repo
23
+ kage setup generic-mcp --project /path/to/repo
24
+ kage setup doctor --project /path/to/repo
25
+ kage init --project /path/to/repo
26
+ kage policy --project /path/to/repo
27
+ kage doctor --project /path/to/repo
28
+ kage index --project /path/to/repo
29
+ kage branch --project /path/to/repo
30
+ kage code-graph --project /path/to/repo
31
+ kage code-graph "createApp routes tests" --project /path/to/repo
32
+ kage graph --project /path/to/repo
33
+ kage graph --project /path/to/repo --mermaid
34
+ kage graph "test command" --project /path/to/repo
35
+ kage recall "how do I run tests" --project /path/to/repo
36
+ kage recall "how do I run tests" --project /path/to/repo --explain --json
37
+ kage quality --project /path/to/repo
38
+ kage benchmark --project /path/to/repo
39
+ kage viewer --project /path/to/repo
40
+ kage daemon start --project /path/to/repo
41
+ kage observe --project /path/to/repo --event '{"type":"command_result","session_id":"s1","command":"npm test","exit_code":0}'
42
+ kage distill --project /path/to/repo --session s1
43
+ kage learn --project /path/to/repo --learning "Decision: use kage_learn for actual session discoveries." --paths mcp/index.ts
44
+ kage feedback --project /path/to/repo --packet <approved-packet-id> --kind stale
45
+ kage capture --project /path/to/repo --type runbook --title "Webhook tests" --body "Run pnpm test:api -- webhooks."
46
+ kage propose --project /path/to/repo --from-diff
47
+ kage review-artifact --project /path/to/repo
48
+ kage registry --project /path/to/repo
49
+ kage marketplace --project /path/to/repo
50
+ kage promote --project /path/to/repo --public <approved-packet-id>
51
+ kage export-public --project /path/to/repo
52
+ kage org upload --project /path/to/repo --org acme --packet <approved-packet-id>
53
+ kage org review --project /path/to/repo --org acme --packet <org-packet-id> --approve
54
+ kage org recall "how do I run tests" --project /path/to/repo --org acme
55
+ kage layered-recall "how do I run tests" --project /path/to/repo --org acme --global
56
+ kage global build --project /path/to/repo --org acme
57
+ kage review --project /path/to/repo
58
+ kage validate --project /path/to/repo
59
+ ```
60
+
61
+ `kage init` is the first-run command. It creates `.agent_memory/`, migrates
62
+ legacy Markdown nodes into `.agent_memory/packets/*.json`, builds generated
63
+ indexes, installs/updates `AGENTS.md`, validates the result, and prints a first
64
+ recall preview.
65
+
66
+ The graph builder writes evidence-backed graph artifacts under
67
+ `.agent_memory/graph/`:
68
+
69
+ - `episodes.json`: where graph facts came from, such as memory packets or
70
+ repo manifests.
71
+ - `entities.json`: typed nodes for repo, memory, path, tag, package, command,
72
+ and memory type entities.
73
+ - `edges.json`: typed facts such as `contains_memory`, `affects_path`,
74
+ `mentions_tag`, `uses_package`, `documents_command`, and `defines_command`.
75
+ - `graph.json`: the assembled graph with branch, head, and merge-base metadata.
76
+
77
+ The code graph builder writes source-derived artifacts under
78
+ `.agent_memory/code_graph/`:
79
+
80
+ - `files.json`: source, test, config, manifest, and doc files, including
81
+ language and parser metadata.
82
+ - `symbols.json`: functions, classes, constants, and test cases.
83
+ - `imports.json`: local and external import edges.
84
+ - `calls.json`: best-effort call edges between discovered symbols.
85
+ - `routes.json`: best-effort Node/Express/Next route facts.
86
+ - `tests.json`: test-to-symbol/file coverage hints.
87
+ - `packages.json`: package scripts and dependencies.
88
+ - `graph.json`: the assembled code graph.
89
+
90
+ The code graph is multi-language by design. JS/TS/JSX/TSX files use the
91
+ TypeScript compiler API for AST-backed symbols, imports, and call hints. Python,
92
+ Go, Rust, Java, Kotlin, Ruby, PHP, C#, C/C++, and Swift use deterministic generic
93
+ static extractors so every repo gets a useful graph immediately.
94
+
95
+ Kage also consumes external industry indexer artifacts when present:
96
+
97
+ - `.agent_memory/code_index/tree-sitter.json`
98
+ - `.agent_memory/code_index/scip.json`
99
+ - `.agent_memory/code_index/lsp-symbols.json`
100
+ - `.agent_memory/code_index/lsif.jsonl`
101
+ - `tree-sitter-index.json`
102
+ - `index.scip.json`
103
+ - `dump.lsif`
104
+
105
+ Those adapters are merge inputs, not required runtime dependencies. Facts from
106
+ Tree-sitter, SCIP, LSIF, and LSP are tagged with parser provenance and outrank
107
+ generic extraction in metrics and file parser coverage. This keeps installation
108
+ light while allowing teams to plug in the strongest indexer available for their
109
+ language stack.
110
+
111
+ The memory graph follows the same product direction as temporal context graph
112
+ systems such as Graphiti: immutable ingestion episodes, derived entities and
113
+ facts, evidence/provenance on every edge, confidence, branch/commit context, and
114
+ temporal validity fields (`valid_from`, `invalidated_at`). Kage keeps code facts
115
+ and learned memory separate, then recalls across both when assembling context.
116
+
117
+ Use `kage metrics --project <repo>` or the `kage_metrics` MCP tool to inspect
118
+ whether the harness is actually carrying its weight. Metrics include language
119
+ and parser coverage, code graph counts, evidence coverage, approved vs pending
120
+ memory, validation status, estimated tokens saved per recall, duplicate
121
+ candidates, average memory quality, and a readiness score.
122
+
123
+ Review artifacts include memory quality reasons, risks, duplicate candidates,
124
+ and estimated token savings so reviewers can approve, reject, or merge pending
125
+ memory with less manual inspection.
126
+
127
+ `kage observe` is the automatic-capture primitive for agent hooks and daemon
128
+ clients. It accepts session, prompt, tool, file-change, command, test, and
129
+ session-end events; deduplicates them; scans for secrets and PII; and stores raw
130
+ observations locally only. `kage distill` turns those observations into pending
131
+ packets with observation session source refs. It never approves or publishes
132
+ memory.
133
+
134
+ `kage recall --explain --json` exposes the hybrid scoring explanation used for
135
+ ranking: text, graph, path/type/tag, freshness, quality, feedback, and a vector
136
+ placeholder for future local or external embedding providers. Current fallback
137
+ is deterministic text plus graph retrieval.
138
+
139
+ `kage daemon start` exposes the optional local REST runtime on
140
+ `127.0.0.1:3111`:
141
+
142
+ - `GET /health`
143
+ - `GET /kage/status`
144
+ - `GET /kage/metrics`
145
+ - `GET /kage/quality`
146
+ - `GET /kage/benchmark`
147
+ - `POST /kage/recall`
148
+ - `POST /kage/observe`
149
+ - `POST /kage/distill`
150
+
151
+ The daemon is not required for stdio MCP or CLI use; it exists for agents and
152
+ workflows that need REST, live observation ingestion, or Aider-style scripting.
153
+
154
+ ## Local Graph Viewer
155
+
156
+ Run `kage viewer --project <repo>` to start the local terminal console. It
157
+ serves the viewer and the selected repo's `.agent_memory/` files from the same
158
+ localhost server, then prints a URL that auto-loads memory graph, code graph,
159
+ metrics, review artifact, and pending packets. Manual JSON selection remains as
160
+ a fallback, not the main workflow.
161
+
162
+ The viewer renders nodes and relations in SVG, supports memory/code/combined
163
+ modes, filters by type and relation, displays metrics, shows the pending review
164
+ queue, and marks review risks such as low-confidence or missing-evidence edges.
165
+
166
+ For demos or local docs, the viewer also accepts URL params:
167
+
168
+ ```text
169
+ mcp/viewer/index.html?graph=/repo/.agent_memory/graph/graph.json&code=/repo/.agent_memory/code_graph/graph.json&metrics=/repo/.agent_memory/metrics.json
170
+ ```
171
+
172
+ The graph canvas supports drag-to-pan, wheel zoom, explicit zoom buttons,
173
+ fit-to-view, click selection, and background deselect. This keeps review
174
+ interactive enough to explain how repo facts, learned memory, evidence,
175
+ confidence, and token-savings metrics connect.
176
+
177
+ ## MCP Tools
178
+
179
+ Local repo tools:
180
+
181
+ - `kage_recall`
182
+ - `kage_code_graph`
183
+ - `kage_metrics`
184
+ - `kage_quality`
185
+ - `kage_benchmark`
186
+ - `kage_setup_agent`
187
+ - `kage_graph`
188
+ - `kage_graph_visual`
189
+ - `kage_learn`
190
+ - `kage_capture`
191
+ - `kage_observe`
192
+ - `kage_distill`
193
+ - `kage_feedback`
194
+ - `kage_install_policy`
195
+ - `kage_branch_overlay`
196
+ - `kage_validate`
197
+ - `kage_registry_recommend`
198
+ - `kage_marketplace`
199
+ - `kage_org_status`
200
+ - `kage_org_upload_candidate`
201
+ - `kage_org_recall`
202
+ - `kage_layered_recall`
203
+ - `kage_global_build`
204
+ - `kage_review_artifact`
205
+ - `kage_propose_from_diff`
206
+ - `kage_promote_public_candidate`
207
+ - `kage_export_public_bundle`
208
+
209
+ Public graph tools:
210
+
211
+ - `kage_search`
212
+ - `kage_fetch`
213
+ - `kage_list_domains`
214
+
215
+ ## Codex MCP Configuration
216
+
217
+ Fast path from the repo you want Kage to remember:
218
+
219
+ ```bash
220
+ curl -fsSL https://raw.githubusercontent.com/kage-core/Kage/master/codex-setup.sh | bash
221
+ ```
222
+
223
+ This clones/updates Kage under `~/.kage/Kage`, builds this MCP package, writes
224
+ the `mcp_servers.kage` block to `~/.codex/config.toml`, and runs `kage init` for
225
+ the current repo. Restart Codex after it completes.
226
+
227
+ Local development path:
228
+
229
+ ```bash
230
+ /path/to/Kage/codex-setup.sh --project /path/to/repo
231
+ ```
232
+
233
+ After building the package, add the local stdio server to Codex.
234
+
235
+ `~/.codex/config.toml`:
236
+
237
+ ```toml
238
+ [mcp_servers.kage]
239
+ command = "node"
240
+ args = ["/absolute/path/to/Kage/mcp/dist/index.js"]
241
+ ```
242
+
243
+ Then restart Codex. To make Kage ambient instead of manual, run `kage init` or
244
+ `kage policy`; both install an `AGENTS.md` policy that tells Codex to call Kage
245
+ automatically before and after coding tasks.
246
+
247
+ For other agents, generate the exact config with:
248
+
249
+ ```bash
250
+ kage setup list
251
+ kage setup cursor --project /path/to/repo
252
+ kage setup windsurf --project /path/to/repo
253
+ kage setup gemini-cli --project /path/to/repo
254
+ kage setup opencode --project /path/to/repo
255
+ kage setup generic-mcp --project /path/to/repo
256
+ ```
257
+
258
+ Minimum policy:
259
+
260
+ ```md
261
+ Before code changes or repo-specific answers:
262
+ 1. Call `kage_validate`.
263
+ 2. Call `kage_recall` with the user task as the query.
264
+ 3. Call `kage_graph` with the user task as the query.
265
+ 4. Capture reusable learnings with `kage_learn` or `kage_capture`.
266
+ 5. Before finishing changed-file tasks, call `kage_propose_from_diff`.
267
+ 6. Never approve or publish memory automatically.
268
+ ```
269
+
270
+ The official Codex MCP docs also support adding HTTP MCP servers with:
271
+
272
+ ```bash
273
+ codex mcp add <name> --url <server-url>
274
+ codex mcp list
275
+ ```
276
+
277
+ Kage currently runs as a local stdio MCP server, so the TOML form is the direct
278
+ fit for this MVP.
279
+
280
+ ## Safety Model
281
+
282
+ - `kage_learn` is the preferred surface for actual session learning. It creates
283
+ pending packets with explicit learning/evidence/verification text.
284
+ - `kage_capture` only creates pending packets.
285
+ - `kage_propose_from_diff` writes a branch review summary under
286
+ `.agent_memory/review/` and a pending change-memory packet under
287
+ `.agent_memory/pending/`. It becomes shared recall only after human approval.
288
+ - `kage_promote_public_candidate` writes a local sanitized review candidate
289
+ under `.agent_memory/public-candidates/`; it does not publish.
290
+ - Registry recommendations never auto-install skills, docs, or MCP servers.
291
+ - Shared approved memory still requires `kage review`.
292
+ - Capture blocks obvious secrets, tokens, private URL credentials, bearer
293
+ tokens, private keys, and email addresses before writing a packet.
294
+ - Generated indexes are disposable and can be rebuilt from packets.