bluera-knowledge 0.10.0 → 0.11.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 (49) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/CHANGELOG.md +25 -0
  3. package/README.md +98 -2
  4. package/commands/sync.md +96 -0
  5. package/dist/{chunk-ITH6FWQY.js → chunk-2WBITQWZ.js} +24 -3
  6. package/dist/{chunk-ITH6FWQY.js.map → chunk-2WBITQWZ.js.map} +1 -1
  7. package/dist/{chunk-CUHYSPRV.js → chunk-565OVW3C.js} +999 -2
  8. package/dist/chunk-565OVW3C.js.map +1 -0
  9. package/dist/{chunk-DWAIT2OD.js → chunk-TRDMYKGC.js} +190 -5
  10. package/dist/chunk-TRDMYKGC.js.map +1 -0
  11. package/dist/index.js +217 -5
  12. package/dist/index.js.map +1 -1
  13. package/dist/mcp/server.js +2 -2
  14. package/dist/workers/background-worker-cli.js +2 -2
  15. package/package.json +1 -1
  16. package/src/analysis/adapter-registry.test.ts +211 -0
  17. package/src/analysis/adapter-registry.ts +155 -0
  18. package/src/analysis/language-adapter.ts +127 -0
  19. package/src/analysis/parser-factory.test.ts +79 -1
  20. package/src/analysis/parser-factory.ts +8 -0
  21. package/src/analysis/zil/index.ts +34 -0
  22. package/src/analysis/zil/zil-adapter.test.ts +187 -0
  23. package/src/analysis/zil/zil-adapter.ts +121 -0
  24. package/src/analysis/zil/zil-lexer.test.ts +222 -0
  25. package/src/analysis/zil/zil-lexer.ts +239 -0
  26. package/src/analysis/zil/zil-parser.test.ts +210 -0
  27. package/src/analysis/zil/zil-parser.ts +360 -0
  28. package/src/analysis/zil/zil-special-forms.ts +193 -0
  29. package/src/cli/commands/sync.test.ts +54 -0
  30. package/src/cli/commands/sync.ts +264 -0
  31. package/src/cli/index.ts +1 -0
  32. package/src/crawl/claude-client.test.ts +56 -0
  33. package/src/crawl/claude-client.ts +27 -1
  34. package/src/index.ts +8 -0
  35. package/src/mcp/commands/index.ts +2 -0
  36. package/src/mcp/commands/sync.commands.test.ts +283 -0
  37. package/src/mcp/commands/sync.commands.ts +233 -0
  38. package/src/mcp/server.ts +9 -1
  39. package/src/services/gitignore.service.test.ts +157 -0
  40. package/src/services/gitignore.service.ts +132 -0
  41. package/src/services/store-definition.service.test.ts +440 -0
  42. package/src/services/store-definition.service.ts +198 -0
  43. package/src/services/store.service.test.ts +279 -1
  44. package/src/services/store.service.ts +101 -4
  45. package/src/types/index.ts +18 -0
  46. package/src/types/store-definition.test.ts +492 -0
  47. package/src/types/store-definition.ts +129 -0
  48. package/dist/chunk-CUHYSPRV.js.map +0 -1
  49. package/dist/chunk-DWAIT2OD.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,12 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ StoreDefinitionService,
4
+ ZilAdapter,
5
+ isFileStoreDefinition,
6
+ isRepoStoreDefinition,
7
+ isWebStoreDefinition,
3
8
  runMCPServer
4
- } from "./chunk-CUHYSPRV.js";
9
+ } from "./chunk-565OVW3C.js";
5
10
  import {
6
11
  IntelligentCrawler
7
- } from "./chunk-ITH6FWQY.js";
12
+ } from "./chunk-2WBITQWZ.js";
8
13
  import {
9
14
  ASTParser,
15
+ AdapterRegistry,
10
16
  ChunkingService,
11
17
  classifyWebContentType,
12
18
  createDocumentId,
@@ -16,7 +22,7 @@ import {
16
22
  err,
17
23
  extractRepoName,
18
24
  ok
19
- } from "./chunk-DWAIT2OD.js";
25
+ } from "./chunk-TRDMYKGC.js";
20
26
  import "./chunk-6FHWC36B.js";
21
27
 
22
28
  // src/index.ts
@@ -1531,11 +1537,214 @@ Store: ${s.name}`);
1531
1537
  return store;
1532
1538
  }
1533
1539
 
1540
+ // src/cli/commands/sync.ts
1541
+ import { Command as Command9 } from "commander";
1542
+ async function createStoreFromDefinition(def, defService, storeService) {
1543
+ try {
1544
+ if (isFileStoreDefinition(def)) {
1545
+ const resolvedPath = defService.resolvePath(def.path);
1546
+ const createResult = await storeService.create(
1547
+ {
1548
+ name: def.name,
1549
+ type: "file",
1550
+ path: resolvedPath,
1551
+ description: def.description,
1552
+ tags: def.tags
1553
+ },
1554
+ { skipDefinitionSync: true }
1555
+ );
1556
+ if (!createResult.success) {
1557
+ return { success: false, error: createResult.error.message };
1558
+ }
1559
+ return { success: true };
1560
+ }
1561
+ if (isRepoStoreDefinition(def)) {
1562
+ const createResult = await storeService.create(
1563
+ {
1564
+ name: def.name,
1565
+ type: "repo",
1566
+ url: def.url,
1567
+ branch: def.branch,
1568
+ depth: def.depth,
1569
+ description: def.description,
1570
+ tags: def.tags
1571
+ },
1572
+ { skipDefinitionSync: true }
1573
+ );
1574
+ if (!createResult.success) {
1575
+ return { success: false, error: createResult.error.message };
1576
+ }
1577
+ return { success: true };
1578
+ }
1579
+ if (isWebStoreDefinition(def)) {
1580
+ const createResult = await storeService.create(
1581
+ {
1582
+ name: def.name,
1583
+ type: "web",
1584
+ url: def.url,
1585
+ depth: def.depth,
1586
+ description: def.description,
1587
+ tags: def.tags
1588
+ },
1589
+ { skipDefinitionSync: true }
1590
+ );
1591
+ if (!createResult.success) {
1592
+ return { success: false, error: createResult.error.message };
1593
+ }
1594
+ return { success: true };
1595
+ }
1596
+ return { success: false, error: "Unknown store definition type" };
1597
+ } catch (error) {
1598
+ return {
1599
+ success: false,
1600
+ error: error instanceof Error ? error.message : String(error)
1601
+ };
1602
+ }
1603
+ }
1604
+ function createSyncCommand(getOptions) {
1605
+ const sync = new Command9("sync").description(
1606
+ "Sync stores from definitions config (bootstrap on fresh clone)"
1607
+ );
1608
+ sync.option("--dry-run", "Show what would happen without making changes").option("--prune", "Remove stores not in definitions").option("--reindex", "Re-index existing stores after sync").action(async (options) => {
1609
+ const globalOpts = getOptions();
1610
+ const projectRoot = globalOpts.projectRoot ?? process.cwd();
1611
+ const defService = new StoreDefinitionService(projectRoot);
1612
+ const services = await createServices(globalOpts.config, globalOpts.dataDir, projectRoot);
1613
+ try {
1614
+ const config = await defService.load();
1615
+ const existingStores = await services.store.list();
1616
+ const existingNames = new Set(existingStores.map((s) => s.name));
1617
+ const definedNames = new Set(config.stores.map((d) => d.name));
1618
+ const result = {
1619
+ created: [],
1620
+ skipped: [],
1621
+ failed: [],
1622
+ orphans: [],
1623
+ pruned: [],
1624
+ dryRun: options.dryRun === true,
1625
+ wouldCreate: [],
1626
+ wouldPrune: []
1627
+ };
1628
+ for (const def of config.stores) {
1629
+ if (existingNames.has(def.name)) {
1630
+ result.skipped.push(def.name);
1631
+ continue;
1632
+ }
1633
+ if (options.dryRun === true) {
1634
+ result.wouldCreate.push(def.name);
1635
+ continue;
1636
+ }
1637
+ const createResult = await createStoreFromDefinition(def, defService, services.store);
1638
+ if (createResult.success) {
1639
+ result.created.push(def.name);
1640
+ } else {
1641
+ result.failed.push({ name: def.name, error: createResult.error });
1642
+ }
1643
+ }
1644
+ for (const store of existingStores) {
1645
+ if (!definedNames.has(store.name)) {
1646
+ result.orphans.push(store.name);
1647
+ }
1648
+ }
1649
+ if (options.prune === true && result.orphans.length > 0) {
1650
+ if (options.dryRun === true) {
1651
+ result.wouldPrune = [...result.orphans];
1652
+ } else {
1653
+ for (const orphanName of result.orphans) {
1654
+ const store = await services.store.getByName(orphanName);
1655
+ if (store !== void 0) {
1656
+ const deleteResult = await services.store.delete(store.id, {
1657
+ skipDefinitionSync: true
1658
+ });
1659
+ if (deleteResult.success) {
1660
+ result.pruned.push(orphanName);
1661
+ }
1662
+ }
1663
+ }
1664
+ }
1665
+ }
1666
+ if (globalOpts.format === "json") {
1667
+ console.log(JSON.stringify(result, null, 2));
1668
+ } else {
1669
+ printHumanReadable(result, globalOpts.quiet === true);
1670
+ }
1671
+ } finally {
1672
+ await destroyServices(services);
1673
+ }
1674
+ });
1675
+ return sync;
1676
+ }
1677
+ function printHumanReadable(result, quiet) {
1678
+ if (quiet) {
1679
+ for (const name of result.created) {
1680
+ console.log(`created: ${name}`);
1681
+ }
1682
+ for (const name of result.pruned) {
1683
+ console.log(`pruned: ${name}`);
1684
+ }
1685
+ for (const name of result.wouldCreate) {
1686
+ console.log(`would create: ${name}`);
1687
+ }
1688
+ for (const name of result.wouldPrune) {
1689
+ console.log(`would prune: ${name}`);
1690
+ }
1691
+ return;
1692
+ }
1693
+ if (result.dryRun) {
1694
+ console.log("\n[DRY RUN] No changes made.\n");
1695
+ } else {
1696
+ console.log("\nSync completed.\n");
1697
+ }
1698
+ if (result.created.length > 0) {
1699
+ console.log(`Created (${String(result.created.length)}):`);
1700
+ for (const name of result.created) {
1701
+ console.log(` + ${name}`);
1702
+ }
1703
+ }
1704
+ if (result.wouldCreate.length > 0) {
1705
+ console.log(`Would create (${String(result.wouldCreate.length)}):`);
1706
+ for (const name of result.wouldCreate) {
1707
+ console.log(` + ${name}`);
1708
+ }
1709
+ }
1710
+ if (result.skipped.length > 0) {
1711
+ console.log(`Skipped (already exist) (${String(result.skipped.length)}):`);
1712
+ for (const name of result.skipped) {
1713
+ console.log(` - ${name}`);
1714
+ }
1715
+ }
1716
+ if (result.failed.length > 0) {
1717
+ console.log(`Failed (${String(result.failed.length)}):`);
1718
+ for (const { name, error } of result.failed) {
1719
+ console.log(` ! ${name}: ${error}`);
1720
+ }
1721
+ }
1722
+ if (result.orphans.length > 0) {
1723
+ console.log(`Orphans (not in definitions) (${String(result.orphans.length)}):`);
1724
+ for (const name of result.orphans) {
1725
+ console.log(` ? ${name}`);
1726
+ }
1727
+ }
1728
+ if (result.pruned.length > 0) {
1729
+ console.log(`Pruned (${String(result.pruned.length)}):`);
1730
+ for (const name of result.pruned) {
1731
+ console.log(` x ${name}`);
1732
+ }
1733
+ }
1734
+ if (result.wouldPrune.length > 0) {
1735
+ console.log(`Would prune (${String(result.wouldPrune.length)}):`);
1736
+ for (const name of result.wouldPrune) {
1737
+ console.log(` x ${name}`);
1738
+ }
1739
+ }
1740
+ console.log("");
1741
+ }
1742
+
1534
1743
  // src/cli/program.ts
1535
1744
  import { readFileSync } from "fs";
1536
1745
  import { dirname, join as join3 } from "path";
1537
1746
  import { fileURLToPath } from "url";
1538
- import { Command as Command9 } from "commander";
1747
+ import { Command as Command10 } from "commander";
1539
1748
  function getVersion() {
1540
1749
  const __filename2 = fileURLToPath(import.meta.url);
1541
1750
  const __dirname2 = dirname(__filename2);
@@ -1545,7 +1754,7 @@ function getVersion() {
1545
1754
  }
1546
1755
  var version = getVersion();
1547
1756
  function createProgram() {
1548
- const program2 = new Command9();
1757
+ const program2 = new Command10();
1549
1758
  program2.name("bluera-knowledge").description("CLI tool for managing knowledge stores with semantic search").version(version);
1550
1759
  program2.option("-c, --config <path>", "Path to config file").option("-d, --data-dir <path>", "Data directory").option("-p, --project-root <path>", "Project root directory (for resolving relative paths)").option("-f, --format <format>", "Output format: json | table | plain", "table").option("-q, --quiet", "Suppress non-essential output").option("-v, --verbose", "Enable verbose logging");
1551
1760
  return program2;
@@ -1563,6 +1772,8 @@ function getGlobalOptions(program2) {
1563
1772
  }
1564
1773
 
1565
1774
  // src/index.ts
1775
+ var registry = AdapterRegistry.getInstance();
1776
+ registry.register(new ZilAdapter());
1566
1777
  var DEFAULT_DATA_DIR = join4(homedir2(), ".bluera", "bluera-knowledge", "data");
1567
1778
  var DEFAULT_CONFIG = join4(homedir2(), ".bluera", "bluera-knowledge", "config.json");
1568
1779
  var DEFAULT_REPOS_DIR2 = join4(homedir2(), ".bluera", "bluera-knowledge", "repos");
@@ -1620,6 +1831,7 @@ program.addCommand(createIndexCommand(() => getGlobalOptions(program)));
1620
1831
  program.addCommand(createServeCommand(() => getGlobalOptions(program)));
1621
1832
  program.addCommand(createCrawlCommand(() => getGlobalOptions(program)));
1622
1833
  program.addCommand(createSetupCommand(() => getGlobalOptions(program)));
1834
+ program.addCommand(createSyncCommand(() => getGlobalOptions(program)));
1623
1835
  program.addCommand(createMCPCommand(() => getGlobalOptions(program)));
1624
1836
  if (process.argv.length <= 2) {
1625
1837
  printFullHelp(program);