@karmaniverous/jeeves-watcher 0.2.0 → 0.2.1

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
@@ -159,6 +159,11 @@ interface EmbeddingProvider {
159
159
  */
160
160
  declare function createEmbeddingProvider(config: EmbeddingConfig, logger?: pino.Logger): EmbeddingProvider;
161
161
 
162
+ /**
163
+ * @module rules/attributes
164
+ * Builds file attribute objects for rule matching. Pure function: derives attributes from path, stats, and extracted data.
165
+ */
166
+
162
167
  /**
163
168
  * Attributes derived from a watched file for rule matching.
164
169
  */
@@ -183,15 +188,6 @@ interface FileAttributes {
183
188
  /** Parsed JSON content, if any. */
184
189
  json?: Record<string, unknown>;
185
190
  }
186
- /**
187
- * A compiled inference rule ready for evaluation.
188
- */
189
- interface CompiledRule {
190
- /** The original rule definition. */
191
- rule: InferenceRule;
192
- /** The compiled ajv validate function. */
193
- validate: (data: unknown) => boolean;
194
- }
195
191
  /**
196
192
  * Build {@link FileAttributes} from a file path and stat info.
197
193
  *
@@ -202,6 +198,21 @@ interface CompiledRule {
202
198
  * @returns The constructed file attributes.
203
199
  */
204
200
  declare function buildAttributes(filePath: string, stats: Stats, extractedFrontmatter?: Record<string, unknown>, extractedJson?: Record<string, unknown>): FileAttributes;
201
+
202
+ /**
203
+ * @module rules/compile
204
+ * Compiles inference rule definitions into executable AJV validators for efficient rule evaluation.
205
+ */
206
+
207
+ /**
208
+ * A compiled inference rule ready for evaluation.
209
+ */
210
+ interface CompiledRule {
211
+ /** The original rule definition. */
212
+ rule: InferenceRule;
213
+ /** The compiled AJV validate function. */
214
+ validate: (data: unknown) => boolean;
215
+ }
205
216
  /**
206
217
  * Compile an array of inference rules into executable validators.
207
218
  *
@@ -209,6 +220,19 @@ declare function buildAttributes(filePath: string, stats: Stats, extractedFrontm
209
220
  * @returns An array of compiled rules.
210
221
  */
211
222
  declare function compileRules(rules: InferenceRule[]): CompiledRule[];
223
+
224
+ /**
225
+ * @module rules/apply
226
+ * Applies compiled inference rules to file attributes, producing merged metadata via template resolution and JsonMap transforms.
227
+ */
228
+
229
+ /**
230
+ * A minimal logger interface for rule application warnings.
231
+ */
232
+ interface RuleLogger {
233
+ /** Log a warning message during rule application. */
234
+ warn(msg: string): void;
235
+ }
212
236
  /**
213
237
  * Apply compiled inference rules to file attributes, returning merged metadata.
214
238
  *
@@ -219,10 +243,10 @@ declare function compileRules(rules: InferenceRule[]): CompiledRule[];
219
243
  * @param compiledRules - The compiled rules to evaluate.
220
244
  * @param attributes - The file attributes to match against.
221
245
  * @param namedMaps - Optional record of named JsonMap definitions.
222
- * @param logger - Optional pino logger for warnings (falls back to console.warn).
246
+ * @param logger - Optional logger for warnings (falls back to console.warn).
223
247
  * @returns The merged metadata from all matching rules.
224
248
  */
225
- declare function applyRules(compiledRules: CompiledRule[], attributes: FileAttributes, namedMaps?: Record<string, JsonMapMap>, logger?: pino.Logger): Promise<Record<string, unknown>>;
249
+ declare function applyRules(compiledRules: CompiledRule[], attributes: FileAttributes, namedMaps?: Record<string, JsonMapMap>, logger?: RuleLogger): Promise<Record<string, unknown>>;
226
250
 
227
251
  /**
228
252
  * A point to upsert into the vector store.
@@ -262,7 +286,7 @@ declare class VectorStoreClient {
262
286
  private readonly client;
263
287
  private readonly collectionName;
264
288
  private readonly dims;
265
- private readonly logger?;
289
+ private readonly log;
266
290
  /**
267
291
  * Create a new VectorStoreClient.
268
292
  *
@@ -504,26 +528,91 @@ interface ApiServerOptions {
504
528
  */
505
529
  declare function createApiServer(options: ApiServerOptions): FastifyInstance;
506
530
 
531
+ /**
532
+ * @module logger
533
+ * Creates pino logger instances. I/O: optionally writes logs to file via pino/file transport. Defaults to stdout at info level.
534
+ */
535
+
536
+ /**
537
+ * Create a pino logger instance.
538
+ *
539
+ * @param config - Optional logging configuration.
540
+ * @returns A configured pino logger.
541
+ */
542
+ declare function createLogger(config?: LoggingConfig): pino.Logger;
543
+
544
+ /**
545
+ * Filesystem watcher that maps chokidar events to the processing queue.
546
+ */
547
+ declare class FileSystemWatcher {
548
+ private readonly config;
549
+ private readonly queue;
550
+ private readonly processor;
551
+ private readonly logger;
552
+ private watcher;
553
+ /**
554
+ * Create a new FileSystemWatcher.
555
+ *
556
+ * @param config - Watch configuration.
557
+ * @param queue - The event queue.
558
+ * @param processor - The document processor.
559
+ * @param logger - The logger instance.
560
+ */
561
+ constructor(config: WatchConfig, queue: EventQueue, processor: DocumentProcessor, logger: pino.Logger);
562
+ /**
563
+ * Start watching the filesystem and processing events.
564
+ */
565
+ start(): void;
566
+ /**
567
+ * Stop the filesystem watcher.
568
+ */
569
+ stop(): Promise<void>;
570
+ }
571
+
572
+ /**
573
+ * Component factories for {@link JeevesWatcher}. Override in tests to inject mocks.
574
+ */
575
+ interface JeevesWatcherFactories {
576
+ /** Load and validate a {@link JeevesWatcherConfig} from disk. */
577
+ loadConfig: (configPath?: string) => Promise<JeevesWatcherConfig>;
578
+ /** Create a pino logger instance. */
579
+ createLogger: typeof createLogger;
580
+ /** Create an embedding provider from config. */
581
+ createEmbeddingProvider: typeof createEmbeddingProvider;
582
+ /** Create a vector-store client for similarity search and upsert. */
583
+ createVectorStoreClient: (config: JeevesWatcherConfig['vectorStore'], dimensions: number, logger: pino.Logger) => VectorStoreClient;
584
+ /** Compile inference rules from config. */
585
+ compileRules: typeof compileRules;
586
+ /** Create a document processor for file ingestion. */
587
+ createDocumentProcessor: (config: ConstructorParameters<typeof DocumentProcessor>[0], embeddingProvider: EmbeddingProvider, vectorStore: VectorStoreClient, compiledRules: ConstructorParameters<typeof DocumentProcessor>[3], logger: pino.Logger) => DocumentProcessor;
588
+ /** Create an event queue for batching file-system events. */
589
+ createEventQueue: (options: ConstructorParameters<typeof EventQueue>[0]) => EventQueue;
590
+ /** Create a file-system watcher for the configured watch paths. */
591
+ createFileSystemWatcher: (config: JeevesWatcherConfig['watch'], queue: EventQueue, processor: DocumentProcessor, logger: pino.Logger) => FileSystemWatcher;
592
+ /** Create the HTTP API server. */
593
+ createApiServer: typeof createApiServer;
594
+ }
507
595
  /**
508
596
  * Main application class that wires together all components.
509
597
  */
510
598
  declare class JeevesWatcher {
511
599
  private config;
512
600
  private readonly configPath?;
601
+ private readonly factories;
513
602
  private logger;
514
603
  private watcher;
515
604
  private queue;
516
605
  private server;
517
606
  private processor;
518
607
  private configWatcher;
519
- private configDebounce;
520
608
  /**
521
609
  * Create a new JeevesWatcher instance.
522
610
  *
523
611
  * @param config - The application configuration.
524
612
  * @param configPath - Optional config file path to watch for changes.
613
+ * @param factories - Optional component factories (for dependency injection).
525
614
  */
526
- constructor(config: JeevesWatcherConfig, configPath?: string);
615
+ constructor(config: JeevesWatcherConfig, configPath?: string, factories?: Partial<JeevesWatcherFactories>);
527
616
  /**
528
617
  * Start the watcher, API server, and all components.
529
618
  */
@@ -586,19 +675,6 @@ declare function extractText(filePath: string, extension: string): Promise<Extra
586
675
  */
587
676
  declare function contentHash(text: string): string;
588
677
 
589
- /**
590
- * @module logger
591
- * Creates pino logger instances. I/O: optionally writes logs to file via pino/file transport. Defaults to stdout at info level.
592
- */
593
-
594
- /**
595
- * Create a pino logger instance.
596
- *
597
- * @param config - Optional logging configuration.
598
- * @returns A configured pino logger.
599
- */
600
- declare function createLogger(config?: LoggingConfig): pino.Logger;
601
-
602
678
  /**
603
679
  * Derive a deterministic `.meta.json` path for a given file.
604
680
  *
@@ -640,33 +716,5 @@ declare function deleteMetadata(filePath: string, metadataDir: string): Promise<
640
716
  */
641
717
  declare function pointId(filePath: string, chunkIndex?: number): string;
642
718
 
643
- /**
644
- * Filesystem watcher that maps chokidar events to the processing queue.
645
- */
646
- declare class FileSystemWatcher {
647
- private readonly config;
648
- private readonly queue;
649
- private readonly processor;
650
- private readonly logger;
651
- private watcher;
652
- /**
653
- * Create a new FileSystemWatcher.
654
- *
655
- * @param config - Watch configuration.
656
- * @param queue - The event queue.
657
- * @param processor - The document processor.
658
- * @param logger - The logger instance.
659
- */
660
- constructor(config: WatchConfig, queue: EventQueue, processor: DocumentProcessor, logger: pino.Logger);
661
- /**
662
- * Start watching the filesystem and processing events.
663
- */
664
- start(): void;
665
- /**
666
- * Stop the filesystem watcher.
667
- */
668
- stop(): Promise<void>;
669
- }
670
-
671
719
  export { DocumentProcessor, EventQueue, FileSystemWatcher, JeevesWatcher, VectorStoreClient, apiConfigSchema, applyRules, buildAttributes, compileRules, configWatchConfigSchema, contentHash, createApiServer, createEmbeddingProvider, createLogger, deleteMetadata, embeddingConfigSchema, extractText, inferenceRuleSchema, jeevesWatcherConfigSchema, loadConfig, loggingConfigSchema, metadataPath, pointId, readMetadata, startFromConfig, vectorStoreConfigSchema, watchConfigSchema, writeMetadata };
672
- export type { ApiConfig, ApiServerOptions, CompiledRule, ConfigWatchConfig, EmbeddingConfig, EmbeddingProvider, EventQueueOptions, ExtractedText, FileAttributes, InferenceRule, JeevesWatcherConfig, LoggingConfig, ProcessFn, ProcessorConfig, ScrolledPoint, SearchResult, VectorPoint, VectorStoreConfig, WatchConfig, WatchEvent };
720
+ export type { ApiConfig, ApiServerOptions, CompiledRule, ConfigWatchConfig, EmbeddingConfig, EmbeddingProvider, EventQueueOptions, ExtractedText, FileAttributes, InferenceRule, JeevesWatcherConfig, JeevesWatcherFactories, LoggingConfig, ProcessFn, ProcessorConfig, RuleLogger, ScrolledPoint, SearchResult, VectorPoint, VectorStoreConfig, WatchConfig, WatchEvent };