@agenthifive/openclaw 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.
@@ -1,422 +0,0 @@
1
- /**
2
- * Auto-patching for OpenClaw's credential resolution.
3
- *
4
- * Finds the OpenClaw installation and injects vault credential resolution
5
- * into resolveApiKeyForProvider(). Supports both source installs (TypeScript)
6
- * and npm installs (compiled JS chunks with hashed filenames).
7
- *
8
- * The patch adds two tiers before local profile resolution:
9
- * - Tier 0: Proxied providers (vault bearer token used directly)
10
- * - Tier 0.5: Credential provider chain (query vault before local profiles)
11
- */
12
- import { existsSync, readdirSync, readFileSync, realpathSync, writeFileSync, } from "node:fs";
13
- import os from "node:os";
14
- import path from "node:path";
15
- // ---------------------------------------------------------------------------
16
- // Marker used to detect if the patch is already applied
17
- // ---------------------------------------------------------------------------
18
- const PATCH_MARKER = "@agenthifive/openclaw/runtime";
19
- // ---------------------------------------------------------------------------
20
- // Code injected into compiled dist files
21
- // ---------------------------------------------------------------------------
22
- const INJECTED_CODE = `
23
- \t// -- AgentHiFive: Tier 0 + Tier 0.5 vault credential resolution --
24
- \t// @agenthifive/openclaw/runtime
25
- \ttry {
26
- \t\tconst runtime = await import("@agenthifive/openclaw/runtime");
27
- \t\tif (runtime.isInitialized()) {
28
- \t\t\tconst proxiedProviders = runtime.getProxiedProviders();
29
- \t\t\tif (proxiedProviders.includes(provider)) {
30
- \t\t\t\tconst vaultToken = runtime.getVaultBearerToken();
31
- \t\t\t\tif (vaultToken) {
32
- \t\t\t\t\treturn { apiKey: vaultToken, source: "vault:agent-token", mode: "api-key" };
33
- \t\t\t\t}
34
- \t\t\t}
35
- \t\t\tconst vaultResult = await runtime.resolveCredential({
36
- \t\t\t\tkind: "model_provider",
37
- \t\t\t\tprovider,
38
- \t\t\t\tprofileId: preferredProfile,
39
- \t\t\t});
40
- \t\t\tif (vaultResult?.apiKey) {
41
- \t\t\t\treturn {
42
- \t\t\t\t\tapiKey: vaultResult.apiKey,
43
- \t\t\t\t\tsource: "credential-provider:vault",
44
- \t\t\t\t\tmode: vaultResult.mode ?? "api-key",
45
- \t\t\t\t};
46
- \t\t\t}
47
- \t\t}
48
- \t} catch {
49
- \t\t// Plugin not installed -- skip vault credential resolution
50
- \t}
51
- `;
52
- // ---------------------------------------------------------------------------
53
- // Anchor patterns
54
- // ---------------------------------------------------------------------------
55
- /**
56
- * Regex matching the store assignment line in resolveApiKeyForProvider.
57
- * This is stable across upstream versions — it's the first line after
58
- * the destructuring of params.
59
- *
60
- * Upstream dist (2026.3.13):
61
- * const store = params.store ?? ensureAuthProfileStore(params.agentDir);
62
- * if (profileId) {
63
- */
64
- const DIST_ANCHOR = /const store\s*=\s*params\.store\s*\?\?\s*ensureAuthProfileStore\(params\.agentDir\);\n/;
65
- // ---------------------------------------------------------------------------
66
- // Find OpenClaw installation
67
- // ---------------------------------------------------------------------------
68
- /**
69
- * Locate the OpenClaw installation directory.
70
- *
71
- * Strategy (cascading, first match wins):
72
- * 1. `which`/`where` openclaw → resolve symlink → walk up to package.json
73
- * 2. `npm root -g` → check for openclaw package
74
- * 3. Well-known paths (Linux, macOS, Windows)
75
- * 4. `find` as last resort (Linux/macOS only, with timeout)
76
- *
77
- * Returns null if not found — caller should ask the user.
78
- */
79
- export function findOpenClawInstallDir() {
80
- // Strategy 1: scan PATH for openclaw binary → resolve symlink
81
- const result = findViaPath();
82
- if (result)
83
- return result;
84
- // Strategy 2: derive global node_modules from Node.js binary location
85
- const npmResult = findViaNpmPrefix();
86
- if (npmResult)
87
- return npmResult;
88
- // Strategy 3: well-known paths
89
- const wellKnown = findViaWellKnownPaths();
90
- if (wellKnown)
91
- return wellKnown;
92
- // Strategy 4: recursive directory scan (last resort)
93
- const found = findViaRecursiveScan();
94
- if (found)
95
- return found;
96
- return null;
97
- }
98
- function classifyInstall(dir) {
99
- const hasSrc = existsSync(path.join(dir, "src", "agents", "model-auth.ts"));
100
- return { dir, kind: hasSrc ? "source" : "dist" };
101
- }
102
- function isOpenClawDir(dir) {
103
- const pkgPath = path.join(dir, "package.json");
104
- if (!existsSync(pkgPath))
105
- return false;
106
- try {
107
- const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
108
- return pkg.name === "openclaw";
109
- }
110
- catch {
111
- return false;
112
- }
113
- }
114
- function walkUpToPackageRoot(startDir) {
115
- let dir = startDir;
116
- for (let i = 0; i < 10; i++) {
117
- if (isOpenClawDir(dir))
118
- return dir;
119
- const parent = path.dirname(dir);
120
- if (parent === dir)
121
- break;
122
- dir = parent;
123
- }
124
- return null;
125
- }
126
- function findViaPath() {
127
- const pathEnv = process.env.PATH ?? "";
128
- const sep = process.platform === "win32" ? ";" : ":";
129
- const exts = process.platform === "win32" ? [".cmd", ".bat", ".exe", ""] : [""];
130
- for (const dir of pathEnv.split(sep).filter(Boolean)) {
131
- for (const ext of exts) {
132
- const candidate = path.join(dir, `openclaw${ext}`);
133
- if (!existsSync(candidate))
134
- continue;
135
- // Resolve symlinks to find the real binary location
136
- let realBin;
137
- try {
138
- realBin = realpathSync(candidate);
139
- }
140
- catch {
141
- realBin = candidate;
142
- }
143
- // Walk up from binary to find package root
144
- const root = walkUpToPackageRoot(path.dirname(realBin));
145
- if (root)
146
- return classifyInstall(root);
147
- // Binary might be a wrapper script — check if it references a node_modules path
148
- try {
149
- const content = readFileSync(realBin, "utf-8");
150
- const match = /["']([^"']+openclaw[^"']*)['"]/i.exec(content);
151
- if (match?.[1]) {
152
- const resolved = path.resolve(path.dirname(realBin), match[1]);
153
- const root2 = walkUpToPackageRoot(path.dirname(resolved));
154
- if (root2)
155
- return classifyInstall(root2);
156
- }
157
- }
158
- catch {
159
- // Not readable as text
160
- }
161
- }
162
- }
163
- return null;
164
- }
165
- function findViaNpmPrefix() {
166
- // Derive global node_modules from the running Node.js binary location
167
- // e.g. /usr/lib/node_modules/openclaw or /home/user/.nvm/versions/node/v24/lib/node_modules/openclaw
168
- const nodeDir = path.dirname(process.execPath); // e.g. /usr/bin or .../bin
169
- const prefixDir = path.dirname(nodeDir); // e.g. /usr or .../v24
170
- const candidate = path.join(prefixDir, "lib", "node_modules", "openclaw");
171
- if (isOpenClawDir(candidate))
172
- return classifyInstall(candidate);
173
- // Also check directly under prefix (some setups)
174
- const candidate2 = path.join(prefixDir, "node_modules", "openclaw");
175
- if (isOpenClawDir(candidate2))
176
- return classifyInstall(candidate2);
177
- return null;
178
- }
179
- function findViaWellKnownPaths() {
180
- const home = os.homedir();
181
- const candidates = [];
182
- if (process.platform === "win32") {
183
- // Windows: AppData paths derived from home directory
184
- candidates.push(path.join(home, "AppData", "Roaming", "npm", "node_modules", "openclaw"), path.join(home, "AppData", "Local", "pnpm", "global", "5", "node_modules", "openclaw"));
185
- }
186
- else {
187
- candidates.push("/usr/lib/node_modules/openclaw", "/usr/local/lib/node_modules/openclaw", path.join(home, ".local/share/pnpm/global/5/node_modules/openclaw"));
188
- if (process.platform === "darwin") {
189
- candidates.push("/opt/homebrew/lib/node_modules/openclaw");
190
- }
191
- }
192
- for (const candidate of candidates) {
193
- if (isOpenClawDir(candidate))
194
- return classifyInstall(candidate);
195
- }
196
- return null;
197
- }
198
- function findViaRecursiveScan() {
199
- const home = os.homedir();
200
- const searchDirs = ["/usr", "/opt", home].filter((d) => d && existsSync(d));
201
- const matches = [];
202
- const maxDepth = 8;
203
- function scan(dir, depth) {
204
- if (depth > maxDepth || matches.length > 1)
205
- return;
206
- try {
207
- const entries = readdirSync(dir, { withFileTypes: true });
208
- for (const entry of entries) {
209
- if (!entry.isDirectory())
210
- continue;
211
- // Skip hidden dirs, node_modules internals, and proc/sys
212
- if (entry.name.startsWith(".") && entry.name !== ".nvm" && entry.name !== ".local")
213
- continue;
214
- if (entry.name === "node_modules" && depth > 0) {
215
- // Check for openclaw directly inside node_modules
216
- const candidate = path.join(dir, entry.name, "openclaw");
217
- if (isOpenClawDir(candidate))
218
- matches.push(candidate);
219
- continue;
220
- }
221
- if (entry.name === "openclaw") {
222
- const candidate = path.join(dir, entry.name);
223
- if (isOpenClawDir(candidate)) {
224
- matches.push(candidate);
225
- continue;
226
- }
227
- }
228
- scan(path.join(dir, entry.name), depth + 1);
229
- }
230
- }
231
- catch {
232
- // Permission denied or other error
233
- }
234
- }
235
- for (const searchDir of searchDirs) {
236
- scan(searchDir, 0);
237
- if (matches.length > 1)
238
- return null; // Multiple — caller should ask user
239
- }
240
- if (matches.length === 1)
241
- return classifyInstall(matches[0]);
242
- return null;
243
- }
244
- /**
245
- * Find all OpenClaw installations (for disambiguation when multiple exist).
246
- */
247
- export function findAllOpenClawInstalls() {
248
- const results = [];
249
- const seen = new Set();
250
- const add = (install) => {
251
- if (!install)
252
- return;
253
- const resolved = path.resolve(install.dir);
254
- if (seen.has(resolved))
255
- return;
256
- seen.add(resolved);
257
- results.push({ ...install, dir: resolved });
258
- };
259
- add(findViaPath());
260
- add(findViaNpmPrefix());
261
- add(findViaWellKnownPaths());
262
- return results;
263
- }
264
- // ---------------------------------------------------------------------------
265
- // Validate user-provided path
266
- // ---------------------------------------------------------------------------
267
- /**
268
- * Validate a user-provided OpenClaw installation path.
269
- */
270
- export function validateOpenClawDir(dir) {
271
- const resolved = path.resolve(dir);
272
- if (!isOpenClawDir(resolved))
273
- return null;
274
- return classifyInstall(resolved);
275
- }
276
- // ---------------------------------------------------------------------------
277
- // Apply patch to dist (compiled JS)
278
- // ---------------------------------------------------------------------------
279
- /**
280
- * Find the chunk file containing resolveApiKeyForProvider in dist/.
281
- */
282
- export function findDistChunk(distDir) {
283
- if (!existsSync(distDir))
284
- return null;
285
- const files = readdirSync(distDir).filter((f) => f.endsWith(".js"));
286
- // Primary: look for auth-profiles-*.js (upstream chunk name)
287
- const authChunk = files.find((f) => f.startsWith("auth-profiles") || f.startsWith("model-auth"));
288
- if (authChunk) {
289
- const content = readFileSync(path.join(distDir, authChunk), "utf-8");
290
- if (content.includes("resolveApiKeyForProvider")) {
291
- return path.join(distDir, authChunk);
292
- }
293
- }
294
- // Fallback: search all JS files
295
- for (const file of files) {
296
- const filePath = path.join(distDir, file);
297
- const content = readFileSync(filePath, "utf-8");
298
- if (content.includes("async function resolveApiKeyForProvider") &&
299
- content.includes("ensureAuthProfileStore")) {
300
- return filePath;
301
- }
302
- }
303
- return null;
304
- }
305
- export function applyDistPatch(openclawDir) {
306
- const distDir = path.join(openclawDir, "dist");
307
- const chunkPath = findDistChunk(distDir);
308
- if (!chunkPath) {
309
- return {
310
- applied: false,
311
- alreadyPatched: false,
312
- message: "Could not find resolveApiKeyForProvider in OpenClaw dist/. " +
313
- "The OpenClaw version may be incompatible.",
314
- };
315
- }
316
- const source = readFileSync(chunkPath, "utf-8");
317
- // Already patched?
318
- if (source.includes(PATCH_MARKER)) {
319
- return {
320
- applied: true,
321
- alreadyPatched: true,
322
- message: `Already patched: ${path.basename(chunkPath)}`,
323
- };
324
- }
325
- // Find anchor
326
- const match = DIST_ANCHOR.exec(source);
327
- if (!match) {
328
- return {
329
- applied: false,
330
- alreadyPatched: false,
331
- message: `Found ${path.basename(chunkPath)} but could not locate the anchor point. ` +
332
- "The OpenClaw version may be incompatible.",
333
- };
334
- }
335
- // Create backup
336
- const backupPath = chunkPath + ".bak";
337
- writeFileSync(backupPath, source);
338
- // Inject code after the anchor line
339
- const insertPos = match.index + match[0].length;
340
- const patched = source.slice(0, insertPos) + INJECTED_CODE + source.slice(insertPos);
341
- writeFileSync(chunkPath, patched);
342
- return {
343
- applied: true,
344
- alreadyPatched: false,
345
- message: `Patched ${path.basename(chunkPath)} (backup: ${path.basename(backupPath)})`,
346
- };
347
- }
348
- // ---------------------------------------------------------------------------
349
- // Apply patch to source install
350
- // ---------------------------------------------------------------------------
351
- export function applySourcePatch(openclawDir) {
352
- const targetFile = path.join(openclawDir, "src", "agents", "model-auth.ts");
353
- if (!existsSync(targetFile)) {
354
- return {
355
- applied: false,
356
- alreadyPatched: false,
357
- message: "src/agents/model-auth.ts not found",
358
- };
359
- }
360
- const source = readFileSync(targetFile, "utf-8");
361
- if (source.includes(PATCH_MARKER)) {
362
- return {
363
- applied: true,
364
- alreadyPatched: true,
365
- message: "Source already patched",
366
- };
367
- }
368
- // Text injection (same approach as dist patching, with spaces instead of tabs)
369
- const match = DIST_ANCHOR.exec(source);
370
- if (match) {
371
- const backupPath = targetFile + ".bak";
372
- writeFileSync(backupPath, source);
373
- const insertPos = match.index + match[0].length;
374
- const patched = source.slice(0, insertPos) +
375
- "\n" +
376
- INJECTED_CODE.replace(/\t/g, " ") +
377
- "\n" +
378
- source.slice(insertPos);
379
- writeFileSync(targetFile, patched);
380
- return {
381
- applied: true,
382
- alreadyPatched: false,
383
- message: `Source patched (backup: ${path.basename(backupPath)})`,
384
- };
385
- }
386
- return {
387
- applied: false,
388
- alreadyPatched: false,
389
- message: "Could not locate anchor point in source file",
390
- };
391
- }
392
- // ---------------------------------------------------------------------------
393
- // Unified apply
394
- // ---------------------------------------------------------------------------
395
- /**
396
- * Apply the credential resolution patch to an OpenClaw installation.
397
- * Automatically detects source vs dist installs.
398
- */
399
- export function applyPatch(install) {
400
- return install.kind === "source"
401
- ? applySourcePatch(install.dir)
402
- : applyDistPatch(install.dir);
403
- }
404
- // ---------------------------------------------------------------------------
405
- // Check if patch is applied
406
- // ---------------------------------------------------------------------------
407
- /**
408
- * Check if the credential resolution patch is applied in an OpenClaw installation.
409
- */
410
- export function isPatchApplied(install) {
411
- if (install.kind === "source") {
412
- const file = path.join(install.dir, "src", "agents", "model-auth.ts");
413
- if (!existsSync(file))
414
- return false;
415
- return readFileSync(file, "utf-8").includes(PATCH_MARKER);
416
- }
417
- const chunkPath = findDistChunk(path.join(install.dir, "dist"));
418
- if (!chunkPath)
419
- return false;
420
- return readFileSync(chunkPath, "utf-8").includes(PATCH_MARKER);
421
- }
422
- //# sourceMappingURL=auto-patch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"auto-patch.js","sourceRoot":"","sources":["../src/auto-patch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,E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OAAO,CAAC,IAAI,KAAK,QAAQ;QAC9B,CAAC,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,CAAC;QAC/B,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;AAClC,CAAC;AAED,8EAA8E;AAC9E,4BAA4B;AAC5B,8EAA8E;AAE9E;;GAEG;AACH,MAAM,UAAU,cAAc,CAAC,OAAwB;IACrD,IAAI,OAAO,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,eAAe,CAAC,CAAC;QACtE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,KAAK,CAAC;QACpC,OAAO,YAAY,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;IAC5D,CAAC;IAED,MAAM,SAAS,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC;IAChE,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,YAAY,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,QAAQ,CAAC,YAAY,CAAC,CAAC;AACjE,CAAC"}
@@ -1,41 +0,0 @@
1
- /**
2
- * OpenClaw config file discovery and merge utilities.
3
- *
4
- * Reimplements OpenClaw's config path resolution logic since we can't
5
- * import from the openclaw package (we're a plugin, not a dependency).
6
- *
7
- * Resolution order (matches OpenClaw's src/config/paths.ts):
8
- * 1. $OPENCLAW_CONFIG_PATH / $CLAWDBOT_CONFIG_PATH (explicit override)
9
- * 2. $OPENCLAW_STATE_DIR/openclaw.json
10
- * 3. ~/.openclaw/openclaw.json (preferred)
11
- * 4. Legacy: ~/.openclaw/clawdbot.json, ~/.clawdbot/, ~/.moltbot/, ~/.moldbot/
12
- * 5. Return null — caller must ask the user
13
- */
14
- /**
15
- * Find an existing OpenClaw config file.
16
- *
17
- * Returns the absolute path to the first existing config file found,
18
- * or `null` if no config file exists anywhere. The caller should prompt
19
- * the user rather than silently creating a default file.
20
- */
21
- export declare function resolveOpenClawConfigPath(env?: NodeJS.ProcessEnv): string | null;
22
- /**
23
- * Return the canonical default config path (for prompting the user).
24
- */
25
- export declare function defaultConfigPath(): string;
26
- /**
27
- * Read an existing config file. Returns `{}` if the file doesn't exist.
28
- * Throws on parse errors so the caller can warn the user.
29
- */
30
- export declare function readExistingConfig(configPath: string): Record<string, unknown>;
31
- /**
32
- * Deep-merge the AgentHiFive plugin config into an existing OpenClaw config.
33
- *
34
- * - Sets `plugins.enabled = true`
35
- * - Adds `"agenthifive"` to `plugins.allow` (deduped)
36
- * - Adds `"@agenthifive/openclaw"` to `plugins.load.paths` (deduped)
37
- * - Replaces `plugins.entries.agenthifive` entirely
38
- * - Preserves ALL other keys untouched
39
- */
40
- export declare function mergePluginConfig(existing: Record<string, unknown>, pluginBlock: Record<string, unknown>): Record<string, unknown>;
41
- //# sourceMappingURL=config-discovery.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-discovery.d.ts","sourceRoot":"","sources":["../src/config-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAiDH;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CACvC,GAAG,GAAE,MAAM,CAAC,UAAwB,GACnC,MAAM,GAAG,IAAI,CAgCf;AAED;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAMD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,UAAU,EAAE,MAAM,GACjB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAiBzB;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACjC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACnC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAyCzB"}
@@ -1,161 +0,0 @@
1
- /**
2
- * OpenClaw config file discovery and merge utilities.
3
- *
4
- * Reimplements OpenClaw's config path resolution logic since we can't
5
- * import from the openclaw package (we're a plugin, not a dependency).
6
- *
7
- * Resolution order (matches OpenClaw's src/config/paths.ts):
8
- * 1. $OPENCLAW_CONFIG_PATH / $CLAWDBOT_CONFIG_PATH (explicit override)
9
- * 2. $OPENCLAW_STATE_DIR/openclaw.json
10
- * 3. ~/.openclaw/openclaw.json (preferred)
11
- * 4. Legacy: ~/.openclaw/clawdbot.json, ~/.clawdbot/, ~/.moltbot/, ~/.moldbot/
12
- * 5. Return null — caller must ask the user
13
- */
14
- import { existsSync, readFileSync } from "node:fs";
15
- import os from "node:os";
16
- import path from "node:path";
17
- // ---------------------------------------------------------------------------
18
- // Constants
19
- // ---------------------------------------------------------------------------
20
- const STATE_DIRNAMES = [".openclaw", ".clawdbot", ".moltbot", ".moldbot"];
21
- const CONFIG_FILENAMES = [
22
- "openclaw.json",
23
- "clawdbot.json",
24
- "moltbot.json",
25
- "moldbot.json",
26
- ];
27
- // ---------------------------------------------------------------------------
28
- // Home directory resolution (cross-platform)
29
- // ---------------------------------------------------------------------------
30
- function resolveHome() {
31
- // Match OpenClaw's home-dir.ts: OPENCLAW_HOME → HOME → USERPROFILE → os.homedir()
32
- const explicit = process.env.OPENCLAW_HOME?.trim();
33
- if (explicit && !explicit.startsWith("~"))
34
- return path.resolve(explicit);
35
- const home = process.env.HOME?.trim() ||
36
- process.env.USERPROFILE?.trim() ||
37
- os.homedir();
38
- if (explicit) {
39
- // OPENCLAW_HOME starts with ~ — expand it
40
- return path.resolve(explicit.replace(/^~(?=$|[/\\])/, home));
41
- }
42
- return home;
43
- }
44
- function expandTilde(p) {
45
- if (!p.startsWith("~"))
46
- return path.resolve(p);
47
- return path.resolve(p.replace(/^~(?=$|[/\\])/, resolveHome()));
48
- }
49
- // ---------------------------------------------------------------------------
50
- // Config path resolution
51
- // ---------------------------------------------------------------------------
52
- /**
53
- * Find an existing OpenClaw config file.
54
- *
55
- * Returns the absolute path to the first existing config file found,
56
- * or `null` if no config file exists anywhere. The caller should prompt
57
- * the user rather than silently creating a default file.
58
- */
59
- export function resolveOpenClawConfigPath(env = process.env) {
60
- // 1. Explicit override
61
- const explicit = env.OPENCLAW_CONFIG_PATH?.trim() || env.CLAWDBOT_CONFIG_PATH?.trim();
62
- if (explicit) {
63
- const resolved = expandTilde(explicit);
64
- return existsSync(resolved) ? resolved : null;
65
- }
66
- // 2. State dir override
67
- const stateDir = env.OPENCLAW_STATE_DIR?.trim() || env.CLAWDBOT_STATE_DIR?.trim();
68
- if (stateDir) {
69
- const resolved = expandTilde(stateDir);
70
- for (const name of CONFIG_FILENAMES) {
71
- const candidate = path.join(resolved, name);
72
- if (existsSync(candidate))
73
- return candidate;
74
- }
75
- return null;
76
- }
77
- // 3. Default dirs × config filenames
78
- const home = resolveHome();
79
- for (const dir of STATE_DIRNAMES) {
80
- for (const name of CONFIG_FILENAMES) {
81
- const candidate = path.join(home, dir, name);
82
- if (existsSync(candidate))
83
- return candidate;
84
- }
85
- }
86
- // 4. Not found — caller should ask the user
87
- return null;
88
- }
89
- /**
90
- * Return the canonical default config path (for prompting the user).
91
- */
92
- export function defaultConfigPath() {
93
- return path.join(resolveHome(), ".openclaw", "openclaw.json");
94
- }
95
- // ---------------------------------------------------------------------------
96
- // Config read / merge / write helpers
97
- // ---------------------------------------------------------------------------
98
- /**
99
- * Read an existing config file. Returns `{}` if the file doesn't exist.
100
- * Throws on parse errors so the caller can warn the user.
101
- */
102
- export function readExistingConfig(configPath) {
103
- if (!existsSync(configPath))
104
- return {};
105
- const raw = readFileSync(configPath, "utf-8").trim();
106
- if (!raw)
107
- return {};
108
- // Try standard JSON first (most configs are valid JSON)
109
- try {
110
- return JSON.parse(raw);
111
- }
112
- catch {
113
- // Try stripping single-line comments and trailing commas (light JSON5 compat)
114
- const cleaned = raw
115
- .replace(/\/\/.*$/gm, "") // strip // comments
116
- .replace(/\/\*[\s\S]*?\*\//g, "") // strip /* */ comments
117
- .replace(/,(\s*[}\]])/g, "$1"); // strip trailing commas
118
- return JSON.parse(cleaned);
119
- }
120
- }
121
- /**
122
- * Deep-merge the AgentHiFive plugin config into an existing OpenClaw config.
123
- *
124
- * - Sets `plugins.enabled = true`
125
- * - Adds `"agenthifive"` to `plugins.allow` (deduped)
126
- * - Adds `"@agenthifive/openclaw"` to `plugins.load.paths` (deduped)
127
- * - Replaces `plugins.entries.agenthifive` entirely
128
- * - Preserves ALL other keys untouched
129
- */
130
- export function mergePluginConfig(existing, pluginBlock) {
131
- const result = { ...existing };
132
- // Extract our plugin config from the block buildConfigOutput() produces
133
- const srcPlugins = pluginBlock.plugins;
134
- const srcEntries = srcPlugins.entries ?? {};
135
- // Build merged plugins object
136
- const plugins = {
137
- ...(result.plugins ?? {}),
138
- };
139
- plugins.enabled = true;
140
- // Merge allow list
141
- const allow = new Set(plugins.allow ?? []);
142
- allow.add("agenthifive");
143
- plugins.allow = [...allow];
144
- // Merge load paths
145
- const load = {
146
- ...(plugins.load ?? {}),
147
- };
148
- const paths = new Set(load.paths ?? []);
149
- paths.add("@agenthifive/openclaw");
150
- load.paths = [...paths];
151
- plugins.load = load;
152
- // Replace agenthifive entry entirely (fresh bootstrap replaces old)
153
- const entries = {
154
- ...(plugins.entries ?? {}),
155
- };
156
- entries.agenthifive = srcEntries.agenthifive;
157
- plugins.entries = entries;
158
- result.plugins = plugins;
159
- return result;
160
- }
161
- //# sourceMappingURL=config-discovery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-discovery.js","sourceRoot":"","sources":["../src/config-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MA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