@karmaniverous/jeeves-meta 0.4.1 → 0.5.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
@@ -82,6 +82,7 @@ declare const serviceConfigSchema: z.ZodObject<{
82
82
  port: z.ZodDefault<z.ZodNumber>;
83
83
  schedule: z.ZodDefault<z.ZodString>;
84
84
  reportChannel: z.ZodOptional<z.ZodString>;
85
+ watcherHealthIntervalMs: z.ZodDefault<z.ZodNumber>;
85
86
  logging: z.ZodDefault<z.ZodObject<{
86
87
  level: z.ZodDefault<z.ZodString>;
87
88
  file: z.ZodOptional<z.ZodString>;
@@ -185,6 +186,20 @@ declare function readLatestArchive(metaPath: string): MetaJson | null;
185
186
  */
186
187
  declare function createSnapshot(metaPath: string, meta: MetaJson): string;
187
188
 
189
+ /**
190
+ * Shared constants for the jeeves-meta service package.
191
+ *
192
+ * @module constants
193
+ */
194
+ /** Default HTTP port for the jeeves-meta service. */
195
+ declare const DEFAULT_PORT = 1938;
196
+ /** Default port as a string (for Commander CLI defaults). */
197
+ declare const DEFAULT_PORT_STR: string;
198
+ /** Service name identifier. */
199
+ declare const SERVICE_NAME = "jeeves-meta";
200
+ /** Service version, read from package.json at startup. */
201
+ declare const SERVICE_VERSION: string;
202
+
188
203
  /**
189
204
  * Load and resolve jeeves-meta service config.
190
205
  *
@@ -224,7 +239,7 @@ declare function loadServiceConfig(configPath: string): ServiceConfig;
224
239
  * Context package for a single synthesis cycle.
225
240
  *
226
241
  * The orchestrator computes this once per cycle from the meta path,
227
- * ownership tree, watcher scan results, and filesystem reads.
242
+ * ownership tree, watcher walk results, and filesystem reads.
228
243
  */
229
244
  interface MetaContext {
230
245
  /** Absolute path to the .meta directory. */
@@ -289,45 +304,11 @@ interface MetaExecutor {
289
304
  /**
290
305
  * Abstraction over the jeeves-watcher HTTP API.
291
306
  *
292
- * The orchestrator uses this for structured queries (POST /scan)
293
- * and virtual rule registration. Subprocesses use watcher_search
294
- * directly via tools.
307
+ * The service uses this for filesystem enumeration (POST /walk)
308
+ * and virtual rule registration (POST /rules/register).
295
309
  *
296
310
  * @module interfaces/WatcherClient
297
311
  */
298
- /** A file returned from a scan query. */
299
- interface ScanFile {
300
- /** Absolute file path. */
301
- file_path: string;
302
- /** Last modified time as Unix seconds. */
303
- modified_at: number;
304
- /** SHA-256 hash of file content. */
305
- content_hash: string;
306
- /** Additional payload fields requested via `fields`. */
307
- [key: string]: unknown;
308
- }
309
- /** Parameters for a scan request. */
310
- interface ScanParams {
311
- /** File path prefix to match. Required unless filter is provided. */
312
- pathPrefix?: string;
313
- /** Qdrant filter object for structural queries. */
314
- filter?: Record<string, unknown>;
315
- /** Filter files modified after this Unix timestamp (seconds). */
316
- modifiedAfter?: number;
317
- /** Which payload fields to return (default: all). */
318
- fields?: string[];
319
- /** Maximum results per page. */
320
- limit?: number;
321
- /** Pagination cursor from previous response. */
322
- cursor?: string;
323
- }
324
- /** Response from a scan request. */
325
- interface ScanResponse {
326
- /** Deduplicated file results (one per file). */
327
- files: ScanFile[];
328
- /** Pagination cursor. Absent when no more results. */
329
- next?: string;
330
- }
331
312
  /** An inference rule to register with the watcher. */
332
313
  interface InferenceRuleSpec {
333
314
  /** Rule name. */
@@ -351,11 +332,6 @@ interface InferenceRuleSpec {
351
332
  * Implementations handle retry with backoff internally.
352
333
  */
353
334
  interface WatcherClient {
354
- /**
355
- * Query indexed files by path prefix and optional filters.
356
- * Qdrant has no native prefix match; the watcher handles this internally.
357
- */
358
- scan(params: ScanParams): Promise<ScanResponse>;
359
335
  /**
360
336
  * Register virtual inference rules with the watcher.
361
337
  *
@@ -364,72 +340,33 @@ interface WatcherClient {
364
340
  */
365
341
  registerRules(source: string, rules: InferenceRuleSpec[]): Promise<void>;
366
342
  /**
367
- * Unregister virtual inference rules by source.
343
+ * Walk filesystem using glob patterns.
368
344
  *
369
- * @param source - Source identifier to unregister.
345
+ * @param globs - Array of glob patterns to match against.
346
+ * @returns Promise resolving to array of matching file paths.
370
347
  */
371
- unregisterRules(source: string): Promise<void>;
372
- }
373
-
374
- /**
375
- * Pino logger factory.
376
- *
377
- * @module logger
378
- */
379
-
380
- /** Minimal logger interface accepted by library functions. */
381
- interface MinimalLogger {
382
- debug: (obj: Record<string, unknown>, msg: string) => void;
383
- info: (obj: Record<string, unknown>, msg: string) => void;
384
- warn: (obj: Record<string, unknown>, msg: string) => void;
385
- error: (obj: Record<string, unknown>, msg: string) => void;
348
+ walk(globs: string[]): Promise<string[]>;
386
349
  }
387
- /** Logger configuration options. */
388
- interface LoggerConfig {
389
- /** Log level (default: 'info'). */
390
- level?: string;
391
- /** Optional file path to write logs to. */
392
- file?: string;
393
- }
394
- /**
395
- * Create a pino logger instance.
396
- *
397
- * @param config - Optional logger configuration.
398
- * @returns Configured pino logger.
399
- */
400
- declare function createLogger(config?: LoggerConfig): pino.Logger;
401
350
 
402
351
  /**
403
- * Discover .meta/ directories via watcher scan.
352
+ * Discover .meta/ directories via watcher `/walk` endpoint.
404
353
  *
405
- * Replaces filesystem-based globMetas() with a watcher query
406
- * that returns indexed .meta/meta.json points, filtered by domain.
354
+ * Uses filesystem enumeration through the watcher (not Qdrant) to find
355
+ * all `.meta/meta.json` files and returns deduplicated meta directory paths.
407
356
  *
408
357
  * @module discovery/discoverMetas
409
358
  */
410
359
 
411
360
  /**
412
- * Build a Qdrant filter from config metaProperty.
361
+ * Discover all .meta/ directories via watcher walk.
413
362
  *
414
- * Iterates all key-value pairs in `metaProperty` (a generic record)
415
- * to construct `must` clauses. Always appends `file_path: meta.json`
416
- * for deduplication.
363
+ * Uses the watcher's `/walk` endpoint to find all `.meta/meta.json` files
364
+ * and returns deduplicated meta directory paths.
417
365
  *
418
- * @param config - Meta config with metaProperty.
419
- * @returns Qdrant filter object for scanning live metas.
420
- */
421
- declare function buildMetaFilter(config: MetaConfig): Record<string, unknown>;
422
- /**
423
- * Discover all .meta/ directories via watcher scan.
424
- *
425
- * Queries the watcher for indexed .meta/meta.json points using the
426
- * configured domain filter. Returns deduplicated meta directory paths.
427
- *
428
- * @param config - Meta config (for domain filter).
429
- * @param watcher - WatcherClient for scan queries.
366
+ * @param watcher - WatcherClient for walk queries.
430
367
  * @returns Array of normalized .meta/ directory paths.
431
368
  */
432
- declare function discoverMetas(config: MetaConfig, watcher: WatcherClient, logger?: MinimalLogger): Promise<string[]>;
369
+ declare function discoverMetas(watcher: WatcherClient): Promise<string[]>;
433
370
 
434
371
  /**
435
372
  * Types for meta discovery and ownership tree.
@@ -529,7 +466,7 @@ interface MetaListResult {
529
466
  * @param watcher - Watcher HTTP client for discovery.
530
467
  * @returns Enriched meta list with summary statistics and ownership tree.
531
468
  */
532
- declare function listMetas(config: MetaConfig, watcher: WatcherClient, logger?: MinimalLogger): Promise<MetaListResult>;
469
+ declare function listMetas(config: MetaConfig, watcher: WatcherClient): Promise<MetaListResult>;
533
470
 
534
471
  /**
535
472
  * Build the ownership tree from discovered .meta/ paths.
@@ -564,7 +501,7 @@ declare function findNode(tree: OwnershipTree, targetPath: string): MetaNode | u
564
501
  * - Its own .meta/ subtree (outputs, not inputs)
565
502
  * - Child meta ownerPath subtrees (except their .meta/meta.json for rollups)
566
503
  *
567
- * Uses filesystem walks instead of watcher scans for performance.
504
+ * All filesystem enumeration delegated to the watcher's `/walk` endpoint.
568
505
  *
569
506
  * @module discovery/scope
570
507
  */
@@ -580,7 +517,7 @@ declare function getScopePrefix(node: MetaNode): string;
580
517
  * - The node's own .meta/ subtree (synthesis outputs are not scope inputs)
581
518
  * - Child meta ownerPath subtrees (except child .meta/meta.json for rollups)
582
519
  *
583
- * walkFiles already returns normalized forward-slash paths.
520
+ * Watcher walk returns normalized forward-slash paths.
584
521
  */
585
522
  declare function filterInScope(node: MetaNode, files: string[]): string[];
586
523
 
@@ -703,21 +640,6 @@ declare function cleanupStaleLocks(metaPaths: string[], logger?: {
703
640
  */
704
641
  declare function normalizePath(p: string): string;
705
642
 
706
- /**
707
- * Paginated scan helper for exhaustive scope enumeration.
708
- *
709
- * @module paginatedScan
710
- */
711
-
712
- /**
713
- * Perform a paginated scan that follows cursor tokens until exhausted.
714
- *
715
- * @param watcher - WatcherClient instance.
716
- * @param params - Base scan parameters (cursor is managed internally).
717
- * @returns All matching files across all pages.
718
- */
719
- declare function paginatedScan(watcher: WatcherClient, params: Omit<ScanParams, 'cursor'>, logger?: MinimalLogger): Promise<ScanFile[]>;
720
-
721
643
  /**
722
644
  * Compute a structure hash from a sorted file listing.
723
645
  *
@@ -734,32 +656,6 @@ declare function paginatedScan(watcher: WatcherClient, params: Omit<ScanParams,
734
656
  */
735
657
  declare function computeStructureHash(filePaths: string[]): string;
736
658
 
737
- /**
738
- * Recursive filesystem walker for file enumeration.
739
- *
740
- * Replaces paginated watcher scans for scope/delta/staleness checks.
741
- * Returns normalized forward-slash paths.
742
- *
743
- * @module walkFiles
744
- */
745
- /** Options for walkFiles. */
746
- interface WalkFilesOptions {
747
- /** Directory names to exclude (in addition to defaults). */
748
- exclude?: string[];
749
- /** Only include files modified after this Unix timestamp (seconds). */
750
- modifiedAfter?: number;
751
- /** Maximum recursion depth. Default: 50. */
752
- maxDepth?: number;
753
- }
754
- /**
755
- * Recursively walk a directory and return all file paths.
756
- *
757
- * @param root - Root directory to walk.
758
- * @param options - Walk options.
759
- * @returns Array of normalized file paths.
760
- */
761
- declare function walkFiles(root: string, options?: WalkFilesOptions): string[];
762
-
763
659
  /**
764
660
  * MetaExecutor implementation using the OpenClaw gateway HTTP API.
765
661
  *
@@ -778,7 +674,7 @@ interface GatewayExecutorOptions {
778
674
  apiKey?: string;
779
675
  /** Polling interval in ms. Default: 5000. */
780
676
  pollIntervalMs?: number;
781
- /** Workspace directory for output staging. Default: J:\\jeeves\\jeeves-meta */
677
+ /** Workspace directory for output staging. Default: OS temp dir + /jeeves-meta. */
782
678
  workspaceDir?: string;
783
679
  }
784
680
  /**
@@ -802,6 +698,34 @@ declare class GatewayExecutor implements MetaExecutor {
802
698
  spawn(task: string, options?: MetaSpawnOptions): Promise<MetaSpawnResult>;
803
699
  }
804
700
 
701
+ /**
702
+ * Pino logger factory.
703
+ *
704
+ * @module logger
705
+ */
706
+
707
+ /** Minimal logger interface accepted by library functions. */
708
+ interface MinimalLogger {
709
+ debug: (obj: Record<string, unknown>, msg: string) => void;
710
+ info: (obj: Record<string, unknown>, msg: string) => void;
711
+ warn: (obj: Record<string, unknown>, msg: string) => void;
712
+ error: (obj: Record<string, unknown>, msg: string) => void;
713
+ }
714
+ /** Logger configuration options. */
715
+ interface LoggerConfig {
716
+ /** Log level (default: 'info'). */
717
+ level?: string;
718
+ /** Optional file path to write logs to. */
719
+ file?: string;
720
+ }
721
+ /**
722
+ * Create a pino logger instance.
723
+ *
724
+ * @param config - Optional logger configuration.
725
+ * @returns Configured pino logger.
726
+ */
727
+ declare function createLogger(config?: LoggerConfig): pino.Logger;
728
+
805
729
  /**
806
730
  * Build task prompts for each synthesis step.
807
731
  *
@@ -853,7 +777,7 @@ declare function buildCriticTask(ctx: MetaContext, meta: MetaJson, config: MetaC
853
777
  * @param watcher - WatcherClient for scope enumeration.
854
778
  * @returns The computed context package.
855
779
  */
856
- declare function buildContextPackage(node: MetaNode, meta: MetaJson): MetaContext;
780
+ declare function buildContextPackage(node: MetaNode, meta: MetaJson, watcher: WatcherClient): Promise<MetaContext>;
857
781
 
858
782
  /**
859
783
  * Parse subprocess outputs for each synthesis step.
@@ -1064,22 +988,27 @@ declare function computeEffectiveStaleness(candidates: Array<{
1064
988
  declare function selectCandidate(candidates: StalenessCandidate[]): StalenessCandidate | null;
1065
989
 
1066
990
  /**
1067
- * Staleness detection via watcher scan.
991
+ * Staleness detection via watcher walk.
1068
992
  *
1069
- * A meta is stale when any file in its scope was modified after _generatedAt.
993
+ * A meta is stale when any watched file in its scope was modified after
994
+ * `_generatedAt`.
1070
995
  *
1071
996
  * @module scheduling/staleness
1072
997
  */
1073
998
 
1074
999
  /**
1075
- * Check if a meta is stale by querying the watcher for modified files.
1000
+ * Check if a meta is stale.
1001
+ *
1002
+ * Uses watcher `/walk` to enumerate watched files under the scope prefix,
1003
+ * then applies a local mtime check (fast) to detect any modifications since
1004
+ * `_generatedAt`. Short-circuits on first match.
1076
1005
  *
1077
1006
  * @param scopePrefix - Path prefix for this meta's scope.
1078
1007
  * @param meta - Current meta.json content.
1079
1008
  * @param watcher - WatcherClient instance.
1080
- * @returns True if any file in scope was modified after _generatedAt.
1009
+ * @returns True if any file in scope was modified after `_generatedAt`.
1081
1010
  */
1082
- declare function isStale(scopePrefix: string, meta: MetaJson): boolean;
1011
+ declare function isStale(scopePrefix: string, meta: MetaJson, watcher: WatcherClient): Promise<boolean>;
1083
1012
  /**
1084
1013
  * Compute actual staleness in seconds (now minus _generatedAt).
1085
1014
  *
@@ -1258,7 +1187,7 @@ declare class RuleRegistrar {
1258
1187
  /**
1259
1188
  * HTTP implementation of the WatcherClient interface.
1260
1189
  *
1261
- * Talks to jeeves-watcher's POST /scan and POST /rules endpoints
1190
+ * Talks to jeeves-watcher's POST /walk and POST /rules/register endpoints
1262
1191
  * with retry and exponential backoff.
1263
1192
  *
1264
1193
  * @module watcher-client/HttpWatcherClient
@@ -1289,9 +1218,8 @@ declare class HttpWatcherClient implements WatcherClient {
1289
1218
  constructor(options: HttpWatcherClientOptions);
1290
1219
  /** POST JSON with retry. */
1291
1220
  private post;
1292
- scan(params: ScanParams): Promise<ScanResponse>;
1293
1221
  registerRules(source: string, rules: InferenceRuleSpec[]): Promise<void>;
1294
- unregisterRules(source: string): Promise<void>;
1222
+ walk(globs: string[]): Promise<string[]>;
1295
1223
  }
1296
1224
 
1297
1225
  /**
@@ -1367,6 +1295,8 @@ interface RouteDeps {
1367
1295
  watcher: HttpWatcherClient;
1368
1296
  scheduler: Scheduler | null;
1369
1297
  stats: ServiceStats;
1298
+ /** Rule registrar for reporting registration state in /status. */
1299
+ registrar?: RuleRegistrar;
1370
1300
  /** Set to true during graceful shutdown. */
1371
1301
  shuttingDown?: boolean;
1372
1302
  }
@@ -1417,6 +1347,8 @@ interface ShutdownDeps {
1417
1347
  queue: SynthesisQueue;
1418
1348
  logger: Logger;
1419
1349
  routeDeps?: RouteDeps;
1350
+ /** Optional cleanup callback (e.g., stop health check). */
1351
+ onShutdown?: () => void;
1420
1352
  }
1421
1353
  /**
1422
1354
  * Register shutdown handlers for SIGTERM and SIGINT.
@@ -1445,5 +1377,5 @@ declare function registerShutdownHandlers(deps: ShutdownDeps): void;
1445
1377
  */
1446
1378
  declare function startService(config: ServiceConfig, configPath?: string): Promise<void>;
1447
1379
 
1448
- export { GatewayExecutor, HttpWatcherClient, ProgressReporter, RuleRegistrar, Scheduler, SynthesisQueue, acquireLock, actualStaleness, buildArchitectTask, buildBuilderTask, buildContextPackage, buildCriticTask, buildMetaFilter, buildOwnershipTree, cleanupStaleLocks, computeEffectiveStaleness, computeEma, computeStructureHash, createLogger, createServer, createSnapshot, discoverMetas, filterInScope, findNode, formatProgressEvent, getScopePrefix, hasSteerChanged, isArchitectTriggered, isLocked, isStale, listArchiveFiles, listMetas, loadServiceConfig, mergeAndWrite, metaConfigSchema, metaErrorSchema, metaJsonSchema, normalizePath, orchestrate, paginatedScan, parseArchitectOutput, parseBuilderOutput, parseCriticOutput, pruneArchive, readLatestArchive, readLockState, registerRoutes, registerShutdownHandlers, releaseLock, resolveConfigPath, resolveMetaDir, selectCandidate, serviceConfigSchema, sleep, startService, toMetaError, walkFiles };
1449
- export type { BuilderOutput, EnqueueResult, GatewayExecutorOptions, HttpWatcherClientOptions, InferenceRuleSpec, LockState, LoggerConfig, MergeOptions, MetaConfig, MetaContext, MetaEntry, MetaError, MetaExecutor, MetaJson, MetaListResult, MetaListSummary, MetaNode, MetaSpawnOptions, MetaSpawnResult, MinimalLogger, OrchestrateResult, OwnershipTree, ProgressCallback, ProgressEvent, ProgressPhase, ProgressReporterConfig, QueueItem, QueueState, RouteDeps, ScanFile, ScanParams, ScanResponse, ServerOptions, ServiceConfig, ServiceStats, StalenessCandidate, WatcherClient };
1380
+ export { DEFAULT_PORT, DEFAULT_PORT_STR, GatewayExecutor, HttpWatcherClient, ProgressReporter, RuleRegistrar, SERVICE_NAME, SERVICE_VERSION, Scheduler, SynthesisQueue, acquireLock, actualStaleness, buildArchitectTask, buildBuilderTask, buildContextPackage, buildCriticTask, buildOwnershipTree, cleanupStaleLocks, computeEffectiveStaleness, computeEma, computeStructureHash, createLogger, createServer, createSnapshot, discoverMetas, filterInScope, findNode, formatProgressEvent, getScopePrefix, hasSteerChanged, isArchitectTriggered, isLocked, isStale, listArchiveFiles, listMetas, loadServiceConfig, mergeAndWrite, metaConfigSchema, metaErrorSchema, metaJsonSchema, normalizePath, orchestrate, parseArchitectOutput, parseBuilderOutput, parseCriticOutput, pruneArchive, readLatestArchive, readLockState, registerRoutes, registerShutdownHandlers, releaseLock, resolveConfigPath, resolveMetaDir, selectCandidate, serviceConfigSchema, sleep, startService, toMetaError };
1381
+ export type { BuilderOutput, EnqueueResult, GatewayExecutorOptions, HttpWatcherClientOptions, InferenceRuleSpec, LockState, LoggerConfig, MergeOptions, MetaConfig, MetaContext, MetaEntry, MetaError, MetaExecutor, MetaJson, MetaListResult, MetaListSummary, MetaNode, MetaSpawnOptions, MetaSpawnResult, MinimalLogger, OrchestrateResult, OwnershipTree, ProgressCallback, ProgressEvent, ProgressPhase, ProgressReporterConfig, QueueItem, QueueState, RouteDeps, ServerOptions, ServiceConfig, ServiceStats, StalenessCandidate, WatcherClient };