@hedge-layer/cli 4.0.1 → 5.0.0

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 CHANGED
@@ -1,113 +1,142 @@
1
1
  # @hedge-layer/cli
2
2
 
3
- [![npm version](https://img.shields.io/npm/v/@hedge-layer/cli)](https://www.npmjs.com/package/@hedge-layer/cli)
4
- [![license](https://img.shields.io/github/license/hedge-layer/hedge-layer-cli)](LICENSE)
3
+ [Hedge Layer](https://github.com/hedge-layer/hedge-layer) is a unified layer for
4
+ financial data and trade execution. Its main service exposes tools through MCP
5
+ at `/mcp` and the HTTP API. The `hl` CLI calls that API to offer the same
6
+ operations to agents and scripts that prefer command-line tools. The web app
7
+ provides connection instructions and API token management.
5
8
 
6
- Command-line interface for [Hedge Layer](https://hedgelayer.ai): prediction market intelligence from the terminal.
9
+ [Agent H](https://github.com/hedge-layer/agent-h) is the native MCP agent and an
10
+ optional client. You can use Codex, Claude Code, Python, or any other compatible
11
+ client. Research workflows belong to the chosen agent; the CLI discovers tool
12
+ schemas from the service and forwards the arguments you supply.
7
13
 
8
- The canonical CLI guide now lives in the Hedge Layer web app docs:
9
- [hedgelayer.ai/docs/cli](https://hedgelayer.ai/docs/cli).
14
+ Current tools cover Polymarket and Hyperliquid market search, Polymarket market
15
+ data and order books, web evidence search, and locally signed Polymarket order
16
+ submission, lookup, and cancellation. Matching and settlement stay at the venue.
10
17
 
11
18
  ## Install
12
19
 
13
20
  ```bash
14
- npm install -g @hedge-layer/cli
21
+ npm install -g @hedge-layer/cli@5
15
22
  ```
16
23
 
17
- Requires Node.js 22 or later.
24
+ CLI 5.x requires Node.js 22 or later and a Hedge Layer server providing the
25
+ `/api/v1/tools` API. To build from source, follow the
26
+ [development instructions](#development) and replace `hl` in the examples with
27
+ `node dist/index.mjs`.
18
28
 
19
- ### Install troubleshooting
29
+ ## Quick start
20
30
 
21
- - **`EACCES` / "operation was rejected by your operating system"** on `npm install -g`:
22
- your npm prefix points at a root-owned directory (e.g. `/usr/lib/node_modules`) and you
23
- don't have `sudo`. Install into a user-writable prefix instead:
31
+ Create an API token in your Hedge Layer account settings, then:
24
32
 
25
- ```bash
26
- mkdir -p "$HOME/.npm-global"
27
- npm config set prefix "$HOME/.npm-global"
28
- export PATH="$HOME/.npm-global/bin:$PATH" # add to your shell rc to persist
29
- npm install -g @hedge-layer/cli
30
- ```
33
+ ```bash
34
+ hl auth login
35
+ hl tools
36
+ hl tools search_markets
37
+ hl call search_markets --args '{"query":"bitcoin","venues":["polymarket","hyperliquid"],"limit":5}'
38
+ hl call list_polymarket_markets
39
+ hl call get_polymarket_orderbook --args '{"token_id":"<token-id>"}'
40
+ ```
41
+
42
+ `hl auth login` hides token input. For scripts, provide `HL_TOKEN` through your
43
+ shell or secret manager. Set `HL_API_URL` to use another server, or pass
44
+ `--api-url http://localhost:3000` for local development.
31
45
 
32
- - **`nvm` warns `npmrc ... globalconfig and/or prefix setting ... incompatible with nvm`:**
33
- this is harmless shell-init noise from `nvm` (not from `hl`) that appears after setting a
34
- custom npm prefix as above — the CLI still works. To avoid it entirely under `nvm`, install
35
- without a custom prefix (nvm's per-version `bin/` is already user-writable):
46
+ ## Commands
36
47
 
37
- ```bash
38
- npm config delete prefix
39
- npm config delete globalconfig
40
- nvm use --delete-prefix "$(node -v)" --silent
41
- npm install -g @hedge-layer/cli
42
- ```
48
+ | Command | Behavior |
49
+ | --- | --- |
50
+ | `hl tools [name]` | List the server's tools and JSON Schemas, or inspect one tool |
51
+ | `hl call <name> [--args <json> \| --file <path> \| --stdin]` | Invoke a tool with a JSON object; defaults to `{}` |
52
+ | `hl auth login` | Validate and save an API token |
53
+ | `hl auth status` | Validate the active token against the tool catalog |
54
+ | `hl auth logout` | Remove the saved token; environment variables and flags still apply |
43
55
 
44
- Alternatively, skip the global install and run on demand with `npx @hedge-layer/cli <command>`.
56
+ All successful command output is JSON on stdout. Prompts and diagnostics go to
57
+ stderr. `hl call` preserves the complete MCP result, including `content`,
58
+ `structuredContent`, and `isError`. Tool errors (`isError: true`) retain their
59
+ JSON output and exit with status 1. HTTP, network, and input errors also exit
60
+ with status 1, with a JSON error on stderr. Command-line usage errors are
61
+ printed by the argument parser.
45
62
 
46
- ## Quick Start
63
+ Arguments must be a JSON object, using exactly one input source:
47
64
 
48
65
  ```bash
49
- # 1. Create an API token at https://hedgelayer.ai/account/settings
50
- # 2. Authenticate the CLI
51
- hl auth login
52
-
53
- # 3. Generate a Market Brief
54
- hl brief "US China trade war tariffs"
66
+ hl call search_markets --file query.json
67
+ cat query.json | hl call search_markets --stdin
68
+ hl call search_markets --args '{"query":"bitcoin"}' | jq '.structuredContent'
69
+ ```
55
70
 
56
- # 4. Or start an interactive research session
57
- hl research
71
+ Use `hl tools` as the authoritative list for your server. Tool names, schemas,
72
+ and `requiredScope` come from the API, so the CLI does not need a release when
73
+ a provider adds a tool.
58
74
 
59
- # 5. Preview a directional quote (analysis only; no order is submitted)
60
- hl quote "example-market" --action buy --outcome yes --cash 25
75
+ ## Execution
61
76
 
62
- # 6. Save a fresh quote preview with Signal-linked sizing context
63
- hl quote "example-market" --action buy --outcome yes --cash 25 \
64
- --signal-id <forecast-id> --capital 1000 --save
77
+ Polymarket order submission, cancellation, and order lookup use locally signed
78
+ venue requests. Create a Hedge Layer token with `read` and `trade` scopes for
79
+ submission and cancellation; order lookup requires `read`. New tokens are
80
+ read-only by default. Inspect the exact schemas first:
65
81
 
66
- # 7. Analyze a market probability edge
67
- hl signal analyze "https://polymarket.com/event/example-market"
82
+ ```bash
83
+ hl tools submit_polymarket_order
84
+ hl tools cancel_polymarket_order
85
+ hl tools get_polymarket_order
68
86
  ```
69
87
 
70
- ## Commands
71
-
72
- Full command documentation is available at
73
- [hedgelayer.ai/docs/cli](https://hedgelayer.ai/docs/cli).
74
-
75
- Directional quote previews are available with `hl quote`:
88
+ Use the venue SDK locally to sign the order and its request authentication.
89
+ Your signing code should produce an arguments object containing `signed_body`
90
+ (the exact signed request body as a string) and `auth` (address, API key,
91
+ passphrase, timestamp, and signature). Pass that object through stdin or a
92
+ private file so credentials do not enter shell history:
76
93
 
77
94
  ```bash
78
- hl quote example-market --action buy --outcome yes --cash 25
79
- hl quote example-market --action buy --outcome no --shares 50 --route passive
80
- hl quote example-market --action sell --outcome yes --shares 20 --save
81
- hl --json quote example-market --action buy --outcome yes --cash 25
95
+ hl call submit_polymarket_order --stdin < signed-order-arguments.json
96
+ hl call cancel_polymarket_order --stdin < signed-cancellation-arguments.json
97
+ hl call get_polymarket_order --stdin < signed-order-lookup-arguments.json
82
98
  ```
83
99
 
84
- Quote reads public Polymarket market data and order-book depth, then reports the
85
- estimated fill, slippage, fees, cost or proceeds, payout risk, and optional
86
- Signal edge. It never signs or submits an order. `--cash` is BUY-only; SELL
87
- quotes require `--shares`.
100
+ Order lookup arguments contain `order_id` and `auth` instead of `signed_body`.
101
+ The CLI preserves the exact `signed_body` string. It never signs requests,
102
+ requests wallet private keys or CLOB API secrets, or retries calls. If a
103
+ submission times out, reconcile its status with the venue before submitting
104
+ again. See the [Hedge Layer execution guide](https://hedgelayer.ai/docs/execution)
105
+ for the server contract and signing workflow.
88
106
 
89
- Liquidity allocation, wallet management, and trade execution are outside the
90
- official `hl` CLI.
107
+ ## Configuration
91
108
 
92
- For a broader discovery screen, `hl feed ensemble` runs several feed lenses
93
- (liquid core, active volume, movers, new markets, uncertainty, and LP quality),
94
- de-duplicates by slug, and writes a ranked candidate file:
109
+ Options take precedence over environment variables, then saved configuration:
95
110
 
96
- ```bash
97
- hl feed ensemble --limit 25 --output candidates.json
98
- ```
111
+ | Setting | Flag | Environment | Default |
112
+ | --- | --- | --- | --- |
113
+ | API origin | `--api-url` | `HL_API_URL` | `https://hedgelayer.ai` |
114
+ | API token | `--token` | `HL_TOKEN` | Token saved by `hl auth login` |
115
+ | HTTP diagnostics | `--verbose` | — | Off |
116
+
117
+ The CLI does not load `.env` files. Export variables in your shell or secret
118
+ manager. Configuration is saved to `~/.hedgelayer/config.json` with file mode
119
+ `0600`. URLs must use HTTPS, except HTTP loopback servers for development.
120
+ Redirects are rejected. Verbose output includes method, URL, and status only.
99
121
 
100
- Signal-agent analysis is available under `hl signal`:
122
+ ## Development
101
123
 
102
124
  ```bash
103
- hl signal analyze "https://polymarket.com/event/example-market"
104
- hl signal analyze "https://polymarket.com/event/example-market" --context "Recent search notes"
105
- hl --json signal analyze "https://polymarket.com/event/example-market" | jq '.result.analysis'
125
+ npm ci
126
+ npm run typecheck
127
+ npm run lint
128
+ npm test
129
+ npm run build
130
+ node dist/index.mjs --help
106
131
  ```
107
132
 
108
- ## Changelog
133
+ Tests cover the HTTP contract, the built binary against a local API server,
134
+ authentication, signed payload preservation, error exits, redirects, and
135
+ configuration permissions. They do not place live orders.
109
136
 
110
- See [CHANGELOG.md](CHANGELOG.md) for release history.
137
+ This is a fresh command surface: the former `brief`, `research`, `feed`,
138
+ `signal`, `quote`, and `profile` commands have been removed. Use the server's
139
+ tools directly and let your chosen agent handle research workflows.
111
140
 
112
141
  ## License
113
142