asyx 0.5.2 → 0.5.5

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,169 +1,240 @@
1
1
  # Asyx CLI
2
2
 
3
- Secure, device-bound tunnels for HTTP, TCP, and UDP. The CLI handles device auth, JWT refresh, and resilient control-plane connectivity so you can expose local services without managing relay infrastructure.
3
+ **Turn `localhost:3000` into `https://yourname.tunnel.asyx.ai` in one command.**
4
4
 
5
- > Beta access is open — create an account at https://www.asyx.ai/register (email + magic link; no invite code).
5
+ Coding assistants—Cursor, Claude Code, Copilot, Windsurf, and others—build apps that run on your machine. Stakeholders cannot see that work until you share a public URL. Asyx closes that gap: install the CLI, enroll once, then tunnel whatever port your dev server uses.
6
6
 
7
- **Documentation:** https://www.asyx.ai/docs
7
+ > **Free account** — [asyx.ai/register](https://www.asyx.ai/register) (email + magic link; no invite code).
8
8
 
9
- | Guide | Link |
10
- |-------|------|
11
- | Getting started | https://www.asyx.ai/docs/getting-started |
12
- | Publish in 60 seconds | https://www.asyx.ai/docs/publish-local-project |
13
- | Expose localhost | https://www.asyx.ai/docs/expose-localhost |
14
- | AI coding agents | https://www.asyx.ai/docs/ai-agents |
15
- | Cursor + Asyx | https://www.asyx.ai/docs/cursor-asyx |
16
- | vs ngrok & Cloudflare | https://www.asyx.ai/docs/vs-ngrok-cloudflare |
17
- | Quickpass (guest access) | https://www.asyx.ai/docs/quickpass |
9
+ **Full documentation:** https://www.asyx.ai/docs
18
10
 
19
11
  ---
20
12
 
21
- ## 0. Install & Update
13
+ ## Publish what your agent built
14
+
15
+ ```text
16
+ Agent writes code → dev server starts → asyx tunnel → share HTTPS link
17
+ ```
18
+
19
+ | Step | Who | What to do |
20
+ | --- | --- | --- |
21
+ | Account + enroll | **You** (once per machine) | `asyx setup` after [registering](https://www.asyx.ai/register) |
22
+ | Build / edit code | **Agent** | Implements the feature locally |
23
+ | Start dev server | **Agent or you** | `npm run dev`, `vite`, `flask run`, etc. |
24
+ | Open public URL | **Agent or you** (terminal) | `asyx tunnel --http --port <port>` |
25
+ | Share the link | **You** | PR comment, Slack, email, client review |
26
+
27
+ Enrollment is human-gated (browser verification) so prompts alone cannot open tunnels from an unbound machine. After `asyx setup`, your agent only needs the port and one tunnel command.
28
+
29
+ ### 60-second path to a public link
30
+
22
31
  ```bash
23
- npm install -g asyx # install
24
- npm update -g asyx # upgrade
25
- npm uninstall -g asyx # remove
32
+ npm install -g asyx # 1. install (Node 18.17+)
33
+ asyx setup # 2. enroll once — browser opens, pick your subdomain
34
+ npm run dev # 3. start your app (note the port, often 3000 or 5173)
35
+ asyx tunnel --http --port 3000 # 4. second terminal — copy the printed URL
36
+ ```
37
+
38
+ Share `https://yourname.tunnel.asyx.ai`. Press `Ctrl+C` in the tunnel terminal when the demo ends.
39
+
40
+ Works with React, Next.js, Vite, Flask, FastAPI, Express, static sites, local LLM UIs—anything speaking HTTP on localhost.
41
+
42
+ Prefer no global install?
43
+
44
+ ```bash
45
+ npx asyx@latest tunnel --http --port 3000
26
46
  ```
27
- - Node.js 18.17+ recommended. Prefer `npx asyx <cmd>` if you cannot install globally.
47
+
48
+ ### Copy-paste for your agent
49
+
50
+ Add this to a Cursor rule, Claude project, or task prompt:
51
+
52
+ ```text
53
+ PUBLISHING CONTRACT — Asyx tunnel
54
+
55
+ Prerequisites (human completes once per machine):
56
+ - asyx CLI installed (npm install -g asyx)
57
+ - asyx setup completed (browser enrollment)
58
+
59
+ When a local HTTP server is running on PORT:
60
+ 1. Run: asyx tunnel --http --port PORT
61
+ 2. Return the https://*.tunnel.asyx.ai URL as "public_demo_url"
62
+ 3. Do NOT read, print, or commit ~/.asyx/ or any private.pem files
63
+ 4. Stop tunnel with Ctrl+C when the user says the demo is over
64
+
65
+ If asyx setup was never run, tell the human to run it before tunneling.
66
+ ```
67
+
68
+ Replace `PORT` with the actual port (e.g. `3000`, `5173`, `8080`).
69
+
70
+ ### Example Cursor prompt
71
+
72
+ ```text
73
+ Implement the settings page, run the dev server on port 3000, then run
74
+ asyx tunnel --http --port 3000 and give me the public demo URL.
75
+ I already ran asyx setup on this machine.
76
+ ```
77
+
78
+ **Can the agent run the tunnel itself?** Yes—if your IDE grants terminal access and `asyx` is installed. Many teams run the tunnel command themselves for visibility.
79
+
80
+ **More guides:** [AI agents](https://www.asyx.ai/docs/ai-agents) · [Cursor + Asyx](https://www.asyx.ai/docs/cursor-asyx) · [Agent checklist](https://www.asyx.ai/docs/ai-agent-checklist) · [Publish in 60 seconds](https://www.asyx.ai/docs/publish-local-project)
28
81
 
29
82
  ---
30
83
 
31
- ## What's New in 0.4.0
84
+ ## Install & update
85
+
86
+ ```bash
87
+ npm install -g asyx # install
88
+ npm update -g asyx # upgrade
89
+ npm uninstall -g asyx # remove
90
+ ```
32
91
 
33
- **Improved large file downloads**: HTTP tunnels now automatically use streaming transport for large responses (8 MiB+ or unknown size). This enables reliable downloads of any size without hitting memory limits or connection timeouts. The switch happens automatically—no flags or configuration needed. Small responses continue to work exactly as before.
92
+ Node.js **18.17+** recommended.
34
93
 
35
94
  ---
36
95
 
37
- ## 1. Set up the device (once per host)
96
+ ## One-time device setup
97
+
38
98
  ```bash
39
99
  asyx setup
40
100
  ```
41
- - Opens a browser for passwordless approval and lets you choose `<subdomain>.tunnel.asyx.ai`.
101
+
102
+ - Opens your browser for passwordless approval; you choose `<subdomain>.tunnel.asyx.ai`.
42
103
  - Provisions a device certificate and client ID under `~/.asyx/certs/<clientId>/`.
43
104
  - Hardware fingerprint is hashed locally; raw attributes never leave the device.
44
- - Certificates are single-device; run `asyx setup` on each host.
105
+ - Run `asyx setup` on each host you want to trust—certificates are single-device.
45
106
 
46
107
  ---
47
108
 
48
- ## 2. Open tunnels
49
- All tunnels are loopback-only. The CLI never binds your app port; it forwards to your existing listener. Public port comes from your tenant’s 10-port block (auto-assigned unless you request one with `--external-port`).
109
+ ## HTTP tunnels (most common)
50
110
 
51
- ### HTTP
52
111
  ```bash
53
112
  asyx tunnel --http --port 3000
54
113
  ```
55
- - Forwards HTTP traffic to `127.0.0.1:3000`.
56
- - Forward-only proxy; automatic JWT refresh.
57
114
 
58
- ### TCP
115
+ - Forwards to `127.0.0.1:3000` (loopback only).
116
+ - Prints your stable `https://<subdomain>.tunnel.asyx.ai` URL.
117
+ - TLS and JWT refresh handled automatically; your app keeps its port.
118
+
119
+ ### Private demos (Quickpass)
120
+
121
+ For client-only or team-only previews—not open to the whole internet:
122
+
123
+ ```bash
124
+ asyx tunnel --http --port 3000 --secgroup reviewers
125
+ ```
126
+
127
+ Guests enroll via Quickpass; the relay enforces membership. See https://www.asyx.ai/docs/quickpass
128
+
129
+ ---
130
+
131
+ ## Other tunnel types
132
+
133
+ All tunnels are loopback-only. The CLI forwards to your existing listener—it never binds your app port.
134
+
135
+ **TCP** — databases, SSH, games:
136
+
59
137
  ```bash
60
138
  asyx tunnel --tcp --port <targetPort> [--name <alias>] [--external-port <publicPort>]
61
139
  ```
62
- - For raw TCP services (databases, SSH, games).
63
- - `--port`: local app port on loopback.
64
- - `--name` (optional): CNAME alias `<name>.<subdomain>.tunnel.asyx.ai`; otherwise use `fqdn:publicPort`.
65
- - `--external-port` (optional): must be inside your tenant block; otherwise rejected.
66
- - Uses tcpWs transport; guests connect with native TCP on the public port.
67
140
 
68
- ### UDP
141
+ **UDP** — games, realtime apps:
142
+
69
143
  ```bash
70
144
  asyx tunnel --udp --port <targetPort> [--external-port <publicPort>]
71
145
  ```
72
- - For UDP services (games, realtime apps).
73
- - `--port`: local app port on loopback.
74
- - `--external-port`: optional request within your tenant block.
75
- - CLI uses an **ephemeral** socket; it never claims your service port. Forwards to your app.
76
- - Loopback-only is enforced by CLI and relay.
77
- - Uses udpWs transport; guests send native UDP to the public port.
78
-
79
- ### Minecraft (shortcut)
146
+
147
+ **Minecraft** — shortcut with SRV record (players use hostname only):
148
+
80
149
  ```bash
81
- asyx tunnel --minecraft [--port <localPort>] [--name <alias>]
150
+ asyx tunnel --minecraft [--port 25565] [--name <alias>]
82
151
  ```
83
- - One command to share a Minecraft server (defaults to 25565).
84
- - SRV record created so players use the hostname only (no port needed).
85
152
 
86
- After a tunnel opens, the CLI prints:
87
- - `fqdn` and `fqdn:publicPort` for guests.
88
- - Target shown as `tcp://127.0.0.1:<port>` or `udp://127.0.0.1:<port>` so you know your app keeps the port.
153
+ After a tunnel opens, the CLI prints the public `fqdn` (and port for TCP/UDP) plus the local target (`tcp://127.0.0.1:<port>` or `udp://127.0.0.1:<port>`).
89
154
 
90
155
  ---
91
156
 
92
- ## 3. Command quick reference
157
+ ## Command quick reference
158
+
93
159
  ```bash
94
- asyx setup # Provision device cert & client ID
95
- asyx tunnel --http --port <n> # HTTP tunnel
160
+ asyx setup
161
+ asyx tunnel --http --port <n> [--secgroup <slug>]
96
162
  asyx tunnel --tcp --port <n> [--name <alias>] [--external-port <p>]
97
163
  asyx tunnel --udp --port <n> [--external-port <p>]
98
164
  asyx tunnel --minecraft [--port <n>] [--name <alias>]
99
165
  ```
100
- - Targets are loopback-only; non-loopback hosts are rejected.
101
- - `--external-port` must be inside your assigned block; omit to auto-assign blockStart.
102
166
 
103
167
  ---
104
168
 
105
- ## 4. Protocol details (high level)
106
- - **Transport**: TCP/UDP tunnels use WebSocket to the relay (tcpWs/udpWs); guests see native TCP/UDP on the public port.
107
- - **Assignments**: Coordinator returns `fqdn`, `publicPort`, `relayUrl`, and JWT. CLI validates JWT via JWKS before connecting.
108
- - **Aliases & SRV**: TCP can create CNAME aliases via `--name`; Minecraft auto-provisions SRV so players use the hostname only.
109
- - **Loopback-only**: CLI validates; relay enforces at admission/binding. Targets must resolve to loopback.
110
- - **Owner-only auth**: HTTP can use Quickpass groups; TCP/UDP are owner-authenticated via JWT (no per-guest auth in v4.1).
111
-
112
- ### Quickpass (HTTP guest access control)
113
- - Passwordless guest access: invite guests into a **security group** and run `asyx tunnel --http --port <n> --secgroup <slug>`.
114
- - Relay-enforced: guests must present a valid Quickpass cookie; unauthorized requests are rejected at the relay (no app changes).
115
- - Perfect for sharing dashboards/dev tools without opening them publicly; no VPN, no basic auth.
116
- - Zero extra infra: no DNS edits, no reverse proxies; the relay does the policy check.
117
- - Coming extensions: the same flow will back future sharing for TCP/UDP when per-guest auth is added.
118
- - TCP/UDP today remain owner-only via JWT (no per-guest auth in v4.1).
169
+ ## What's new in 0.5.x
170
+
171
+ **Reconnect after a DNS blip (0.5.5)** — if the network drops before the MQTT TLS handshake, the CLI stays up and uses the reconnect it already scheduled.
172
+
173
+ **Tunnel-only CLI (0.5.0)** — npm ships tunnel commands only: `setup`, `mqtt`, and `tunnel`. Focused on secure localhost exposure (HTTP, TCP, UDP). Docs at https://www.asyx.ai/docs
174
+
175
+ **Reliable global install (0.5.2)** — `asyx setup` uses Node's built-in Web Crypto. `npm install -g asyx` works on Node 18+ without module-resolution errors.
176
+
177
+ **Earlier (0.4.0)** — HTTP tunnels auto-switch to streaming transport for large responses (8 MiB+), so big downloads do not hit memory limits.
119
178
 
120
179
  ---
121
180
 
122
- ## 5. Logging
123
- Set verbosity with `ASYX_LOG_LEVEL` (`error|warn|info|debug`, default `info`):
124
- ```bash
125
- ASYX_LOG_LEVEL=debug asyx tunnel --tcp --port 25565
126
- ```
127
- Structured logs go to stdout/stderr; user banners remain.
181
+ ## Documentation
182
+
183
+ | Guide | Link |
184
+ | --- | --- |
185
+ | Getting started | https://www.asyx.ai/docs/getting-started |
186
+ | Publish in 60 seconds | https://www.asyx.ai/docs/publish-local-project |
187
+ | AI coding agents | https://www.asyx.ai/docs/ai-agents |
188
+ | Cursor + Asyx | https://www.asyx.ai/docs/cursor-asyx |
189
+ | Agent checklist | https://www.asyx.ai/docs/ai-agent-checklist |
190
+ | Expose localhost | https://www.asyx.ai/docs/expose-localhost |
191
+ | Quickpass (guest access) | https://www.asyx.ai/docs/quickpass |
192
+ | vs ngrok & Cloudflare | https://www.asyx.ai/docs/vs-ngrok-cloudflare |
128
193
 
129
194
  ---
130
195
 
131
- ## 6. Behavior notes
132
- - Short-lived JWTs with in-band refresh; tunnels stay up without reconnecting.
133
- - MQTT/JWT control plane is shared across HTTP/TCP/UDP.
134
- - CLI never binds your app port (TCP/UDP); it forwards to it.
135
- - Loopback-only enforcement at both CLI and relay.
136
- - Idle/heartbeat handled automatically; no tuning needed.
196
+ ## Agent workflow safety
197
+
198
+ - **Never** paste device certificates or private keys into chat or git.
199
+ - **Do not** tunnel database admin ports without authentication.
200
+ - **Stop** the tunnel when the demo ends (`Ctrl+C`).
201
+ - Treat the public URL as a temporary preview—not a production deploy.
202
+ - Agents **cannot** enroll a device (`asyx setup` requires browser verification) or open tunnels from a machine that has not been set up.
137
203
 
138
204
  ---
139
205
 
140
- ## 7. Why Asyx
141
- - **Device-bound identity**: Each `setup` issues a unique cert + uuLID per host; backend rejects duplicates to prevent credential reuse.
142
- - **Hardware attestation without PII**: Fingerprint is hashed locally from safe fields; raw hardware data never leaves the device.
143
- - **Resilient control plane**: In-band JWT refresh, bounded reconnects, and structured logs (`ASYX_LOG_LEVEL`, `ASYX_DEBUG`) keep long sessions stable.
144
- - **Zero manual relay config**: Assignments route traffic for you—no DNS edits, firewall poking, or relay setup.
145
- - **Multi-protocol, one system**: HTTP, TCP, and UDP share the same assignment/JWT/MQTT fabric; pick the protocol that fits your service.
146
- - **Secure proxy architecture**: Forward-only; avoids local port conflicts and isolates your app from the CLI process.
147
- - **Observability-first UX**: Clear errors, deterministic exits, optional debug traces.
148
- - **Future-ready auth**: Today’s magic-link flow extends to sharing via Asyx Quickpass (passwordless downstream approvals).
206
+ ## Logging
207
+
208
+ ```bash
209
+ ASYX_LOG_LEVEL=debug asyx tunnel --http --port 3000
210
+ ```
211
+
212
+ Levels: `error` | `warn` | `info` | `debug` (default `info`).
149
213
 
150
214
  ---
151
215
 
152
- ## 7. Troubleshooting (quick)
153
- - **External port rejected**: ensure `--external-port` is inside your 10-port block.
154
- - **Relay unavailable**: check network/WSS reachability; see logs for `...RELAY_UNAVAILABLE`.
155
- - **No traffic to app**: confirm your service is listening on `127.0.0.1:<port>` and the tunnel is active; for UDP ensure the WS is still connected.
156
- - **Windows MQTT handshake issues**: rerun `asyx setup` to regenerate keys (PKCS#1).
216
+ ## Troubleshooting
217
+
218
+ | Issue | Fix |
219
+ | --- | --- |
220
+ | `asyx: command not found` | `npm install -g asyx` or `npx asyx@latest` |
221
+ | Setup browser did not open | Run `asyx setup` again; open the printed URL manually |
222
+ | Tunnel URL 502 / unreachable | Dev server not running on the same port |
223
+ | Link dies overnight | Expected—tunnel stops when CLI exits or machine sleeps |
224
+ | External port rejected | `--external-port` must be inside your assigned 10-port block |
225
+ | Windows MQTT handshake issues | Re-run `asyx setup` to regenerate keys (PKCS#1) |
157
226
 
158
227
  ---
159
228
 
160
- ## 8. Security (brief)
229
+ ## Security
230
+
161
231
  - Device-bound identity per host; hardware fingerprint hashed locally.
162
232
  - Mutual TLS to control plane; RS256 JWTs validated via JWKS.
163
- - Forward-only proxy: your app remains isolated; no direct inbound to your host.
164
- - Report issues: [security@asyx.ai](mailto:security@asyx.ai) (no public issues for security).
233
+ - Forward-only proxy—your app stays isolated; no direct inbound to your host.
234
+ - Report issues: [security@asyx.ai](mailto:security@asyx.ai)
165
235
 
166
236
  ---
167
237
 
168
- ## 9. License
238
+ ## License
239
+
169
240
  [Apache-2.0](./LICENSE)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asyx",
3
- "version": "0.5.2",
3
+ "version": "0.5.5",
4
4
  "description": "Asyx tunnel CLI — secure localhost exposure (HTTP, TCP, UDP)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -62,6 +62,7 @@ export class MqttControlPlaneClient {
62
62
 
63
63
  // State tracking
64
64
  this.client = null;
65
+ this.forceClosing = null;
65
66
  this.shuttingDown = false;
66
67
  this.mqttOnline = false;
67
68
  this.hardErrorCount = 0;
@@ -427,6 +428,11 @@ export class MqttControlPlaneClient {
427
428
  };
428
429
 
429
430
  const onError = (err) => {
431
+ // A pre-TLS failure can be emitted twice. The first emit force-closes
432
+ // this client; ignore that client afterwards so the second emit cannot
433
+ // throw or schedule another reconnect.
434
+ if (this.forceClosing === client || this.client !== client) return;
435
+
430
436
  lastError = err; // Store error for diagnostics
431
437
 
432
438
  // Try to extract more details from the client's internal state
@@ -812,13 +818,17 @@ export class MqttControlPlaneClient {
812
818
  */
813
819
  forceCloseClient() {
814
820
  if (!this.client) return;
821
+ const client = this.client;
822
+ this.forceClosing = client;
815
823
  try {
816
- this.client.end(true);
824
+ client.removeAllListeners();
825
+ client.on('error', () => {});
826
+ client.end(true);
817
827
  } catch {
818
828
  // ignore
819
829
  }
820
- this.client.removeAllListeners();
821
830
  this.client = null;
831
+ this.forceClosing = null;
822
832
  }
823
833
 
824
834
  /**