@karmaniverous/jeeves-watcher 0.12.0 → 0.14.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.
package/dist/index.d.ts CHANGED
@@ -22,6 +22,10 @@ declare const watchConfigSchema: z.ZodObject<{
22
22
  debounceMs: z.ZodOptional<z.ZodNumber>;
23
23
  stabilityThresholdMs: z.ZodOptional<z.ZodNumber>;
24
24
  respectGitignore: z.ZodOptional<z.ZodBoolean>;
25
+ moveDetection: z.ZodOptional<z.ZodObject<{
26
+ enabled: z.ZodDefault<z.ZodBoolean>;
27
+ bufferMs: z.ZodDefault<z.ZodNumber>;
28
+ }, z.core.$strip>>;
25
29
  }, z.core.$strip>;
26
30
  /** Watch configuration for file system monitoring paths, ignore patterns, and debounce/stability settings. */
27
31
  type WatchConfig = z.infer<typeof watchConfigSchema>;
@@ -113,6 +117,10 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
113
117
  debounceMs: z.ZodOptional<z.ZodNumber>;
114
118
  stabilityThresholdMs: z.ZodOptional<z.ZodNumber>;
115
119
  respectGitignore: z.ZodOptional<z.ZodBoolean>;
120
+ moveDetection: z.ZodOptional<z.ZodObject<{
121
+ enabled: z.ZodDefault<z.ZodBoolean>;
122
+ bufferMs: z.ZodDefault<z.ZodNumber>;
123
+ }, z.core.$strip>>;
116
124
  }, z.core.$strip>;
117
125
  configWatch: z.ZodOptional<z.ZodObject<{
118
126
  enabled: z.ZodOptional<z.ZodBoolean>;
@@ -134,7 +142,6 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
134
142
  collectionName: z.ZodString;
135
143
  apiKey: z.ZodOptional<z.ZodString>;
136
144
  }, z.core.$strip>;
137
- metadataDir: z.ZodOptional<z.ZodString>;
138
145
  api: z.ZodOptional<z.ZodObject<{
139
146
  host: z.ZodOptional<z.ZodString>;
140
147
  port: z.ZodOptional<z.ZodNumber>;
@@ -289,6 +296,62 @@ type ProviderFactory = (config: EmbeddingConfig, logger?: pino.Logger) => Embedd
289
296
  */
290
297
  declare function createEmbeddingProvider(config: EmbeddingConfig, logger?: pino.Logger, additionalProviders?: Map<string, ProviderFactory>): EmbeddingProvider;
291
298
 
299
+ /**
300
+ * @module enrichment/EnrichmentStore
301
+ * SQLite-backed enrichment metadata store. Persists path-keyed metadata at stateDir/enrichments.sqlite. Atomic writes, supports move.
302
+ */
303
+ /**
304
+ * Interface for enrichment metadata persistence.
305
+ */
306
+ interface EnrichmentStoreInterface {
307
+ /** Get enrichment metadata for a file path, or null. */
308
+ get(path: string): Record<string, unknown> | null;
309
+ /** Set/merge enrichment metadata for a file path. */
310
+ set(path: string, metadata: Record<string, unknown>): void;
311
+ /** Delete enrichment metadata for a file path. */
312
+ delete(path: string): void;
313
+ /** Move enrichment from old path to new path (atomic). */
314
+ move(oldPath: string, newPath: string): void;
315
+ /** List all enriched paths (for diagnostics). */
316
+ list(): string[];
317
+ /** Close the database connection. */
318
+ close(): void;
319
+ }
320
+ /**
321
+ * SQLite-backed enrichment metadata store.
322
+ */
323
+ declare class EnrichmentStore implements EnrichmentStoreInterface {
324
+ private readonly db;
325
+ /**
326
+ * Create or open the enrichment store.
327
+ *
328
+ * @param stateDir - Directory for the SQLite database file.
329
+ */
330
+ constructor(stateDir: string);
331
+ get(path: string): Record<string, unknown> | null;
332
+ set(path: string, metadata: Record<string, unknown>): void;
333
+ delete(path: string): void;
334
+ move(oldPath: string, newPath: string): void;
335
+ list(): string[];
336
+ close(): void;
337
+ }
338
+
339
+ /**
340
+ * @module enrichment/merge
341
+ * Composable merge for inferred + enrichment metadata. Scalars: enrichment overwrites. Arrays: union + deduplicate. No I/O.
342
+ */
343
+ /**
344
+ * Merge enrichment metadata into inferred metadata with composable semantics.
345
+ *
346
+ * - Scalar fields: enrichment value overwrites inferred value.
347
+ * - Array fields: union merge with deduplication (enrichment values appended).
348
+ *
349
+ * @param inferred - Metadata derived from inference rules.
350
+ * @param enrichment - Human/agent-provided enrichment metadata.
351
+ * @returns Merged metadata.
352
+ */
353
+ declare function mergeEnrichment(inferred: Record<string, unknown>, enrichment: Record<string, unknown>): Record<string, unknown>;
354
+
292
355
  /**
293
356
  * Processor-level gitignore filter. Checks file paths against the nearest
294
357
  * `.gitignore` chain in git repositories.
@@ -416,6 +479,52 @@ declare class IssuesManager extends JsonFileStore<IssuesFile> {
416
479
  getAll(): IssuesFile;
417
480
  }
418
481
 
482
+ /**
483
+ * @module cache/ContentHashCache
484
+ * In-memory cache mapping normalized file paths to content hashes.
485
+ * Supports reverse lookup by hash for move correlation.
486
+ */
487
+ /**
488
+ * In-memory content hash cache for move detection.
489
+ *
490
+ * Maps normalized file paths to SHA-256 content hashes.
491
+ * Supports reverse lookup (hash → paths) for correlating
492
+ * unlink+add events as file moves.
493
+ */
494
+ declare class ContentHashCache {
495
+ private readonly pathToHash;
496
+ private readonly hashToPaths;
497
+ /**
498
+ * Store or update the content hash for a file path.
499
+ *
500
+ * @param filePath - The file path (will be normalized).
501
+ * @param hash - The SHA-256 content hash.
502
+ */
503
+ set(filePath: string, hash: string): void;
504
+ /**
505
+ * Get the content hash for a file path.
506
+ *
507
+ * @param filePath - The file path (will be normalized).
508
+ * @returns The content hash, or undefined if not cached.
509
+ */
510
+ get(filePath: string): string | undefined;
511
+ /**
512
+ * Remove a file path from the cache.
513
+ *
514
+ * @param filePath - The file path (will be normalized).
515
+ */
516
+ delete(filePath: string): void;
517
+ /**
518
+ * Reverse lookup: get all file paths with a given content hash.
519
+ *
520
+ * @param hash - The content hash to look up.
521
+ * @returns Array of normalized file paths with that hash.
522
+ */
523
+ getByHash(hash: string): string[];
524
+ /** Number of cached entries. */
525
+ get size(): number;
526
+ }
527
+
419
528
  /**
420
529
  * @module templates/engine
421
530
  * Handlebars template compilation, caching, and resolution (file path vs named ref vs inline).
@@ -872,6 +981,13 @@ interface VectorStore {
872
981
  * @returns An array of search results.
873
982
  */
874
983
  hybridSearch(vector: number[], queryText: string, limit: number, textWeight: number, filter?: Record<string, unknown>): Promise<SearchResult[]>;
984
+ /**
985
+ * Retrieve points with their vectors by ID.
986
+ *
987
+ * @param ids - The point IDs to retrieve.
988
+ * @returns Points with vectors and payloads; missing IDs are omitted.
989
+ */
990
+ getPointsWithVectors(ids: string[]): Promise<VectorPoint[]>;
875
991
  }
876
992
 
877
993
  /**
@@ -989,6 +1105,13 @@ declare class VectorStoreClient implements VectorStore {
989
1105
  * @returns An array of search results.
990
1106
  */
991
1107
  hybridSearch(vector: number[], queryText: string, limit: number, textWeight: number, filter?: Record<string, unknown>): Promise<SearchResult[]>;
1108
+ /**
1109
+ * Retrieve points with their vectors by ID.
1110
+ *
1111
+ * @param ids - The point IDs to retrieve.
1112
+ * @returns Points with vectors and payloads; missing IDs are omitted.
1113
+ */
1114
+ getPointsWithVectors(ids: string[]): Promise<VectorPoint[]>;
992
1115
  /**
993
1116
  * Scroll one page of points matching a filter.
994
1117
  *
@@ -1018,8 +1141,6 @@ declare class VectorStoreClient implements VectorStore {
1018
1141
  * Configuration needed by DocumentProcessor (ISP — narrow interface).
1019
1142
  */
1020
1143
  interface ProcessorConfig {
1021
- /** Metadata directory for enrichment files. */
1022
- metadataDir: string;
1023
1144
  /** Maximum chunk size in characters. */
1024
1145
  chunkSize?: number;
1025
1146
  /** Overlap between chunks in characters. */
@@ -1075,6 +1196,8 @@ interface DocumentProcessorInterface {
1075
1196
  processRulesUpdate(filePath: string): Promise<Record<string, unknown> | null>;
1076
1197
  /** Render a file through the rule engine without embedding. */
1077
1198
  renderFile(filePath: string): Promise<RenderResult>;
1199
+ /** Move a file's vector points and metadata from old path to new path (no re-embed). */
1200
+ moveFile(oldPath: string, newPath: string): Promise<void>;
1078
1201
  /** Update compiled inference rules and associated engines. */
1079
1202
  updateRules(compiledRules: CompiledRule[], templateEngine?: TemplateEngine, customMapLib?: Record<string, (...args: unknown[]) => unknown>): void;
1080
1203
  }
@@ -1103,10 +1226,14 @@ interface DocumentProcessorDeps {
1103
1226
  logger: pino.Logger;
1104
1227
  /** Optional Handlebars template engine for content templates. */
1105
1228
  templateEngine?: TemplateEngine;
1229
+ /** Optional enrichment store for persisted enrichment metadata. */
1230
+ enrichmentStore?: EnrichmentStoreInterface;
1106
1231
  /** Optional issues manager for tracking processing errors. */
1107
1232
  issuesManager?: IssuesManager;
1108
1233
  /** Optional values manager for tracking rule-extracted values. */
1109
1234
  valuesManager?: ValuesManager;
1235
+ /** Optional content hash cache for move detection. */
1236
+ contentHashCache?: ContentHashCache;
1110
1237
  }
1111
1238
  /**
1112
1239
  * Core document processing pipeline.
@@ -1120,14 +1247,16 @@ declare class DocumentProcessor implements DocumentProcessorInterface {
1120
1247
  private compiledRules;
1121
1248
  private readonly logger;
1122
1249
  private templateEngine?;
1250
+ private readonly enrichmentStore?;
1123
1251
  private readonly issuesManager?;
1124
1252
  private readonly valuesManager?;
1253
+ private readonly contentHashCache?;
1125
1254
  /**
1126
1255
  * Create a new DocumentProcessor.
1127
1256
  *
1128
1257
  * @param deps - The processor dependencies.
1129
1258
  */
1130
- constructor({ config, embeddingProvider, vectorStore, compiledRules, logger, templateEngine, issuesManager, valuesManager, }: DocumentProcessorDeps);
1259
+ constructor({ config, embeddingProvider, vectorStore, compiledRules, logger, templateEngine, enrichmentStore, issuesManager, valuesManager, contentHashCache, }: DocumentProcessorDeps);
1131
1260
  /**
1132
1261
  * Build merged metadata for a file and add matched_rules.
1133
1262
  */
@@ -1149,7 +1278,7 @@ declare class DocumentProcessor implements DocumentProcessorInterface {
1149
1278
  */
1150
1279
  deleteFile(filePath: string): Promise<void>;
1151
1280
  /**
1152
- * Process a metadata update: merge metadata, write to disk, update Qdrant payloads (no re-embed).
1281
+ * Process a metadata update: merge into enrichment store, update Qdrant payloads (no re-embed).
1153
1282
  *
1154
1283
  * @param filePath - The file whose metadata to update.
1155
1284
  * @param metadata - The new metadata to merge.
@@ -1173,6 +1302,14 @@ declare class DocumentProcessor implements DocumentProcessorInterface {
1173
1302
  * @returns The render result.
1174
1303
  */
1175
1304
  renderFile(filePath: string): Promise<RenderResult>;
1305
+ /**
1306
+ * Move a file's vector points from old path to new path without re-embedding.
1307
+ * Re-applies inference rules against the new path.
1308
+ *
1309
+ * @param oldPath - The original file path.
1310
+ * @param newPath - The new file path.
1311
+ */
1312
+ moveFile(oldPath: string, newPath: string): Promise<void>;
1176
1313
  /**
1177
1314
  * Update compiled inference rules, template engine, and custom map lib.
1178
1315
  *
@@ -1192,9 +1329,11 @@ declare class DocumentProcessor implements DocumentProcessorInterface {
1192
1329
  */
1193
1330
  type WatchEvent = {
1194
1331
  /** Event type. */
1195
- type: 'create' | 'modify' | 'delete';
1196
- /** File path associated with the event. */
1332
+ type: 'create' | 'modify' | 'delete' | 'move';
1333
+ /** File path associated with the event (new path for moves). */
1197
1334
  path: string;
1335
+ /** Original path before move (populated only for move events). */
1336
+ oldPath?: string;
1198
1337
  /** Event priority. */
1199
1338
  priority: 'normal' | 'low';
1200
1339
  };
@@ -1376,6 +1515,8 @@ interface FileSystemWatcherOptions {
1376
1515
  gitignoreFilter?: GitignoreFilter;
1377
1516
  /** Optional tracker for initial scan visibility in /status. */
1378
1517
  initialScanTracker?: InitialScanTracker;
1518
+ /** Optional content hash cache for move detection. */
1519
+ contentHashCache?: ContentHashCache;
1379
1520
  }
1380
1521
  /**
1381
1522
  * Filesystem watcher that maps chokidar events to the processing queue.
@@ -1388,6 +1529,8 @@ declare class FileSystemWatcher {
1388
1529
  private readonly health;
1389
1530
  private readonly gitignoreFilter?;
1390
1531
  private readonly initialScanTracker?;
1532
+ private readonly contentHashCache?;
1533
+ private moveCorrelator?;
1391
1534
  private globMatches;
1392
1535
  private watcher;
1393
1536
  /**
@@ -1518,6 +1661,8 @@ interface ApiServerOptions {
1518
1661
  initialScanTracker?: InitialScanTracker;
1519
1662
  /** Filesystem watcher instance for /walk endpoint (in-memory file list). */
1520
1663
  fileSystemWatcher?: FileSystemWatcher;
1664
+ /** Optional enrichment store for persisted enrichment metadata. */
1665
+ enrichmentStore?: EnrichmentStoreInterface;
1521
1666
  }
1522
1667
  /**
1523
1668
  * Create the Fastify API server with all routes registered.
@@ -1617,6 +1762,8 @@ declare class JeevesWatcher {
1617
1762
  private vectorStore;
1618
1763
  private embeddingProvider;
1619
1764
  private gitignoreFilter;
1765
+ private enrichmentStore;
1766
+ private contentHashCache;
1620
1767
  private readonly initialScanTracker;
1621
1768
  private readonly version;
1622
1769
  /** Create a new JeevesWatcher instance. */
@@ -1680,38 +1827,6 @@ declare function extractText(filePath: string, extension: string, additionalExtr
1680
1827
  */
1681
1828
  declare function contentHash(text: string): string;
1682
1829
 
1683
- /**
1684
- * Derive a deterministic `.meta.json` path for a given file.
1685
- *
1686
- * @param filePath - The watched file path.
1687
- * @param metadataDir - The root metadata directory.
1688
- * @returns The full path to the metadata file.
1689
- */
1690
- declare function metadataPath(filePath: string, metadataDir: string): string;
1691
- /**
1692
- * Read persisted metadata for a file.
1693
- *
1694
- * @param filePath - The watched file path.
1695
- * @param metadataDir - The root metadata directory.
1696
- * @returns The parsed metadata object, or `null` if not found.
1697
- */
1698
- declare function readMetadata(filePath: string, metadataDir: string): Promise<Record<string, unknown> | null>;
1699
- /**
1700
- * Write metadata for a file.
1701
- *
1702
- * @param filePath - The watched file path.
1703
- * @param metadataDir - The root metadata directory.
1704
- * @param metadata - The metadata to persist.
1705
- */
1706
- declare function writeMetadata(filePath: string, metadataDir: string, metadata: Record<string, unknown>): Promise<void>;
1707
- /**
1708
- * Delete metadata for a file.
1709
- *
1710
- * @param filePath - The watched file path.
1711
- * @param metadataDir - The root metadata directory.
1712
- */
1713
- declare function deleteMetadata(filePath: string, metadataDir: string): Promise<void>;
1714
-
1715
1830
  /**
1716
1831
  * Generate a deterministic UUID v5 point ID for a file (and optional chunk index).
1717
1832
  *
@@ -1721,5 +1836,5 @@ declare function deleteMetadata(filePath: string, metadataDir: string): Promise<
1721
1836
  */
1722
1837
  declare function pointId(filePath: string, chunkIndex?: number): string;
1723
1838
 
1724
- export { DocumentProcessor, EventQueue, FileSystemWatcher, GitignoreFilter, InitialScanTracker, IssuesManager, JeevesWatcher, ReindexTracker, SystemHealth, TemplateEngine, ValuesManager, VectorStoreClient, VirtualRuleStore, apiConfigSchema, applyRules, buildAttributes, buildTemplateEngine, compileRules, configWatchConfigSchema, contentHash, createApiServer, createEmbeddingProvider, createHandlebarsInstance, createLogger, deleteMetadata, embeddingConfigSchema, extractText, inferenceRuleSchema, issueRecordSchema, jeevesWatcherConfigSchema, loadConfig, loadCustomHelpers, loggingConfigSchema, metadataPath, pointId, readMetadata, registerBuiltinHelpers, resolveTemplateSource, startFromConfig, vectorStoreConfigSchema, watchConfigSchema, writeMetadata };
1725
- export type { AllHelpersIntrospection, ApiConfig, ApiServerOptions, ApplyRulesOptions, ApplyRulesResult, CollectionInfo, CompiledRule, CompiledTemplate, ConfigWatchConfig, DocumentProcessorDeps, DocumentProcessorInterface, EmbeddingConfig, EmbeddingProvider, EventQueueOptions, ExtractedText, Extractor, FileAttributes, FileSystemWatcherOptions, HelperModuleIntrospection, InferenceRule, InitialScanStatus, IssueRecord, IssuesFile, JeevesWatcherConfig, JeevesWatcherConfigInput, JeevesWatcherFactories, JeevesWatcherRuntimeOptions, LoggingConfig, PayloadFieldSchema, ProcessFn, ProcessorConfig, ProviderFactory, ReindexStatus, RenderResult, RuleLogger, ScrollPageResult, ScrolledPoint, SearchResult, SystemHealthOptions, ValuesIndex, VectorPoint, VectorStore, VectorStoreConfig, WatchConfig, WatchEvent };
1839
+ export { DocumentProcessor, EnrichmentStore, EventQueue, FileSystemWatcher, GitignoreFilter, InitialScanTracker, IssuesManager, JeevesWatcher, ReindexTracker, SystemHealth, TemplateEngine, ValuesManager, VectorStoreClient, VirtualRuleStore, apiConfigSchema, applyRules, buildAttributes, buildTemplateEngine, compileRules, configWatchConfigSchema, contentHash, createApiServer, createEmbeddingProvider, createHandlebarsInstance, createLogger, embeddingConfigSchema, extractText, inferenceRuleSchema, issueRecordSchema, jeevesWatcherConfigSchema, loadConfig, loadCustomHelpers, loggingConfigSchema, mergeEnrichment, pointId, registerBuiltinHelpers, resolveTemplateSource, startFromConfig, vectorStoreConfigSchema, watchConfigSchema };
1840
+ export type { AllHelpersIntrospection, ApiConfig, ApiServerOptions, ApplyRulesOptions, ApplyRulesResult, CollectionInfo, CompiledRule, CompiledTemplate, ConfigWatchConfig, DocumentProcessorDeps, DocumentProcessorInterface, EmbeddingConfig, EmbeddingProvider, EnrichmentStoreInterface, EventQueueOptions, ExtractedText, Extractor, FileAttributes, FileSystemWatcherOptions, HelperModuleIntrospection, InferenceRule, InitialScanStatus, IssueRecord, IssuesFile, JeevesWatcherConfig, JeevesWatcherConfigInput, JeevesWatcherFactories, JeevesWatcherRuntimeOptions, LoggingConfig, PayloadFieldSchema, ProcessFn, ProcessorConfig, ProviderFactory, ReindexStatus, RenderResult, RuleLogger, ScrollPageResult, ScrolledPoint, SearchResult, SystemHealthOptions, ValuesIndex, VectorPoint, VectorStore, VectorStoreConfig, WatchConfig, WatchEvent };