openbroker 1.9.0 → 1.9.2
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/CHANGELOG.md +8 -0
- package/README.md +28 -17
- package/SKILL.md +54 -43
- package/agents/openai.yaml +7 -0
- package/bin/cli.ts +4 -1
- package/dist/setup/install.d.ts +3 -0
- package/dist/setup/install.d.ts.map +1 -0
- package/dist/setup/install.js +113 -0
- package/dist/setup/onboard.d.ts.map +1 -1
- package/dist/setup/onboard.js +14 -6
- package/package.json +2 -1
- package/scripts/setup/install.ts +146 -0
- package/scripts/setup/onboard.ts +15 -6
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to Open Broker will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.9.1] - 2026-06-22
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
- Added `openbroker install --codex` and `npx openbroker@latest install --codex` for one-command Codex skill installation, persistent CLI installation, and restricted API-wallet onboarding.
|
|
9
|
+
- Made restricted API-wallet onboarding the recommended interactive default.
|
|
10
|
+
- Added `openbroker setup --api-wallet` for deterministic agent setup without the wallet-selection prompt.
|
|
11
|
+
- Updated the Codex skill to install the CLI, hand the browser approval URL to the user, wait for authorization, and verify the connected master account without exposing private keys.
|
|
12
|
+
|
|
5
13
|
## [1.5.0] - 2026-06-01
|
|
6
14
|
|
|
7
15
|
### Added
|
package/README.md
CHANGED
|
@@ -8,13 +8,23 @@ Hyperliquid trading CLI. Execute orders, manage positions, and run trading strat
|
|
|
8
8
|
npm install -g openbroker
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
+
### Codex: one-command install
|
|
12
|
+
|
|
13
|
+
Install the Codex skill, persistent CLI, and restricted API-wallet onboarding flow:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx openbroker@latest install --codex
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
When the command prints an approval URL, open it and connect the funded master Hyperliquid account you want OpenBroker to trade on. Restart Codex or start a new thread when setup finishes, then invoke `$openbroker`.
|
|
20
|
+
|
|
11
21
|
## Quick Start
|
|
12
22
|
|
|
13
23
|
```bash
|
|
14
|
-
# 1. Setup
|
|
15
|
-
openbroker setup
|
|
24
|
+
# 1. Setup a restricted API wallet (recommended for agents)
|
|
25
|
+
openbroker setup --api-wallet
|
|
16
26
|
|
|
17
|
-
# 2.
|
|
27
|
+
# 2. Open the printed approval link and connect your funded master Hyperliquid wallet
|
|
18
28
|
|
|
19
29
|
# 3. Start trading
|
|
20
30
|
openbroker account # View account info
|
|
@@ -27,18 +37,20 @@ openbroker search --query GOLD # Find markets
|
|
|
27
37
|
### Setup
|
|
28
38
|
|
|
29
39
|
```bash
|
|
30
|
-
openbroker
|
|
40
|
+
npx openbroker@latest install --codex # Codex skill + CLI + API-wallet onboarding
|
|
41
|
+
openbroker setup --api-wallet # Recommended: restricted agent wallet + browser approval
|
|
42
|
+
openbroker setup # Interactive; API wallet is the default
|
|
31
43
|
```
|
|
32
44
|
|
|
33
45
|
The setup command handles everything automatically:
|
|
34
|
-
- Generates a
|
|
46
|
+
- Generates a restricted API wallet by default, or accepts another wallet mode interactively
|
|
35
47
|
- Saves configuration to `~/.openbroker/.env` (permissions `0600`)
|
|
36
|
-
-
|
|
48
|
+
- Prints a browser approval link and waits for master-wallet authorization
|
|
37
49
|
|
|
38
50
|
Setup offers three modes:
|
|
39
|
-
1. **Generate fresh wallet**
|
|
51
|
+
1. **Generate fresh wallet** — separately funded wallet, no browser steps
|
|
40
52
|
2. **Import existing key** — use a key you already have
|
|
41
|
-
3. **Generate API wallet** —
|
|
53
|
+
3. **Generate API wallet** (default and recommended for agents) — can trade but cannot withdraw; requires browser approval from a master wallet
|
|
42
54
|
|
|
43
55
|
---
|
|
44
56
|
|
|
@@ -717,25 +729,24 @@ export HYPERLIQUID_NETWORK=mainnet # Optional: mainnet (default) or testne
|
|
|
717
729
|
export HYPERLIQUID_ACCOUNT_ADDRESS=0x... # Optional: for API wallets
|
|
718
730
|
```
|
|
719
731
|
|
|
720
|
-
###
|
|
732
|
+
### API Wallet Setup (Recommended for Agents)
|
|
721
733
|
|
|
722
|
-
The
|
|
734
|
+
The safest default for agents delegates trading from an API wallet that cannot withdraw. The CLI prints an approval URL, waits for the funded master wallet to authorize it, and then saves the master account mapping automatically:
|
|
723
735
|
|
|
724
736
|
```bash
|
|
725
|
-
openbroker setup
|
|
737
|
+
openbroker setup --api-wallet
|
|
726
738
|
```
|
|
727
739
|
|
|
728
|
-
|
|
740
|
+
Open the printed `https://openbroker.dev/approve?agent=...` link, connect the intended master Hyperliquid wallet, and approve `ApproveAgent` plus the 1 bps `ApproveBuilderFee` transaction. If approval times out, rerun the same command; OpenBroker resumes the incomplete setup without generating a new key.
|
|
741
|
+
|
|
742
|
+
### Fresh Wallet Setup (Alternative)
|
|
729
743
|
|
|
730
|
-
|
|
744
|
+
Run interactive setup and explicitly choose option 1 to create a separately funded wallet:
|
|
731
745
|
|
|
732
746
|
```bash
|
|
733
|
-
|
|
734
|
-
export HYPERLIQUID_ACCOUNT_ADDRESS="0x..." # Main account address
|
|
747
|
+
openbroker setup
|
|
735
748
|
```
|
|
736
749
|
|
|
737
|
-
**Note:** API wallets require browser approval from the master wallet. The master wallet signs `ApproveAgent` and `ApproveBuilderFee` transactions via the approval URL provided during setup.
|
|
738
|
-
|
|
739
750
|
## Builder Fee
|
|
740
751
|
|
|
741
752
|
Open Broker charges **1 bps (0.01%)** per trade to fund development. The builder fee is automatically approved during `openbroker setup`.
|
package/SKILL.md
CHANGED
|
@@ -1,38 +1,74 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: openbroker
|
|
3
|
-
description:
|
|
4
|
-
license: MIT
|
|
5
|
-
compatibility: Requires Node.js 22+, network access to api.hyperliquid.xyz
|
|
6
|
-
homepage: https://www.npmjs.com/package/openbroker
|
|
7
|
-
metadata: {"author": "monemetrics", "version": "1.3.2"}
|
|
8
|
-
allowed-tools: Bash(openbroker:*)
|
|
3
|
+
description: Install, onboard, and operate the OpenBroker Hyperliquid CLI for market and account inspection, restricted API-wallet setup, perp/HIP-3/spot/HIP-4 trading, order management, and TypeScript automations. Use when Codex needs to set up OpenBroker, run or explain `openbroker` commands, inspect Hyperliquid state, safely preview or execute trades, or create and debug OpenBroker automations.
|
|
9
4
|
---
|
|
10
5
|
|
|
11
6
|
# OpenBroker — Hyperliquid CLI skill
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
Use the `openbroker` CLI as the canonical interface. Prefer structured JSON output for inspection and dry runs before live writes.
|
|
14
9
|
|
|
15
10
|
## Operating rules
|
|
16
11
|
|
|
17
12
|
- For unfamiliar assets, **search before trading**. Hyperliquid has main perps, HIP-3 perps, spot markets, and HIP-4 outcomes that can share names.
|
|
18
13
|
- Prefer `--json` for machine-readable info commands.
|
|
19
|
-
- Before any write, verify the
|
|
20
|
-
-
|
|
14
|
+
- Before any write, verify the network, trading account, asset, side, size, open positions/orders, and whether the action should be reduce-only.
|
|
15
|
+
- Use `--dry` for proposed trades and new or changed trading logic. Execute live only when the user explicitly requests live execution and the dry-run plan matches that intent.
|
|
16
|
+
- Never infer a live trade size, switch to mainnet, or create/import/export a wallet without explicit user direction.
|
|
17
|
+
- Never print, echo, log, or expose private keys or seed material. Refer only to the configured signing wallet address when diagnosing identity.
|
|
21
18
|
- Treat CLI output as exchange state, not just prose: parse order IDs, balances, fills, and errors instead of assuming success.
|
|
22
19
|
|
|
23
|
-
##
|
|
20
|
+
## First-run installation and API-wallet onboarding
|
|
21
|
+
|
|
22
|
+
Use the following flow when the user asks to install, set up, or use OpenBroker. Do not ask the user for a private key.
|
|
23
|
+
|
|
24
|
+
For a fresh Codex installation, prefer the unified harness installer:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx --yes openbroker@latest install --codex
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
This installs or updates the Codex skill, installs the persistent `openbroker` CLI, and starts restricted API-wallet onboarding. Keep the command attached while it prints the browser approval link and polls for authorization.
|
|
31
|
+
|
|
32
|
+
If the unified installer is unavailable or the skill is already installed, first check whether Node.js 22+ and the CLI are installed:
|
|
24
33
|
|
|
25
34
|
```bash
|
|
26
|
-
|
|
27
|
-
openbroker
|
|
28
|
-
openbroker
|
|
35
|
+
node --version
|
|
36
|
+
command -v openbroker
|
|
37
|
+
openbroker --version
|
|
29
38
|
```
|
|
30
39
|
|
|
31
|
-
|
|
40
|
+
Require OpenBroker 1.9.1 or newer. When the user explicitly asks to set up OpenBroker, install or upgrade the CLI as part of that request, using the normal approval flow for global or network writes:
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
```bash
|
|
43
|
+
npm install -g openbroker@latest
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Public market-data commands such as `search`, `markets`, `funding`, `candles`, and `trades` work without wallet setup. For account-specific reads or trading, prefer a restricted API wallet because it can trade on the user's master Hyperliquid account but cannot withdraw funds.
|
|
47
|
+
|
|
48
|
+
Run setup in an interactive terminal session and select the API-wallet flow directly:
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
openbroker setup --api-wallet
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The command generates and stores the API wallet key locally in `~/.openbroker/.env` with mode `0600`, prints an approval URL, and waits up to ten minutes for browser approval. Handle that handoff as follows:
|
|
55
|
+
|
|
56
|
+
1. Keep the setup process running. Polling output is expected; do not treat it as a stuck command.
|
|
57
|
+
2. Capture the `https://openbroker.dev/approve?agent=...` URL from terminal output and immediately show it to the user as a clickable link.
|
|
58
|
+
3. Ask the user to open the link, connect the funded master Hyperliquid wallet they want OpenBroker to trade on, review the addresses and network, and sign the requested approvals. On mainnet this authorizes the API agent and the 1 bps builder fee; it does not grant withdrawal access.
|
|
59
|
+
4. Never ask the user to paste a master-wallet or API-wallet private key into Codex. Never display the key or read the config file into the conversation.
|
|
60
|
+
5. Leave the terminal session running while the user completes approval. The CLI detects approval automatically and saves `HYPERLIQUID_ACCOUNT_ADDRESS` as the master account.
|
|
61
|
+
6. After setup completes, verify the connection with `openbroker account --json` and report the master account address, API signing-wallet address, account mode, and equity without exposing secrets.
|
|
62
|
+
|
|
63
|
+
If approval times out, preserve the incomplete config and approval URL. Ask the user to finish approval, then rerun `openbroker setup --api-wallet`; the CLI reuses the existing API key and resumes polling instead of generating another wallet.
|
|
64
|
+
|
|
65
|
+
If a complete config already exists, do not delete or replace it without explicit user approval. Inspect account identity with `openbroker account --json` first.
|
|
66
|
+
|
|
67
|
+
The interactive `openbroker setup` command still supports three modes, with API wallet as the default when the user presses Enter:
|
|
68
|
+
|
|
69
|
+
1. **Fresh wallet** — creates a separately funded wallet; builder fee approval is handled automatically.
|
|
34
70
|
2. **Imported key** — use an existing wallet.
|
|
35
|
-
3. **API wallet** — can trade but not withdraw; the human owner
|
|
71
|
+
3. **API wallet (default)** — can trade but not withdraw; the human owner approves it in a browser.
|
|
36
72
|
|
|
37
73
|
For API wallets, `HYPERLIQUID_PRIVATE_KEY` is the signing key and `HYPERLIQUID_ACCOUNT_ADDRESS` must be the funded master account. If account output shows `$0` equity unexpectedly, check that mapping first.
|
|
38
74
|
|
|
@@ -190,7 +226,6 @@ Bundled examples are **references, not production strategies**. Read them for AP
|
|
|
190
226
|
- `api.on(...)`, `api.every(...)`, `api.onStart(...)`, `api.onStop(...)`, `api.onError(...)`.
|
|
191
227
|
- `api.state` — persisted state; survives restarts.
|
|
192
228
|
- `api.audit.record(...)` / `api.audit.metric(...)` — durable observability.
|
|
193
|
-
- `api.publish(...)` — notify an OpenClaw agent when hooks are configured.
|
|
194
229
|
- `api.dryRun` — whether writes are intercepted.
|
|
195
230
|
|
|
196
231
|
Core events include `tick`, `price_change`, `funding_update`, `position_opened`, `position_closed`, `position_changed`, `pnl_threshold`, `margin_warning`, `order_filled`, `order_update`, and `liquidation`.
|
|
@@ -223,7 +258,7 @@ These matter more than boilerplate:
|
|
|
223
258
|
7. **Separate strategy logic from execution policy.** Maker-first execution can reduce fees, but it needs bounded retries, post-only rejection handling, order cancellation, partial-fill accounting, minimum trade thresholds, and a defined IOC fallback. Measure progress from refreshed balances/positions, not only from submit responses.
|
|
224
259
|
8. **Size from real NAV and hard caps.** Multi-leg strategies often need spot balances, spot USDC, and perp account value combined; a 50/50 carry target derived from total NAV must then be halved per side and still respect a hard per-side cap.
|
|
225
260
|
9. **Define stop behavior intentionally.** On shutdown, always handle working orders, but do not blindly flatten every strategy. A hedged carry may need “preserve hedge and alert,” while a transient execution bot may need “cancel and flatten.”
|
|
226
|
-
10. **Instrument first-class decisions.** Log and audit funding source, targets, leg notionals, settlement distance, hold/close decisions, fills, retries, and error paths.
|
|
261
|
+
10. **Instrument first-class decisions.** Log and audit funding source, targets, leg notionals, settlement distance, hold/close decisions, fills, retries, and error paths. Surface events that need human attention through the configured monitoring path.
|
|
227
262
|
|
|
228
263
|
Additional practical caveats:
|
|
229
264
|
|
|
@@ -234,34 +269,10 @@ Additional practical caveats:
|
|
|
234
269
|
- Naked directional positions usually need explicit TP/SL or equivalent risk logic. Hedged multi-leg strategies need strategy-specific exits instead of cargo-cult TP/SL rules.
|
|
235
270
|
- For new automations, do a dry run, inspect `auto report`, and only then run live unless the user explicitly requested immediate live execution.
|
|
236
271
|
|
|
237
|
-
## Plugin-aware use
|
|
238
|
-
|
|
239
|
-
When the OpenClaw plugin is available:
|
|
240
|
-
|
|
241
|
-
- Prefer `ob_*` tools for common structured reads and simple writes.
|
|
242
|
-
- Use `ob_watcher_status` for background monitoring state.
|
|
243
|
-
- Use `ob_auto_run`, `ob_auto_stop`, and `ob_auto_list` for supported automation actions.
|
|
244
|
-
- Fall back to the CLI for unsupported commands, debugging, richer flags, or if a tool returns empty/unexpected data.
|
|
245
|
-
|
|
246
|
-
Representative mappings:
|
|
247
|
-
|
|
248
|
-
| Plugin tool | CLI equivalent |
|
|
249
|
-
|---|---|
|
|
250
|
-
| `ob_account` | `openbroker account --json` |
|
|
251
|
-
| `ob_positions` | `openbroker positions --json` |
|
|
252
|
-
| `ob_funding` | `openbroker funding --json --include-hip3` |
|
|
253
|
-
| `ob_search` | `openbroker search --query <QUERY> --json` |
|
|
254
|
-
| `ob_buy` / `ob_sell` | `openbroker buy|sell --coin <COIN> --size <SIZE>` |
|
|
255
|
-
| `ob_limit` | `openbroker limit ...` |
|
|
256
|
-
| `ob_tpsl` | `openbroker tpsl ...` |
|
|
257
|
-
| `ob_auto_run` | `openbroker auto run <script> ...` |
|
|
258
|
-
|
|
259
|
-
Skill-only mode is fully usable through the CLI; the plugin adds agent tools, watcher notifications, and OpenClaw webhook integration.
|
|
260
|
-
|
|
261
272
|
## Failure checks
|
|
262
273
|
|
|
263
274
|
- `No market data found` → search again; likely wrong venue prefix.
|
|
264
275
|
- `$0` equity on an API wallet → likely missing `HYPERLIQUID_ACCOUNT_ADDRESS`.
|
|
265
276
|
- Unexpected funding behavior → check whether you are reading predicted vs cached instantaneous data.
|
|
266
277
|
- Strategy churn → inspect confirmation loops, fee-aware hold logic, settlement guards, and min-trade thresholds before changing position size.
|
|
267
|
-
-
|
|
278
|
+
- Unexpected or empty CLI output → rerun the command with `--json` and `--verbose`, then inspect the returned error before retrying a write.
|
package/bin/cli.ts
CHANGED
|
@@ -11,6 +11,7 @@ const scriptsDir = path.resolve(__dirname, '../scripts');
|
|
|
11
11
|
|
|
12
12
|
const commands: Record<string, { script: string; description: string }> = {
|
|
13
13
|
// Setup
|
|
14
|
+
'install': { script: 'setup/install.ts', description: 'Install OpenBroker for an agent harness' },
|
|
14
15
|
'setup': { script: 'setup/onboard.ts', description: 'Interactive setup wizard' },
|
|
15
16
|
'onboard': { script: 'setup/onboard.ts', description: 'Interactive setup wizard' },
|
|
16
17
|
'approve-builder': { script: 'setup/approve-builder.ts', description: 'Approve builder fee' },
|
|
@@ -68,6 +69,7 @@ Open Broker - Hyperliquid Trading CLI
|
|
|
68
69
|
Usage: openbroker <command> [options]
|
|
69
70
|
|
|
70
71
|
Setup:
|
|
72
|
+
install Install OpenBroker for Codex or another agent harness
|
|
71
73
|
setup One-command setup (wallet + config + builder approval)
|
|
72
74
|
|
|
73
75
|
Info Commands:
|
|
@@ -136,7 +138,8 @@ Utility:
|
|
|
136
138
|
approve-builder Check or retry builder fee approval
|
|
137
139
|
|
|
138
140
|
Examples:
|
|
139
|
-
openbroker
|
|
141
|
+
npx openbroker@latest install --codex # Install skill + CLI + API-wallet setup
|
|
142
|
+
openbroker setup --api-wallet # Recommended restricted API-wallet setup
|
|
140
143
|
openbroker account # View account info
|
|
141
144
|
openbroker buy --coin ETH --size 0.1 # Market buy 0.1 ETH
|
|
142
145
|
openbroker limit --coin BTC --side buy --size 0.01 --price 60000
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"install.d.ts","sourceRoot":"","sources":["../../scripts/setup/install.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
// Harness-aware OpenBroker installer.
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { homedir } from 'os';
|
|
6
|
+
import { fileURLToPath } from 'url';
|
|
7
|
+
import { spawnSync } from 'child_process';
|
|
8
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
9
|
+
const __dirname = path.dirname(__filename);
|
|
10
|
+
const packageRoot = path.resolve(__dirname, '../..');
|
|
11
|
+
const args = new Set(process.argv.slice(2));
|
|
12
|
+
function printUsage() {
|
|
13
|
+
console.log(`
|
|
14
|
+
OpenBroker Harness Installer
|
|
15
|
+
============================
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
openbroker install --codex [options]
|
|
19
|
+
npx openbroker@latest install --codex [options]
|
|
20
|
+
|
|
21
|
+
Harnesses:
|
|
22
|
+
--codex Install the OpenBroker skill for Codex
|
|
23
|
+
|
|
24
|
+
Options:
|
|
25
|
+
--skip-cli Do not install the persistent global CLI
|
|
26
|
+
--skip-setup Install files without starting API-wallet onboarding
|
|
27
|
+
--help Show this help
|
|
28
|
+
|
|
29
|
+
The default Codex flow installs the global CLI, writes the skill under
|
|
30
|
+
$CODEX_HOME/skills/openbroker (default: ~/.codex/skills/openbroker), and starts
|
|
31
|
+
restricted API-wallet onboarding.
|
|
32
|
+
`);
|
|
33
|
+
}
|
|
34
|
+
function fail(message) {
|
|
35
|
+
console.error(`Error: ${message}`);
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
function assertOpenBrokerSkill(skillPath) {
|
|
39
|
+
if (!fs.existsSync(skillPath))
|
|
40
|
+
return;
|
|
41
|
+
const existing = fs.readFileSync(skillPath, 'utf8');
|
|
42
|
+
if (!/^name:\s*openbroker\s*$/m.test(existing)) {
|
|
43
|
+
fail(`refusing to overwrite unrelated skill at ${skillPath}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function copyManagedFile(source, destination) {
|
|
47
|
+
if (!fs.existsSync(source)) {
|
|
48
|
+
fail(`packaged installer asset is missing: ${source}`);
|
|
49
|
+
}
|
|
50
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true, mode: 0o755 });
|
|
51
|
+
fs.copyFileSync(source, destination);
|
|
52
|
+
fs.chmodSync(destination, 0o644);
|
|
53
|
+
}
|
|
54
|
+
function installCodexSkill() {
|
|
55
|
+
const codexHome = process.env.CODEX_HOME || path.join(homedir(), '.codex');
|
|
56
|
+
const destination = path.join(codexHome, 'skills', 'openbroker');
|
|
57
|
+
const skillPath = path.join(destination, 'SKILL.md');
|
|
58
|
+
assertOpenBrokerSkill(skillPath);
|
|
59
|
+
copyManagedFile(path.join(packageRoot, 'SKILL.md'), skillPath);
|
|
60
|
+
copyManagedFile(path.join(packageRoot, 'agents', 'openai.yaml'), path.join(destination, 'agents', 'openai.yaml'));
|
|
61
|
+
console.log(`✅ Codex skill installed: ${destination}`);
|
|
62
|
+
return destination;
|
|
63
|
+
}
|
|
64
|
+
function installGlobalCli() {
|
|
65
|
+
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
66
|
+
console.log('\nInstalling the persistent OpenBroker CLI...');
|
|
67
|
+
const result = spawnSync(npmCommand, ['install', '-g', 'openbroker@latest'], {
|
|
68
|
+
stdio: 'inherit',
|
|
69
|
+
});
|
|
70
|
+
if (result.error) {
|
|
71
|
+
fail(`could not start npm: ${result.error.message}`);
|
|
72
|
+
}
|
|
73
|
+
if (result.status !== 0) {
|
|
74
|
+
fail('global CLI installation failed. Fix the npm permission error, then rerun with --skip-cli.');
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function runApiWalletSetup() {
|
|
78
|
+
const onboardPath = path.join(packageRoot, 'scripts', 'setup', 'onboard.ts');
|
|
79
|
+
console.log('\nStarting restricted API-wallet onboarding...\n');
|
|
80
|
+
const result = spawnSync(process.execPath, ['--import', 'tsx', onboardPath, '--api-wallet'], {
|
|
81
|
+
stdio: 'inherit',
|
|
82
|
+
cwd: packageRoot,
|
|
83
|
+
env: process.env,
|
|
84
|
+
});
|
|
85
|
+
if (result.error) {
|
|
86
|
+
fail(`could not start onboarding: ${result.error.message}`);
|
|
87
|
+
}
|
|
88
|
+
if (result.status !== 0) {
|
|
89
|
+
fail('API-wallet onboarding did not complete. Rerun `openbroker setup --api-wallet`.');
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
function main() {
|
|
93
|
+
if (args.has('--help') || args.has('-h')) {
|
|
94
|
+
printUsage();
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (!args.has('--codex')) {
|
|
98
|
+
printUsage();
|
|
99
|
+
fail('choose a supported harness flag such as --codex');
|
|
100
|
+
}
|
|
101
|
+
console.log('OpenBroker — Codex Installation');
|
|
102
|
+
console.log('================================\n');
|
|
103
|
+
installCodexSkill();
|
|
104
|
+
if (!args.has('--skip-cli')) {
|
|
105
|
+
installGlobalCli();
|
|
106
|
+
}
|
|
107
|
+
if (!args.has('--skip-setup')) {
|
|
108
|
+
runApiWalletSetup();
|
|
109
|
+
}
|
|
110
|
+
console.log('\n✅ OpenBroker installation complete.');
|
|
111
|
+
console.log('Restart Codex or start a new thread, then invoke $openbroker.');
|
|
112
|
+
}
|
|
113
|
+
main();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onboard.d.ts","sourceRoot":"","sources":["../../scripts/setup/onboard.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"onboard.d.ts","sourceRoot":"","sources":["../../scripts/setup/onboard.ts"],"names":[],"mappings":";AA6BA,UAAU,aAAa;IACrB,OAAO,EAAE,OAAO,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAwND,iBAAe,IAAI,IAAI,OAAO,CAAC,aAAa,CAAC,CA8R5C;AAGD,OAAO,EAAE,IAAI,IAAI,OAAO,EAAE,CAAC"}
|
package/dist/setup/onboard.js
CHANGED
|
@@ -14,6 +14,7 @@ const GLOBAL_CONFIG_PATH = path.join(GLOBAL_CONFIG_DIR, '.env');
|
|
|
14
14
|
// Parse CLI flags
|
|
15
15
|
const cliArgs = process.argv.slice(2);
|
|
16
16
|
const useTestnet = cliArgs.includes('--testnet') || ENV_TESTNET;
|
|
17
|
+
const useApiWallet = cliArgs.includes('--api-wallet');
|
|
17
18
|
const accountAddressIdx = cliArgs.indexOf('--account-address');
|
|
18
19
|
const cliAccountAddress = accountAddressIdx !== -1 ? cliArgs[accountAddressIdx + 1] : undefined;
|
|
19
20
|
const configPathIdx = cliArgs.indexOf('-c') !== -1 ? cliArgs.indexOf('-c') : cliArgs.indexOf('--config');
|
|
@@ -213,11 +214,13 @@ Usage: openbroker setup [options]
|
|
|
213
214
|
Options:
|
|
214
215
|
-c, --config <path> Save config to a custom path (default: ~/.openbroker/.env)
|
|
215
216
|
--testnet Configure for testnet
|
|
217
|
+
--api-wallet Generate a restricted API wallet and skip the wallet menu
|
|
216
218
|
--account-address <addr> Set HYPERLIQUID_ACCOUNT_ADDRESS (for API wallet / vault trading)
|
|
217
219
|
--help Show this help
|
|
218
220
|
|
|
219
221
|
Examples:
|
|
220
|
-
openbroker setup # Interactive
|
|
222
|
+
openbroker setup # Interactive; API wallet is the default
|
|
223
|
+
openbroker setup --api-wallet # Recommended agent setup
|
|
221
224
|
openbroker setup -c .env --testnet # Write to ./.env for testnet
|
|
222
225
|
openbroker setup -c ./testnet.env --testnet --account-address 0x... # API wallet config
|
|
223
226
|
`);
|
|
@@ -300,21 +303,26 @@ Examples:
|
|
|
300
303
|
walletAddress: account.address,
|
|
301
304
|
};
|
|
302
305
|
}
|
|
306
|
+
// Agent-friendly non-interactive selection. Browser approval is still
|
|
307
|
+
// deliberately completed by the human who controls the master wallet.
|
|
308
|
+
if (useApiWallet) {
|
|
309
|
+
return setupApiWallet();
|
|
310
|
+
}
|
|
303
311
|
// Ask user which setup mode
|
|
304
312
|
const rl = createReadline();
|
|
305
313
|
console.log('Step 1/3: Wallet Setup');
|
|
306
314
|
console.log('----------------------');
|
|
307
315
|
console.log('How would you like to set up your wallet?\n');
|
|
308
|
-
console.log(' 1) Generate a fresh wallet
|
|
309
|
-
console.log(' Creates a dedicated
|
|
310
|
-
console.log(' Just fund it with USDC and start trading — no browser steps needed.');
|
|
316
|
+
console.log(' 1) Generate a fresh wallet');
|
|
317
|
+
console.log(' Creates a dedicated funded wallet. Builder fee is auto-approved.');
|
|
311
318
|
console.log('');
|
|
312
319
|
console.log(' 2) Import existing private key');
|
|
313
|
-
console.log(' 3) Generate API wallet (
|
|
320
|
+
console.log(' 3) Generate API wallet (recommended for agents)');
|
|
314
321
|
console.log(' Can trade but cannot withdraw. Requires master wallet approval in browser.\n');
|
|
315
322
|
let choice = '';
|
|
316
323
|
while (choice !== '1' && choice !== '2' && choice !== '3') {
|
|
317
|
-
|
|
324
|
+
const input = await prompt(rl, 'Enter choice (1, 2, or 3) [3]: ');
|
|
325
|
+
choice = input || '3';
|
|
318
326
|
if (choice !== '1' && choice !== '2' && choice !== '3') {
|
|
319
327
|
console.log('Please enter 1, 2, or 3');
|
|
320
328
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openbroker",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.2",
|
|
4
4
|
"description": "Hyperliquid trading CLI - execute orders, manage positions, and run trading strategies",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
"dist/",
|
|
21
21
|
"scripts/",
|
|
22
22
|
"config/example.env",
|
|
23
|
+
"agents/",
|
|
23
24
|
"SKILL.md",
|
|
24
25
|
"README.md",
|
|
25
26
|
"CHANGELOG.md"
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
#!/usr/bin/env npx tsx
|
|
2
|
+
// Harness-aware OpenBroker installer.
|
|
3
|
+
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import * as path from 'path';
|
|
6
|
+
import { homedir } from 'os';
|
|
7
|
+
import { fileURLToPath } from 'url';
|
|
8
|
+
import { spawnSync } from 'child_process';
|
|
9
|
+
|
|
10
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
11
|
+
const __dirname = path.dirname(__filename);
|
|
12
|
+
const packageRoot = path.resolve(__dirname, '../..');
|
|
13
|
+
const args = new Set(process.argv.slice(2));
|
|
14
|
+
|
|
15
|
+
function printUsage(): void {
|
|
16
|
+
console.log(`
|
|
17
|
+
OpenBroker Harness Installer
|
|
18
|
+
============================
|
|
19
|
+
|
|
20
|
+
Usage:
|
|
21
|
+
openbroker install --codex [options]
|
|
22
|
+
npx openbroker@latest install --codex [options]
|
|
23
|
+
|
|
24
|
+
Harnesses:
|
|
25
|
+
--codex Install the OpenBroker skill for Codex
|
|
26
|
+
|
|
27
|
+
Options:
|
|
28
|
+
--skip-cli Do not install the persistent global CLI
|
|
29
|
+
--skip-setup Install files without starting API-wallet onboarding
|
|
30
|
+
--help Show this help
|
|
31
|
+
|
|
32
|
+
The default Codex flow installs the global CLI, writes the skill under
|
|
33
|
+
$CODEX_HOME/skills/openbroker (default: ~/.codex/skills/openbroker), and starts
|
|
34
|
+
restricted API-wallet onboarding.
|
|
35
|
+
`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function fail(message: string): never {
|
|
39
|
+
console.error(`Error: ${message}`);
|
|
40
|
+
process.exit(1);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function assertOpenBrokerSkill(skillPath: string): void {
|
|
44
|
+
if (!fs.existsSync(skillPath)) return;
|
|
45
|
+
|
|
46
|
+
const existing = fs.readFileSync(skillPath, 'utf8');
|
|
47
|
+
if (!/^name:\s*openbroker\s*$/m.test(existing)) {
|
|
48
|
+
fail(`refusing to overwrite unrelated skill at ${skillPath}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function copyManagedFile(source: string, destination: string): void {
|
|
53
|
+
if (!fs.existsSync(source)) {
|
|
54
|
+
fail(`packaged installer asset is missing: ${source}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fs.mkdirSync(path.dirname(destination), { recursive: true, mode: 0o755 });
|
|
58
|
+
fs.copyFileSync(source, destination);
|
|
59
|
+
fs.chmodSync(destination, 0o644);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function installCodexSkill(): string {
|
|
63
|
+
const codexHome = process.env.CODEX_HOME || path.join(homedir(), '.codex');
|
|
64
|
+
const destination = path.join(codexHome, 'skills', 'openbroker');
|
|
65
|
+
const skillPath = path.join(destination, 'SKILL.md');
|
|
66
|
+
|
|
67
|
+
assertOpenBrokerSkill(skillPath);
|
|
68
|
+
copyManagedFile(path.join(packageRoot, 'SKILL.md'), skillPath);
|
|
69
|
+
copyManagedFile(
|
|
70
|
+
path.join(packageRoot, 'agents', 'openai.yaml'),
|
|
71
|
+
path.join(destination, 'agents', 'openai.yaml'),
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
console.log(`✅ Codex skill installed: ${destination}`);
|
|
75
|
+
return destination;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function installGlobalCli(): void {
|
|
79
|
+
const npmCommand = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
80
|
+
|
|
81
|
+
console.log('\nInstalling the persistent OpenBroker CLI...');
|
|
82
|
+
const result = spawnSync(npmCommand, ['install', '-g', 'openbroker@latest'], {
|
|
83
|
+
stdio: 'inherit',
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
if (result.error) {
|
|
87
|
+
fail(`could not start npm: ${result.error.message}`);
|
|
88
|
+
}
|
|
89
|
+
if (result.status !== 0) {
|
|
90
|
+
fail(
|
|
91
|
+
'global CLI installation failed. Fix the npm permission error, then rerun with --skip-cli.',
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function runApiWalletSetup(): void {
|
|
97
|
+
const onboardPath = path.join(packageRoot, 'scripts', 'setup', 'onboard.ts');
|
|
98
|
+
|
|
99
|
+
console.log('\nStarting restricted API-wallet onboarding...\n');
|
|
100
|
+
const result = spawnSync(
|
|
101
|
+
process.execPath,
|
|
102
|
+
['--import', 'tsx', onboardPath, '--api-wallet'],
|
|
103
|
+
{
|
|
104
|
+
stdio: 'inherit',
|
|
105
|
+
cwd: packageRoot,
|
|
106
|
+
env: process.env,
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (result.error) {
|
|
111
|
+
fail(`could not start onboarding: ${result.error.message}`);
|
|
112
|
+
}
|
|
113
|
+
if (result.status !== 0) {
|
|
114
|
+
fail('API-wallet onboarding did not complete. Rerun `openbroker setup --api-wallet`.');
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function main(): void {
|
|
119
|
+
if (args.has('--help') || args.has('-h')) {
|
|
120
|
+
printUsage();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
if (!args.has('--codex')) {
|
|
125
|
+
printUsage();
|
|
126
|
+
fail('choose a supported harness flag such as --codex');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
console.log('OpenBroker — Codex Installation');
|
|
130
|
+
console.log('================================\n');
|
|
131
|
+
|
|
132
|
+
installCodexSkill();
|
|
133
|
+
|
|
134
|
+
if (!args.has('--skip-cli')) {
|
|
135
|
+
installGlobalCli();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (!args.has('--skip-setup')) {
|
|
139
|
+
runApiWalletSetup();
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
console.log('\n✅ OpenBroker installation complete.');
|
|
143
|
+
console.log('Restart Codex or start a new thread, then invoke $openbroker.');
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
main();
|
package/scripts/setup/onboard.ts
CHANGED
|
@@ -18,6 +18,7 @@ const GLOBAL_CONFIG_PATH = path.join(GLOBAL_CONFIG_DIR, '.env');
|
|
|
18
18
|
// Parse CLI flags
|
|
19
19
|
const cliArgs = process.argv.slice(2);
|
|
20
20
|
const useTestnet = cliArgs.includes('--testnet') || ENV_TESTNET;
|
|
21
|
+
const useApiWallet = cliArgs.includes('--api-wallet');
|
|
21
22
|
const accountAddressIdx = cliArgs.indexOf('--account-address');
|
|
22
23
|
const cliAccountAddress = accountAddressIdx !== -1 ? cliArgs[accountAddressIdx + 1] : undefined;
|
|
23
24
|
const configPathIdx = cliArgs.indexOf('-c') !== -1 ? cliArgs.indexOf('-c') : cliArgs.indexOf('--config');
|
|
@@ -257,11 +258,13 @@ Usage: openbroker setup [options]
|
|
|
257
258
|
Options:
|
|
258
259
|
-c, --config <path> Save config to a custom path (default: ~/.openbroker/.env)
|
|
259
260
|
--testnet Configure for testnet
|
|
261
|
+
--api-wallet Generate a restricted API wallet and skip the wallet menu
|
|
260
262
|
--account-address <addr> Set HYPERLIQUID_ACCOUNT_ADDRESS (for API wallet / vault trading)
|
|
261
263
|
--help Show this help
|
|
262
264
|
|
|
263
265
|
Examples:
|
|
264
|
-
openbroker setup # Interactive
|
|
266
|
+
openbroker setup # Interactive; API wallet is the default
|
|
267
|
+
openbroker setup --api-wallet # Recommended agent setup
|
|
265
268
|
openbroker setup -c .env --testnet # Write to ./.env for testnet
|
|
266
269
|
openbroker setup -c ./testnet.env --testnet --account-address 0x... # API wallet config
|
|
267
270
|
`);
|
|
@@ -358,23 +361,29 @@ Examples:
|
|
|
358
361
|
};
|
|
359
362
|
}
|
|
360
363
|
|
|
364
|
+
// Agent-friendly non-interactive selection. Browser approval is still
|
|
365
|
+
// deliberately completed by the human who controls the master wallet.
|
|
366
|
+
if (useApiWallet) {
|
|
367
|
+
return setupApiWallet();
|
|
368
|
+
}
|
|
369
|
+
|
|
361
370
|
// Ask user which setup mode
|
|
362
371
|
const rl = createReadline();
|
|
363
372
|
|
|
364
373
|
console.log('Step 1/3: Wallet Setup');
|
|
365
374
|
console.log('----------------------');
|
|
366
375
|
console.log('How would you like to set up your wallet?\n');
|
|
367
|
-
console.log(' 1) Generate a fresh wallet
|
|
368
|
-
console.log(' Creates a dedicated
|
|
369
|
-
console.log(' Just fund it with USDC and start trading — no browser steps needed.');
|
|
376
|
+
console.log(' 1) Generate a fresh wallet');
|
|
377
|
+
console.log(' Creates a dedicated funded wallet. Builder fee is auto-approved.');
|
|
370
378
|
console.log('');
|
|
371
379
|
console.log(' 2) Import existing private key');
|
|
372
|
-
console.log(' 3) Generate API wallet (
|
|
380
|
+
console.log(' 3) Generate API wallet (recommended for agents)');
|
|
373
381
|
console.log(' Can trade but cannot withdraw. Requires master wallet approval in browser.\n');
|
|
374
382
|
|
|
375
383
|
let choice = '';
|
|
376
384
|
while (choice !== '1' && choice !== '2' && choice !== '3') {
|
|
377
|
-
|
|
385
|
+
const input = await prompt(rl, 'Enter choice (1, 2, or 3) [3]: ');
|
|
386
|
+
choice = input || '3';
|
|
378
387
|
if (choice !== '1' && choice !== '2' && choice !== '3') {
|
|
379
388
|
console.log('Please enter 1, 2, or 3');
|
|
380
389
|
}
|