@kage-core/kage-graph-mcp 1.1.2 → 1.1.3

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
@@ -27,6 +27,7 @@ kage init --project /path/to/repo
27
27
  kage policy --project /path/to/repo
28
28
  kage doctor --project /path/to/repo
29
29
  kage index --project /path/to/repo
30
+ kage refresh --project /path/to/repo
30
31
  kage branch --project /path/to/repo
31
32
  kage code-graph --project /path/to/repo
32
33
  kage code-graph "createApp routes tests" --project /path/to/repo
@@ -45,6 +46,8 @@ kage learn --project /path/to/repo --learning "Decision: use kage_learn for actu
45
46
  kage feedback --project /path/to/repo --packet <approved-packet-id> --kind stale
46
47
  kage capture --project /path/to/repo --type runbook --title "Webhook tests" --body "Run pnpm test:api -- webhooks."
47
48
  kage propose --project /path/to/repo --from-diff
49
+ kage pr summarize --project /path/to/repo
50
+ kage pr check --project /path/to/repo
48
51
  kage review-artifact --project /path/to/repo
49
52
  kage registry --project /path/to/repo
50
53
  kage marketplace --project /path/to/repo
@@ -57,6 +60,7 @@ kage layered-recall "how do I run tests" --project /path/to/repo --org acme --gl
57
60
  kage global build --project /path/to/repo --org acme
58
61
  kage review --project /path/to/repo
59
62
  kage validate --project /path/to/repo
63
+ kage upgrade --dry-run
60
64
  ```
61
65
 
62
66
  `kage init` is the first-run command. It creates `.agent_memory/`, migrates
@@ -121,6 +125,16 @@ and parser coverage, code graph counts, evidence coverage, approved vs pending
121
125
  memory, validation status, estimated tokens saved per recall, duplicate
122
126
  candidates, average memory quality, and a readiness score.
123
127
 
128
+ Use `kage refresh --project <repo>` or the `kage_refresh` MCP tool after
129
+ meaningful file changes. Refresh rebuilds indexes, code graph, memory graph,
130
+ metrics, and stale-memory metadata. Memory is marked stale when status or
131
+ feedback says it is stale, its TTL expires, or grounded paths disappear.
132
+
133
+ Use `kage pr summarize --project <repo>` / `kage_pr_summarize` before handoff to
134
+ write branch review metadata and repo-local change memory from the git diff.
135
+ Use `kage pr check --project <repo>` / `kage_pr_check` before merge to verify
136
+ validation, graph freshness, stale packets, and memory packet changes.
137
+
124
138
  Review artifacts include memory quality reasons, risks, duplicate candidates,
125
139
  and estimated token savings for legacy pending/quarantine packets and promotion
126
140
  review.
@@ -185,6 +199,9 @@ Local repo tools:
185
199
  - `kage_recall`
186
200
  - `kage_code_graph`
187
201
  - `kage_metrics`
202
+ - `kage_refresh`
203
+ - `kage_pr_summarize`
204
+ - `kage_pr_check`
188
205
  - `kage_quality`
189
206
  - `kage_benchmark`
190
207
  - `kage_setup_agent`
@@ -267,8 +284,10 @@ Before code changes or repo-specific answers:
267
284
  2. Call `kage_recall` with the user task as the query.
268
285
  3. Call `kage_graph` with the user task as the query.
269
286
  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.
287
+ 5. After meaningful file changes, call `kage_refresh`.
288
+ 6. Before finishing changed-file tasks, call `kage_propose_from_diff` or `kage_pr_summarize`.
289
+ 7. Before merge, call `kage_pr_check`.
290
+ 8. Never publish or promote org/global memory automatically.
272
291
  ```
273
292
 
274
293
  Run `kage setup verify-agent --agent codex --project <repo>` after setup. The
package/dist/cli.js CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
+ const node_child_process_1 = require("node:child_process");
4
5
  const promises_1 = require("node:readline/promises");
5
6
  const node_process_1 = require("node:process");
6
7
  const daemon_js_1 = require("./daemon.js");
@@ -22,6 +23,10 @@ Usage:
22
23
  kage daemon status --project <dir> [--json]
23
24
  kage daemon doctor --project <dir> [--json]
24
25
  kage viewer --project <dir> [--port 3113]
26
+ kage refresh --project <dir> [--json]
27
+ kage pr summarize --project <dir> [--json]
28
+ kage pr check --project <dir> [--json]
29
+ kage upgrade [--dry-run]
25
30
  kage branch --project <dir> [--json]
26
31
  kage metrics --project <dir> [--json]
27
32
  kage quality --project <dir> [--json]
@@ -296,6 +301,97 @@ async function main() {
296
301
  await (0, daemon_js_1.startViewer)(projectArg(args), { port: numberArg(args, "--port", 3113) });
297
302
  return;
298
303
  }
304
+ if (command === "refresh") {
305
+ const result = (0, kernel_js_1.refreshProject)(projectArg(args));
306
+ if (args.includes("--json")) {
307
+ console.log(JSON.stringify(result, null, 2));
308
+ if (!result.ok)
309
+ process.exit(2);
310
+ return;
311
+ }
312
+ console.log(`Refreshed ${result.project_dir}`);
313
+ console.log(`Packets indexed: ${result.index.packets}`);
314
+ console.log(`Packet metadata updated: ${result.updated_packets}`);
315
+ console.log(`Code graph: ${result.code_graph.files} files, ${result.code_graph.symbols} symbols, ${result.code_graph.imports} imports, ${result.code_graph.calls} calls`);
316
+ console.log(`Memory graph: ${result.memory_graph.entities} entities, ${result.memory_graph.edges} edges, ${result.memory_graph.episodes} episodes`);
317
+ console.log(`Stale packets: ${result.stale_packets.length}`);
318
+ for (const packet of result.stale_packets.slice(0, 8)) {
319
+ console.log(` - ${packet.title} (${packet.id}): ${packet.reasons.join("; ")}`);
320
+ }
321
+ console.log(result.validation.ok ? "Validation: passed" : "Validation: failed");
322
+ if (result.validation.errors.length)
323
+ console.log(`Errors:\n${result.validation.errors.map((error) => ` - ${error}`).join("\n")}`);
324
+ if (result.validation.warnings.length)
325
+ console.log(`Warnings:\n${result.validation.warnings.map((warning) => ` - ${warning}`).join("\n")}`);
326
+ console.log(`Next actions:\n${result.next_actions.map((action) => ` - ${action}`).join("\n")}`);
327
+ if (!result.ok)
328
+ process.exit(2);
329
+ return;
330
+ }
331
+ if (command === "pr") {
332
+ const action = args[1];
333
+ if (action === "summarize") {
334
+ const result = (0, kernel_js_1.prSummarize)(projectArg(args));
335
+ if (args.includes("--json")) {
336
+ console.log(JSON.stringify(result, null, 2));
337
+ if (!result.ok)
338
+ process.exit(2);
339
+ return;
340
+ }
341
+ console.log(`PR summary for ${result.project_dir}`);
342
+ console.log(`Branch: ${result.branch ?? "(detached)"}`);
343
+ console.log(`Changed files: ${result.changed_files.join(", ") || "(none)"}`);
344
+ if (result.diff_memory_packet_id)
345
+ console.log(`Repo memory: ${result.diff_memory_packet_id}`);
346
+ if (result.branch_summary_path)
347
+ console.log(`Branch summary: ${result.branch_summary_path}`);
348
+ if (result.review_artifact_path)
349
+ console.log(`Review artifact: ${result.review_artifact_path}`);
350
+ if (result.warnings.length)
351
+ console.log(`Warnings:\n${result.warnings.map((warning) => ` - ${warning}`).join("\n")}`);
352
+ if (result.errors.length)
353
+ console.log(`Errors:\n${result.errors.map((error) => ` - ${error}`).join("\n")}`);
354
+ if (!result.ok)
355
+ process.exit(2);
356
+ return;
357
+ }
358
+ if (action === "check") {
359
+ const result = (0, kernel_js_1.prCheck)(projectArg(args));
360
+ if (args.includes("--json")) {
361
+ console.log(JSON.stringify(result, null, 2));
362
+ if (!result.ok)
363
+ process.exit(2);
364
+ return;
365
+ }
366
+ console.log(`PR memory check for ${result.project_dir}`);
367
+ console.log(`Branch: ${result.branch ?? "(detached)"}`);
368
+ console.log(`Changed files: ${result.changed_files.length}`);
369
+ console.log(`Memory packet changes: ${result.memory_packet_changes.length}`);
370
+ console.log(`Code graph current: ${result.code_graph_current ? "yes" : "no"}`);
371
+ console.log(`Memory graph current: ${result.memory_graph_current ? "yes" : "no"}`);
372
+ console.log(`Stale packets: ${result.stale_packets.length}`);
373
+ if (result.warnings.length)
374
+ console.log(`Warnings:\n${result.warnings.map((warning) => ` - ${warning}`).join("\n")}`);
375
+ if (result.errors.length)
376
+ console.log(`Errors:\n${result.errors.map((error) => ` - ${error}`).join("\n")}`);
377
+ console.log(`Required actions:\n${result.required_actions.map((action) => ` - ${action}`).join("\n")}`);
378
+ if (!result.ok)
379
+ process.exit(2);
380
+ return;
381
+ }
382
+ usage();
383
+ }
384
+ if (command === "upgrade") {
385
+ const commandLine = "npm install -g @kage-core/kage-graph-mcp@latest";
386
+ if (args.includes("--dry-run")) {
387
+ console.log(commandLine);
388
+ return;
389
+ }
390
+ console.log(`Running: ${commandLine}`);
391
+ (0, node_child_process_1.execFileSync)("npm", ["install", "-g", "@kage-core/kage-graph-mcp@latest"], { stdio: "inherit" });
392
+ console.log("Kage upgraded. Restart Codex or Claude Code so the MCP process reloads the new package.");
393
+ return;
394
+ }
299
395
  if (command === "graph") {
300
396
  const query = firstPositional(args);
301
397
  if (query) {
package/dist/index.js CHANGED
@@ -154,6 +154,39 @@ function listTools() {
154
154
  required: ["project_dir"],
155
155
  },
156
156
  },
157
+ {
158
+ name: "kage_refresh",
159
+ 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.",
160
+ inputSchema: {
161
+ type: "object",
162
+ properties: {
163
+ project_dir: { type: "string" },
164
+ },
165
+ required: ["project_dir"],
166
+ },
167
+ },
168
+ {
169
+ name: "kage_pr_summarize",
170
+ description: "Create a PR/branch memory summary from local git diff metadata and write repo-local change memory. Use when a branch is ready to hand off.",
171
+ inputSchema: {
172
+ type: "object",
173
+ properties: {
174
+ project_dir: { type: "string" },
175
+ },
176
+ required: ["project_dir"],
177
+ },
178
+ },
179
+ {
180
+ name: "kage_pr_check",
181
+ description: "Check whether repo memory, code graph, memory graph, and stale-memory state are ready for merge.",
182
+ inputSchema: {
183
+ type: "object",
184
+ properties: {
185
+ project_dir: { type: "string" },
186
+ },
187
+ required: ["project_dir"],
188
+ },
189
+ },
157
190
  {
158
191
  name: "kage_quality",
159
192
  description: "Return memory quality metrics: useful memory ratio, duplicate burden, stale/wrong feedback, evidence coverage, path grounding, and review queue size.",
@@ -595,6 +628,27 @@ async function callTool(name, args) {
595
628
  content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
596
629
  };
597
630
  }
631
+ if (name === "kage_refresh") {
632
+ const result = (0, kernel_js_1.refreshProject)(String(args?.project_dir ?? ""));
633
+ return {
634
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
635
+ isError: !result.ok,
636
+ };
637
+ }
638
+ if (name === "kage_pr_summarize") {
639
+ const result = (0, kernel_js_1.prSummarize)(String(args?.project_dir ?? ""));
640
+ return {
641
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
642
+ isError: !result.ok,
643
+ };
644
+ }
645
+ if (name === "kage_pr_check") {
646
+ const result = (0, kernel_js_1.prCheck)(String(args?.project_dir ?? ""));
647
+ return {
648
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }],
649
+ isError: !result.ok,
650
+ };
651
+ }
598
652
  if (name === "kage_quality") {
599
653
  const result = (0, kernel_js_1.qualityReport)(String(args?.project_dir ?? ""));
600
654
  return {
package/dist/kernel.js CHANGED
@@ -66,6 +66,7 @@ exports.buildCodeGraph = buildCodeGraph;
66
66
  exports.buildKnowledgeGraph = buildKnowledgeGraph;
67
67
  exports.buildIndexes = buildIndexes;
68
68
  exports.indexProject = indexProject;
69
+ exports.refreshProject = refreshProject;
69
70
  exports.installAgentPolicy = installAgentPolicy;
70
71
  exports.recall = recall;
71
72
  exports.queryCodeGraph = queryCodeGraph;
@@ -86,6 +87,8 @@ exports.distillSession = distillSession;
86
87
  exports.proposeFromDiff = proposeFromDiff;
87
88
  exports.buildBranchOverlay = buildBranchOverlay;
88
89
  exports.createReviewArtifact = createReviewArtifact;
90
+ exports.prSummarize = prSummarize;
91
+ exports.prCheck = prCheck;
89
92
  exports.exportPublicBundle = exportPublicBundle;
90
93
  exports.orgStatus = orgStatus;
91
94
  exports.orgUploadPacket = orgUploadPacket;
@@ -447,12 +450,41 @@ function packetFeedbackScore(packet) {
447
450
  const quality = packet.quality;
448
451
  return Number(quality.votes_up ?? 0) * 2 - Number(quality.votes_down ?? 0) * 3 - Number(quality.reports_stale ?? 0) * 4;
449
452
  }
453
+ function meaningfulMemoryPath(path) {
454
+ return path !== "root" && path !== "." && !isNoisePath(path);
455
+ }
456
+ function staleMemoryReasons(projectDir, packet) {
457
+ const reasons = [];
458
+ const quality = packet.quality;
459
+ const freshness = packet.freshness;
460
+ if (packet.status === "deprecated" || packet.status === "superseded") {
461
+ reasons.push(`packet status is ${packet.status}`);
462
+ }
463
+ if (Number(quality.reports_stale ?? 0) > 0) {
464
+ reasons.push("user or agent reported this memory stale");
465
+ }
466
+ const ttlDays = Number(freshness.ttl_days ?? freshness.ttlDays ?? 0);
467
+ const verifiedAt = Date.parse(String(freshness.last_verified_at ?? packet.updated_at ?? packet.created_at));
468
+ if (Number.isFinite(ttlDays) && ttlDays > 0 && Number.isFinite(verifiedAt)) {
469
+ const ageDays = (Date.now() - verifiedAt) / (1000 * 60 * 60 * 24);
470
+ if (ageDays > ttlDays)
471
+ reasons.push(`freshness ttl expired (${Math.floor(ageDays)}d old, ttl ${ttlDays}d)`);
472
+ }
473
+ const paths = packet.paths.filter(meaningfulMemoryPath);
474
+ const missingPaths = paths.filter((path) => !(0, node_fs_1.existsSync)((0, node_path_1.join)(projectDir, path)));
475
+ if (paths.length > 0 && missingPaths.length === paths.length) {
476
+ reasons.push(`all referenced paths are missing: ${missingPaths.slice(0, 4).join(", ")}`);
477
+ }
478
+ else if (missingPaths.length > 0) {
479
+ reasons.push(`some referenced paths are missing: ${missingPaths.slice(0, 4).join(", ")}`);
480
+ }
481
+ return unique(reasons);
482
+ }
450
483
  function classifyPacket(projectDir, packet) {
451
484
  const quality = evaluateMemoryQuality(projectDir, packet);
452
485
  const score = Number(quality.score);
453
486
  const duplicates = quality.duplicate_candidates;
454
- const q = packet.quality;
455
- if (Number(q.reports_stale ?? 0) > 0 || packet.status === "deprecated" || packet.status === "superseded")
487
+ if (staleMemoryReasons(projectDir, packet).length)
456
488
  return "stale";
457
489
  if (duplicates.length)
458
490
  return "duplicate";
@@ -522,11 +554,17 @@ function evaluateMemoryQuality(projectDir, packet) {
522
554
  score -= 18;
523
555
  risks.push("possible duplicate memory");
524
556
  }
557
+ const staleReasons = staleMemoryReasons(projectDir, packet);
558
+ if (staleReasons.length) {
559
+ score -= 22;
560
+ risks.push(...staleReasons);
561
+ }
525
562
  return {
526
563
  score: Math.max(0, Math.min(100, score)),
527
564
  reasons,
528
565
  risks,
529
566
  duplicate_candidates: duplicates,
567
+ stale_reasons: staleReasons,
530
568
  estimated_tokens_saved: Math.max(40, estimateTokens(packet.body) * 2),
531
569
  };
532
570
  }
@@ -769,6 +807,17 @@ function loadPacketsFromDir(dir) {
769
807
  .sort()
770
808
  .map((name) => readJson((0, node_path_1.join)(dir, name)));
771
809
  }
810
+ function loadPacketEntriesFromDir(dir) {
811
+ if (!(0, node_fs_1.existsSync)(dir))
812
+ return [];
813
+ return (0, node_fs_1.readdirSync)(dir)
814
+ .filter((name) => name.endsWith(".json"))
815
+ .sort()
816
+ .map((name) => {
817
+ const path = (0, node_path_1.join)(dir, name);
818
+ return { path, packet: readJson(path) };
819
+ });
820
+ }
772
821
  function loadApprovedPackets(projectDir) {
773
822
  return loadPacketsFromDir(packetsDir(projectDir)).filter((packet) => packet.status === "approved");
774
823
  }
@@ -837,14 +886,15 @@ function isNoisePath(filePath) {
837
886
  function parsePorcelainStatus(status) {
838
887
  return unique(status
839
888
  .split(/\r?\n/)
840
- .map((line) => {
841
- const raw = line.length > 2 && line[2] === " " ? line.slice(3) : line.slice(2);
842
- return raw.trim();
843
- })
889
+ .map(parsePorcelainPath)
844
890
  .map((path) => path.replace(/^.* -> /, ""))
845
891
  .filter(Boolean)
846
892
  .filter((path) => !shouldSkipRepoMemoryPath(path))).sort();
847
893
  }
894
+ function parsePorcelainPath(line) {
895
+ const raw = line.length > 2 && line[2] === " " ? line.slice(3) : line.slice(2);
896
+ return raw.trim();
897
+ }
848
898
  function shouldSkipRepoMemoryPath(relativePath) {
849
899
  return isNoisePath(relativePath) || shouldSkipCodePath(relativePath);
850
900
  }
@@ -2342,6 +2392,104 @@ function indexProject(projectDir) {
2342
2392
  policyPath: (0, node_path_1.relative)(projectDir, policy.path),
2343
2393
  };
2344
2394
  }
2395
+ function staleSuggestedAction(reasons) {
2396
+ if (reasons.some((reason) => reason.includes("status is")))
2397
+ return "mark_stale";
2398
+ if (reasons.some((reason) => reason.includes("missing")))
2399
+ return "update";
2400
+ if (reasons.some((reason) => reason.includes("reported")))
2401
+ return "supersede";
2402
+ return "verify";
2403
+ }
2404
+ function staleFinding(packet, reasons) {
2405
+ return {
2406
+ id: packet.id,
2407
+ title: packet.title,
2408
+ type: packet.type,
2409
+ status: packet.status,
2410
+ paths: packet.paths,
2411
+ reasons,
2412
+ suggested_action: staleSuggestedAction(reasons),
2413
+ };
2414
+ }
2415
+ function refreshPacketStaleness(projectDir) {
2416
+ const findings = [];
2417
+ let updated = 0;
2418
+ for (const entry of loadPacketEntriesFromDir(packetsDir(projectDir))) {
2419
+ const reasons = staleMemoryReasons(projectDir, entry.packet);
2420
+ const oldQuality = entry.packet.quality;
2421
+ const oldFreshness = entry.packet.freshness;
2422
+ let nextQuality;
2423
+ if (reasons.length) {
2424
+ const finding = staleFinding(entry.packet, reasons);
2425
+ findings.push(finding);
2426
+ nextQuality = {
2427
+ ...oldQuality,
2428
+ stale: true,
2429
+ stale_reasons: reasons,
2430
+ suggested_action: finding.suggested_action,
2431
+ };
2432
+ }
2433
+ else {
2434
+ const { stale: _stale, stale_reasons: _staleReasons, suggested_action: _suggestedAction, ...rest } = oldQuality;
2435
+ nextQuality = rest;
2436
+ }
2437
+ const nextFreshness = oldFreshness;
2438
+ const changed = JSON.stringify(oldQuality) !== JSON.stringify(nextQuality)
2439
+ || JSON.stringify(oldFreshness) !== JSON.stringify(nextFreshness);
2440
+ if (changed) {
2441
+ writeJson(entry.path, {
2442
+ ...entry.packet,
2443
+ freshness: nextFreshness,
2444
+ quality: nextQuality,
2445
+ updated_at: nowIso(),
2446
+ });
2447
+ updated += 1;
2448
+ }
2449
+ }
2450
+ return { findings, updated };
2451
+ }
2452
+ function refreshProject(projectDir) {
2453
+ const index = indexProject(projectDir);
2454
+ const stale = refreshPacketStaleness(projectDir);
2455
+ const indexes = stale.updated > 0 ? buildIndexes(projectDir).map((path) => (0, node_path_1.relative)(projectDir, path)) : index.indexes;
2456
+ const validation = validateProject(projectDir);
2457
+ const metrics = kageMetrics(projectDir);
2458
+ const nextActions = [];
2459
+ if (stale.findings.length)
2460
+ nextActions.push("Update, verify, or supersede stale repo memories before relying on them.");
2461
+ if (!validation.ok)
2462
+ nextActions.push("Fix validation errors before merging or sharing memory.");
2463
+ if (validation.warnings.length)
2464
+ nextActions.push("Review validation warnings for grounding, indexes, or generated artifacts.");
2465
+ if (!nextActions.length)
2466
+ nextActions.push("Repo memory, code graph, and indexes are current.");
2467
+ return {
2468
+ ok: validation.ok,
2469
+ project_dir: projectDir,
2470
+ generated_at: nowIso(),
2471
+ index,
2472
+ validation,
2473
+ metrics,
2474
+ stale_packets: stale.findings,
2475
+ updated_packets: stale.updated,
2476
+ indexes,
2477
+ code_graph: {
2478
+ files: metrics.code_graph.files,
2479
+ symbols: metrics.code_graph.symbols,
2480
+ imports: metrics.code_graph.imports,
2481
+ calls: metrics.code_graph.calls,
2482
+ routes: metrics.code_graph.routes,
2483
+ tests: metrics.code_graph.tests,
2484
+ },
2485
+ memory_graph: {
2486
+ entities: metrics.memory_graph.entities,
2487
+ edges: metrics.memory_graph.edges,
2488
+ episodes: metrics.memory_graph.episodes,
2489
+ },
2490
+ next_actions: nextActions,
2491
+ };
2492
+ }
2345
2493
  function installAgentPolicy(projectDir) {
2346
2494
  const agentsPath = (0, node_path_1.join)(projectDir, "AGENTS.md");
2347
2495
  const claudePath = (0, node_path_1.join)(projectDir, "CLAUDE.md");
@@ -3847,7 +3995,7 @@ function proposeFromDiff(projectDir) {
3847
3995
  }
3848
3996
  function buildBranchOverlay(projectDir) {
3849
3997
  ensureMemoryDirs(projectDir);
3850
- const status = readGit(projectDir, ["status", "--porcelain"]) ?? "";
3998
+ const status = readGit(projectDir, ["status", "--porcelain", "-uall"]) ?? "";
3851
3999
  const overlay = {
3852
4000
  schema_version: 1,
3853
4001
  project_dir: projectDir,
@@ -3925,6 +4073,91 @@ function createReviewArtifact(projectDir) {
3925
4073
  (0, node_fs_1.writeFileSync)(path, `${lines.join("\n").trim()}\n`, "utf8");
3926
4074
  return { path, pending: pending.length };
3927
4075
  }
4076
+ function graphIsCurrent(projectDir, relativePath, head) {
4077
+ const path = (0, node_path_1.join)(projectDir, relativePath);
4078
+ if (!(0, node_fs_1.existsSync)(path))
4079
+ return false;
4080
+ if (!head)
4081
+ return true;
4082
+ try {
4083
+ const graph = readJson(path);
4084
+ return graph.repo_state?.head === head;
4085
+ }
4086
+ catch {
4087
+ return false;
4088
+ }
4089
+ }
4090
+ function prSummarize(projectDir) {
4091
+ ensureMemoryDirs(projectDir);
4092
+ const proposal = proposeFromDiff(projectDir);
4093
+ const artifact = createReviewArtifact(projectDir);
4094
+ const validation = validateProject(projectDir);
4095
+ const warnings = [...validation.warnings];
4096
+ if (!proposal.ok)
4097
+ warnings.push(...proposal.errors);
4098
+ return {
4099
+ ok: proposal.ok && validation.ok,
4100
+ project_dir: projectDir,
4101
+ branch: gitBranch(projectDir),
4102
+ head: gitHead(projectDir),
4103
+ changed_files: proposal.changedFiles,
4104
+ diff_memory_packet_id: proposal.packet?.id,
4105
+ diff_memory_packet_path: proposal.packetPath,
4106
+ branch_summary_path: proposal.path,
4107
+ review_artifact_path: artifact.path,
4108
+ validation,
4109
+ errors: validation.errors,
4110
+ warnings,
4111
+ };
4112
+ }
4113
+ function prCheck(projectDir) {
4114
+ ensureMemoryDirs(projectDir);
4115
+ const overlay = buildBranchOverlay(projectDir);
4116
+ const rawStatus = readGit(projectDir, ["status", "--porcelain", "-uall"]) ?? "";
4117
+ const validation = validateProject(projectDir);
4118
+ const stalePackets = loadPacketsFromDir(packetsDir(projectDir))
4119
+ .map((packet) => ({ packet, reasons: staleMemoryReasons(projectDir, packet) }))
4120
+ .filter((entry) => entry.reasons.length)
4121
+ .map((entry) => staleFinding(entry.packet, entry.reasons));
4122
+ const memoryPacketChanges = unique(rawStatus
4123
+ .split(/\r?\n/)
4124
+ .map(parsePorcelainPath)
4125
+ .map((path) => path.replace(/^.* -> /, ""))
4126
+ .filter((path) => path.startsWith(".agent_memory/packets/") && path.endsWith(".json"))).sort();
4127
+ const codeGraphCurrent = graphIsCurrent(projectDir, ".agent_memory/code_graph/graph.json", overlay.head);
4128
+ const memoryGraphCurrent = graphIsCurrent(projectDir, ".agent_memory/graph/graph.json", overlay.head);
4129
+ const errors = [...validation.errors];
4130
+ const warnings = [...validation.warnings];
4131
+ const requiredActions = [];
4132
+ if (stalePackets.length) {
4133
+ errors.push(`${stalePackets.length} stale memory packet(s) require update, verification, or supersession.`);
4134
+ requiredActions.push("Run kage refresh, then update or supersede stale packets.");
4135
+ }
4136
+ if (!codeGraphCurrent || !memoryGraphCurrent) {
4137
+ errors.push("Generated graph artifacts are missing or not current for this branch head.");
4138
+ requiredActions.push("Run kage refresh --project <dir> before merge.");
4139
+ }
4140
+ if (!memoryPacketChanges.length && overlay.changed_files.some((path) => !path.startsWith(".agent_memory/"))) {
4141
+ warnings.push("No repo memory packet changed for this branch. If durable knowledge was learned, run kage propose --from-diff or kage learn.");
4142
+ }
4143
+ if (!requiredActions.length)
4144
+ requiredActions.push("PR memory and graph checks passed.");
4145
+ return {
4146
+ ok: errors.length === 0,
4147
+ project_dir: projectDir,
4148
+ branch: overlay.branch,
4149
+ head: overlay.head,
4150
+ changed_files: overlay.changed_files,
4151
+ validation,
4152
+ stale_packets: stalePackets,
4153
+ memory_packet_changes: memoryPacketChanges,
4154
+ code_graph_current: codeGraphCurrent,
4155
+ memory_graph_current: memoryGraphCurrent,
4156
+ errors,
4157
+ warnings,
4158
+ required_actions: requiredActions,
4159
+ };
4160
+ }
3928
4161
  function exportPublicBundle(projectDir) {
3929
4162
  ensureMemoryDirs(projectDir);
3930
4163
  const candidates = loadPacketsFromDir(publicCandidatesDir(projectDir));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kage-core/kage-graph-mcp",
3
- "version": "1.1.2",
3
+ "version": "1.1.3",
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": [