kibi-cli 0.18.1 → 0.19.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.
Files changed (89) hide show
  1. package/dist/cli-json-command.d.ts +1 -2
  2. package/dist/cli-json-command.d.ts.map +1 -1
  3. package/dist/cli-json-command.js +2 -34
  4. package/dist/cli-operation-loader.d.ts +3 -0
  5. package/dist/cli-operation-loader.d.ts.map +1 -0
  6. package/dist/cli-operation-loader.js +58 -0
  7. package/dist/cli-operation-metadata.d.ts +82 -0
  8. package/dist/cli-operation-metadata.d.ts.map +1 -0
  9. package/dist/cli-operation-metadata.js +106 -0
  10. package/dist/cli-protocol.d.ts +1 -1
  11. package/dist/cli-protocol.d.ts.map +1 -1
  12. package/dist/cli-protocol.js +4 -3
  13. package/dist/cli-register-foundation.d.ts.map +1 -1
  14. package/dist/cli-register-foundation.js +14 -17
  15. package/dist/cli-register-json.d.ts +3 -0
  16. package/dist/cli-register-json.d.ts.map +1 -0
  17. package/dist/cli-register-json.js +35 -0
  18. package/dist/cli-register-maintenance.d.ts.map +1 -1
  19. package/dist/cli-register-maintenance.js +35 -10
  20. package/dist/cli-register-reporting.d.ts.map +1 -1
  21. package/dist/cli-register-reporting.js +13 -14
  22. package/dist/cli-register-skills.d.ts.map +1 -1
  23. package/dist/cli-register-skills.js +8 -6
  24. package/dist/cli.js +1 -1
  25. package/dist/commands/check.d.ts.map +1 -1
  26. package/dist/commands/check.js +30 -12
  27. package/dist/commands/coverage.js +1 -1
  28. package/dist/commands/discovery-shared.d.ts +2 -1
  29. package/dist/commands/discovery-shared.d.ts.map +1 -1
  30. package/dist/commands/discovery-shared.js +35 -13
  31. package/dist/commands/engine.d.ts +8 -0
  32. package/dist/commands/engine.d.ts.map +1 -0
  33. package/dist/commands/engine.js +100 -0
  34. package/dist/commands/gaps.js +1 -1
  35. package/dist/commands/graph.js +1 -1
  36. package/dist/commands/query.d.ts.map +1 -1
  37. package/dist/commands/query.js +3 -1
  38. package/dist/commands/search.d.ts.map +1 -1
  39. package/dist/commands/search.js +3 -1
  40. package/dist/commands/status.d.ts.map +1 -1
  41. package/dist/commands/status.js +2 -1
  42. package/dist/commands/sync/cache.d.ts +10 -0
  43. package/dist/commands/sync/cache.d.ts.map +1 -1
  44. package/dist/commands/sync/cache.js +30 -1
  45. package/dist/commands/sync/persistence.d.ts +10 -1
  46. package/dist/commands/sync/persistence.d.ts.map +1 -1
  47. package/dist/commands/sync/persistence.js +220 -44
  48. package/dist/commands/sync/staging.d.ts +10 -1
  49. package/dist/commands/sync/staging.d.ts.map +1 -1
  50. package/dist/commands/sync/staging.js +84 -1
  51. package/dist/commands/sync.d.ts.map +1 -1
  52. package/dist/commands/sync.js +450 -13
  53. package/dist/engine-daemon.d.ts +3 -0
  54. package/dist/engine-daemon.d.ts.map +1 -0
  55. package/dist/engine-daemon.js +34 -0
  56. package/dist/engine.d.ts +63 -0
  57. package/dist/engine.d.ts.map +1 -0
  58. package/dist/engine.js +1256 -0
  59. package/dist/extractors/relationships.d.ts +2 -0
  60. package/dist/extractors/relationships.d.ts.map +1 -1
  61. package/dist/extractors/relationships.js +15 -17
  62. package/dist/prolog.d.ts +8 -0
  63. package/dist/prolog.d.ts.map +1 -1
  64. package/dist/prolog.js +39 -8
  65. package/dist/public/operations/discovery-entities.d.ts.map +1 -1
  66. package/dist/public/operations/discovery-entities.js +3 -2
  67. package/dist/public/operations/discovery-executors.d.ts.map +1 -1
  68. package/dist/public/operations/discovery-executors.js +40 -3
  69. package/dist/public/operations/prolog-json.d.ts.map +1 -1
  70. package/dist/public/operations/prolog-json.js +14 -4
  71. package/dist/public/operations/runtime-types.d.ts +31 -0
  72. package/dist/public/operations/runtime-types.d.ts.map +1 -1
  73. package/dist/public/skills/init-kibi/SKILL.md +2 -2
  74. package/dist/public/skills/kibi-freshness/SKILL.md +2 -2
  75. package/dist/public/skills/kibi-traceability/SKILL.md +1 -1
  76. package/dist/public/skills/kibi-usage/SKILL.md +2 -2
  77. package/dist/public/skills/kibi-usage/resources/operation-access.md +1 -1
  78. package/dist/runtime/cli-runtime.d.ts.map +1 -1
  79. package/dist/runtime/cli-runtime.js +33 -37
  80. package/package.json +8 -4
  81. package/src/public/operations/discovery-entities.ts +3 -2
  82. package/src/public/operations/discovery-executors.ts +44 -3
  83. package/src/public/operations/prolog-json.ts +15 -3
  84. package/src/public/operations/runtime-types.ts +39 -0
  85. package/src/public/skills/init-kibi/SKILL.md +2 -2
  86. package/src/public/skills/kibi-freshness/SKILL.md +2 -2
  87. package/src/public/skills/kibi-traceability/SKILL.md +1 -1
  88. package/src/public/skills/kibi-usage/SKILL.md +2 -2
  89. package/src/public/skills/kibi-usage/resources/operation-access.md +1 -1
@@ -1,16 +1,15 @@
1
1
  import { withExitCode } from "./cli-command.js";
2
- import { runJsonInvocation } from "./cli-json-command.js";
3
- import { checkCommand } from "./commands/check.js";
4
- import { coverageCommand } from "./commands/coverage.js";
5
- import { gapsCommand } from "./commands/gaps.js";
6
- import { graphCommand } from "./commands/graph.js";
7
- import { getSpec } from "./public/operations/index.js";
2
+ import { getCliOperationMetadata } from "./cli-operation-metadata.js";
3
+ async function runJsonInvocation(invocation) {
4
+ const executor = await import("./cli-json-command.js");
5
+ await executor.runJsonInvocation(invocation);
6
+ }
8
7
  // implements REQ-kibi-operation-interface-parity
9
8
  export function registerReportingCommands(program) {
10
9
  program
11
10
  .command("find-gaps [type]")
12
11
  .alias("gaps")
13
- .description(getSpec("kb_find_gaps").description)
12
+ .description(getCliOperationMetadata("kb_find_gaps").description)
14
13
  .option("--input <path>", "JSON input file (use - for stdin)")
15
14
  .option("--missing-rel <rels>", "Comma-separated missing relationship filters")
16
15
  .option("--present-rel <rels>", "Comma-separated present relationship filters")
@@ -29,11 +28,11 @@ export function registerReportingCommands(program) {
29
28
  });
30
29
  return;
31
30
  }
32
- await gapsCommand(type, options);
31
+ await (await import("./commands/gaps.js")).gapsCommand(type, options);
33
32
  });
34
33
  program
35
34
  .command("coverage")
36
- .description(getSpec("kb_coverage").description)
35
+ .description(getCliOperationMetadata("kb_coverage").description)
37
36
  .option("--input <path>", "JSON input file (use - for stdin)")
38
37
  .option("--by <group>", "Coverage mode: req|symbol|type", "req")
39
38
  .option("--tag <tags>", "Comma-separated tag filter")
@@ -56,11 +55,11 @@ export function registerReportingCommands(program) {
56
55
  });
57
56
  return;
58
57
  }
59
- await coverageCommand(options);
58
+ await (await import("./commands/coverage.js")).coverageCommand(options);
60
59
  });
61
60
  program
62
61
  .command("graph")
63
- .description(getSpec("kb_graph").description)
62
+ .description(getCliOperationMetadata("kb_graph").description)
64
63
  .option("--input <path>", "JSON input file (use - for stdin)")
65
64
  .option("--from <ids>", "Comma-separated seed IDs")
66
65
  .option("--relationships <rels>", "Comma-separated relationship filter")
@@ -79,11 +78,11 @@ export function registerReportingCommands(program) {
79
78
  });
80
79
  return;
81
80
  }
82
- await graphCommand(options);
81
+ await (await import("./commands/graph.js")).graphCommand(options);
83
82
  });
84
83
  program
85
84
  .command("check")
86
- .description(getSpec("kb_check").description)
85
+ .description(getCliOperationMetadata("kb_check").description)
87
86
  .option("--input <path>", "JSON input file (use - for stdin)")
88
87
  .option("--fix", "Suggest fixes for violations")
89
88
  .option("--kb-path <dir>", "Path to KB directory (overrides branch resolution)")
@@ -101,6 +100,6 @@ export function registerReportingCommands(program) {
101
100
  });
102
101
  return undefined;
103
102
  }
104
- return checkCommand(options);
103
+ return (await import("./commands/check.js")).checkCommand(options);
105
104
  }));
106
105
  }
@@ -1 +1 @@
1
- {"version":3,"file":"cli-register-skills.d.ts","sourceRoot":"","sources":["../src/cli-register-skills.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAWzC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAoF7D"}
1
+ {"version":3,"file":"cli-register-skills.d.ts","sourceRoot":"","sources":["../src/cli-register-skills.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAgBzC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA+F7D"}
@@ -1,6 +1,8 @@
1
1
  import { withExitCode } from "./cli-command.js";
2
- import { runJsonInvocation } from "./cli-json-command.js";
3
- import { skillsListCommand, skillsLoadCommand, skillsReadCommand, skillsValidateCommand, } from "./commands/skills.js";
2
+ async function runJsonInvocation(invocation) {
3
+ const executor = await import("./cli-json-command.js");
4
+ await executor.runJsonInvocation(invocation);
5
+ }
4
6
  // implements REQ-kibi-operation-interface-parity
5
7
  export function registerSkillsCommands(program) {
6
8
  const skillsProgram = program
@@ -20,7 +22,7 @@ export function registerSkillsCommands(program) {
20
22
  });
21
23
  return;
22
24
  }
23
- await skillsListCommand(options);
25
+ await (await import("./commands/skills.js")).skillsListCommand(options);
24
26
  });
25
27
  skillsProgram
26
28
  .command("load")
@@ -38,7 +40,7 @@ export function registerSkillsCommands(program) {
38
40
  });
39
41
  return;
40
42
  }
41
- await skillsLoadCommand(id ?? "", options);
43
+ await (await import("./commands/skills.js")).skillsLoadCommand(id ?? "", options);
42
44
  });
43
45
  skillsProgram
44
46
  .command("read")
@@ -60,12 +62,12 @@ export function registerSkillsCommands(program) {
60
62
  });
61
63
  return;
62
64
  }
63
- await skillsReadCommand(id ?? "", resource ?? "", options);
65
+ await (await import("./commands/skills.js")).skillsReadCommand(id ?? "", resource ?? "", options);
64
66
  });
65
67
  skillsProgram
66
68
  .command("validate")
67
69
  .description("Validate a bundled markdown skill path")
68
70
  .argument("<path>", "Skill bundle directory or SKILL.md path")
69
71
  .option("--format <format>", "Output format: json|table", "table")
70
- .action(withExitCode(async (pathLike, options) => skillsValidateCommand(pathLike, options)));
72
+ .action(withExitCode(async (pathLike, options) => (await import("./commands/skills.js")).skillsValidateCommand(pathLike, options)));
71
73
  }
package/dist/cli.js CHANGED
@@ -20,8 +20,8 @@ import { readFileSync } from "node:fs";
20
20
  import { resolve } from "node:path";
21
21
  import { pathToFileURL } from "node:url";
22
22
  import { Command } from "commander";
23
- import { registerJsonOnlyCommands } from "./cli-json-command.js";
24
23
  import { registerFoundationCommands } from "./cli-register-foundation.js";
24
+ import { registerJsonOnlyCommands } from "./cli-register-json.js";
25
25
  import { registerMaintenanceCommands } from "./cli-register-maintenance.js";
26
26
  import { registerReportingCommands } from "./cli-register-reporting.js";
27
27
  import { registerSkillsCommands } from "./cli-register-skills.js";
@@ -1 +1 @@
1
- {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAkFA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,CAAC;AAG1B,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AA2bD,wBAAsB,YAAY,CAChC,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAqW/B"}
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/commands/check.ts"],"names":[],"mappings":"AAmFA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAE3D,YAAY,EAAE,SAAS,EAAE,CAAC;AAG1B,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;CAC1B;AA2bD,wBAAsB,YAAY,CAChC,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CAqX/B"}
@@ -17,6 +17,7 @@
17
17
  */
18
18
  import { existsSync } from "node:fs";
19
19
  import * as path from "node:path";
20
+ import { EngineClient } from "../engine.js";
20
21
  import { getBranchOverride, isCliTraceOrDebugEnabled } from "../env.js";
21
22
  import { extractFromManifest, extractFromManifestString, } from "../extractors/manifest.js";
22
23
  import { extractFromMarkdownString, } from "../extractors/markdown.js";
@@ -360,7 +361,9 @@ function buildStagedKibiImpactEvidence(options) {
360
361
  // implements REQ-006
361
362
  export async function checkCommand(options) {
362
363
  let prolog = null;
364
+ let engine = null;
363
365
  let attached = false;
366
+ let resolvedBranch = "develop";
364
367
  try {
365
368
  let resolvedKbPath = "";
366
369
  if (options.kbPath) {
@@ -379,6 +382,7 @@ export async function checkCommand(options) {
379
382
  }
380
383
  if (!branch)
381
384
  branch = envBranch || "develop";
385
+ resolvedBranch = branch;
382
386
  // fallback to main if develop isn't present? keep path consistent
383
387
  resolvedKbPath = path.join(process.cwd(), ".kb/branches", branch || "main");
384
388
  }
@@ -564,20 +568,33 @@ export async function checkCommand(options) {
564
568
  return { exitCode: 1 };
565
569
  }
566
570
  }
567
- prolog = new PrologProcess({ timeout: 120000 });
568
- await prolog.start();
569
- const kbPathEscaped = escapeAtom(resolvedKbPath);
570
- const attachResult = await prolog.query(`kb_attach('${kbPathEscaped}')`);
571
- if (!attachResult.success) {
572
- await prolog.terminate();
573
- console.error(`Error: Failed to attach KB: ${attachResult.error}`);
574
- return { exitCode: 1 };
571
+ // The active branch is hosted by the journaled engine. Keep the explicit
572
+ // --kb-path escape hatch on the one-shot path for alternate/staged stores,
573
+ // but never compete with the branch daemon for its RDF lock.
574
+ if (options.kbPath === undefined) {
575
+ engine = new EngineClient({
576
+ workspaceRoot: process.cwd(),
577
+ branch: resolvedBranch,
578
+ timeout: 120_000,
579
+ });
580
+ await engine.start();
581
+ }
582
+ else {
583
+ prolog = new PrologProcess({ timeout: 120000 });
584
+ await prolog.start();
585
+ const kbPathEscaped = escapeAtom(resolvedKbPath);
586
+ const attachResult = await prolog.query(`kb_attach('${kbPathEscaped}')`);
587
+ if (!attachResult.success) {
588
+ await prolog.terminate();
589
+ console.error(`Error: Failed to attach KB: ${attachResult.error}`);
590
+ return { exitCode: 1 };
591
+ }
592
+ attached = true;
575
593
  }
576
- attached = true;
577
- if (!prolog) {
578
- throw new Error("Prolog process not initialized");
594
+ const activeProlog = engine ?? prolog;
595
+ if (!activeProlog) {
596
+ throw new Error("Prolog runtime not initialized");
579
597
  }
580
- const activeProlog = prolog;
581
598
  const rules = options.rules
582
599
  ?.split(",")
583
600
  .map((rule) => rule.trim())
@@ -637,6 +654,7 @@ export async function checkCommand(options) {
637
654
  return { exitCode: 1 };
638
655
  }
639
656
  finally {
657
+ await engine?.terminate();
640
658
  await safeCleanupProlog(prolog);
641
659
  }
642
660
  }
@@ -1,4 +1,4 @@
1
- import { coverageSpec } from "../public/operations/index.js";
1
+ import { coverageSpec } from "../public/operations/specs/reporting.js";
2
2
  import { executeReportingSpec, printDiscoveryResult, } from "./discovery-shared.js";
3
3
  // implements REQ-002, REQ-003
4
4
  export async function coverageCommand(options) {
@@ -1,5 +1,6 @@
1
1
  import { PrologProcess, resolveKbPlPath } from "../prolog.js";
2
- import { type OperationSpec, type RuntimeOptions } from "../public/operations/index.js";
2
+ import { type RuntimeOptions } from "../public/operations/runtime-types.js";
3
+ import type { OperationSpec } from "../public/operations/types.js";
3
4
  export { renderCoverageTable } from "./discovery-table.js";
4
5
  export interface DiscoveryCommandOptions {
5
6
  format?: "json" | "table";
@@ -1 +1 @@
1
- {"version":3,"file":"discovery-shared.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AAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC5B,MAAM,CAGR;AAGD,wBAAsB,kBAAkB,CAAC,CAAC,EACxC,MAAM,EAAE,aAAa,EACrB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,IAAI,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC5B,OAAO,CAAC,CAAC,CAAC,CAwBZ;AAGD,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,EACpC,UAAU,EAAE,OAAO,EACnB,YAAY,EAAE,MAAM,GACnB,IAAI,CAQN"}
@@ -1,8 +1,9 @@
1
1
  import path from "node:path";
2
+ import { EngineClient } from "../engine.js";
2
3
  import { getBranchOverride } from "../env.js";
3
4
  import { PrologProcess, resolveKbPlPath } from "../prolog.js";
4
5
  import { escapeAtom } from "../prolog/codec.js";
5
- import { executeOperation, } from "../public/operations/index.js";
6
+ import { executeOperation, } from "../public/operations/runtime-types.js";
6
7
  import { createCliRuntime } from "../runtime/cli-runtime.js";
7
8
  import { safeCleanupProlog } from "../utils/prolog-cleanup.js";
8
9
  import { renderDiscoveryTable } from "./discovery-table.js";
@@ -14,30 +15,51 @@ export async function executeReportingSpec(spec, input, options = {}) {
14
15
  }
15
16
  // implements REQ-003
16
17
  export async function withAttachedBranchProlog(callback, deps) {
18
+ const usesEngine = deps?.createProlog === undefined;
17
19
  const createProlog = deps?.createProlog ?? ((opts) => new PrologProcess(opts));
18
20
  let prolog = null;
21
+ let engine = null;
19
22
  let attached = false;
23
+ let branchName;
20
24
  try {
21
- prolog = createProlog({ timeout: 120000 });
22
- await prolog.start();
23
- await prolog.query("set_prolog_flag(answer_write_options, [max_depth(0), spacing(next_argument)])");
24
- let branch;
25
25
  try {
26
- branch = getBranchOverride() || (await getCurrentBranch(process.cwd()));
26
+ branchName =
27
+ getBranchOverride() || (await getCurrentBranch(process.cwd()));
27
28
  }
28
29
  catch {
29
- branch = getBranchOverride() || "main";
30
+ branchName = getBranchOverride() || "main";
31
+ }
32
+ if (usesEngine) {
33
+ engine = new EngineClient({
34
+ workspaceRoot: process.cwd(),
35
+ branch: branchName,
36
+ timeout: 120_000,
37
+ });
38
+ await engine.start();
39
+ prolog = engine;
40
+ }
41
+ else {
42
+ prolog = createProlog({ timeout: 120000 });
43
+ await prolog.start();
30
44
  }
31
- const kbPath = path.join(process.cwd(), ".kb/branches", branch);
32
- const attachResult = await prolog.query(`kb_attach('${escapeAtom(kbPath)}')`);
33
- if (!attachResult.success) {
34
- throw new Error(`Failed to attach KB: ${attachResult.error || "Unknown error"}`);
45
+ await prolog.query("set_prolog_flag(answer_write_options, [max_depth(0), spacing(next_argument)])");
46
+ if (!usesEngine) {
47
+ const kbPath = path.join(process.cwd(), ".kb/branches", branchName);
48
+ const attachResult = await prolog.query(`kb_attach('${escapeAtom(kbPath)}')`);
49
+ if (!attachResult.success) {
50
+ throw new Error(`Failed to attach KB: ${attachResult.error || "Unknown error"}`);
51
+ }
52
+ attached = true;
35
53
  }
36
- attached = true;
37
54
  return await callback(prolog);
38
55
  }
39
56
  finally {
40
- await safeCleanupProlog(prolog);
57
+ if (usesEngine) {
58
+ await engine?.terminate();
59
+ }
60
+ else {
61
+ await safeCleanupProlog(prolog);
62
+ }
41
63
  }
42
64
  }
43
65
  // implements REQ-003
@@ -0,0 +1,8 @@
1
+ export declare function engineStatusCommand(): Promise<void>;
2
+ export declare function engineStopCommand(): Promise<void>;
3
+ export declare function storageStatusCommand(): Promise<void>;
4
+ export declare function storageCompactCommand(): Promise<void>;
5
+ export declare function storageExportCommand(options: {
6
+ output: string;
7
+ }): Promise<void>;
8
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../../src/commands/engine.ts"],"names":[],"mappings":"AAwCA,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CA4BzD;AAED,wBAAsB,iBAAiB,IAAI,OAAO,CAAC,IAAI,CAAC,CAWvD;AAED,wBAAsB,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC,CAE1D;AAED,wBAAsB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAU3D;AAED,wBAAsB,oBAAoB,CAAC,OAAO,EAAE;IAClD,MAAM,EAAE,MAAM,CAAC;CAChB,GAAG,OAAO,CAAC,IAAI,CAAC,CAWhB"}
@@ -0,0 +1,100 @@
1
+ import path from "node:path";
2
+ import { EngineClient } from "../engine.js";
3
+ import { resolveActiveBranch } from "../utils/branch-resolver.js";
4
+ function currentBranch(root) {
5
+ const resolved = resolveActiveBranch(root);
6
+ if ("error" in resolved) {
7
+ if (resolved.code === "NOT_A_GIT_REPO" ||
8
+ resolved.code === "GIT_NOT_AVAILABLE") {
9
+ return "main";
10
+ }
11
+ throw new Error(resolved.error);
12
+ }
13
+ return resolved.branch;
14
+ }
15
+ function client() {
16
+ const workspaceRoot = path.resolve(process.env.KIBI_WORKSPACE ??
17
+ process.env.KIBI_PROJECT_ROOT ??
18
+ process.env.KIBI_ROOT ??
19
+ process.cwd());
20
+ return new EngineClient({
21
+ workspaceRoot,
22
+ branch: currentBranch(workspaceRoot),
23
+ });
24
+ }
25
+ function workspaceRoot() {
26
+ return path.resolve(process.env.KIBI_WORKSPACE ??
27
+ process.env.KIBI_PROJECT_ROOT ??
28
+ process.env.KIBI_ROOT ??
29
+ process.cwd());
30
+ }
31
+ export async function engineStatusCommand() {
32
+ const engine = client();
33
+ try {
34
+ const result = await engine.storageStatus();
35
+ if (!result.success)
36
+ throw new Error(result.error ?? "Engine status failed");
37
+ let status = result.bindings.Status ?? null;
38
+ const encoded = result.bindings.Json;
39
+ if (encoded !== undefined) {
40
+ try {
41
+ const decoded = JSON.parse(encoded);
42
+ status = typeof decoded === "string" ? JSON.parse(decoded) : decoded;
43
+ }
44
+ catch {
45
+ // Preserve the raw Prolog dict text for diagnostics when a mismatched
46
+ // engine version cannot provide the negotiated JSON binding.
47
+ }
48
+ }
49
+ console.log(JSON.stringify({
50
+ pid: engine.getPid(),
51
+ running: engine.isRunning(),
52
+ branch: currentBranch(workspaceRoot()),
53
+ status,
54
+ }));
55
+ }
56
+ finally {
57
+ await engine.terminate();
58
+ }
59
+ }
60
+ export async function engineStopCommand() {
61
+ const engine = client();
62
+ try {
63
+ // Stopping an absent daemon must remain a no-op. Starting SWI merely to
64
+ // shut it down defeats the maintenance command and can unexpectedly
65
+ // migrate a legacy branch during an operator status check.
66
+ await engine.stop(false);
67
+ console.log("Kibi engine stopped");
68
+ }
69
+ finally {
70
+ await engine.terminate();
71
+ }
72
+ }
73
+ export async function storageStatusCommand() {
74
+ await engineStatusCommand();
75
+ }
76
+ export async function storageCompactCommand() {
77
+ const engine = client();
78
+ try {
79
+ const result = await engine.compact();
80
+ if (!result.success)
81
+ throw new Error(result.error ?? "Storage compaction failed");
82
+ console.log("Kibi storage compacted");
83
+ }
84
+ finally {
85
+ await engine.terminate();
86
+ }
87
+ }
88
+ export async function storageExportCommand(options) {
89
+ const output = path.resolve(options.output);
90
+ const engine = client();
91
+ try {
92
+ const result = await engine.exportStorage(output);
93
+ if (!result.success)
94
+ throw new Error(result.error ?? "Storage export failed");
95
+ console.log(`Exported Kibi storage to ${output}`);
96
+ }
97
+ finally {
98
+ await engine.terminate();
99
+ }
100
+ }
@@ -1,4 +1,4 @@
1
- import { findGapsSpec } from "../public/operations/index.js";
1
+ import { findGapsSpec } from "../public/operations/specs/reporting.js";
2
2
  import { executeReportingSpec, printDiscoveryResult, } from "./discovery-shared.js";
3
3
  // implements REQ-002, REQ-003
4
4
  export async function gapsCommand(type, options) {
@@ -1,4 +1,4 @@
1
- import { graphSpec } from "../public/operations/index.js";
1
+ import { graphSpec } from "../public/operations/specs/reporting.js";
2
2
  import { executeReportingSpec, printDiscoveryResult, } from "./discovery-shared.js";
3
3
  // implements REQ-002, REQ-003
4
4
  export async function graphCommand(options) {
@@ -1 +1 @@
1
- {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAqBA,UAAU,YAAY;IACpB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA+C/B"}
1
+ {"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAmBA,UAAU,YAAY;IACpB,QAAQ,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,YAAY,CAChC,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,OAAO,EAAE,YAAY,GACpB,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,CAAC,CA+C/B"}
@@ -1,6 +1,8 @@
1
1
  import Table from "cli-table3";
2
2
  import { parseListOfLists, parsePrologValue } from "../prolog/codec.js";
3
- import { VALID_ENTITY_TYPES, executeOperation, querySpec, } from "../public/operations/index.js";
3
+ import { VALID_ENTITY_TYPES } from "../public/operations/discovery-entities.js";
4
+ import { executeOperation } from "../public/operations/runtime-types.js";
5
+ import { querySpec } from "../public/operations/specs/discovery.js";
4
6
  import relationshipSchema from "../public/schemas/relationship.js";
5
7
  import { createCliRuntime } from "../runtime/cli-runtime.js";
6
8
  import { withAttachedBranchProlog } from "./discovery-shared.js";
@@ -1 +1 @@
1
- {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAQA,UAAU,aAAa;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAmCf"}
1
+ {"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../../src/commands/search.ts"],"names":[],"mappings":"AAMA,UAAU,aAAa;IACrB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IACnC,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAsB,aAAa,CACjC,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,IAAI,CAAC,CAmCf"}
@@ -1,4 +1,6 @@
1
- import { VALID_ENTITY_TYPES, executeOperation, searchSpec, } from "../public/operations/index.js";
1
+ import { VALID_ENTITY_TYPES } from "../public/operations/discovery-entities.js";
2
+ import { executeOperation } from "../public/operations/runtime-types.js";
3
+ import { searchSpec } from "../public/operations/specs/discovery.js";
2
4
  import { createCliRuntime } from "../runtime/cli-runtime.js";
3
5
  import { printDiscoveryResult } from "./discovery-shared.js";
4
6
  export async function searchCommand(query, options) {
@@ -1 +1 @@
1
- {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAIA,UAAU,aAAa;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAazE"}
1
+ {"version":3,"file":"status.d.ts","sourceRoot":"","sources":["../../src/commands/status.ts"],"names":[],"mappings":"AAKA,UAAU,aAAa;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CACpC;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAazE"}
@@ -1,4 +1,5 @@
1
- import { executeOperation, statusSpec } from "../public/operations/index.js";
1
+ import { executeOperation } from "../public/operations/runtime-types.js";
2
+ import { statusSpec } from "../public/operations/specs/discovery.js";
2
3
  import { createCliRuntime } from "../runtime/cli-runtime.js";
3
4
  import { printDiscoveryResult } from "./discovery-shared.js";
4
5
  export async function statusCommand(options) {
@@ -10,6 +10,14 @@ interface SyncCacheDeps {
10
10
  export type SyncCache = {
11
11
  version: number;
12
12
  hashes: Record<string, string>;
13
+ /** Content hashes for relationship shards; optional for v1 caches. */
14
+ relationshipHashes?: Record<string, string>;
15
+ /** Normalized entity payload hashes, keyed by canonical entity ID. */
16
+ entityHashes?: Record<string, string>;
17
+ /** Entity IDs last compiled from each normalized source path. */
18
+ sourceEntityIds?: Record<string, string[]>;
19
+ /** Normalized relationship keys last compiled from each shard. */
20
+ shardRelationships?: Record<string, string[]>;
13
21
  seenAt: Record<string, string>;
14
22
  semanticHashes: Record<string, string>;
15
23
  semanticContracts: Record<string, boolean>;
@@ -18,6 +26,8 @@ export declare const SYNC_CACHE_VERSION = 1;
18
26
  export declare const SYNC_CACHE_TTL_MS: number;
19
27
  export declare function toCacheKey(filePath: string): string;
20
28
  export declare function hashFile(filePath: string, deps?: Partial<SyncCacheDeps>): string;
29
+ /** Deterministically hash a JSON-compatible compiler payload. */
30
+ export declare function hashNormalized(value: unknown): string;
21
31
  export declare function readSyncCache(cachePath: string, deps?: Partial<SyncCacheDeps>): SyncCache;
22
32
  export declare function writeSyncCache(cachePath: string, cache: SyncCache, deps?: Partial<SyncCacheDeps>): void;
23
33
  export declare function copySyncCache(livePath: string, stagingPath: string, deps?: Partial<SyncCacheDeps>): void;
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/cache.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7E,UAAU,aAAa;IACrB,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,UAAU,EAAE,OAAO,UAAU,CAAC;IAC9B,SAAS,EAAE,OAAO,SAAS,CAAC;IAC5B,YAAY,EAAE,OAAO,YAAY,CAAC;IAClC,aAAa,EAAE,OAAO,aAAa,CAAC;CACrC;AAaD,MAAM,MAAM,SAAS,GAAG;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,cAAc,EAAE,MAAM,CA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M,EAChB,WAAW,EAAE,MAAM,EACnB,IAAI,CAAC,EAAE,OAAO,CAAC,aAAa,CAAC,GAC5B,IAAI,CASN"}
@@ -40,6 +40,22 @@ filePath, deps) {
40
40
  const content = resolved.readFileSync(filePath);
41
41
  return resolved.createHash("sha256").update(content).digest("hex");
42
42
  }
43
+ /** Deterministically hash a JSON-compatible compiler payload. */
44
+ export function hashNormalized(value) {
45
+ const normalize = (input) => {
46
+ if (Array.isArray(input))
47
+ return input.map(normalize);
48
+ if (input !== null && typeof input === "object") {
49
+ return Object.fromEntries(Object.entries(input)
50
+ .sort(([left], [right]) => left.localeCompare(right))
51
+ .map(([key, child]) => [key, normalize(child)]));
52
+ }
53
+ return input;
54
+ };
55
+ return createHash("sha256")
56
+ .update(JSON.stringify(normalize(value)))
57
+ .digest("hex");
58
+ }
43
59
  export function readSyncCache(
44
60
  // implements REQ-003
45
61
  cachePath, deps) {
@@ -64,13 +80,26 @@ cachePath, deps) {
64
80
  semanticContracts: {},
65
81
  };
66
82
  }
67
- return {
83
+ const cache = {
68
84
  version: SYNC_CACHE_VERSION,
69
85
  hashes: parsed.hashes ?? {},
70
86
  seenAt: parsed.seenAt ?? {},
71
87
  semanticHashes: parsed.semanticHashes ?? {},
72
88
  semanticContracts: parsed.semanticContracts ?? {},
73
89
  };
90
+ if (parsed.relationshipHashes !== undefined) {
91
+ cache.relationshipHashes = parsed.relationshipHashes;
92
+ }
93
+ if (parsed.entityHashes !== undefined) {
94
+ cache.entityHashes = parsed.entityHashes;
95
+ }
96
+ if (parsed.sourceEntityIds !== undefined) {
97
+ cache.sourceEntityIds = parsed.sourceEntityIds;
98
+ }
99
+ if (parsed.shardRelationships !== undefined) {
100
+ cache.shardRelationships = parsed.shardRelationships;
101
+ }
102
+ return cache;
74
103
  }
75
104
  catch {
76
105
  return {
@@ -5,7 +5,16 @@ export interface PersistenceResult {
5
5
  relationshipCount: number;
6
6
  kbModified: boolean;
7
7
  }
8
- export declare function persistEntities(prolog: PrologProcess, results: ExtractionResult[], entityIds: Set<string>): Promise<{
8
+ /** Remove entities owned by changed/deleted source files before re-upserting. */
9
+ export declare function retractEntitiesForSources(prolog: PrologProcess, sourceFiles: readonly string[]): Promise<number>;
10
+ /** Remove an exact entity delta without scanning every indexed source. */
11
+ export declare function retractEntitiesById(prolog: PrologProcess, entityIds: readonly string[]): Promise<number>;
12
+ /** Clear outgoing inline relationships for entities whose payload changed. */
13
+ export declare function retractEntityRelationshipsById(prolog: PrologProcess, entityIds: readonly string[]): Promise<void>;
14
+ export declare function retractRelationships(prolog: PrologProcess, relationships: readonly ExtractedRelationship[]): Promise<number>;
15
+ export declare function persistEntities(prolog: PrologProcess, results: ExtractionResult[], entityIds: Set<string>, options?: {
16
+ loadExistingEntityIds?: boolean;
17
+ }): Promise<{
9
18
  entityCount: number;
10
19
  kbModified: boolean;
11
20
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"persistence.d.ts","sourceRoot":"","sources":["../../../src/commands/sync/persistence.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAEV,qBAAqB,EACrB,gBAAgB,EACjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAgHrD,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,UAAU,EAAE,OAAO,CAAC;CACrB;AAmCD,wBAAsB,eAAe,CAEnC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,gBAAgB,EAAE,EAC3B,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GACrB,OAAO,CAAC;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,OAAO,CAAA;CAAE,CAAC,CAwKvD;AA6BD,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,gBAAgB,EAAE,EAC3B,kBAAkB,EAAE,qBAAqB,EAAE,GAC1C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