@reefclaw/openclaw-plugin 0.1.34 → 0.1.36
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/README.md +65 -0
- package/bridge/bridge.js +1 -1
- package/bridge/config.d.ts +8 -9
- package/bridge/config.js +39 -74
- package/bridge/gateway/heartbeat-cron.js +1 -1
- package/bridge/gateway/poller.d.ts +26 -4
- package/bridge/gateway/poller.js +19 -2
- package/bridge/heartbeat-transcript.js +25 -1
- package/bridge/providers/connector-update.d.ts +92 -10
- package/bridge/providers/connector-update.js +261 -31
- package/bridge/providers/gateway.d.ts +21 -15
- package/bridge/providers/gateway.js +67 -59
- package/bridge/providers/onboarding-commands.js +3 -3
- package/bridge/utils/skill-version.d.ts +14 -9
- package/bridge/utils/skill-version.js +38 -27
- package/config/brackets-config.js +1 -1
- package/config/plugin-config-io.d.ts +1 -1
- package/config/user-data-stream-config.js +1 -1
- package/connector-supervisor.d.ts +2 -2
- package/connector-supervisor.js +3 -3
- package/index.js +5 -5
- package/live/proposal-decision-listener.d.ts +1 -1
- package/openclaw.plugin.json +2 -2
- package/package.json +2 -2
- package/plugin-version.d.ts +1 -1
- package/plugin-version.js +3 -3
- package/release-notes.json +4 -2
- package/skills/reefclaw/SKILL.md +6 -5
- package/tools/cancel-all-orders.js +1 -1
- package/tools/create-order.js +24 -2
- package/wave9/usdm-evidence-provider.js +9 -1
|
@@ -15,11 +15,16 @@
|
|
|
15
15
|
// This module can run a command on the trader's machine, initiated from our
|
|
16
16
|
// dashboard. That is only acceptable because the command is a FIXED CONSTANT:
|
|
17
17
|
//
|
|
18
|
-
// -
|
|
19
|
-
//
|
|
20
|
-
//
|
|
21
|
-
//
|
|
22
|
-
//
|
|
18
|
+
// - The command shape is fixed (`connectorUpdateCommand`). Its ONLY variable
|
|
19
|
+
// is an exact release version, and that version has exactly one source:
|
|
20
|
+
// ReefClaw's release endpoint (`fetchPinnedConnectVersion`, a public HTTPS
|
|
21
|
+
// GET of build-time constants; release versions are public data), validated
|
|
22
|
+
// as MAJOR.MINOR.PATCH before use. Nothing from the browser, the
|
|
23
|
+
// relay, the agent, or any config file reaches the string, and there is no
|
|
24
|
+
// args/flags parameter. A missing or malformed version refuses the update;
|
|
25
|
+
// it never falls back to an unpinned install. The moment a caller could
|
|
26
|
+
// influence the string this would stop being an update button and become
|
|
27
|
+
// a remote shell, which is why the RPC carries none.
|
|
23
28
|
// - The RPC that reaches this module carries NO command field. Adding one is
|
|
24
29
|
// not a feature request to accept; it is the vulnerability.
|
|
25
30
|
// - No secret is ever placed on the command line. `@reefclaw/connect` takes
|
|
@@ -43,31 +48,89 @@
|
|
|
43
48
|
// `gateway.terminal.enabled=false` is honoured too (`describeOpenFailure`).
|
|
44
49
|
// - terminal.* needs operator.admin: the update opens a separate short-lived
|
|
45
50
|
// admin session and checks the granted scopes before `terminal.open`.
|
|
46
|
-
// - Residual trust:
|
|
47
|
-
// is the registry plus the publisher account (2FA), exactly
|
|
48
|
-
//
|
|
49
|
-
// (the SKILL.md OTA already carries the Ed25519 key for it)
|
|
51
|
+
// - Residual trust: the exact version still resolves on the npm registry, so
|
|
52
|
+
// the trust root is the registry plus the publisher account (2FA), exactly
|
|
53
|
+
// as for a manual install of that version. An offline signature over the
|
|
54
|
+
// release (the SKILL.md OTA already carries the Ed25519 key for it) is the
|
|
55
|
+
// planned next step.
|
|
50
56
|
// - The updater overwrites local modifications to the placed bridge/plugin,
|
|
51
57
|
// as any reinstall would. Self-hosters carrying patches: switch it off.
|
|
52
58
|
import { logger } from '../logger.js';
|
|
53
59
|
const TAG = 'connector-update';
|
|
60
|
+
/** The npm package the update runs. Fixed. */
|
|
61
|
+
export const CONNECT_PACKAGE = '@reefclaw/connect';
|
|
62
|
+
/** Exact release versions only — no tags, ranges or pre-release suffixes. */
|
|
63
|
+
const EXACT_VERSION_RE = /^\d{1,4}\.\d{1,4}\.\d{1,4}$/;
|
|
64
|
+
export function isExactConnectVersion(v) {
|
|
65
|
+
return typeof v === 'string' && EXACT_VERSION_RE.test(v);
|
|
66
|
+
}
|
|
54
67
|
/**
|
|
55
|
-
* The ONE command this feature can ever run.
|
|
56
|
-
*
|
|
57
|
-
* `-y`
|
|
58
|
-
* update. No user input, no interpolation, no exceptions.
|
|
68
|
+
* The ONE command shape this feature can ever run. The only variable part is
|
|
69
|
+
* an exact version, validated against EXACT_VERSION_RE; anything else throws.
|
|
70
|
+
* `-y` keeps the package runner from stopping at its install prompt.
|
|
59
71
|
*/
|
|
60
|
-
export
|
|
72
|
+
export function connectorUpdateCommand(version) {
|
|
73
|
+
if (!isExactConnectVersion(version)) {
|
|
74
|
+
throw new Error(`refusing to build an update command for a non-exact version: ${JSON.stringify(version)}`);
|
|
75
|
+
}
|
|
76
|
+
return `npx -y ${CONNECT_PACKAGE}@${version}`;
|
|
77
|
+
}
|
|
61
78
|
/** Marker printed after the command so we can detect completion + exit code. */
|
|
62
79
|
export const DONE_SENTINEL = '__RC_CONNECTOR_UPDATE_DONE__';
|
|
63
80
|
/**
|
|
64
|
-
* The exact line written to the PTY.
|
|
65
|
-
*
|
|
81
|
+
* The exact line written to the PTY. `$?` is expanded by the remote shell,
|
|
82
|
+
* not by us.
|
|
66
83
|
*/
|
|
67
|
-
export function buildUpdateCommandLine() {
|
|
68
|
-
return `${
|
|
84
|
+
export function buildUpdateCommandLine(version) {
|
|
85
|
+
return `${connectorUpdateCommand(version)}; printf '\\n${DONE_SENTINEL}%s\\n' "$?"`;
|
|
86
|
+
}
|
|
87
|
+
/** Manual-fallback copy for the refusals below: the operator runs the same
|
|
88
|
+
* pinned command from a shell on the box. `version` is unknown when the
|
|
89
|
+
* refusal happened before the release lookup. */
|
|
90
|
+
export function manualUpdateHint(version) {
|
|
91
|
+
return version
|
|
92
|
+
? `run this from a shell on the box: npx -y ${CONNECT_PACKAGE}@${version}`
|
|
93
|
+
: `run the ReefClaw connect installer from a shell on the box, pinned to the version the dashboard's update notice shows (${CONNECT_PACKAGE}@<version>)`;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Ask ReefClaw which connector release an update installs: `connectVersion` on
|
|
97
|
+
* the PUBLIC `/api/release` endpoint, baked by the webapp at build from the
|
|
98
|
+
* released installer (the same constants ride the authenticated config
|
|
99
|
+
* channel as `release.connectVersion`). No credential is needed or sent —
|
|
100
|
+
* release versions are public data, and an update must keep working on a box
|
|
101
|
+
* whose connection token is stale. Any failure, or anything that is not an
|
|
102
|
+
* exact version, refuses the update — this feature never falls back to an
|
|
103
|
+
* unpinned install.
|
|
104
|
+
*/
|
|
105
|
+
export async function fetchPinnedConnectVersion(opts) {
|
|
106
|
+
const refuse = (why) => ({
|
|
107
|
+
ok: false,
|
|
108
|
+
outcome: {
|
|
109
|
+
ok: false,
|
|
110
|
+
status: 'blocked',
|
|
111
|
+
message: `Could not confirm the connector version to install (${why}), so the update was not started — ` +
|
|
112
|
+
`it only ever installs an exact, ReefClaw-confirmed release. Try again shortly, or ${manualUpdateHint()}.`,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
115
|
+
// www matches every other webapp call the bridge makes (reefclaw.com
|
|
116
|
+
// 307-redirects to it).
|
|
117
|
+
const base = (opts.webappUrl ?? process.env.REEFCLAW_API_URL ?? 'https://www.reefclaw.com').replace(/\/$/, '');
|
|
118
|
+
try {
|
|
119
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
120
|
+
const res = await doFetch(`${base}/api/release`, { signal: AbortSignal.timeout(15_000) });
|
|
121
|
+
if (!res.ok)
|
|
122
|
+
return refuse(`ReefClaw answered HTTP ${res.status}`);
|
|
123
|
+
const body = (await res.json());
|
|
124
|
+
const version = body?.connectVersion;
|
|
125
|
+
if (!isExactConnectVersion(version))
|
|
126
|
+
return refuse('ReefClaw did not report an exact release version');
|
|
127
|
+
return { ok: true, version };
|
|
128
|
+
}
|
|
129
|
+
catch (err) {
|
|
130
|
+
return refuse(err instanceof Error ? err.message : String(err));
|
|
131
|
+
}
|
|
69
132
|
}
|
|
70
|
-
/** Terminal grid we request. Wide enough that
|
|
133
|
+
/** Terminal grid we request. Wide enough that package-manager output does not wrap into
|
|
71
134
|
* unreadable soup in the dashboard's output pane. */
|
|
72
135
|
const COLS = 120;
|
|
73
136
|
const ROWS = 40;
|
|
@@ -90,7 +153,7 @@ export function describeOpenFailure(err) {
|
|
|
90
153
|
ok: false,
|
|
91
154
|
status: 'blocked',
|
|
92
155
|
message: 'This box has the OpenClaw terminal disabled, so ReefClaw cannot run the update for you. '
|
|
93
|
-
+
|
|
156
|
+
+ `Instead, ${manualUpdateHint()}.`,
|
|
94
157
|
};
|
|
95
158
|
}
|
|
96
159
|
if (lower.includes('sandbox')) {
|
|
@@ -98,7 +161,7 @@ export function describeOpenFailure(err) {
|
|
|
98
161
|
ok: false,
|
|
99
162
|
status: 'blocked',
|
|
100
163
|
message: 'This agent runs in a sandbox, and OpenClaw does not support terminals inside one yet. '
|
|
101
|
-
+
|
|
164
|
+
+ `Instead, ${manualUpdateHint()}.`,
|
|
102
165
|
};
|
|
103
166
|
}
|
|
104
167
|
// Scope refusal: terminal.* requires operator.admin on OpenClaw >= 2026.7
|
|
@@ -112,7 +175,20 @@ export function describeOpenFailure(err) {
|
|
|
112
175
|
status: 'blocked',
|
|
113
176
|
message: 'The gateway refused to open a terminal for the connector (it needs the operator.admin scope). '
|
|
114
177
|
+ 'One-click updates need a connector released 2026-09-14 or later — update once by pasting the manual '
|
|
115
|
-
+
|
|
178
|
+
+ `command to your agent, or ${manualUpdateHint()}. After that, updates are one click.`,
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
// No terminal RPC at all: OpenClaw < 2026.7 has no `terminal.*` methods, so
|
|
182
|
+
// the gateway answers `unknown method: terminal.open`. That is a fact about
|
|
183
|
+
// 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).
|
|
185
|
+
if (/unknown method/.test(lower)) {
|
|
186
|
+
return {
|
|
187
|
+
ok: false,
|
|
188
|
+
status: 'blocked',
|
|
189
|
+
message: 'This box runs an OpenClaw older than 2026.7, which has no terminal API, so ReefClaw cannot run the '
|
|
190
|
+
+ 'update for you. Upgrade OpenClaw to enable one-click updates; until then, paste the manual command '
|
|
191
|
+
+ `to your agent, or ${manualUpdateHint()}.`,
|
|
116
192
|
};
|
|
117
193
|
}
|
|
118
194
|
return {
|
|
@@ -128,7 +204,7 @@ export function describeUpdateDisabled() {
|
|
|
128
204
|
ok: false,
|
|
129
205
|
status: 'blocked',
|
|
130
206
|
message: 'One-click updates are switched off on this box (REEFCLAW_ALLOW_CONNECTOR_UPDATE=0). '
|
|
131
|
-
+ `
|
|
207
|
+
+ `Instead, ${manualUpdateHint()}.`,
|
|
132
208
|
};
|
|
133
209
|
}
|
|
134
210
|
/**
|
|
@@ -140,6 +216,15 @@ export function describeUpdateDisabled() {
|
|
|
140
216
|
export function classifyTransportLoss(started) {
|
|
141
217
|
return started ? 'restarting' : 'failed';
|
|
142
218
|
}
|
|
219
|
+
/** What the installer prints when it placed the new version but could not
|
|
220
|
+
* restart the gateway (installer/src/gateway-restart.ts NOT_RESTARTED_MARKER
|
|
221
|
+
* — inside a Docker container that is the normal outcome, only the host can
|
|
222
|
+
* restart the container). The installer still exits 0 (the files ARE
|
|
223
|
+
* installed), so completion is inspected for it. Pinned across packages. */
|
|
224
|
+
export const INSTALLER_NOT_RESTARTED_MARKER = 'GATEWAY NOT RESTARTED';
|
|
225
|
+
export function installerReportedNoRestart(screen) {
|
|
226
|
+
return typeof screen === 'string' && screen.includes(INSTALLER_NOT_RESTARTED_MARKER);
|
|
227
|
+
}
|
|
143
228
|
/** Extract the exit code that follows the DONE sentinel, if it has appeared. */
|
|
144
229
|
export function parseDoneSentinel(screen) {
|
|
145
230
|
const idx = screen.lastIndexOf(DONE_SENTINEL);
|
|
@@ -184,7 +269,9 @@ export function checkPositionGuard(opts) {
|
|
|
184
269
|
* Open a PTY and write the update command to it. Returns as soon as the command
|
|
185
270
|
* is running — the caller polls `readTerminalText` for output.
|
|
186
271
|
*/
|
|
187
|
-
export async function startConnectorUpdate(rpc, opts
|
|
272
|
+
export async function startConnectorUpdate(rpc, opts,
|
|
273
|
+
/** Exact connector release to install — from fetchPinnedConnectVersion, nowhere else. */
|
|
274
|
+
version) {
|
|
188
275
|
const blocked = checkPositionGuard(opts);
|
|
189
276
|
if (blocked) {
|
|
190
277
|
logger.info(TAG, `update refused: ${opts.openPositionCount} open position(s), no acknowledgement`);
|
|
@@ -214,7 +301,7 @@ export async function startConnectorUpdate(rpc, opts) {
|
|
|
214
301
|
logger.info(TAG, `terminal opened (shell=${opened.shell} cwd=${opened.cwd} confined=${opened.confined})`);
|
|
215
302
|
try {
|
|
216
303
|
// `\r` submits the line — terminal.input is raw keystrokes, not a command API.
|
|
217
|
-
await rpc('terminal.input', { sessionId, data: `${buildUpdateCommandLine()}\r` });
|
|
304
|
+
await rpc('terminal.input', { sessionId, data: `${buildUpdateCommandLine(version)}\r` });
|
|
218
305
|
}
|
|
219
306
|
catch (err) {
|
|
220
307
|
const reason = err instanceof Error ? err.message : String(err);
|
|
@@ -231,7 +318,9 @@ export async function startConnectorUpdate(rpc, opts) {
|
|
|
231
318
|
message: 'Update started. The agent restarts when it finishes, so the dashboard will reconnect on its own.',
|
|
232
319
|
};
|
|
233
320
|
}
|
|
234
|
-
/** Read the current screen contents. Returns null when the
|
|
321
|
+
/** Read the current screen contents via `terminal.text`. Returns null when the
|
|
322
|
+
* session is gone. Prefer `createTerminalReader` — `terminal.text` no longer
|
|
323
|
+
* exists on OpenClaw ≥ 2026.8 (see there). */
|
|
235
324
|
export async function readTerminalText(rpc, sessionId) {
|
|
236
325
|
try {
|
|
237
326
|
const res = await rpc('terminal.text', { sessionId });
|
|
@@ -250,6 +339,122 @@ export async function readTerminalText(rpc, sessionId) {
|
|
|
250
339
|
return null;
|
|
251
340
|
}
|
|
252
341
|
}
|
|
342
|
+
/** The gateway's reply to a method it does not have. A capability fact about
|
|
343
|
+
* the box, not a sign the box went away. */
|
|
344
|
+
export function isUnknownMethodError(err) {
|
|
345
|
+
return /unknown method/i.test(err instanceof Error ? err.message : String(err));
|
|
346
|
+
}
|
|
347
|
+
/** Reduce raw PTY output to the plain text a human (or the marker scan) would
|
|
348
|
+
* read — what the removed `terminal.text` used to do server-side. Handles the
|
|
349
|
+
* families a shell + npm + the installer emit: CSI (incl. private parameter
|
|
350
|
+
* bytes `<=>?:` and 8-bit `\x9b`), OSC (BEL- or ST-terminated), charset
|
|
351
|
+
* designations (`ESC ( B`), DEC save/restore/keypad (`ESC 7`, `ESC 8`,
|
|
352
|
+
* `ESC =`, `ESC >`), then carriage-return overwrites (progress bars redraw a
|
|
353
|
+
* line with `\r`; keep the last rendering) and stray C0 controls. */
|
|
354
|
+
export function stripAnsi(s) {
|
|
355
|
+
return (s
|
|
356
|
+
// npm's spinner redraws its line with "cursor to column 1" (CSI 1G) +
|
|
357
|
+
// "clear line" instead of \r; make it an overwrite point too, so the
|
|
358
|
+
// pane shows the last frame rather than a wall of braille glyphs.
|
|
359
|
+
// eslint-disable-next-line no-control-regex
|
|
360
|
+
.replace(/(?:\u001b\[|\u009b)0?1?G/g, '\r')
|
|
361
|
+
// eslint-disable-next-line no-control-regex
|
|
362
|
+
.replace(/(?:\u001b\[|\u009b)[0-?]*[ -/]*[@-~]/g, '') // CSI
|
|
363
|
+
// eslint-disable-next-line no-control-regex
|
|
364
|
+
.replace(/\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g, '') // OSC
|
|
365
|
+
// eslint-disable-next-line no-control-regex
|
|
366
|
+
.replace(/\u001b[()*+][0-~]/g, '') // charset designation, e.g. ESC ( B
|
|
367
|
+
// eslint-disable-next-line no-control-regex
|
|
368
|
+
.replace(/\u001b[@-Z\\-_=>78]/g, '') // lone ESC + final (Fe / Fp)
|
|
369
|
+
.replace(/\r+\n/g, '\n') // CRLF → LF
|
|
370
|
+
.replace(/(^|\n)[^\n]*\r(?=[^\n])/g, '$1') // `\r` overwrite: keep what came after
|
|
371
|
+
.replace(/\r/g, '')
|
|
372
|
+
// eslint-disable-next-line no-control-regex
|
|
373
|
+
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/g, '') // other C0 / DEL
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Reads a PTY's output on any OpenClaw that has `terminal.open` at all.
|
|
378
|
+
*
|
|
379
|
+
* OpenClaw's 2026.7 terminal family offered two reads — `terminal.text` (the
|
|
380
|
+
* rendered screen) and `terminal.attach` (the raw replay `buffer`) — and
|
|
381
|
+
* REMOVED `terminal.text` in 2026.8 (gateway-protocol CHANGELOG, #121387). A
|
|
382
|
+
* bridge that only knew `terminal.text` got `unknown method` on every poll
|
|
383
|
+
* from 2026.8.1 on, counted the two rejections as the gateway dying, and
|
|
384
|
+
* reported "restarting" ~3 s into every one-click update with no output —
|
|
385
|
+
* while the installer kept running unwatched in a PTY that the dropped admin
|
|
386
|
+
* session left to be reaped. So: `terminal.attach` first (it exists wherever
|
|
387
|
+
* `terminal.open` does), `terminal.text` for a gateway that answers
|
|
388
|
+
* `unknown method` to attach, and an unknown-method reply is NEVER a dead read.
|
|
389
|
+
*/
|
|
390
|
+
export function createTerminalReader(rpc) {
|
|
391
|
+
let attachSupported = null; // null = not yet probed
|
|
392
|
+
let textSupported = null;
|
|
393
|
+
let method = null;
|
|
394
|
+
const viaAttach = async (sessionId) => {
|
|
395
|
+
try {
|
|
396
|
+
const res = (await rpc('terminal.attach', { sessionId }));
|
|
397
|
+
const buffer = res && typeof res === 'object' && typeof res.buffer === 'string' ? res.buffer : '';
|
|
398
|
+
return stripAnsi(buffer);
|
|
399
|
+
}
|
|
400
|
+
catch (err) {
|
|
401
|
+
return isUnknownMethodError(err) ? 'unsupported' : null;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
const viaText = async (sessionId) => {
|
|
405
|
+
try {
|
|
406
|
+
const res = await rpc('terminal.text', { sessionId });
|
|
407
|
+
if (typeof res === 'string')
|
|
408
|
+
return res;
|
|
409
|
+
if (res && typeof res === 'object') {
|
|
410
|
+
const t = res;
|
|
411
|
+
if (typeof t.text === 'string')
|
|
412
|
+
return t.text;
|
|
413
|
+
if (typeof t.data === 'string')
|
|
414
|
+
return t.data;
|
|
415
|
+
}
|
|
416
|
+
return '';
|
|
417
|
+
}
|
|
418
|
+
catch (err) {
|
|
419
|
+
return isUnknownMethodError(err) ? 'unsupported' : null;
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
return {
|
|
423
|
+
get method() {
|
|
424
|
+
return method;
|
|
425
|
+
},
|
|
426
|
+
get unreadable() {
|
|
427
|
+
return attachSupported === false && textSupported === false;
|
|
428
|
+
},
|
|
429
|
+
async read(sessionId) {
|
|
430
|
+
if (attachSupported !== false) {
|
|
431
|
+
const r = await viaAttach(sessionId);
|
|
432
|
+
if (r !== 'unsupported') {
|
|
433
|
+
attachSupported = true;
|
|
434
|
+
if (r !== null)
|
|
435
|
+
method = 'terminal.attach';
|
|
436
|
+
return r;
|
|
437
|
+
}
|
|
438
|
+
attachSupported = false;
|
|
439
|
+
logger.info(TAG, 'terminal.attach is not available on this gateway — reading via terminal.text');
|
|
440
|
+
}
|
|
441
|
+
if (textSupported !== false) {
|
|
442
|
+
const r = await viaText(sessionId);
|
|
443
|
+
if (r !== 'unsupported') {
|
|
444
|
+
textSupported = true;
|
|
445
|
+
if (r !== null)
|
|
446
|
+
method = 'terminal.text';
|
|
447
|
+
return r;
|
|
448
|
+
}
|
|
449
|
+
textSupported = false;
|
|
450
|
+
}
|
|
451
|
+
// Neither read exists: the gateway is alive but we cannot watch the PTY
|
|
452
|
+
// (`unreadable` tells the loop this null is not the restart).
|
|
453
|
+
logger.warn(TAG, 'neither terminal.attach nor terminal.text is available on this gateway — cannot watch the update');
|
|
454
|
+
return null;
|
|
455
|
+
},
|
|
456
|
+
};
|
|
457
|
+
}
|
|
253
458
|
/** Best-effort PTY cleanup. Never throws — cleanup failure must not mask an outcome. */
|
|
254
459
|
export async function closeTerminal(rpc, sessionId) {
|
|
255
460
|
await rpc('terminal.close', { sessionId }).catch(() => undefined);
|
|
@@ -263,7 +468,7 @@ export function describeMissingAdminScope(granted) {
|
|
|
263
468
|
ok: false,
|
|
264
469
|
status: 'blocked',
|
|
265
470
|
message: `This gateway did not grant the connector the operator.admin scope it needs to open a terminal (granted: ${list}). `
|
|
266
|
-
+
|
|
471
|
+
+ `One-click updates are unavailable on this box — ${manualUpdateHint()}.`,
|
|
267
472
|
};
|
|
268
473
|
}
|
|
269
474
|
/** Connect a fresh admin-scoped client and wait for hello-ok. Resolves with the
|
|
@@ -308,11 +513,26 @@ export async function runConnectorUpdate(rpc, sessionId, emit, opts = {}) {
|
|
|
308
513
|
// Generous: an npm install on a small VPS is slow (240 × 1.5 s = 6 min).
|
|
309
514
|
const maxPolls = opts.maxPolls ?? 240;
|
|
310
515
|
const sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
516
|
+
const reader = opts.reader ?? createTerminalReader(rpc);
|
|
311
517
|
let lastEmitted = '';
|
|
312
518
|
let consecutiveDeadReads = 0;
|
|
313
519
|
for (let i = 0; i < maxPolls; i++) {
|
|
314
520
|
await sleep(pollMs);
|
|
315
|
-
const screen = await
|
|
521
|
+
const screen = await reader.read(sessionId);
|
|
522
|
+
if (screen === null && reader.unreadable) {
|
|
523
|
+
// Alive but unwatchable — not a restart, not a completion. Leave the PTY
|
|
524
|
+
// running (the installer is in it) and say exactly that.
|
|
525
|
+
const outcome = {
|
|
526
|
+
ok: false,
|
|
527
|
+
status: 'failed',
|
|
528
|
+
sessionId,
|
|
529
|
+
output: lastEmitted,
|
|
530
|
+
message: 'The update was started, but this gateway offers no way to watch the terminal (neither terminal.attach nor '
|
|
531
|
+
+ 'terminal.text), so its outcome cannot be reported here. Check the plugin version notice on the dashboard in a few minutes.',
|
|
532
|
+
};
|
|
533
|
+
emit(outcome);
|
|
534
|
+
return outcome;
|
|
535
|
+
}
|
|
316
536
|
if (screen !== null)
|
|
317
537
|
consecutiveDeadReads = 0;
|
|
318
538
|
else if (++consecutiveDeadReads < 2)
|
|
@@ -337,15 +557,25 @@ export async function runConnectorUpdate(rpc, sessionId, emit, opts = {}) {
|
|
|
337
557
|
if (isCredibleCompletion(screen)) {
|
|
338
558
|
const { exitCode } = parseDoneSentinel(screen);
|
|
339
559
|
const ok = exitCode === 0;
|
|
560
|
+
// Exit 0 + the installer's own "not restarted" verdict: the files are in
|
|
561
|
+
// place but the OLD gateway is still running (a Docker box, or any
|
|
562
|
+
// unmanaged gateway the CLI cannot signal). Say so — "the agent restarts
|
|
563
|
+
// to load it" would be false, and no restart is coming from this side.
|
|
564
|
+
const restartRequired = ok && installerReportedNoRestart(screen);
|
|
340
565
|
const outcome = {
|
|
341
566
|
ok,
|
|
342
567
|
status: 'completed',
|
|
343
568
|
sessionId,
|
|
344
569
|
exitCode,
|
|
345
570
|
output: screen,
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
571
|
+
...(restartRequired ? { restartRequired: true } : {}),
|
|
572
|
+
message: !ok
|
|
573
|
+
? `The updater exited with code ${exitCode}. The connector was left as it was.`
|
|
574
|
+
: restartRequired
|
|
575
|
+
? 'Connector files updated, but the gateway was NOT restarted, so the previous version is still running. '
|
|
576
|
+
+ 'If OpenClaw runs in Docker, restart the container from the host machine (docker restart <container>); '
|
|
577
|
+
+ 'otherwise restart OpenClaw. The new version loads then.'
|
|
578
|
+
: 'Connector updated. The agent restarts to load it.',
|
|
349
579
|
};
|
|
350
580
|
emit(outcome);
|
|
351
581
|
await closeTerminal(rpc, sessionId);
|
|
@@ -261,10 +261,11 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
261
261
|
* Operator-only. Update the ReefClaw connector on this box to the latest
|
|
262
262
|
* published version.
|
|
263
263
|
*
|
|
264
|
-
* Runs
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
264
|
+
* Runs the connect installer over the gateway's PTY, pinned to the exact
|
|
265
|
+
* connector release ReefClaw's public release endpoint reports. The
|
|
266
|
+
* RPC carries no command/version/args parameter and never should — the
|
|
267
|
+
* version is looked up server-side by this process, never taken from the
|
|
268
|
+
* caller (see providers/connector-update.ts).
|
|
268
269
|
*
|
|
269
270
|
* The installer restarts the gateway when it finishes, which kills both the
|
|
270
271
|
* PTY and this process's own transport. That is the SUCCESS path: we report
|
|
@@ -300,18 +301,15 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
300
301
|
private startToolRetry;
|
|
301
302
|
private createPoller;
|
|
302
303
|
private wireWsEvents;
|
|
303
|
-
/**
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
*
|
|
307
|
-
* the
|
|
308
|
-
*
|
|
309
|
-
|
|
310
|
-
* only when it demonstrably withheld the one we need. On the supported
|
|
311
|
-
* range the scope survives and nothing is written. */
|
|
312
|
-
private deviceIdentityRelaxationApplied;
|
|
304
|
+
/** The gateway withheld `operator.write` from this connection (or rejected
|
|
305
|
+
* the handshake for missing device identity). The connector used to react
|
|
306
|
+
* by writing OpenClaw's legacy auth-relaxation flags itself (2026-07-29 →
|
|
307
|
+
* 2026-09-19). It no longer touches the gateway's auth settings at all: it
|
|
308
|
+
* reports the exact manual remedy once per process and leaves the decision
|
|
309
|
+
* to the operator. */
|
|
310
|
+
private writeScopeRemedyReported;
|
|
313
311
|
/** Handshake rejected outright for missing device identity (see
|
|
314
|
-
* isDeviceIdentityRejection). Same
|
|
312
|
+
* isDeviceIdentityRejection). Same report as the withheld-write-scope
|
|
315
313
|
* case, keyed on the rejection instead of on hello-ok scopes. */
|
|
316
314
|
private onHandshakeRejectedForDeviceIdentity;
|
|
317
315
|
private checkGrantedScopes;
|
|
@@ -354,6 +352,14 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
354
352
|
*/
|
|
355
353
|
private emitSyntheticFill;
|
|
356
354
|
private onPollerBalance;
|
|
355
|
+
/**
|
|
356
|
+
* Adopt the plugin-provided Day-P&L anchor whenever it differs from ours.
|
|
357
|
+
* Shared by the 10 s balance poll and the reconnect snapshot so the two can
|
|
358
|
+
* never disagree about which anchor is current. No-op for a missing / zero /
|
|
359
|
+
* garbage value (old plugin, torn response) — the self-seed fallback in
|
|
360
|
+
* trySetSessionStartNav covers plugins that emit nothing.
|
|
361
|
+
*/
|
|
362
|
+
private syncPluginSessionNav;
|
|
357
363
|
/**
|
|
358
364
|
* Set session start NAV once both balance AND positions have been received.
|
|
359
365
|
* Checks persisted file first — if today's NAV was already captured in a
|