@reefclaw/openclaw-plugin 0.1.39 → 0.1.41
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/.gitignore +1 -0
- package/bridge/provider.d.ts +2 -0
- package/bridge/providers/connector-update-direct.d.ts +79 -0
- package/bridge/providers/connector-update-direct.js +311 -0
- package/bridge/providers/connector-update.d.ts +6 -0
- package/bridge/providers/connector-update.js +7 -1
- package/bridge/providers/gateway.d.ts +5 -0
- package/bridge/providers/gateway.js +40 -0
- package/bridge/providers/onboarding-commands.d.ts +3 -0
- package/connector-supervisor.js +17 -6
- package/index.js +55 -15
- package/lifecycle/process-role.d.ts +27 -0
- package/lifecycle/process-role.js +99 -0
- package/live/stop-watcher.d.ts +12 -0
- package/live/stop-watcher.js +24 -0
- package/openclaw.plugin.json +1 -1
- package/package.json +1 -1
- package/plugin-integrity.d.ts +5 -2
- package/plugin-integrity.js +4 -1
- package/release-integrity.json +12 -0
- package/release-notes.json +3 -1
- package/skills/reefclaw/SKILL.md +1 -1
- package/tools/set-exchange-credentials.d.ts +4 -0
- package/tools/set-exchange-credentials.js +57 -10
package/.gitignore
CHANGED
package/bridge/provider.d.ts
CHANGED
|
@@ -186,6 +186,8 @@ export interface OpenClawProvider {
|
|
|
186
186
|
requiresVenueSwitchConfirm?: boolean;
|
|
187
187
|
currentVenue?: string;
|
|
188
188
|
currentMode?: string;
|
|
189
|
+
/** False = keyless (paper-only) venue activation. */
|
|
190
|
+
credentialsStored?: boolean;
|
|
189
191
|
}>;
|
|
190
192
|
/** Operator-only: verify exchange credentials with transient read-only
|
|
191
193
|
* calls, per venue. Nothing is persisted. */
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
2
|
+
import { type ConnectorUpdateOutcome, type TerminalRpc } from './connector-update.js';
|
|
3
|
+
/** The installer flag that selects the files-only mode (installer/src/files-only.ts). */
|
|
4
|
+
export declare const FILES_ONLY_FLAG = "--files-only";
|
|
5
|
+
/**
|
|
6
|
+
* ★ The first connector release whose installer understands `--files-only`.
|
|
7
|
+
* An OLDER installer ignores unknown flags and runs the FULL install — the
|
|
8
|
+
* `openclaw` CLI inside the container, the double plugin stack — so the
|
|
9
|
+
* direct path refuses to run anything older, whatever the release endpoint
|
|
10
|
+
* says. Bump only when a release before it could never be pinned again.
|
|
11
|
+
*/
|
|
12
|
+
export declare const FILES_ONLY_MIN_CONNECT_VERSION = "0.1.53";
|
|
13
|
+
export declare function compareExactVersions(a: string, b: string): number;
|
|
14
|
+
/** True when `version` (exact) has a files-only installer. */
|
|
15
|
+
export declare function supportsFilesOnly(version: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* The ONE argument vector this path can ever run. The only variable is an
|
|
18
|
+
* exact version, validated before it is placed; anything else throws.
|
|
19
|
+
*/
|
|
20
|
+
export declare function directUpdateArgs(version: string): string[];
|
|
21
|
+
/**
|
|
22
|
+
* Where npx is. Preferred: next to the node binary running this process
|
|
23
|
+
* (`process.execPath`) — every standard install (official Docker image, nvm,
|
|
24
|
+
* nodesource, Homebrew) puts `npx` beside `node`, and it is the node the
|
|
25
|
+
* gateway itself runs on, so the installer's Node floor is met by
|
|
26
|
+
* construction. Fallback: `npx` on PATH. Pure (injected `exists`).
|
|
27
|
+
*/
|
|
28
|
+
export declare function resolveNpx(execPath?: string, platform?: NodeJS.Platform, exists?: (p: string) => boolean): string;
|
|
29
|
+
/** PATH for the child: the node binary's directory first, so the installer's
|
|
30
|
+
* own `npm install` children resolve the same node/npm/npx this process runs
|
|
31
|
+
* on even under a service manager whose PATH omits it (nvm under systemd). */
|
|
32
|
+
export declare function childPath(execPath: string, basePath: string | undefined, platform?: NodeJS.Platform): string;
|
|
33
|
+
/** What the bridge can see of its surroundings — read once, judged by the
|
|
34
|
+
* pure `isInsideContainer`. Mirrors installer/src/gateway-restart.ts
|
|
35
|
+
* (readContainerProbe / detectContainer) without the host-command parts. */
|
|
36
|
+
export interface ContainerProbe {
|
|
37
|
+
/** `/.dockerenv` exists (Docker creates it in every container). */
|
|
38
|
+
dockerEnv: boolean;
|
|
39
|
+
/** Contents of /proc/1/cgroup, '' when unreadable. */
|
|
40
|
+
cgroup: string;
|
|
41
|
+
env: NodeJS.ProcessEnv;
|
|
42
|
+
}
|
|
43
|
+
export declare function readContainerProbe(): ContainerProbe;
|
|
44
|
+
/**
|
|
45
|
+
* A host-restartable container (Docker / Podman / Kubernetes) — where the PTY
|
|
46
|
+
* path would run the full installer, and with it the `openclaw` CLI, INSIDE
|
|
47
|
+
* the live gateway. System containers with their own init (LXC, nspawn) are
|
|
48
|
+
* ordinary boxes for this purpose. Pure.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isInsideContainer(probe: ContainerProbe): boolean;
|
|
51
|
+
/** Only ever this much of the installer's output is kept (the tail), so a
|
|
52
|
+
* chatty npm cannot grow the bridge's memory or the relay frames. */
|
|
53
|
+
export declare const MAX_OUTPUT_BYTES: number;
|
|
54
|
+
export declare function appendTail(buffer: string, chunk: string, max?: number): string;
|
|
55
|
+
export interface DirectRunDeps {
|
|
56
|
+
/** Injected for tests. */
|
|
57
|
+
spawn?: typeof nodeSpawn;
|
|
58
|
+
/** Injected for tests; defaults to resolveNpx(). */
|
|
59
|
+
npx?: string;
|
|
60
|
+
env?: NodeJS.ProcessEnv;
|
|
61
|
+
cwd?: string;
|
|
62
|
+
/** Hard cap on the installer's run; it is killed past it. */
|
|
63
|
+
timeoutMs?: number;
|
|
64
|
+
/** Minimum gap between two progress frames to the dashboard. */
|
|
65
|
+
emitThrottleMs?: number;
|
|
66
|
+
now?: () => number;
|
|
67
|
+
setTimer?: typeof setTimeout;
|
|
68
|
+
clearTimer?: typeof clearTimeout;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Run the installer directly and finish the job: files placed → ask the
|
|
72
|
+
* gateway to restart itself. Resolves with the final outcome; `emit` receives
|
|
73
|
+
* every intermediate one (started + progress), exactly like runConnectorUpdate.
|
|
74
|
+
*
|
|
75
|
+
* `rpc` is the operator.admin session the caller already opened (the restart
|
|
76
|
+
* RPC needs that scope). The position guard and the per-host opt-out have
|
|
77
|
+
* been applied by the caller.
|
|
78
|
+
*/
|
|
79
|
+
export declare function runDirectConnectorUpdate(rpc: TerminalRpc, version: string, emit: (outcome: ConnectorUpdateOutcome) => void, deps?: DirectRunDeps): Promise<ConnectorUpdateOutcome>;
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
// Direct connector update: the bridge runs the installer ITSELF, as its own
|
|
2
|
+
// child process, instead of typing it into a gateway PTY.
|
|
3
|
+
//
|
|
4
|
+
// WHY THIS EXISTS: the PTY path (connector-update.ts) needs the gateway's
|
|
5
|
+
// `terminal.*` RPC family, which OpenClaw < 2026.7 does not have at all — the
|
|
6
|
+
// rig (OpenClaw 2026.6.9 in Docker) answered every dashboard click with
|
|
7
|
+
// `unknown method: terminal.open` and could only be updated by hand
|
|
8
|
+
// (2026-09-20, 2026-09-21). The bridge does not need the gateway's shell: it
|
|
9
|
+
// is spawned BY the gateway (plugin/src/connector-supervisor.ts), so it
|
|
10
|
+
// already runs as the gateway's user, with the gateway's environment and the
|
|
11
|
+
// gateway's own node binary. A child process of the bridge is exactly the
|
|
12
|
+
// process a PTY would have given us, minus the PTY.
|
|
13
|
+
//
|
|
14
|
+
// Two further reasons this is the path of choice inside a container:
|
|
15
|
+
// - the installer is run with `--files-only`, which NEVER executes the
|
|
16
|
+
// `openclaw` CLI — inside a live gateway container every CLI invocation
|
|
17
|
+
// boots a second plugin stack against the same state files and relay
|
|
18
|
+
// room (2026-07-27, 2026-09-19, 2026-09-20 with a live book open);
|
|
19
|
+
// - the restart is the gateway's own `update.run` self-restart
|
|
20
|
+
// (requestGatewayRestart), the one restart that reloads code in a
|
|
21
|
+
// container (OpenClaw respawns the process and exits; the container
|
|
22
|
+
// supervisor brings the new one up) and exits into Restart=always under
|
|
23
|
+
// systemd.
|
|
24
|
+
//
|
|
25
|
+
// ★★ SECURITY — the same rule as connector-update.ts, restated for this file:
|
|
26
|
+
// the command is a FIXED CONSTANT. The executable is npx (resolved next to the
|
|
27
|
+
// node binary running this process, else on PATH), the argument vector is
|
|
28
|
+
// `-y @reefclaw/connect@<exact version> --files-only`, built by
|
|
29
|
+
// `directUpdateArgs` from a MAJOR.MINOR.PATCH version that has exactly one
|
|
30
|
+
// source (ReefClaw's public release endpoint). No shell is involved
|
|
31
|
+
// (`shell: false`), nothing from the browser, relay, agent or config reaches
|
|
32
|
+
// the argv, and no secret is placed on it. The RPC that reaches this module
|
|
33
|
+
// carries NO command field.
|
|
34
|
+
import { spawn as nodeSpawn } from 'node:child_process';
|
|
35
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
36
|
+
import { homedir } from 'node:os';
|
|
37
|
+
import { posix, win32 } from 'node:path';
|
|
38
|
+
import { logger } from '../logger.js';
|
|
39
|
+
import { CONNECT_PACKAGE, INSTALLER_NOT_RESTARTED_MARKER, RESTART_REASON_AFTER_UPDATE, installerReportedNoRestart, isExactConnectVersion, manualUpdateHint, requestGatewayRestart, } from './connector-update.js';
|
|
40
|
+
const TAG = 'connector-update';
|
|
41
|
+
/** The installer flag that selects the files-only mode (installer/src/files-only.ts). */
|
|
42
|
+
export const FILES_ONLY_FLAG = '--files-only';
|
|
43
|
+
/**
|
|
44
|
+
* ★ The first connector release whose installer understands `--files-only`.
|
|
45
|
+
* An OLDER installer ignores unknown flags and runs the FULL install — the
|
|
46
|
+
* `openclaw` CLI inside the container, the double plugin stack — so the
|
|
47
|
+
* direct path refuses to run anything older, whatever the release endpoint
|
|
48
|
+
* says. Bump only when a release before it could never be pinned again.
|
|
49
|
+
*/
|
|
50
|
+
export const FILES_ONLY_MIN_CONNECT_VERSION = '0.1.53';
|
|
51
|
+
export function compareExactVersions(a, b) {
|
|
52
|
+
const pa = a.split('.').map(Number);
|
|
53
|
+
const pb = b.split('.').map(Number);
|
|
54
|
+
for (let i = 0; i < 3; i += 1) {
|
|
55
|
+
if (pa[i] !== pb[i])
|
|
56
|
+
return pa[i] < pb[i] ? -1 : 1;
|
|
57
|
+
}
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
/** True when `version` (exact) has a files-only installer. */
|
|
61
|
+
export function supportsFilesOnly(version) {
|
|
62
|
+
return isExactConnectVersion(version) && compareExactVersions(version, FILES_ONLY_MIN_CONNECT_VERSION) >= 0;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The ONE argument vector this path can ever run. The only variable is an
|
|
66
|
+
* exact version, validated before it is placed; anything else throws.
|
|
67
|
+
*/
|
|
68
|
+
export function directUpdateArgs(version) {
|
|
69
|
+
if (!isExactConnectVersion(version)) {
|
|
70
|
+
throw new Error(`refusing to build an update command for a non-exact version: ${JSON.stringify(version)}`);
|
|
71
|
+
}
|
|
72
|
+
return ['-y', `${CONNECT_PACKAGE}@${version}`, FILES_ONLY_FLAG];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Where npx is. Preferred: next to the node binary running this process
|
|
76
|
+
* (`process.execPath`) — every standard install (official Docker image, nvm,
|
|
77
|
+
* nodesource, Homebrew) puts `npx` beside `node`, and it is the node the
|
|
78
|
+
* gateway itself runs on, so the installer's Node floor is met by
|
|
79
|
+
* construction. Fallback: `npx` on PATH. Pure (injected `exists`).
|
|
80
|
+
*/
|
|
81
|
+
export function resolveNpx(execPath = process.execPath, platform = process.platform, exists = existsSync) {
|
|
82
|
+
const path = platform === 'win32' ? win32 : posix;
|
|
83
|
+
const name = platform === 'win32' ? 'npx.cmd' : 'npx';
|
|
84
|
+
const beside = path.join(path.dirname(execPath), name);
|
|
85
|
+
return exists(beside) ? beside : name;
|
|
86
|
+
}
|
|
87
|
+
/** PATH for the child: the node binary's directory first, so the installer's
|
|
88
|
+
* own `npm install` children resolve the same node/npm/npx this process runs
|
|
89
|
+
* on even under a service manager whose PATH omits it (nvm under systemd). */
|
|
90
|
+
export function childPath(execPath, basePath, platform = process.platform) {
|
|
91
|
+
const path = platform === 'win32' ? win32 : posix;
|
|
92
|
+
const bin = path.dirname(execPath);
|
|
93
|
+
const rest = (basePath ?? '').split(path.delimiter).filter((p) => p.length > 0 && p !== bin);
|
|
94
|
+
return [bin, ...rest].join(path.delimiter);
|
|
95
|
+
}
|
|
96
|
+
export function readContainerProbe() {
|
|
97
|
+
let cgroup = '';
|
|
98
|
+
try {
|
|
99
|
+
cgroup = readFileSync('/proc/1/cgroup', 'utf-8');
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
/* not Linux, or unreadable — the other tells decide */
|
|
103
|
+
}
|
|
104
|
+
return { dockerEnv: existsSync('/.dockerenv'), cgroup, env: process.env };
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* A host-restartable container (Docker / Podman / Kubernetes) — where the PTY
|
|
108
|
+
* path would run the full installer, and with it the `openclaw` CLI, INSIDE
|
|
109
|
+
* the live gateway. System containers with their own init (LXC, nspawn) are
|
|
110
|
+
* ordinary boxes for this purpose. Pure.
|
|
111
|
+
*/
|
|
112
|
+
export function isInsideContainer(probe) {
|
|
113
|
+
const c = (probe.env.container ?? '').trim().toLowerCase();
|
|
114
|
+
if (c === 'lxc' || c === 'systemd-nspawn' || c === 'lxc-libvirt')
|
|
115
|
+
return false;
|
|
116
|
+
const hinted = (probe.env.OPENCLAW_CONTAINER_HINT?.trim() || probe.env.OPENCLAW_CONTAINER?.trim() || '').length > 0;
|
|
117
|
+
return (hinted ||
|
|
118
|
+
probe.dockerEnv ||
|
|
119
|
+
c === 'docker' ||
|
|
120
|
+
c === 'podman' ||
|
|
121
|
+
/\b(docker|containerd|kubepods|libpod|podman)\b/.test(probe.cgroup));
|
|
122
|
+
}
|
|
123
|
+
/** Only ever this much of the installer's output is kept (the tail), so a
|
|
124
|
+
* chatty npm cannot grow the bridge's memory or the relay frames. */
|
|
125
|
+
export const MAX_OUTPUT_BYTES = 64 * 1024;
|
|
126
|
+
export function appendTail(buffer, chunk, max = MAX_OUTPUT_BYTES) {
|
|
127
|
+
const next = buffer + chunk;
|
|
128
|
+
return next.length > max ? next.slice(next.length - max) : next;
|
|
129
|
+
}
|
|
130
|
+
/** The message the PTY path uses for the same verdict — kept identical so the
|
|
131
|
+
* dashboard copy does not depend on which path ran. */
|
|
132
|
+
function notRestartedOutcome(exitCode, output, refused) {
|
|
133
|
+
return {
|
|
134
|
+
ok: true,
|
|
135
|
+
status: 'completed',
|
|
136
|
+
exitCode,
|
|
137
|
+
output,
|
|
138
|
+
restartRequired: true,
|
|
139
|
+
message: 'Connector files updated, but the gateway was NOT restarted, so the previous version is still running. '
|
|
140
|
+
+ 'If OpenClaw runs in Docker, restart the container from the host machine (docker restart <container>); '
|
|
141
|
+
+ `otherwise restart OpenClaw. The new version loads then. (Self-restart refused: ${refused.message})`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Run the installer directly and finish the job: files placed → ask the
|
|
146
|
+
* gateway to restart itself. Resolves with the final outcome; `emit` receives
|
|
147
|
+
* every intermediate one (started + progress), exactly like runConnectorUpdate.
|
|
148
|
+
*
|
|
149
|
+
* `rpc` is the operator.admin session the caller already opened (the restart
|
|
150
|
+
* RPC needs that scope). The position guard and the per-host opt-out have
|
|
151
|
+
* been applied by the caller.
|
|
152
|
+
*/
|
|
153
|
+
export async function runDirectConnectorUpdate(rpc, version, emit, deps = {}) {
|
|
154
|
+
if (!supportsFilesOnly(version)) {
|
|
155
|
+
// Not a retryable condition on this box: the release endpoint pins an
|
|
156
|
+
// installer that would run the full install here. Refuse, say why.
|
|
157
|
+
const outcome = {
|
|
158
|
+
ok: false,
|
|
159
|
+
status: 'blocked',
|
|
160
|
+
message: `The pinned connector release (${version}) predates files-only updates (${FILES_ONLY_MIN_CONNECT_VERSION}), `
|
|
161
|
+
+ `which this box needs, so the update was not started. ${manualUpdateHint(version)}.`,
|
|
162
|
+
};
|
|
163
|
+
logger.warn(TAG, outcome.message);
|
|
164
|
+
return outcome;
|
|
165
|
+
}
|
|
166
|
+
const spawn = deps.spawn ?? nodeSpawn;
|
|
167
|
+
const npx = deps.npx ?? resolveNpx();
|
|
168
|
+
const args = directUpdateArgs(version);
|
|
169
|
+
const timeoutMs = deps.timeoutMs ?? 10 * 60_000;
|
|
170
|
+
const throttleMs = deps.emitThrottleMs ?? 750;
|
|
171
|
+
const now = deps.now ?? Date.now;
|
|
172
|
+
const setTimer = deps.setTimer ?? setTimeout;
|
|
173
|
+
const clearTimer = deps.clearTimer ?? clearTimeout;
|
|
174
|
+
const baseEnv = deps.env ?? process.env;
|
|
175
|
+
const env = { ...baseEnv, PATH: childPath(process.execPath, baseEnv.PATH) };
|
|
176
|
+
const cwd = deps.cwd ?? homedir();
|
|
177
|
+
logger.info(TAG, `direct update: ${npx} ${args.join(' ')} (cwd=${cwd})`);
|
|
178
|
+
let child;
|
|
179
|
+
try {
|
|
180
|
+
child = spawn(npx, args, { cwd, env, stdio: ['ignore', 'pipe', 'pipe'], shell: false });
|
|
181
|
+
}
|
|
182
|
+
catch (err) {
|
|
183
|
+
const reason = err instanceof Error ? err.message : String(err);
|
|
184
|
+
const outcome = {
|
|
185
|
+
ok: false,
|
|
186
|
+
status: 'failed',
|
|
187
|
+
message: `Could not start the updater on the box (${reason}). ${manualUpdateHint(version)}.`,
|
|
188
|
+
};
|
|
189
|
+
logger.warn(TAG, outcome.message);
|
|
190
|
+
return outcome;
|
|
191
|
+
}
|
|
192
|
+
const started = {
|
|
193
|
+
ok: true,
|
|
194
|
+
status: 'started',
|
|
195
|
+
message: 'Update started on the box. The agent restarts when it finishes, so the dashboard will reconnect on its own.',
|
|
196
|
+
};
|
|
197
|
+
emit(started);
|
|
198
|
+
logger.info(TAG, `direct update started (pid ${child.pid ?? 'unknown'})`);
|
|
199
|
+
return new Promise((resolve) => {
|
|
200
|
+
let output = '';
|
|
201
|
+
// The first progress frame goes out at once; later ones are throttled.
|
|
202
|
+
let lastEmitAt = Number.NEGATIVE_INFINITY;
|
|
203
|
+
let pendingEmit = null;
|
|
204
|
+
let settled = false;
|
|
205
|
+
let timedOut = false;
|
|
206
|
+
const flushProgress = () => {
|
|
207
|
+
pendingEmit = null;
|
|
208
|
+
if (settled)
|
|
209
|
+
return;
|
|
210
|
+
lastEmitAt = now();
|
|
211
|
+
emit({ ok: true, status: 'started', output, message: 'Updating…' });
|
|
212
|
+
};
|
|
213
|
+
const onData = (chunk) => {
|
|
214
|
+
output = appendTail(output, chunk.toString());
|
|
215
|
+
if (settled)
|
|
216
|
+
return;
|
|
217
|
+
const due = lastEmitAt + throttleMs - now();
|
|
218
|
+
if (due <= 0)
|
|
219
|
+
flushProgress();
|
|
220
|
+
else if (!pendingEmit)
|
|
221
|
+
pendingEmit = setTimer(flushProgress, due);
|
|
222
|
+
};
|
|
223
|
+
child.stdout?.on('data', onData);
|
|
224
|
+
child.stderr?.on('data', onData);
|
|
225
|
+
const killTimer = setTimer(() => {
|
|
226
|
+
timedOut = true;
|
|
227
|
+
logger.warn(TAG, `direct update exceeded ${timeoutMs} ms — killing pid ${child.pid ?? 'unknown'}`);
|
|
228
|
+
try {
|
|
229
|
+
child.kill('SIGKILL');
|
|
230
|
+
}
|
|
231
|
+
catch {
|
|
232
|
+
/* already gone */
|
|
233
|
+
}
|
|
234
|
+
}, timeoutMs);
|
|
235
|
+
const settle = (outcome) => {
|
|
236
|
+
if (settled)
|
|
237
|
+
return;
|
|
238
|
+
settled = true;
|
|
239
|
+
clearTimer(killTimer);
|
|
240
|
+
if (pendingEmit)
|
|
241
|
+
clearTimer(pendingEmit);
|
|
242
|
+
emit(outcome);
|
|
243
|
+
resolve(outcome);
|
|
244
|
+
};
|
|
245
|
+
child.on('error', (err) => {
|
|
246
|
+
// ENOENT (no npx where we looked) arrives here, not from spawn().
|
|
247
|
+
settle({
|
|
248
|
+
ok: false,
|
|
249
|
+
status: 'failed',
|
|
250
|
+
output,
|
|
251
|
+
message: `Could not start the updater on the box (${err.message}). ${manualUpdateHint(version)}.`,
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
// 'exit' can precede the last stdout flush; the outcome is taken on 'close'.
|
|
255
|
+
child.on('close', (code, signal) => {
|
|
256
|
+
void (async () => {
|
|
257
|
+
if (timedOut) {
|
|
258
|
+
settle({
|
|
259
|
+
ok: false,
|
|
260
|
+
status: 'failed',
|
|
261
|
+
output,
|
|
262
|
+
message: 'The update did not finish in time and was stopped. Check the box directly before retrying.',
|
|
263
|
+
});
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (code !== 0) {
|
|
267
|
+
settle({
|
|
268
|
+
ok: false,
|
|
269
|
+
status: 'completed',
|
|
270
|
+
exitCode: code,
|
|
271
|
+
output,
|
|
272
|
+
message: code === null
|
|
273
|
+
? `The updater was interrupted${signal ? ` (${signal})` : ''}. The connector was left as it was.`
|
|
274
|
+
: `The updater exited with code ${code}. The connector was left as it was.`,
|
|
275
|
+
});
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
if (!installerReportedNoRestart(output)) {
|
|
279
|
+
// A files-only run always ends on the marker. Its absence means the
|
|
280
|
+
// installer did something else (an unexpected build) — do not guess
|
|
281
|
+
// that the files are in place, and do not restart on top of it.
|
|
282
|
+
settle({
|
|
283
|
+
ok: false,
|
|
284
|
+
status: 'failed',
|
|
285
|
+
exitCode: code,
|
|
286
|
+
output,
|
|
287
|
+
message: `The updater finished without the "${INSTALLER_NOT_RESTARTED_MARKER}" verdict a files-only update ends on, `
|
|
288
|
+
+ 'so it is not clear what it did. Check the plugin version on the dashboard in a few minutes; '
|
|
289
|
+
+ `if it did not change, ${manualUpdateHint(version)}.`,
|
|
290
|
+
});
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
// Files in place. Finish the job from here: the gateway restarts
|
|
294
|
+
// ITSELF (update.run — the reason that reloads code, see
|
|
295
|
+
// connector-update.ts RESTART_REASON_AFTER_UPDATE).
|
|
296
|
+
const kicked = await requestGatewayRestart(rpc, { reason: RESTART_REASON_AFTER_UPDATE });
|
|
297
|
+
if (kicked.status === 'restarting') {
|
|
298
|
+
settle({
|
|
299
|
+
ok: true,
|
|
300
|
+
status: 'restarting',
|
|
301
|
+
exitCode: code,
|
|
302
|
+
output,
|
|
303
|
+
message: `Connector files updated. ${kicked.message}`,
|
|
304
|
+
});
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
settle(notRestartedOutcome(code, output, kicked));
|
|
308
|
+
})();
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
}
|
|
@@ -68,6 +68,12 @@ export interface ConnectorUpdateOutcome {
|
|
|
68
68
|
* the gateway (its output carries INSTALLER_NOT_RESTARTED_MARKER) — the
|
|
69
69
|
* previous version is still running until the operator restarts it. */
|
|
70
70
|
restartRequired?: boolean;
|
|
71
|
+
/** A `blocked` verdict about the gateway's TERMINAL only (no terminal RPC,
|
|
72
|
+
* terminal disabled, sandboxed agent): the box itself can still be updated
|
|
73
|
+
* by the connector running the installer directly
|
|
74
|
+
* (connector-update-direct.ts). The provider falls through to that path;
|
|
75
|
+
* the verdict is not shown. */
|
|
76
|
+
directFallback?: true;
|
|
71
77
|
}
|
|
72
78
|
/**
|
|
73
79
|
* Map a gateway error from `terminal.open` onto an operator-readable outcome.
|
|
@@ -152,6 +152,7 @@ export function describeOpenFailure(err) {
|
|
|
152
152
|
return {
|
|
153
153
|
ok: false,
|
|
154
154
|
status: 'blocked',
|
|
155
|
+
directFallback: true,
|
|
155
156
|
message: 'This box has the OpenClaw terminal disabled, so ReefClaw cannot run the update for you. '
|
|
156
157
|
+ `Instead, ${manualUpdateHint()}.`,
|
|
157
158
|
};
|
|
@@ -160,6 +161,7 @@ export function describeOpenFailure(err) {
|
|
|
160
161
|
return {
|
|
161
162
|
ok: false,
|
|
162
163
|
status: 'blocked',
|
|
164
|
+
directFallback: true,
|
|
163
165
|
message: 'This agent runs in a sandbox, and OpenClaw does not support terminals inside one yet. '
|
|
164
166
|
+ `Instead, ${manualUpdateHint()}.`,
|
|
165
167
|
};
|
|
@@ -181,11 +183,15 @@ export function describeOpenFailure(err) {
|
|
|
181
183
|
// No terminal RPC at all: OpenClaw < 2026.7 has no `terminal.*` methods, so
|
|
182
184
|
// the gateway answers `unknown method: terminal.open`. That is a fact about
|
|
183
185
|
// the box's OpenClaw version, not a fault, and no retry / "Update anyway"
|
|
184
|
-
// changes it (the rig on 2026.6.9 looped on exactly this, 2026-09-20).
|
|
186
|
+
// changes it (the rig on 2026.6.9 looped on exactly this, 2026-09-20). The
|
|
187
|
+
// connector does not need the terminal, though: `directFallback` sends the
|
|
188
|
+
// provider down connector-update-direct.ts, and this copy is only what an
|
|
189
|
+
// older provider would have shown.
|
|
185
190
|
if (/unknown method/.test(lower)) {
|
|
186
191
|
return {
|
|
187
192
|
ok: false,
|
|
188
193
|
status: 'blocked',
|
|
194
|
+
directFallback: true,
|
|
189
195
|
message: 'This box runs an OpenClaw older than 2026.7, which has no terminal API, so ReefClaw cannot run the '
|
|
190
196
|
+ 'update for you. Upgrade OpenClaw to enable one-click updates; until then, paste the manual command '
|
|
191
197
|
+ `to your agent, or ${manualUpdateHint()}.`,
|
|
@@ -274,6 +274,11 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
274
274
|
updateConnector(args: {
|
|
275
275
|
acknowledgeOpenPositions?: boolean;
|
|
276
276
|
}): Promise<ConnectorUpdateOutcome>;
|
|
277
|
+
/** The direct (no-PTY) update. Resolves the RPC with the `started` frame as
|
|
278
|
+
* soon as the installer is running (or the refusal), streams the rest as
|
|
279
|
+
* connector_update events, and tears the admin session down at the end —
|
|
280
|
+
* the same contract as the PTY path. */
|
|
281
|
+
private runDirectUpdate;
|
|
277
282
|
/**
|
|
278
283
|
* Operator-triggered gateway self-restart through OpenClaw's own
|
|
279
284
|
* `gateway.restart.request` RPC. The one door on a Docker / unmanaged box:
|
|
@@ -20,6 +20,7 @@ import { assessDrawdownPlausibility, computeEquity as _computeEquity, computePos
|
|
|
20
20
|
import { executeKill as _executeKill, executeFlatten as _executeFlatten, executePause as _executePause, executeResume as _executeResume, cancelPendingProposals, withProposalDetail, } from './emergency-commands.js';
|
|
21
21
|
import { executeSetTradingMode, executeGetBracketConfig, executeSetBracketRequirement, executeSetExchangeCredentials, executeTestExchangeCredentials, executeClearExchangeCredentials, executeProvisionHlAgentWallet, executeHlAgentWalletStatus, executeSubmitHlAgentApproval, } from './onboarding-commands.js';
|
|
22
22
|
import { startConnectorUpdate, runConnectorUpdate, fetchPinnedConnectVersion, openAdminGatewaySession, checkPositionGuard, describeUpdateDisabled, requestGatewayRestart, RESTART_REASON_OPERATOR, } from './connector-update.js';
|
|
23
|
+
import { isInsideContainer, readContainerProbe, runDirectConnectorUpdate } from './connector-update-direct.js';
|
|
23
24
|
import { DEFAULT_AGENT_ID, isForeignAgentEvent, resolveAgentEventOwner } from '../gateway/agent-scope.js';
|
|
24
25
|
const TAG = 'gateway';
|
|
25
26
|
// ---- Day-start NAV persistence ----
|
|
@@ -815,7 +816,22 @@ export class GatewayProvider {
|
|
|
815
816
|
if (!session.ok)
|
|
816
817
|
return session.outcome;
|
|
817
818
|
const rpc = (method, params) => admin.sendRpc(method, params);
|
|
819
|
+
// Inside a container the PTY path is the wrong tool even where the
|
|
820
|
+
// terminal RPC exists: the full installer runs the `openclaw` CLI inside
|
|
821
|
+
// the live gateway (a second plugin stack) and cannot restart the
|
|
822
|
+
// container. The connector runs the files-only installer itself and has
|
|
823
|
+
// the gateway restart itself (connector-update-direct.ts).
|
|
824
|
+
if (isInsideContainer(readContainerProbe())) {
|
|
825
|
+
logger.info(TAG, 'connector.update: container detected — running the installer directly (files-only)');
|
|
826
|
+
return this.runDirectUpdate(rpc, pinned.version, admin);
|
|
827
|
+
}
|
|
818
828
|
const started = await startConnectorUpdate(rpc, guardArgs, pinned.version);
|
|
829
|
+
if (started.status === 'blocked' && started.directFallback) {
|
|
830
|
+
// The gateway has no usable terminal (OpenClaw < 2026.7, terminal
|
|
831
|
+
// disabled, sandboxed agent). The connector does not need one.
|
|
832
|
+
logger.info(TAG, `connector.update: no gateway terminal (${started.message}) — running the installer directly`);
|
|
833
|
+
return this.runDirectUpdate(rpc, pinned.version, admin);
|
|
834
|
+
}
|
|
819
835
|
if (started.status !== 'started' || !started.sessionId) {
|
|
820
836
|
admin.destroy();
|
|
821
837
|
return started;
|
|
@@ -828,6 +844,30 @@ export class GatewayProvider {
|
|
|
828
844
|
});
|
|
829
845
|
return started;
|
|
830
846
|
}
|
|
847
|
+
/** The direct (no-PTY) update. Resolves the RPC with the `started` frame as
|
|
848
|
+
* soon as the installer is running (or the refusal), streams the rest as
|
|
849
|
+
* connector_update events, and tears the admin session down at the end —
|
|
850
|
+
* the same contract as the PTY path. */
|
|
851
|
+
runDirectUpdate(rpc, version, admin) {
|
|
852
|
+
return new Promise((resolve) => {
|
|
853
|
+
let answered = false;
|
|
854
|
+
const answer = (outcome) => {
|
|
855
|
+
if (answered)
|
|
856
|
+
return;
|
|
857
|
+
answered = true;
|
|
858
|
+
resolve(outcome);
|
|
859
|
+
};
|
|
860
|
+
void runDirectConnectorUpdate(rpc, version, (outcome) => {
|
|
861
|
+
// The first frame (`started`) is the RPC reply; every frame, including
|
|
862
|
+
// that one, also goes out as an event so the dashboard's pane fills.
|
|
863
|
+
this.emitConnectorUpdate(outcome);
|
|
864
|
+
if (outcome.status === 'started')
|
|
865
|
+
answer(outcome);
|
|
866
|
+
})
|
|
867
|
+
.then((final) => answer(final))
|
|
868
|
+
.finally(() => admin.destroy());
|
|
869
|
+
});
|
|
870
|
+
}
|
|
831
871
|
/**
|
|
832
872
|
* Operator-triggered gateway self-restart through OpenClaw's own
|
|
833
873
|
* `gateway.restart.request` RPC. The one door on a Docker / unmanaged box:
|
|
@@ -26,6 +26,9 @@ export interface SetExchangeCredentialsOutcome {
|
|
|
26
26
|
requiresVenueSwitchConfirm?: boolean;
|
|
27
27
|
currentVenue?: string;
|
|
28
28
|
currentMode?: string;
|
|
29
|
+
/** False = keyless (paper-only) venue activation — the venue was selected
|
|
30
|
+
* with no credentials on disk (plugin ≥ 0.1.41). */
|
|
31
|
+
credentialsStored?: boolean;
|
|
29
32
|
}
|
|
30
33
|
export interface TestExchangeCredentialsOutcome {
|
|
31
34
|
ok: boolean;
|
package/connector-supervisor.js
CHANGED
|
@@ -19,6 +19,7 @@ import { homedir } from 'node:os';
|
|
|
19
19
|
import { join, dirname } from 'node:path';
|
|
20
20
|
import { fileURLToPath } from 'node:url';
|
|
21
21
|
import { logger } from './logger.js';
|
|
22
|
+
import { processRuntime } from './lifecycle/process-role.js';
|
|
22
23
|
const TAG = 'connector-supervisor';
|
|
23
24
|
/** Bridge bundled INSIDE the plugin package (the npm-channel distribution
|
|
24
25
|
* `@reefclaw/openclaw-plugin` ships the connector at <pluginRoot>/bridge).
|
|
@@ -50,15 +51,25 @@ const MIN_BACKOFF_MS = 5_000;
|
|
|
50
51
|
const MAX_BACKOFF_MS = 60_000;
|
|
51
52
|
/** A child that survives this long resets the backoff (it was healthy). */
|
|
52
53
|
const STABLE_RESET_MS = 5 * 60_000;
|
|
53
|
-
|
|
54
|
+
// Process-wide, not module-scoped: OpenClaw 2026.9.5+ can load the plugin as
|
|
55
|
+
// two module instances in one gateway, and a per-module singleton let each
|
|
56
|
+
// start its own connector — two bridges sharing one relay-instance-id, which
|
|
57
|
+
// the relay's same-instance rule turns into a 4010 eviction loop.
|
|
58
|
+
function getSingleton() {
|
|
59
|
+
return processRuntime().connectorSupervisor ?? null;
|
|
60
|
+
}
|
|
61
|
+
function setSingleton(h) {
|
|
62
|
+
processRuntime().connectorSupervisor = h;
|
|
63
|
+
}
|
|
54
64
|
/**
|
|
55
65
|
* Start supervising the connector. Idempotent per process — repeat calls
|
|
56
66
|
* (OpenClaw can invoke register() more than once) return the existing handle.
|
|
57
67
|
* Returns null when the bridge isn't placed on disk (installer not run).
|
|
58
68
|
*/
|
|
59
69
|
export function startConnectorSupervisor(opts = {}) {
|
|
60
|
-
|
|
61
|
-
|
|
70
|
+
const existing = getSingleton();
|
|
71
|
+
if (existing)
|
|
72
|
+
return existing;
|
|
62
73
|
const bridgeDir = opts.bridgeDir ?? resolveBridgeDir();
|
|
63
74
|
if (!bridgeDir) {
|
|
64
75
|
logger.warn(TAG, 'connector not found (no bundled bridge/ and no ~/.reefclaw/bridge) — supervisor idle');
|
|
@@ -134,16 +145,16 @@ export function startConnectorSupervisor(opts = {}) {
|
|
|
134
145
|
/* already gone */
|
|
135
146
|
}
|
|
136
147
|
}
|
|
137
|
-
|
|
148
|
+
setSingleton(null);
|
|
138
149
|
},
|
|
139
150
|
isRunning() {
|
|
140
151
|
return child !== null;
|
|
141
152
|
},
|
|
142
153
|
};
|
|
143
|
-
|
|
154
|
+
setSingleton(handle);
|
|
144
155
|
return handle;
|
|
145
156
|
}
|
|
146
157
|
/** Test-only: reset the module singleton. */
|
|
147
158
|
export function resetConnectorSupervisorForTest() {
|
|
148
|
-
|
|
159
|
+
setSingleton(null);
|
|
149
160
|
}
|
package/index.js
CHANGED
|
@@ -39,6 +39,7 @@ import { onStopWatcherClose } from './ingest/position-auto-capture.js';
|
|
|
39
39
|
import { ReentryTracker } from './portfolio/reentry-tracker.js';
|
|
40
40
|
import { startReadinessReporter } from './ingest/readiness-reporter.js';
|
|
41
41
|
import { resolvePluginInstallFacts } from './plugin-version.js';
|
|
42
|
+
import { processRuntime, resolveProcessRole } from './lifecycle/process-role.js';
|
|
42
43
|
import { computePluginIntegrity, describePluginIntegrity } from './plugin-integrity.js';
|
|
43
44
|
import { IntelMicrostructureAssembler } from './live/microstructure-assembler.js';
|
|
44
45
|
import { recordPositionReviewsTool } from './tools/record-position-reviews.js';
|
|
@@ -906,9 +907,31 @@ function jsonResult(data) {
|
|
|
906
907
|
// Tools are re-registered on the second+ calls so OpenClaw's tool map stays
|
|
907
908
|
// consistent (the api.registerTool factory closes over the singleton state
|
|
908
909
|
// created on the first call).
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
910
|
+
//
|
|
911
|
+
// 2026-09-26: the guard lives on globalThis (lifecycle/process-role.ts), not
|
|
912
|
+
// in module scope — OpenClaw 2026.9.5+ can load this file as two module
|
|
913
|
+
// instances in one gateway, and a module-scoped flag let the second one start
|
|
914
|
+
// a full second runtime. And the runtime starts only in a runtime process:
|
|
915
|
+
// the `openclaw` CLI loads plugins too, and a CLI-started runtime ran a second
|
|
916
|
+
// simulator + stop watcher + connector (whose bridge evicted the gateway's
|
|
917
|
+
// from the relay). CLI processes get the tool NAMES only, with a handler
|
|
918
|
+
// that says where the tools run.
|
|
919
|
+
/** Tools registered in a non-runtime process (CLI / discovery): same names and
|
|
920
|
+
* schemas, so OpenClaw's manifest contract and tool listings stay intact, but
|
|
921
|
+
* nothing is started and every call answers that trading runs in the gateway. */
|
|
922
|
+
function buildInspectionTools() {
|
|
923
|
+
return Object.keys(TOOL_PARAMS).map((name) => ({
|
|
924
|
+
name,
|
|
925
|
+
label: name,
|
|
926
|
+
description: 'ReefClaw trading tool. It runs inside the OpenClaw gateway process; this process is not the gateway.',
|
|
927
|
+
parameters: TOOL_PARAMS[name],
|
|
928
|
+
execute: async () => jsonResult({
|
|
929
|
+
error: 'not_available_in_this_process',
|
|
930
|
+
message: 'ReefClaw trading tools run only inside the OpenClaw gateway. This process is an OpenClaw CLI command, '
|
|
931
|
+
+ 'so nothing was executed. Use the tool from a normal agent turn (heartbeat or chat).',
|
|
932
|
+
}),
|
|
933
|
+
}));
|
|
934
|
+
}
|
|
912
935
|
const paperTradingPlugin = {
|
|
913
936
|
id: PLUGIN_ID,
|
|
914
937
|
name: 'ReefClaw Trading',
|
|
@@ -930,14 +953,30 @@ const paperTradingPlugin = {
|
|
|
930
953
|
},
|
|
931
954
|
register(api) {
|
|
932
955
|
setLogLevel('info');
|
|
933
|
-
//
|
|
934
|
-
//
|
|
935
|
-
//
|
|
936
|
-
|
|
937
|
-
if (
|
|
956
|
+
// Not the gateway (a CLI command or an OpenClaw inspection pass): register
|
|
957
|
+
// the tool names only. Nothing below — adapters, watchers, feeds,
|
|
958
|
+
// reporters, the connector — may start in such a process.
|
|
959
|
+
const role = resolveProcessRole({ registrationMode: api.registrationMode });
|
|
960
|
+
if (role.role === 'inspect') {
|
|
961
|
+
logger.debug(TAG, `register() in a non-runtime process (${role.reason}) — tool names only, runtime not started`);
|
|
962
|
+
const inspectionTools = buildInspectionTools();
|
|
963
|
+
api.registerTool(() => inspectionTools, { names: inspectionTools.map(t => t.name) });
|
|
964
|
+
return;
|
|
965
|
+
}
|
|
966
|
+
// Idempotency guard (see note above). Process-wide: every module instance
|
|
967
|
+
// of this file shares the record. If already initialised, re-register the
|
|
968
|
+
// same tools so OpenClaw's tool map stays populated across its multiple
|
|
969
|
+
// register() calls, but do NOT spin up a second adapter / stream / poller
|
|
970
|
+
// stack.
|
|
971
|
+
const processRecord = processRuntime();
|
|
972
|
+
if (processRecord.initialised) {
|
|
938
973
|
logger.warn(TAG, 'register() called again — reusing existing adapter (singleton)');
|
|
939
|
-
if (
|
|
940
|
-
api.registerTool(
|
|
974
|
+
if (processRecord.toolsFactory) {
|
|
975
|
+
api.registerTool(processRecord.toolsFactory, { names: processRecord.toolNames });
|
|
976
|
+
}
|
|
977
|
+
const diskRelease = resolvePluginInstallFacts({ pluginRoot: dirname(fileURLToPath(import.meta.url)) }).version ?? null;
|
|
978
|
+
if (diskRelease && processRecord.release && diskRelease !== processRecord.release) {
|
|
979
|
+
logger.warn(TAG, `plugin ${diskRelease} is on disk but this gateway process is still running ${processRecord.release} — restart the gateway to load it`);
|
|
941
980
|
}
|
|
942
981
|
// The supervisor must be (re)evaluated on EVERY register call, not just
|
|
943
982
|
// the first: the first full register can run BEFORE the installer has
|
|
@@ -2747,7 +2786,7 @@ const paperTradingPlugin = {
|
|
|
2747
2786
|
{
|
|
2748
2787
|
name: 'set_exchange_credentials',
|
|
2749
2788
|
label: 'Set Exchange Credentials',
|
|
2750
|
-
description: 'Operator-only. Store exchange credentials in ~/.reefclaw/plugin-config.json — Binance API key + secret, or Hyperliquid master address + agent wallet key (venue-selected). Same-venue live modes reconnect the adapter; a venue CHANGE is stored but requires an agent restart. Refused without dashboard operator provenance.',
|
|
2789
|
+
description: 'Operator-only. Store exchange credentials in ~/.reefclaw/plugin-config.json — Binance API key + secret, or Hyperliquid master address + agent wallet key (venue-selected). A venue-only call (no credential fields) activates that venue: with stored credentials it switches back to them; with none it selects the venue for PAPER trading (refused in live modes). Same-venue live modes reconnect the adapter; a venue CHANGE is stored but requires an agent restart. Refused without dashboard operator provenance.',
|
|
2751
2790
|
parameters: TOOL_PARAMS.set_exchange_credentials,
|
|
2752
2791
|
execute: async (_id, params) => {
|
|
2753
2792
|
const prov = verifyOperatorProvenance(params.operator_token);
|
|
@@ -2918,9 +2957,9 @@ const paperTradingPlugin = {
|
|
|
2918
2957
|
// Cache factory + names on the module singleton so repeat register()
|
|
2919
2958
|
// calls can re-register without spinning up duplicate adapters (the
|
|
2920
2959
|
// factory closes over the already-wrapped tools — idempotent).
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2960
|
+
processRecord.toolsFactory = toolsFactory;
|
|
2961
|
+
processRecord.toolNames = toolNames;
|
|
2962
|
+
processRecord.initialised = true;
|
|
2924
2963
|
logger.info(TAG, `Registered ${gatedTools.length} tools (gate mode=${toolGate.getMode()}): ${toolNames.join(', ')}. Plugin v3.8.0 (${runtime.mode} mode)`);
|
|
2925
2964
|
// Agent-readiness reporter (docs/AGENT_READINESS_GATE_PLAN.md Phase 1):
|
|
2926
2965
|
// probe host→venue reachability (Binance HTTP 451 geo-block / Hyperliquid
|
|
@@ -2950,6 +2989,7 @@ const paperTradingPlugin = {
|
|
|
2950
2989
|
connectorSupervisor: readPluginConfig().connectorSupervisor,
|
|
2951
2990
|
});
|
|
2952
2991
|
logger.info(TAG, `Plugin release ${installFacts.version ?? 'unknown (no stamped manifest)'} via ${installFacts.channel}`);
|
|
2992
|
+
processRecord.release = installFacts.version ?? null;
|
|
2953
2993
|
// What THIS process actually loaded — install-location CLASS (never the
|
|
2954
2994
|
// path), process start, SHA-256 of the plugin's own order-path files —
|
|
2955
2995
|
// captured once here at boot and carried on every readiness post. The
|
|
@@ -2963,7 +3003,7 @@ const paperTradingPlugin = {
|
|
|
2963
3003
|
logger.info(TAG, runtimeIntegrity
|
|
2964
3004
|
? `Plugin runtime ${describePluginIntegrity(runtimeIntegrity, pluginRoot)}`
|
|
2965
3005
|
: `Plugin runtime integrity report OFF (RC_READINESS_INTEGRITY=off); root=${pluginRoot}`);
|
|
2966
|
-
// Runs here once (guarded by the
|
|
3006
|
+
// Runs here once (guarded by the process-record early-return → once per
|
|
2967
3007
|
// process) + on an unref'd interval inside the reporter.
|
|
2968
3008
|
startReadinessReporter({
|
|
2969
3009
|
apiBaseUrl,
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export type ProcessRole = 'runtime' | 'inspect';
|
|
2
|
+
export interface ProcessRoleInput {
|
|
3
|
+
registrationMode?: unknown;
|
|
4
|
+
title?: string;
|
|
5
|
+
argv?: readonly string[];
|
|
6
|
+
/** RC_PLUGIN_PROCESS_ROLE: 'runtime' | 'inspect' forces the role; anything
|
|
7
|
+
* else means auto. Escape hatch if a future OpenClaw renames its gateway. */
|
|
8
|
+
override?: string;
|
|
9
|
+
}
|
|
10
|
+
export interface ProcessRoleDecision {
|
|
11
|
+
role: ProcessRole;
|
|
12
|
+
reason: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function resolveProcessRole(input?: ProcessRoleInput): ProcessRoleDecision;
|
|
15
|
+
/** The one runtime this process runs, shared by every module instance. */
|
|
16
|
+
export interface ProcessRuntimeRecord {
|
|
17
|
+
initialised: boolean;
|
|
18
|
+
toolsFactory: ((context?: unknown) => unknown[]) | null;
|
|
19
|
+
toolNames: string[];
|
|
20
|
+
/** Plugin release that started the runtime (disk read at boot). */
|
|
21
|
+
release: string | null;
|
|
22
|
+
/** Connector supervisor handle — started at most once per process. */
|
|
23
|
+
connectorSupervisor: unknown;
|
|
24
|
+
}
|
|
25
|
+
export declare function processRuntime(): ProcessRuntimeRecord;
|
|
26
|
+
/** Test-only. */
|
|
27
|
+
export declare function resetProcessRuntimeForTest(): void;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Which OpenClaw process loaded this plugin, and the process-wide record of
|
|
2
|
+
// the one runtime this process may run.
|
|
3
|
+
//
|
|
4
|
+
// Two defects share this file (2026-09-26):
|
|
5
|
+
//
|
|
6
|
+
// 1. The `openclaw` CLI loads plugins IN ITS OWN PROCESS. Every `openclaw
|
|
7
|
+
// --help`, `openclaw hooks …`, `openclaw agent …` ran a full register():
|
|
8
|
+
// a second simulator over the same state.json, a second stop watcher, a
|
|
9
|
+
// second readiness reporter, and a second connector supervisor. The second
|
|
10
|
+
// bridge reads the same ~/.reefclaw/relay-instance-id as the gateway's, so
|
|
11
|
+
// the relay's same-instance rule evicted the real bridge (4010) on every
|
|
12
|
+
// connect for as long as the CLI lived. Seen on a paying customer's box:
|
|
13
|
+
// one `openclaw --help` by the agent → 55 evictions in 2 minutes. A CLI's
|
|
14
|
+
// un-unref'd watcher timers also kept it alive until a reaper killed it.
|
|
15
|
+
//
|
|
16
|
+
// 2. OpenClaw 2026.9.5+ can load index.js as TWO module instances inside the
|
|
17
|
+
// gateway (Ardi report #8). A module-scoped "already initialised" flag is
|
|
18
|
+
// invisible to the second instance, so everything above ran twice in the
|
|
19
|
+
// gateway itself — on a live box, two exchange adapters.
|
|
20
|
+
//
|
|
21
|
+
// Fix: the runtime (adapters, watchers, feeds, reporters, the connector
|
|
22
|
+
// supervisor) starts ONLY in a runtime process, at most once per process,
|
|
23
|
+
// recorded on globalThis so every module instance sees it.
|
|
24
|
+
//
|
|
25
|
+
// Fail direction: only a POSITIVE non-gateway signal makes this a CLI. An
|
|
26
|
+
// unknown process runs the runtime exactly as before, because a gateway
|
|
27
|
+
// misread as a CLI would leave the agent with no working trading tools.
|
|
28
|
+
/** Registration modes in which OpenClaw only inspects the plugin (it never
|
|
29
|
+
* runs tools from these registries). Unknown or absent → runtime. */
|
|
30
|
+
const INSPECTION_MODES = new Set([
|
|
31
|
+
'cli-metadata',
|
|
32
|
+
'discovery',
|
|
33
|
+
'tool-discovery',
|
|
34
|
+
'setup-only',
|
|
35
|
+
]);
|
|
36
|
+
export function resolveProcessRole(input = {}) {
|
|
37
|
+
const override = input.override ?? process.env.RC_PLUGIN_PROCESS_ROLE;
|
|
38
|
+
if (override === 'runtime' || override === 'inspect') {
|
|
39
|
+
return { role: override, reason: `RC_PLUGIN_PROCESS_ROLE=${override}` };
|
|
40
|
+
}
|
|
41
|
+
const mode = input.registrationMode;
|
|
42
|
+
if (typeof mode === 'string' && INSPECTION_MODES.has(mode)) {
|
|
43
|
+
return { role: 'inspect', reason: `registrationMode=${mode}` };
|
|
44
|
+
}
|
|
45
|
+
// OpenClaw titles its CLI processes `openclaw-<top-level command>` and its
|
|
46
|
+
// gateway `openclaw-gateway`; a bare `openclaw` is the root command (e.g.
|
|
47
|
+
// `openclaw --help`), or a gateway that has not renamed itself yet.
|
|
48
|
+
const title = input.title ?? process.title;
|
|
49
|
+
const argv = input.argv ?? process.argv;
|
|
50
|
+
const sub = gatewaySubcommand(argv);
|
|
51
|
+
if (title === 'openclaw-gateway') {
|
|
52
|
+
// `openclaw gateway status|stop|call …` are CLIs titled the same way.
|
|
53
|
+
return sub
|
|
54
|
+
? { role: 'inspect', reason: `title=openclaw-gateway subcommand=${sub}` }
|
|
55
|
+
: { role: 'runtime', reason: 'title=openclaw-gateway' };
|
|
56
|
+
}
|
|
57
|
+
if (/^openclaw-[a-z0-9][a-z0-9-]*$/.test(title))
|
|
58
|
+
return { role: 'inspect', reason: `title=${title}` };
|
|
59
|
+
if (title === 'openclaw') {
|
|
60
|
+
return argv.slice(2).includes('gateway') && !sub
|
|
61
|
+
? { role: 'runtime', reason: 'title=openclaw argv=gateway' }
|
|
62
|
+
: { role: 'inspect', reason: 'title=openclaw (CLI command)' };
|
|
63
|
+
}
|
|
64
|
+
return { role: 'runtime', reason: `unrecognised process (title=${title}) — runtime by default` };
|
|
65
|
+
}
|
|
66
|
+
/** `openclaw gateway <sub>` commands that talk to or manage a gateway and
|
|
67
|
+
* exit — they never ARE the gateway. From OpenClaw's gateway CLI (checked
|
|
68
|
+
* against 2026.7.1 and 2026.9.6) plus the service-manager verbs.
|
|
69
|
+
* Deliberately a known list, not "any positional": `gateway --bind lan`
|
|
70
|
+
* must stay the runtime. Left OUT on purpose (unlisted = runtime, the safe
|
|
71
|
+
* side): `start` and `daemon` (can start the gateway in the foreground) and
|
|
72
|
+
* the 9.6 restart-handoff commands (`restart-handoff`, `consume`). */
|
|
73
|
+
const GATEWAY_CLI_SUBCOMMANDS = new Set([
|
|
74
|
+
'call', 'probe', 'health', 'discover', 'diagnostics', 'export', 'stability', 'usage-cost',
|
|
75
|
+
'status', 'stop', 'restart', 'install', 'uninstall',
|
|
76
|
+
// 2026.9.6
|
|
77
|
+
'suspend', 'resume', 'capabilities', 'auth-token',
|
|
78
|
+
]);
|
|
79
|
+
function gatewaySubcommand(argv) {
|
|
80
|
+
const args = argv.slice(2);
|
|
81
|
+
const i = args.indexOf('gateway');
|
|
82
|
+
if (i < 0)
|
|
83
|
+
return null;
|
|
84
|
+
return args.slice(i + 1).find((a) => GATEWAY_CLI_SUBCOMMANDS.has(a)) ?? null;
|
|
85
|
+
}
|
|
86
|
+
const RUNTIME_KEY = Symbol.for('reefclaw.paper-trading.process-runtime');
|
|
87
|
+
export function processRuntime() {
|
|
88
|
+
const g = globalThis;
|
|
89
|
+
let rec = g[RUNTIME_KEY];
|
|
90
|
+
if (!rec) {
|
|
91
|
+
rec = { initialised: false, toolsFactory: null, toolNames: [], release: null, connectorSupervisor: null };
|
|
92
|
+
g[RUNTIME_KEY] = rec;
|
|
93
|
+
}
|
|
94
|
+
return rec;
|
|
95
|
+
}
|
|
96
|
+
/** Test-only. */
|
|
97
|
+
export function resetProcessRuntimeForTest() {
|
|
98
|
+
delete globalThis[RUNTIME_KEY];
|
|
99
|
+
}
|
package/live/stop-watcher.d.ts
CHANGED
|
@@ -3,6 +3,14 @@ import type { IExchangeAdapter } from '../exchange-adapter.js';
|
|
|
3
3
|
import type { CcxtOrder, CcxtPosition } from '../types.js';
|
|
4
4
|
import type { TradingOperationLock } from '../lifecycle/trading-operation-lock.js';
|
|
5
5
|
export declare const DEFAULT_INTERVAL_MS = 10000;
|
|
6
|
+
/** After start(), a missing mark is reported as warm-up (INFO) rather than
|
|
7
|
+
* STOP UNENFORCEABLE (ERROR) for this long. The quote feed needs a cycle or
|
|
8
|
+
* two after a gateway restart before it has a mark for every symbol (Ardi
|
|
9
|
+
* report #8: the first tick ~13s after boot alarmed on every position, the
|
|
10
|
+
* second was clean). Enforcement is unchanged: a position WITH a mark is
|
|
11
|
+
* evaluated from the first tick, and one still without a mark after this
|
|
12
|
+
* window raises the full ERROR. */
|
|
13
|
+
export declare const STOP_WATCHER_WARMUP_MS = 30000;
|
|
6
14
|
export interface StopTriggeredEvent {
|
|
7
15
|
symbol: string;
|
|
8
16
|
side: 'long' | 'short';
|
|
@@ -68,6 +76,10 @@ export declare class PositionWatcher extends EventEmitter {
|
|
|
68
76
|
/** Symbols already alarmed for an unusable mark, so the ERROR fires once per
|
|
69
77
|
* episode rather than every tick. Cleared as soon as a usable mark returns. */
|
|
70
78
|
private notifiedUnusableMark;
|
|
79
|
+
/** Symbols already reported as waiting for a first mark during warm-up. */
|
|
80
|
+
private notifiedWarmup;
|
|
81
|
+
/** When start() ran; null when ticks are driven directly (tests). */
|
|
82
|
+
private startedAt;
|
|
71
83
|
constructor(adapter: IExchangeAdapter, intervalMs?: number, operationLock?: TradingOperationLock);
|
|
72
84
|
/** Configure this after the durable execution ledger is ready. Runtime
|
|
73
85
|
* lifecycle hooks reapply it to every watcher after reconnect. */
|
package/live/stop-watcher.js
CHANGED
|
@@ -28,6 +28,14 @@ const TAG = 'stop-watcher';
|
|
|
28
28
|
// revert with zero deploy via plugin-config.json `stopWatcher.intervalMs`.
|
|
29
29
|
// See docs/EFFICIENCY_QUICK_WINS_PLAN.md + the Binance ban-gate context.
|
|
30
30
|
export const DEFAULT_INTERVAL_MS = 10_000;
|
|
31
|
+
/** After start(), a missing mark is reported as warm-up (INFO) rather than
|
|
32
|
+
* STOP UNENFORCEABLE (ERROR) for this long. The quote feed needs a cycle or
|
|
33
|
+
* two after a gateway restart before it has a mark for every symbol (Ardi
|
|
34
|
+
* report #8: the first tick ~13s after boot alarmed on every position, the
|
|
35
|
+
* second was clean). Enforcement is unchanged: a position WITH a mark is
|
|
36
|
+
* evaluated from the first tick, and one still without a mark after this
|
|
37
|
+
* window raises the full ERROR. */
|
|
38
|
+
export const STOP_WATCHER_WARMUP_MS = 30_000;
|
|
31
39
|
/** True when this position carries a protective stop we are supposed to be
|
|
32
40
|
* enforcing. Used to decide whether an unusable mark is an ALARM (a stop we
|
|
33
41
|
* cannot evaluate) or simply uninteresting (no stop set). */
|
|
@@ -74,6 +82,10 @@ export class PositionWatcher extends EventEmitter {
|
|
|
74
82
|
/** Symbols already alarmed for an unusable mark, so the ERROR fires once per
|
|
75
83
|
* episode rather than every tick. Cleared as soon as a usable mark returns. */
|
|
76
84
|
notifiedUnusableMark = new Set();
|
|
85
|
+
/** Symbols already reported as waiting for a first mark during warm-up. */
|
|
86
|
+
notifiedWarmup = new Set();
|
|
87
|
+
/** When start() ran; null when ticks are driven directly (tests). */
|
|
88
|
+
startedAt = null;
|
|
77
89
|
constructor(adapter, intervalMs = DEFAULT_INTERVAL_MS, operationLock) {
|
|
78
90
|
super();
|
|
79
91
|
this.adapter = adapter;
|
|
@@ -91,6 +103,7 @@ export class PositionWatcher extends EventEmitter {
|
|
|
91
103
|
return;
|
|
92
104
|
}
|
|
93
105
|
logger.info(TAG, `Starting stop watcher (interval: ${this.intervalMs}ms)`);
|
|
106
|
+
this.startedAt = Date.now();
|
|
94
107
|
this.interval = setInterval(() => {
|
|
95
108
|
void this.tick();
|
|
96
109
|
}, this.intervalMs);
|
|
@@ -103,6 +116,8 @@ export class PositionWatcher extends EventEmitter {
|
|
|
103
116
|
this.closePending.clear();
|
|
104
117
|
this.notifiedBreach.clear();
|
|
105
118
|
this.notifiedUnusableMark.clear();
|
|
119
|
+
this.notifiedWarmup.clear();
|
|
120
|
+
this.startedAt = null;
|
|
106
121
|
logger.info(TAG, 'Stopped');
|
|
107
122
|
}
|
|
108
123
|
/** Run one check cycle. Exposed for tests (skip setInterval). */
|
|
@@ -146,6 +161,15 @@ export class PositionWatcher extends EventEmitter {
|
|
|
146
161
|
// fabricated entryPrice fallback, isStopBreached read false, and the
|
|
147
162
|
// watcher skipped it every tick without ever saying so. Alarm instead.
|
|
148
163
|
if (hasEnforceableStop(position) && isMarkUnusable(position)) {
|
|
164
|
+
const warmingUp = this.startedAt !== null && Date.now() - this.startedAt < STOP_WATCHER_WARMUP_MS;
|
|
165
|
+
if (warmingUp) {
|
|
166
|
+
if (!this.notifiedWarmup.has(position.symbol)) {
|
|
167
|
+
logger.info(TAG, `warming up: no mark yet for ${position.symbol} (stop=${position.stopPrice}) — the quote feed has not ` +
|
|
168
|
+
`delivered its first price since start; this stop is evaluated as soon as it does`);
|
|
169
|
+
this.notifiedWarmup.add(position.symbol);
|
|
170
|
+
}
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
149
173
|
if (!this.notifiedUnusableMark.has(position.symbol)) {
|
|
150
174
|
logger.error(TAG, `STOP UNENFORCEABLE: ${position.symbol} ${position.side} has stop=${position.stopPrice} ` +
|
|
151
175
|
`but no usable mark (markPrice=${position.markPrice}` +
|
package/openclaw.plugin.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"id": "reefclaw-paper-trading",
|
|
3
3
|
"name": "ReefClaw Trading",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.41",
|
|
5
5
|
"description": "Supervised trading plugin for the ReefClaw dashboard. It runs on YOUR machine and starts in PAPER mode with no API keys. It cannot trade real funds until you supply exchange credentials and step PAPER→MICRO_LIVE→LIVE yourself from the dashboard — the agent cannot make that change (the tool is refused without operator provenance). Exchange keys stay local, are used only to sign requests to the exchange, and are never transmitted to ReefClaw (asserted by a test in this package). Trading telemetry — positions, fills, decision journal — is sent to ReefClaw to render the dashboard. Every live position carries exchange-native protective stops. Remote updates to the agent's trading instructions are applied only after an Ed25519 signature is verified against a public key pinned in this build. It runs on gateway startup and supervises a local connector process; the package README lists every path it writes and everything it sends. It never changes the gateway's auth settings.",
|
|
6
6
|
"author": "ReefClaw",
|
|
7
7
|
"activation": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@reefclaw/openclaw-plugin",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.41",
|
|
4
4
|
"description": "ReefClaw supervised trading plugin for OpenClaw. Runs entirely on YOUR machine and starts in PAPER mode — it cannot trade real funds until you supply exchange credentials and walk the PAPER→MICRO_LIVE→LIVE ladder yourself from the ReefClaw dashboard (the agent cannot make that change; it is refused without operator provenance). Your exchange API keys stay on your machine to sign requests to the exchange and are NEVER sent to ReefClaw — a test in the package asserts this. What does reach ReefClaw is trading telemetry for the dashboard (positions, fills, decision journal). Live trading always carries exchange-native protective stops. Trading instructions can be updated remotely, and every update must carry a valid Ed25519 signature verified against a key pinned in this build before it is applied. Install from ClawHub on OpenClaw 2026.8.1+ (Control UI Plugins > Discover, or /plugins install clawhub:@reefclaw/openclaw-plugin then the same with --accept-capabilities after reviewing the listed capabilities), or with the ReefClaw connect installer (@reefclaw/connect on npm, pinned to the exact release named in the bundled skill). It runs on gateway startup, supervises a local connector process, and writes only under ~/.reefclaw and OpenClaw's own skill, config and cron locations; the README lists every path it writes and everything it sends. It never changes the gateway's auth settings.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "index.js",
|
package/plugin-integrity.d.ts
CHANGED
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
export declare const INTEGRITY_FILES: readonly ["index.js", "tools/create-order.js", "risk/pre-trade-check.js"];
|
|
5
5
|
/** Where the running index.js lives, as a class — never the path.
|
|
6
6
|
* reefclaw_home = under ~/.reefclaw (the connect installer's layout);
|
|
7
|
-
*
|
|
7
|
+
* openclaw_capture = under ~/.openclaw/tmp/plugin-captures (OpenClaw
|
|
8
|
+
* 2026.9.6+ runs plugins from a copy it makes there — the hashes are of
|
|
9
|
+
* that copy, i.e. of what actually runs; Ardi report #8);
|
|
10
|
+
* openclaw_home = elsewhere under ~/.openclaw (ClawHub extension layout);
|
|
8
11
|
* other = anywhere else (a hand-placed copy, a source checkout, a fork). */
|
|
9
|
-
export type PluginRootLocation = 'reefclaw_home' | 'openclaw_home' | 'other';
|
|
12
|
+
export type PluginRootLocation = 'reefclaw_home' | 'openclaw_capture' | 'openclaw_home' | 'other';
|
|
10
13
|
export interface PluginRuntimeIntegrity {
|
|
11
14
|
rootLocation: PluginRootLocation;
|
|
12
15
|
/** ISO timestamp the gateway process started (now − process.uptime()). */
|
package/plugin-integrity.js
CHANGED
|
@@ -38,7 +38,10 @@ export function classifyPluginRoot(pluginRoot, homes = {}) {
|
|
|
38
38
|
const root = resolve(pluginRoot);
|
|
39
39
|
if (isUnder(root, homes.reefclawHome ?? join(homedir(), '.reefclaw')))
|
|
40
40
|
return 'reefclaw_home';
|
|
41
|
-
|
|
41
|
+
const openclawHome = homes.openclawHome ?? join(homedir(), '.openclaw');
|
|
42
|
+
if (isUnder(root, join(openclawHome, 'tmp', 'plugin-captures')))
|
|
43
|
+
return 'openclaw_capture';
|
|
44
|
+
if (isUnder(root, openclawHome))
|
|
42
45
|
return 'openclaw_home';
|
|
43
46
|
return 'other';
|
|
44
47
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"0.1.39": {
|
|
3
|
+
"index.js": "03b9e7ea593dfd8b8cc372603967f2be3bf87b05835dc32b1147cc3579e28cd7",
|
|
4
|
+
"tools/create-order.js": "b0244ff69cb5b4a44e18c7ceaf91669ee19649d0e6b18bb857aa47ca80f63b2a",
|
|
5
|
+
"risk/pre-trade-check.js": "15ba2c91e7a1f5ea03a2452eda40d489eda406a434e3bc3e9b7e024190f6a22f"
|
|
6
|
+
},
|
|
7
|
+
"0.1.40": {
|
|
8
|
+
"index.js": "03b9e7ea593dfd8b8cc372603967f2be3bf87b05835dc32b1147cc3579e28cd7",
|
|
9
|
+
"tools/create-order.js": "b0244ff69cb5b4a44e18c7ceaf91669ee19649d0e6b18bb857aa47ca80f63b2a",
|
|
10
|
+
"risk/pre-trade-check.js": "15ba2c91e7a1f5ea03a2452eda40d489eda406a434e3bc3e9b7e024190f6a22f"
|
|
11
|
+
}
|
|
12
|
+
}
|
package/release-notes.json
CHANGED
|
@@ -10,5 +10,7 @@
|
|
|
10
10
|
"0.1.36": "Day P&L no longer shows two days as 'today' after midnight UTC: the connector now takes the exchange-anchored figure on every balance read, not only when the dashboard reconnects. The one-click update tells the truth on Docker and other unmanaged gateways (a restart the installer could not perform is reported, never assumed), shows live progress again on OpenClaw 2026.8+, and never resets the live skill with a forced reinstall; a box whose OpenClaw has no terminal API gets a clear 'update from a shell' notice instead of a retry loop.",
|
|
11
11
|
"0.1.37": "Updates now finish on Docker and other unmanaged gateways: the connector asks the gateway to restart itself through OpenClaw's own restart request, so a one-click update no longer ends with 'files installed, restart it from the host', and the dashboard offers 'Restart now' if that ever does happen. The installer no longer re-registers an already-registered plugin on an update, which is what used to start a second plugin process inside a container.",
|
|
12
12
|
"0.1.38": "Fixes the restart that 0.1.37 introduced for Docker and other unmanaged gateways: the connector now asks for OpenClaw's update restart, the one kind that replaces the running process so the new files actually load (the previous kind restarted in place and kept the old code while reporting success). The installer no longer claims a self-restart it cannot verify; the connector or the dashboard's Restart now button performs it, waiting for an in-progress agent run to finish first.",
|
|
13
|
-
"0.1.39": "wave9: a refusal by the plugin's own risk gate no longer burns the whole trading day (the authorization is released and a fresh one can be requested inside the window; a wrong-side stop still latches). wave9 evidence: the previous day's funding settlement stamped a few milliseconds late no longer makes the whole night's evidence read as incomplete. Model health: the model note OpenClaw 2026.9 writes at the start of every session no longer counts as a model switch, so the model dot can be green. Readiness: the plugin now reports whether its own files match the release (an install-location class, the process start time and fingerprints of three of its own files; never a path, never file contents; switch RC_READINESS_INTEGRITY=off), so a stale or modified install can be told apart from the release without touching the box."
|
|
13
|
+
"0.1.39": "wave9: a refusal by the plugin's own risk gate no longer burns the whole trading day (the authorization is released and a fresh one can be requested inside the window; a wrong-side stop still latches). wave9 evidence: the previous day's funding settlement stamped a few milliseconds late no longer makes the whole night's evidence read as incomplete. Model health: the model note OpenClaw 2026.9 writes at the start of every session no longer counts as a model switch, so the model dot can be green. Readiness: the plugin now reports whether its own files match the release (an install-location class, the process start time and fingerprints of three of its own files; never a path, never file contents; switch RC_READINESS_INTEGRITY=off), so a stale or modified install can be told apart from the release without touching the box.",
|
|
14
|
+
"0.1.40": "One-click updates now work on boxes without a gateway terminal (OpenClaw older than 2026.7, terminal disabled) and inside Docker: the connector runs the installer itself in a files-only mode that never touches the OpenClaw CLI or config, then asks the gateway to restart itself. The installer gains --files-only for the same purpose.",
|
|
15
|
+
"0.1.41": "Fixes the dashboard link dropping and reconnecting (seen as a connect/disconnect loop): when the agent or anyone ran an openclaw command, that command started a second copy of the trading plugin and its connector, which knocked the real one off the relay. The trading runtime now starts only inside the OpenClaw gateway, once per process (also covers OpenClaw 2026.9.5+ loading the plugin twice); openclaw commands see the tool names but nothing runs there. Paper venue switch: Binance <-> Hyperliquid can now be switched from the dashboard in paper mode without exchange keys (refused while live). Stop watcher: right after a restart, a position waiting for its first price is reported as warming up instead of as an unenforceable stop; an alarm still fires if the price never arrives. Readiness: OpenClaw 2026.9.6's plugin run copy is reported as its own install location."
|
|
14
16
|
}
|
package/skills/reefclaw/SKILL.md
CHANGED
|
@@ -101,7 +101,7 @@ When a user gives you this message (or just a bare `Here's my ReefClaw token: rc
|
|
|
101
101
|
If the ReefClaw trading tools are not present yet, the **user** installs them by running this once, in a terminal on the machine running OpenClaw (inside the container, if OpenClaw runs in Docker):
|
|
102
102
|
|
|
103
103
|
```
|
|
104
|
-
npx --yes @reefclaw/connect@0.1.
|
|
104
|
+
npx --yes @reefclaw/connect@0.1.54
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
That is the whole install. It places the plugin, sets up the connector, restarts the gateway where it can, and prints what it changed. If its closing lines say **GATEWAY NOT RESTARTED**, the plugin is on disk but not running yet: restarting is the user's step (in Docker, `docker restart <container>` from the host; otherwise restarting OpenClaw). Tell the user exactly that and stop — do not restart, signal or kill any process, do not run docker or service commands, and do not edit the gateway config, even if you could. The plugin reports its own version to ReefClaw after the restart; never post readiness, version or health reports yourself. The version is pinned on purpose: the line names the exact connector release this plugin was published with, so what runs on the machine is reviewable and never "whatever the registry serves today". It needs no ReefClaw token — the connection is the separate paste step above, and the connector picks it up on its own.
|
|
@@ -47,6 +47,10 @@ export interface SetExchangeCredentialsResult {
|
|
|
47
47
|
currentVenue?: VenueId;
|
|
48
48
|
/** Trading mode currently persisted (only with the confirm request). */
|
|
49
49
|
currentMode?: TradingMode;
|
|
50
|
+
/** Whether the activated venue has a usable credential set on disk after
|
|
51
|
+
* this call. False = keyless (paper-only) activation — the dashboard says
|
|
52
|
+
* "add credentials to go live" instead of implying a live-capable box. */
|
|
53
|
+
credentialsStored?: boolean;
|
|
50
54
|
}
|
|
51
55
|
export interface SetExchangeCredentialsDeps {
|
|
52
56
|
runtime: PluginRuntime;
|
|
@@ -20,6 +20,15 @@
|
|
|
20
20
|
// agent (`/restart` in chat). Same-venue behavior is unchanged: PAPER stores
|
|
21
21
|
// without activating; live modes hot-reconnect the adapter.
|
|
22
22
|
//
|
|
23
|
+
// Keyless (paper) activation — 2026-09-25: a `{ venue }` call with NO credential
|
|
24
|
+
// fields and NOTHING stored for that venue is allowed when the box is in PAPER.
|
|
25
|
+
// Paper trading needs no keys on either venue (public market data), and this is
|
|
26
|
+
// the one-click answer for a host Binance geo-blocks (HTTP 451): switch the agent
|
|
27
|
+
// to Hyperliquid and keep trading paper from the same box. Refused when the
|
|
28
|
+
// persisted or running mode is non-PAPER — a venue with no credentials cannot
|
|
29
|
+
// carry a live book, and boot would silently fall back to PAPER; the operator
|
|
30
|
+
// steps down to PAPER (or stores credentials) first. Never a silent mode change.
|
|
31
|
+
//
|
|
23
32
|
// Security:
|
|
24
33
|
// - Secrets (Binance secret / HL agent key) are NEVER logged. Only a redacted
|
|
25
34
|
// fingerprint (Binance apiKey prefix, or the PUBLIC master address for HL)
|
|
@@ -145,13 +154,26 @@ export async function setExchangeCredentialsTool(rawArgs, deps) {
|
|
|
145
154
|
catch {
|
|
146
155
|
// Unreadable/absent config — treat as a fresh box.
|
|
147
156
|
}
|
|
148
|
-
// Activation-only: no credentials supplied
|
|
149
|
-
//
|
|
157
|
+
// Activation-only: no credentials supplied. Either the operator is switching
|
|
158
|
+
// back to a venue they configured before (credentials on disk), or — keyless
|
|
159
|
+
// — they want to paper-trade a venue they never gave keys for. Keyless is
|
|
160
|
+
// fine in PAPER (no keys needed for public market data) and REFUSED in any
|
|
161
|
+
// live mode: the switch would leave the box with nothing to trade live and
|
|
162
|
+
// boot would silently fall back to PAPER — the operator must step down (or
|
|
163
|
+
// store credentials) first, so a mode change is never a side effect here.
|
|
150
164
|
const activationOnly = isActivationOnly(args, venue);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
165
|
+
const keyless = activationOnly && !hasCredentialsForVenue(existing, venue);
|
|
166
|
+
if (keyless) {
|
|
167
|
+
const persistedMode = existingMode ?? 'PAPER';
|
|
168
|
+
if (persistedMode !== 'PAPER' || deps.runtime.mode !== 'PAPER') {
|
|
169
|
+
const liveMode = persistedMode !== 'PAPER' ? persistedMode : deps.runtime.mode;
|
|
170
|
+
return fail(`This agent is in ${liveMode} mode and has no ${venue} credentials stored, so switching it to ` +
|
|
171
|
+
`${venue} now would leave it with nothing to trade live. Switch to PAPER first, or store ` +
|
|
172
|
+
(venue === 'hyperliquid'
|
|
173
|
+
? 'Hyperliquid credentials (walletAddress + agentPrivateKey, or the guided setup) '
|
|
174
|
+
: 'Binance credentials (apiKey + secret) ') +
|
|
175
|
+
'and try again.', '(not-set)', deps, venue);
|
|
176
|
+
}
|
|
155
177
|
}
|
|
156
178
|
const validationError = activationOnly
|
|
157
179
|
? null
|
|
@@ -185,7 +207,9 @@ export async function setExchangeCredentialsTool(rawArgs, deps) {
|
|
|
185
207
|
let fingerprint;
|
|
186
208
|
if (activationOnly) {
|
|
187
209
|
exchange = buildVenueExchangeConfig(existing, venue, {}, args.testnet);
|
|
188
|
-
fingerprint =
|
|
210
|
+
fingerprint = keyless
|
|
211
|
+
? '(no credentials — paper)'
|
|
212
|
+
: redactCredential(venue === 'hyperliquid' ? (exchange.walletAddress ?? '') : (exchange.apiKey ?? ''));
|
|
189
213
|
}
|
|
190
214
|
else if (venue === 'hyperliquid') {
|
|
191
215
|
const walletAddress = args.walletAddress.trim();
|
|
@@ -229,7 +253,10 @@ export async function setExchangeCredentialsTool(rawArgs, deps) {
|
|
|
229
253
|
logger.error(TAG, `Failed to write credentials: ${msg}`);
|
|
230
254
|
return fail(`Failed to persist credentials: ${msg}`, fingerprint, deps, venue);
|
|
231
255
|
}
|
|
232
|
-
|
|
256
|
+
const credentialsStored = hasCredentialsForVenue(exchange, venue);
|
|
257
|
+
logger.info(TAG, keyless
|
|
258
|
+
? `Venue set to ${venue} for paper trading (no ${venue} credentials stored, testnet: ${exchange.testnet === true})`
|
|
259
|
+
: `Stored ${venue} credentials (fingerprint: ${fingerprint}, testnet: ${exchange.testnet === true})`);
|
|
233
260
|
// Venue change: the paper feed / symbols / quote currency / readiness prober
|
|
234
261
|
// are wired to the BOOT venue — hot-reconnecting a live adapter into a
|
|
235
262
|
// different venue would run it on top of the old venue's paper stack. Write,
|
|
@@ -237,14 +264,33 @@ export async function setExchangeCredentialsTool(rawArgs, deps) {
|
|
|
237
264
|
if (venue !== bootVenue) {
|
|
238
265
|
return {
|
|
239
266
|
ok: true,
|
|
240
|
-
message:
|
|
241
|
-
`
|
|
267
|
+
message: keyless
|
|
268
|
+
? `Venue set to ${venue} for paper trading (no ${venue} credentials stored — add them whenever you ` +
|
|
269
|
+
`want to go live). Restart your agent to apply.`
|
|
270
|
+
: `Credentials stored and venue set to ${venue} — restart your agent to apply ` +
|
|
271
|
+
`(send /restart to your agent in chat, or restart the OpenClaw service)`,
|
|
242
272
|
fingerprint,
|
|
243
273
|
reconnected: false,
|
|
244
274
|
mode: deps.runtime.mode,
|
|
245
275
|
readiness: deps.runtime.adapter.readiness,
|
|
246
276
|
venue,
|
|
247
277
|
restartRequired: true,
|
|
278
|
+
credentialsStored,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
// Keyless on the venue we already booted with: nothing changes at runtime
|
|
282
|
+
// (the gate above guarantees PAPER) — the write only made `venue` explicit.
|
|
283
|
+
if (keyless) {
|
|
284
|
+
return {
|
|
285
|
+
ok: true,
|
|
286
|
+
message: `Already trading ${venue} in PAPER mode — nothing to change.`,
|
|
287
|
+
fingerprint,
|
|
288
|
+
reconnected: false,
|
|
289
|
+
mode: deps.runtime.mode,
|
|
290
|
+
readiness: deps.runtime.adapter.readiness,
|
|
291
|
+
venue,
|
|
292
|
+
restartRequired: false,
|
|
293
|
+
credentialsStored,
|
|
248
294
|
};
|
|
249
295
|
}
|
|
250
296
|
// Same venue: only reconnect if we're already in a live mode — if the
|
|
@@ -276,5 +322,6 @@ export async function setExchangeCredentialsTool(rawArgs, deps) {
|
|
|
276
322
|
readiness: deps.runtime.adapter.readiness,
|
|
277
323
|
venue,
|
|
278
324
|
restartRequired: false,
|
|
325
|
+
credentialsStored,
|
|
279
326
|
};
|
|
280
327
|
}
|