@toolbaux/guardian 0.1.22 → 0.2.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 (37) hide show
  1. package/README.md +6 -4
  2. package/dist/adapters/runner.js +72 -3
  3. package/dist/adapters/typescript-adapter.js +24 -10
  4. package/dist/benchmarking/metrics/context-coverage.js +82 -0
  5. package/dist/benchmarking/metrics/drift-score.js +104 -0
  6. package/dist/benchmarking/metrics/search-recall.js +207 -0
  7. package/dist/benchmarking/metrics/token-efficiency.js +79 -0
  8. package/dist/benchmarking/report.js +131 -0
  9. package/dist/benchmarking/runner.js +175 -0
  10. package/dist/benchmarking/types.js +13 -0
  11. package/dist/cli.js +53 -10
  12. package/dist/commands/benchmark.js +62 -0
  13. package/dist/commands/context.js +87 -29
  14. package/dist/commands/discrepancy.js +1 -1
  15. package/dist/commands/doc-generate.js +1 -1
  16. package/dist/commands/doc-html.js +1 -1
  17. package/dist/commands/extract.js +4 -1
  18. package/dist/commands/feature-context.js +1 -1
  19. package/dist/commands/generate.js +83 -10
  20. package/dist/commands/init.js +89 -56
  21. package/dist/commands/intel.js +70 -1
  22. package/dist/commands/mcp-serve.js +155 -316
  23. package/dist/commands/search.js +642 -14
  24. package/dist/config.js +1 -0
  25. package/dist/db/embeddings.js +113 -0
  26. package/dist/db/file-specs-store.js +174 -0
  27. package/dist/db/fts-builder.js +390 -0
  28. package/dist/db/index.js +55 -0
  29. package/dist/db/specs-store.js +13 -0
  30. package/dist/db/sqlite-specs-store.js +934 -0
  31. package/dist/extract/codebase-intel.js +31 -2
  32. package/dist/extract/compress.js +70 -3
  33. package/dist/extract/context-block.js +11 -2
  34. package/dist/extract/function-intel.js +5 -2
  35. package/dist/extract/index.js +1 -23
  36. package/dist/extract/writer.js +6 -0
  37. package/package.json +4 -1
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Public API for the specs store module.
3
+ *
4
+ * Usage:
5
+ * import { openSpecsStore } from "./db/index.js";
6
+ * const store = await openSpecsStore(layout);
7
+ * const entry = await store.readSpec("codebase-intelligence");
8
+ * await store.close();
9
+ *
10
+ * The adapter is chosen automatically:
11
+ * - If guardian.db exists in the specs root → SqliteSpecsStore
12
+ * - Otherwise → FileSpecsStore (current behavior, fully backward-compatible)
13
+ *
14
+ * To force SQLite (e.g. during `guardian extract --backend sqlite`):
15
+ * const store = await openSpecsStore(layout, { backend: "sqlite" });
16
+ */
17
+ import fs from "node:fs/promises";
18
+ import path from "node:path";
19
+ import { FileSpecsStore } from "./file-specs-store.js";
20
+ import { SqliteSpecsStore, DB_FILENAME } from "./sqlite-specs-store.js";
21
+ export { FileSpecsStore } from "./file-specs-store.js";
22
+ export { SqliteSpecsStore, DB_FILENAME } from "./sqlite-specs-store.js";
23
+ /**
24
+ * Open the appropriate SpecsStore for the given output layout.
25
+ * Always calls store.init() before returning.
26
+ *
27
+ * backend "auto" (default): use SQLite if guardian.db exists, else file
28
+ * backend "sqlite": require SQLite (caller must handle missing db)
29
+ * backend "file": always use file store
30
+ */
31
+ export async function openSpecsStore(layout, options = {}) {
32
+ // "auto" and undefined both probe for guardian.db
33
+ const requested = options.backend ?? "auto";
34
+ const resolved = requested === "auto" || requested === undefined
35
+ ? await detectBackend(layout.rootDir)
36
+ : requested;
37
+ let store;
38
+ if (resolved === "sqlite") {
39
+ store = new SqliteSpecsStore(layout.rootDir);
40
+ }
41
+ else {
42
+ store = new FileSpecsStore(layout.machineDir, layout.humanDir);
43
+ }
44
+ await store.init();
45
+ return store;
46
+ }
47
+ async function detectBackend(rootDir) {
48
+ try {
49
+ await fs.stat(path.join(rootDir, DB_FILENAME));
50
+ return "sqlite";
51
+ }
52
+ catch {
53
+ return "file";
54
+ }
55
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * SpecsStore — IO adapter interface for guardian spec files.
3
+ *
4
+ * All reads and writes of .specs content flow through this interface.
5
+ * Two implementations exist:
6
+ * - FileSpecsStore (default today) — reads/writes individual files on disk
7
+ * - SqliteSpecsStore — reads/writes a single guardian.db
8
+ *
9
+ * Callers never reference the filesystem or SQLite directly; they use
10
+ * this interface. Switching storage backends requires zero changes outside
11
+ * this module.
12
+ */
13
+ export {};