asyx 0.10.1 → 0.11.1

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 (93) hide show
  1. package/AGENTS.md +42 -0
  2. package/bin/asyx.js +1 -1
  3. package/package.json +8 -2
  4. package/src/commands/account.js +80 -71
  5. package/src/commands/app.js +317 -151
  6. package/src/commands/in-use-messages.js +47 -48
  7. package/src/commands/mqtt-broker.js +36 -49
  8. package/src/commands/mqtt.js +111 -149
  9. package/src/commands/name.js +24 -22
  10. package/src/commands/reject-messages.js +123 -123
  11. package/src/commands/setup.js +107 -131
  12. package/src/commands/sts.js +45 -61
  13. package/src/commands/tunnel.js +853 -932
  14. package/src/commands/validate-target-host.js +36 -59
  15. package/src/lib/aws-iot-config.js +26 -24
  16. package/src/lib/certs.js +15 -18
  17. package/src/lib/csr.js +107 -182
  18. package/src/lib/device.js +26 -37
  19. package/src/lib/ids.js +1 -2
  20. package/src/lib/naming.js +74 -68
  21. package/src/lib/pairing.js +10 -11
  22. package/src/lib/shared-transport.js +5 -9
  23. package/src/main.js +63 -53
  24. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.js +25 -287
  25. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.js +0 -72
  26. package/vendor/tunnel-core/dist/control-plane/session.js +0 -20
  27. package/vendor/tunnel-core/dist/errors.js +0 -19
  28. package/vendor/tunnel-core/dist/flows/account.js +1 -6
  29. package/vendor/tunnel-core/dist/flows/goodbye.js +0 -4
  30. package/vendor/tunnel-core/dist/flows/http.js +24 -112
  31. package/vendor/tunnel-core/dist/flows/identity.js +17 -10
  32. package/vendor/tunnel-core/dist/flows/in-use.js +0 -6
  33. package/vendor/tunnel-core/dist/flows/reopen.js +0 -4
  34. package/vendor/tunnel-core/dist/flows/tcp.js +18 -84
  35. package/vendor/tunnel-core/dist/flows/udp.js +15 -52
  36. package/vendor/tunnel-core/dist/lib/fingerprint.js +38 -42
  37. package/vendor/tunnel-core/dist/lib/jwt-verifier.js +22 -74
  38. package/vendor/tunnel-core/dist/lib/logger.js +1 -9
  39. package/vendor/tunnel-core/dist/lib/refresh-helpers.js +1 -22
  40. package/vendor/tunnel-core/dist/lifecycle.js +1 -8
  41. package/vendor/tunnel-core/dist/mqtt/awaiter-map.js +1 -53
  42. package/vendor/tunnel-core/dist/mqtt/events/handlers.js +10 -64
  43. package/vendor/tunnel-core/dist/mqtt/events/index.js +3 -36
  44. package/vendor/tunnel-core/dist/mqtt/events/schemas.js +0 -1
  45. package/vendor/tunnel-core/dist/mqtt/ingress.js +0 -60
  46. package/vendor/tunnel-core/dist/state/assignment.js +6 -122
  47. package/vendor/tunnel-core/dist/state/instance-registry.js +0 -63
  48. package/vendor/tunnel-core/dist/tcp-v1/framing.js +2 -64
  49. package/vendor/tunnel-core/dist/tunnel/http-tunnel.js +64 -331
  50. package/vendor/tunnel-core/dist/tunnel/httpws-constants.js +5 -14
  51. package/vendor/tunnel-core/dist/tunnel/reconnect.js +10 -50
  52. package/vendor/tunnel-core/dist/tunnel/request-sink.js +0 -16
  53. package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.js +32 -195
  54. package/vendor/tunnel-core/dist/tunnel/udp-tunnel.js +28 -153
  55. package/vendor/tunnel-core/dist/tunnel/ws-control.js +4 -39
  56. package/vendor/tunnel-core/dist/types.js +0 -2
  57. package/vendor/tunnel-core/dist/udp-v1/framing.js +2 -64
  58. package/vendor/tunnel-core/package.json +0 -25
  59. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneClient.d.ts +0 -273
  60. package/vendor/tunnel-core/dist/control-plane/MqttControlPlaneTransport.d.ts +0 -79
  61. package/vendor/tunnel-core/dist/control-plane/session.d.ts +0 -55
  62. package/vendor/tunnel-core/dist/errors.d.ts +0 -49
  63. package/vendor/tunnel-core/dist/flows/account.d.ts +0 -24
  64. package/vendor/tunnel-core/dist/flows/goodbye.d.ts +0 -10
  65. package/vendor/tunnel-core/dist/flows/http.d.ts +0 -61
  66. package/vendor/tunnel-core/dist/flows/identity.d.ts +0 -23
  67. package/vendor/tunnel-core/dist/flows/in-use.d.ts +0 -27
  68. package/vendor/tunnel-core/dist/flows/reopen.d.ts +0 -9
  69. package/vendor/tunnel-core/dist/flows/tcp.d.ts +0 -85
  70. package/vendor/tunnel-core/dist/flows/udp.d.ts +0 -52
  71. package/vendor/tunnel-core/dist/lib/adapt-logger.d.ts +0 -2
  72. package/vendor/tunnel-core/dist/lib/fingerprint.d.ts +0 -145
  73. package/vendor/tunnel-core/dist/lib/jwt-verifier.d.ts +0 -27
  74. package/vendor/tunnel-core/dist/lib/logger.d.ts +0 -9
  75. package/vendor/tunnel-core/dist/lib/refresh-helpers.d.ts +0 -16
  76. package/vendor/tunnel-core/dist/lifecycle.d.ts +0 -24
  77. package/vendor/tunnel-core/dist/mqtt/awaiter-map.d.ts +0 -56
  78. package/vendor/tunnel-core/dist/mqtt/events/handlers.d.ts +0 -60
  79. package/vendor/tunnel-core/dist/mqtt/events/index.d.ts +0 -1
  80. package/vendor/tunnel-core/dist/mqtt/events/schemas.d.ts +0 -498
  81. package/vendor/tunnel-core/dist/mqtt/ingress.d.ts +0 -63
  82. package/vendor/tunnel-core/dist/state/assignment.d.ts +0 -136
  83. package/vendor/tunnel-core/dist/state/instance-registry.d.ts +0 -88
  84. package/vendor/tunnel-core/dist/tcp-v1/framing.d.ts +0 -43
  85. package/vendor/tunnel-core/dist/tunnel/http-tunnel.d.ts +0 -140
  86. package/vendor/tunnel-core/dist/tunnel/httpws-constants.d.ts +0 -13
  87. package/vendor/tunnel-core/dist/tunnel/reconnect.d.ts +0 -76
  88. package/vendor/tunnel-core/dist/tunnel/request-sink.d.ts +0 -40
  89. package/vendor/tunnel-core/dist/tunnel/tcp-tunnel.d.ts +0 -92
  90. package/vendor/tunnel-core/dist/tunnel/udp-tunnel.d.ts +0 -93
  91. package/vendor/tunnel-core/dist/tunnel/ws-control.d.ts +0 -22
  92. package/vendor/tunnel-core/dist/types.d.ts +0 -24
  93. package/vendor/tunnel-core/dist/udp-v1/framing.d.ts +0 -41
package/src/lib/naming.js CHANGED
@@ -1,89 +1,95 @@
1
- // Story 2.1 r3: hostname choice for `asyx setup` and `asyx name check`.
2
- // The server decides (GET /www/names/check, POST /www/sts/authorize); these checks only give an early,
3
- // clear answer in the terminal. The terminal never prompts (4.7 c5).
4
1
  import os from 'node:os';
5
2
  import { createHash } from 'node:crypto';
6
-
7
3
  export const ZONE = 'tunnel.asyx.ai';
8
- export const LABEL_RE = /^[a-z0-9](?:[a-z0-9-]{1,28}[a-z0-9])$/; // same rule as the server (4.3 c3)
4
+ export const LABEL_RE = /^[a-z0-9](?:[a-z0-9-]{1,28}[a-z0-9])$/;
9
5
  export const NAMES_URL = process.env.ASYX_NAMES_URL || 'https://www.asyx.ai/www/names/check';
10
-
11
- // Exit codes (documented in webui/content/docs/ai-agent-checklist.mdx)
12
6
  export const EXIT = { OK: 0, FAILED: 1, USAGE: 2, NAME_UNAVAILABLE: 3 };
13
-
14
- /** "Orders-API.tunnel.asyx.ai" -> "orders-api"; returns the label or null when it is not valid. */
15
7
  export function normalizeLabel(input) {
16
- let l = String(input || '').trim().toLowerCase();
17
- if (l.endsWith(`.${ZONE}`)) l = l.slice(0, -(ZONE.length + 1));
18
- return LABEL_RE.test(l) ? l : null;
8
+ let l = String(input || '').trim().toLowerCase();
9
+ if (l.endsWith(`.${ZONE}`))
10
+ l = l.slice(0, -(ZONE.length + 1));
11
+ return LABEL_RE.test(l) ? l : null;
19
12
  }
20
-
21
- /** Parses `asyx setup` options. Returns { hostname, random, json } or { error }. */
22
13
  export function parseSetupArgs(argv) {
23
- const out = { hostname: null, random: false, json: false, address: null };
24
- for (let i = 0; i < argv.length; i++) {
25
- const a = argv[i];
26
- if (a === 'setup') continue;
27
- if (a === '--json') out.json = true;
28
- else if (a === '--random') out.random = true;
29
- else if (a === '--hostname' || a.startsWith('--hostname=')) {
30
- const v = a.includes('=') ? a.slice(a.indexOf('=') + 1) : argv[++i];
31
- if (!v) return { error: '--hostname needs a name, for example --hostname orders-api' };
32
- const label = normalizeLabel(v);
33
- if (!label) return { error: `"${v}" is not a valid name: use 3-30 characters a-z, 0-9 and hyphens, starting and ending with a letter or digit` };
34
- out.hostname = label;
35
- } else if (a === '--address' || a.startsWith('--address=')) {
36
- // Story 2.11 c5/c8: one of the account's addresses as this device's default (new or already set up)
37
- const v = a.includes('=') ? a.slice(a.indexOf('=') + 1) : argv[++i];
38
- if (!v) return { error: '--address needs one of your addresses, for example --address orders-api' };
39
- const label = normalizeLabel(v);
40
- if (!label) return { error: `"${v}" is not a valid address name` };
41
- out.address = label;
42
- } else return { error: `unknown option ${a}` };
43
- }
44
- if ([out.hostname, out.random, out.address].filter(Boolean).length > 1) return { error: 'use one of --hostname, --random or --address' };
45
- return out;
14
+ const out = { hostname: null, random: false, json: false, address: null };
15
+ for (let i = 0; i < argv.length; i++) {
16
+ const a = argv[i];
17
+ if (a === 'setup')
18
+ continue;
19
+ if (a === '--json')
20
+ out.json = true;
21
+ else if (a === '--random')
22
+ out.random = true;
23
+ else if (a === '--hostname' || a.startsWith('--hostname=')) {
24
+ const v = a.includes('=') ? a.slice(a.indexOf('=') + 1) : argv[++i];
25
+ if (!v)
26
+ return { error: '--hostname needs a name, for example --hostname orders-api' };
27
+ const label = normalizeLabel(v);
28
+ if (!label)
29
+ return { error: `"${v}" is not a valid name: use 3-30 characters a-z, 0-9 and hyphens, starting and ending with a letter or digit` };
30
+ out.hostname = label;
31
+ }
32
+ else if (a === '--address' || a.startsWith('--address=')) {
33
+ const v = a.includes('=') ? a.slice(a.indexOf('=') + 1) : argv[++i];
34
+ if (!v)
35
+ return { error: '--address needs one of your addresses, for example --address orders-api' };
36
+ const label = normalizeLabel(v);
37
+ if (!label)
38
+ return { error: `"${v}" is not a valid address name` };
39
+ out.address = label;
40
+ }
41
+ else
42
+ return { error: `unknown option ${a}` };
43
+ }
44
+ if ([out.hostname, out.random, out.address].filter(Boolean).length > 1)
45
+ return { error: 'use one of --hostname, --random or --address' };
46
+ return out;
46
47
  }
47
-
48
- /** The approval link. v=2 tells the page this CLI supports device naming (2.1 r3). */
49
48
  export function approvalUrl(base, { clientId, ticket, hostname, random, address, machine = os.hostname() }) {
50
- const q = new URLSearchParams({ clientId, ticket, v: '2' });
51
- if (machine) q.set('machine', String(machine).slice(0, 64));
52
- if (hostname) q.set('hostname', hostname);
53
- if (random) q.set('random', '1');
54
- if (address) q.set('address', address); // Story 2.11 c5/c8
55
- return `${base}?${q.toString()}`;
49
+ const q = new URLSearchParams({ clientId, ticket, v: '2' });
50
+ if (machine)
51
+ q.set('machine', String(machine).slice(0, 64));
52
+ if (hostname)
53
+ q.set('hostname', hostname);
54
+ if (random)
55
+ q.set('random', '1');
56
+ if (address)
57
+ q.set('address', address);
58
+ return `${base}?${q.toString()}`;
56
59
  }
57
-
58
- /** Asks the server whether <label>.tunnel.asyx.ai can be claimed. Throws on network/service errors. */
59
60
  export async function checkName(label, { fetchImpl = fetch, url = NAMES_URL } = {}) {
60
- const res = await fetchImpl(`${url}?label=${encodeURIComponent(label)}`, { headers: { accept: 'application/json' } });
61
- if (res.status === 429) { const e = new Error('too many name checks, try again in a minute'); e.code = 'rate_limited'; throw e; }
62
- if (!res.ok) { const e = new Error(`name check failed (HTTP ${res.status})`); e.code = 'service_error'; throw e; }
63
- return res.json();
61
+ const res = await fetchImpl(`${url}?label=${encodeURIComponent(label)}`, { headers: { accept: 'application/json' } });
62
+ if (res.status === 429) {
63
+ const e = new Error('too many name checks, try again in a minute');
64
+ e.code = 'rate_limited';
65
+ throw e;
66
+ }
67
+ if (!res.ok) {
68
+ const e = new Error(`name check failed (HTTP ${res.status})`);
69
+ e.code = 'service_error';
70
+ throw e;
71
+ }
72
+ return res.json();
64
73
  }
65
-
66
74
  const REASONS = {
67
- hostname_taken: 'is taken',
68
- hostname_reserved: 'is reserved',
69
- hostname_cooling_down: 'was released recently and is not available yet',
70
- hostname_invalid: 'is not a valid name',
75
+ hostname_taken: 'is taken',
76
+ hostname_reserved: 'is reserved',
77
+ hostname_cooling_down: 'was released recently and is not available yet',
78
+ hostname_invalid: 'is not a valid name',
71
79
  };
72
80
  export function describeAnswer(a) {
73
- if (a.status === 'available') return `${a.hostname} is available`;
74
- const name = a.hostname || a.label;
75
- const s = a.suggestions?.length ? ` Try: ${a.suggestions.join(', ')}` : '';
76
- return `${name} ${REASONS[a.status] || 'is not available'}.${s}`;
81
+ if (a.status === 'available')
82
+ return `${a.hostname} is available`;
83
+ const name = a.hostname || a.label;
84
+ const s = a.suggestions?.length ? ` Try: ${a.suggestions.join(', ')}` : '';
85
+ return `${name} ${REASONS[a.status] || 'is not available'}.${s}`;
77
86
  }
78
-
79
- /** Defect 11.25 / Story 4.7 c6: the short code the terminal shows and the approval page asks for.
80
- * Derived from the setup ticket, so the CLI and the server agree without storing anything; it is never
81
- * put in the approval link. Alphabet without look-alikes (no I, L, O, U, 0, 1). */
82
87
  export const SETUP_CODE_ALPHABET = "ABCDEFGHJKMNPQRSTVWXYZ23456789";
83
88
  export function setupCode(ticket) {
84
- const h = createHash("sha256").update(`asyx-setup-code|${ticket}`).digest();
85
- let s = "";
86
- for (let i = 0; i < 6; i++) s += SETUP_CODE_ALPHABET[h[i] % SETUP_CODE_ALPHABET.length];
87
- return `${s.slice(0, 3)}-${s.slice(3)}`;
89
+ const h = createHash("sha256").update(`asyx-setup-code|${ticket}`).digest();
90
+ let s = "";
91
+ for (let i = 0; i < 6; i++)
92
+ s += SETUP_CODE_ALPHABET[h[i] % SETUP_CODE_ALPHABET.length];
93
+ return `${s.slice(0, 3)}-${s.slice(3)}`;
88
94
  }
89
95
  export const normalizeCode = (c) => String(c || "").toUpperCase().replace(/[^A-Z0-9]/g, "");
@@ -1,15 +1,14 @@
1
1
  import open from "open";
2
2
  import chalk from "chalk";
3
-
4
3
  export async function startPairing(deviceCode) {
5
- const claimUrl = `https://www.asyx.ai/console/tunnel?code=${encodeURIComponent(deviceCode)}`;
6
- console.log(chalk.gray(`Preparing browser for pairing...`));
7
-
8
- try {
9
- await open(claimUrl);
10
- console.log(chalk.green("✅ Opening your default browser to complete pairing..."));
11
- } catch (err) {
12
- console.log(chalk.yellow("⚠️ Could not open your browser automatically."));
13
- console.log(`Please visit:\n${chalk.cyan(claimUrl)}`);
14
- }
4
+ const claimUrl = `https://www.asyx.ai/console/tunnel?code=${encodeURIComponent(deviceCode)}`;
5
+ console.log(chalk.gray(`Preparing browser for pairing...`));
6
+ try {
7
+ await open(claimUrl);
8
+ console.log(chalk.green("✅ Opening your default browser to complete pairing..."));
9
+ }
10
+ catch (err) {
11
+ console.log(chalk.yellow("⚠️ Could not open your browser automatically."));
12
+ console.log(`Please visit:\n${chalk.cyan(claimUrl)}`);
13
+ }
15
14
  }
@@ -1,15 +1,11 @@
1
1
  import { MemoryTransport } from "@asyx/mqtt-client";
2
-
3
- // Simple singleton pattern for shared transport in dev mode
4
2
  let sharedTransport = null;
5
-
6
3
  export function getSharedTransport() {
7
- if (!sharedTransport) {
8
- sharedTransport = new MemoryTransport();
9
- }
10
- return sharedTransport;
4
+ if (!sharedTransport) {
5
+ sharedTransport = new MemoryTransport();
6
+ }
7
+ return sharedTransport;
11
8
  }
12
-
13
9
  export function resetSharedTransport() {
14
- sharedTransport = null;
10
+ sharedTransport = null;
15
11
  }
package/src/main.js CHANGED
@@ -2,30 +2,24 @@
2
2
  import { createRequire } from 'node:module';
3
3
  import cmdSetup from "./commands/setup.js";
4
4
  import cmdSts from "./commands/sts.js";
5
-
6
5
  const require = createRequire(import.meta.url);
7
6
  const pkg = require("../package.json");
8
-
9
7
  export const CLI_VERSION = pkg.version;
10
- // Story 2.1 c7: tunnel-core adds this to every cmd/open.
11
- if (!process.env.ASYX_CLIENT_VERSION) process.env.ASYX_CLIENT_VERSION = `asyx-cli@${CLI_VERSION}`;
8
+ if (!process.env.ASYX_CLIENT_VERSION)
9
+ process.env.ASYX_CLIENT_VERSION = `asyx-cli@${CLI_VERSION}`;
12
10
  export const CLI_DESCRIPTION = pkg.description;
13
-
14
- // Unified error handling
15
11
  process.on('unhandledRejection', (err) => {
16
- console.error('Unexpected error:', err?.message ?? err);
17
- process.exit(1);
12
+ console.error('Unexpected error:', err?.message ?? err);
13
+ process.exit(1);
18
14
  });
19
-
20
15
  const handleFailure = (label) => (err) => {
21
- console.error(`${label} failed:`, err?.message ?? err);
22
- process.exit(1);
16
+ console.error(`${label} failed:`, err?.message ?? err);
17
+ process.exit(1);
23
18
  };
24
-
25
19
  async function run() {
26
- const cmd = process.argv[2];
27
- if (!cmd || cmd === "help" || cmd === "--help" || cmd === "-h") {
28
- console.log(`asyx ${CLI_VERSION}
20
+ const cmd = process.argv[2];
21
+ if (!cmd || cmd === "help" || cmd === "--help" || cmd === "-h") {
22
+ console.log(`asyx ${CLI_VERSION}
29
23
 
30
24
  Usage: asyx <command>
31
25
 
@@ -52,48 +46,64 @@ Usage: asyx <command>
52
46
  asyx tunnel --udp --port 27015 --to orders-api.tunnel.asyx.ai
53
47
  asyx app create orders-api (--hostname <label>, --random or --address <existing>)
54
48
  asyx tunnel --http --port 3000 --app orders-api
49
+ asyx app list (each app's state: active, revoked or deleted)
50
+ asyx app forget orders-api (remove this computer's copy of its credentials)
55
51
 
56
52
  Options for each tunnel type: asyx tunnel --help
57
53
  Documentation: https://www.asyx.ai/docs
58
54
  `);
59
- process.exit(0);
60
- }
61
- if (cmd === "--version" || cmd === "-v") {
62
- console.log(`asyx ${CLI_VERSION}`);
63
- process.exit(0);
64
- }
65
- if (cmd === "setup") {
66
- cmdSetup(process.argv.slice(2)).catch(handleFailure('Setup'));
67
- } else if (cmd === "name") {
68
- const { default: cmdName } = await import("./commands/name.js");
69
- cmdName(process.argv.slice(3)).then((code) => process.exit(code), handleFailure('Name'));
70
- } else if (cmd === "port") {
71
- const { cmdPort } = await import("./commands/account.js"); // Story 2.11 c3
72
- cmdPort(process.argv.slice(3)).then((code) => process.exit(code), handleFailure('Port release'));
73
- } else if (cmd === "sts") {
74
- cmdSts(process.argv.slice(2)).catch(handleFailure('STS'));
75
- } else if (cmd === "mqtt") {
76
- const { default: mqttCommand } = await import("./commands/mqtt.js");
77
- mqttCommand().catch(handleFailure('MQTT'));
78
- } else if (cmd === "app") {
79
- const { default: cmdApp } = await import("./commands/app.js"); // Story 12.2
80
- cmdApp(process.argv.slice(3)).then((code) => process.exit(code), handleFailure('App'));
81
- } else if (cmd === "tunnel") {
82
- let args = process.argv.slice(3);
83
- const at = args.indexOf("--app"); // Story 12.2: run the tunnel as one of this machine's apps
84
- if (at !== -1) {
85
- const { appIdForTunnel } = await import("./commands/app.js");
86
- const appId = appIdForTunnel(args[at + 1]);
87
- if (!appId) { console.error(`No app named ${args[at + 1] || ''} on this machine. asyx app list shows the apps kept here.`); process.exit(2); }
88
- process.env.ASYX_CLIENT_ID = appId;
89
- args = [...args.slice(0, at), ...args.slice(at + 2)];
55
+ process.exit(0);
56
+ }
57
+ if (cmd === "--version" || cmd === "-v") {
58
+ console.log(`asyx ${CLI_VERSION}`);
59
+ process.exit(0);
60
+ }
61
+ if (cmd === "setup") {
62
+ cmdSetup(process.argv.slice(2)).catch(handleFailure('Setup'));
63
+ }
64
+ else if (cmd === "name") {
65
+ const { default: cmdName } = await import("./commands/name.js");
66
+ cmdName(process.argv.slice(3)).then((code) => process.exit(code), handleFailure('Name'));
67
+ }
68
+ else if (cmd === "port") {
69
+ const { cmdPort } = await import("./commands/account.js");
70
+ cmdPort(process.argv.slice(3)).then((code) => process.exit(code), handleFailure('Port release'));
71
+ }
72
+ else if (cmd === "sts") {
73
+ cmdSts(process.argv.slice(2)).catch(handleFailure('STS'));
74
+ }
75
+ else if (cmd === "mqtt") {
76
+ const { default: mqttCommand } = await import("./commands/mqtt.js");
77
+ mqttCommand().catch(handleFailure('MQTT'));
78
+ }
79
+ else if (cmd === "app") {
80
+ const { default: cmdApp } = await import("./commands/app.js");
81
+ cmdApp(process.argv.slice(3)).then((code) => process.exit(code), handleFailure('App'));
82
+ }
83
+ else if (cmd === "tunnel") {
84
+ let args = process.argv.slice(3);
85
+ const at = args.indexOf("--app");
86
+ if (at !== -1) {
87
+ const { appIdForTunnel, appRefusalForTunnel, reconcileApps } = await import("./commands/app.js");
88
+ const name = args[at + 1];
89
+ const rec = appIdForTunnel(name) ? null : await reconcileApps({ out: console.error });
90
+ const appId = appIdForTunnel(name);
91
+ if (!appId) {
92
+ const gone = rec?.removed?.includes(String(name || '').trim().toLowerCase());
93
+ if (!gone)
94
+ console.error(appRefusalForTunnel(name));
95
+ process.exit(gone || /revoked/.test(appRefusalForTunnel(name) || '') ? 1 : 2);
96
+ }
97
+ process.env.ASYX_CLIENT_ID = appId;
98
+ process.env.ASYX_APP_ID = appId;
99
+ args = [...args.slice(0, at), ...args.slice(at + 2)];
100
+ }
101
+ const { default: tunnelCommand } = await import("./commands/tunnel.js");
102
+ tunnelCommand(args).catch(handleFailure('Tunnel'));
103
+ }
104
+ else {
105
+ console.log(`Unknown command: ${cmd}\nRun "asyx help" for the list of commands.`);
106
+ process.exit(1);
90
107
  }
91
- const { default: tunnelCommand } = await import("./commands/tunnel.js");
92
- tunnelCommand(args).catch(handleFailure('Tunnel'));
93
- } else {
94
- console.log(`Unknown command: ${cmd}\nRun "asyx help" for the list of commands.`);
95
- process.exit(1);
96
- }
97
108
  }
98
-
99
109
  run();