@karmaniverous/jeeves 0.5.0 → 0.5.3

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.
@@ -696,6 +696,21 @@ function createServiceManager(descriptor) {
696
696
  }
697
697
  }
698
698
 
699
+ /**
700
+ * Shared internal utility functions.
701
+ *
702
+ * @packageDocumentation
703
+ */
704
+ /**
705
+ * Extract a human-readable message from an unknown caught value.
706
+ *
707
+ * @param err - The caught value (typically `unknown`).
708
+ * @returns The error message string.
709
+ */
710
+ function getErrorMessage(err) {
711
+ return err instanceof Error ? err.message : String(err);
712
+ }
713
+
699
714
  /**
700
715
  * Workspace-level shared configuration: `jeeves.config.json`.
701
716
  *
@@ -747,7 +762,13 @@ z.object({
747
762
  /** Memory hygiene shared defaults. */
748
763
  memory: workspaceMemoryConfigSchema.optional(),
749
764
  });
750
- /** Built-in workspace config defaults. */
765
+ /**
766
+ * Built-in workspace config defaults.
767
+ *
768
+ * @remarks
769
+ * These defaults are used as the lowest-priority tier in config resolution
770
+ * (below CLI flags, env vars, and `jeeves.config.json` values).
771
+ */
751
772
  const WORKSPACE_CONFIG_DEFAULTS = {
752
773
  core: {
753
774
  workspace: '.',
@@ -773,6 +794,10 @@ const DEFAULT_CONFIG_ROOT = WORKSPACE_CONFIG_DEFAULTS.core.configRoot;
773
794
  * a component descriptor. Components add domain-specific commands
774
795
  * via `descriptor.customCliCommands`.
775
796
  */
797
+ function handleCommandError(action, err) {
798
+ console.error(`${action} failed: ${getErrorMessage(err)}`);
799
+ process.exitCode = 1;
800
+ }
776
801
  /**
777
802
  * Create a standard service CLI program from a component descriptor.
778
803
  *
@@ -825,8 +850,7 @@ function createServiceCli(descriptor) {
825
850
  console.log(JSON.stringify(result, null, 2));
826
851
  }
827
852
  catch (err) {
828
- const msg = err instanceof Error ? err.message : String(err);
829
- console.error(`Service unreachable: ${msg}`);
853
+ console.error(`Service unreachable: ${getErrorMessage(err)}`);
830
854
  process.exitCode = 1;
831
855
  }
832
856
  });
@@ -844,8 +868,7 @@ function createServiceCli(descriptor) {
844
868
  console.log(JSON.stringify(result, null, 2));
845
869
  }
846
870
  catch (err) {
847
- const msg = err instanceof Error ? err.message : String(err);
848
- console.error(`Config query failed: ${msg}`);
871
+ console.error(`Config query failed: ${getErrorMessage(err)}`);
849
872
  process.exitCode = 1;
850
873
  }
851
874
  });
@@ -861,8 +884,7 @@ function createServiceCli(descriptor) {
861
884
  console.log('Config is valid.');
862
885
  }
863
886
  catch (err) {
864
- const msg = err instanceof Error ? err.message : String(err);
865
- console.error(`Validation failed: ${msg}`);
887
+ console.error(`Validation failed: ${getErrorMessage(err)}`);
866
888
  process.exitCode = 1;
867
889
  }
868
890
  });
@@ -899,8 +921,7 @@ function createServiceCli(descriptor) {
899
921
  console.log(JSON.stringify(result, null, 2));
900
922
  }
901
923
  catch (err) {
902
- const msg = err instanceof Error ? err.message : String(err);
903
- console.error(`Config apply failed: ${msg}`);
924
+ console.error(`Config apply failed: ${getErrorMessage(err)}`);
904
925
  process.exitCode = 1;
905
926
  }
906
927
  });
@@ -937,9 +958,7 @@ function createServiceCli(descriptor) {
937
958
  console.log(`Service "${opts.name}" installed.`);
938
959
  }
939
960
  catch (err) {
940
- const msg = err instanceof Error ? err.message : String(err);
941
- console.error(`Install failed: ${msg}`);
942
- process.exitCode = 1;
961
+ handleCommandError('Install', err);
943
962
  }
944
963
  });
945
964
  serviceCmd
@@ -952,9 +971,7 @@ function createServiceCli(descriptor) {
952
971
  console.log(`Service "${opts.name}" uninstalled.`);
953
972
  }
954
973
  catch (err) {
955
- const msg = err instanceof Error ? err.message : String(err);
956
- console.error(`Uninstall failed: ${msg}`);
957
- process.exitCode = 1;
974
+ handleCommandError('Uninstall', err);
958
975
  }
959
976
  });
960
977
  serviceCmd
@@ -967,9 +984,7 @@ function createServiceCli(descriptor) {
967
984
  console.log(`Service "${opts.name}" started.`);
968
985
  }
969
986
  catch (err) {
970
- const msg = err instanceof Error ? err.message : String(err);
971
- console.error(`Start failed: ${msg}`);
972
- process.exitCode = 1;
987
+ handleCommandError('Start', err);
973
988
  }
974
989
  });
975
990
  serviceCmd
@@ -982,9 +997,7 @@ function createServiceCli(descriptor) {
982
997
  console.log(`Service "${opts.name}" stopped.`);
983
998
  }
984
999
  catch (err) {
985
- const msg = err instanceof Error ? err.message : String(err);
986
- console.error(`Stop failed: ${msg}`);
987
- process.exitCode = 1;
1000
+ handleCommandError('Stop', err);
988
1001
  }
989
1002
  });
990
1003
  serviceCmd
@@ -997,9 +1010,7 @@ function createServiceCli(descriptor) {
997
1010
  console.log(`Service "${opts.name}" restarted.`);
998
1011
  }
999
1012
  catch (err) {
1000
- const msg = err instanceof Error ? err.message : String(err);
1001
- console.error(`Restart failed: ${msg}`);
1002
- process.exitCode = 1;
1013
+ handleCommandError('Restart', err);
1003
1014
  }
1004
1015
  });
1005
1016
  serviceCmd
@@ -1012,9 +1023,7 @@ function createServiceCli(descriptor) {
1012
1023
  console.log(`Service "${opts.name}": ${state}`);
1013
1024
  }
1014
1025
  catch (err) {
1015
- const msg = err instanceof Error ? err.message : String(err);
1016
- console.error(`Status failed: ${msg}`);
1017
- process.exitCode = 1;
1026
+ handleCommandError('Status', err);
1018
1027
  }
1019
1028
  });
1020
1029
  // Apply custom CLI commands if provided
package/dist/index.d.ts CHANGED
@@ -304,16 +304,30 @@ declare const workspaceConfigSchema: z.ZodObject<{
304
304
  }, z.core.$strip>;
305
305
  /** Workspace config type. */
306
306
  type WorkspaceConfig = z.infer<typeof workspaceConfigSchema>;
307
- /** Built-in workspace config defaults. */
307
+ /**
308
+ * Built-in workspace config defaults.
309
+ *
310
+ * @remarks
311
+ * These defaults are used as the lowest-priority tier in config resolution
312
+ * (below CLI flags, env vars, and `jeeves.config.json` values).
313
+ */
308
314
  declare const WORKSPACE_CONFIG_DEFAULTS: {
315
+ /** Core shared defaults. */
309
316
  readonly core: {
310
- readonly workspace: ".";
311
- readonly configRoot: "./config";
312
- readonly gatewayUrl: "http://127.0.0.1:3000";
317
+ /** Default workspace root path. */
318
+ readonly workspace: '.';
319
+ /** Default platform config root path. */
320
+ readonly configRoot: './config';
321
+ /** Default OpenClaw gateway URL. */
322
+ readonly gatewayUrl: 'http://127.0.0.1:3000';
313
323
  };
324
+ /** Memory hygiene shared defaults. */
314
325
  readonly memory: {
315
- readonly budget: 20000;
326
+ /** Default MEMORY.md character budget. */
327
+ readonly budget: 20_000;
328
+ /** Default warning threshold as a fraction of budget (80%). */
316
329
  readonly warningThreshold: 0.8;
330
+ /** Default staleness threshold in days. */
317
331
  readonly staleDays: 30;
318
332
  };
319
333
  };
@@ -369,14 +383,20 @@ interface WorkspaceOptions {
369
383
  interface ResolvedCliConfig {
370
384
  /** Core shared config. */
371
385
  core: {
386
+ /** Resolved workspace root path. */
372
387
  workspace: ResolvedValue<string>;
388
+ /** Resolved platform config root path. */
373
389
  configRoot: ResolvedValue<string>;
390
+ /** Resolved OpenClaw gateway URL. */
374
391
  gatewayUrl: ResolvedValue<string>;
375
392
  };
376
393
  /** Memory shared config. */
377
394
  memory: {
395
+ /** Resolved MEMORY.md character budget. */
378
396
  budget: ResolvedValue<number>;
397
+ /** Resolved warning threshold as a fraction of budget. */
379
398
  warningThreshold: ResolvedValue<number>;
399
+ /** Resolved staleness threshold in days. */
380
400
  staleDays: ResolvedValue<number>;
381
401
  };
382
402
  }
@@ -530,14 +550,6 @@ declare function removeComponentVersion(coreConfigDir: string, componentName: st
530
550
  * on a configurable prime-interval timer cycle.
531
551
  */
532
552
 
533
- /**
534
- * Orchestrates managed content writing for a single Jeeves component.
535
- *
536
- * @remarks
537
- * Created via `createComponentWriter()`. Manages a timer that fires
538
- * at the component's prime-interval, calling `generateToolsContent()`
539
- * and `refreshPlatformContent()` on each cycle.
540
- */
541
553
  /** Options for ComponentWriter construction. */
542
554
  interface ComponentWriterOptions {
543
555
  /**
@@ -548,8 +560,17 @@ interface ComponentWriterOptions {
548
560
  */
549
561
  gatewayUrl?: string;
550
562
  }
563
+ /**
564
+ * Orchestrates managed content writing for a single Jeeves component.
565
+ *
566
+ * @remarks
567
+ * Created via {@link createComponentWriter}. Manages a timer that fires
568
+ * at the component's prime-interval, calling `generateToolsContent()`
569
+ * and `refreshPlatformContent()` on each cycle.
570
+ */
551
571
  declare class ComponentWriter {
552
572
  private timer;
573
+ private jitterTimeout;
553
574
  private readonly component;
554
575
  private readonly configDir;
555
576
  private readonly gatewayUrl;
@@ -558,13 +579,15 @@ declare class ComponentWriter {
558
579
  constructor(component: JeevesComponentDescriptor, options?: ComponentWriterOptions);
559
580
  /** The component's config directory path. */
560
581
  get componentConfigDir(): string;
561
- /** Whether the writer timer is currently running. */
582
+ /** Whether the writer timer is currently running or pending its first cycle. */
562
583
  get isRunning(): boolean;
563
584
  /**
564
585
  * Start the writer timer.
565
586
  *
566
587
  * @remarks
567
- * Performs an immediate first write, then sets up the interval.
588
+ * Delays the first cycle by a random jitter (0 to one full interval) to
589
+ * spread initial writes across all component plugins and reduce EPERM
590
+ * contention on startup.
568
591
  */
569
592
  start(): void;
570
593
  /** Stop the writer timer. */
@@ -1138,6 +1161,10 @@ declare const DEFAULT_CORE_VERSION: string;
1138
1161
  /**
1139
1162
  * Write content to a file atomically via a temp file + rename.
1140
1163
  *
1164
+ * @remarks
1165
+ * Retries the rename up to three times on EPERM (Windows file-handle
1166
+ * contention) with a 100 ms synchronous delay between attempts.
1167
+ *
1141
1168
  * @param filePath - Absolute path to the target file.
1142
1169
  * @param content - Content to write.
1143
1170
  */
@@ -1355,6 +1382,28 @@ declare function extractMostRecentDate(text: string): Date | undefined;
1355
1382
  */
1356
1383
  declare function analyzeMemory(options: MemoryHygieneOptions): MemoryHygieneResult;
1357
1384
 
1385
+ /**
1386
+ * HEARTBEAT integration for memory hygiene.
1387
+ *
1388
+ * @remarks
1389
+ * Calls `analyzeMemory()` and converts the result into a `HeartbeatEntry`
1390
+ * suitable for inclusion in the HEARTBEAT.md platform status section.
1391
+ * Returns `undefined` when MEMORY.md is healthy (no alert needed).
1392
+ *
1393
+ * Uses the `## MEMORY.md` heading (Decision 50) to distinguish memory
1394
+ * alerts from component alerts (`## jeeves-{name}`).
1395
+ */
1396
+
1397
+ /** The HEARTBEAT heading name for memory alerts. */
1398
+ declare const MEMORY_HEARTBEAT_NAME = "MEMORY.md";
1399
+ /**
1400
+ * Check memory health and return a HEARTBEAT entry if unhealthy.
1401
+ *
1402
+ * @param options - Memory hygiene options (workspacePath, budget, etc.).
1403
+ * @returns A `HeartbeatEntry` when memory needs attention, `undefined` when healthy.
1404
+ */
1405
+ declare function checkMemoryHealth(options: MemoryHygieneOptions): HeartbeatEntry | undefined;
1406
+
1358
1407
  /**
1359
1408
  * Internal function to maintain SOUL.md, AGENTS.md, and TOOLS.md Platform section.
1360
1409
  *
@@ -1526,20 +1575,34 @@ declare function resolveOpenClawHome(): string;
1526
1575
  * @returns Absolute path to the config file.
1527
1576
  */
1528
1577
  declare function resolveConfigPath(home: string): string;
1578
+ /** Options for writing a plugin install provenance record. */
1579
+ interface PluginInstallRecord {
1580
+ /** Absolute path to the extensions directory where the plugin was installed. */
1581
+ installPath: string;
1582
+ /** Plugin version string from package.json, if known. */
1583
+ version?: string;
1584
+ /** ISO timestamp of installation. Defaults to `new Date().toISOString()`. */
1585
+ installedAt?: string;
1586
+ }
1529
1587
  /**
1530
- * Patch an OpenClaw config for plugin install or uninstall.
1588
+ * Patch an OpenClaw config for plugin install.
1531
1589
  *
1532
- * @remarks
1533
- * Manages `plugins.entries.{pluginId}` and `tools.alsoAllow`.
1534
- * Idempotent: adding twice produces no duplicates; removing when absent
1535
- * produces no errors.
1590
+ * @param config - The parsed OpenClaw config object (mutated in place).
1591
+ * @param pluginId - The plugin identifier.
1592
+ * @param mode - Install mode.
1593
+ * @param installRecord - Install provenance record.
1594
+ * @returns Array of log messages describing changes made.
1595
+ */
1596
+ declare function patchConfig(config: Record<string, unknown>, pluginId: string, mode: 'add', installRecord: PluginInstallRecord): string[];
1597
+ /**
1598
+ * Patch an OpenClaw config for plugin uninstall.
1536
1599
  *
1537
1600
  * @param config - The parsed OpenClaw config object (mutated in place).
1538
1601
  * @param pluginId - The plugin identifier.
1539
- * @param mode - Whether to add or remove the plugin.
1602
+ * @param mode - Uninstall mode.
1540
1603
  * @returns Array of log messages describing changes made.
1541
1604
  */
1542
- declare function patchConfig(config: Record<string, unknown>, pluginId: string, mode: 'add' | 'remove'): string[];
1605
+ declare function patchConfig(config: Record<string, unknown>, pluginId: string, mode: 'remove'): string[];
1543
1606
 
1544
1607
  /**
1545
1608
  * Plugin resolution helpers for the OpenClaw plugin SDK.
@@ -1816,5 +1879,5 @@ interface ServiceManager {
1816
1879
  */
1817
1880
  declare function createServiceManager(descriptor: JeevesComponentDescriptor): ServiceManager;
1818
1881
 
1819
- export { AGENTS_MARKERS, CLEANUP_FLAG, COMPONENT_CONFIG_PREFIX, COMPONENT_VERSIONS_FILE, CONFIG_FILE, CORE_CONFIG_DIR, CORE_VERSION, ComponentWriter, DEFAULT_BIND_ADDRESS, DEFAULT_CORE_VERSION, DEFAULT_PORTS, HEARTBEAT_HEADING, JEEVES_SKILL_DIR, META_PORT, PLATFORM_COMPONENTS, REGISTRY_CACHE_FILE, RUNNER_PORT, SECTION_IDS, SECTION_ORDER, SERVER_PORT, SKILLS_DIR, SOUL_MARKERS, STALENESS_THRESHOLD_MS, STALE_LOCK_MS, TEMPLATES_DIR, TOOLS_MARKERS, VERSION_STAMP_PATTERN, WATCHER_PORT, WORKSPACE_CONFIG_DEFAULTS, WORKSPACE_CONFIG_FILE, WORKSPACE_FILES, analyzeMemory, appendJsonl, atomicWrite, buildEffectiveConfig, buildHeartbeatSection, checkNodeVersion, checkRegistryVersion, connectionFail, coreConfigSchema, createAsyncContentCache, createComponentWriter, createConfigApplyHandler, createConfigQueryHandler, createGoogleAuth, createPluginCli, createPluginToolset, createServiceCli, createServiceManager, createStatusHandler, ensureDir, extractMostRecentDate, fail, fetchJson, fetchWithTimeout, formatBeginMarker, formatEndMarker, generateJsonSchema, generateWorkspaceJsonSchema, getArg, getBindAddress, getChannelWorkspace, getComponentConfigDir, getConfigRoot, getCoreConfigDir, getCoreConfigFile, getEffectiveServiceName, getPackageVersion, getServiceState, getServiceUrl, getWorkspacePath, init, isPrime, jaccard, jeevesComponentDescriptorSchema, loadEnvFile, loadWorkspaceConfig, needsCleanup, nowIso, ok, orchestrateHeartbeat, parseArgs, parseHeartbeat, parseManaged, patchConfig, postJson, readComponentVersions, readJson, readJsonl, refreshPlatformContent, removeComponentVersion, removeManagedSection, resetInit, resolveConfigPath, resolveConfigValue, resolveOpenClawHome, resolveOptionalPluginSetting, resolvePluginSetting, resolveWorkspacePath, run, runScript, runWithRetry, saveCache, seedContent, seedSkill, shingles, shouldWrite, sleepAsync, sleepMs, updateManagedSection, uuid, withFileLock, workspaceConfigSchema, writeComponentVersion, writeHeartbeatSection, writeJsonAtomic, writeJsonl };
1820
- export type { AccountConfig, AsyncContentCacheOptions, ComponentDependencies, ComponentState, ComponentVersionEntry, ComponentVersionsState, ComponentWriterOptions, ConfigApplyHandler, ConfigApplyRequest, ConfigApplyResult, ConfigProvenance, ConfigQueryHandler, ConfigQueryResponse, CoreConfig, CreatePluginCliOptions, CreateStatusHandlerOptions, GoogleAuthOptions, HeartbeatEntry, InitOptions, JeevesComponentDescriptor, ManagedMarkers, ManagedSection, MemoryHygieneOptions, MemoryHygieneResult, OrchestrateHeartbeatOptions, ParseManagedResult, ParsedHeartbeat, PlatformComponent, PluginApi, RefreshPlatformContentOptions, RemoveManagedSectionOptions, ResolvedValue, RetryOptions, RunOptions, SectionId, SeedContentOptions, ServiceAccountFileConfig, ServiceManager, ServiceManagerOptions, ServiceState, SlackWorkspaceOptions, StatusHandler, StatusHandlerResult, StatusResponse, ToolDescriptor, ToolRegistrationOptions, ToolResult, UpdateManagedSectionOptions, VersionStamp, WorkspaceConfig, WriteComponentVersionOptions };
1882
+ export { AGENTS_MARKERS, CLEANUP_FLAG, COMPONENT_CONFIG_PREFIX, COMPONENT_VERSIONS_FILE, CONFIG_FILE, CORE_CONFIG_DIR, CORE_VERSION, ComponentWriter, DEFAULT_BIND_ADDRESS, DEFAULT_CORE_VERSION, DEFAULT_PORTS, HEARTBEAT_HEADING, JEEVES_SKILL_DIR, MEMORY_HEARTBEAT_NAME, META_PORT, PLATFORM_COMPONENTS, REGISTRY_CACHE_FILE, RUNNER_PORT, SECTION_IDS, SECTION_ORDER, SERVER_PORT, SKILLS_DIR, SOUL_MARKERS, STALENESS_THRESHOLD_MS, STALE_LOCK_MS, TEMPLATES_DIR, TOOLS_MARKERS, VERSION_STAMP_PATTERN, WATCHER_PORT, WORKSPACE_CONFIG_DEFAULTS, WORKSPACE_CONFIG_FILE, WORKSPACE_FILES, analyzeMemory, appendJsonl, atomicWrite, buildEffectiveConfig, buildHeartbeatSection, checkMemoryHealth, checkNodeVersion, checkRegistryVersion, connectionFail, coreConfigSchema, createAsyncContentCache, createComponentWriter, createConfigApplyHandler, createConfigQueryHandler, createGoogleAuth, createPluginCli, createPluginToolset, createServiceCli, createServiceManager, createStatusHandler, ensureDir, extractMostRecentDate, fail, fetchJson, fetchWithTimeout, formatBeginMarker, formatEndMarker, generateJsonSchema, generateWorkspaceJsonSchema, getArg, getBindAddress, getChannelWorkspace, getComponentConfigDir, getConfigRoot, getCoreConfigDir, getCoreConfigFile, getEffectiveServiceName, getPackageVersion, getServiceState, getServiceUrl, getWorkspacePath, init, isPrime, jaccard, jeevesComponentDescriptorSchema, loadEnvFile, loadWorkspaceConfig, needsCleanup, nowIso, ok, orchestrateHeartbeat, parseArgs, parseHeartbeat, parseManaged, patchConfig, postJson, readComponentVersions, readJson, readJsonl, refreshPlatformContent, removeComponentVersion, removeManagedSection, resetInit, resolveConfigPath, resolveConfigValue, resolveOpenClawHome, resolveOptionalPluginSetting, resolvePluginSetting, resolveWorkspacePath, run, runScript, runWithRetry, saveCache, seedContent, seedSkill, shingles, shouldWrite, sleepAsync, sleepMs, updateManagedSection, uuid, withFileLock, workspaceConfigSchema, writeComponentVersion, writeHeartbeatSection, writeJsonAtomic, writeJsonl };
1883
+ export type { AccountConfig, AsyncContentCacheOptions, ComponentDependencies, ComponentState, ComponentVersionEntry, ComponentVersionsState, ComponentWriterOptions, ConfigApplyHandler, ConfigApplyRequest, ConfigApplyResult, ConfigProvenance, ConfigQueryHandler, ConfigQueryResponse, CoreConfig, CreatePluginCliOptions, CreateStatusHandlerOptions, GoogleAuthOptions, HeartbeatEntry, InitOptions, JeevesComponentDescriptor, ManagedMarkers, ManagedSection, MemoryHygieneOptions, MemoryHygieneResult, OrchestrateHeartbeatOptions, ParseManagedResult, ParsedHeartbeat, PlatformComponent, PluginApi, PluginInstallRecord, RefreshPlatformContentOptions, RemoveManagedSectionOptions, ResolvedCliConfig, ResolvedValue, RetryOptions, RunOptions, SectionId, SeedContentOptions, ServiceAccountFileConfig, ServiceManager, ServiceManagerOptions, ServiceState, SlackWorkspaceOptions, StatusHandler, StatusHandlerResult, StatusResponse, ToolDescriptor, ToolRegistrationOptions, ToolResult, UpdateManagedSectionOptions, VersionStamp, WorkspaceConfig, WorkspaceOptions, WriteComponentVersionOptions };