@karmaniverous/jeeves-watcher 0.5.0 → 0.6.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
@@ -125,7 +125,7 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
125
125
  }, z.core.$strip>>;
126
126
  extractors: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
127
127
  stateDir: z.ZodOptional<z.ZodString>;
128
- inferenceRules: z.ZodOptional<z.ZodArray<z.ZodObject<{
128
+ inferenceRules: z.ZodOptional<z.ZodArray<z.ZodUnion<readonly [z.ZodObject<{
129
129
  name: z.ZodString;
130
130
  description: z.ZodString;
131
131
  match: z.ZodRecord<z.ZodString, z.ZodUnknown>;
@@ -135,7 +135,7 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
135
135
  }, z.core.$strip>]>>>;
136
136
  map: z.ZodOptional<z.ZodUnion<readonly [z.ZodType<_karmaniverous_jsonmap.JsonMapMap, unknown, z.core.$ZodTypeInternals<_karmaniverous_jsonmap.JsonMapMap, unknown>>, z.ZodString]>>;
137
137
  template: z.ZodOptional<z.ZodString>;
138
- }, z.core.$strip>>>;
138
+ }, z.core.$strip>, z.ZodString]>>>;
139
139
  maps: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodType<_karmaniverous_jsonmap.JsonMapMap, unknown, z.core.$ZodTypeInternals<_karmaniverous_jsonmap.JsonMapMap, unknown>>, z.ZodString, z.ZodObject<{
140
140
  map: z.ZodUnion<[z.ZodType<_karmaniverous_jsonmap.JsonMapMap, unknown, z.core.$ZodTypeInternals<_karmaniverous_jsonmap.JsonMapMap, unknown>>, z.ZodString]>;
141
141
  description: z.ZodOptional<z.ZodString>;
@@ -162,6 +162,10 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
162
162
  relevant: z.ZodNumber;
163
163
  noise: z.ZodNumber;
164
164
  }, z.core.$strip>>;
165
+ hybrid: z.ZodOptional<z.ZodObject<{
166
+ enabled: z.ZodDefault<z.ZodBoolean>;
167
+ textWeight: z.ZodDefault<z.ZodNumber>;
168
+ }, z.core.$strip>>;
165
169
  }, z.core.$strip>>;
166
170
  logging: z.ZodOptional<z.ZodObject<{
167
171
  level: z.ZodOptional<z.ZodString>;
@@ -171,8 +175,18 @@ declare const jeevesWatcherConfigSchema: z.ZodObject<{
171
175
  maxRetries: z.ZodOptional<z.ZodNumber>;
172
176
  maxBackoffMs: z.ZodOptional<z.ZodNumber>;
173
177
  }, z.core.$strip>;
174
- /** Top-level jeeves-watcher configuration: watch paths, embedding, vector store, rules, maps, API, and logging. */
175
- type JeevesWatcherConfig = z.infer<typeof jeevesWatcherConfigSchema>;
178
+ /**
179
+ * Raw configuration as parsed from the Zod schema.
180
+ * May contain string file paths in `inferenceRules` that need resolution.
181
+ */
182
+ type JeevesWatcherConfigInput = z.infer<typeof jeevesWatcherConfigSchema>;
183
+ /**
184
+ * Resolved configuration with all file references loaded.
185
+ * After `loadConfig`, all string rule entries have been resolved to `InferenceRule` objects.
186
+ */
187
+ type JeevesWatcherConfig = Omit<JeevesWatcherConfigInput, 'inferenceRules'> & {
188
+ inferenceRules?: InferenceRule[];
189
+ };
176
190
 
177
191
  /**
178
192
  * @module config/schemas/services
@@ -389,7 +403,7 @@ declare function loadCustomHelpers(hbs: typeof Handlebars, helpers: Record<strin
389
403
  * The template engine: holds compiled templates and renders them against context.
390
404
  */
391
405
  declare class TemplateEngine {
392
- private readonly hbs;
406
+ readonly hbs: typeof Handlebars;
393
407
  private readonly compiled;
394
408
  constructor(hbs: typeof Handlebars);
395
409
  /**
@@ -537,6 +551,23 @@ interface ApplyRulesResult {
537
551
  /** Names of rules that matched. */
538
552
  matchedRules: string[];
539
553
  }
554
+ /**
555
+ * Optional parameters for applyRules beyond the required compiledRules and attributes.
556
+ */
557
+ interface ApplyRulesOptions {
558
+ /** Optional record of named JsonMap definitions. */
559
+ namedMaps?: Record<string, JsonMapMap>;
560
+ /** Optional logger for warnings (falls back to console.warn). */
561
+ logger?: RuleLogger;
562
+ /** Optional template engine for rendering content templates. */
563
+ templateEngine?: TemplateEngine;
564
+ /** Optional config directory for resolving .json map file paths. */
565
+ configDir?: string;
566
+ /** Optional custom JsonMap transform library. */
567
+ customMapLib?: Record<string, (...args: unknown[]) => unknown>;
568
+ /** Optional global schemas collection for resolving schema references. */
569
+ globalSchemas?: Record<string, SchemaEntry>;
570
+ }
540
571
  /**
541
572
  * Apply compiled inference rules to file attributes, returning merged metadata and optional rendered content.
542
573
  *
@@ -546,14 +577,10 @@ interface ApplyRulesResult {
546
577
  *
547
578
  * @param compiledRules - The compiled rules to evaluate.
548
579
  * @param attributes - The file attributes to match against.
549
- * @param namedMaps - Optional record of named JsonMap definitions.
550
- * @param logger - Optional logger for warnings (falls back to console.warn).
551
- * @param templateEngine - Optional template engine for rendering content templates.
552
- * @param configDir - Optional config directory for resolving .json map file paths.
553
- * @param globalSchemas - Optional global schemas collection for resolving schema references.
580
+ * @param options - Optional configuration for rule application.
554
581
  * @returns The merged metadata and optional rendered content.
555
582
  */
556
- declare function applyRules(compiledRules: CompiledRule[], attributes: FileAttributes, namedMaps?: Record<string, JsonMapMap>, logger?: RuleLogger, templateEngine?: TemplateEngine, configDir?: string, customMapLib?: Record<string, (...args: unknown[]) => unknown>, globalSchemas?: Record<string, SchemaEntry>): Promise<ApplyRulesResult>;
583
+ declare function applyRules(compiledRules: CompiledRule[], attributes: FileAttributes, options?: ApplyRulesOptions): Promise<ApplyRulesResult>;
557
584
 
558
585
  /**
559
586
  * @module values/ValuesManager
@@ -689,6 +716,23 @@ interface VectorStore {
689
716
  * @yields Scrolled points.
690
717
  */
691
718
  scroll(filter?: Record<string, unknown>, limit?: number): AsyncGenerator<ScrolledPoint>;
719
+ /**
720
+ * Create a full-text payload index on the specified field.
721
+ *
722
+ * @param fieldName - The payload field to index.
723
+ */
724
+ ensureTextIndex(fieldName: string): Promise<void>;
725
+ /**
726
+ * Hybrid search combining dense vector and full-text match with RRF fusion.
727
+ *
728
+ * @param vector - The query vector.
729
+ * @param queryText - The raw query text for full-text matching.
730
+ * @param limit - Maximum results to return.
731
+ * @param textWeight - Weight for text results in RRF (0–1).
732
+ * @param filter - Optional Qdrant filter.
733
+ * @returns An array of search results.
734
+ */
735
+ hybridSearch(vector: number[], queryText: string, limit: number, textWeight: number, filter?: Record<string, unknown>): Promise<SearchResult[]>;
692
736
  }
693
737
 
694
738
  /**
@@ -701,6 +745,7 @@ declare class VectorStoreClient implements VectorStore {
701
745
  private readonly collectionName;
702
746
  private readonly dims;
703
747
  private readonly log;
748
+ private readonly pinoLogger?;
704
749
  /**
705
750
  * Create a new VectorStoreClient.
706
751
  *
@@ -756,21 +801,32 @@ declare class VectorStoreClient implements VectorStore {
756
801
  */
757
802
  getCollectionInfo(): Promise<CollectionInfo>;
758
803
  /**
759
- * Sample points and discover payload field names and inferred types.
804
+ * Search for similar vectors.
805
+ *
806
+ * @param vector - The query vector.
807
+ * @param limit - Maximum results to return.
808
+ * @param filter - Optional Qdrant filter.
809
+ * @returns An array of search results.
810
+ */
811
+ search(vector: number[], limit: number, filter?: Record<string, unknown>, offset?: number): Promise<SearchResult[]>;
812
+ /**
813
+ * Create a full-text payload index on the specified field.
814
+ * Idempotent — skips if the field already has a text index.
760
815
  *
761
- * @param target - Object to populate with discovered fields.
762
- * @param sampleSize - Number of points to sample.
816
+ * @param fieldName - The payload field to index.
763
817
  */
764
- private discoverPayloadFields;
818
+ ensureTextIndex(fieldName: string): Promise<void>;
765
819
  /**
766
- * Search for similar vectors.
820
+ * Hybrid search combining dense vector and full-text match with RRF fusion.
767
821
  *
768
822
  * @param vector - The query vector.
823
+ * @param queryText - The raw query text for full-text matching.
769
824
  * @param limit - Maximum results to return.
825
+ * @param textWeight - Weight for text results in RRF (0–1).
770
826
  * @param filter - Optional Qdrant filter.
771
827
  * @returns An array of search results.
772
828
  */
773
- search(vector: number[], limit: number, filter?: Record<string, unknown>, offset?: number): Promise<SearchResult[]>;
829
+ hybridSearch(vector: number[], queryText: string, limit: number, textWeight: number, filter?: Record<string, unknown>): Promise<SearchResult[]>;
774
830
  /**
775
831
  * Scroll through all points matching a filter.
776
832
  *
@@ -878,6 +934,14 @@ declare class DocumentProcessor implements DocumentProcessorInterface {
878
934
  * @param deps - The processor dependencies.
879
935
  */
880
936
  constructor({ config, embeddingProvider, vectorStore, compiledRules, logger, templateEngine, issuesManager, valuesManager, }: DocumentProcessorDeps);
937
+ /**
938
+ * Build merged metadata for a file and add matched_rules.
939
+ */
940
+ private buildMetadataWithRules;
941
+ /**
942
+ * Execute an async operation with standardized file error handling.
943
+ */
944
+ private withFileErrorHandling;
881
945
  /**
882
946
  * Process a file through the full pipeline: extract, hash, chunk, embed, upsert.
883
947
  *
@@ -995,6 +1059,54 @@ declare class EventQueue {
995
1059
  private maybeResolveDrain;
996
1060
  }
997
1061
 
1062
+ /**
1063
+ * @module rules/virtualRules
1064
+ * In-memory virtual rule store for externally registered inference rules.
1065
+ *
1066
+ * Virtual rules are registered at runtime by external consumers (e.g., OpenClaw plugins)
1067
+ * and merge into the inference pipeline alongside config-file rules.
1068
+ * They survive config reloads but NOT service restarts.
1069
+ */
1070
+
1071
+ /**
1072
+ * In-memory store for virtual inference rules.
1073
+ *
1074
+ * Virtual rules are appended AFTER config-file rules in evaluation order.
1075
+ * Since inference uses last-match-wins for overlapping fields,
1076
+ * virtual rules take precedence over config rules when both match the same file.
1077
+ */
1078
+ declare class VirtualRuleStore {
1079
+ private readonly entries;
1080
+ /**
1081
+ * Register virtual rules from an external source.
1082
+ * Idempotent: re-registering with the same source replaces previous rules.
1083
+ *
1084
+ * @param source - Unique identifier for the rule source.
1085
+ * @param rules - Inference rule definitions to register.
1086
+ */
1087
+ register(source: string, rules: InferenceRule[]): void;
1088
+ /**
1089
+ * Remove virtual rules by source.
1090
+ *
1091
+ * @param source - The source identifier to unregister.
1092
+ * @returns true if rules were found and removed.
1093
+ */
1094
+ unregister(source: string): boolean;
1095
+ /**
1096
+ * Get all compiled virtual rules in registration order.
1097
+ */
1098
+ getCompiled(): CompiledRule[];
1099
+ /**
1100
+ * Get all raw virtual rule definitions grouped by source.
1101
+ * Used by the merged virtual document.
1102
+ */
1103
+ getAll(): Record<string, InferenceRule[]>;
1104
+ /** Check if any virtual rules are registered. */
1105
+ get isEmpty(): boolean;
1106
+ /** Total number of virtual rules across all sources. */
1107
+ get size(): number;
1108
+ }
1109
+
998
1110
  /**
999
1111
  * @module api/ReindexTracker
1000
1112
  * Tracks reindex operation state for status reporting. Single instance shared across handlers.
@@ -1054,6 +1166,8 @@ interface ApiServerOptions {
1054
1166
  configPath: string;
1055
1167
  /** Helper introspection for merged document. */
1056
1168
  helperIntrospection?: AllHelpersIntrospection;
1169
+ /** Virtual rule store for externally registered inference rules. */
1170
+ virtualRuleStore?: VirtualRuleStore;
1057
1171
  }
1058
1172
  /**
1059
1173
  * Create the Fastify API server with all routes registered.
@@ -1307,14 +1421,10 @@ declare class JeevesWatcher {
1307
1421
  private issuesManager;
1308
1422
  private valuesManager;
1309
1423
  private helperIntrospection;
1310
- /**
1311
- * Create a new JeevesWatcher instance.
1312
- *
1313
- * @param config - The application configuration.
1314
- * @param configPath - Optional config file path to watch for changes.
1315
- * @param factories - Optional component factories (for dependency injection).
1316
- * @param runtimeOptions - Optional runtime-only options (e.g., onFatalError).
1317
- */
1424
+ private virtualRuleStore;
1425
+ private vectorStore;
1426
+ private embeddingProvider;
1427
+ /** Create a new JeevesWatcher instance. */
1318
1428
  constructor(config: JeevesWatcherConfig, configPath?: string, factories?: Partial<JeevesWatcherFactories>, runtimeOptions?: JeevesWatcherRuntimeOptions);
1319
1429
  /**
1320
1430
  * Start the watcher, API server, and all components.