@kage-core/kage-graph-mcp 1.1.16 → 1.1.17

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 CHANGED
@@ -9,6 +9,12 @@ This package exposes two surfaces:
9
9
 
10
10
  ## Latest Release
11
11
 
12
+ `1.1.17` publishes content-based graph freshness:
13
+
14
+ - `kage pr check` now uses graph input hashes, so push-only operations and
15
+ empty/same-tree commits do not force another refresh while real source,
16
+ approved-memory, or code-index changes still stale generated graph artifacts.
17
+
12
18
  `1.1.16` fixes the guarded release helper's npm verification step:
13
19
 
14
20
  - exact-version `npm view` checks now retry with backoff after publish so npm
@@ -79,6 +85,10 @@ The script fetches the current branch and blocks if the remote branch is not an
79
85
  ancestor of local `HEAD`, which prevents publishing an npm version from a branch
80
86
  that cannot be pushed cleanly.
81
87
 
88
+ Do not refresh again just because the branch was pushed. Graph freshness is
89
+ based on source, approved memory, and code-index inputs; empty/same-tree commits
90
+ are accepted by `kage pr check`.
91
+
82
92
  ## CLI
83
93
 
84
94
  ```bash
@@ -232,9 +242,10 @@ hashes, git state, audit trust, inbox counts, and metrics readiness. CI, PR, and
232
242
  sync workflows build it after refresh.
233
243
 
234
244
  Use `kage refresh --project <repo>` or the `kage_refresh` MCP tool after
235
- meaningful file changes. Refresh rebuilds indexes, code graph, memory graph,
236
- metrics, and stale-memory metadata. Memory is marked stale when status or
237
- feedback says it is stale, its TTL expires, or grounded paths disappear.
245
+ meaningful file/content changes. Refresh rebuilds indexes, code graph, memory
246
+ graph, metrics, and stale-memory metadata. Memory is marked stale when status or
247
+ feedback says it is stale, its TTL expires, or grounded paths disappear. Pushes
248
+ and empty/same-tree commits do not need another refresh.
238
249
 
239
250
  Use `kage gc --project <repo> --dry-run` to preview stale packet cleanup.
240
251
  `kage gc --project <repo>` marks stale repo packets deprecated, rebuilds
@@ -407,7 +418,7 @@ Minimum policy:
407
418
  Before code changes or repo-specific answers:
408
419
  1. Call `kage_context` with `project_dir` and the user task as `query`.
409
420
  2. Capture reusable learnings with `kage_learn` or `kage_capture`.
410
- 3. After meaningful file changes, call `kage_refresh`.
421
+ 3. After meaningful file/content changes, call `kage_refresh`; skip it for push-only or same-tree commits.
411
422
  4. Before finishing changed-file tasks, call `kage_propose_from_diff` or `kage_pr_summarize`.
412
423
  5. Before merge, call `kage_pr_check`.
413
424
  6. Never publish or promote org/global memory automatically.
package/dist/index.js CHANGED
@@ -217,7 +217,7 @@ function listTools() {
217
217
  },
218
218
  {
219
219
  name: "kage_refresh",
220
- description: "Rebuild repo indexes, code graph, memory graph, metrics, and stale-memory metadata. Agents should run this after meaningful file changes and before PR checks.",
220
+ description: "Rebuild repo indexes, code graph, memory graph, metrics, and stale-memory metadata. Agents should run this after meaningful file/content changes before PR checks; push-only or same-tree commits do not need another refresh.",
221
221
  inputSchema: {
222
222
  type: "object",
223
223
  properties: {
package/dist/kernel.js CHANGED
@@ -193,8 +193,10 @@ decisions, debugging, explanation, or action. Do not store raw transcripts.
193
193
 
194
194
  ## End-Of-Task Proposal
195
195
 
196
- After meaningful file changes, call \`kage_refresh\` so indexes, code graph,
197
- memory graph, metrics, and stale-memory checks are current.
196
+ After meaningful file/content changes, call \`kage_refresh\` so indexes, code
197
+ graph, memory graph, metrics, and stale-memory checks are current. Do not
198
+ refresh solely because a branch was pushed, an empty commit was created, or the
199
+ git commit changed without graph inputs changing.
198
200
 
199
201
  Before finishing a task that changed files, call \`kage_pr_summarize\` or
200
202
  \`kage_propose_from_diff\`, then call \`kage_pr_check\`.
@@ -232,7 +234,7 @@ For normal coding tasks:
232
234
  1. \`kage_context\` — validate + recall + code graph + knowledge graph in one call
233
235
  2. Work on the task
234
236
  3. \`kage_learn\` for concrete learnings
235
- 4. \`kage_refresh\` after meaningful file changes
237
+ 4. \`kage_refresh\` after meaningful file/content changes, not after push-only or same-tree commits
236
238
  5. \`kage_propose_from_diff\` before the final response to create repo-local change memory
237
239
 
238
240
  For quick factual questions, \`kage_context\` alone is enough. For status or demo requests, call \`kage_metrics\`.
@@ -882,6 +884,9 @@ function gitBranch(projectDir) {
882
884
  function gitHead(projectDir) {
883
885
  return readGit(projectDir, ["rev-parse", "HEAD"]);
884
886
  }
887
+ function gitTree(projectDir) {
888
+ return readGit(projectDir, ["rev-parse", "HEAD^{tree}"]);
889
+ }
885
890
  function gitMergeBase(projectDir) {
886
891
  return readGit(projectDir, ["merge-base", "HEAD", "origin/main"])
887
892
  || readGit(projectDir, ["merge-base", "HEAD", "origin/master"]);
@@ -1863,6 +1868,49 @@ function externalIndexFiles(projectDir) {
1863
1868
  { path: (0, node_path_1.join)(projectDir, "dump.lsif"), parser: "lsif", format: "lsif" },
1864
1869
  ];
1865
1870
  }
1871
+ function sha256Hex(content) {
1872
+ return (0, node_crypto_1.createHash)("sha256").update(content).digest("hex");
1873
+ }
1874
+ function projectRelative(projectDir, path) {
1875
+ return (0, node_path_1.relative)(projectDir, path).replace(/\\/g, "/");
1876
+ }
1877
+ function graphInputHash(entries) {
1878
+ const hash = (0, node_crypto_1.createHash)("sha256");
1879
+ const sorted = entries.slice().sort((a, b) => a.kind.localeCompare(b.kind) || a.path.localeCompare(b.path));
1880
+ for (const entry of sorted) {
1881
+ hash.update(entry.kind);
1882
+ hash.update("\0");
1883
+ hash.update(entry.path);
1884
+ hash.update("\0");
1885
+ hash.update(entry.sha256);
1886
+ hash.update("\0");
1887
+ }
1888
+ return hash.digest("hex");
1889
+ }
1890
+ function fileInputEntries(projectDir, paths, kind) {
1891
+ return paths
1892
+ .filter((path) => (0, node_fs_1.existsSync)(path))
1893
+ .map((path) => ({
1894
+ kind,
1895
+ path: projectRelative(projectDir, path),
1896
+ sha256: sha256Hex((0, node_fs_1.readFileSync)(path)),
1897
+ }));
1898
+ }
1899
+ function codeGraphInputHash(projectDir) {
1900
+ return graphInputHash([
1901
+ ...fileInputEntries(projectDir, listCodeFiles(projectDir), "code_file"),
1902
+ ...fileInputEntries(projectDir, externalIndexFiles(projectDir).map((index) => index.path), "external_code_index"),
1903
+ ]);
1904
+ }
1905
+ function knowledgeGraphInputHash(projectDir, codeInputHash = codeGraphInputHash(projectDir)) {
1906
+ const packetEntries = loadPacketEntriesFromDir(packetsDir(projectDir))
1907
+ .filter((entry) => entry.packet.status === "approved")
1908
+ .map((entry) => entry.path);
1909
+ return graphInputHash([
1910
+ { kind: "code_graph_input", path: ".agent_memory/code_graph/input", sha256: codeInputHash },
1911
+ ...fileInputEntries(projectDir, packetEntries, "approved_packet"),
1912
+ ]);
1913
+ }
1866
1914
  function normalizeExternalKind(value) {
1867
1915
  const kind = String(value ?? "").toLowerCase();
1868
1916
  if (["function", "method", "class", "constant", "route", "test"].includes(kind))
@@ -2103,7 +2151,9 @@ function buildCodeGraph(projectDir) {
2103
2151
  ensureMemoryDirs(projectDir);
2104
2152
  const branch = gitBranch(projectDir);
2105
2153
  const head = gitHead(projectDir);
2154
+ const tree = gitTree(projectDir);
2106
2155
  const mergeBase = gitMergeBase(projectDir);
2156
+ const inputHash = codeGraphInputHash(projectDir);
2107
2157
  const absoluteFiles = listCodeFiles(projectDir);
2108
2158
  const knownFiles = new Set(absoluteFiles.map((path) => (0, node_path_1.relative)(projectDir, path).replace(/\\/g, "/")));
2109
2159
  const files = [];
@@ -2188,7 +2238,7 @@ function buildCodeGraph(projectDir) {
2188
2238
  project_dir: projectDir,
2189
2239
  repo_key: repoKey(projectDir),
2190
2240
  generated_at: nowIso(),
2191
- repo_state: { branch, head, merge_base: mergeBase },
2241
+ repo_state: { branch, head, merge_base: mergeBase, tree, input_hash: inputHash },
2192
2242
  files: files.sort((a, b) => a.path.localeCompare(b.path)),
2193
2243
  symbols: symbols.sort((a, b) => a.path.localeCompare(b.path) || a.line - b.line || a.name.localeCompare(b.name)),
2194
2244
  imports: imports.sort((a, b) => a.from_path.localeCompare(b.from_path) || a.line - b.line || a.specifier.localeCompare(b.specifier)),
@@ -2212,6 +2262,7 @@ function buildKnowledgeGraph(projectDir) {
2212
2262
  const packets = loadApprovedPackets(projectDir).sort((a, b) => a.id.localeCompare(b.id));
2213
2263
  const branch = gitBranch(projectDir);
2214
2264
  const head = gitHead(projectDir);
2265
+ const tree = gitTree(projectDir);
2215
2266
  const mergeBase = gitMergeBase(projectDir);
2216
2267
  const entities = new Map();
2217
2268
  const edges = new Map();
@@ -2219,6 +2270,7 @@ function buildKnowledgeGraph(projectDir) {
2219
2270
  const repoEntityId = graphEntityId("repo", repoKey(projectDir));
2220
2271
  const generatedFrom = packets.map((packet) => packet.updated_at).sort().at(-1) ?? null;
2221
2272
  const codeGraph = buildCodeGraph(projectDir);
2273
+ const inputHash = knowledgeGraphInputHash(projectDir, codeGraph.repo_state.input_hash ?? codeGraphInputHash(projectDir));
2222
2274
  addEntity(entities, {
2223
2275
  id: repoEntityId,
2224
2276
  type: "repo",
@@ -2540,7 +2592,7 @@ function buildKnowledgeGraph(projectDir) {
2540
2592
  project_dir: projectDir,
2541
2593
  repo_key: repoKey(projectDir),
2542
2594
  generated_from_updated_at: generatedFrom,
2543
- repo_state: { branch, head, merge_base: mergeBase },
2595
+ repo_state: { branch, head, merge_base: mergeBase, tree, input_hash: inputHash },
2544
2596
  episodes: episodes.sort((a, b) => a.id.localeCompare(b.id)),
2545
2597
  entities: [...entities.values()].sort((a, b) => a.id.localeCompare(b.id)),
2546
2598
  edges: [...edges.values()].sort((a, b) => a.id.localeCompare(b.id)),
@@ -4239,7 +4291,7 @@ Before making code changes or answering implementation questions:
4239
4291
  1. Call kage_context with project_dir and the user task as query.
4240
4292
  2. Use returned memory only when it is relevant, source-backed, and not stale.
4241
4293
  When you learn something reusable: kage_learn.
4242
- After meaningful file changes: kage_refresh.
4294
+ After meaningful file/content changes: kage_refresh. Push-only or same-tree commits do not need another refresh.
4243
4295
  Before finishing a task that changed files: kage_pr_summarize or kage_propose_from_diff, then kage_pr_check.
4244
4296
  If recalled memory helped: kage_feedback helpful. If wrong or stale: kage_feedback wrong or stale."
4245
4297
  fi
@@ -4963,15 +5015,22 @@ function createReviewArtifact(projectDir) {
4963
5015
  (0, node_fs_1.writeFileSync)(path, `${lines.join("\n").trim()}\n`, "utf8");
4964
5016
  return { path, pending: pending.length };
4965
5017
  }
4966
- function graphIsCurrent(projectDir, relativePath, head) {
5018
+ function graphIsCurrent(projectDir, relativePath, expected) {
4967
5019
  const path = (0, node_path_1.join)(projectDir, relativePath);
4968
5020
  if (!(0, node_fs_1.existsSync)(path))
4969
5021
  return false;
4970
- if (!head)
4971
- return true;
4972
5022
  try {
4973
5023
  const graph = readJson(path);
4974
- return graph.repo_state?.head === head;
5024
+ const repoState = graph.repo_state;
5025
+ if (!repoState)
5026
+ return false;
5027
+ if (expected.inputHash && repoState.input_hash)
5028
+ return repoState.input_hash === expected.inputHash;
5029
+ if (expected.tree && repoState.tree)
5030
+ return repoState.tree === expected.tree;
5031
+ if (!expected.head)
5032
+ return true;
5033
+ return repoState.head === expected.head;
4975
5034
  }
4976
5035
  catch {
4977
5036
  return false;
@@ -5005,6 +5064,9 @@ function prCheck(projectDir) {
5005
5064
  const overlay = buildBranchOverlay(projectDir);
5006
5065
  const rawStatus = readGit(projectDir, ["status", "--porcelain", "-uall"]) ?? "";
5007
5066
  const validation = validateProject(projectDir);
5067
+ const tree = gitTree(projectDir);
5068
+ const codeInputHash = codeGraphInputHash(projectDir);
5069
+ const memoryInputHash = knowledgeGraphInputHash(projectDir, codeInputHash);
5008
5070
  const stalePackets = loadPacketsFromDir(packetsDir(projectDir))
5009
5071
  .map((packet) => ({ packet, reasons: staleMemoryReasons(projectDir, packet) }))
5010
5072
  .filter((entry) => entry.reasons.length)
@@ -5014,8 +5076,8 @@ function prCheck(projectDir) {
5014
5076
  .map(parsePorcelainPath)
5015
5077
  .map((path) => path.replace(/^.* -> /, ""))
5016
5078
  .filter((path) => path.startsWith(".agent_memory/packets/") && path.endsWith(".json"))).sort();
5017
- const codeGraphCurrent = graphIsCurrent(projectDir, ".agent_memory/code_graph/graph.json", overlay.head);
5018
- const memoryGraphCurrent = graphIsCurrent(projectDir, ".agent_memory/graph/graph.json", overlay.head);
5079
+ const codeGraphCurrent = graphIsCurrent(projectDir, ".agent_memory/code_graph/graph.json", { head: overlay.head, tree, inputHash: codeInputHash });
5080
+ const memoryGraphCurrent = graphIsCurrent(projectDir, ".agent_memory/graph/graph.json", { head: overlay.head, tree, inputHash: memoryInputHash });
5019
5081
  const errors = [...validation.errors];
5020
5082
  const warnings = [...validation.warnings];
5021
5083
  const requiredActions = [];
@@ -5024,7 +5086,7 @@ function prCheck(projectDir) {
5024
5086
  requiredActions.push("Run kage refresh, then update or supersede stale packets.");
5025
5087
  }
5026
5088
  if (!codeGraphCurrent || !memoryGraphCurrent) {
5027
- errors.push("Generated graph artifacts are missing or not current for this branch head.");
5089
+ errors.push("Generated graph artifacts are missing or not current for this working tree content.");
5028
5090
  requiredActions.push("Run kage refresh --project <dir> before merge.");
5029
5091
  }
5030
5092
  if (!memoryPacketChanges.length && overlay.changed_files.some((path) => !path.startsWith(".agent_memory/"))) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kage-core/kage-graph-mcp",
3
- "version": "1.1.16",
3
+ "version": "1.1.17",
4
4
  "description": "Local-first repo memory, code graph, and recall MCP server for coding agents",
5
5
  "main": "dist/index.js",
6
6
  "files": [