@matelink/cli 2026.4.7

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.
Files changed (3) hide show
  1. package/README.md +180 -0
  2. package/bin/matecli.mjs +3093 -0
  3. package/package.json +20 -0
package/README.md ADDED
@@ -0,0 +1,180 @@
1
+ # @matelink/cli
2
+
3
+ Relay-first standalone CLI for pairing a mobile client with an OpenClaw host and
4
+ keeping a relay bridge online.
5
+
6
+ ## 1) Install
7
+
8
+ Install standalone CLI:
9
+
10
+ ```bash
11
+ # global
12
+ npm i -g @matelink/cli
13
+
14
+ # or one-off
15
+ npx @matelink/cli pair
16
+ ```
17
+
18
+ CLI commands:
19
+
20
+ ```bash
21
+ matecli setup
22
+ matecli pair
23
+ matecli pair 123456
24
+ matecli pair --code 123456
25
+ matecli bridge
26
+ matecli pair-url
27
+ matecli status
28
+ ```
29
+
30
+ Recommended first-run flow after `npm i -g @matelink/cli`:
31
+
32
+ ```bash
33
+ # 1) prepare OpenClaw config + permissions
34
+ matecli setup --relay http://<relay-host>:8090 --public-base http://<gateway-public-host>:<port>
35
+
36
+ # 2) then pair and keep relay bridge online (short form)
37
+ matecli pair 123456 --serve-relay
38
+ ```
39
+
40
+ Relay-aware pairing (auto publish + local bind worker):
41
+
42
+ ```bash
43
+ matecli pair --relay http://<relay-host>:8090 --wait-bind --serve-relay
44
+ matecli pair --code 123456 --relay http://<relay-host>:8090 --wait-bind --serve-relay
45
+ # or set once:
46
+ export TESTNEXTIM_RELAY_URL=http://<relay-host>:8090
47
+ matecli pair --wait-bind --serve-relay
48
+ ```
49
+
50
+ When relay is configured, `pair` publishes `{code, bindUrl, gatewayBaseUrl, relayGatewayId, relayClientToken, relayGatewayToken}` to:
51
+
52
+ `POST /v1/pair-sessions`
53
+
54
+ And in `--wait-bind` mode it also runs a local bind worker:
55
+
56
+ - Polls relay `GET /v1/pair-sessions/{code}/bind-requests/next`
57
+ - Records the bind result in local CLI state
58
+ - Reports result via `POST /v1/pair-sessions/{code}/bind-results`
59
+
60
+ In `--serve-relay` mode, CLI also keeps a chat bridge online:
61
+
62
+ - Polls relay `GET /v1/gateways/{gatewayId}/requests/next`
63
+ - Calls local gateway `POST /v1/responses`
64
+ - Streams chunks back through `POST /v1/gateways/{gatewayId}/requests/{requestId}/events`
65
+
66
+ ## 2) Configure minimum fields
67
+
68
+ ```bash
69
+ matecli setup --relay http://<relay-host>:8090 --public-base https://gw.example.com
70
+ ```
71
+
72
+ This prepares the local OpenClaw gateway for `/v1/responses`, stores relay
73
+ credentials in `~/.openclaw/testnextim.state.json`, and keeps plugin config out
74
+ of `openclaw.json`.
75
+
76
+ ## 3) QR login flow
77
+
78
+ Start OpenClaw first, then pair from the app:
79
+
80
+ ```bash
81
+ openclaw gateway run --bind loopback --port 18789 --force
82
+ ```
83
+
84
+ Use the mobile app to generate a pairing code, then run:
85
+
86
+ ```bash
87
+ matecli pair 123456 --serve-relay
88
+ ```
89
+
90
+ ### 4.3 Check active bind state (optional)
91
+
92
+ `GET {bindPublicBaseUrl}{bindPath}?accountId=default`
93
+
94
+ Response includes current active `code`, `bindUrl`, and `expiresAt` if a pairing session is active.
95
+
96
+ The plugin validates DM policy and pairing, dispatches to OpenClaw, and sends replies to your IM backend via:
97
+
98
+ `POST {apiBaseUrl}/messages`
99
+
100
+ Payload:
101
+
102
+ ```json
103
+ {
104
+ "to": "im-user-123",
105
+ "text": "reply text",
106
+ "mediaUrl": "https://...",
107
+ "replyToId": "msg-1"
108
+ }
109
+ ```
110
+
111
+ ## 5) Modify config from IM + restart
112
+
113
+ This plugin enables config commands by default when setup/bind succeeds.
114
+
115
+ In chat:
116
+
117
+ ```text
118
+ /config set channels.testnextim.allowFrom ["im-user-123","im-admin-1"]
119
+ /config set channels.testnextim.configWrites true
120
+ /restart
121
+ ```
122
+
123
+ Notes:
124
+
125
+ - most `channels.*` updates hot-reload
126
+ - gateway/network base settings usually require restart
127
+
128
+ ## 6) Optional environment secrets
129
+
130
+ You can provide secrets by environment instead of config file:
131
+
132
+ - `TESTNEXTIM_ACCESS_TOKEN`
133
+ - `TESTNEXTIM_APP_SECRET`
134
+ - `OPENCLAW_TESTNEXTIM_PUBLIC_BASE_URL`
135
+ - `OPENCLAW_TESTNEXTIM_GATEWAY_BASE_URL`
136
+
137
+ Compatibility:
138
+
139
+ - Legacy `channels.custom-im.*` config keys are still read during migration.
140
+ - Legacy headers `x-custom-im-token` and `x-custom-im-app-secret` are still accepted.
141
+
142
+ ## 7) Relay architecture requirement
143
+
144
+ Relay is optional for traditional direct bind, but strongly recommended for mobile pairing when OpenClaw is behind NAT or has no public gateway URL.
145
+
146
+ - Direct mode: app calls your gateway bind URL directly.
147
+ - Relay worker mode (`matecli pair --wait-bind`): app only talks to relay, server-side CLI does local bind on behalf of app.
148
+ - Relay bridge mode (`matecli pair --serve-relay` or `matecli bridge`): app chat traffic goes through relay, and host-side CLI forwards to local `127.0.0.1` gateway.
149
+
150
+ ## 8) Go Relay Server (Pair Session Bus)
151
+
152
+ Server path:
153
+
154
+ `extensions/testnextim/relay-server`
155
+
156
+ Run:
157
+
158
+ ```bash
159
+ cd extensions/testnextim/relay-server
160
+ go run .
161
+ ```
162
+
163
+ Environment:
164
+
165
+ - `TESTNEXTIM_RELAY_PORT` (default `8090`)
166
+ - `TESTNEXTIM_RELAY_TOKEN` (optional bearer token for publish/worker endpoints)
167
+ - `TESTNEXTIM_RELAY_DEFAULT_TTL_SECONDS` (default `600`)
168
+
169
+ API:
170
+
171
+ - `POST /v1/pair-sessions` create/update pair session
172
+ - `GET /v1/pair-sessions/{code}` query pair session (app side)
173
+ - `POST /v1/pair-sessions/{code}/consume` mark consumed
174
+ - `GET /v1/pair-sessions/{code}/events` SSE stream for status updates
175
+ - `POST /v1/pair-sessions/{code}/bind` app submits bind payload and waits for worker result
176
+ - `GET /v1/pair-sessions/{code}/bind-requests/next` worker polls pending bind requests
177
+ - `POST /v1/pair-sessions/{code}/bind-results` worker reports local gateway bind result
178
+ - `GET /v1/gateways/{gatewayId}/requests/next` gateway bridge polls pending chat requests
179
+ - `POST /v1/gateways/{gatewayId}/requests/{requestId}/events` gateway bridge streams relay events
180
+ - `POST /v1/openclaw/responses` app chat endpoint (supports `gatewayId + clientToken`)