@reefclaw/openclaw-plugin 0.1.48 → 0.1.50
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 +10 -6
- package/bridge/bridge.js +22 -16
- package/bridge/gateway/gateway-ws-client.d.ts +79 -1
- package/bridge/gateway/gateway-ws-client.js +99 -5
- package/bridge/gateway/heartbeat-cron.d.ts +64 -0
- package/bridge/gateway/heartbeat-cron.js +150 -1
- package/bridge/provider.d.ts +12 -0
- package/bridge/providers/connector-update-direct.d.ts +3 -0
- package/bridge/providers/connector-update-direct.js +11 -1
- package/bridge/providers/connector-update-openclaw.d.ts +268 -0
- package/bridge/providers/connector-update-openclaw.js +772 -0
- package/bridge/providers/connector-update.d.ts +115 -1
- package/bridge/providers/connector-update.js +228 -13
- package/bridge/providers/gateway.d.ts +52 -10
- package/bridge/providers/gateway.js +243 -34
- package/bridge/utils/skill-version.d.ts +6 -0
- package/bridge/utils/skill-version.js +10 -0
- package/config/first-start-venue.d.ts +147 -0
- package/config/first-start-venue.js +400 -0
- package/config/plugin-config-io.d.ts +9 -2
- package/config/plugin-config-io.js +29 -5
- package/connector-supervisor.d.ts +20 -0
- package/connector-supervisor.js +27 -1
- package/index.js +36 -1
- package/openclaw.plugin.json +333 -1
- package/package.json +1 -1
- package/release-integrity.json +10 -0
- package/release-notes.json +3 -1
- package/signals/stop-rules.d.ts +13 -0
- package/signals/stop-rules.js +35 -6
- package/signals/strategy-adapter.js +25 -6
- package/skills/reefclaw/SKILL.md +21 -8
- package/tools/assessment-validation.d.ts +10 -2
- package/tools/assessment-validation.js +19 -5
- package/tools/create-order.d.ts +4 -0
- package/tools/create-order.js +15 -0
- package/tools/intel-cache.d.ts +14 -0
- package/tools/intel-cache.js +59 -0
- package/tools/venue-quote-hint.d.ts +49 -0
- package/tools/venue-quote-hint.js +200 -0
|
@@ -18,6 +18,29 @@ export declare function buildUpdateCommandLine(version: string): string;
|
|
|
18
18
|
* pinned command from a shell on the box. `version` is unknown when the
|
|
19
19
|
* refusal happened before the release lookup. */
|
|
20
20
|
export declare function manualUpdateHint(version?: string): string;
|
|
21
|
+
/** The package ClawHub / npm serve the plugin under (plugin-package/package.json).
|
|
22
|
+
* Fixed — the OpenClaw update path (connector-update-openclaw.ts) installs
|
|
23
|
+
* nothing else, and a copy of any other package is never touched. */
|
|
24
|
+
export declare const OPENCLAW_PLUGIN_PACKAGE = "@reefclaw/openclaw-plugin";
|
|
25
|
+
/** The plugin id in openclaw.plugin.json. Fixed. */
|
|
26
|
+
export declare const OPENCLAW_PLUGIN_ID = "reefclaw-paper-trading";
|
|
27
|
+
/** The one line that updates a copy OpenClaw installed, run by the owner on
|
|
28
|
+
* the box. `install … --force` and not `openclaw plugins update`: an install
|
|
29
|
+
* pinned to a version (spec `clawhub:<pkg>@<v>`, which is what the no-terminal
|
|
30
|
+
* route records) keeps that version on `update` ("already at <v>");
|
|
31
|
+
* `--force` runs the install in update mode and replaces the copy. Same line
|
|
32
|
+
* as the dashboard's ClawHub steps (webapp plugin-update.ts
|
|
33
|
+
* buildClawHubUpdateInstruction). */
|
|
34
|
+
export declare function openClawManualUpdateLine(version?: string | null): string;
|
|
35
|
+
/** Manual-fallback copy for a copy OpenClaw installed: the pinned `--force`
|
|
36
|
+
* line, then a restart — the new code runs only in a fresh gateway process. */
|
|
37
|
+
export declare function openClawManualUpdateHint(version?: string | null): string;
|
|
38
|
+
/** The same for a copy OpenClaw installed from npm. It stays on npm (the
|
|
39
|
+
* `npm:` locator — installer/src/existing-install.ts NPM_UPDATE_COMMAND):
|
|
40
|
+
* pointing it at ClawHub would silently change where the box's plugin comes
|
|
41
|
+
* from. */
|
|
42
|
+
export declare function openClawNpmManualUpdateLine(version?: string | null): string;
|
|
43
|
+
export declare function openClawNpmManualUpdateHint(version?: string | null): string;
|
|
21
44
|
export interface PinnedVersionLookup {
|
|
22
45
|
/** Webapp base URL; defaults to REEFCLAW_API_URL, then production. */
|
|
23
46
|
webappUrl?: string;
|
|
@@ -30,6 +53,22 @@ export type PinnedVersionResult = {
|
|
|
30
53
|
ok: false;
|
|
31
54
|
outcome: ConnectorUpdateOutcome;
|
|
32
55
|
};
|
|
56
|
+
/** Both releases `/api/release` vouches for, each exact or null. At least one
|
|
57
|
+
* is exact whenever ok is true. */
|
|
58
|
+
export type PinnedReleaseResult = {
|
|
59
|
+
ok: true;
|
|
60
|
+
connectVersion: string | null;
|
|
61
|
+
pluginVersion: string | null;
|
|
62
|
+
} | {
|
|
63
|
+
ok: false;
|
|
64
|
+
outcome: ConnectorUpdateOutcome;
|
|
65
|
+
};
|
|
66
|
+
/** The installer path needs an exact connector release; the release lookup
|
|
67
|
+
* answered without one. Refused, never an unpinned install. */
|
|
68
|
+
export declare function describeUnconfirmedConnectVersion(): ConnectorUpdateOutcome;
|
|
69
|
+
/** The OpenClaw path needs an exact plugin release; the lookup answered
|
|
70
|
+
* without one (or the caller has none). Refused, never an unpinned install. */
|
|
71
|
+
export declare function describeUnconfirmedPluginVersion(): ConnectorUpdateOutcome;
|
|
33
72
|
/**
|
|
34
73
|
* Ask ReefClaw which connector release an update installs: `connectVersion` on
|
|
35
74
|
* the PUBLIC `/api/release` endpoint, baked by the webapp at build from the
|
|
@@ -41,6 +80,16 @@ export type PinnedVersionResult = {
|
|
|
41
80
|
* unpinned install.
|
|
42
81
|
*/
|
|
43
82
|
export declare function fetchPinnedConnectVersion(opts: PinnedVersionLookup): Promise<PinnedVersionResult>;
|
|
83
|
+
/**
|
|
84
|
+
* The same public `/api/release` GET, read for BOTH releases it publishes:
|
|
85
|
+
* `connectVersion` (what the connect installer path runs) and `pluginVersion`
|
|
86
|
+
* (the @reefclaw/openclaw-plugin release OpenClaw's own update path installs —
|
|
87
|
+
* connector-update-openclaw.ts). One request; each value is kept only when it
|
|
88
|
+
* is an exact MAJOR.MINOR.PATCH, and the caller refuses the path whose value
|
|
89
|
+
* is missing. A failed request, or neither value exact, refuses outright —
|
|
90
|
+
* before any gateway call.
|
|
91
|
+
*/
|
|
92
|
+
export declare function fetchPinnedRelease(opts: PinnedVersionLookup): Promise<PinnedReleaseResult>;
|
|
44
93
|
/** Minimal RPC surface this module needs (injected — keeps it unit-testable). */
|
|
45
94
|
export type TerminalRpc = (method: string, params: Record<string, unknown>) => Promise<unknown>;
|
|
46
95
|
export type ConnectorUpdateStatus =
|
|
@@ -101,6 +150,57 @@ export declare function classifyTransportLoss(started: boolean): ConnectorUpdate
|
|
|
101
150
|
* installed), so completion is inspected for it. Pinned across packages. */
|
|
102
151
|
export declare const INSTALLER_NOT_RESTARTED_MARKER = "GATEWAY NOT RESTARTED";
|
|
103
152
|
export declare function installerReportedNoRestart(screen: string | null | undefined): boolean;
|
|
153
|
+
/** What the installer prints on the closing line of every duplicate-install
|
|
154
|
+
* refusal (installer/src/existing-install.ts ALREADY_INSTALLED_MARKER): the
|
|
155
|
+
* box's plugin was installed by OpenClaw itself (ClawHub via the plugins
|
|
156
|
+
* tool / Control UI / chat, npm, another folder), so the connect installer
|
|
157
|
+
* changed nothing. The FULL installer exits 0 on it for a ClawHub / npm copy
|
|
158
|
+
* (1 otherwise); the --files-only installer always exits 1. Either way it is
|
|
159
|
+
* checked BEFORE the exit code: mapped by exit code alone, the PTY path said
|
|
160
|
+
* "Connector updated. The agent restarts to load it." (a false green — nothing
|
|
161
|
+
* was updated and no restart was coming) and the direct path "The updater
|
|
162
|
+
* exited with code 1". Pinned across packages
|
|
163
|
+
* (providers/__tests__/installer-markers-pin.test.ts). */
|
|
164
|
+
export declare const ALREADY_INSTALLED_MARKER = "REEFCLAW ALREADY INSTALLED ELSEWHERE";
|
|
165
|
+
export declare function installerReportedAlreadyInstalled(output: string | null | undefined): boolean;
|
|
166
|
+
/** One fragment of each refusal headline the installer prints
|
|
167
|
+
* (installer/src/existing-install.ts foreignInstallMessage), pinned against
|
|
168
|
+
* the installer's source by installer-markers-pin.test.ts (the webapp keeps
|
|
169
|
+
* the same three in plugin-update.ts INSTALLER_REFUSAL_HEADLINES). Matched
|
|
170
|
+
* with all whitespace removed: a PTY screen (terminal.text, 120 columns)
|
|
171
|
+
* breaks a long headline wherever its row ends. */
|
|
172
|
+
export declare const INSTALLER_REFUSAL_HEADLINE_FRAGMENTS: {
|
|
173
|
+
readonly clawhub: "is already installed from ClawHub on this machine";
|
|
174
|
+
readonly npm: "installed through OpenClaw from npm";
|
|
175
|
+
readonly other: "adding its own copy would load a second copy of the plugin";
|
|
176
|
+
};
|
|
177
|
+
export type InstalledElsewhereOrigin = keyof typeof INSTALLER_REFUSAL_HEADLINE_FRAGMENTS | 'unknown';
|
|
178
|
+
/** How the copy the installer refused got there, from its headline. */
|
|
179
|
+
export declare function installedElsewhereOrigin(output: string | null | undefined): InstalledElsewhereOrigin;
|
|
180
|
+
/** The verdict for an installer run that refused on ALREADY_INSTALLED_MARKER.
|
|
181
|
+
* `blocked`: nothing changed on the box, and nothing may be restarted onto
|
|
182
|
+
* it — the caller never asks the gateway to restart after this. The manual
|
|
183
|
+
* line follows the origin the installer's headline names: a ClawHub copy
|
|
184
|
+
* (and an unrecognised headline) gets the ClawHub line, an npm copy stays on
|
|
185
|
+
* npm, and any other copy (a copied folder, a folder on the load path — it
|
|
186
|
+
* outranks a ClawHub install, which would then never load) gets no install
|
|
187
|
+
* line at all: only the owner can decide which copy stays. */
|
|
188
|
+
export declare function describeInstalledElsewhere(input: {
|
|
189
|
+
exitCode: number | null;
|
|
190
|
+
output: string;
|
|
191
|
+
sessionId?: string;
|
|
192
|
+
/** Exact plugin release for the manual line, when known. */
|
|
193
|
+
pluginVersion?: string | null;
|
|
194
|
+
}): ConnectorUpdateOutcome;
|
|
195
|
+
/** Take the slot, or null when an update is already running. The returned
|
|
196
|
+
* function releases it (idempotent; a stale release never frees a newer run's
|
|
197
|
+
* slot). */
|
|
198
|
+
export declare function tryBeginConnectorUpdate(now?: number): (() => void) | null;
|
|
199
|
+
export declare function isConnectorUpdateInFlight(): boolean;
|
|
200
|
+
/** Tests only: forget any slot a previous test's background run still holds. */
|
|
201
|
+
export declare function resetConnectorUpdateLockForTests(): void;
|
|
202
|
+
/** A second connector.update while one is running. Nothing new was started. */
|
|
203
|
+
export declare function describeUpdateAlreadyRunning(): ConnectorUpdateOutcome;
|
|
104
204
|
/** Extract the exit code that follows the DONE sentinel, if it has appeared. */
|
|
105
205
|
export declare function parseDoneSentinel(screen: string): {
|
|
106
206
|
done: boolean;
|
|
@@ -221,11 +321,22 @@ export interface GatewayRestartReply {
|
|
|
221
321
|
}>;
|
|
222
322
|
summary?: string;
|
|
223
323
|
};
|
|
324
|
+
/** 2026.9.6 shape (no `status`): the restart record itself. */
|
|
325
|
+
signal?: unknown;
|
|
326
|
+
coalesced?: unknown;
|
|
224
327
|
}
|
|
225
328
|
/** Pure: map the RPC reply / error onto an operator outcome.
|
|
226
329
|
* `scheduled` + `coalesced` = the restart is happening now; `deferred` = the
|
|
227
330
|
* gateway restarts as soon as its active agent run drains (still a promise
|
|
228
|
-
* the gateway itself made, so it is `restarting`, with the reason shown).
|
|
331
|
+
* the gateway itself made, so it is `restarting`, with the reason shown).
|
|
332
|
+
*
|
|
333
|
+
* OpenClaw 2026.9.6 answers with the restart record itself and NO status:
|
|
334
|
+
* `{pid, signal:'SIGUSR2', reason:'update.run', mode:'emit',
|
|
335
|
+
* cooldownMsApplied, delayMs, coalesced, emitHooksQueued}` — and the process
|
|
336
|
+
* was replaced right after (canary box, 2026-09-30). A signal the gateway
|
|
337
|
+
* says it emitted, or a restart it coalesced into one already pending, is the
|
|
338
|
+
* restart; read as "unrecognised" it reported every successful 9.6 restart
|
|
339
|
+
* as refused. An explicit ok:false, or neither field, is still a failure. */
|
|
229
340
|
export declare function classifyGatewayRestartReply(reply: unknown): ConnectorUpdateOutcome;
|
|
230
341
|
/** Map an RPC error from `gateway.restart.request` onto an outcome. */
|
|
231
342
|
export declare function describeRestartRpcFailure(err: unknown): ConnectorUpdateOutcome;
|
|
@@ -260,6 +371,9 @@ export interface RunOptions {
|
|
|
260
371
|
sleep?: (ms: number) => Promise<void>;
|
|
261
372
|
/** Injected for tests; defaults to createTerminalReader(rpc). */
|
|
262
373
|
reader?: TerminalReader;
|
|
374
|
+
/** Exact plugin release, for the manual line of an "installed elsewhere"
|
|
375
|
+
* verdict only. Never reaches the command. */
|
|
376
|
+
pluginVersion?: string | null;
|
|
263
377
|
}
|
|
264
378
|
/**
|
|
265
379
|
* Poll the PTY and emit progress until the command finishes or the gateway
|
|
@@ -11,6 +11,13 @@
|
|
|
11
11
|
// OpenClaw version a code-plugin can only be installed/updated from a shell.
|
|
12
12
|
// `terminal.*` is the gateway's shell.
|
|
13
13
|
//
|
|
14
|
+
// (2026-09-30) That changed for ONE install shape: OpenClaw >= 2026.9.5 has a
|
|
15
|
+
// `plugins.install` RPC with an update mode, and a copy OpenClaw installed
|
|
16
|
+
// itself from ClawHub (the no-terminal onboarding route) is updated through it
|
|
17
|
+
// — connector-update-openclaw.ts. The provider inspects the install record
|
|
18
|
+
// first and only comes here for a copy this installer placed; the installer
|
|
19
|
+
// refuses to touch an OpenClaw-installed copy (ALREADY_INSTALLED_MARKER below).
|
|
20
|
+
//
|
|
14
21
|
// ★★ SECURITY — READ BEFORE CHANGING ANYTHING IN THIS FILE ★★
|
|
15
22
|
// This module can run a command on the trader's machine, initiated from our
|
|
16
23
|
// dashboard. That is only acceptable because the command is a FIXED CONSTANT:
|
|
@@ -94,6 +101,71 @@ export function manualUpdateHint(version) {
|
|
|
94
101
|
? `run this from a shell on the box: npx -y ${CONNECT_PACKAGE}@${version}`
|
|
95
102
|
: `run the ReefClaw connect installer from a shell on the box, pinned to the version the dashboard's update notice shows (${CONNECT_PACKAGE}@<version>)`;
|
|
96
103
|
}
|
|
104
|
+
// ---- A copy OpenClaw installed itself ----------------------------------------
|
|
105
|
+
/** The package ClawHub / npm serve the plugin under (plugin-package/package.json).
|
|
106
|
+
* Fixed — the OpenClaw update path (connector-update-openclaw.ts) installs
|
|
107
|
+
* nothing else, and a copy of any other package is never touched. */
|
|
108
|
+
export const OPENCLAW_PLUGIN_PACKAGE = '@reefclaw/openclaw-plugin';
|
|
109
|
+
/** The plugin id in openclaw.plugin.json. Fixed. */
|
|
110
|
+
export const OPENCLAW_PLUGIN_ID = 'reefclaw-paper-trading';
|
|
111
|
+
/** The one line that updates a copy OpenClaw installed, run by the owner on
|
|
112
|
+
* the box. `install … --force` and not `openclaw plugins update`: an install
|
|
113
|
+
* pinned to a version (spec `clawhub:<pkg>@<v>`, which is what the no-terminal
|
|
114
|
+
* route records) keeps that version on `update` ("already at <v>");
|
|
115
|
+
* `--force` runs the install in update mode and replaces the copy. Same line
|
|
116
|
+
* as the dashboard's ClawHub steps (webapp plugin-update.ts
|
|
117
|
+
* buildClawHubUpdateInstruction). */
|
|
118
|
+
export function openClawManualUpdateLine(version) {
|
|
119
|
+
const v = typeof version === 'string' && isExactConnectVersion(version) ? version : '<version>';
|
|
120
|
+
return `openclaw plugins install clawhub:${OPENCLAW_PLUGIN_PACKAGE}@${v} --force`;
|
|
121
|
+
}
|
|
122
|
+
/** Manual-fallback copy for a copy OpenClaw installed: the pinned `--force`
|
|
123
|
+
* line, then a restart — the new code runs only in a fresh gateway process. */
|
|
124
|
+
export function openClawManualUpdateHint(version) {
|
|
125
|
+
const pinned = typeof version === 'string' && isExactConnectVersion(version);
|
|
126
|
+
return ('update it from a shell on the machine running OpenClaw (inside the container, if OpenClaw runs in Docker): '
|
|
127
|
+
+ `${openClawManualUpdateLine(version)}${pinned ? '' : " (<version> = the version the dashboard's update notice shows)"}, `
|
|
128
|
+
+ 'then restart OpenClaw (in Docker: docker restart <container> from the host)');
|
|
129
|
+
}
|
|
130
|
+
/** The same for a copy OpenClaw installed from npm. It stays on npm (the
|
|
131
|
+
* `npm:` locator — installer/src/existing-install.ts NPM_UPDATE_COMMAND):
|
|
132
|
+
* pointing it at ClawHub would silently change where the box's plugin comes
|
|
133
|
+
* from. */
|
|
134
|
+
export function openClawNpmManualUpdateLine(version) {
|
|
135
|
+
const v = typeof version === 'string' && isExactConnectVersion(version) ? version : '<version>';
|
|
136
|
+
return `openclaw plugins install npm:${OPENCLAW_PLUGIN_PACKAGE}@${v} --force`;
|
|
137
|
+
}
|
|
138
|
+
export function openClawNpmManualUpdateHint(version) {
|
|
139
|
+
const pinned = typeof version === 'string' && isExactConnectVersion(version);
|
|
140
|
+
return ('update it from a shell on the machine running OpenClaw (inside the container, if OpenClaw runs in Docker): '
|
|
141
|
+
+ `${openClawNpmManualUpdateLine(version)}${pinned ? '' : " (<version> = the version the dashboard's update notice shows)"}, `
|
|
142
|
+
+ 'then restart OpenClaw (in Docker: docker restart <container> from the host)');
|
|
143
|
+
}
|
|
144
|
+
/** The refusal every "which version?" failure ends in.
|
|
145
|
+
* `release`: the lookup itself failed — BEFORE the provider has asked
|
|
146
|
+
* OpenClaw who installed the copy, so no manual line is named: the connect
|
|
147
|
+
* installer's would be the wrong tool on a copy OpenClaw installed (it
|
|
148
|
+
* refuses, ALREADY_INSTALLED_MARKER), and the OpenClaw line the wrong one on
|
|
149
|
+
* the installer's own linked copy. `connector` / `plugin`: the route is
|
|
150
|
+
* known, so its own manual line is. */
|
|
151
|
+
function unconfirmedVersionOutcome(why, what) {
|
|
152
|
+
const lead = `Could not confirm the ${what === 'release' ? '' : `${what} `}version to install (${why}), so the update was not started — `
|
|
153
|
+
+ 'it only ever installs an exact, ReefClaw-confirmed release.';
|
|
154
|
+
const tail = what === 'release'
|
|
155
|
+
? ' Nothing changed on the box; try again shortly.'
|
|
156
|
+
: ` Try again shortly, or ${what === 'plugin' ? openClawManualUpdateHint() : manualUpdateHint()}.`;
|
|
157
|
+
return { ok: false, status: 'blocked', message: `${lead}${tail}` };
|
|
158
|
+
}
|
|
159
|
+
/** The installer path needs an exact connector release; the release lookup
|
|
160
|
+
* answered without one. Refused, never an unpinned install. */
|
|
161
|
+
export function describeUnconfirmedConnectVersion() {
|
|
162
|
+
return unconfirmedVersionOutcome('ReefClaw did not report an exact release version', 'connector');
|
|
163
|
+
}
|
|
164
|
+
/** The OpenClaw path needs an exact plugin release; the lookup answered
|
|
165
|
+
* without one (or the caller has none). Refused, never an unpinned install. */
|
|
166
|
+
export function describeUnconfirmedPluginVersion() {
|
|
167
|
+
return unconfirmedVersionOutcome('ReefClaw did not report an exact plugin release', 'plugin');
|
|
168
|
+
}
|
|
97
169
|
/**
|
|
98
170
|
* Ask ReefClaw which connector release an update installs: `connectVersion` on
|
|
99
171
|
* the PUBLIC `/api/release` endpoint, baked by the webapp at build from the
|
|
@@ -105,15 +177,24 @@ export function manualUpdateHint(version) {
|
|
|
105
177
|
* unpinned install.
|
|
106
178
|
*/
|
|
107
179
|
export async function fetchPinnedConnectVersion(opts) {
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
180
|
+
const release = await fetchPinnedRelease(opts);
|
|
181
|
+
if (!release.ok)
|
|
182
|
+
return release;
|
|
183
|
+
if (release.connectVersion === null)
|
|
184
|
+
return { ok: false, outcome: describeUnconfirmedConnectVersion() };
|
|
185
|
+
return { ok: true, version: release.connectVersion };
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The same public `/api/release` GET, read for BOTH releases it publishes:
|
|
189
|
+
* `connectVersion` (what the connect installer path runs) and `pluginVersion`
|
|
190
|
+
* (the @reefclaw/openclaw-plugin release OpenClaw's own update path installs —
|
|
191
|
+
* connector-update-openclaw.ts). One request; each value is kept only when it
|
|
192
|
+
* is an exact MAJOR.MINOR.PATCH, and the caller refuses the path whose value
|
|
193
|
+
* is missing. A failed request, or neither value exact, refuses outright —
|
|
194
|
+
* before any gateway call.
|
|
195
|
+
*/
|
|
196
|
+
export async function fetchPinnedRelease(opts) {
|
|
197
|
+
const refuse = (why) => ({ ok: false, outcome: unconfirmedVersionOutcome(why, 'release') });
|
|
117
198
|
const base = resolveWebappBaseUrl(opts.webappUrl);
|
|
118
199
|
try {
|
|
119
200
|
const doFetch = opts.fetchImpl ?? fetch;
|
|
@@ -138,10 +219,12 @@ export async function fetchPinnedConnectVersion(opts) {
|
|
|
138
219
|
}
|
|
139
220
|
noteWebappResponse(res, '/api/release', undefined, startedAt);
|
|
140
221
|
const body = (await res.json());
|
|
141
|
-
const
|
|
142
|
-
|
|
222
|
+
const connectVersion = isExactConnectVersion(body?.connectVersion) ? body.connectVersion : null;
|
|
223
|
+
const pluginVersion = isExactConnectVersion(body?.pluginVersion) ? body.pluginVersion : null;
|
|
224
|
+
if (connectVersion === null && pluginVersion === null) {
|
|
143
225
|
return refuse('ReefClaw did not report an exact release version');
|
|
144
|
-
|
|
226
|
+
}
|
|
227
|
+
return { ok: true, connectVersion, pluginVersion };
|
|
145
228
|
}
|
|
146
229
|
catch (err) {
|
|
147
230
|
return refuse(err instanceof Error ? err.message : String(err));
|
|
@@ -248,6 +331,110 @@ export const INSTALLER_NOT_RESTARTED_MARKER = 'GATEWAY NOT RESTARTED';
|
|
|
248
331
|
export function installerReportedNoRestart(screen) {
|
|
249
332
|
return typeof screen === 'string' && screen.includes(INSTALLER_NOT_RESTARTED_MARKER);
|
|
250
333
|
}
|
|
334
|
+
/** What the installer prints on the closing line of every duplicate-install
|
|
335
|
+
* refusal (installer/src/existing-install.ts ALREADY_INSTALLED_MARKER): the
|
|
336
|
+
* box's plugin was installed by OpenClaw itself (ClawHub via the plugins
|
|
337
|
+
* tool / Control UI / chat, npm, another folder), so the connect installer
|
|
338
|
+
* changed nothing. The FULL installer exits 0 on it for a ClawHub / npm copy
|
|
339
|
+
* (1 otherwise); the --files-only installer always exits 1. Either way it is
|
|
340
|
+
* checked BEFORE the exit code: mapped by exit code alone, the PTY path said
|
|
341
|
+
* "Connector updated. The agent restarts to load it." (a false green — nothing
|
|
342
|
+
* was updated and no restart was coming) and the direct path "The updater
|
|
343
|
+
* exited with code 1". Pinned across packages
|
|
344
|
+
* (providers/__tests__/installer-markers-pin.test.ts). */
|
|
345
|
+
export const ALREADY_INSTALLED_MARKER = 'REEFCLAW ALREADY INSTALLED ELSEWHERE';
|
|
346
|
+
export function installerReportedAlreadyInstalled(output) {
|
|
347
|
+
return typeof output === 'string' && output.includes(ALREADY_INSTALLED_MARKER);
|
|
348
|
+
}
|
|
349
|
+
/** One fragment of each refusal headline the installer prints
|
|
350
|
+
* (installer/src/existing-install.ts foreignInstallMessage), pinned against
|
|
351
|
+
* the installer's source by installer-markers-pin.test.ts (the webapp keeps
|
|
352
|
+
* the same three in plugin-update.ts INSTALLER_REFUSAL_HEADLINES). Matched
|
|
353
|
+
* with all whitespace removed: a PTY screen (terminal.text, 120 columns)
|
|
354
|
+
* breaks a long headline wherever its row ends. */
|
|
355
|
+
export const INSTALLER_REFUSAL_HEADLINE_FRAGMENTS = {
|
|
356
|
+
clawhub: 'is already installed from ClawHub on this machine',
|
|
357
|
+
npm: 'installed through OpenClaw from npm',
|
|
358
|
+
other: 'adding its own copy would load a second copy of the plugin',
|
|
359
|
+
};
|
|
360
|
+
/** How the copy the installer refused got there, from its headline. */
|
|
361
|
+
export function installedElsewhereOrigin(output) {
|
|
362
|
+
if (typeof output !== 'string')
|
|
363
|
+
return 'unknown';
|
|
364
|
+
const squash = (s) => s.replace(/\s+/g, '');
|
|
365
|
+
const text = squash(output);
|
|
366
|
+
for (const origin of ['clawhub', 'npm', 'other']) {
|
|
367
|
+
if (text.includes(squash(INSTALLER_REFUSAL_HEADLINE_FRAGMENTS[origin])))
|
|
368
|
+
return origin;
|
|
369
|
+
}
|
|
370
|
+
return 'unknown';
|
|
371
|
+
}
|
|
372
|
+
/** The verdict for an installer run that refused on ALREADY_INSTALLED_MARKER.
|
|
373
|
+
* `blocked`: nothing changed on the box, and nothing may be restarted onto
|
|
374
|
+
* it — the caller never asks the gateway to restart after this. The manual
|
|
375
|
+
* line follows the origin the installer's headline names: a ClawHub copy
|
|
376
|
+
* (and an unrecognised headline) gets the ClawHub line, an npm copy stays on
|
|
377
|
+
* npm, and any other copy (a copied folder, a folder on the load path — it
|
|
378
|
+
* outranks a ClawHub install, which would then never load) gets no install
|
|
379
|
+
* line at all: only the owner can decide which copy stays. */
|
|
380
|
+
export function describeInstalledElsewhere(input) {
|
|
381
|
+
const origin = installedElsewhereOrigin(input.output);
|
|
382
|
+
const message = origin === 'other'
|
|
383
|
+
? 'OpenClaw on this box already loads another copy of ReefClaw that the connect installer did not place, so the '
|
|
384
|
+
+ 'installer left it alone — nothing changed and no restart was requested. The installer\'s output says where '
|
|
385
|
+
+ 'that copy is and how to replace it with the installer\'s own.'
|
|
386
|
+
: 'ReefClaw on this box was installed through OpenClaw (ClawHub/npm), so the connect installer left it alone — '
|
|
387
|
+
+ 'nothing changed and no restart was requested. To update this copy, '
|
|
388
|
+
+ `${origin === 'npm' ? openClawNpmManualUpdateHint(input.pluginVersion) : openClawManualUpdateHint(input.pluginVersion)}.`;
|
|
389
|
+
return {
|
|
390
|
+
ok: false,
|
|
391
|
+
status: 'blocked',
|
|
392
|
+
exitCode: input.exitCode,
|
|
393
|
+
output: input.output,
|
|
394
|
+
...(input.sessionId ? { sessionId: input.sessionId } : {}),
|
|
395
|
+
message,
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
// ---- One update at a time --------------------------------------------------------
|
|
399
|
+
// Process-wide single-flight for connector.update. The dashboard's BUSY flag
|
|
400
|
+
// is per browser (useConnectorUpdate.ts), so a second tab or device can send a
|
|
401
|
+
// second connector.update while the first is still installing (34–59 s for a
|
|
402
|
+
// ClawHub install, minutes for an installer run). Two PTYs racing the same
|
|
403
|
+
// installer, or a second run's gateway restart landing in the middle of the
|
|
404
|
+
// first run's plugins.install (a restart replaces the process and kills the
|
|
405
|
+
// install mid-stage), is exactly what must not happen. Held from the moment a
|
|
406
|
+
// request passes its guards until its run ends, whichever way; a gateway
|
|
407
|
+
// restart ends the process and the lock with it.
|
|
408
|
+
let connectorUpdateInFlight = null;
|
|
409
|
+
/** Take the slot, or null when an update is already running. The returned
|
|
410
|
+
* function releases it (idempotent; a stale release never frees a newer run's
|
|
411
|
+
* slot). */
|
|
412
|
+
export function tryBeginConnectorUpdate(now = Date.now()) {
|
|
413
|
+
if (connectorUpdateInFlight)
|
|
414
|
+
return null;
|
|
415
|
+
const mine = { since: now };
|
|
416
|
+
connectorUpdateInFlight = mine;
|
|
417
|
+
return () => {
|
|
418
|
+
if (connectorUpdateInFlight === mine)
|
|
419
|
+
connectorUpdateInFlight = null;
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
export function isConnectorUpdateInFlight() {
|
|
423
|
+
return connectorUpdateInFlight !== null;
|
|
424
|
+
}
|
|
425
|
+
/** Tests only: forget any slot a previous test's background run still holds. */
|
|
426
|
+
export function resetConnectorUpdateLockForTests() {
|
|
427
|
+
connectorUpdateInFlight = null;
|
|
428
|
+
}
|
|
429
|
+
/** A second connector.update while one is running. Nothing new was started. */
|
|
430
|
+
export function describeUpdateAlreadyRunning() {
|
|
431
|
+
return {
|
|
432
|
+
ok: false,
|
|
433
|
+
status: 'blocked',
|
|
434
|
+
message: 'An update is already running on this box (started from this or another dashboard), so no second one was '
|
|
435
|
+
+ 'started. Wait for it to finish; its progress shows in the update notice.',
|
|
436
|
+
};
|
|
437
|
+
}
|
|
251
438
|
/** Extract the exit code that follows the DONE sentinel, if it has appeared. */
|
|
252
439
|
export function parseDoneSentinel(screen) {
|
|
253
440
|
const idx = screen.lastIndexOf(DONE_SENTINEL);
|
|
@@ -528,10 +715,26 @@ export async function openAdminGatewaySession(client, timeoutMs = 20_000) {
|
|
|
528
715
|
/** Pure: map the RPC reply / error onto an operator outcome.
|
|
529
716
|
* `scheduled` + `coalesced` = the restart is happening now; `deferred` = the
|
|
530
717
|
* gateway restarts as soon as its active agent run drains (still a promise
|
|
531
|
-
* the gateway itself made, so it is `restarting`, with the reason shown).
|
|
718
|
+
* the gateway itself made, so it is `restarting`, with the reason shown).
|
|
719
|
+
*
|
|
720
|
+
* OpenClaw 2026.9.6 answers with the restart record itself and NO status:
|
|
721
|
+
* `{pid, signal:'SIGUSR2', reason:'update.run', mode:'emit',
|
|
722
|
+
* cooldownMsApplied, delayMs, coalesced, emitHooksQueued}` — and the process
|
|
723
|
+
* was replaced right after (canary box, 2026-09-30). A signal the gateway
|
|
724
|
+
* says it emitted, or a restart it coalesced into one already pending, is the
|
|
725
|
+
* restart; read as "unrecognised" it reported every successful 9.6 restart
|
|
726
|
+
* as refused. An explicit ok:false, or neither field, is still a failure. */
|
|
532
727
|
export function classifyGatewayRestartReply(reply) {
|
|
533
728
|
const r = (reply && typeof reply === 'object' ? reply : {});
|
|
534
729
|
const status = typeof r.status === 'string' ? r.status : '';
|
|
730
|
+
const emittedSignal = typeof r.signal === 'string' && r.signal.length > 0;
|
|
731
|
+
if (!status && r.ok !== false && (emittedSignal || r.coalesced === true)) {
|
|
732
|
+
return {
|
|
733
|
+
ok: true,
|
|
734
|
+
status: 'restarting',
|
|
735
|
+
message: 'The gateway is restarting itself to load the new version. The dashboard reconnects on its own.',
|
|
736
|
+
};
|
|
737
|
+
}
|
|
535
738
|
if (status === 'scheduled' || status === 'coalesced') {
|
|
536
739
|
return {
|
|
537
740
|
ok: true,
|
|
@@ -669,6 +872,18 @@ export async function runConnectorUpdate(rpc, sessionId, emit, opts = {}) {
|
|
|
669
872
|
}
|
|
670
873
|
if (isCredibleCompletion(screen)) {
|
|
671
874
|
const { exitCode } = parseDoneSentinel(screen);
|
|
875
|
+
// ★ The installer's own "this copy is not mine" refusal comes FIRST,
|
|
876
|
+
// before the exit code (the full installer exits 0 on it for a ClawHub /
|
|
877
|
+
// npm copy) and before the NOT_RESTARTED mapping: nothing was installed,
|
|
878
|
+
// so "Connector updated" would be a false green, and a restart would load
|
|
879
|
+
// nothing new. No gateway.restart.request on this outcome, ever.
|
|
880
|
+
if (installerReportedAlreadyInstalled(screen)) {
|
|
881
|
+
await closeTerminal(rpc, sessionId);
|
|
882
|
+
const outcome = describeInstalledElsewhere({ exitCode, output: screen, sessionId, pluginVersion: opts.pluginVersion });
|
|
883
|
+
logger.info(TAG, `connector update: installer refused — ${ALREADY_INSTALLED_MARKER} (exit ${exitCode}); no restart`);
|
|
884
|
+
emit(outcome);
|
|
885
|
+
return outcome;
|
|
886
|
+
}
|
|
672
887
|
const ok = exitCode === 0;
|
|
673
888
|
// Exit 0 + the installer's own "not restarted" verdict: the files are in
|
|
674
889
|
// place but the OLD gateway is still running (a Docker box, or any
|
|
@@ -54,6 +54,13 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
54
54
|
private agentNameReadAtMs;
|
|
55
55
|
/** One-shot latch for the boot-time heartbeat-cron ensure (re-armed on failure). */
|
|
56
56
|
private heartbeatCronEnsureStarted;
|
|
57
|
+
/** Whether this install's FIRST market check may still run early:
|
|
58
|
+
* 'maybe' while the ensure is in flight, 'pending' from 'created' until
|
|
59
|
+
* runFirstHeartbeat settles, 'none' otherwise (deferToFirstMarketCheck). */
|
|
60
|
+
private firstBeatState;
|
|
61
|
+
/** The bridge's "instructions updated" notice, held while a first check is
|
|
62
|
+
* possible; sent only if that check does not start. Latest wins. */
|
|
63
|
+
private deferredSkillNotice;
|
|
57
64
|
/** Live heartbeat cadence (seconds), read from the OpenClaw cron store; cached 60s. */
|
|
58
65
|
private heartbeatSeconds?;
|
|
59
66
|
private heartbeatReadAtMs;
|
|
@@ -230,6 +237,20 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
230
237
|
received: boolean;
|
|
231
238
|
error?: string;
|
|
232
239
|
}>;
|
|
240
|
+
/** See OpenClawProvider.deferToFirstMarketCheck. Held while this install's
|
|
241
|
+
* first market check may still run early, or while an earlier held notice
|
|
242
|
+
* waits for the socket to come back; the latest notice wins. */
|
|
243
|
+
deferToFirstMarketCheck(send: () => void): boolean;
|
|
244
|
+
/** The first market check is settled: send a held notice ('send') or drop
|
|
245
|
+
* it ('drop': the check started, or may have, and reads the new
|
|
246
|
+
* instructions itself). A stopped provider sends nothing. If the socket is
|
|
247
|
+
* down right now (the settle may be BECAUSE it dropped), the notice stays
|
|
248
|
+
* held and goes out on the next connect (flushHeldSkillNotice) instead of
|
|
249
|
+
* being lost. */
|
|
250
|
+
private settleFirstBeat;
|
|
251
|
+
/** Send a held notice once nothing is pending any more (settle, or the next
|
|
252
|
+
* connect after a settle that found the socket down). */
|
|
253
|
+
private flushHeldSkillNotice;
|
|
233
254
|
closePosition(symbol: string): Promise<{
|
|
234
255
|
closed: boolean;
|
|
235
256
|
symbol: string;
|
|
@@ -267,24 +288,45 @@ export declare class GatewayProvider implements OpenClawProvider {
|
|
|
267
288
|
* Operator-only. Update the ReefClaw connector on this box to the latest
|
|
268
289
|
* published version.
|
|
269
290
|
*
|
|
270
|
-
*
|
|
271
|
-
*
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
*
|
|
291
|
+
* Two update paths, chosen by how the plugin was installed (plugins.inspect
|
|
292
|
+
* over the admin session, after every guard):
|
|
293
|
+
* - a copy OpenClaw installed from ClawHub → OpenClaw's own plugins.install
|
|
294
|
+
* (update mode), pinned to the exact PLUGIN release ReefClaw's public
|
|
295
|
+
* release endpoint reports, then a gateway self-restart
|
|
296
|
+
* (providers/connector-update-openclaw.ts);
|
|
297
|
+
* - everything else → the connect installer over the gateway's PTY, or run
|
|
298
|
+
* directly (files-only) where there is no usable terminal, pinned to the
|
|
299
|
+
* exact CONNECTOR release (providers/connector-update.ts).
|
|
300
|
+
* The RPC carries no command/version/args parameter and never should — the
|
|
301
|
+
* versions are looked up by this process, never taken from the caller.
|
|
275
302
|
*
|
|
276
|
-
* The
|
|
277
|
-
*
|
|
278
|
-
* `restarting` and the dashboard waits for the reconnect.
|
|
303
|
+
* The update restarts the gateway when it finishes, which kills both the
|
|
304
|
+
* session and this process's own transport. That is the SUCCESS path: we
|
|
305
|
+
* report `restarting` and the dashboard waits for the reconnect.
|
|
279
306
|
*/
|
|
280
307
|
updateConnector(args: {
|
|
281
308
|
acknowledgeOpenPositions?: boolean;
|
|
282
309
|
}): Promise<ConnectorUpdateOutcome>;
|
|
310
|
+
/** updateConnector past its guards and holding the one-update lock.
|
|
311
|
+
* `handOff()` is called by a path that returns while its run continues in
|
|
312
|
+
* the background; that run releases the lock (the returned function) when
|
|
313
|
+
* it ends. */
|
|
314
|
+
private updateConnectorLocked;
|
|
283
315
|
/** The direct (no-PTY) update. Resolves the RPC with the `started` frame as
|
|
284
316
|
* soon as the installer is running (or the refusal), streams the rest as
|
|
285
|
-
* connector_update events, and tears the admin session down
|
|
286
|
-
* the same contract as the PTY
|
|
317
|
+
* connector_update events, and tears the admin session down (and releases
|
|
318
|
+
* the one-update lock, `onEnd`) at the end — the same contract as the PTY
|
|
319
|
+
* path. */
|
|
287
320
|
private runDirectUpdate;
|
|
321
|
+
/** The OpenClaw (plugins.install) update. Same contract as the direct path:
|
|
322
|
+
* the RPC resolves with the first `started` frame (a restart-only run sends
|
|
323
|
+
* one too, before it asks the gateway to restart) else with the final
|
|
324
|
+
* outcome (a refusal decided before anything ran, or "already up to
|
|
325
|
+
* date"); every emitted frame also goes out as a connector_update event.
|
|
326
|
+
* The admin session stays open for the whole install (OpenClaw 2026.9.7
|
|
327
|
+
* re-checks the caller's admin authority before persisting) and is torn
|
|
328
|
+
* down — and the one-update lock released (`onEnd`) — at the end. */
|
|
329
|
+
private runOpenClawUpdate;
|
|
288
330
|
/**
|
|
289
331
|
* Operator-triggered gateway self-restart through OpenClaw's own
|
|
290
332
|
* `gateway.restart.request` RPC. The one door on a Docker / unmanaged box:
|