kibi-mcp 0.21.1 → 0.22.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.
@@ -1,4 +1,4 @@
1
- import { stat } from "node:fs/promises";
1
+ import { readFile, stat } from "node:fs/promises";
2
2
  import path from "node:path";
3
3
  export class KbRefreshError extends Error {
4
4
  constructor(message) {
@@ -21,7 +21,17 @@ export async function readBranchKbStamp(branchPath) {
21
21
  stamp.dirMissing = true;
22
22
  errors.push(formatStatError(branchPath, error));
23
23
  }
24
- const rdfPath = path.join(branchPath, "kb.rdf");
24
+ const markerPath = path.join(branchPath, "storage.json");
25
+ let journaled = false;
26
+ try {
27
+ journaled = (await readFile(markerPath, "utf8")).includes("kibi.rdf-journal.v1");
28
+ }
29
+ catch {
30
+ journaled = false;
31
+ }
32
+ // Journaled stores expose CURRENT as their cheap, atomic freshness marker;
33
+ // legacy stores retain kb.rdf for compatibility.
34
+ const rdfPath = path.join(branchPath, journaled ? "CURRENT" : "kb.rdf");
25
35
  try {
26
36
  const rdfStat = await stat(rdfPath);
27
37
  stamp.rdfDev = rdfStat.dev;
@@ -18,6 +18,7 @@
18
18
  import fs from "node:fs";
19
19
  import { createRequire } from "node:module";
20
20
  import process from "node:process";
21
+ import { EngineClient } from "kibi-cli/engine";
21
22
  import { PrologProcess } from "kibi-cli/prolog";
22
23
  import { copyCleanSnapshot, getBranchDiagnostic, isValidBranchName, resolveActiveBranch, } from "kibi-cli/public/branch-resolver";
23
24
  import { getBranchOverride, isMcpDebugEnabled } from "../env.js";
@@ -202,6 +203,7 @@ function usesBranchKbPath(kbPath) {
202
203
  async function ensurePrologUnsafe() {
203
204
  const generationAtStart = prologResetGeneration;
204
205
  const workspaceRoot = sessionDeps.resolveWorkspaceRoot();
206
+ const useEngine = sessionDeps.PrologProcess === defaultSessionDeps.PrologProcess;
205
207
  const assertGeneration = async () => {
206
208
  if (generationAtStart !== prologResetGeneration) {
207
209
  const current = prologProcess;
@@ -236,6 +238,19 @@ async function ensurePrologUnsafe() {
236
238
  targetBranch = branchResult.branch;
237
239
  }
238
240
  // Check if we need to switch branches
241
+ if (isInitialized && useEngine && prologProcess?.isRunning()) {
242
+ const kbPath = sessionDeps.resolveKbPath(workspaceRoot, targetBranch);
243
+ if (targetBranch === activeBranchName) {
244
+ attachedBranchKbPath = kbPath;
245
+ attachedBranchStamp = await readBranchKbStamp(kbPath);
246
+ return prologProcess;
247
+ }
248
+ await prologProcess.terminate();
249
+ prologProcess = null;
250
+ isInitialized = false;
251
+ attachedBranchKbPath = null;
252
+ attachedBranchStamp = null;
253
+ }
239
254
  if (isInitialized && prologProcess?.isRunning()) {
240
255
  const kbPath = sessionDeps.resolveKbPath(workspaceRoot, targetBranch);
241
256
  if (targetBranch === activeBranchName) {
@@ -298,7 +313,13 @@ async function ensurePrologUnsafe() {
298
313
  }
299
314
  // First initialization
300
315
  debugLog("[KIBI-MCP] Initializing Prolog process...");
301
- prologProcess = new sessionDeps.PrologProcess({ timeout: 120000 });
316
+ prologProcess = useEngine
317
+ ? new EngineClient({
318
+ workspaceRoot,
319
+ branch: targetBranch,
320
+ timeout: 120000,
321
+ })
322
+ : new sessionDeps.PrologProcess({ timeout: 120000 });
302
323
  await prologProcess.start();
303
324
  await assertGeneration();
304
325
  // Startup debug: resolve which kibi-cli is being used and its version (best-effort).
@@ -340,16 +361,18 @@ async function ensurePrologUnsafe() {
340
361
  activeBranchName = targetBranch;
341
362
  const createdEmptyBranch = ensureBranchKbExists(workspaceRoot, targetBranch);
342
363
  const kbPath = sessionDeps.resolveKbPath(workspaceRoot, targetBranch);
343
- const attachResult = await prologProcess.query(`kb_attach('${kbPath}')`);
344
- await assertGeneration();
345
- if (!attachResult.success) {
346
- throw new Error(`Failed to attach KB: ${attachResult.error || "Unknown error"}`);
347
- }
348
- if (createdEmptyBranch) {
349
- const initialSaveResult = await prologProcess.query("kb_save");
364
+ if (!useEngine) {
365
+ const attachResult = await prologProcess.query(`kb_attach('${kbPath}')`);
350
366
  await assertGeneration();
351
- if (!initialSaveResult.success) {
352
- throw new Error(`Failed to initialize empty branch KB: ${initialSaveResult.error || "Unknown error"}`);
367
+ if (!attachResult.success) {
368
+ throw new Error(`Failed to attach KB: ${attachResult.error || "Unknown error"}`);
369
+ }
370
+ if (createdEmptyBranch) {
371
+ const initialSaveResult = await prologProcess.query("kb_save");
372
+ await assertGeneration();
373
+ if (!initialSaveResult.success) {
374
+ throw new Error(`Failed to initialize empty branch KB: ${initialSaveResult.error || "Unknown error"}`);
375
+ }
353
376
  }
354
377
  }
355
378
  attachedBranchKbPath = kbPath;
@@ -62,6 +62,30 @@ function adaptProlog(prolog) {
62
62
  return result;
63
63
  },
64
64
  save: () => prolog.query("kb_save"),
65
+ ...(typeof prolog.queryEntities ===
66
+ "function"
67
+ ? {
68
+ queryEntities: (input) => prolog.queryEntities(input),
69
+ }
70
+ : {}),
71
+ ...(typeof prolog.searchEntities ===
72
+ "function"
73
+ ? {
74
+ searchEntities: (input) => prolog.searchEntities(input),
75
+ }
76
+ : {}),
77
+ ...(typeof prolog.storageStatus ===
78
+ "function"
79
+ ? {
80
+ storageStatus: () => prolog.storageStatus(),
81
+ }
82
+ : {}),
83
+ ...(typeof prolog.queryStatusJson ===
84
+ "function"
85
+ ? {
86
+ queryStatusJson: () => prolog.queryStatusJson(),
87
+ }
88
+ : {}),
65
89
  };
66
90
  prologPorts.set(prolog, port);
67
91
  return port;
@@ -13,6 +13,12 @@ export function createDiscoveryContext(prolog, baseContext) {
13
13
  return result;
14
14
  },
15
15
  save: () => prolog.query("kb_save"),
16
+ ...(typeof prolog.queryStatusJson ===
17
+ "function"
18
+ ? {
19
+ queryStatusJson: () => prolog.queryStatusJson(),
20
+ }
21
+ : {}),
16
22
  };
17
23
  return {
18
24
  ...(baseContext ?? {}),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kibi-mcp",
3
- "version": "0.21.1",
3
+ "version": "0.22.0",
4
4
  "dependencies": {
5
5
  "@modelcontextprotocol/sdk": "^1.26.0",
6
6
  "ajv": "^8.18.0",
@@ -9,8 +9,8 @@
9
9
  "fast-glob": "^3.2.12",
10
10
  "gray-matter": "^4.0.3",
11
11
  "js-yaml": "^4.1.0",
12
- "kibi-cli": "^0.18.1",
13
- "kibi-core": "^0.9.1",
12
+ "kibi-cli": "^0.19.0",
13
+ "kibi-core": "^0.10.0",
14
14
  "mcpcat": "^0.1.12",
15
15
  "ts-morph": "^23.0.0",
16
16
  "zod": "^4.3.6"
@@ -30,8 +30,7 @@
30
30
  },
31
31
  "files": ["dist", "bin"],
32
32
  "engines": {
33
- "node": ">=18",
34
- "bun": ">=1.0"
33
+ "node": ">=18"
35
34
  },
36
35
  "exports": {
37
36
  ".": "./dist/server.js"