hopwire 0.1.4 → 0.1.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.
@@ -5,7 +5,7 @@ import path from 'node:path';
5
5
  import { HopwireError, errorCode } from './errors.js';
6
6
  import { ApiError, sendError } from './inspector-api.js';
7
7
  /**
8
- * The agent socket of a tunnel started with --agent: the inspector API on a Unix socket that only this user can
8
+ * The agent socket of a tunnel (on by default, decision 139; --no-agent turns it off): the inspector API on a Unix socket that only this user can
9
9
  * reach (`<dataDir>/run/agent.sock`, the directory 0700, the socket 0600), for `hopwire mcp`. It needs no access
10
10
  * key, Host or Origin check: a browser cannot reach a Unix socket, and the file system decides who can.
11
11
  */
@@ -30,14 +30,14 @@ export async function checkRunDirectory(dir, repair) {
30
30
  }
31
31
  if ((stats.mode & 0o077) !== 0) {
32
32
  if (!repair) {
33
- throw new HopwireError(`${dir} can be entered by other users; restart the tunnel with --agent to fix it.`);
33
+ throw new HopwireError(`${dir} can be entered by other users; restart the tunnel to fix it.`);
34
34
  }
35
35
  await chmod(dir, 0o700);
36
36
  }
37
37
  }
38
38
  export async function startAgentSocket(api, dataDir) {
39
39
  if (process.platform === 'win32') {
40
- throw new HopwireError('--agent needs a Unix socket and is not available on Windows.');
40
+ throw new HopwireError('The agent socket needs a Unix socket and is not available on Windows; start without --agent.');
41
41
  }
42
42
  const socketPath = agentSocketPath(dataDir);
43
43
  if (Buffer.byteLength(socketPath) > AGENT_SOCKET_PATH_MAX_BYTES) {
package/dist/cli.js CHANGED
@@ -51,7 +51,7 @@ Commands:
51
51
  hopwire doctor Print a report about this installation (versions, data directory, account,
52
52
  hopwire.yaml) to read or to paste into a bug report. It is sent nowhere
53
53
  hopwire mcp An MCP server for a coding agent on this machine (stdio): it reads and replays
54
- the traffic of a tunnel started with --agent on the same data directory
54
+ the traffic of a tunnel running on the same data directory
55
55
 
56
56
  Options for http:
57
57
  --listen <port> Loopback port of the entry point (default ${LOCAL_ENTRY_DEFAULT_PORT}, 0 picks a free one)
@@ -74,16 +74,22 @@ Options for http:
74
74
  it the fixed t-... URL of your organisation is used (a random one with a dev token)
75
75
  --force When another tunnel holds the data directory, stop it (as Ctrl+C does) and start
76
76
  this one in its place
77
- --agent Let a coding agent on this machine read the traffic and replay it (hopwire mcp),
78
- through a socket only this user can open. What the agent reads goes to its model
79
- provider
77
+ --no-agent Do not let a coding agent on this machine read the traffic and replay it. By
78
+ default it can, through hopwire mcp and a socket only this user can open; what the
79
+ agent reads goes to its model provider. Nothing reaches an agent until you register
80
+ hopwire mcp with one
81
+ --agent Require that socket: fail when it cannot open (by default the tunnel then runs
82
+ without it)
83
+ --allow-agents With --share: the coding agents of teammates who watch the log (hopwire watch
84
+ --agent) may read the exchanges captured from now on. What an agent reads goes to its
85
+ model provider; exchanges captured without it stay closed to agents
80
86
 
81
87
  Options for up:
82
88
  --config <path> The config file (default ${HOPWIRE_YAML_FILE} in the working directory). A public service
83
89
  takes the URL of the edge from edge.url in the file. With controlPlane.url in the file
84
90
  it uses your account (hopwire login), without it the dev token in HOPWIRE_DEV_TOKEN.
85
91
  p2p.team in the file is --team of http
86
- --agent As for http: the traffic of every service for hopwire mcp
92
+ --no-agent, --agent As for http, for every service; agent: false in the file turns it off too
87
93
  --force As for http: stop the tunnel that holds the data directory first
88
94
 
89
95
  Options for login:
@@ -118,6 +124,9 @@ Options for watch:
118
124
  --inspect <port> Loopback port of the inspector (default ${INSPECTOR_DEFAULT_PORT}, 0 picks a free one)
119
125
  --team For a teammate who shares with --team: registers the key of this machine with your
120
126
  organisation (hopwire login first), so the sharer lets it in
127
+ --agent Let a coding agent on this machine read the exchanges your teammate allowed for
128
+ agents (they share with --allow-agents) through hopwire mcp; never on without it.
129
+ What the agent reads goes to its model provider
121
130
  --force As for http: stop the tunnel that holds the data directory first
122
131
 
123
132
  Global options:
@@ -131,8 +140,8 @@ export const MCP_TERMINAL_HINT = [
131
140
  'hopwire mcp is an MCP server for coding agents. It is started by the agent, not by hand,',
132
141
  'and is now waiting for one on standard input.',
133
142
  '',
134
- ' 1. Start a tunnel with --agent: hopwire http 3000 --agent',
135
- ' 2. Register it with your agent: claude mcp add hopwire -- hopwire mcp',
143
+ ' 1. Start a tunnel: hopwire http 3000',
144
+ ' 2. Register it with your agent: claude mcp add hopwire -- hopwire mcp',
136
145
  '',
137
146
  `Cursor, Codex and other agents: ${DOCS_URL}/coding-agents`,
138
147
  'Press Ctrl+C to stop.',
@@ -148,16 +157,18 @@ const COMMAND_OPTIONS = {
148
157
  'share',
149
158
  'allow',
150
159
  'team',
160
+ 'allow-agents',
151
161
  'public',
152
162
  'subdomain',
153
163
  'agent',
164
+ 'no-agent',
154
165
  'force',
155
166
  ],
156
- up: ['config', 'agent', 'force'],
167
+ up: ['config', 'agent', 'no-agent', 'force'],
157
168
  id: [],
158
169
  rotate: [],
159
170
  connect: ['port', 'service', 'allow-host', 'team'],
160
- watch: ['replay-target', 'inspect', 'team', 'force'],
171
+ watch: ['replay-target', 'inspect', 'team', 'agent', 'force'],
161
172
  login: ['api', 'token', 'no-browser'],
162
173
  logout: [],
163
174
  mcp: ['read-only'],
@@ -298,11 +309,13 @@ export async function run(argv, io) {
298
309
  dataDir,
299
310
  print: io.print,
300
311
  bootstrap: parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP),
312
+ agent: values.agent ?? false,
301
313
  signal: io.signal,
302
314
  });
303
315
  }
304
316
  if (command === 'up') {
305
317
  noMoreArguments(rest, 0, 'hopwire up [--config <path>]');
318
+ const agent = agentChoice(values);
306
319
  if (values.config === '') {
307
320
  throw new UsageError('--config needs the path of a config file');
308
321
  }
@@ -326,7 +339,7 @@ export async function run(argv, io) {
326
339
  // The account is only read for p2p.team: without it private mode never looks at it
327
340
  team: config.team ? await teamAccessOfFile(shown, config, dataDir) : undefined,
328
341
  bootstrap: config.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
329
- agent: values.agent ?? false,
342
+ agent: agent ?? config.agent ?? undefined,
330
343
  signal: io.signal,
331
344
  });
332
345
  // After the lines of the start, so the mode stays the first line of every tunnel
@@ -344,6 +357,9 @@ export async function run(argv, io) {
344
357
  if (values.team && !values.share) {
345
358
  throw new UsageError('--team only works together with --share');
346
359
  }
360
+ if (values['allow-agents'] && !values.share) {
361
+ throw new UsageError('--allow-agents only works together with --share');
362
+ }
347
363
  if (values.team && allow.length > 0) {
348
364
  throw new UsageError('--team and --allow cannot be combined: with --team the team is the list');
349
365
  }
@@ -367,19 +383,27 @@ export async function run(argv, io) {
367
383
  serviceName: values.name ?? 'default',
368
384
  print: io.print,
369
385
  share: values.share ?? false,
386
+ allowAgents: values['allow-agents'] ?? false,
370
387
  allow,
371
388
  // The account is only read for --team: without it private mode never looks at it
372
389
  team: values.team ? await teamAccess('--team', dataDir) : undefined,
373
390
  bootstrap: values.share ? parseBootstrap(io.env.HOPWIRE_DHT_BOOTSTRAP) : undefined,
374
391
  // Edge URL, token and account are only read for --public: private mode never looks at them
375
392
  public: values.public ? update.watch(await parsePublic(values.subdomain, io.env, dataDir)) : undefined,
376
- agent: values.agent ?? false,
393
+ agent: agentChoice(values),
377
394
  signal: io.signal,
378
395
  });
379
396
  // After the lines of the start, so the mode stays the first line of every tunnel
380
397
  update.print(io.print);
381
398
  return running;
382
399
  }
400
+ /** --agent or --no-agent; undefined leaves the choice to hopwire.yaml or the default (on, decision 139). */
401
+ function agentChoice(values) {
402
+ if (values.agent && values['no-agent']) {
403
+ throw new UsageError('--agent and --no-agent cannot be combined');
404
+ }
405
+ return values.agent ? true : values['no-agent'] ? false : undefined;
406
+ }
383
407
  function parse(argv) {
384
408
  try {
385
409
  return parseArgs({
@@ -400,12 +424,14 @@ function parse(argv) {
400
424
  share: { type: 'boolean' },
401
425
  allow: { type: 'string', multiple: true },
402
426
  team: { type: 'boolean' },
427
+ 'allow-agents': { type: 'boolean' },
403
428
  'allow-host': { type: 'string', multiple: true },
404
429
  port: { type: 'string' },
405
430
  service: { type: 'string' },
406
431
  'replay-target': { type: 'string' },
407
432
  config: { type: 'string' },
408
433
  agent: { type: 'boolean' },
434
+ 'no-agent': { type: 'boolean' },
409
435
  'read-only': { type: 'boolean' },
410
436
  api: { type: 'string' },
411
437
  token: { type: 'boolean' },
@@ -1,4 +1,4 @@
1
- import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, agentLine, formatExchange, formatLimitReached, formatMeteredUsage, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
1
+ import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatLimitReached, formatMeteredUsage, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
2
2
  import { startServing } from '../serve.js';
3
3
  export { INSPECTOR_FILES } from '../serve.js';
4
4
  /**
@@ -18,12 +18,13 @@ export async function startHttpTunnel(options) {
18
18
  force: options.force ?? false,
19
19
  onHolderStopped: (line) => stopped.push(line),
20
20
  share: options.share ?? false,
21
+ allowAgents: options.allowAgents ?? false,
21
22
  allow,
22
23
  team: options.team,
23
24
  onTeamEvent: (event, organisation) => options.print(formatTeamEvent(event, organisation)),
24
25
  bootstrap: options.bootstrap,
25
26
  inspectorFiles: options.inspectorFiles,
26
- agent: options.agent ?? false,
27
+ agent: options.agent,
27
28
  signal: options.signal,
28
29
  listenOption: '--listen <port>',
29
30
  inspectOption: '--inspect <port> or run with --no-inspect',
@@ -58,12 +59,18 @@ export async function startHttpTunnel(options) {
58
59
  if (peerKey !== null) {
59
60
  options.print(`Peer key ${peerKey}`);
60
61
  options.print(shareNotice(access));
62
+ if (options.allowAgents === true) {
63
+ options.print(AGENTS_ALLOWED_LINE);
64
+ }
61
65
  }
62
66
  if (inspectorUrl !== null) {
63
67
  options.print(`Inspector ${inspectorUrl}`);
64
68
  }
65
69
  if (agentSocket !== null) {
66
- options.print(agentLine(agentSocket, target.origin));
70
+ options.print(agentLine(agentSocket, target.origin, '--no-agent'));
71
+ }
72
+ else if (serving.agentProblem !== null) {
73
+ options.print(agentOffLine(serving.agentProblem));
67
74
  }
68
75
  for (const line of tunnelGuide({
69
76
  services: [
@@ -1,7 +1,7 @@
1
1
  import { createAgentClient } from '../mcp/client.js';
2
2
  import { MESSAGE_LIMIT_BYTES, createMcpServer } from '../mcp/jsonrpc.js';
3
3
  /**
4
- * `hopwire mcp`: a stdio MCP server for coding agents on this machine. It reaches a tunnel started with --agent
4
+ * `hopwire mcp`: a stdio MCP server for coding agents on this machine. It reaches a tunnel with the agent socket (on by default)
5
5
  * through the agent socket of the data directory. It opens no TCP connection, never opens the traffic log and writes
6
6
  * no file; standard output carries JSON-RPC and nothing else.
7
7
  */
@@ -1,7 +1,7 @@
1
1
  import { randomBytes } from 'node:crypto';
2
2
  import { LOCAL_ENTRY_DEFAULT_PORT, RANDOM_SUBDOMAIN_BYTES, randomSubdomain } from '@hopwire/protocol';
3
3
  import { HopwireError } from '../errors.js';
4
- import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, agentLine, formatExchange, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
4
+ import { MODE_LOCAL, MODE_P2P, MODE_P2P_TEAM, MODE_PUBLIC, MODE_PUBLIC_P2P, MODE_PUBLIC_P2P_TEAM, AGENTS_ALLOWED_LINE, agentLine, agentOffLine, formatExchange, formatTeamEvent, formatUsage, shareNotice, tunnelGuide, } from '../output.js';
5
5
  import { startServing } from '../serve.js';
6
6
  import { formatBridgeEvent } from './http.js';
7
7
  /**
@@ -41,12 +41,13 @@ export async function startUp(options) {
41
41
  force: options.force ?? false,
42
42
  onHolderStopped: (line) => stopped.push(line),
43
43
  share: config.share,
44
+ allowAgents: config.allowAgents,
44
45
  allow: config.allow ?? [],
45
46
  team: options.team,
46
47
  onTeamEvent: (event, organisation) => options.print(formatTeamEvent(event, organisation)),
47
48
  bootstrap: options.bootstrap,
48
49
  inspectorFiles: options.inspectorFiles,
49
- agent: options.agent ?? false,
50
+ agent: options.agent,
50
51
  signal: options.signal,
51
52
  listenOption: 'a free port',
52
53
  inspectOption: 'inspector.port in hopwire.yaml',
@@ -83,11 +84,17 @@ export async function startUp(options) {
83
84
  if (serving.peerKey !== null) {
84
85
  options.print(`Peer key ${serving.peerKey}`);
85
86
  options.print(shareNotice(access, 'p2p.allow in hopwire.yaml'));
87
+ if (config.allowAgents) {
88
+ options.print(AGENTS_ALLOWED_LINE);
89
+ }
86
90
  }
87
91
  options.print(`Inspector ${serving.inspectorUrl ?? ''}`);
88
92
  if (serving.agentSocket !== null) {
89
93
  const [first, ...rest] = serving.services;
90
- options.print(agentLine(serving.agentSocket, first !== undefined && rest.length === 0 ? first.target : 'the local service of each exchange'));
94
+ options.print(agentLine(serving.agentSocket, first !== undefined && rest.length === 0 ? first.target : 'the local service of each exchange', '--no-agent or agent: false in hopwire.yaml'));
95
+ }
96
+ else if (serving.agentProblem !== null) {
97
+ options.print(agentOffLine(serving.agentProblem));
91
98
  }
92
99
  for (const line of tunnelGuide({
93
100
  services: serving.services.map((service, index) => ({
@@ -1,10 +1,12 @@
1
1
  import { openOwnLog } from '../data-dir-holder.js';
2
+ import { startAgentSocket } from '../agent-socket.js';
2
3
  import { HopwireError, listenError } from '../errors.js';
3
4
  import { loadOrCreateIdentity } from '../identity.js';
5
+ import { agentsOnly, createInspectorApi } from '../inspector-api.js';
4
6
  import { startInspectorServer } from '../inspector-server.js';
5
7
  import { createInterceptor } from '../interceptor.js';
6
8
  import { REMOTE_LOG_BUDGET_BYTES } from '../log.js';
7
- import { MODE_P2P, MODE_P2P_TEAM, formatExchange, printable, shortKey, watchGuide } from '../output.js';
9
+ import { MODE_P2P, MODE_P2P_TEAM, formatExchange, printable, shortKey, watchAgentLine, watchGuide } from '../output.js';
8
10
  import { INSPECTOR_FILES } from '../serve.js';
9
11
  import { Supervisor, unlessAborted } from '../supervisor.js';
10
12
  /**
@@ -107,6 +109,23 @@ export async function startWatch(options) {
107
109
  throw listenError(error, options.inspectPort, 'inspector', '--inspect <port>');
108
110
  });
109
111
  supervisor.add('servers', () => inspector.close());
112
+ let agentSocket = null;
113
+ if (options.agent === true) {
114
+ proceed();
115
+ // Its own API: the browser inspector above shows the whole log, the agent only what the sharer allowed
116
+ const api = createInspectorApi({
117
+ sources: [
118
+ { origin: 'remote', log: agentsOnly(remote) },
119
+ { origin: 'own', log: own },
120
+ ],
121
+ status: () => status,
122
+ replayThrough: (exchange) => replayThrough(exchange.serviceName),
123
+ });
124
+ supervisor.add('servers', async () => api.close());
125
+ const socket = await startAgentSocket(api, options.dataDir);
126
+ supervisor.add('servers', () => socket.close());
127
+ agentSocket = socket.path;
128
+ }
110
129
  // Stopped at the last step: nothing is reported as running
111
130
  proceed();
112
131
  const stopPrinting = remote.subscribe((_index, exchange) => options.print(formatExchange(exchange)));
@@ -122,13 +141,16 @@ export async function startWatch(options) {
122
141
  ? 'Replay off; start hopwire watch with --replay-target <url> to replay to a local service'
123
142
  : `Replay to ${options.replayTarget.origin}`);
124
143
  options.print(`Inspector ${inspector.url}`);
144
+ if (agentSocket !== null) {
145
+ options.print(watchAgentLine(agentSocket, options.replayTarget?.origin ?? null));
146
+ }
125
147
  for (const line of watchGuide(options.replayTarget?.origin ?? null)) {
126
148
  options.print(line);
127
149
  }
128
150
  for (const line of stopped) {
129
151
  options.print(line);
130
152
  }
131
- return { kind: 'watch', inspectorUrl: inspector.url, logKey, peerKey, close };
153
+ return { kind: 'watch', inspectorUrl: inspector.url, agentSocket, logKey, peerKey, close };
132
154
  }
133
155
  catch (error) {
134
156
  await close().catch(() => { });
package/dist/config.js CHANGED
@@ -23,7 +23,7 @@ class Problem {
23
23
  this.problem = problem;
24
24
  }
25
25
  }
26
- const ROOT_KEYS = ['version', 'inspector', 'edge', 'controlPlane', 'p2p', 'services'];
26
+ const ROOT_KEYS = ['version', 'inspector', 'agent', 'edge', 'controlPlane', 'p2p', 'services'];
27
27
  const SERVICE_KEYS = ['local', 'public', 'subdomain', 'auth'];
28
28
  const LOCAL_RULE = 'must be an http URL on this machine without a path, for example http://127.0.0.1:3000; Hopwire only forwards to loopback addresses.';
29
29
  const SUBDOMAIN_RULE = '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.';
@@ -142,10 +142,15 @@ function validate(value, ordered) {
142
142
  let share = false;
143
143
  let allow = null;
144
144
  let team = false;
145
+ let allowAgents = false;
145
146
  if (root.p2p !== undefined) {
146
- const p2p = mapping(root.p2p, ['p2p'], ['share', 'allow', 'team'], 'p2p');
147
+ const p2p = mapping(root.p2p, ['p2p'], ['share', 'allow', 'team', 'allowAgents'], 'p2p');
147
148
  share = boolean(p2p.share, ['p2p', 'share']);
148
149
  team = boolean(p2p.team, ['p2p', 'team']);
150
+ allowAgents = boolean(p2p.allowAgents, ['p2p', 'allowAgents']);
151
+ if (allowAgents && !share) {
152
+ throw new Problem(['p2p', 'allowAgents'], 'needs p2p.share: true; it lets the coding agents of teammates who watch the shared log read it.');
153
+ }
149
154
  if (team && !share) {
150
155
  throw new Problem(['p2p', 'team'], 'only works together with p2p.share: true; it decides who the shared services and the shared log are for.');
151
156
  }
@@ -191,7 +196,8 @@ function validate(value, ordered) {
191
196
  if (edgeUrl === null && services.some((service) => service.public)) {
192
197
  throw new Problem(['edge', 'url'], 'is missing, and a service is public; add the URL of the edge, for example ws://127.0.0.1:8787 for a local edge.');
193
198
  }
194
- return { inspectorPort, edgeUrl, controlPlaneUrl, share, allow, team, services };
199
+ const agent = root.agent === undefined ? null : boolean(root.agent, ['agent']);
200
+ return { inspectorPort, edgeUrl, controlPlaneUrl, share, allow, team, allowAgents, agent, services };
195
201
  }
196
202
  /**
197
203
  * The names of the services in the order of the file. The plain object cannot say: JavaScript lists keys that look
@@ -3,6 +3,36 @@ import { INSPECTOR_HEARTBEAT_INTERVAL_MS, ProtocolError, decodeReplayOverrides,
3
3
  import { isRedactedHeader } from './agent/redact.js';
4
4
  import { summarize } from './agent/summary.js';
5
5
  import { InvalidBlockError } from './log.js';
6
+ /**
7
+ * A teammate's log as their coding agents may see it (spec decision 140): only the exchanges the sharer marked with
8
+ * agents: true. Any other block is left out as a block that is not an exchange is, so no route can list, find or
9
+ * replay it; the browser inspector reads the log itself.
10
+ */
11
+ export function agentsOnly(log) {
12
+ return {
13
+ get length() {
14
+ return log.length;
15
+ },
16
+ async get(index, options) {
17
+ const exchange = await log.get(index, options);
18
+ if (exchange.agents !== true) {
19
+ throw new InvalidBlockError(index);
20
+ }
21
+ return exchange;
22
+ },
23
+ async find(id) {
24
+ const found = await log.find(id);
25
+ return found?.exchange.agents === true ? found : null;
26
+ },
27
+ subscribe(listener) {
28
+ return log.subscribe((index, exchange) => {
29
+ if (exchange.agents === true) {
30
+ listener(index, exchange);
31
+ }
32
+ });
33
+ },
34
+ };
35
+ }
6
36
  /** An answer of the API that is not a success: HTTP status, a stable code and one sentence. */
7
37
  export class ApiError extends Error {
8
38
  status;
@@ -45,6 +45,7 @@ export function createInterceptor(options) {
45
45
  serviceName,
46
46
  source: request.source,
47
47
  ...(request.replayOf === undefined ? {} : { replayOf: request.replayOf }),
48
+ ...(options.allowAgents === true ? { agents: true } : {}),
48
49
  request: {
49
50
  method: request.method,
50
51
  path: request.path,
@@ -19,7 +19,7 @@ export class ToolError extends Error {
19
19
  this.hint = hint;
20
20
  }
21
21
  }
22
- export const START_HINT = 'Start the tunnel with hopwire http <port> --agent (or hopwire up --agent) on the same data directory, then try again.';
22
+ export const START_HINT = 'Start a tunnel with hopwire http <port> (or hopwire up) on the same data directory, without --no-agent, then try again.';
23
23
  /** Largest answer read from the tunnel: a record holds up to about 6 MB of Base64 bodies */
24
24
  const ANSWER_LIMIT_BYTES = 32 * 1024 * 1024;
25
25
  const REQUEST_TIMEOUT_MS = 30_000;
@@ -165,5 +165,5 @@ export function createAgentClient(dataDir) {
165
165
  };
166
166
  }
167
167
  export function noInstance() {
168
- return new ToolError('no_instance', 'No tunnel with --agent is running on this data directory.', START_HINT);
168
+ return new ToolError('no_instance', 'No tunnel with the agent socket is running on this data directory.', START_HINT);
169
169
  }
package/dist/mcp/tools.js CHANGED
@@ -297,7 +297,7 @@ async function record(context, id) {
297
297
  const statusTool = {
298
298
  name: 'hopwire_status',
299
299
  title: 'Hopwire tunnel status',
300
- description: `Whether a Hopwire tunnel started with --agent is running on this machine's data directory, its mode and its services (local target, loopback entry point, public URL). Call it first. ${NOTE}`,
300
+ description: `Whether a Hopwire tunnel with the agent socket (on unless started with --no-agent) is running on this machine's data directory, its mode and its services (local target, loopback entry point, public URL). Call it first. ${NOTE}`,
301
301
  inputSchema: schema({}),
302
302
  annotations: { readOnlyHint: true, openWorldHint: false },
303
303
  async call(args, context) {
package/dist/output.js CHANGED
@@ -31,6 +31,8 @@ export function shareNotice(allowed, restrictWith = '--allow <pubkey>') {
31
31
  : `Only machines of the members of ${printable(allowed.team)} can read it or reach the service (${allowed.keys === 1 ? 'one key' : `${allowed.keys} keys`} now; the list follows the team).`;
32
32
  return `Notice The shared log contains headers and bodies as captured, including credentials. It is the whole log of this data directory, earlier runs included. ${who}`;
33
33
  }
34
+ /** The line of a tunnel shared with --allow-agents (decision 140): what a teammate's agent may read from now on. */
35
+ export const AGENTS_ALLOWED_LINE = 'Agents Teammates who watch this log can let their coding agents read the exchanges captured from now on (hopwire watch --agent); what an agent reads goes to its model provider. Exchanges captured before, or after a start without it, stay closed to agents.';
34
36
  /** One line for a change of the list of a tunnel shared with --team. */
35
37
  export function formatTeamEvent(event, organisation) {
36
38
  switch (event.type) {
@@ -43,11 +45,20 @@ export function formatTeamEvent(event, organisation) {
43
45
  }
44
46
  }
45
47
  /**
46
- * The line of a tunnel started with --agent. It says what the socket gives away: a coding agent of this user reads
48
+ * The line of a tunnel with the agent socket (on by default, decision 139). It says what the socket gives away: a coding agent of this user reads
47
49
  * the traffic (and the agent's model provider then receives what it reads) and can replay it to the local service.
48
50
  */
49
- export function agentLine(socketPath, replayTo) {
50
- return `Agent ${socketPath} (a coding agent on this machine can read this traffic and replay it to ${replayTo})`;
51
+ export function agentLine(socketPath, replayTo, turnOff) {
52
+ return `Agent ${socketPath} (a coding agent on this machine can read this traffic and replay it to ${replayTo}; ${turnOff} turns it off)`;
53
+ }
54
+ /** The agent line of hopwire watch --agent (decision 140): the teammate decides which exchanges an agent sees. */
55
+ export function watchAgentLine(socketPath, replayTo) {
56
+ const replay = replayTo === null ? 'not replay them (no --replay-target)' : `replay them to ${replayTo}`;
57
+ return `Agent ${socketPath} (a coding agent on this machine can read the exchanges your teammate allowed for agents with --allow-agents, and ${replay}; exchanges captured without it stay closed)`;
58
+ }
59
+ /** The line of a tunnel whose agent socket of the default could not open: it runs without one. */
60
+ export function agentOffLine(problem) {
61
+ return `Agent off: ${problem}`;
51
62
  }
52
63
  /**
53
64
  * One line per exchange: METHOD path status duration. Method and path of a
package/dist/serve.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { once } from 'node:events';
2
2
  import { fileURLToPath } from 'node:url';
3
- import { errorCode, listenError } from './errors.js';
3
+ import { HopwireError, errorCode, listenError } from './errors.js';
4
4
  import { loadOrCreateIdentity } from './identity.js';
5
5
  import { startAgentSocket } from './agent-socket.js';
6
6
  import { createInspectorApi } from './inspector-api.js';
@@ -45,6 +45,7 @@ export async function startServing(options) {
45
45
  target: service.target,
46
46
  serviceName: service.name,
47
47
  log,
48
+ allowAgents: options.share && options.allowAgents === true,
48
49
  onExchange: options.onExchange,
49
50
  onLogError: () => {
50
51
  if (!storeClosing) {
@@ -169,7 +170,10 @@ export async function startServing(options) {
169
170
  };
170
171
  let inspectorUrl = null;
171
172
  let agentSocket = null;
172
- if (options.inspectPort !== null || options.agent === true) {
173
+ let agentProblem = null;
174
+ // Windows has no Unix socket: by default its tunnels simply run without one
175
+ const agent = options.agent ?? (process.platform === 'win32' ? false : 'default');
176
+ if (options.inspectPort !== null || agent !== false) {
173
177
  proceed();
174
178
  // One API for both listeners: the same streams, the same replays
175
179
  const api = createInspectorApi({
@@ -191,11 +195,20 @@ export async function startServing(options) {
191
195
  supervisor.add('servers', () => inspector.close());
192
196
  inspectorUrl = inspector.url;
193
197
  }
194
- if (options.agent === true) {
198
+ if (agent !== false) {
195
199
  proceed();
196
- const socket = await startAgentSocket(api, options.dataDir);
197
- supervisor.add('servers', () => socket.close());
198
- agentSocket = socket.path;
200
+ try {
201
+ const socket = await startAgentSocket(api, options.dataDir);
202
+ supervisor.add('servers', () => socket.close());
203
+ agentSocket = socket.path;
204
+ }
205
+ catch (error) {
206
+ // Asked for, a socket that cannot open stops the start; by default the tunnel runs without it
207
+ if (agent === true || !(error instanceof HopwireError)) {
208
+ throw error;
209
+ }
210
+ agentProblem = error.message;
211
+ }
199
212
  }
200
213
  }
201
214
  // Stopped at the last step: nothing is reported as running
@@ -204,6 +217,7 @@ export async function startServing(options) {
204
217
  services,
205
218
  inspectorUrl,
206
219
  agentSocket,
220
+ agentProblem,
207
221
  logKey: log.key,
208
222
  logLength: log.length,
209
223
  peerKey,
@@ -15,6 +15,11 @@ export interface CapturedExchange {
15
15
  source: ExchangeSource;
16
16
  /** Id of the exchange a replay was made from; only set when the source is `replay` */
17
17
  replayOf?: string;
18
+ /**
19
+ * Set by a sharer started with --allow-agents (spec decision 140): a teammate's coding agent may read this
20
+ * exchange (hopwire watch --agent). Never false: absent means not allowed. CLIs before 0.1.5 ignore it
21
+ */
22
+ agents?: true;
18
23
  request: {
19
24
  method: string;
20
25
  /** Path including the query string */
@@ -31,7 +31,7 @@ export function isCapturedExchange(value) {
31
31
  if (!isRecord(value)) {
32
32
  return false;
33
33
  }
34
- const { id, timestamp, serviceName, source, replayOf, request, response } = value;
34
+ const { id, timestamp, serviceName, source, replayOf, agents, request, response } = value;
35
35
  return (typeof id === 'string' &&
36
36
  id !== '' &&
37
37
  id.length <= CAPTURED_ID_MAX_LENGTH &&
@@ -41,6 +41,7 @@ export function isCapturedExchange(value) {
41
41
  serviceName.length <= CAPTURED_SERVICE_NAME_MAX_LENGTH &&
42
42
  EXCHANGE_SOURCES.some((known) => known === source) &&
43
43
  (replayOf === undefined || (typeof replayOf === 'string' && replayOf.length <= CAPTURED_ID_MAX_LENGTH)) &&
44
+ (agents === undefined || agents === true) &&
44
45
  isRecord(request) &&
45
46
  typeof request.method === 'string' &&
46
47
  request.method.length <= CAPTURED_METHOD_MAX_LENGTH &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hopwire",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Record, share and replay the HTTP traffic of your local services: private P2P sharing with teammates, and public HTTPS URLs.",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://hopwire.to",