@reefclaw/openclaw-plugin 0.1.49 → 0.1.51
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/config.js +10 -3
- 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 +39 -2
- package/bridge/gateway/heartbeat-cron.js +62 -8
- package/bridge/heartbeat-transcript.d.ts +3 -1
- package/bridge/heartbeat-transcript.js +26 -5
- package/bridge/index.js +2 -2
- 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 +31 -10
- package/bridge/providers/gateway.js +144 -28
- package/bridge/setup.js +6 -3
- package/bridge/utils/relay-host.d.ts +16 -0
- package/bridge/utils/relay-host.js +30 -1
- 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 +32 -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/skills/reefclaw/SKILL.md +21 -8
- package/strategy/builtin-strategies.js +2 -2
- package/tools/venue-quote-hint.d.ts +49 -0
- package/tools/venue-quote-hint.js +200 -0
|
@@ -23,8 +23,9 @@ import { parseIdentityName } from '../utils/identity-name.js';
|
|
|
23
23
|
import { assessDrawdownPlausibility, computeEquity as _computeEquity, computePositionNotional as _computePositionNotional, computeRiskMetrics as _computeRiskMetrics, DEFAULT_RISK_LIMITS, DRAWDOWN_ZONE_THRESHOLDS, TENANT_LIMIT_BOUNDS, boundedNum, validateDrawdownLadder, } from './risk-calculator.js';
|
|
24
24
|
import { executeKill as _executeKill, executeFlatten as _executeFlatten, executePause as _executePause, executeResume as _executeResume, cancelPendingProposals, withProposalDetail, } from './emergency-commands.js';
|
|
25
25
|
import { executeSetTradingMode, executeGetBracketConfig, executeSetBracketRequirement, executeSetExchangeCredentials, executeTestExchangeCredentials, executeClearExchangeCredentials, executeProvisionHlAgentWallet, executeHlAgentWalletStatus, executeSubmitHlAgentApproval, } from './onboarding-commands.js';
|
|
26
|
-
import { startConnectorUpdate, runConnectorUpdate,
|
|
26
|
+
import { startConnectorUpdate, runConnectorUpdate, fetchPinnedRelease, openAdminGatewaySession, checkPositionGuard, describeUnconfirmedConnectVersion, describeUpdateAlreadyRunning, describeUpdateDisabled, tryBeginConnectorUpdate, requestGatewayRestart, RESTART_REASON_OPERATOR, } from './connector-update.js';
|
|
27
27
|
import { isInsideContainer, readContainerProbe, runDirectConnectorUpdate } from './connector-update-direct.js';
|
|
28
|
+
import { getRunningPluginRelease, inspectInstalledPlugin, planConnectorUpdate, runOpenClawPluginUpdate, } from './connector-update-openclaw.js';
|
|
28
29
|
import { DEFAULT_AGENT_ID, isForeignAgentEvent, resolveAgentEventOwner } from '../gateway/agent-scope.js';
|
|
29
30
|
import { noteWebappResponse, webappEdgeTracker, webappHeaders } from '../utils/webapp-edge.js';
|
|
30
31
|
const TAG = 'gateway';
|
|
@@ -817,15 +818,21 @@ export class GatewayProvider {
|
|
|
817
818
|
* Operator-only. Update the ReefClaw connector on this box to the latest
|
|
818
819
|
* published version.
|
|
819
820
|
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
*
|
|
823
|
-
*
|
|
824
|
-
*
|
|
821
|
+
* Two update paths, chosen by how the plugin was installed (plugins.inspect
|
|
822
|
+
* over the admin session, after every guard):
|
|
823
|
+
* - a copy OpenClaw installed from ClawHub → OpenClaw's own plugins.install
|
|
824
|
+
* (update mode), pinned to the exact PLUGIN release ReefClaw's public
|
|
825
|
+
* release endpoint reports, then a gateway self-restart
|
|
826
|
+
* (providers/connector-update-openclaw.ts);
|
|
827
|
+
* - everything else → the connect installer over the gateway's PTY, or run
|
|
828
|
+
* directly (files-only) where there is no usable terminal, pinned to the
|
|
829
|
+
* exact CONNECTOR release (providers/connector-update.ts).
|
|
830
|
+
* The RPC carries no command/version/args parameter and never should — the
|
|
831
|
+
* versions are looked up by this process, never taken from the caller.
|
|
825
832
|
*
|
|
826
|
-
* The
|
|
827
|
-
*
|
|
828
|
-
* `restarting` and the dashboard waits for the reconnect.
|
|
833
|
+
* The update restarts the gateway when it finishes, which kills both the
|
|
834
|
+
* session and this process's own transport. That is the SUCCESS path: we
|
|
835
|
+
* report `restarting` and the dashboard waits for the reconnect.
|
|
829
836
|
*/
|
|
830
837
|
async updateConnector(args) {
|
|
831
838
|
// Per-host opt-out FIRST: a box whose operator switched this off must
|
|
@@ -852,16 +859,51 @@ export class GatewayProvider {
|
|
|
852
859
|
const blocked = checkPositionGuard(guardArgs);
|
|
853
860
|
if (blocked)
|
|
854
861
|
return blocked;
|
|
855
|
-
//
|
|
862
|
+
// ONE update at a time, process-wide (connector-update.ts
|
|
863
|
+
// tryBeginConnectorUpdate): the dashboard's busy flag is per browser, so a
|
|
864
|
+
// second tab or device can ask again mid-install — and a second run's
|
|
865
|
+
// gateway restart would kill the first run's install mid-stage. Taken
|
|
866
|
+
// synchronously, before the first await, so two requests cannot interleave;
|
|
867
|
+
// released when the run ends, whichever way (a background run releases it
|
|
868
|
+
// itself — `handedOff`).
|
|
869
|
+
const endUpdate = tryBeginConnectorUpdate();
|
|
870
|
+
if (!endUpdate) {
|
|
871
|
+
logger.info(TAG, 'connector.update refused: an update is already running on this box');
|
|
872
|
+
return describeUpdateAlreadyRunning();
|
|
873
|
+
}
|
|
874
|
+
let handedOff = false;
|
|
875
|
+
try {
|
|
876
|
+
return await this.updateConnectorLocked(guardArgs, () => {
|
|
877
|
+
handedOff = true;
|
|
878
|
+
return endUpdate;
|
|
879
|
+
});
|
|
880
|
+
}
|
|
881
|
+
finally {
|
|
882
|
+
if (!handedOff)
|
|
883
|
+
endUpdate();
|
|
884
|
+
}
|
|
885
|
+
}
|
|
886
|
+
/** updateConnector past its guards and holding the one-update lock.
|
|
887
|
+
* `handOff()` is called by a path that returns while its run continues in
|
|
888
|
+
* the background; that run releases the lock (the returned function) when
|
|
889
|
+
* it ends. */
|
|
890
|
+
async updateConnectorLocked(guardArgs, handOff) {
|
|
891
|
+
if (!this.wsClient) {
|
|
892
|
+
return { ok: false, status: 'failed', message: 'Not connected to the OpenClaw gateway.' };
|
|
893
|
+
}
|
|
894
|
+
// Which version? Only the ones ReefClaw vouches for, fetched by THIS
|
|
856
895
|
// process from the public release endpoint — never `@latest`, never a
|
|
857
|
-
// caller-supplied string.
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
//
|
|
864
|
-
//
|
|
896
|
+
// caller-supplied string. One request, both releases (connector + plugin);
|
|
897
|
+
// each path below refuses when ITS release is missing. Neither confirmed ⇒
|
|
898
|
+
// no update, before any gateway call.
|
|
899
|
+
const release = await fetchPinnedRelease({});
|
|
900
|
+
if (!release.ok)
|
|
901
|
+
return release.outcome;
|
|
902
|
+
// terminal.* and plugins.install are operator.admin-only (OpenClaw
|
|
903
|
+
// method-scopes). The long-lived session runs on operator.read/write by
|
|
904
|
+
// design, so open a SEPARATE short-lived admin session for this update.
|
|
905
|
+
// Reconnects are effectively disabled: the gateway restart is supposed to
|
|
906
|
+
// kill it.
|
|
865
907
|
const admin = new GatewayWsClient({
|
|
866
908
|
gatewayUrl: this.config.gatewayUrl,
|
|
867
909
|
gatewayToken: this.config.gatewayToken,
|
|
@@ -874,6 +916,38 @@ export class GatewayProvider {
|
|
|
874
916
|
if (!session.ok)
|
|
875
917
|
return session.outcome;
|
|
876
918
|
const rpc = (method, params) => admin.sendRpc(method, params);
|
|
919
|
+
// ★ Who installed this copy? Decided BEFORE picking PTY / direct: a copy
|
|
920
|
+
// OpenClaw installed from ClawHub (the no-terminal onboarding route) is
|
|
921
|
+
// not the connect installer's to update — the installer refuses it
|
|
922
|
+
// (ALREADY_INSTALLED_MARKER) — so it goes through OpenClaw's own
|
|
923
|
+
// plugins.install instead. No usable answer (older OpenClaw, an error) or
|
|
924
|
+
// a path install keeps today's installer path, unchanged.
|
|
925
|
+
const inspected = await inspectInstalledPlugin(rpc);
|
|
926
|
+
const plan = planConnectorUpdate(inspected, { pluginVersion: release.pluginVersion });
|
|
927
|
+
logger.info(TAG, `connector.update: route=${plan.path} (${plan.reason})`);
|
|
928
|
+
if (plan.path === 'blocked') {
|
|
929
|
+
admin.destroy();
|
|
930
|
+
return plan.outcome;
|
|
931
|
+
}
|
|
932
|
+
if (plan.path === 'openclaw') {
|
|
933
|
+
// opts only when given, so every other call is the byte-identical
|
|
934
|
+
// two-argument sendRpc it always was.
|
|
935
|
+
const gatewayRpc = (method, params, opts) => opts ? admin.sendRpc(method, params, opts) : admin.sendRpc(method, params);
|
|
936
|
+
const running = getRunningPluginRelease();
|
|
937
|
+
return this.runOpenClawUpdate(gatewayRpc, admin, {
|
|
938
|
+
inspect: inspected,
|
|
939
|
+
pinnedPluginVersion: release.pluginVersion,
|
|
940
|
+
hello: admin.getHelloInfo(),
|
|
941
|
+
runningRelease: running.version,
|
|
942
|
+
runningReleaseLoadedByGateway: running.loadedByGateway,
|
|
943
|
+
}, handOff());
|
|
944
|
+
}
|
|
945
|
+
// The installer path needs the exact CONNECTOR release.
|
|
946
|
+
if (release.connectVersion === null) {
|
|
947
|
+
admin.destroy();
|
|
948
|
+
return describeUnconfirmedConnectVersion();
|
|
949
|
+
}
|
|
950
|
+
const connectVersion = release.connectVersion;
|
|
877
951
|
// Inside a container the PTY path is the wrong tool even where the
|
|
878
952
|
// terminal RPC exists: the full installer runs the `openclaw` CLI inside
|
|
879
953
|
// the live gateway (a second plugin stack) and cannot restart the
|
|
@@ -881,14 +955,14 @@ export class GatewayProvider {
|
|
|
881
955
|
// the gateway restart itself (connector-update-direct.ts).
|
|
882
956
|
if (isInsideContainer(readContainerProbe())) {
|
|
883
957
|
logger.info(TAG, 'connector.update: container detected — running the installer directly (files-only)');
|
|
884
|
-
return this.runDirectUpdate(rpc,
|
|
958
|
+
return this.runDirectUpdate(rpc, connectVersion, admin, release.pluginVersion, handOff());
|
|
885
959
|
}
|
|
886
|
-
const started = await startConnectorUpdate(rpc, guardArgs,
|
|
960
|
+
const started = await startConnectorUpdate(rpc, guardArgs, connectVersion);
|
|
887
961
|
if (started.status === 'blocked' && started.directFallback) {
|
|
888
962
|
// The gateway has no usable terminal (OpenClaw < 2026.7, terminal
|
|
889
963
|
// disabled, sandboxed agent). The connector does not need one.
|
|
890
964
|
logger.info(TAG, `connector.update: no gateway terminal (${started.message}) — running the installer directly`);
|
|
891
|
-
return this.runDirectUpdate(rpc,
|
|
965
|
+
return this.runDirectUpdate(rpc, connectVersion, admin, release.pluginVersion, handOff());
|
|
892
966
|
}
|
|
893
967
|
if (started.status !== 'started' || !started.sessionId) {
|
|
894
968
|
admin.destroy();
|
|
@@ -896,17 +970,23 @@ export class GatewayProvider {
|
|
|
896
970
|
}
|
|
897
971
|
// Stream progress in the background; the RPC returns as soon as the command
|
|
898
972
|
// is running so the browser is never left waiting on a minutes-long call.
|
|
899
|
-
// The admin session is torn down
|
|
900
|
-
|
|
973
|
+
// The admin session is torn down, and the one-update lock released, when
|
|
974
|
+
// the loop ends, whichever way.
|
|
975
|
+
const endUpdate = handOff();
|
|
976
|
+
void runConnectorUpdate(rpc, started.sessionId, (outcome) => this.emitConnectorUpdate(outcome), {
|
|
977
|
+
pluginVersion: release.pluginVersion,
|
|
978
|
+
}).finally(() => {
|
|
901
979
|
admin.destroy();
|
|
980
|
+
endUpdate();
|
|
902
981
|
});
|
|
903
982
|
return started;
|
|
904
983
|
}
|
|
905
984
|
/** The direct (no-PTY) update. Resolves the RPC with the `started` frame as
|
|
906
985
|
* soon as the installer is running (or the refusal), streams the rest as
|
|
907
|
-
* connector_update events, and tears the admin session down
|
|
908
|
-
* the same contract as the PTY
|
|
909
|
-
|
|
986
|
+
* connector_update events, and tears the admin session down (and releases
|
|
987
|
+
* the one-update lock, `onEnd`) at the end — the same contract as the PTY
|
|
988
|
+
* path. */
|
|
989
|
+
runDirectUpdate(rpc, version, admin, pluginVersion, onEnd) {
|
|
910
990
|
return new Promise((resolve) => {
|
|
911
991
|
let answered = false;
|
|
912
992
|
const answer = (outcome) => {
|
|
@@ -921,9 +1001,41 @@ export class GatewayProvider {
|
|
|
921
1001
|
this.emitConnectorUpdate(outcome);
|
|
922
1002
|
if (outcome.status === 'started')
|
|
923
1003
|
answer(outcome);
|
|
1004
|
+
}, { pluginVersion })
|
|
1005
|
+
.then((final) => answer(final))
|
|
1006
|
+
.finally(() => {
|
|
1007
|
+
admin.destroy();
|
|
1008
|
+
onEnd();
|
|
1009
|
+
});
|
|
1010
|
+
});
|
|
1011
|
+
}
|
|
1012
|
+
/** The OpenClaw (plugins.install) update. Same contract as the direct path:
|
|
1013
|
+
* the RPC resolves with the first `started` frame (a restart-only run sends
|
|
1014
|
+
* one too, before it asks the gateway to restart) else with the final
|
|
1015
|
+
* outcome (a refusal decided before anything ran, or "already up to
|
|
1016
|
+
* date"); every emitted frame also goes out as a connector_update event.
|
|
1017
|
+
* The admin session stays open for the whole install (OpenClaw 2026.9.7
|
|
1018
|
+
* re-checks the caller's admin authority before persisting) and is torn
|
|
1019
|
+
* down — and the one-update lock released (`onEnd`) — at the end. */
|
|
1020
|
+
runOpenClawUpdate(rpc, admin, ctx, onEnd) {
|
|
1021
|
+
return new Promise((resolve) => {
|
|
1022
|
+
let answered = false;
|
|
1023
|
+
const answer = (outcome) => {
|
|
1024
|
+
if (answered)
|
|
1025
|
+
return;
|
|
1026
|
+
answered = true;
|
|
1027
|
+
resolve(outcome);
|
|
1028
|
+
};
|
|
1029
|
+
void runOpenClawPluginUpdate(rpc, ctx, (outcome) => {
|
|
1030
|
+
this.emitConnectorUpdate(outcome);
|
|
1031
|
+
if (outcome.status === 'started')
|
|
1032
|
+
answer(outcome);
|
|
924
1033
|
})
|
|
925
1034
|
.then((final) => answer(final))
|
|
926
|
-
.finally(() =>
|
|
1035
|
+
.finally(() => {
|
|
1036
|
+
admin.destroy();
|
|
1037
|
+
onEnd();
|
|
1038
|
+
});
|
|
927
1039
|
});
|
|
928
1040
|
}
|
|
929
1041
|
/**
|
|
@@ -1515,7 +1627,10 @@ export class GatewayProvider {
|
|
|
1515
1627
|
const markerPath = join(this.workspaceDir(), 'heartbeat-cron-ensured.json');
|
|
1516
1628
|
// A first market check is possible only while the ensure is owed; hold
|
|
1517
1629
|
// the bridge's update notice from now until it is known either way.
|
|
1518
|
-
|
|
1630
|
+
// Read BEFORE the ensure writes its marker: owed = this session was
|
|
1631
|
+
// opened with operator.admin (the reconcile below needs it).
|
|
1632
|
+
const ensureOwed = heartbeatEnsureOwed(markerPath);
|
|
1633
|
+
if (ensureOwed)
|
|
1519
1634
|
this.firstBeatState = 'maybe';
|
|
1520
1635
|
void ensureHeartbeatCron({
|
|
1521
1636
|
rpc: ws,
|
|
@@ -1575,6 +1690,7 @@ export class GatewayProvider {
|
|
|
1575
1690
|
rpc: ws,
|
|
1576
1691
|
log: (msg) => logger.info(TAG, msg),
|
|
1577
1692
|
channelsConfigured,
|
|
1693
|
+
adminScope: ensureOwed,
|
|
1578
1694
|
agentId: this.agentId(),
|
|
1579
1695
|
agentIsDefault: this.config.agentIsDefault ?? true,
|
|
1580
1696
|
});
|
package/bridge/setup.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Validates token format, tests relay connection, saves to OpenClaw config.
|
|
3
3
|
import WebSocket from 'ws';
|
|
4
4
|
import { writeOpenClawConfig } from './config.js';
|
|
5
|
-
import { checkRelayHost, describeRelayRefusal } from './utils/relay-host.js';
|
|
5
|
+
import { checkRelayHost, describeRelayRefusal, migrateRetiredRelayUrl } from './utils/relay-host.js';
|
|
6
6
|
import { logger } from './logger.js';
|
|
7
7
|
const TAG = 'setup';
|
|
8
|
-
const DEFAULT_RELAY_URL = 'wss://reefclaw.
|
|
8
|
+
const DEFAULT_RELAY_URL = 'wss://relay.reefclaw.com';
|
|
9
9
|
const TOKEN_PREFIX = 'rc_';
|
|
10
10
|
const TOKEN_MIN_LENGTH = 10; // rc_ + at least 7 chars
|
|
11
11
|
const CONNECTION_TEST_TIMEOUT_MS = 10_000;
|
|
@@ -119,7 +119,10 @@ export async function runSetup(tokenOrBundle, userId, relayUrl) {
|
|
|
119
119
|
const parsed = parseConnectBundle(tokenOrBundle);
|
|
120
120
|
const token = parsed.token ?? tokenOrBundle.trim();
|
|
121
121
|
const resolvedUserId = userId ?? parsed.userId;
|
|
122
|
-
const
|
|
122
|
+
const givenRelayUrl = relayUrl ?? parsed.relayUrl;
|
|
123
|
+
// An old connect message still names the retired PartyKit host — save its
|
|
124
|
+
// replacement so the config is right on disk, not just rewritten at startup.
|
|
125
|
+
const resolvedRelayUrl = givenRelayUrl ? migrateRetiredRelayUrl(givenRelayUrl).url : givenRelayUrl;
|
|
123
126
|
// Validate token format
|
|
124
127
|
const validation = validateToken(token);
|
|
125
128
|
if (!validation.valid) {
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
/** Hosts (exact, lowercase) or suffixes (leading dot) of ReefClaw relays. */
|
|
2
2
|
export declare const ALLOWED_RELAY_HOSTS: readonly string[];
|
|
3
3
|
export declare const ALLOW_CUSTOM_RELAY_ENV = "REEFCLAW_ALLOW_CUSTOM_RELAY";
|
|
4
|
+
/** Where a connect message from reefclaw.com points today. */
|
|
5
|
+
export declare const PRIMARY_RELAY_HOST = "relay.reefclaw.com";
|
|
6
|
+
/**
|
|
7
|
+
* Relay hosts that no longer serve traffic, mapped to their replacement.
|
|
8
|
+
* PartyKit's hosted platform deleted `reefclaw.radunlupsa.partykit.dev` on
|
|
9
|
+
* 2026-10-23 and the relay moved to our own Cloudflare account. Most boxes
|
|
10
|
+
* saved the old URL in openclaw.json at onboarding, and many are on hosts we
|
|
11
|
+
* cannot log into, so the bridge rewrites the host in memory at startup
|
|
12
|
+
* instead of asking every user to edit their config.
|
|
13
|
+
*/
|
|
14
|
+
export declare const RETIRED_RELAY_HOSTS: Readonly<Record<string, string>>;
|
|
15
|
+
/** Rewrite a relay URL whose host is retired; any other URL comes back unchanged. */
|
|
16
|
+
export declare function migrateRetiredRelayUrl(relayUrl: string): {
|
|
17
|
+
url: string;
|
|
18
|
+
retiredHost?: string;
|
|
19
|
+
};
|
|
4
20
|
export type RelayHostVerdict = {
|
|
5
21
|
ok: true;
|
|
6
22
|
host: string;
|
|
@@ -20,6 +20,35 @@ export const ALLOWED_RELAY_HOSTS = [
|
|
|
20
20
|
'.reefclaw.partykit.dev',
|
|
21
21
|
];
|
|
22
22
|
export const ALLOW_CUSTOM_RELAY_ENV = 'REEFCLAW_ALLOW_CUSTOM_RELAY';
|
|
23
|
+
/** Where a connect message from reefclaw.com points today. */
|
|
24
|
+
export const PRIMARY_RELAY_HOST = 'relay.reefclaw.com';
|
|
25
|
+
/**
|
|
26
|
+
* Relay hosts that no longer serve traffic, mapped to their replacement.
|
|
27
|
+
* PartyKit's hosted platform deleted `reefclaw.radunlupsa.partykit.dev` on
|
|
28
|
+
* 2026-10-23 and the relay moved to our own Cloudflare account. Most boxes
|
|
29
|
+
* saved the old URL in openclaw.json at onboarding, and many are on hosts we
|
|
30
|
+
* cannot log into, so the bridge rewrites the host in memory at startup
|
|
31
|
+
* instead of asking every user to edit their config.
|
|
32
|
+
*/
|
|
33
|
+
export const RETIRED_RELAY_HOSTS = {
|
|
34
|
+
'reefclaw.radunlupsa.partykit.dev': PRIMARY_RELAY_HOST,
|
|
35
|
+
};
|
|
36
|
+
/** Rewrite a relay URL whose host is retired; any other URL comes back unchanged. */
|
|
37
|
+
export function migrateRetiredRelayUrl(relayUrl) {
|
|
38
|
+
let u;
|
|
39
|
+
try {
|
|
40
|
+
u = new URL(relayUrl);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return { url: relayUrl };
|
|
44
|
+
}
|
|
45
|
+
const replacement = RETIRED_RELAY_HOSTS[u.hostname.toLowerCase()];
|
|
46
|
+
if (!replacement)
|
|
47
|
+
return { url: relayUrl };
|
|
48
|
+
const retiredHost = u.hostname;
|
|
49
|
+
u.hostname = replacement;
|
|
50
|
+
return { url: u.toString().replace(/\/+$/, ''), retiredHost };
|
|
51
|
+
}
|
|
23
52
|
function isPrivateHost(h) {
|
|
24
53
|
if (h === 'localhost' || h.endsWith('.localhost') || h === '::1' || h === '[::1]')
|
|
25
54
|
return true;
|
|
@@ -61,6 +90,6 @@ export function describeRelayRefusal(v) {
|
|
|
61
90
|
return v.reason === 'unparseable'
|
|
62
91
|
? 'The relay URL in the connect message could not be parsed.'
|
|
63
92
|
: `The relay host "${v.host}" is not a ReefClaw relay. A connect message from reefclaw.com always points at ` +
|
|
64
|
-
`${
|
|
93
|
+
`${PRIMARY_RELAY_HOST} — a different host means the message was altered, and connecting would hand it your token. ` +
|
|
65
94
|
`Self-hosting your own relay? Set ${ALLOW_CUSTOM_RELAY_ENV}=1 in the connector's environment to allow it.`;
|
|
66
95
|
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { type VenueId } from '../venues/symbols.js';
|
|
2
|
+
import { updatePluginConfig } from './plugin-config-io.js';
|
|
3
|
+
/** = index.ts PLUGIN_ID, the StateManager directory name (pinned by test). */
|
|
4
|
+
export declare const FIRST_START_PLUGIN_ID = "reefclaw-paper-trading";
|
|
5
|
+
/** The marker left in <OpenClaw state dir>/plugins/<pluginId>/ when that dir
|
|
6
|
+
* is not the plugin's own $HOME state dir. */
|
|
7
|
+
export declare const FIRST_START_MARKER_FILE = "first-start.json";
|
|
8
|
+
/** Keys the connect installer writes into plugin-config.json before the
|
|
9
|
+
* plugin's first start. Same table as installer/src/venue-config.ts
|
|
10
|
+
* isInstallerOwned — change both together. `connectorSupervisor` counts only
|
|
11
|
+
* as the installer's 'on'; an 'off' is a deliberate human setting. */
|
|
12
|
+
export declare function isInstallerOwnedKey(key: string, value: unknown): boolean;
|
|
13
|
+
export type SavedVenue = {
|
|
14
|
+
kind: 'none';
|
|
15
|
+
} | {
|
|
16
|
+
kind: 'venue';
|
|
17
|
+
venue: VenueId;
|
|
18
|
+
} | {
|
|
19
|
+
kind: 'unrecognized';
|
|
20
|
+
shown: string;
|
|
21
|
+
};
|
|
22
|
+
/** Tolerant parse (an agent wrote it): strings only, trimmed + lowercased,
|
|
23
|
+
* and only the exact ids 'hyperliquid' / 'binance' after that. */
|
|
24
|
+
export declare function parseSavedVenue(raw: unknown): SavedVenue;
|
|
25
|
+
export type PluginConfigView = {
|
|
26
|
+
kind: 'absent';
|
|
27
|
+
} | {
|
|
28
|
+
kind: 'unreadable';
|
|
29
|
+
} | {
|
|
30
|
+
kind: 'object';
|
|
31
|
+
value: Record<string, unknown>;
|
|
32
|
+
};
|
|
33
|
+
export type FirstStartVenueSkipReason = 'disabled' | 'not-requested' | 'ran-before' | 'unrecognized' | 'binance-default' | 'unreadable' | 'already-set' | 'configured-before';
|
|
34
|
+
export type FirstStartVenueDecision = {
|
|
35
|
+
action: 'write';
|
|
36
|
+
venue: 'hyperliquid';
|
|
37
|
+
} | {
|
|
38
|
+
action: 'skip';
|
|
39
|
+
reason: Exclude<FirstStartVenueSkipReason, 'disabled'>;
|
|
40
|
+
};
|
|
41
|
+
/** Pure. Order matters: `ran-before` is checked before garbage, so a box that
|
|
42
|
+
* ran before never warns about its saved value on every restart. */
|
|
43
|
+
export declare function decideFirstStartVenue(input: {
|
|
44
|
+
saved: SavedVenue;
|
|
45
|
+
ranBefore: boolean;
|
|
46
|
+
pluginConfig: PluginConfigView;
|
|
47
|
+
}): FirstStartVenueDecision;
|
|
48
|
+
/** The state dir and the transport key are written only by this plugin's
|
|
49
|
+
* first full register() (StateManager, ensureCredentialTransportKey); the
|
|
50
|
+
* OpenClaw-side dir only by markFirstStart below. Any one present = ran
|
|
51
|
+
* before. */
|
|
52
|
+
export declare function pluginRanBefore(paths: {
|
|
53
|
+
stateDir: string;
|
|
54
|
+
transportKeyFile: string;
|
|
55
|
+
openclawPluginDir?: string;
|
|
56
|
+
}): boolean;
|
|
57
|
+
export type FirstStartMarkOutcome = 'not-needed' | 'present' | 'written' | 'failed';
|
|
58
|
+
/** Record that ReefClaw has started on this OpenClaw state, in OpenClaw's
|
|
59
|
+
* state dir, when that is not where StateManager already records it (the
|
|
60
|
+
* $HOME state dir). Exclusive create: never overwrites. Never throws. */
|
|
61
|
+
export declare function markFirstStart(paths: {
|
|
62
|
+
stateDir: string;
|
|
63
|
+
openclawPluginDir: string;
|
|
64
|
+
}, now?: Date): FirstStartMarkOutcome;
|
|
65
|
+
/** plugin-config.json as this rule sees it. Never throws. A symlink or a
|
|
66
|
+
* directory is `unreadable` (never written through), as is bad JSON, a BOM,
|
|
67
|
+
* or a non-object root. */
|
|
68
|
+
export declare function viewPluginConfig(path: string): PluginConfigView;
|
|
69
|
+
/** The saved onboarding venue, raw. OpenClaw's own resolved config handed to
|
|
70
|
+
* register() (api.config) first: it is the running gateway's config, and a
|
|
71
|
+
* config file at a default location may belong to another layout. The file
|
|
72
|
+
* only when api.config holds no venue (the agent wrote the file a moment
|
|
73
|
+
* before the hot-load). Nested `.config.venue` only. */
|
|
74
|
+
export declare function readSavedVenue(openclawConfig?: unknown, openclawConfigPath?: string): unknown;
|
|
75
|
+
/** Mirror of OpenClaw's resolveStateDir (src/config/state-dir.ts, v2026.9.7)
|
|
76
|
+
* without its legacy-dir fallback: OPENCLAW_STATE_DIR (a `~` expands against
|
|
77
|
+
* the effective home), else <effective home>/.openclaw, where the effective
|
|
78
|
+
* home is OPENCLAW_HOME, else the OS home. */
|
|
79
|
+
export declare function openClawStateDirFromEnv(env: NodeJS.ProcessEnv, home: string): string;
|
|
80
|
+
/** OpenClaw's state dir: the host's own answer when it hands one over
|
|
81
|
+
* (api.runtime.state.resolveStateDir on 2026.9.x, through `hostStateDir`),
|
|
82
|
+
* else the env mirror. Never throws. */
|
|
83
|
+
export declare function resolveOpenClawStateDir(input: {
|
|
84
|
+
hostStateDir?: () => unknown;
|
|
85
|
+
env: NodeJS.ProcessEnv;
|
|
86
|
+
home: string;
|
|
87
|
+
}): string;
|
|
88
|
+
export interface FirstStartPaths {
|
|
89
|
+
/** = plugin-config-io defaultConfigPath(). */
|
|
90
|
+
pluginConfigPath: string;
|
|
91
|
+
/** = dirname(new StateManager(pluginId).getStatePath()). */
|
|
92
|
+
stateDir: string;
|
|
93
|
+
/** = the file ensureCredentialTransportKey() writes with no dir. */
|
|
94
|
+
transportKeyFile: string;
|
|
95
|
+
/** <OpenClaw state dir>/plugins/<pluginId>: the marker's home. */
|
|
96
|
+
openclawPluginDir: string;
|
|
97
|
+
/** OPENCLAW_CONFIG_PATH, else <OpenClaw state dir>/openclaw.json. */
|
|
98
|
+
openclawConfigPath: string;
|
|
99
|
+
}
|
|
100
|
+
/** The default paths. Exported so tests pin them against the code that
|
|
101
|
+
* creates each one (StateManager, ensureCredentialTransportKey,
|
|
102
|
+
* defaultConfigPath) rather than against a literal. */
|
|
103
|
+
export declare function defaultFirstStartPaths(input: {
|
|
104
|
+
home: string;
|
|
105
|
+
pluginId: string;
|
|
106
|
+
openclawStateDir: string;
|
|
107
|
+
env: NodeJS.ProcessEnv;
|
|
108
|
+
}): FirstStartPaths;
|
|
109
|
+
export interface ApplyFirstStartVenueOptions {
|
|
110
|
+
/** register()'s api.config (OpenClaw's resolved config) — read first. */
|
|
111
|
+
openclawConfig?: unknown;
|
|
112
|
+
/** Lazily yields OpenClaw's own state dir (api.runtime.state.resolveStateDir);
|
|
113
|
+
* called inside the never-throw boundary. */
|
|
114
|
+
hostStateDir?: () => unknown;
|
|
115
|
+
/** Defaults to FIRST_START_PLUGIN_ID; decides the default state dirs. */
|
|
116
|
+
pluginId?: string;
|
|
117
|
+
/** Test seams. Defaults: defaultFirstStartPaths(). */
|
|
118
|
+
pluginConfigPath?: string;
|
|
119
|
+
stateDir?: string;
|
|
120
|
+
transportKeyFile?: string;
|
|
121
|
+
openclawPluginDir?: string;
|
|
122
|
+
openclawConfigPath?: string;
|
|
123
|
+
/** Test seam: OpenClaw's state dir (default resolveOpenClawStateDir()). */
|
|
124
|
+
openclawStateDir?: string;
|
|
125
|
+
env?: NodeJS.ProcessEnv;
|
|
126
|
+
/** Test seam for the atomic writer (default updatePluginConfig). */
|
|
127
|
+
writePluginConfig?: typeof updatePluginConfig;
|
|
128
|
+
}
|
|
129
|
+
export type FirstStartVenueResult = {
|
|
130
|
+
outcome: 'applied';
|
|
131
|
+
venue: 'hyperliquid';
|
|
132
|
+
} | {
|
|
133
|
+
outcome: 'skipped';
|
|
134
|
+
reason: FirstStartVenueSkipReason;
|
|
135
|
+
} | {
|
|
136
|
+
outcome: 'failed';
|
|
137
|
+
error: string;
|
|
138
|
+
};
|
|
139
|
+
/** See the file header. Synchronous (register() must be), never throws. */
|
|
140
|
+
export declare function applyFirstStartVenue(options?: ApplyFirstStartVenueOptions): FirstStartVenueResult;
|
|
141
|
+
/** The venue this box will actually start on, for log lines: what
|
|
142
|
+
* plugin-config.json selects, read the way index.ts reads it (following a
|
|
143
|
+
* symlink; unreadable = the Binance default). Never throws. */
|
|
144
|
+
export declare function describeSelectedVenue(path: string): {
|
|
145
|
+
venue: VenueId;
|
|
146
|
+
text: string;
|
|
147
|
+
};
|