hopwire 0.1.9 → 0.2.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 (35) hide show
  1. package/dist/account.js +180 -35
  2. package/dist/agent/redact.js +55 -8
  3. package/dist/cli.js +172 -58
  4. package/dist/commands/doctor.js +53 -12
  5. package/dist/commands/http.js +19 -4
  6. package/dist/commands/init.js +38 -9
  7. package/dist/commands/login.js +47 -8
  8. package/dist/commands/up.js +16 -3
  9. package/dist/commands/watch.js +33 -4
  10. package/dist/config-template.js +11 -1
  11. package/dist/config.js +65 -6
  12. package/dist/control-plane-client.js +42 -0
  13. package/dist/inspector/assets/index-CIOfyIbK.js +5 -0
  14. package/dist/inspector/assets/index-Du4-DCNN.css +2 -0
  15. package/dist/inspector/index.html +2 -2
  16. package/dist/inspector-api.js +145 -0
  17. package/dist/interceptor.js +19 -4
  18. package/dist/log-follow.js +473 -0
  19. package/dist/log.js +178 -11
  20. package/dist/mcp/logs.js +46 -0
  21. package/dist/mcp/tools.js +136 -3
  22. package/dist/output.js +38 -0
  23. package/dist/relay.js +1 -1
  24. package/dist/serve.js +49 -2
  25. package/node_modules/@hopwire/protocol/dist/constants.d.ts +10 -0
  26. package/node_modules/@hopwire/protocol/dist/constants.js +10 -0
  27. package/node_modules/@hopwire/protocol/dist/index.d.ts +1 -0
  28. package/node_modules/@hopwire/protocol/dist/index.js +1 -0
  29. package/node_modules/@hopwire/protocol/dist/inspector.d.ts +18 -0
  30. package/node_modules/@hopwire/protocol/dist/log-entries.d.ts +72 -0
  31. package/node_modules/@hopwire/protocol/dist/log-entries.js +147 -0
  32. package/node_modules/@hopwire/protocol/dist/ws-messages.d.ts +2 -1
  33. package/package.json +1 -1
  34. package/dist/inspector/assets/index-D3yNjmSA.js +0 -2
  35. package/dist/inspector/assets/index-XotF7D1X.css +0 -2
package/dist/cli.js CHANGED
@@ -4,12 +4,12 @@ import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import { parseArgs } from 'node:util';
6
6
  import { INSPECTOR_DEFAULT_PORT, LOCAL_ENTRY_DEFAULT_PORT, RANDOM_SUBDOMAIN_BYTES, HOPWIRE_YAML_FILE, isPublicKeyHex, isReservableSubdomain, randomSubdomain, } from '@hopwire/protocol';
7
- import { bindEdge, boundEdge, readAccount } from './account.js';
7
+ import { bindEdge, boundEdge, isProfileName, readAccount } from './account.js';
8
8
  import { startConnect } from './commands/connect.js';
9
9
  import { doctor } from './commands/doctor.js';
10
10
  import { init } from './commands/init.js';
11
11
  import { startHttpTunnel } from './commands/http.js';
12
- import { login, logout } from './commands/login.js';
12
+ import { login, logout, profiles, use } from './commands/login.js';
13
13
  import { startMcp } from './commands/mcp.js';
14
14
  import { rotate } from './commands/rotate.js';
15
15
  import { startUp } from './commands/up.js';
@@ -17,6 +17,7 @@ import { startWatch } from './commands/watch.js';
17
17
  import { ConfigError, isServiceName, loadConfig } from './config.js';
18
18
  import { HopwireError, TemporaryError, UsageError, errorCode } from './errors.js';
19
19
  import { loadOrCreateIdentity } from './identity.js';
20
+ import { defaultLogName, isFollowablePath } from './log-follow.js';
20
21
  import { DOCS_URL, printable } from './output.js';
21
22
  import { createUpdateNotice } from './update-notice.js';
22
23
  import { parseControlPlaneUrl, parseEdgeUrl, parseLocalTarget } from './urls.js';
@@ -25,7 +26,7 @@ const USAGE = `Usage: hopwire <command>
25
26
 
26
27
  Private mode: no account, no servers of ours, end-to-end encrypted between you and the teammates you choose.
27
28
  With --team (Team plan) your account's control plane names who gets in; the traffic stays direct.
28
- With --relay as well, a connection that cannot be made directly goes through our edge, end-to-end encrypted.
29
+ With --relay (turns on --team), a connection that cannot be made directly goes through our edge, end-to-end encrypted.
29
30
  Public mode (--public): a public URL for the service through the edge; it needs an account (hopwire login).
30
31
 
31
32
  Start here:
@@ -52,6 +53,9 @@ Commands:
52
53
  hopwire login Sign in through the browser and store an API token of the control plane on this
53
54
  machine, for public mode (--token pastes a token instead)
54
55
  hopwire logout Remove the stored API token from this machine
56
+ hopwire profiles List the logins on this machine (one profile per organisation) and which one
57
+ is current; nothing is contacted
58
+ hopwire use <profile> Make another profile the current one, for example after hopwire login --profile acme
55
59
  hopwire doctor Print a report about this installation (versions, data directory, account,
56
60
  hopwire.yaml) to read or to paste into a bug report. It is sent nowhere
57
61
  hopwire mcp An MCP server for a coding agent on this machine (stdio): it reads and replays
@@ -70,10 +74,11 @@ Options for http:
70
74
  (Team plan). Needs an account: run hopwire login first. The control plane of the
71
75
  account names the keys of the team and gets the public key of this machine; this is
72
76
  the one thing private mode asks a server. Your traffic still passes none
73
- --relay With --team: teammates whose network allows no direct P2P connection (UDP blocked,
74
- or both sides behind a strict NAT) come in through the relay of your account's edge
75
- on port 443. End-to-end encrypted: the edge passes on bytes it cannot read, and sees
76
- addresses, your organisation, keys and byte counts. Direct P2P is always tried first
77
+ --relay With --share, turns on --team: teammates whose network allows no direct P2P connection
78
+ (UDP blocked, or both sides behind a strict NAT) come in through the relay of your
79
+ account's edge on port 443. End-to-end encrypted: the edge passes on bytes it cannot
80
+ read, and sees addresses, your organisation, keys and byte counts. Direct P2P is
81
+ always tried first
77
82
  --public Serve the service under a public URL through the edge. Needs an account: run
78
83
  hopwire login first; the edge is the one its control plane names. HOPWIRE_EDGE_URL
79
84
  sets another one. A local edge (ws://127.0.0.1:8787) can be used without an account,
@@ -93,6 +98,15 @@ Options for http:
93
98
  model provider; exchanges captured without it stay closed to agents
94
99
  --no-ws-capture Log the handshake of a WebSocket but not its messages (by default both directions
95
100
  are recorded, up to 64 KiB per message and 2 MB or 10,000 messages per WebSocket)
101
+ --log <path> Follow a log file of the service (storage/logs/laravel.log) and show its new entries
102
+ next to the traffic, linked to the requests they were written during. Nothing written
103
+ before the start is read; a * in the file name follows the newest match. Can be given
104
+ several times. The entries stay on this machine unless --share-logs
105
+ --share-logs With --share and --log: teammates who watch the log also see the new entries of the
106
+ --log files (their coding agents only with --allow-agents). Logs often hold secrets and
107
+ other people's data. Neither the edge nor the control plane ever sees them
108
+ --log-request-id With --log: every request forwarded to the service carries X-Hopwire-Exchange-Id; a
109
+ service that writes it into its log gets exact links when requests overlap
96
110
 
97
111
  Options for init:
98
112
  --config <path> The file to write (default ${HOPWIRE_YAML_FILE} in the working directory). An existing file
@@ -113,7 +127,7 @@ Options for up:
113
127
  --config <path> The config file (default ${HOPWIRE_YAML_FILE} in the working directory). A public service
114
128
  takes the URL of the edge from edge.url in the file. With controlPlane.url in the file
115
129
  it uses your account (hopwire login), without it the dev token in HOPWIRE_DEV_TOKEN.
116
- p2p.team in the file is --team of http, p2p.relay is --relay
130
+ p2p.team in the file is --team of http, p2p.relay is --relay (and turns on p2p.team)
117
131
  --no-agent, --agent As for http, for every service; agent: false in the file turns it off too
118
132
  --force As for http: stop the tunnel that holds the data directory first
119
133
 
@@ -127,6 +141,9 @@ Options for login:
127
141
  page, and waits until you sign in there and approve the code; the control plane
128
142
  then creates an API token for this machine. The token is checked with the control
129
143
  plane and stored in config.json of the data directory, readable for this user only
144
+ --profile <name> Store the login in this profile and make it the current one (default: the current
145
+ profile, else "default"). One profile per organisation: hopwire login --profile acme
146
+ with a token of Acme keeps the login of your own organisation next to it
130
147
 
131
148
  Options for mcp:
132
149
  --read-only Leave out the replay tool; the agent can only read the traffic
@@ -142,7 +159,7 @@ Options for connect:
142
159
  service); without it only 127.0.0.1:<port> and localhost:<port>. Can be given several times
143
160
  --team For a teammate who shares with --team: registers the key of this machine with your
144
161
  organisation (hopwire login first) and connects only to a machine of one of its members
145
- --relay With --team: when no direct connection comes about, go through the relay of your
162
+ --relay Turns on --team: when no direct connection comes about, go through the relay of your
146
163
  account's edge (the teammate shares with --relay); end-to-end encrypted
147
164
 
148
165
  Options for watch:
@@ -151,16 +168,20 @@ Options for watch:
151
168
  --inspect <port> Loopback port of the inspector (default ${INSPECTOR_DEFAULT_PORT}, 0 picks a free one)
152
169
  --team For a teammate who shares with --team: registers the key of this machine with your
153
170
  organisation (hopwire login first), so the sharer lets it in
154
- --relay With --team: when no direct connection comes about, go through the relay of your
171
+ --relay Turns on --team: when no direct connection comes about, go through the relay of your
155
172
  account's edge (the teammate shares with --relay); end-to-end encrypted
156
173
  --agent Let a coding agent on this machine read the exchanges your teammate allowed for
157
174
  agents (they share with --allow-agents) through hopwire mcp; never on without it.
158
175
  What the agent reads goes to its model provider
176
+ --log <path> As for http: follow a log file of your own service, so the entries of your replays
177
+ show next to them. They stay on this machine
159
178
  --force As for http: stop the tunnel that holds the data directory first
160
179
 
161
180
  Global options:
162
181
  --data-dir <path> Where identity, traffic log and the API token are stored (default $HOPWIRE_HOME or
163
182
  ~/.hopwire)
183
+ --profile <name> Use the login of this profile for this command only, not the current one (default
184
+ $HOPWIRE_PROFILE); identity, traffic log and inspector are the same for every profile
164
185
  -h, --help Show this help
165
186
  --version Show the version
166
187
  `;
@@ -176,7 +197,7 @@ export const MCP_TERMINAL_HINT = [
176
197
  'Press Ctrl+C to stop.',
177
198
  ].join('\n');
178
199
  /** Options every command takes, and the ones of each command. Anything else is a usage error. */
179
- const GLOBAL_OPTIONS = ['help', 'version', 'data-dir'];
200
+ const GLOBAL_OPTIONS = ['help', 'version', 'data-dir', 'profile'];
180
201
  const COMMAND_OPTIONS = {
181
202
  http: [
182
203
  'listen',
@@ -189,6 +210,9 @@ const COMMAND_OPTIONS = {
189
210
  'relay',
190
211
  'allow-agents',
191
212
  'no-ws-capture',
213
+ 'log',
214
+ 'share-logs',
215
+ 'log-request-id',
192
216
  'public',
193
217
  'subdomain',
194
218
  'agent',
@@ -199,9 +223,11 @@ const COMMAND_OPTIONS = {
199
223
  id: [],
200
224
  rotate: [],
201
225
  connect: ['port', 'service', 'allow-host', 'team', 'relay'],
202
- watch: ['replay-target', 'inspect', 'team', 'relay', 'agent', 'force'],
226
+ watch: ['replay-target', 'inspect', 'team', 'relay', 'agent', 'log', 'force'],
203
227
  login: ['api', 'token', 'no-browser'],
204
228
  logout: [],
229
+ profiles: [],
230
+ use: [],
205
231
  mcp: ['read-only'],
206
232
  doctor: ['network'],
207
233
  };
@@ -239,6 +265,9 @@ export async function run(argv, io) {
239
265
  throw new UsageError('--data-dir needs the path of a directory');
240
266
  }
241
267
  const dataDir = resolveDataDir(values['data-dir'], io.env);
268
+ const profile = resolveProfile(values.profile, io.env);
269
+ // The login a command uses: the profile it names, else the current one of the data directory
270
+ const store = { dataDir, profile };
242
271
  if (command === 'id') {
243
272
  noMoreArguments(rest, 0, 'hopwire id');
244
273
  io.print((await loadOrCreateIdentity(dataDir)).publicKey.toString('hex'));
@@ -253,6 +282,7 @@ export async function run(argv, io) {
253
282
  noMoreArguments(rest, 0, 'hopwire doctor [--network]');
254
283
  await doctor({
255
284
  dataDir,
285
+ profile,
256
286
  cwd: io.cwd ?? process.cwd(),
257
287
  version: readVersion(),
258
288
  network: values.network ?? false,
@@ -268,9 +298,10 @@ export async function run(argv, io) {
268
298
  // The value is not repeated: it may be a token, which belongs neither in an error nor in shell history
269
299
  throw new UsageError('--token takes no value: hopwire login --token asks for the token without showing it, or set HOPWIRE_TOKEN');
270
300
  }
271
- noMoreArguments(rest, 0, 'hopwire login [--api <url>] [--token] [--no-browser]');
301
+ noMoreArguments(rest, 0, 'hopwire login [--api <url>] [--token] [--no-browser] [--profile <name>]');
272
302
  await login({
273
303
  dataDir,
304
+ profile,
274
305
  apiUrl: values.api === undefined ? null : parseApiUrl(values.api),
275
306
  token: io.env.HOPWIRE_TOKEN,
276
307
  paste: values.token ?? false,
@@ -283,8 +314,18 @@ export async function run(argv, io) {
283
314
  return null;
284
315
  }
285
316
  if (command === 'logout') {
286
- noMoreArguments(rest, 0, 'hopwire logout');
287
- await logout({ dataDir, print: io.print });
317
+ noMoreArguments(rest, 0, 'hopwire logout [--profile <name>]');
318
+ await logout({ dataDir, profile, print: io.print });
319
+ return null;
320
+ }
321
+ if (command === 'profiles') {
322
+ noMoreArguments(rest, 0, 'hopwire profiles');
323
+ await profiles({ dataDir, print: io.print });
324
+ return null;
325
+ }
326
+ if (command === 'use') {
327
+ noMoreArguments(rest, 1, 'hopwire use <profile>');
328
+ await use({ dataDir, name: parseProfile(rest[0] ?? '', 'hopwire use'), print: io.print });
288
329
  return null;
289
330
  }
290
331
  if (command === 'mcp') {
@@ -315,15 +356,15 @@ export async function run(argv, io) {
315
356
  const port = parsePort(values.port, '--port', 0);
316
357
  const service = parseService(values.service);
317
358
  const allowHosts = (values['allow-host'] ?? []).map(parseAllowedHost);
318
- relayNeedsTeam(values);
359
+ relayImpliesTeam(values);
319
360
  return startConnect({
320
361
  peerKey,
321
362
  port,
322
363
  service,
323
364
  allowHosts,
324
365
  // The account is only read for --team: without it private mode never looks at it
325
- team: values.team ? await teamAccess('--team', dataDir) : undefined,
326
- relay: values.relay ? await relayAccess('--relay', dataDir) : undefined,
366
+ team: values.team ? await teamAccess(values.relay ? '--relay' : '--team', store) : undefined,
367
+ relay: values.relay ? await relayAccess('--relay', store) : undefined,
327
368
  dataDir,
328
369
  print: io.print,
329
370
  bootstrap: parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP),
@@ -335,15 +376,20 @@ export async function run(argv, io) {
335
376
  const logKey = parseKey(rest[0], 'The log key');
336
377
  const replayTarget = values['replay-target'] === undefined ? null : parseReplayTarget(values['replay-target']);
337
378
  const inspectPort = parsePort(values.inspect ?? String(INSPECTOR_DEFAULT_PORT), '--inspect', 0);
338
- relayNeedsTeam(values);
379
+ relayImpliesTeam(values);
380
+ if (values.log !== undefined && replayTarget === null) {
381
+ throw new UsageError('--log of hopwire watch only works together with --replay-target: it shows the entries of your replays');
382
+ }
339
383
  return startWatch({
340
384
  force: values.force ?? false,
385
+ logs: parseLogs(values.log, io.cwd ?? process.cwd()),
386
+ cwd: io.cwd ?? process.cwd(),
341
387
  logKey,
342
388
  replayTarget,
343
389
  inspectPort,
344
390
  // The account is only read for --team: without it private mode never looks at it
345
- team: values.team ? await teamAccess('--team', dataDir) : undefined,
346
- relay: values.relay ? await relayAccess('--relay', dataDir) : undefined,
391
+ team: values.team ? await teamAccess(values.relay ? '--relay' : '--team', store) : undefined,
392
+ relay: values.relay ? await relayAccess('--relay', store) : undefined,
347
393
  dataDir,
348
394
  print: io.print,
349
395
  bootstrap: parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP),
@@ -369,12 +415,12 @@ export async function run(argv, io) {
369
415
  print: io.print,
370
416
  // Token and account are only read when a service is public: private mode never looks at them
371
417
  ...(config.services.some((service) => service.public)
372
- ? update.watch(await publicAccess(shown, config, io.env, dataDir))
418
+ ? update.watch(await publicAccess(shown, config, io.env, store))
373
419
  : {}),
374
420
  // The account is only read for p2p.team: without it private mode never looks at it
375
- team: config.team ? await teamAccessOfFile(shown, config, dataDir) : undefined,
421
+ team: config.team ? await teamAccessOfFile(shown, config, store) : undefined,
376
422
  // The edge is only contacted for p2p.relay, and then only through the relay
377
- relay: config.relay ? await relayAccess('p2p.relay', dataDir) : undefined,
423
+ relay: config.relay ? await relayAccess('p2p.relay', store) : undefined,
378
424
  bootstrap: config.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
379
425
  agent: agent ?? config.agent ?? undefined,
380
426
  signal: io.signal,
@@ -391,13 +437,29 @@ export async function run(argv, io) {
391
437
  if (allow.length > 0 && !values.share) {
392
438
  throw new UsageError('--allow only works together with --share');
393
439
  }
440
+ if (values.relay && !values.share) {
441
+ throw new UsageError('--relay only works together with --share');
442
+ }
443
+ if (values.relay && allow.length > 0) {
444
+ throw new UsageError('--relay and --allow cannot be combined: the relay of the edge (Team plan) only pairs machines of one organisation, so --relay shares with your team');
445
+ }
446
+ relayImpliesTeam(values);
394
447
  if (values.team && !values.share) {
395
448
  throw new UsageError('--team only works together with --share');
396
449
  }
397
450
  if (values['allow-agents'] && !values.share) {
398
451
  throw new UsageError('--allow-agents only works together with --share');
399
452
  }
400
- relayNeedsTeam(values);
453
+ if (values['share-logs'] && !values.share) {
454
+ throw new UsageError('--share-logs only works together with --share');
455
+ }
456
+ if (values['share-logs'] && values.log === undefined) {
457
+ throw new UsageError('--share-logs only works together with --log <path>');
458
+ }
459
+ if (values['log-request-id'] && values.log === undefined) {
460
+ throw new UsageError('--log-request-id only works together with --log <path>');
461
+ }
462
+ const logs = parseLogs(values.log, io.cwd ?? process.cwd());
401
463
  if (values.team && allow.length > 0) {
402
464
  throw new UsageError('--team and --allow cannot be combined: with --team the team is the list');
403
465
  }
@@ -424,19 +486,62 @@ export async function run(argv, io) {
424
486
  allowAgents: values['allow-agents'] ?? false,
425
487
  allow,
426
488
  // The account is only read for --team: without it private mode never looks at it
427
- team: values.team ? await teamAccess('--team', dataDir) : undefined,
428
- relay: values.relay ? await relayAccess('--relay', dataDir) : undefined,
489
+ team: values.team ? await teamAccess(values.relay ? '--relay' : '--team', store) : undefined,
490
+ relay: values.relay ? await relayAccess('--relay', store) : undefined,
429
491
  bootstrap: values.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
430
492
  // Edge URL, token and account are only read for --public: private mode never looks at them
431
- public: values.public ? update.watch(await parsePublic(values.subdomain, io.env, dataDir)) : undefined,
493
+ public: values.public ? update.watch(await parsePublic(values.subdomain, io.env, store)) : undefined,
432
494
  agent: agentChoice(values),
433
495
  captureWebSocket: !(values['no-ws-capture'] ?? false),
496
+ logs,
497
+ shareLogs: values['share-logs'] ?? false,
498
+ logRequestId: values['log-request-id'] ?? false,
499
+ cwd: io.cwd ?? process.cwd(),
434
500
  signal: io.signal,
435
501
  });
436
502
  // After the lines of the start, so the mode stays the first line of every tunnel
437
503
  update.print(io.print);
438
504
  return running;
439
505
  }
506
+ /**
507
+ * The files of --log, resolved against the working directory and named after themselves. Two files with the same name
508
+ * would label their entries alike; hopwire.yaml can name them apart.
509
+ */
510
+ function parseLogs(values, cwd) {
511
+ const logs = [];
512
+ for (const value of values ?? []) {
513
+ if (value === '') {
514
+ throw new UsageError('--log needs the path of a log file');
515
+ }
516
+ const file = path.resolve(cwd, value);
517
+ if (!isFollowablePath(file)) {
518
+ throw new UsageError('--log takes a * only in the file name, not in a directory of the path');
519
+ }
520
+ const name = defaultLogName(file);
521
+ if (logs.some((log) => log.name === name)) {
522
+ throw new UsageError(`Two --log files are both named ${name}; give them names of their own under logs: in hopwire.yaml`);
523
+ }
524
+ logs.push({ path: file, name });
525
+ }
526
+ return logs;
527
+ }
528
+ /**
529
+ * The profile a command names: --profile, else HOPWIRE_PROFILE; null leaves it to the current profile of the data
530
+ * directory. A variable that is set but empty counts as not set.
531
+ */
532
+ function resolveProfile(option, env) {
533
+ if (option !== undefined) {
534
+ return parseProfile(option, '--profile');
535
+ }
536
+ const fromEnv = env.HOPWIRE_PROFILE === '' ? undefined : env.HOPWIRE_PROFILE;
537
+ return fromEnv === undefined ? null : parseProfile(fromEnv, 'HOPWIRE_PROFILE');
538
+ }
539
+ function parseProfile(value, label) {
540
+ if (!isProfileName(value)) {
541
+ throw new UsageError(`${label} needs a profile name: a letter or digit, then up to 31 letters, digits, - or _ (for example acme)`);
542
+ }
543
+ return value;
544
+ }
440
545
  /** The data directory: --data-dir, else HOPWIRE_HOME, else ~/.hopwire. */
441
546
  function resolveDataDir(option, env) {
442
547
  // A variable that is set but empty counts as not set; as a path it would be the working directory
@@ -456,7 +561,7 @@ function commandOf(argv) {
456
561
  if (argument === '--') {
457
562
  return argv[index + 1];
458
563
  }
459
- if (argument === '--data-dir') {
564
+ if (argument === '--data-dir' || argument === '--profile') {
460
565
  index++;
461
566
  }
462
567
  else if (!argument.startsWith('-')) {
@@ -476,6 +581,7 @@ async function runInit(argv, io) {
476
581
  help: { type: 'boolean', short: 'h' },
477
582
  version: { type: 'boolean' },
478
583
  'data-dir': { type: 'string' },
584
+ profile: { type: 'string' },
479
585
  config: { type: 'string' },
480
586
  yes: { type: 'boolean' },
481
587
  service: { type: 'string', multiple: true },
@@ -535,6 +641,7 @@ async function runInit(argv, io) {
535
641
  named: values.config !== undefined,
536
642
  cwd,
537
643
  dataDir: resolveDataDir(values['data-dir'], io.env),
644
+ profile: resolveProfile(values.profile, io.env),
538
645
  flags,
539
646
  ask: promptLine === undefined ? undefined : (question) => promptLine(question, io.signal),
540
647
  say: (line) => (io.notice ?? io.print)(line),
@@ -563,6 +670,7 @@ function parse(argv) {
563
670
  force: { type: 'boolean' },
564
671
  name: { type: 'string' },
565
672
  'data-dir': { type: 'string' },
673
+ profile: { type: 'string' },
566
674
  public: { type: 'boolean' },
567
675
  subdomain: { type: 'string' },
568
676
  share: { type: 'boolean' },
@@ -578,6 +686,9 @@ function parse(argv) {
578
686
  agent: { type: 'boolean' },
579
687
  'no-agent': { type: 'boolean' },
580
688
  'no-ws-capture': { type: 'boolean' },
689
+ log: { type: 'string', multiple: true },
690
+ 'share-logs': { type: 'boolean' },
691
+ 'log-request-id': { type: 'boolean' },
581
692
  'read-only': { type: 'boolean' },
582
693
  api: { type: 'string' },
583
694
  token: { type: 'boolean' },
@@ -656,13 +767,13 @@ function parseApiUrl(value) {
656
767
  * connect token for the subdomain, and the edge the account is bound to (the one its control plane names), unless
657
768
  * HOPWIRE_EDGE_URL names it. `hopwire up` reads the edge from edge.url in hopwire.yaml instead.
658
769
  */
659
- async function parsePublic(subdomain, env, dataDir) {
770
+ async function parsePublic(subdomain, env, store) {
660
771
  if (subdomain !== undefined && !isReservableSubdomain(subdomain)) {
661
772
  throw new UsageError('--subdomain must be 3 to 63 lowercase letters, digits or hyphens, must not start or end with a hyphen, must not start with t- and must not be a reserved name such as www or api');
662
773
  }
663
774
  const edge = env.HOPWIRE_EDGE_URL;
664
775
  if ((edge === undefined || edge.trim() === '') && (env.HOPWIRE_DEV_TOKEN ?? '').trim() === '') {
665
- return publicThroughAccountEdge(subdomain, dataDir);
776
+ return publicThroughAccountEdge(subdomain, store);
666
777
  }
667
778
  if (edge === undefined || edge.trim() === '') {
668
779
  throw new HopwireError('--public needs the URL of the edge: set HOPWIRE_EDGE_URL, for example ws://127.0.0.1:8787 for a local edge.');
@@ -683,11 +794,11 @@ async function parsePublic(subdomain, env, dataDir) {
683
794
  subdomain: subdomain ?? randomSubdomain(randomBytes(RANDOM_SUBDOMAIN_BYTES)),
684
795
  };
685
796
  }
686
- const account = await readAccount(dataDir);
797
+ const account = await readAccount(store);
687
798
  if (account === null) {
688
799
  throw new HopwireError('--public needs an account: run hopwire login first. For a local edge without a control plane, set HOPWIRE_DEV_TOKEN to its dev token instead.');
689
800
  }
690
- const connectTokens = await tokensForEdge(dataDir, account, edgeUrl, (bound) => new HopwireError(`HOPWIRE_EDGE_URL is ${edgeUrl.origin}, but the connect tokens of the account on this machine go to the edge ${bound.origin}; run hopwire login again to use the account with another edge.`));
801
+ const connectTokens = await tokensForEdge(store, account, edgeUrl, (bound) => new HopwireError(`HOPWIRE_EDGE_URL is ${edgeUrl.origin}, but the connect tokens of the account on this machine go to the edge ${bound.origin}; run hopwire login again to use the account with another edge.`));
691
802
  // Without --subdomain the control plane names the fixed URL of the organisation
692
803
  return { edgeUrl, connectTokens, subdomain: subdomain ?? null };
693
804
  }
@@ -695,20 +806,20 @@ async function parsePublic(subdomain, env, dataDir) {
695
806
  * --public without HOPWIRE_EDGE_URL: the account of `hopwire login` and the edge it is bound to. An account logged in
696
807
  * before logins stored the edge asks its control plane once and is bound to the edge it names.
697
808
  */
698
- async function publicThroughAccountEdge(subdomain, dataDir) {
699
- const account = await readAccount(dataDir);
809
+ async function publicThroughAccountEdge(subdomain, store) {
810
+ const account = await readAccount(store);
700
811
  if (account === null) {
701
812
  throw new HopwireError('--public needs an account: run hopwire login first. For a local edge without a control plane, set HOPWIRE_EDGE_URL and HOPWIRE_DEV_TOKEN to its URL and dev token instead.');
702
813
  }
703
814
  const { createControlPlaneClient } = await import('./control-plane-client.js');
704
815
  const connectTokens = createControlPlaneClient({ url: account.controlPlaneUrl, apiToken: account.apiToken });
705
- let edgeUrl = await boundEdge(dataDir);
816
+ let edgeUrl = await boundEdge(store);
706
817
  if (edgeUrl === null) {
707
818
  edgeUrl = (await connectTokens.me()).edgeUrl;
708
819
  if (edgeUrl === null) {
709
820
  throw new HopwireError(`--public needs the URL of the edge: the control plane at ${account.controlPlaneUrl.origin} names none; set HOPWIRE_EDGE_URL.`);
710
821
  }
711
- edgeUrl = await bindEdge(dataDir, edgeUrl);
822
+ edgeUrl = await bindEdge(store, edgeUrl);
712
823
  }
713
824
  return { edgeUrl, connectTokens, subdomain: subdomain ?? null };
714
825
  }
@@ -717,7 +828,7 @@ async function publicThroughAccountEdge(subdomain, dataDir) {
717
828
  * `hopwire login`, which has to be one at that control plane; without it the dev token of the edge from
718
829
  * HOPWIRE_DEV_TOKEN.
719
830
  */
720
- async function publicAccess(file, config, env, dataDir) {
831
+ async function publicAccess(file, config, env, store) {
721
832
  if (config.controlPlaneUrl === null) {
722
833
  const token = env.HOPWIRE_DEV_TOKEN;
723
834
  if (token === undefined || token.trim() === '') {
@@ -726,7 +837,7 @@ async function publicAccess(file, config, env, dataDir) {
726
837
  return { token: token.trim() };
727
838
  }
728
839
  const wanted = config.controlPlaneUrl.origin;
729
- const account = await readAccount(dataDir);
840
+ const account = await readAccount(store);
730
841
  if (account === null) {
731
842
  throw new ConfigError(file, 'controlPlane.url', `is set, so the public services use your account there, but this machine is not logged in; run hopwire login --api ${wanted} first.`);
732
843
  }
@@ -738,7 +849,7 @@ async function publicAccess(file, config, env, dataDir) {
738
849
  // The file names the edge, but the account decides where its connect tokens go (see tokensForEdge)
739
850
  const named = config.edgeUrl;
740
851
  return {
741
- connectTokens: await tokensForEdge(dataDir, account, named, (bound) => new ConfigError(file, 'edge.url', `is ${named.origin}, but the connect tokens of the account on this machine go to the edge ${bound.origin}; run hopwire login again to use the account with another edge, or change the URL in the file.`)),
852
+ connectTokens: await tokensForEdge(store, account, named, (bound) => new ConfigError(file, 'edge.url', `is ${named.origin}, but the connect tokens of the account on this machine go to the edge ${bound.origin}; run hopwire login again to use the account with another edge, or change the URL in the file.`)),
742
853
  };
743
854
  }
744
855
  return { connectTokens: await connectTokenSource(account) };
@@ -753,8 +864,8 @@ async function publicAccess(file, config, env, dataDir) {
753
864
  * into this machine's services, to the edge that repository's file names. The question is part of fetching the
754
865
  * first token, so a start that is stopped gives it up like any request to the control plane.
755
866
  */
756
- async function tokensForEdge(dataDir, account, named, mismatch) {
757
- const bound = await boundEdge(dataDir);
867
+ async function tokensForEdge(store, account, named, mismatch) {
868
+ const bound = await boundEdge(store);
758
869
  if (bound !== null && bound.origin !== named.origin) {
759
870
  throw mismatch(bound);
760
871
  }
@@ -768,7 +879,7 @@ async function tokensForEdge(dataDir, account, named, mismatch) {
768
879
  async connectToken(subdomain, signal) {
769
880
  binding ??= (async () => {
770
881
  const ofControlPlane = (await client.me(signal)).edgeUrl;
771
- const now = await bindEdge(dataDir, ofControlPlane ?? named);
882
+ const now = await bindEdge(store, ofControlPlane ?? named);
772
883
  if (now.origin !== named.origin) {
773
884
  throw mismatch(now);
774
885
  }
@@ -791,22 +902,25 @@ async function tokensForEdge(dataDir, account, named, mismatch) {
791
902
  * What --team needs: the account of `hopwire login`, whose control plane names the keys of the team. Loaded only
792
903
  * for --team (or p2p.team), the one case in which private mode asks a server anything.
793
904
  */
794
- async function teamAccess(option, dataDir) {
795
- return accountClient(option, dataDir);
905
+ async function teamAccess(option, store) {
906
+ return accountClient(option, store);
796
907
  }
797
908
  /** The control plane of the stored account, for --team and --relay. */
798
- async function accountClient(option, dataDir) {
799
- const account = await readAccount(dataDir);
909
+ async function accountClient(option, store) {
910
+ const account = await readAccount(store);
800
911
  if (account === null) {
801
912
  throw new HopwireError(`${option} needs an account in an organisation on the Team plan: run hopwire login first. Without an account, restrict access with --allow <pubkey> (p2p.allow in hopwire.yaml) instead.`);
802
913
  }
803
914
  const { createControlPlaneClient } = await import('./control-plane-client.js');
804
915
  return createControlPlaneClient({ url: account.controlPlaneUrl, apiToken: account.apiToken });
805
916
  }
806
- /** --relay pairs machines of one organisation only, so it needs --team. */
807
- function relayNeedsTeam(values) {
808
- if (values.relay && !values.team) {
809
- throw new UsageError('--relay only works together with --team: the relay of the edge (Team plan) only pairs machines of one organisation');
917
+ /**
918
+ * --relay pairs machines of one organisation only, so it turns on --team: giving --team as well is not needed.
919
+ * Called before anything reads values.team.
920
+ */
921
+ function relayImpliesTeam(values) {
922
+ if (values.relay) {
923
+ values.team = true;
810
924
  }
811
925
  }
812
926
  /**
@@ -814,21 +928,21 @@ function relayNeedsTeam(values) {
814
928
  * control plane, which issues the relay tokens. Loaded only for --relay, the one case in which private mode contacts
815
929
  * the edge, and then only when no direct connection comes about.
816
930
  */
817
- async function relayAccess(option, dataDir) {
818
- const client = await accountClient(option, dataDir);
819
- let edgeUrl = await boundEdge(dataDir);
931
+ async function relayAccess(option, store) {
932
+ const client = await accountClient(option, store);
933
+ let edgeUrl = await boundEdge(store);
820
934
  if (edgeUrl === null) {
821
935
  const named = (await client.me()).edgeUrl;
822
936
  if (named === null) {
823
937
  throw new HopwireError(`${option} goes through the edge of your account, but its control plane names none; run hopwire login again, or leave ${option} out.`);
824
938
  }
825
- edgeUrl = await bindEdge(dataDir, named);
939
+ edgeUrl = await bindEdge(store, named);
826
940
  }
827
941
  return { edgeUrl, tokens: client };
828
942
  }
829
943
  /** p2p.team of a hopwire.yaml: the account has to be one at the control plane the file names, when it names one. */
830
- async function teamAccessOfFile(file, config, dataDir) {
831
- const account = await readAccount(dataDir);
944
+ async function teamAccessOfFile(file, config, store) {
945
+ const account = await readAccount(store);
832
946
  if (account === null) {
833
947
  throw new ConfigError(file, 'p2p.team', 'is true, which needs an account in an organisation on the Team plan, but this machine is not logged in; run hopwire login first, or list the keys under p2p.allow instead.');
834
948
  }
@@ -836,7 +950,7 @@ async function teamAccessOfFile(file, config, dataDir) {
836
950
  // The stored API token belongs to another control plane and is not sent to this one
837
951
  throw new ConfigError(file, 'controlPlane.url', `is ${config.controlPlaneUrl.origin}, but this machine is logged in at ${account.controlPlaneUrl.origin}; run hopwire login --api ${config.controlPlaneUrl.origin}, or change the URL in the file.`);
838
952
  }
839
- return teamAccess('p2p.team', dataDir);
953
+ return teamAccess('p2p.team', store);
840
954
  }
841
955
  /** --allow-host: a host name or address as a Host header carries it, with or without a port; in lower case. */
842
956
  function parseAllowedHost(value) {