@karmaniverous/jeeves 0.1.6 → 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.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,93 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ /**
4
+ * Generic config query handler with JSONPath support.
5
+ *
6
+ * @remarks
7
+ * Provides a transport-agnostic config query function that can be
8
+ * used by any Jeeves component's HTTP API. Returns the full config
9
+ * document or filters it via JSONPath expressions.
10
+ */
11
+ /** Response shape for config query results. */
12
+ interface ConfigQueryResponse {
13
+ /** HTTP status code. */
14
+ status: number;
15
+ /** Response body. */
16
+ body: unknown;
17
+ }
18
+ /**
19
+ * Handler function type for config queries.
20
+ *
21
+ * @param query - Query parameters.
22
+ * @returns Response with status code and body.
23
+ */
24
+ type ConfigQueryHandler = (query: {
25
+ path?: string;
26
+ }) => Promise<ConfigQueryResponse>;
27
+ /**
28
+ * Create a config query handler.
29
+ *
30
+ * @remarks
31
+ * - No `path` parameter → returns the full config document.
32
+ * - Valid JSONPath → returns matching results with count.
33
+ * - Invalid JSONPath → returns 400 error.
34
+ *
35
+ * @param getConfig - Function that returns the current config object.
36
+ * @returns A config query handler function.
37
+ */
38
+ declare function createConfigQueryHandler(getConfig: () => unknown): ConfigQueryHandler;
39
+
40
+ /**
41
+ * Shared component version state file management.
42
+ *
43
+ * @remarks
44
+ * Each `ComponentWriter` cycle writes its component's entry to
45
+ * `{coreConfigDir}/component-versions.json`. The Platform Handlebars
46
+ * template reads this file to populate ALL rows in the service health
47
+ * table, not just the calling component's.
48
+ */
49
+ /** Version entry for a single component. */
50
+ interface ComponentVersionEntry {
51
+ /** Plugin version (the OpenClaw plugin package version). */
52
+ pluginVersion?: string;
53
+ /** npm package name for the service. */
54
+ servicePackage?: string;
55
+ /** npm package name for the plugin. */
56
+ pluginPackage?: string;
57
+ /** ISO timestamp of last update. */
58
+ updatedAt: string;
59
+ }
60
+ /** Shape of the component-versions.json file. */
61
+ type ComponentVersionsState = Record<string, ComponentVersionEntry>;
62
+ /**
63
+ * Read the component versions state file.
64
+ *
65
+ * @param coreConfigDir - Path to the core config directory.
66
+ * @returns The parsed state, or an empty object if the file doesn't exist.
67
+ */
68
+ declare function readComponentVersions(coreConfigDir: string): ComponentVersionsState;
69
+ /** Options for writing a component version entry. */
70
+ interface WriteComponentVersionOptions {
71
+ /** Component name. */
72
+ componentName: string;
73
+ /** Plugin version. */
74
+ pluginVersion?: string;
75
+ /** Service npm package name. */
76
+ servicePackage?: string;
77
+ /** Plugin npm package name. */
78
+ pluginPackage?: string;
79
+ }
80
+ /**
81
+ * Write a component's version entry to the shared state file.
82
+ *
83
+ * @remarks
84
+ * Reads the existing file, merges the new entry, and writes atomically.
85
+ *
86
+ * @param coreConfigDir - Path to the core config directory.
87
+ * @param options - Component version data to write.
88
+ */
89
+ declare function writeComponentVersion(coreConfigDir: string, options: WriteComponentVersionOptions): void;
90
+
3
91
  /**
4
92
  * Component interface types for the Jeeves platform.
5
93
  *
@@ -77,9 +165,8 @@ declare class ComponentWriter {
77
165
  private timer;
78
166
  private readonly component;
79
167
  private readonly configDir;
80
- private readonly probeTimeoutMs;
81
168
  /** @internal */
82
- constructor(component: JeevesComponent, probeTimeoutMs?: number);
169
+ constructor(component: JeevesComponent);
83
170
  /** The component's config directory path. */
84
171
  get componentConfigDir(): string;
85
172
  /** Whether the writer timer is currently running. */
@@ -172,67 +259,14 @@ declare function createAsyncContentCache(options: AsyncContentCacheOptions): ()
172
259
  * - `generateToolsContent` must be a function
173
260
  */
174
261
 
175
- /** Options for creating a ComponentWriter. */
176
- interface CreateComponentWriterOptions {
177
- /** Timeout for health probes in ms (default 3000). */
178
- probeTimeoutMs?: number;
179
- }
180
262
  /**
181
263
  * Create a ComponentWriter for a validated component descriptor.
182
264
  *
183
265
  * @param component - The component descriptor to validate and wrap.
184
- * @param options - Optional configuration.
185
266
  * @returns A new `ComponentWriter` instance.
186
267
  * @throws Error if the component descriptor is invalid.
187
268
  */
188
- declare function createComponentWriter(component: JeevesComponent, options?: CreateComponentWriterOptions): ComponentWriter;
189
-
190
- /**
191
- * Resolve the OpenClaw workspace root from the plugin API.
192
- *
193
- * @remarks
194
- * Tries three sources in order:
195
- * 1. `api.config.agents.defaults.workspace` — explicit config (most authoritative)
196
- * 2. `api.resolvePath('.')` — gateway-provided path resolver
197
- * 3. `process.cwd()` — last resort (unsafe when gateway runs from system32)
198
- *
199
- * The config value is checked first because `api.resolvePath('.')` delegates
200
- * to `path.resolve('.')`, which returns `process.cwd()` — not the workspace.
201
- * When the gateway runs as a Windows service from `C:\Windows\system32`,
202
- * `resolvePath('.')` returns system32, not the configured workspace.
203
- *
204
- * Plugins should call this once at registration time and pass the result
205
- * to `init({ workspacePath })`.
206
- */
207
- /**
208
- * Minimal shape of the OpenClaw plugin API needed for workspace resolution.
209
- *
210
- * @remarks
211
- * Intentionally loose — plugins define their own full `PluginApi` type.
212
- * This captures only the fields `resolveWorkspacePath` inspects.
213
- */
214
- interface PluginApiLike {
215
- /** Gateway-provided path resolver. May not exist in all gateway versions. */
216
- resolvePath?: (input: string) => string;
217
- /** OpenClaw configuration object. */
218
- config?: {
219
- /** Agent configuration block. */
220
- agents?: {
221
- /** Default agent settings. */
222
- defaults?: {
223
- /** Absolute path to the workspace root directory. */
224
- workspace?: string;
225
- };
226
- };
227
- };
228
- }
229
- /**
230
- * Resolve the workspace root from the OpenClaw plugin API.
231
- *
232
- * @param api - The plugin API object provided by the gateway at registration.
233
- * @returns Absolute path to the workspace root.
234
- */
235
- declare function resolveWorkspacePath(api: PluginApiLike): string;
269
+ declare function createComponentWriter(component: JeevesComponent): ComponentWriter;
236
270
 
237
271
  /**
238
272
  * Comment markers for managed content blocks.
@@ -243,33 +277,21 @@ declare function resolveWorkspacePath(api: PluginApiLike): string;
243
277
  * atomically on each writer cycle. User content outside the markers
244
278
  * is never touched.
245
279
  */
246
- /** Default markers for TOOLS.md managed block. */
247
- declare const TOOLS_MARKERS: {
280
+ /** Shape of managed content markers used by updateManagedSection and removeManagedSection. */
281
+ interface ManagedMarkers {
248
282
  /** BEGIN comment marker text. */
249
- readonly begin: "BEGIN JEEVES PLATFORM TOOLS — DO NOT EDIT THIS SECTION";
283
+ begin: string;
250
284
  /** END comment marker text. */
251
- readonly end: "END JEEVES PLATFORM TOOLS";
252
- /** H1 title prepended in section mode. */
253
- readonly title: "Jeeves Platform Tools";
254
- };
285
+ end: string;
286
+ /** Optional H1 title prepended inside the managed block. */
287
+ title?: string;
288
+ }
289
+ /** Default markers for TOOLS.md managed block. */
290
+ declare const TOOLS_MARKERS: ManagedMarkers;
255
291
  /** Default markers for SOUL.md managed block. */
256
- declare const SOUL_MARKERS: {
257
- /** BEGIN comment marker text. */
258
- readonly begin: "BEGIN JEEVES SOUL — DO NOT EDIT THIS SECTION";
259
- /** END comment marker text. */
260
- readonly end: "END JEEVES SOUL";
261
- /** H1 title prepended in the managed block. */
262
- readonly title: "Jeeves Platform Soul";
263
- };
292
+ declare const SOUL_MARKERS: ManagedMarkers;
264
293
  /** Default markers for AGENTS.md managed block. */
265
- declare const AGENTS_MARKERS: {
266
- /** BEGIN comment marker text. */
267
- readonly begin: "BEGIN JEEVES AGENTS — DO NOT EDIT THIS SECTION";
268
- /** END comment marker text. */
269
- readonly end: "END JEEVES AGENTS";
270
- /** H1 title prepended in the managed block. */
271
- readonly title: "Jeeves Platform Agents";
272
- };
294
+ declare const AGENTS_MARKERS: ManagedMarkers;
273
295
  /**
274
296
  * Regex pattern to extract version stamp from a BEGIN marker comment.
275
297
  *
@@ -305,6 +327,8 @@ declare const TEMPLATES_DIR = "templates";
305
327
  declare const REGISTRY_CACHE_FILE = "registry-cache.json";
306
328
  /** Core config file name. */
307
329
  declare const CONFIG_FILE = "config.json";
330
+ /** Component versions state file name. */
331
+ declare const COMPONENT_VERSIONS_FILE = "component-versions.json";
308
332
 
309
333
  /**
310
334
  * Default port assignments for Jeeves platform services.
@@ -451,44 +475,6 @@ declare function generateJsonSchema(): Record<string, unknown>;
451
475
  */
452
476
  declare function getServiceUrl(serviceName: string, consumerName?: string): string;
453
477
 
454
- /**
455
- * HTTP health probing for Jeeves platform services.
456
- *
457
- * @remarks
458
- * Probes service ports for health endpoints (HTTP GET to /status or /health).
459
- * Returns structured health data for rendering into TOOLS.md Platform section.
460
- */
461
- /** Health probe result for a single service. */
462
- interface ProbeResult {
463
- /** Service name (e.g., 'server', 'watcher'). */
464
- name: string;
465
- /** Port number. */
466
- port: number;
467
- /** Whether the service responded successfully. */
468
- healthy: boolean;
469
- /** Service version from the health response, if available. */
470
- version?: string;
471
- /** Error message if the probe failed. */
472
- error?: string;
473
- }
474
- /**
475
- * Probe a single service for health.
476
- *
477
- * @param serviceName - The service name (e.g., 'server', 'watcher').
478
- * @param consumerName - Optional consumer name for URL resolution.
479
- * @param timeoutMs - Request timeout in milliseconds (default 3000).
480
- * @returns Probe result.
481
- */
482
- declare function probeService(serviceName: string, consumerName?: string, timeoutMs?: number): Promise<ProbeResult>;
483
- /**
484
- * Probe all known Jeeves services for health.
485
- *
486
- * @param consumerName - Optional consumer name for URL resolution.
487
- * @param timeoutMs - Request timeout in milliseconds (default 3000).
488
- * @returns Array of probe results for all services.
489
- */
490
- declare function probeAllServices(consumerName?: string, timeoutMs?: number): Promise<ProbeResult[]>;
491
-
492
478
  /**
493
479
  * Registry version cache for npm package update awareness.
494
480
  *
@@ -599,6 +585,38 @@ declare function jaccard(a: Set<string>, b: Set<string>): number;
599
585
  */
600
586
  declare function needsCleanup(managedContent: string, userContent: string, threshold?: number): boolean;
601
587
 
588
+ /**
589
+ * Shared file I/O helpers for managed section operations.
590
+ *
591
+ * @remarks
592
+ * Extracts the atomic write pattern and file-level locking into
593
+ * reusable utilities, eliminating duplication between
594
+ * `updateManagedSection` and `removeManagedSection`.
595
+ */
596
+ /** Stale lock threshold in ms (2 minutes). */
597
+ declare const STALE_LOCK_MS = 120000;
598
+ /** Default core version when none provided. */
599
+ declare const DEFAULT_CORE_VERSION: string;
600
+ /**
601
+ * Write content to a file atomically via a temp file + rename.
602
+ *
603
+ * @param filePath - Absolute path to the target file.
604
+ * @param content - Content to write.
605
+ */
606
+ declare function atomicWrite(filePath: string, content: string): void;
607
+ /**
608
+ * Execute a callback while holding a file lock.
609
+ *
610
+ * @remarks
611
+ * Acquires a lock on the file, executes the callback, and releases
612
+ * the lock in a finally block. The lock uses a 2-minute stale threshold
613
+ * and retries up to 5 times.
614
+ *
615
+ * @param filePath - Absolute path to the file to lock.
616
+ * @param fn - Async callback to execute while holding the lock.
617
+ */
618
+ declare function withFileLock(filePath: string, fn: () => void | Promise<void>): Promise<void>;
619
+
602
620
  /**
603
621
  * Parse managed block from file content.
604
622
  *
@@ -648,6 +666,35 @@ declare function parseManaged(fileContent: string, markers?: {
648
666
  end: string;
649
667
  }): ParseManagedResult;
650
668
 
669
+ /**
670
+ * Remove a managed section or entire managed block from a file.
671
+ *
672
+ * @remarks
673
+ * Supports two modes:
674
+ * - No `sectionId`: Remove the entire managed block (markers + content),
675
+ * leaving user content intact.
676
+ * - With `sectionId`: Remove a specific H2 section from within the
677
+ * managed block. If it was the last section, remove the entire block.
678
+ *
679
+ * Provides file-level locking and atomic writes (temp file + rename).
680
+ * Missing markers or nonexistent sections are no-ops (no error thrown).
681
+ */
682
+
683
+ /** Options for removeManagedSection. */
684
+ interface RemoveManagedSectionOptions {
685
+ /** Section ID to remove. If omitted, removes the entire managed block. */
686
+ sectionId?: string;
687
+ /** Custom markers. Defaults to TOOLS markers. */
688
+ markers?: ManagedMarkers;
689
+ }
690
+ /**
691
+ * Remove a managed section or entire managed block from a file.
692
+ *
693
+ * @param filePath - Absolute path to the target file.
694
+ * @param options - Optional section ID and custom markers.
695
+ */
696
+ declare function removeManagedSection(filePath: string, options?: RemoveManagedSectionOptions): Promise<void>;
697
+
651
698
  /**
652
699
  * Generic managed-section writer with block and section modes.
653
700
  *
@@ -658,6 +705,7 @@ declare function parseManaged(fileContent: string, markers?: {
658
705
  *
659
706
  * Provides file-level locking, version-stamp convergence, and atomic writes.
660
707
  */
708
+
661
709
  /** Options for updateManagedSection. */
662
710
  interface UpdateManagedSectionOptions {
663
711
  /** Write mode. Default: 'block'. */
@@ -665,14 +713,7 @@ interface UpdateManagedSectionOptions {
665
713
  /** Section ID — required when mode is 'section'. */
666
714
  sectionId?: string;
667
715
  /** Custom markers. Defaults to TOOLS markers. */
668
- markers?: {
669
- /** BEGIN comment marker text. */
670
- begin: string;
671
- /** END comment marker text. */
672
- end: string;
673
- /** Optional H1 title prepended in section mode. */
674
- title?: string;
675
- };
716
+ markers?: ManagedMarkers;
676
717
  /** Core library version for version-stamp convergence. */
677
718
  coreVersion?: string;
678
719
  /** Staleness threshold in ms for version-stamp convergence. */
@@ -727,9 +768,9 @@ declare function shouldWrite(myVersion: string, existing: VersionStamp | undefin
727
768
  *
728
769
  * @remarks
729
770
  * Called by `ComponentWriter` on each cycle. Not directly exposed to components.
730
- * Probes service ports for health, reads content files from the package's
731
- * `content/` directory, renders the Platform template with live service data,
732
- * and writes managed sections using `updateManagedSection`.
771
+ * Reads content files from the package's `content/` directory, renders the
772
+ * Platform template with live data, and writes managed sections using
773
+ * `updateManagedSection`.
733
774
  */
734
775
  /** Options for refreshPlatformContent. */
735
776
  interface RefreshPlatformContentOptions {
@@ -745,10 +786,6 @@ interface RefreshPlatformContentOptions {
745
786
  pluginPackage?: string;
746
787
  /** Staleness threshold override in ms. */
747
788
  stalenessThresholdMs?: number;
748
- /** Timeout for health probes in ms. */
749
- probeTimeoutMs?: number;
750
- /** Skip registry version check (useful for testing). */
751
- skipRegistryCheck?: boolean;
752
789
  }
753
790
  /**
754
791
  * Refresh platform content: SOUL.md, AGENTS.md, and TOOLS.md Platform section.
@@ -769,10 +806,6 @@ declare function refreshPlatformContent(options: RefreshPlatformContentOptions):
769
806
  interface SeedContentOptions {
770
807
  /** Core library version for version-stamp convergence. */
771
808
  coreVersion: string;
772
- /** Timeout for health probes in ms. */
773
- probeTimeoutMs?: number;
774
- /** Skip registry version check. */
775
- skipRegistryCheck?: boolean;
776
809
  }
777
810
  /**
778
811
  * Seed all platform content into the workspace.
@@ -786,5 +819,246 @@ interface SeedContentOptions {
786
819
  */
787
820
  declare function seedContent(options: SeedContentOptions): Promise<void>;
788
821
 
789
- export { AGENTS_MARKERS, CLEANUP_FLAG, COMPONENT_CONFIG_PREFIX, CONFIG_FILE, CORE_CONFIG_DIR, CORE_VERSION, ComponentWriter, DEFAULT_PORTS, META_PORT, REGISTRY_CACHE_FILE, RUNNER_PORT, SECTION_IDS, SECTION_ORDER, SERVER_PORT, SOUL_MARKERS, STALENESS_THRESHOLD_MS, TEMPLATES_DIR, TOOLS_MARKERS, VERSION_STAMP_PATTERN, WATCHER_PORT, WORKSPACE_FILES, checkRegistryVersion, coreConfigSchema, createAsyncContentCache, createComponentWriter, formatBeginMarker, formatEndMarker, generateJsonSchema, getComponentConfigDir, getConfigRoot, getCoreConfigDir, getCoreConfigFile, getServiceUrl, getWorkspacePath, init, jaccard, needsCleanup, parseManaged, probeAllServices, probeService, refreshPlatformContent, resetInit, resolveWorkspacePath, seedContent, shingles, shouldWrite, updateManagedSection };
790
- export type { AsyncContentCacheOptions, CoreConfig, CreateComponentWriterOptions, InitOptions, JeevesComponent, ManagedSection, ParseManagedResult, PluginApiLike, PluginCommands, ProbeResult, RefreshPlatformContentOptions, SectionId, SeedContentOptions, ServiceCommands, ServiceStatus, UpdateManagedSectionOptions, VersionStamp };
822
+ /**
823
+ * HTTP helpers for the OpenClaw plugin SDK.
824
+ *
825
+ * @remarks
826
+ * Thin wrappers around `fetch` that throw on non-OK responses
827
+ * and handle JSON serialisation/deserialisation.
828
+ */
829
+ /**
830
+ * Fetch a URL with an automatic abort timeout.
831
+ *
832
+ * @param url - URL to fetch.
833
+ * @param timeoutMs - Timeout in milliseconds before aborting.
834
+ * @param init - Optional `fetch` init options.
835
+ * @returns The fetch Response object.
836
+ */
837
+ declare function fetchWithTimeout(url: string, timeoutMs: number, init?: RequestInit): Promise<Response>;
838
+ /**
839
+ * Fetch JSON from a URL, throwing on non-OK responses.
840
+ *
841
+ * @param url - URL to fetch.
842
+ * @param init - Optional `fetch` init options.
843
+ * @returns Parsed JSON response body.
844
+ * @throws Error with `HTTP {status}: {body}` message on non-OK responses.
845
+ */
846
+ declare function fetchJson(url: string, init?: RequestInit): Promise<unknown>;
847
+ /**
848
+ * POST JSON to a URL and return parsed response.
849
+ *
850
+ * @param url - URL to POST to.
851
+ * @param body - Request body (will be JSON-stringified).
852
+ * @returns Parsed JSON response body.
853
+ */
854
+ declare function postJson(url: string, body: unknown): Promise<unknown>;
855
+
856
+ /**
857
+ * OpenClaw configuration helpers for plugin CLI installers.
858
+ *
859
+ * @remarks
860
+ * Provides resolution of OpenClaw home directory and config file path,
861
+ * plus idempotent config patching for plugin install/uninstall.
862
+ */
863
+ /**
864
+ * Resolve the OpenClaw home directory.
865
+ *
866
+ * @remarks
867
+ * Resolution order:
868
+ * 1. `OPENCLAW_CONFIG` env var → dirname of the config file path
869
+ * 2. `OPENCLAW_HOME` env var → resolved path
870
+ * 3. Default: `~/.openclaw`
871
+ *
872
+ * @returns Absolute path to the OpenClaw home directory.
873
+ */
874
+ declare function resolveOpenClawHome(): string;
875
+ /**
876
+ * Resolve the OpenClaw config file path.
877
+ *
878
+ * @remarks
879
+ * If `OPENCLAW_CONFIG` is set, uses that directly.
880
+ * Otherwise defaults to `{home}/openclaw.json`.
881
+ *
882
+ * @param home - The OpenClaw home directory.
883
+ * @returns Absolute path to the config file.
884
+ */
885
+ declare function resolveConfigPath(home: string): string;
886
+ /**
887
+ * Patch an OpenClaw config for plugin install or uninstall.
888
+ *
889
+ * @remarks
890
+ * Manages `plugins.entries.{pluginId}` and `tools.alsoAllow`.
891
+ * Idempotent: adding twice produces no duplicates; removing when absent
892
+ * produces no errors.
893
+ *
894
+ * @param config - The parsed OpenClaw config object (mutated in place).
895
+ * @param pluginId - The plugin identifier.
896
+ * @param mode - Whether to add or remove the plugin.
897
+ * @returns Array of log messages describing changes made.
898
+ */
899
+ declare function patchConfig(config: Record<string, unknown>, pluginId: string, mode: 'add' | 'remove'): string[];
900
+
901
+ /**
902
+ * Core types for the OpenClaw plugin SDK.
903
+ *
904
+ * @remarks
905
+ * These types define the contract between plugins and the OpenClaw gateway.
906
+ * They unify the various `PluginApi` definitions previously duplicated
907
+ * across component plugins into a single canonical source.
908
+ */
909
+ /** Result shape returned by tool executions. */
910
+ interface ToolResult {
911
+ /** Content blocks — typically a single text block. */
912
+ content: Array<{
913
+ type: string;
914
+ text: string;
915
+ }>;
916
+ /** Whether this result represents an error. */
917
+ isError?: boolean;
918
+ }
919
+ /** Tool descriptor for registration with the OpenClaw gateway. */
920
+ interface ToolDescriptor {
921
+ /** Unique tool name. */
922
+ name: string;
923
+ /** Human-readable description. */
924
+ description: string;
925
+ /** JSON Schema for the tool's parameters. */
926
+ parameters: Record<string, unknown>;
927
+ /** Execute the tool with the given parameters. */
928
+ execute: (id: string, params: Record<string, unknown>) => Promise<ToolResult>;
929
+ }
930
+ /** Options for tool registration. */
931
+ interface ToolRegistrationOptions {
932
+ /** Whether the tool is optional (non-fatal if registration fails). */
933
+ optional?: boolean;
934
+ }
935
+ /**
936
+ * Canonical OpenClaw plugin API interface.
937
+ *
938
+ * @remarks
939
+ * This is the shape of the `api` object passed to plugins by the
940
+ * OpenClaw gateway at registration time. Fields are optional where
941
+ * the gateway may not provide them in all versions.
942
+ */
943
+ interface PluginApi {
944
+ /** OpenClaw configuration object. */
945
+ config?: {
946
+ /** Agent configuration block. */
947
+ agents?: {
948
+ /** Default agent settings. */
949
+ defaults?: {
950
+ /** Absolute path to the workspace root directory. */
951
+ workspace?: string;
952
+ };
953
+ };
954
+ /** Installed plugin configuration. */
955
+ plugins?: {
956
+ /** Plugin entries keyed by plugin ID. */
957
+ entries?: Record<string, {
958
+ config?: Record<string, unknown>;
959
+ }>;
960
+ };
961
+ };
962
+ /**
963
+ * Resolve a path relative to the OpenClaw workspace.
964
+ *
965
+ * @remarks
966
+ * Present on newer OpenClaw builds; optional for backwards compatibility.
967
+ */
968
+ resolvePath?: (input: string) => string;
969
+ /**
970
+ * Register a tool with the OpenClaw gateway.
971
+ *
972
+ * @param tool - Tool descriptor.
973
+ * @param options - Registration options.
974
+ */
975
+ registerTool(tool: ToolDescriptor, options?: ToolRegistrationOptions): void;
976
+ }
977
+
978
+ /**
979
+ * Plugin resolution helpers for the OpenClaw plugin SDK.
980
+ *
981
+ * @remarks
982
+ * Provides workspace path resolution and plugin setting resolution
983
+ * with a standard three-step fallback chain:
984
+ * plugin config → environment variable → default value.
985
+ */
986
+
987
+ /**
988
+ * Resolve the workspace root from the OpenClaw plugin API.
989
+ *
990
+ * @remarks
991
+ * Tries three sources in order:
992
+ * 1. `api.config.agents.defaults.workspace` — explicit config
993
+ * 2. `api.resolvePath('.')` — gateway-provided path resolver
994
+ * 3. `process.cwd()` — last resort
995
+ *
996
+ * @param api - The plugin API object provided by the gateway.
997
+ * @returns Absolute path to the workspace root.
998
+ */
999
+ declare function resolveWorkspacePath(api: PluginApi): string;
1000
+ /**
1001
+ * Resolve a plugin setting via the standard three-step fallback chain:
1002
+ * plugin config → environment variable → fallback value.
1003
+ *
1004
+ * @param api - Plugin API object.
1005
+ * @param pluginId - Plugin identifier (e.g., 'jeeves-watcher-openclaw').
1006
+ * @param key - Config key within the plugin's config object.
1007
+ * @param envVar - Environment variable name.
1008
+ * @param fallback - Default value if neither source provides one.
1009
+ * @returns The resolved setting value.
1010
+ */
1011
+ declare function resolvePluginSetting(api: PluginApi, pluginId: string, key: string, envVar: string, fallback: string): string;
1012
+ /**
1013
+ * Resolve an optional plugin setting via the two-step fallback chain:
1014
+ * plugin config → environment variable. Returns `undefined` if neither
1015
+ * source provides a value.
1016
+ *
1017
+ * @param api - Plugin API object.
1018
+ * @param pluginId - Plugin identifier (e.g., 'jeeves-watcher-openclaw').
1019
+ * @param key - Config key within the plugin's config object.
1020
+ * @param envVar - Environment variable name.
1021
+ * @returns The resolved setting value, or `undefined`.
1022
+ */
1023
+ declare function resolveOptionalPluginSetting(api: PluginApi, pluginId: string, key: string, envVar: string): string | undefined;
1024
+
1025
+ /**
1026
+ * Tool result formatters for the OpenClaw plugin SDK.
1027
+ *
1028
+ * @remarks
1029
+ * Provides standardised helpers for building `ToolResult` objects:
1030
+ * success, error, and connection-error variants.
1031
+ */
1032
+
1033
+ /**
1034
+ * Format a successful tool result.
1035
+ *
1036
+ * @param data - Arbitrary data to return as JSON.
1037
+ * @returns A `ToolResult` with JSON-stringified content.
1038
+ */
1039
+ declare function ok(data: unknown): ToolResult;
1040
+ /**
1041
+ * Format an error tool result.
1042
+ *
1043
+ * @param error - Error instance, string, or other value.
1044
+ * @returns A `ToolResult` with `isError: true`.
1045
+ */
1046
+ declare function fail(error: unknown): ToolResult;
1047
+ /**
1048
+ * Format a connection error with actionable guidance.
1049
+ *
1050
+ * @remarks
1051
+ * Detects `ECONNREFUSED`, `ENOTFOUND`, and `ETIMEDOUT` from
1052
+ * `error.cause.code` and returns a user-friendly message referencing
1053
+ * the plugin's `config.apiUrl` setting. Falls back to `fail()` for
1054
+ * non-connection errors.
1055
+ *
1056
+ * @param error - Error instance (typically from `fetch`).
1057
+ * @param baseUrl - The URL that was being contacted.
1058
+ * @param pluginId - The plugin identifier for config guidance.
1059
+ * @returns A `ToolResult` with `isError: true`.
1060
+ */
1061
+ declare function connectionFail(error: unknown, baseUrl: string, pluginId: string): ToolResult;
1062
+
1063
+ export { AGENTS_MARKERS, CLEANUP_FLAG, COMPONENT_CONFIG_PREFIX, COMPONENT_VERSIONS_FILE, CONFIG_FILE, CORE_CONFIG_DIR, CORE_VERSION, ComponentWriter, DEFAULT_CORE_VERSION, DEFAULT_PORTS, META_PORT, REGISTRY_CACHE_FILE, RUNNER_PORT, SECTION_IDS, SECTION_ORDER, SERVER_PORT, SOUL_MARKERS, STALENESS_THRESHOLD_MS, STALE_LOCK_MS, TEMPLATES_DIR, TOOLS_MARKERS, VERSION_STAMP_PATTERN, WATCHER_PORT, WORKSPACE_FILES, atomicWrite, checkRegistryVersion, connectionFail, coreConfigSchema, createAsyncContentCache, createComponentWriter, createConfigQueryHandler, fail, fetchJson, fetchWithTimeout, formatBeginMarker, formatEndMarker, generateJsonSchema, getComponentConfigDir, getConfigRoot, getCoreConfigDir, getCoreConfigFile, getServiceUrl, getWorkspacePath, init, jaccard, needsCleanup, ok, parseManaged, patchConfig, postJson, readComponentVersions, refreshPlatformContent, removeManagedSection, resetInit, resolveConfigPath, resolveOpenClawHome, resolveOptionalPluginSetting, resolvePluginSetting, resolveWorkspacePath, seedContent, shingles, shouldWrite, updateManagedSection, withFileLock, writeComponentVersion };
1064
+ export type { AsyncContentCacheOptions, ComponentVersionEntry, ComponentVersionsState, ConfigQueryHandler, ConfigQueryResponse, CoreConfig, InitOptions, JeevesComponent, ManagedMarkers, ManagedSection, ParseManagedResult, PluginApi, PluginCommands, RefreshPlatformContentOptions, RemoveManagedSectionOptions, SectionId, SeedContentOptions, ServiceCommands, ServiceStatus, ToolDescriptor, ToolRegistrationOptions, ToolResult, UpdateManagedSectionOptions, VersionStamp, WriteComponentVersionOptions };