@karmaniverous/jeeves-meta 0.2.2 → 0.3.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 (4) hide show
  1. package/dist/cli.js +373 -333
  2. package/dist/index.d.ts +232 -262
  3. package/dist/index.js +317 -341
  4. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -39,7 +39,6 @@ declare function pruneArchive(metaPath: string, maxArchive: number): number;
39
39
 
40
40
  /** Zod schema for jeeves-meta configuration. */
41
41
  declare const synthConfigSchema: z.ZodObject<{
42
- watchPaths: z.ZodArray<z.ZodString>;
43
42
  watcherUrl: z.ZodURL;
44
43
  gatewayUrl: z.ZodDefault<z.ZodURL>;
45
44
  gatewayApiKey: z.ZodOptional<z.ZodString>;
@@ -54,6 +53,12 @@ declare const synthConfigSchema: z.ZodObject<{
54
53
  defaultCritic: z.ZodString;
55
54
  skipUnchanged: z.ZodDefault<z.ZodBoolean>;
56
55
  batchSize: z.ZodDefault<z.ZodNumber>;
56
+ metaProperty: z.ZodDefault<z.ZodObject<{
57
+ domains: z.ZodArray<z.ZodString>;
58
+ }, z.core.$strip>>;
59
+ metaArchiveProperty: z.ZodDefault<z.ZodObject<{
60
+ domains: z.ZodArray<z.ZodString>;
61
+ }, z.core.$strip>>;
57
62
  }, z.core.$strip>;
58
63
  /** Inferred type for jeeves-meta configuration. */
59
64
  type SynthConfig = z.infer<typeof synthConfigSchema>;
@@ -175,143 +180,6 @@ declare function loadSynthConfig(configPath: string): SynthConfig;
175
180
  */
176
181
  declare function resolveConfigPath(args: string[]): string;
177
182
 
178
- /**
179
- * Ensure meta.json exists in each .meta/ directory.
180
- *
181
- * If meta.json is missing, creates it with a generated UUID.
182
- *
183
- * @module discovery/ensureMetaJson
184
- */
185
-
186
- /**
187
- * Ensure meta.json exists at the given .meta/ path.
188
- *
189
- * @param metaPath - Absolute path to a .meta/ directory.
190
- * @returns The meta.json content (existing or newly created).
191
- */
192
- declare function ensureMetaJson(metaPath: string): MetaJson;
193
-
194
- /**
195
- * Glob watchPaths for .meta/ directories.
196
- *
197
- * Walks each watchPath recursively, collecting directories named '.meta'
198
- * that contain (or will contain) a meta.json file.
199
- *
200
- * @module discovery/globMetas
201
- */
202
- /**
203
- * Recursively find all .meta/ directories under the given paths.
204
- *
205
- * @param watchPaths - Root directories to search.
206
- * @returns Array of absolute paths to .meta/ directories.
207
- */
208
- declare function globMetas(watchPaths: string[]): string[];
209
-
210
- /**
211
- * Types for meta discovery and ownership tree.
212
- *
213
- * @module discovery/types
214
- */
215
- /** A discovered meta node in the ownership tree. */
216
- interface MetaNode {
217
- /** Absolute path to the .meta directory. */
218
- metaPath: string;
219
- /** Absolute path to the parent directory that this meta owns. */
220
- ownerPath: string;
221
- /** Depth in the ownership tree (root = 0). */
222
- treeDepth: number;
223
- /** Child meta nodes (subtrees with their own .meta/). */
224
- children: MetaNode[];
225
- /** Parent meta node, or null for roots. */
226
- parent: MetaNode | null;
227
- }
228
- /** The full ownership tree discovered from watchPaths. */
229
- interface OwnershipTree {
230
- /** All discovered meta nodes, keyed by metaPath. */
231
- nodes: Map<string, MetaNode>;
232
- /** Root nodes (metas with no parent meta). */
233
- roots: MetaNode[];
234
- }
235
-
236
- /**
237
- * Build the ownership tree from discovered .meta/ paths.
238
- *
239
- * Each .meta/ directory owns its parent directory and all descendants,
240
- * except subtrees that contain their own .meta/. For those subtrees,
241
- * the parent meta consumes the child meta's synthesis output.
242
- *
243
- * @module discovery/ownershipTree
244
- */
245
-
246
- /**
247
- * Build an ownership tree from an array of .meta/ directory paths.
248
- *
249
- * @param metaPaths - Absolute paths to .meta/ directories.
250
- * @returns The ownership tree with parent/child relationships.
251
- */
252
- declare function buildOwnershipTree(metaPaths: string[]): OwnershipTree;
253
- /**
254
- * Find a node in the ownership tree by meta path or owner path.
255
- *
256
- * @param tree - The ownership tree to search.
257
- * @param targetPath - Path to search for (meta path or owner path).
258
- * @returns The matching node, or undefined if not found.
259
- */
260
- declare function findNode(tree: OwnershipTree, targetPath: string): MetaNode | undefined;
261
-
262
- /**
263
- * Compute the file scope owned by a meta node.
264
- *
265
- * A meta owns: parent dir + all descendants, minus child .meta/ subtrees.
266
- * For child subtrees, it consumes the child's .meta/meta.json as a rollup input.
267
- *
268
- * @module discovery/scope
269
- */
270
-
271
- /**
272
- * Get the scope path prefix for a meta node.
273
- *
274
- * This is the ownerPath — all files under this path are in scope,
275
- * except subtrees owned by child metas.
276
- *
277
- * @param node - The meta node to compute scope for.
278
- * @returns The scope path prefix.
279
- */
280
- declare function getScopePrefix(node: MetaNode): string;
281
- /**
282
- * Get paths that should be excluded from the scope (child meta subtrees).
283
- *
284
- * @param node - The meta node to compute exclusions for.
285
- * @returns Array of path prefixes to exclude from scope queries.
286
- */
287
- declare function getScopeExclusions(node: MetaNode): string[];
288
- /**
289
- * Filter a list of file paths to only those in scope for a meta node.
290
- *
291
- * Includes files under ownerPath, excludes files under child meta ownerPaths,
292
- * but includes child .meta/meta.json files as rollup inputs.
293
- *
294
- * @param node - The meta node.
295
- * @param files - Array of file paths to filter.
296
- * @returns Filtered array of in-scope file paths.
297
- */
298
- declare function filterInScope(node: MetaNode, files: string[]): string[];
299
-
300
- /**
301
- * Exponential moving average helper for token tracking.
302
- *
303
- * @module ema
304
- */
305
- /**
306
- * Compute exponential moving average.
307
- *
308
- * @param current - New observation.
309
- * @param previous - Previous EMA value, or undefined for first observation.
310
- * @param decay - Decay factor (0-1). Higher = more weight on new value. Default 0.3.
311
- * @returns Updated EMA.
312
- */
313
- declare function computeEma(current: number, previous: number | undefined, decay?: number): number;
314
-
315
183
  /**
316
184
  * Per-cycle context package computed by the orchestrator.
317
185
  *
@@ -467,6 +335,228 @@ interface WatcherClient {
467
335
  unregisterRules(source: string): Promise<void>;
468
336
  }
469
337
 
338
+ /**
339
+ * Discover .meta/ directories via watcher scan.
340
+ *
341
+ * Replaces filesystem-based globMetas() with a watcher query
342
+ * that returns indexed .meta/meta.json points, filtered by domain.
343
+ *
344
+ * @module discovery/discoverMetas
345
+ */
346
+
347
+ /**
348
+ * Build a Qdrant filter from config metaProperty.
349
+ *
350
+ * @param config - Synth config with metaProperty.
351
+ * @returns Qdrant filter object for scanning live metas.
352
+ */
353
+ declare function buildMetaFilter(config: SynthConfig): Record<string, unknown>;
354
+ /**
355
+ * Discover all .meta/ directories via watcher scan.
356
+ *
357
+ * Queries the watcher for indexed .meta/meta.json points using the
358
+ * configured domain filter. Returns deduplicated meta directory paths.
359
+ *
360
+ * @param config - Synth config (for domain filter).
361
+ * @param watcher - WatcherClient for scan queries.
362
+ * @returns Array of normalized .meta/ directory paths.
363
+ */
364
+ declare function discoverMetas(config: SynthConfig, watcher: WatcherClient): Promise<string[]>;
365
+
366
+ /**
367
+ * Types for meta discovery and ownership tree.
368
+ *
369
+ * @module discovery/types
370
+ */
371
+ /** A discovered meta node in the ownership tree. */
372
+ interface MetaNode {
373
+ /** Absolute path to the .meta directory. */
374
+ metaPath: string;
375
+ /** Absolute path to the parent directory that this meta owns. */
376
+ ownerPath: string;
377
+ /** Depth in the ownership tree (root = 0). */
378
+ treeDepth: number;
379
+ /** Child meta nodes (subtrees with their own .meta/). */
380
+ children: MetaNode[];
381
+ /** Parent meta node, or null for roots. */
382
+ parent: MetaNode | null;
383
+ }
384
+ /** The full ownership tree discovered from watchPaths. */
385
+ interface OwnershipTree {
386
+ /** All discovered meta nodes, keyed by metaPath. */
387
+ nodes: Map<string, MetaNode>;
388
+ /** Root nodes (metas with no parent meta). */
389
+ roots: MetaNode[];
390
+ }
391
+
392
+ /**
393
+ * Build the ownership tree from discovered .meta/ paths.
394
+ *
395
+ * Each .meta/ directory owns its parent directory and all descendants,
396
+ * except subtrees that contain their own .meta/. For those subtrees,
397
+ * the parent meta consumes the child meta's synthesis output.
398
+ *
399
+ * @module discovery/ownershipTree
400
+ */
401
+
402
+ /**
403
+ * Build an ownership tree from an array of .meta/ directory paths.
404
+ *
405
+ * @param metaPaths - Absolute paths to .meta/ directories.
406
+ * @returns The ownership tree with parent/child relationships.
407
+ */
408
+ declare function buildOwnershipTree(metaPaths: string[]): OwnershipTree;
409
+ /**
410
+ * Find a node in the ownership tree by meta path or owner path.
411
+ *
412
+ * @param tree - The ownership tree to search.
413
+ * @param targetPath - Path to search for (meta path or owner path).
414
+ * @returns The matching node, or undefined if not found.
415
+ */
416
+ declare function findNode(tree: OwnershipTree, targetPath: string): MetaNode | undefined;
417
+
418
+ /**
419
+ * Compute the file scope owned by a meta node.
420
+ *
421
+ * A meta owns: parent dir + all descendants, minus child .meta/ subtrees.
422
+ * For child subtrees, it consumes the child's .meta/meta.json as a rollup input.
423
+ *
424
+ * @module discovery/scope
425
+ */
426
+
427
+ /**
428
+ * Get the scope path prefix for a meta node.
429
+ *
430
+ * This is the ownerPath — all files under this path are in scope,
431
+ * except subtrees owned by child metas.
432
+ *
433
+ * @param node - The meta node to compute scope for.
434
+ * @returns The scope path prefix.
435
+ */
436
+ declare function getScopePrefix(node: MetaNode): string;
437
+ /**
438
+ * Filter a list of file paths to only those in scope for a meta node.
439
+ *
440
+ * Includes files under ownerPath, excludes files under child meta ownerPaths,
441
+ * but includes child .meta/meta.json files as rollup inputs.
442
+ *
443
+ * @param node - The meta node.
444
+ * @param files - Array of file paths to filter.
445
+ * @returns Filtered array of in-scope file paths.
446
+ */
447
+ declare function filterInScope(node: MetaNode, files: string[]): string[];
448
+
449
+ /**
450
+ * Exponential moving average helper for token tracking.
451
+ *
452
+ * @module ema
453
+ */
454
+ /**
455
+ * Compute exponential moving average.
456
+ *
457
+ * @param current - New observation.
458
+ * @param previous - Previous EMA value, or undefined for first observation.
459
+ * @param decay - Decay factor (0-1). Higher = more weight on new value. Default 0.3.
460
+ * @returns Updated EMA.
461
+ */
462
+ declare function computeEma(current: number, previous: number | undefined, decay?: number): number;
463
+
464
+ /**
465
+ * Shared error utilities.
466
+ *
467
+ * @module errors
468
+ */
469
+
470
+ /**
471
+ * Wrap an unknown caught value into a SynthError.
472
+ *
473
+ * @param step - Which synthesis step failed.
474
+ * @param err - The caught error value.
475
+ * @param code - Error classification code.
476
+ * @returns A structured SynthError.
477
+ */
478
+ declare function toSynthError(step: SynthError['step'], err: unknown, code?: string): SynthError;
479
+
480
+ /**
481
+ * SynthExecutor implementation using the OpenClaw gateway HTTP API.
482
+ *
483
+ * Lives in the library package so both plugin and runner can import it.
484
+ * Spawns sub-agent sessions via the gateway, polls for completion,
485
+ * and extracts output text.
486
+ *
487
+ * @module executor/GatewayExecutor
488
+ */
489
+
490
+ /** Options for the GatewayExecutor. */
491
+ interface GatewayExecutorOptions {
492
+ /** OpenClaw gateway base URL. Default: http://127.0.0.1:3000 */
493
+ gatewayUrl?: string;
494
+ /** API key for gateway authentication. */
495
+ apiKey?: string;
496
+ /** Polling interval in ms. Default: 5000. */
497
+ pollIntervalMs?: number;
498
+ }
499
+ /**
500
+ * SynthExecutor that spawns OpenClaw sessions via the gateway HTTP API.
501
+ *
502
+ * Used by both the OpenClaw plugin (in-process tool calls) and the
503
+ * runner/CLI (external invocation). Constructs from `gatewayUrl` and
504
+ * optional `apiKey` — typically sourced from `SynthConfig`.
505
+ */
506
+ declare class GatewayExecutor implements SynthExecutor {
507
+ private readonly gatewayUrl;
508
+ private readonly apiKey;
509
+ private readonly pollIntervalMs;
510
+ constructor(options?: GatewayExecutorOptions);
511
+ spawn(task: string, options?: SynthSpawnOptions): Promise<SynthSpawnResult>;
512
+ }
513
+
514
+ /**
515
+ * File-system lock for preventing concurrent synthesis on the same meta.
516
+ *
517
+ * Lock file: .meta/.lock containing PID + timestamp.
518
+ * Stale timeout: 30 minutes.
519
+ *
520
+ * @module lock
521
+ */
522
+ /**
523
+ * Attempt to acquire a lock on a .meta directory.
524
+ *
525
+ * @param metaPath - Absolute path to the .meta directory.
526
+ * @returns True if lock was acquired, false if already locked (non-stale).
527
+ */
528
+ declare function acquireLock(metaPath: string): boolean;
529
+ /**
530
+ * Release a lock on a .meta directory.
531
+ *
532
+ * @param metaPath - Absolute path to the .meta directory.
533
+ */
534
+ declare function releaseLock(metaPath: string): void;
535
+ /**
536
+ * Check if a .meta directory is currently locked (non-stale).
537
+ *
538
+ * @param metaPath - Absolute path to the .meta directory.
539
+ * @returns True if locked and not stale.
540
+ */
541
+ declare function isLocked(metaPath: string): boolean;
542
+
543
+ /**
544
+ * Normalize file paths to forward slashes for consistency with watcher-indexed paths.
545
+ *
546
+ * Watcher indexes paths with forward slashes (`j:/domains/...`). This utility
547
+ * ensures all paths in the library use the same convention, regardless of
548
+ * the platform's native separator.
549
+ *
550
+ * @module normalizePath
551
+ */
552
+ /**
553
+ * Normalize a file path to forward slashes.
554
+ *
555
+ * @param p - File path (may contain backslashes).
556
+ * @returns Path with all backslashes replaced by forward slashes.
557
+ */
558
+ declare function normalizePath(p: string): string;
559
+
470
560
  /**
471
561
  * Build task prompts for each synthesis step.
472
562
  *
@@ -635,130 +725,10 @@ interface OrchestrateResult {
635
725
  * @param config - Validated synthesis config.
636
726
  * @param executor - Pluggable LLM executor.
637
727
  * @param watcher - Watcher HTTP client.
728
+ * @param targetPath - Optional: specific meta/owner path to synthesize instead of stalest candidate.
638
729
  * @returns Array of results, one per cycle attempted.
639
730
  */
640
- declare function orchestrate(config: SynthConfig, executor: SynthExecutor, watcher: WatcherClient): Promise<OrchestrateResult[]>;
641
-
642
- /**
643
- * Factory for creating a bound synthesis engine.
644
- *
645
- * @module engine
646
- */
647
-
648
- /** A bound synthesis engine instance. */
649
- interface SynthEngine {
650
- /** Run synthesis cycles up to batchSize. */
651
- synthesize(): Promise<OrchestrateResult[]>;
652
- /** Run synthesis targeting a specific path. */
653
- synthesizePath(ownerPath: string): Promise<OrchestrateResult[]>;
654
- /** The bound config. */
655
- readonly config: SynthConfig;
656
- }
657
- /**
658
- * Create a synthesis engine with bound config, executor, and watcher client.
659
- *
660
- * @param config - Validated synthesis config.
661
- * @param executor - Pluggable LLM executor.
662
- * @param watcher - Watcher HTTP client.
663
- * @returns A bound engine instance.
664
- */
665
- declare function createSynthEngine(config: SynthConfig, executor: SynthExecutor, watcher: WatcherClient): SynthEngine;
666
-
667
- /**
668
- * Shared error utilities.
669
- *
670
- * @module errors
671
- */
672
-
673
- /**
674
- * Wrap an unknown caught value into a SynthError.
675
- *
676
- * @param step - Which synthesis step failed.
677
- * @param err - The caught error value.
678
- * @param code - Error classification code.
679
- * @returns A structured SynthError.
680
- */
681
- declare function toSynthError(step: SynthError['step'], err: unknown, code?: string): SynthError;
682
-
683
- /**
684
- * SynthExecutor implementation using the OpenClaw gateway HTTP API.
685
- *
686
- * Lives in the library package so both plugin and runner can import it.
687
- * Spawns sub-agent sessions via the gateway, polls for completion,
688
- * and extracts output text.
689
- *
690
- * @module executor/GatewayExecutor
691
- */
692
-
693
- /** Options for the GatewayExecutor. */
694
- interface GatewayExecutorOptions {
695
- /** OpenClaw gateway base URL. Default: http://127.0.0.1:3000 */
696
- gatewayUrl?: string;
697
- /** API key for gateway authentication. */
698
- apiKey?: string;
699
- /** Polling interval in ms. Default: 5000. */
700
- pollIntervalMs?: number;
701
- }
702
- /**
703
- * SynthExecutor that spawns OpenClaw sessions via the gateway HTTP API.
704
- *
705
- * Used by both the OpenClaw plugin (in-process tool calls) and the
706
- * runner/CLI (external invocation). Constructs from `gatewayUrl` and
707
- * optional `apiKey` — typically sourced from `SynthConfig`.
708
- */
709
- declare class GatewayExecutor implements SynthExecutor {
710
- private readonly gatewayUrl;
711
- private readonly apiKey;
712
- private readonly pollIntervalMs;
713
- constructor(options?: GatewayExecutorOptions);
714
- spawn(task: string, options?: SynthSpawnOptions): Promise<SynthSpawnResult>;
715
- }
716
-
717
- /**
718
- * File-system lock for preventing concurrent synthesis on the same meta.
719
- *
720
- * Lock file: .meta/.lock containing PID + timestamp.
721
- * Stale timeout: 30 minutes.
722
- *
723
- * @module lock
724
- */
725
- /**
726
- * Attempt to acquire a lock on a .meta directory.
727
- *
728
- * @param metaPath - Absolute path to the .meta directory.
729
- * @returns True if lock was acquired, false if already locked (non-stale).
730
- */
731
- declare function acquireLock(metaPath: string): boolean;
732
- /**
733
- * Release a lock on a .meta directory.
734
- *
735
- * @param metaPath - Absolute path to the .meta directory.
736
- */
737
- declare function releaseLock(metaPath: string): void;
738
- /**
739
- * Check if a .meta directory is currently locked (non-stale).
740
- *
741
- * @param metaPath - Absolute path to the .meta directory.
742
- * @returns True if locked and not stale.
743
- */
744
- declare function isLocked(metaPath: string): boolean;
745
-
746
- /**
747
- * Normalize file paths to forward slashes for consistency with watcher-indexed paths.
748
- *
749
- * Watcher indexes paths with forward slashes (`j:/domains/...`). This utility
750
- * ensures all paths in the library use the same convention, regardless of
751
- * the platform's native separator.
752
- *
753
- * @module normalizePath
754
- */
755
- /**
756
- * Normalize a file path to forward slashes.
757
- *
758
- * @param p - File path (may contain backslashes).
759
- * @returns Path with all backslashes replaced by forward slashes.
760
- */
761
- declare function normalizePath(p: string): string;
731
+ declare function orchestrate(config: SynthConfig, executor: SynthExecutor, watcher: WatcherClient, targetPath?: string): Promise<OrchestrateResult[]>;
762
732
 
763
733
  /**
764
734
  * Paginated scan helper for exhaustive scope enumeration.
@@ -925,5 +895,5 @@ declare class HttpWatcherClient implements WatcherClient {
925
895
  unregisterRules(source: string): Promise<void>;
926
896
  }
927
897
 
928
- export { GatewayExecutor, HttpWatcherClient, acquireLock, actualStaleness, buildArchitectTask, buildBuilderTask, buildContextPackage, buildCriticTask, buildOwnershipTree, computeEffectiveStaleness, computeEma, computeStructureHash, createSnapshot, createSynthEngine, ensureMetaJson, filterInScope, findNode, getScopeExclusions, getScopePrefix, globMetas, hasSteerChanged, isArchitectTriggered, isLocked, isStale, listArchiveFiles, loadSynthConfig, mergeAndWrite, metaJsonSchema, normalizePath, orchestrate, paginatedScan, parseArchitectOutput, parseBuilderOutput, parseCriticOutput, pruneArchive, readLatestArchive, releaseLock, resolveConfigPath, selectCandidate, synthConfigSchema, synthErrorSchema, toSynthError };
929
- export type { BuilderOutput, GatewayExecutorOptions, HttpWatcherClientOptions, InferenceRuleSpec, MergeOptions, MetaJson, MetaNode, OrchestrateResult, OwnershipTree, ScanFile, ScanParams, ScanResponse, StalenessCandidate, SynthConfig, SynthContext, SynthEngine, SynthError, SynthExecutor, SynthSpawnOptions, SynthSpawnResult, WatcherClient };
898
+ export { GatewayExecutor, HttpWatcherClient, acquireLock, actualStaleness, buildArchitectTask, buildBuilderTask, buildContextPackage, buildCriticTask, buildMetaFilter, buildOwnershipTree, computeEffectiveStaleness, computeEma, computeStructureHash, createSnapshot, discoverMetas, filterInScope, findNode, getScopePrefix, hasSteerChanged, isArchitectTriggered, isLocked, isStale, listArchiveFiles, loadSynthConfig, mergeAndWrite, metaJsonSchema, normalizePath, orchestrate, paginatedScan, parseArchitectOutput, parseBuilderOutput, parseCriticOutput, pruneArchive, readLatestArchive, releaseLock, resolveConfigPath, selectCandidate, synthConfigSchema, synthErrorSchema, toSynthError };
899
+ export type { BuilderOutput, GatewayExecutorOptions, HttpWatcherClientOptions, InferenceRuleSpec, MergeOptions, MetaJson, MetaNode, OrchestrateResult, OwnershipTree, ScanFile, ScanParams, ScanResponse, StalenessCandidate, SynthConfig, SynthContext, SynthError, SynthExecutor, SynthSpawnOptions, SynthSpawnResult, WatcherClient };