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