Skip to content

Commit 609b020

Browse files
committed
refactor(openclaw-plugins): keep metamask/daemon.ts byte-identical to discovery/daemon.ts
Both OpenClaw plugins kept a near-identical copy of the daemon caller; the discovery version added optional ocapHome support, so a future fix in one copy would drift from the other. Sync the two files (metamask now accepts the same optional ocapHome param, even though it does not use it today) and add a header note instructing future editors to keep them in sync. Plugins remain self-contained so 'openclaw plugins install -l' still works on either directory in isolation.
1 parent e359bf4 commit 609b020

2 files changed

Lines changed: 26 additions & 9 deletions

File tree

packages/agentmask/openclaw-plugin-discovery/daemon.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
2-
* Daemon communication layer for the OpenClaw discovery plugin.
2+
* Daemon communication layer shared by the OpenClaw plugins in this
3+
* monorepo. Spawns `ocap daemon redeem-url` and `ocap daemon queueMessage`
4+
* commands and returns parsed results.
35
*
4-
* Spawns `ocap daemon redeem-url` and `ocap daemon queueMessage` commands
5-
* and returns parsed results.
6+
* NOTE: this file is duplicated byte-for-byte in
7+
* `packages/agentmask/openclaw-plugin-metamask/daemon.ts` so each plugin
8+
* stays installable on its own via `openclaw plugins install -l`. Any
9+
* change here must be mirrored there; please keep them in sync.
610
*/
711
import { spawn } from 'node:child_process';
812

packages/agentmask/openclaw-plugin-metamask/daemon.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
/**
2-
* Daemon communication layer for the OpenClaw MetaMask plugin.
2+
* Daemon communication layer shared by the OpenClaw plugins in this
3+
* monorepo. Spawns `ocap daemon redeem-url` and `ocap daemon queueMessage`
4+
* commands and returns parsed results.
35
*
4-
* Spawns `ocap daemon redeem-url` and `ocap daemon queueMessage` commands
5-
* and returns parsed results.
6+
* NOTE: this file is duplicated byte-for-byte in
7+
* `packages/agentmask/openclaw-plugin-metamask/daemon.ts` so each plugin
8+
* stays installable on its own via `openclaw plugins install -l`. Any
9+
* change here must be mirrored there; please keep them in sync.
610
*/
711
import { spawn } from 'node:child_process';
812

@@ -88,24 +92,32 @@ export type DaemonCaller = {
8892
};
8993

9094
/**
91-
* Create a daemon caller bound to CLI path and timeout.
95+
* Create a daemon caller bound to CLI path, ocap home, and timeout.
9296
*
9397
* @param options - Daemon connection options.
9498
* @param options.cliPath - Path to the ocap CLI.
99+
* @param options.ocapHome - Optional `--home` directory passed to every
100+
* spawned `ocap` invocation. Use a distinct home (e.g.,
101+
* `~/.ocap-consumer`) to address a daemon other than the default
102+
* `~/.ocap`.
95103
* @param options.timeoutMs - Default timeout in ms.
96104
* @returns A daemon caller with `redeemUrl` and `queueMessage` methods.
97105
*/
98106
export function makeDaemonCaller(options: {
99107
cliPath: string;
108+
ocapHome?: string;
100109
timeoutMs: number;
101110
}): DaemonCaller {
102-
const { cliPath, timeoutMs } = options;
111+
const { cliPath, ocapHome, timeoutMs } = options;
112+
113+
const homeArgs: string[] =
114+
ocapHome && ocapHome.length > 0 ? ['--home', ocapHome] : [];
103115

104116
return {
105117
async redeemUrl(url: string): Promise<string> {
106118
const result = await spawnCli({
107119
cliPath,
108-
args: ['daemon', 'redeem-url', url],
120+
args: [...homeArgs, 'daemon', 'redeem-url', url],
109121
timeoutMs,
110122
});
111123
throwOnFailure('redeem-url', result);
@@ -134,6 +146,7 @@ export function makeDaemonCaller(options: {
134146
}): Promise<unknown> {
135147
const args = msgOptions.args ?? [];
136148
const cliArgs = [
149+
...homeArgs,
137150
'daemon',
138151
'queueMessage',
139152
msgOptions.target,

0 commit comments

Comments
 (0)