@openagt/dashboard 0.10.0 → 0.11.0

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 (170) hide show
  1. package/README.md +1 -6
  2. package/dist/built-in.d.ts +8 -1
  3. package/dist/built-in.d.ts.map +1 -1
  4. package/dist/built-in.js +12 -3
  5. package/dist/built-in.js.map +1 -1
  6. package/dist/cli.d.ts +4 -10
  7. package/dist/cli.d.ts.map +1 -1
  8. package/dist/cli.js +11 -67
  9. package/dist/cli.js.map +1 -1
  10. package/dist/client.d.ts +2 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js +3 -4
  13. package/dist/client.js.map +1 -1
  14. package/dist/daemon-runtime.d.ts +12 -12
  15. package/dist/daemon-runtime.d.ts.map +1 -1
  16. package/dist/daemon-runtime.js +96 -35
  17. package/dist/daemon-runtime.js.map +1 -1
  18. package/dist/daemon.d.ts +3 -14
  19. package/dist/daemon.d.ts.map +1 -1
  20. package/dist/daemon.js +15 -26
  21. package/dist/daemon.js.map +1 -1
  22. package/dist/dashboard/bridge-endpoints.d.ts +5 -5
  23. package/dist/dashboard/bridge-endpoints.js +5 -5
  24. package/dist/dashboard/http.d.ts +1 -1
  25. package/dist/dashboard/http.js +1 -1
  26. package/dist/dashboard/machine-call.d.ts +10 -0
  27. package/dist/dashboard/machine-call.d.ts.map +1 -0
  28. package/dist/dashboard/machine-call.js +86 -0
  29. package/dist/dashboard/machine-call.js.map +1 -0
  30. package/dist/dashboard/relay-endpoints.d.ts +26 -17
  31. package/dist/dashboard/relay-endpoints.d.ts.map +1 -1
  32. package/dist/dashboard/relay-endpoints.js +70 -27
  33. package/dist/dashboard/relay-endpoints.js.map +1 -1
  34. package/dist/dashboard/remote-run.d.ts +77 -32
  35. package/dist/dashboard/remote-run.d.ts.map +1 -1
  36. package/dist/dashboard/remote-run.js +120 -42
  37. package/dist/dashboard/remote-run.js.map +1 -1
  38. package/dist/dashboard/rpc-serve.d.ts +19 -25
  39. package/dist/dashboard/rpc-serve.d.ts.map +1 -1
  40. package/dist/dashboard/rpc-serve.js +11 -22
  41. package/dist/dashboard/rpc-serve.js.map +1 -1
  42. package/dist/dashboard/screen.d.ts +53 -0
  43. package/dist/dashboard/screen.d.ts.map +1 -0
  44. package/dist/dashboard/screen.js +175 -0
  45. package/dist/dashboard/screen.js.map +1 -0
  46. package/dist/dashboard/server.d.ts +18 -19
  47. package/dist/dashboard/server.d.ts.map +1 -1
  48. package/dist/dashboard/server.js +52 -81
  49. package/dist/dashboard/server.js.map +1 -1
  50. package/dist/dashboard/types.d.ts +6 -14
  51. package/dist/dashboard/types.d.ts.map +1 -1
  52. package/dist/dashboard/web-start-endpoints.d.ts +2 -2
  53. package/dist/dashboard/web-start-endpoints.js +1 -1
  54. package/dist/dashboard-bundle/assets/main-9Xb8Ao4p.css +2 -0
  55. package/dist/dashboard-bundle/assets/main-DTyyQ0jM.js +140 -0
  56. package/dist/dashboard-bundle/assets/{module-gKz-ZvkG.js → module-DKd-4BTU.js} +4 -4
  57. package/dist/dashboard-bundle/host/module.js +1 -1
  58. package/dist/dashboard-bundle/index.html +3 -3
  59. package/dist/dashboard-rpc/context.d.ts +4 -4
  60. package/dist/dashboard-rpc/context.js +5 -5
  61. package/dist/dashboard-rpc/context.js.map +1 -1
  62. package/dist/dashboard-rpc/control.d.ts +1 -1
  63. package/dist/dashboard-rpc/control.js +7 -7
  64. package/dist/dashboard-rpc/control.js.map +1 -1
  65. package/dist/dashboard-rpc/events.d.ts +1 -1
  66. package/dist/dashboard-rpc/events.js +1 -1
  67. package/dist/dashboard-rpc/index.d.ts +1 -1
  68. package/dist/dashboard-rpc/index.d.ts.map +1 -1
  69. package/dist/dashboard-rpc/index.js +3 -3
  70. package/dist/dashboard-rpc/index.js.map +1 -1
  71. package/dist/dashboard-rpc/machines.d.ts +52 -0
  72. package/dist/dashboard-rpc/machines.d.ts.map +1 -0
  73. package/dist/dashboard-rpc/machines.js +82 -0
  74. package/dist/dashboard-rpc/machines.js.map +1 -0
  75. package/dist/dashboard-rpc/modules.d.ts +1 -1
  76. package/dist/dashboard-rpc/modules.js +2 -2
  77. package/dist/dashboard-rpc/modules.js.map +1 -1
  78. package/dist/dashboard-rpc/projects.d.ts +2 -0
  79. package/dist/dashboard-rpc/projects.d.ts.map +1 -1
  80. package/dist/dashboard-rpc/projects.js +3 -2
  81. package/dist/dashboard-rpc/projects.js.map +1 -1
  82. package/dist/dashboard-rpc/reads.d.ts +3 -4
  83. package/dist/dashboard-rpc/reads.d.ts.map +1 -1
  84. package/dist/dashboard-rpc/reads.js +5 -6
  85. package/dist/dashboard-rpc/reads.js.map +1 -1
  86. package/dist/dashboard-rpc/relay-agent.d.ts +3 -3
  87. package/dist/dashboard-rpc/relay-agent.js +3 -3
  88. package/dist/dashboard-rpc/relay-dispatch.d.ts +4 -4
  89. package/dist/dashboard-rpc/relay-dispatch.d.ts.map +1 -1
  90. package/dist/dashboard-rpc/relay-dispatch.js +7 -7
  91. package/dist/dashboard-rpc/relay-dispatch.js.map +1 -1
  92. package/dist/dashboard-rpc/test-context.js +1 -1
  93. package/dist/dashboard-rpc/test-context.js.map +1 -1
  94. package/dist/events.d.ts +4 -3
  95. package/dist/events.d.ts.map +1 -1
  96. package/dist/loopback-host.d.ts +3 -5
  97. package/dist/loopback-host.d.ts.map +1 -1
  98. package/dist/loopback-host.js +3 -5
  99. package/dist/loopback-host.js.map +1 -1
  100. package/dist/machine-link.d.ts +21 -0
  101. package/dist/machine-link.d.ts.map +1 -0
  102. package/dist/machine-link.js +20 -0
  103. package/dist/machine-link.js.map +1 -0
  104. package/dist/module-server.d.ts +1 -1
  105. package/dist/module-types/dashboard/lib/draft-handoff.d.ts +5 -9
  106. package/dist/module-types/dashboard/module/index.d.ts +45 -0
  107. package/dist/module-types/src/built-in.d.ts +8 -1
  108. package/dist/module-types/src/client.d.ts +2 -1
  109. package/dist/module-types/src/dashboard/bridge-endpoints.d.ts +5 -5
  110. package/dist/module-types/src/dashboard/http.d.ts +1 -1
  111. package/dist/module-types/src/dashboard/machine-call.d.ts +9 -0
  112. package/dist/module-types/src/dashboard/remote-run.d.ts +77 -32
  113. package/dist/module-types/src/dashboard/rpc-serve.d.ts +19 -25
  114. package/dist/module-types/src/dashboard/types.d.ts +6 -14
  115. package/dist/module-types/src/dashboard-rpc/context.d.ts +4 -4
  116. package/dist/module-types/src/dashboard-rpc/control.d.ts +1 -1
  117. package/dist/module-types/src/dashboard-rpc/events.d.ts +1 -1
  118. package/dist/module-types/src/dashboard-rpc/index.d.ts +1 -1
  119. package/dist/module-types/src/dashboard-rpc/machines.d.ts +51 -0
  120. package/dist/module-types/src/dashboard-rpc/modules.d.ts +1 -1
  121. package/dist/module-types/src/dashboard-rpc/projects.d.ts +2 -0
  122. package/dist/module-types/src/dashboard-rpc/reads.d.ts +3 -4
  123. package/dist/module-types/src/dashboard-rpc/relay-agent.d.ts +3 -3
  124. package/dist/module-types/src/events.d.ts +4 -3
  125. package/dist/module-types/src/loopback-host.d.ts +3 -5
  126. package/dist/module-types/src/machine-link.d.ts +20 -0
  127. package/dist/module-types/src/registry.d.ts +59 -16
  128. package/dist/module-types/src/repository-address.d.ts +22 -0
  129. package/dist/module-types/src/screens.d.ts +13 -0
  130. package/dist/module-types/src/store/agent-store.d.ts +2 -2
  131. package/dist/module-types/src/version.d.ts +1 -0
  132. package/dist/package-services.d.ts +27 -0
  133. package/dist/package-services.d.ts.map +1 -0
  134. package/dist/package-services.js +62 -0
  135. package/dist/package-services.js.map +1 -0
  136. package/dist/registry.d.ts +59 -16
  137. package/dist/registry.d.ts.map +1 -1
  138. package/dist/registry.js +91 -20
  139. package/dist/registry.js.map +1 -1
  140. package/dist/repository-address.d.ts +23 -0
  141. package/dist/repository-address.d.ts.map +1 -0
  142. package/dist/repository-address.js +38 -0
  143. package/dist/repository-address.js.map +1 -0
  144. package/dist/screens.d.ts +14 -0
  145. package/dist/screens.d.ts.map +1 -0
  146. package/dist/screens.js +40 -0
  147. package/dist/screens.js.map +1 -0
  148. package/dist/store/agent-store.d.ts +2 -2
  149. package/dist/store/agent-store.d.ts.map +1 -1
  150. package/dist/version.d.ts +2 -0
  151. package/dist/version.d.ts.map +1 -0
  152. package/dist/version.js +26 -0
  153. package/dist/version.js.map +1 -0
  154. package/package.json +13 -10
  155. package/dist/dashboard-bundle/assets/main-Q7JMdMJI.css +0 -2
  156. package/dist/dashboard-bundle/assets/main-fDZWGOub.js +0 -140
  157. package/dist/dashboard-rpc/devices.d.ts +0 -9
  158. package/dist/dashboard-rpc/devices.d.ts.map +0 -1
  159. package/dist/dashboard-rpc/devices.js +0 -12
  160. package/dist/dashboard-rpc/devices.js.map +0 -1
  161. package/dist/install.d.ts +0 -31
  162. package/dist/install.d.ts.map +0 -1
  163. package/dist/install.js +0 -54
  164. package/dist/install.js.map +0 -1
  165. package/dist/module-types/src/dashboard-rpc/devices.d.ts +0 -8
  166. package/dist/module-types/src/openagent-gitignore.d.ts +0 -11
  167. package/dist/openagent-gitignore.d.ts +0 -12
  168. package/dist/openagent-gitignore.d.ts.map +0 -1
  169. package/dist/openagent-gitignore.js +0 -19
  170. package/dist/openagent-gitignore.js.map +0 -1
@@ -1,27 +1,39 @@
1
1
  import { end, readJsonBody, requireGet, sendJson } from './http.js';
2
+ import { passToScreen, screenCallOf } from './screen.js';
3
+ import { isRunId } from '../store/index.js';
4
+ import { openagentVersion } from '../version.js';
2
5
  /**
3
- * The device-side of the remote-agent relay (#1067): the two endpoints a daemon exposes so another
4
- * daemon (holding this device's token) can run a session here and watch it. They live under
5
- * `/_relay`, behind the shared-token guard (#1051) in {@link startDashboard}. The guard admits a matching
6
- * `oa_daemon` cookie without the browser-only `?token=` 302, so a daemon-to-daemon call passes with
7
- * a cookie and a token-less caller is already 401'd before it reaches here.
6
+ * The machine-side of the remote-agent relay (#1067): the endpoints through which another
7
+ * machine's daemon runs a session here and watches it. They live under `/_relay`. This daemon
8
+ * listens on its own computer only: a call from another machine reaches them through whatever
9
+ * this computer opened to the network, which lets in only a machine that holds a key of its own
10
+ * and passes its call on as this computer's own would arrive.
8
11
  *
9
- * - `POST /_relay/start` starts an ordinary local agent and returns its {@link StartAgentResult}. It
10
- * runs in this device's own home checkout (slice 1); which project it targets is a later slice.
11
- * - `GET /_relay/events?run=<id>` streams that agent's events as newline-delimited JSON until it
12
- * ends or the caller disconnects.
13
- * - `GET /_relay/ping` (#1072) a cookie-guarded reachability probe: 200 and an empty body, starts
14
- * nothing. The online/offline status the dashboard shows is the local daemon calling this on each
15
- * saved device with its token; a token-less caller is already 401'd by the shared-token guard (#1051) above.
12
+ * - `POST /_relay/start` starts an ordinary local agent and returns its {@link StartAgentResult}.
13
+ * - `GET /_relay/events?run=<id>&project=<address>` streams that agent's events as
14
+ * newline-delimited JSON until it ends or the caller disconnects.
15
+ * - `GET /_relay/ping` (#1072) a reachability probe: 200 and this OpenAgent's version, starts nothing. The
16
+ * online/offline status the dashboard shows is the local daemon calling this on each saved
17
+ * machine with its key there.
16
18
  * - `POST /_relay/rpc` (#1067 slice 2) runs one whitelisted run-scoped RPC (a read/diff/steer/handoff/
17
- * push/PR) against this device's own checkout for the daemon relaying an agent here, answering {result}.
19
+ * push/PR) against this machine's own checkout for the daemon relaying an agent here, answering {result}.
20
+ * - `GET /_relay/screen/stream?run=<id>&project=<address>` and `POST /_relay/screen/input?…` pass
21
+ * one call on to the live screen of a run here (screen.ts), for the daemon whose person watches it.
22
+ *
23
+ * All but the ping name their project by its repository's address, and work in this machine's own
24
+ * project cloned from it. A call that names none, or one this machine does not have, starts and
25
+ * reads nothing: there is no project a call falls back to.
18
26
  */
19
27
  export const RELAY_PREFIX = '/_relay';
28
+ /** This machine's id for the project a call names, or undefined: no address, or no such project here. */
29
+ async function projectNamed(handlers, address) {
30
+ return typeof address === 'string' && address ? handlers.project(address) : undefined;
31
+ }
20
32
  const MAX_START_BODY = 256 * 1024;
21
33
  /** Route a `/_relay/*` request. A host that wired no relay handlers 404s every relay route. */
22
34
  export async function handleRelayRequest(req, res, pathname, handlers) {
23
- // Ping is a pure reachability + auth probe (#1072): it needs no wired handlers and starts nothing,
24
- // so it answers even on a host that enabled no relay. Reaching here means the cookie already passed.
35
+ // Ping is a pure reachability probe (#1072): it needs no wired handlers and starts nothing,
36
+ // so it answers even on a host that enabled no relay.
25
37
  if (pathname === `${RELAY_PREFIX}/ping`)
26
38
  return handlePing(req, res);
27
39
  if (!handlers)
@@ -32,14 +44,31 @@ export async function handleRelayRequest(req, res, pathname, handlers) {
32
44
  return handleEvents(req, res, handlers);
33
45
  if (pathname === `${RELAY_PREFIX}/rpc`)
34
46
  return handleRpc(req, res, handlers);
47
+ const screenCall = screenCallOf(pathname, `${RELAY_PREFIX}/screen`);
48
+ if (screenCall)
49
+ return handleScreen(req, res, handlers, screenCall);
35
50
  end(res, 404, 'not found');
36
51
  }
37
- /** `GET /_relay/ping` (#1072): answer 200 with an empty body. Starts nothing; only proves this
38
- * daemon is reachable and the caller's cookie is valid (the shared-token guard (#1051) already enforced that). */
52
+ /** `/_relay/screen/<call>?run=<id>&project=<address>`: pass the call on to the run's live screen here. */
53
+ async function handleScreen(req, res, handlers, call) {
54
+ if (!handlers.screen)
55
+ return end(res, 404, 'relay screen not enabled');
56
+ const query = new URL(req.url ?? '/', 'http://localhost').searchParams;
57
+ const agentId = query.get('run');
58
+ if (!agentId || !isRunId(agentId))
59
+ return end(res, 400, 'missing run id');
60
+ const projectId = await projectNamed(handlers, query.get('project')).catch(() => undefined);
61
+ if (projectId === undefined)
62
+ return end(res, 404, 'no such project on this machine');
63
+ await passToScreen(req, res, call, await handlers.screen(projectId, agentId).catch(() => undefined));
64
+ }
65
+ /** `GET /_relay/ping` (#1072): answer 200 with this OpenAgent's version. Starts nothing; it proves this
66
+ * daemon is reachable, and to another machine that its key still lets it in, and tells that
67
+ * machine whether this one fell behind it. */
39
68
  function handlePing(req, res) {
40
69
  if (!requireGet(req, res))
41
70
  return;
42
- end(res, 200, '');
71
+ sendJson(res, { version: openagentVersion() });
43
72
  }
44
73
  /** `POST /_relay/start`: read the agent request, start it locally, and answer with the result JSON. */
45
74
  async function handleStart(req, res, handlers) {
@@ -55,26 +84,37 @@ async function handleStart(req, res, handlers) {
55
84
  const prompt = typeof body.prompt === 'string' ? body.prompt : '';
56
85
  const options = (body.options && typeof body.options === 'object' ? body.options : {});
57
86
  // Never relay onward from a relayed agent: strip any nested target before starting it here.
58
- // And a start relayed to a device never names a branch: the caller's branches are not this machine's.
59
- const { remote: _drop, base: _callers, ...local } = options;
87
+ // And a start relayed to a machine never names a branch: the caller's branches are not this machine's.
88
+ const { machine: _drop, base: _callers, ...local } = options;
60
89
  let result;
61
90
  try {
62
- result = await handlers.start(prompt, local, undefined);
91
+ const projectId = await projectNamed(handlers, body.project);
92
+ result =
93
+ projectId === undefined
94
+ ? { ok: false, error: `no project on this machine is cloned from ${String(body.project)}`, noProject: true }
95
+ : await handlers.start(prompt, local, projectId);
63
96
  }
64
97
  catch (err) {
65
98
  result = { ok: false, error: err instanceof Error ? err.message : String(err) };
66
99
  }
67
100
  sendJson(res, result);
68
101
  }
69
- /** `GET /_relay/events?run=<id>`: stream the agent's events as newline-delimited JSON. */
70
- function handleEvents(req, res, handlers) {
102
+ /** `GET /_relay/events?run=<id>&project=<address>`: stream the agent's events as newline-delimited JSON. */
103
+ async function handleEvents(req, res, handlers) {
71
104
  if (!requireGet(req, res))
72
105
  return;
73
- const agentId = new URL(req.url ?? '/', 'http://localhost').searchParams.get('run');
106
+ const query = new URL(req.url ?? '/', 'http://localhost').searchParams;
107
+ const agentId = query.get('run');
74
108
  if (!agentId)
75
109
  return end(res, 400, 'missing run id');
110
+ const projectId = await projectNamed(handlers, query.get('project')).catch(() => undefined);
111
+ if (projectId === undefined)
112
+ return end(res, 404, 'no such project on this machine');
113
+ // The caller went away while the project was looked up: a tail started now would never be stopped.
114
+ if (res.destroyed || req.socket.destroyed)
115
+ return;
76
116
  res.writeHead(200, { 'content-type': 'application/x-ndjson', 'cache-control': 'no-cache' });
77
- const stop = handlers.tailEvents(agentId, event => {
117
+ const stop = handlers.tailEvents(projectId, agentId, event => {
78
118
  // A dropped write (the caller went away mid-line) must not throw out of the tail callback.
79
119
  try {
80
120
  res.write(`${JSON.stringify(event)}\n`);
@@ -88,7 +128,7 @@ function handleEvents(req, res, handlers) {
88
128
  req.on('close', close);
89
129
  }
90
130
  const MAX_RPC_BODY = 256 * 1024;
91
- /** POST /_relay/rpc: run one whitelisted RPC on this device and answer {result}. */
131
+ /** POST /_relay/rpc: run one whitelisted RPC on this machine and answer {result}. */
92
132
  async function handleRpc(req, res, handlers) {
93
133
  if (req.method !== 'POST')
94
134
  return end(res, 405, 'method not allowed', { allow: 'POST' });
@@ -106,7 +146,10 @@ async function handleRpc(req, res, handlers) {
106
146
  if (!fn)
107
147
  return end(res, 400, 'missing rpc name');
108
148
  try {
109
- sendJson(res, { result: await handlers.rpc(fn, args) });
149
+ const projectId = await projectNamed(handlers, body.project);
150
+ if (projectId === undefined)
151
+ return end(res, 404, 'no such project on this machine');
152
+ sendJson(res, { result: await handlers.rpc(projectId, fn, args) });
110
153
  }
111
154
  catch (err) {
112
155
  end(res, 500, err instanceof Error ? err.message : 'rpc failed');
@@ -1 +1 @@
1
- {"version":3,"file":"relay-endpoints.js","sourceRoot":"","sources":["../../src/dashboard/relay-endpoints.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAE,YAAY,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAA;AAEnE;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,SAAS,CAAA;AAiBrC,MAAM,cAAc,GAAG,GAAG,GAAG,IAAI,CAAA;AAEjC,+FAA+F;AAC/F,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,GAAoB,EACpB,GAAmB,EACnB,QAAgB,EAChB,QAAmC;IAEnC,mGAAmG;IACnG,qGAAqG;IACrG,IAAI,QAAQ,KAAK,GAAG,YAAY,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,SAAS,KAAK,SAAS;YAAE,OAAO,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,iCAAiC,CAAC,CAAA;QACpF,QAAQ,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;IACpE,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,YAAY,CAAC,CAAA;IAClE,CAAC;AACH,CAAC"}
@@ -3,50 +3,90 @@ import type { OpenAgentEvent } from '../events.js';
3
3
  import type { AgentMeta } from '../store/index.js';
4
4
  import type { StartAgentOptions, StartAgentResult } from './types.js';
5
5
  /**
6
- * The server-side half of "run on a connected device" (#1067). The local daemon holds the saved
7
- * device's token, so it - not the browser - drives the remote daemon: it POSTs the agent to the
6
+ * The server-side half of "run on a saved machine" (#1067). The local daemon holds this computer's
7
+ * key on the saved machine, so it - not the browser - drives the remote daemon: it POSTs the agent to the
8
8
  * remote's `/_relay/start` and then fetch-streams the remote's `/_relay/events` back into a local
9
9
  * {@link EventStream}, which the dashboard reads over its normal same-origin `onEvents` channel. So
10
- * the browser never talks cross-origin and the token never leaves the two daemons (issue #1067 (b)).
10
+ * the browser never talks cross-origin and the key never leaves the two daemons (issue #1067 (b)).
11
11
  *
12
- * Authentication is the shared-token cookie (#1051), sent daemon-to-daemon: `Cookie: oa_daemon=<token>` with no
13
- * `Origin` header. The remote's guard admits a matching cookie without the browser-only `?token=`
14
- * 302, and its `/_rpc` CSRF check (absent Origin passes) is not even on these raw routes.
12
+ * Every call but the ping names its project, by its repository's address
13
+ * (repository-address.ts): a project's folder, and so its id, is another one on each machine.
14
+ *
15
+ * The other OpenAgent listens on its own computer only. What answers at a machine's address is
16
+ * whatever that computer opened to the network, which lets this computer in once, with the code
17
+ * a machine's link carries ({@link enterRemote}), answers a key of this computer's own, and from
18
+ * then on passes each call that carries the key (`Authorization: Bearer`, no `Origin`) to its
19
+ * OpenAgent as that computer's own browser would have made it.
15
20
  */
16
- /** Where a relayed agent executes: the remote daemon's origin and its #1051 token. Memory-only. */
17
- export interface RemoteTarget {
21
+ /** How a machine is reached: where its OpenAgent answers, this computer's key there, and what the machine's own key is known by when its link said. */
22
+ export interface MachineAccess {
18
23
  url: string;
19
- token: string;
24
+ key: string;
25
+ pin?: string;
26
+ }
27
+ /** Where a relayed agent works: a machine, and the project there, by its repository's address. */
28
+ export interface RemoteTarget extends MachineAccess {
29
+ project: string;
20
30
  }
21
- /** The body a relay start forwards to the remote's `/_relay/start`. */
31
+ /** What a relay start forwards to the remote's `/_relay/start`, beside the project. */
22
32
  export interface RelayStartBody {
23
33
  prompt: string;
24
34
  options: StartAgentOptions;
25
35
  }
26
36
  /**
27
- * Health-check a saved device (#1072): a cookie'd `GET /_relay/ping`, true on any 2xx, false on a
28
- * non-2xx, an unreachable host, or the timeout. The token stays in memory for the check only, never
29
- * persisted, same as {@link startRemoteAgent}. This is how the browser's status dots learn reachable
30
- * from not: it has the tokens, the daemon does the cross-origin request.
37
+ * What a machine answers a relayed start with: a Start's own outcome, or `noProject` when it has
38
+ * no project cloned from the address the start named.
39
+ */
40
+ export type RelayStartResult = StartAgentResult | {
41
+ ok: false;
42
+ error: string;
43
+ noProject: true;
44
+ };
45
+ /**
46
+ * Health-check a saved machine (#1072): true when it answers this computer's key. This is how
47
+ * the browser's status dots learn reachable from not.
48
+ */
49
+ export declare function pingRemote(target: MachineAccess): Promise<boolean>;
50
+ /** The OpenAgent a saved machine runs, as its ping tells it; nothing for a machine that does not answer, or does not say. */
51
+ export declare function remoteVersion(target: MachineAccess): Promise<string | undefined>;
52
+ /** What asking to be let in came to: this computer's key there, or why not, in words. */
53
+ export type EnterResult = {
54
+ ok: true;
55
+ key: string;
56
+ } | {
57
+ ok: false;
58
+ error: string;
59
+ };
60
+ /**
61
+ * Ask a machine to let this computer in, with the code its link carries, under `name`. The code
62
+ * is good once: a link used before, or older than a few minutes, is refused.
63
+ */
64
+ export declare function enterRemote(door: string, code: string, name: string, pin?: string): Promise<EnterResult>;
65
+ /**
66
+ * Take this computer out of a machine: its key there stops working. Whether the machine did;
67
+ * one that cannot be reached keeps the key until this computer is removed there by hand.
31
68
  */
32
- export declare function pingRemote(target: RemoteTarget): Promise<boolean>;
69
+ export declare function leaveRemote(machine: MachineAccess & {
70
+ door: string;
71
+ }): Promise<boolean>;
33
72
  /**
34
- * Start an agent on the remote daemon and return its {@link StartAgentResult} (with the remote's own run
35
- * id). A non-2xx or a transport failure surfaces as an `ok: false` result the dashboard shows, the
36
- * same shape a local refusal has, so the caller does not special-case remote errors.
73
+ * Start an agent on the remote daemon, in its project cloned from `target.project`, and return
74
+ * what it answered (with the remote's own run id). A non-2xx or a transport failure surfaces as an
75
+ * `ok: false` result the dashboard shows, the same shape a local refusal has, so the caller does
76
+ * not special-case remote errors.
37
77
  */
38
- export declare function startRemoteAgent(target: RemoteTarget, body: RelayStartBody): Promise<StartAgentResult>;
78
+ export declare function startRemoteAgent(target: RemoteTarget, body: RelayStartBody): Promise<RelayStartResult>;
39
79
  /**
40
- * Relay one run-scoped RPC to the device that owns a remote agent (#1067 slice 2). The local daemon
41
- * holds the device token, so a read/diff/handoff/push/PR for a relayed agent runs ON the device: POST
42
- * {fn, args} to the remote's /_relay/rpc over the shared-token cookie (#1051) (no Origin), returning the device's
43
- * result. Throws on an unreachable device or a non-2xx so the caller falls back to its own empty/error
80
+ * Relay one run-scoped RPC to the machine that owns a remote agent (#1067 slice 2). The local daemon
81
+ * holds this computer's key there, so a read/diff/handoff/push/PR for a relayed agent runs ON the machine: POST
82
+ * {fn, args} to the remote's /_relay/rpc with the key (no Origin), returning the machine's
83
+ * result. Throws on an unreachable machine or a non-2xx so the caller falls back to its own empty/error
44
84
  * shape, the same way a failed local read does.
45
85
  */
46
86
  export declare function relayRpc(target: RemoteTarget, fn: string, args: unknown[]): Promise<unknown>;
47
87
  /**
48
88
  * Fetch-stream a remote agent's newline-delimited events into `onEvent` until the remote closes the
49
- * body, the agent ends, or `cancel()` is called. A 401 (the token was rotated) ends the stream
89
+ * body, the agent ends, or `cancel()` is called. A 401 (this computer was removed there) ends the stream
50
90
  * cleanly rather than as an error, so the dashboard sees a normal `done`, not a lost connection.
51
91
  * Returns a cancel function; calling it aborts the fetch and releases the reader.
52
92
  */
@@ -54,11 +94,12 @@ export declare function streamRemoteEvents(target: RemoteTarget, agentId: string
54
94
  /**
55
95
  * The local daemon's live relayed runs (#1067), keyed by the remote agent id. Registering an agent opens
56
96
  * an {@link EventStream} the dashboard reads through `onEvents`, fed by {@link streamRemoteEvents}
57
- * from the remote. This map is where a saved device's token lives daemon-side: in memory, for the
58
- * run's lifetime.
97
+ * from the remote. The target is the saved machine as it was at the Start. A machine is not
98
+ * removed while a run is at work on it ({@link working}); the runs that ended there before it
99
+ * was removed read as unreachable, and one added again answers for them with its new key ({@link rekey}).
59
100
  *
60
101
  * The `targets` map outlives the event pump (#1067 slice 2): a finished remote agent's post-run reads,
61
- * open-PR and merge still have to reach the device after its event stream has ended, so the device
102
+ * open-PR and merge still have to reach the machine after its event stream has ended, so the machine
62
103
  * target is kept until {@link dispose} clears it, not dropped when the stream closes.
63
104
  *
64
105
  * The `metas` map (#1077) holds a local {@link AgentMeta} stub per relayed agent so `onAgents` can show a
@@ -73,22 +114,26 @@ export declare class RelayedAgents {
73
114
  register(agentId: string, target: RemoteTarget, meta: AgentMeta, projectId: string): void;
74
115
  /** The live event stream for a relayed agent, or undefined when this daemon is not relaying it. */
75
116
  get(agentId: string | undefined): EventStream<OpenAgentEvent> | undefined;
76
- /** The device a relayed agent runs on, kept past the event stream so post-run push/PR still reach it. */
117
+ /** The machine a relayed agent runs on, kept past the event stream so post-run push/PR still reach it. */
77
118
  target(agentId: string | undefined): RemoteTarget | undefined;
119
+ /** Whether a run this daemon follows is still at work on the machine at `url`: its events still stream. */
120
+ working(url: string): boolean;
121
+ /** How the machine at `url` is reached since it was added again, for the runs kept from before: this computer's new key there, and the key the machine is known by. */
122
+ rekey(url: string, key: string, pin?: string): void;
78
123
  /** A project's relayed run stubs (#1077), newest-first, so `onAgents` can surface them in the list. */
79
124
  list(projectId: string): AgentMeta[];
80
125
  /** Fold each relayed event into the agent's list row via the store's own reducer (#1077), so the
81
- * local stub mirrors the device: the terminal status on `end`, the waiting flag while it is parked
126
+ * local stub mirrors the machine: the terminal status on `end`, the waiting flag while it is parked
82
127
  * (#785), the driver once its session starts. Events carry no write time, so this stamps its own. */
83
128
  private apply;
84
129
  /** Close a relayed agent's event stream (not its target). Idempotent. */
85
130
  private endStream;
86
- /** Stop every pump, close every stream, and forget every device target + list stub, on daemon shutdown. */
131
+ /** Stop every pump, close every stream, and forget every machine target + list stub, on daemon shutdown. */
87
132
  dispose(): void;
88
133
  }
89
134
  /**
90
- * Fold one relayed event into the memory-only row of a run on a device: what the device's own
91
- * card would say, kept here because that card is on the device. The events are the ones a run's
135
+ * Fold one relayed event into the memory-only row of a run on a machine: what the machine's own
136
+ * card would say, kept here because that card is on the machine. The events are the ones a run's
92
137
  * diary yields: the agent's session id, its cost, its end.
93
138
  */
94
139
  export declare function foldRelayedEvent(meta: AgentMeta, event: OpenAgentEvent, at: string): AgentMeta;
@@ -1 +1 @@
1
- {"version":3,"file":"remote-run.d.ts","sourceRoot":"","sources":["../../src/dashboard/remote-run.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAChD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAClD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAGrE;;;;;;;;;;GAUG;AAEH,mGAAmG;AACnG,MAAM,WAAW,YAAY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,QAAQ,CAAC,MAAM,CAAkC;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAkC;IAG1D,OAAO,CAAC,QAAQ,CAAC,KAAK,CAA4D;IAElF,4FAA4F;IAC5F,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI,CAUxF;IAED,mGAAmG;IACnG,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,WAAW,CAAC,cAAc,CAAC,GAAG,SAAS,CAExE;IAED,0GAA0G;IAC1G,MAAM,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,YAAY,GAAG,SAAS,CAE5D;IAED,2GAA2G;IAC3G,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAG5B;IAED,uKAAuK;IACvK,KAAK,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,CAIlD;IAED,uGAAuG;IACvG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,EAAE,CAKnC;IAED;;0GAEsG;IACtG,OAAO,CAAC,KAAK;IAMb,yEAAyE;IACzE,OAAO,CAAC,SAAS;IAUjB,4GAA4G;IAC5G,OAAO,IAAI,IAAI,CAQd;CACF;AAOD;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,GAAG,SAAS,CAS9F"}
@@ -1,74 +1,137 @@
1
1
  import { EventStream } from '../event-stream.js';
2
2
  import { errorMessage } from '../error-message.js';
3
+ import { machineFetch } from './machine-call.js';
3
4
  const START_TIMEOUT_MS = 15_000;
4
- /** How long a status ping waits before calling a device offline (#1072): short, since it polls. */
5
+ /** How long a status ping waits before calling a machine offline (#1072): short, since it polls. */
5
6
  const PING_TIMEOUT_MS = 3_000;
7
+ /** One `GET /_relay/ping` with this computer's key: the answer when it is a 2xx, else nothing (the key no longer lets in, the host is unreachable, the time is up). */
8
+ async function ping(target) {
9
+ try {
10
+ const res = await machineFetch(`${trimSlashes(target.url)}/_relay/ping`, target.pin, {
11
+ headers: { authorization: `Bearer ${target.key}` },
12
+ signal: AbortSignal.timeout(PING_TIMEOUT_MS),
13
+ });
14
+ return res.ok ? res : undefined;
15
+ }
16
+ catch {
17
+ return undefined;
18
+ }
19
+ }
6
20
  /**
7
- * Health-check a saved device (#1072): a cookie'd `GET /_relay/ping`, true on any 2xx, false on a
8
- * non-2xx, an unreachable host, or the timeout. The token stays in memory for the check only, never
9
- * persisted, same as {@link startRemoteAgent}. This is how the browser's status dots learn reachable
10
- * from not: it has the tokens, the daemon does the cross-origin request.
21
+ * Health-check a saved machine (#1072): true when it answers this computer's key. This is how
22
+ * the browser's status dots learn reachable from not.
11
23
  */
12
24
  export async function pingRemote(target) {
25
+ return (await ping(target)) !== undefined;
26
+ }
27
+ /** The OpenAgent a saved machine runs, as its ping tells it; nothing for a machine that does not answer, or does not say. */
28
+ export async function remoteVersion(target) {
29
+ const said = await (await ping(target))?.json().catch(() => undefined);
30
+ const version = said && typeof said === 'object' ? said.version : undefined;
31
+ // What a machine says is shown on a page: only what reads as a version is one.
32
+ return typeof version === 'string' && /^[0-9A-Za-z.+-]{1,64}$/.test(version) ? version : undefined;
33
+ }
34
+ /** The two headers every relay request carries: JSON, and this computer's key there. No Origin on purpose. */
35
+ function relayHeaders(key) {
36
+ return { 'content-type': 'application/json', authorization: `Bearer ${key}` };
37
+ }
38
+ /** What a machine says when this computer's key no longer lets it in: it was removed there. */
39
+ const NOT_IN = 'this computer is no longer in on the machine: add the machine again, with a new link';
40
+ const ENTER_TIMEOUT_MS = 10_000;
41
+ /** How long a machine gets to take this computer out: it is not waited for by a person. */
42
+ const LEAVE_TIMEOUT_MS = 5_000;
43
+ /** What a machine answers to a code that was used before or is too old. */
44
+ const CODE_SPENT = 'this code no longer works';
45
+ /**
46
+ * Ask a machine to let this computer in, with the code its link carries, under `name`. The code
47
+ * is good once: a link used before, or older than a few minutes, is refused.
48
+ */
49
+ export async function enterRemote(door, code, name, pin) {
50
+ let res;
13
51
  try {
14
- const res = await fetch(`${trimSlashes(target.url)}/_relay/ping`, {
15
- headers: { cookie: `oa_daemon=${target.token}` },
16
- signal: AbortSignal.timeout(PING_TIMEOUT_MS),
52
+ res = await machineFetch(door, pin, {
53
+ method: 'POST',
54
+ headers: { 'content-type': 'application/json' },
55
+ body: JSON.stringify({ code, computer: name }),
56
+ signal: AbortSignal.timeout(ENTER_TIMEOUT_MS),
17
57
  });
58
+ }
59
+ catch (err) {
60
+ return { ok: false, error: `The machine did not answer: ${errorMessage(err)}` };
61
+ }
62
+ if (res.status === 403) {
63
+ // The machine says why in words: a link that was used is one reason among others (this
64
+ // computer is on another network than the machine, the machine's list is full).
65
+ const why = (await res.text().catch(() => '')).trim().slice(0, 200);
66
+ if (why === CODE_SPENT)
67
+ return { ok: false, error: 'This link no longer works. A link works once, and for a short time: make a new one on the other machine.' };
68
+ return { ok: false, error: why ? `The machine refused: ${why}.` : 'The machine refused.' };
69
+ }
70
+ if (!res.ok)
71
+ return { ok: false, error: `The machine refused (${res.status}).` };
72
+ const key = await res.json().then(body => body?.key, () => undefined);
73
+ return typeof key === 'string' && key ? { ok: true, key } : { ok: false, error: 'What answered at this link is not an OpenAgent that lets a machine in.' };
74
+ }
75
+ /**
76
+ * Take this computer out of a machine: its key there stops working. Whether the machine did;
77
+ * one that cannot be reached keeps the key until this computer is removed there by hand.
78
+ */
79
+ export async function leaveRemote(machine) {
80
+ try {
81
+ const res = await machineFetch(machine.door, machine.pin, { method: 'DELETE', headers: { authorization: `Bearer ${machine.key}` }, signal: AbortSignal.timeout(LEAVE_TIMEOUT_MS) });
18
82
  return res.ok;
19
83
  }
20
84
  catch {
21
85
  return false;
22
86
  }
23
87
  }
24
- /** The two headers every relay request carries: JSON, and the shared-token cookie (#1051). No Origin on purpose. */
25
- function relayHeaders(token) {
26
- return { 'content-type': 'application/json', cookie: `oa_daemon=${token}` };
27
- }
28
88
  /**
29
- * Start an agent on the remote daemon and return its {@link StartAgentResult} (with the remote's own run
30
- * id). A non-2xx or a transport failure surfaces as an `ok: false` result the dashboard shows, the
31
- * same shape a local refusal has, so the caller does not special-case remote errors.
89
+ * Start an agent on the remote daemon, in its project cloned from `target.project`, and return
90
+ * what it answered (with the remote's own run id). A non-2xx or a transport failure surfaces as an
91
+ * `ok: false` result the dashboard shows, the same shape a local refusal has, so the caller does
92
+ * not special-case remote errors.
32
93
  */
33
94
  export async function startRemoteAgent(target, body) {
34
95
  try {
35
- const res = await fetch(`${trimSlashes(target.url)}/_relay/start`, {
96
+ const res = await machineFetch(`${trimSlashes(target.url)}/_relay/start`, target.pin, {
36
97
  method: 'POST',
37
- headers: relayHeaders(target.token),
38
- body: JSON.stringify(body),
98
+ headers: relayHeaders(target.key),
99
+ body: JSON.stringify({ ...body, project: target.project }),
39
100
  signal: AbortSignal.timeout(START_TIMEOUT_MS),
40
101
  });
102
+ if (res.status === 401)
103
+ return { ok: false, error: NOT_IN };
41
104
  if (!res.ok)
42
- return { ok: false, error: `the device refused the run (${res.status})` };
105
+ return { ok: false, error: `the machine refused the run (${res.status})` };
43
106
  return (await res.json());
44
107
  }
45
108
  catch (err) {
46
- return { ok: false, error: `could not reach the device: ${errorMessage(err)}` };
109
+ return { ok: false, error: `could not reach the machine: ${errorMessage(err)}` };
47
110
  }
48
111
  }
49
- const RPC_TIMEOUT_MS = 60_000; // a relayed git push/PR runs over the network on the device
112
+ const RPC_TIMEOUT_MS = 60_000; // a relayed git push/PR runs over the network on the machine
50
113
  /**
51
- * Relay one run-scoped RPC to the device that owns a remote agent (#1067 slice 2). The local daemon
52
- * holds the device token, so a read/diff/handoff/push/PR for a relayed agent runs ON the device: POST
53
- * {fn, args} to the remote's /_relay/rpc over the shared-token cookie (#1051) (no Origin), returning the device's
54
- * result. Throws on an unreachable device or a non-2xx so the caller falls back to its own empty/error
114
+ * Relay one run-scoped RPC to the machine that owns a remote agent (#1067 slice 2). The local daemon
115
+ * holds this computer's key there, so a read/diff/handoff/push/PR for a relayed agent runs ON the machine: POST
116
+ * {fn, args} to the remote's /_relay/rpc with the key (no Origin), returning the machine's
117
+ * result. Throws on an unreachable machine or a non-2xx so the caller falls back to its own empty/error
55
118
  * shape, the same way a failed local read does.
56
119
  */
57
120
  export async function relayRpc(target, fn, args) {
58
- const res = await fetch(`${trimSlashes(target.url)}/_relay/rpc`, {
121
+ const res = await machineFetch(`${trimSlashes(target.url)}/_relay/rpc`, target.pin, {
59
122
  method: 'POST',
60
- headers: relayHeaders(target.token),
61
- body: JSON.stringify({ fn, args }),
123
+ headers: relayHeaders(target.key),
124
+ body: JSON.stringify({ fn, args, project: target.project }),
62
125
  signal: AbortSignal.timeout(RPC_TIMEOUT_MS),
63
126
  });
64
127
  if (!res.ok)
65
- throw new Error(`the device refused the request (${res.status})`);
128
+ throw new Error(`the machine refused the request (${res.status})`);
66
129
  const body = (await res.json());
67
130
  return body.result;
68
131
  }
69
132
  /**
70
133
  * Fetch-stream a remote agent's newline-delimited events into `onEvent` until the remote closes the
71
- * body, the agent ends, or `cancel()` is called. A 401 (the token was rotated) ends the stream
134
+ * body, the agent ends, or `cancel()` is called. A 401 (this computer was removed there) ends the stream
72
135
  * cleanly rather than as an error, so the dashboard sees a normal `done`, not a lost connection.
73
136
  * Returns a cancel function; calling it aborts the fetch and releases the reader.
74
137
  */
@@ -83,9 +146,9 @@ export function streamRemoteEvents(target, agentId, onEvent, onEnd) {
83
146
  };
84
147
  void (async () => {
85
148
  try {
86
- const url = `${trimSlashes(target.url)}/_relay/events?run=${encodeURIComponent(agentId)}`;
87
- const res = await fetch(url, { headers: relayHeaders(target.token), signal: controller.signal });
88
- // 401 = the device rotated its token. Nothing more will stream; end cleanly (a done, not a loss).
149
+ const url = `${trimSlashes(target.url)}/_relay/events?run=${encodeURIComponent(agentId)}&project=${encodeURIComponent(target.project)}`;
150
+ const res = await machineFetch(url, target.pin, { headers: relayHeaders(target.key), signal: controller.signal });
151
+ // 401 = this computer was removed on the machine. Nothing more will stream; end cleanly (a done, not a loss).
89
152
  if (!res.ok || !res.body)
90
153
  return end();
91
154
  const reader = res.body.getReader();
@@ -133,11 +196,12 @@ function emitLine(line, onEvent) {
133
196
  /**
134
197
  * The local daemon's live relayed runs (#1067), keyed by the remote agent id. Registering an agent opens
135
198
  * an {@link EventStream} the dashboard reads through `onEvents`, fed by {@link streamRemoteEvents}
136
- * from the remote. This map is where a saved device's token lives daemon-side: in memory, for the
137
- * run's lifetime.
199
+ * from the remote. The target is the saved machine as it was at the Start. A machine is not
200
+ * removed while a run is at work on it ({@link working}); the runs that ended there before it
201
+ * was removed read as unreachable, and one added again answers for them with its new key ({@link rekey}).
138
202
  *
139
203
  * The `targets` map outlives the event pump (#1067 slice 2): a finished remote agent's post-run reads,
140
- * open-PR and merge still have to reach the device after its event stream has ended, so the device
204
+ * open-PR and merge still have to reach the machine after its event stream has ended, so the machine
141
205
  * target is kept until {@link dispose} clears it, not dropped when the stream closes.
142
206
  *
143
207
  * The `metas` map (#1077) holds a local {@link AgentMeta} stub per relayed agent so `onAgents` can show a
@@ -158,7 +222,7 @@ export class RelayedAgents {
158
222
  const stream = new EventStream();
159
223
  const cancel = streamRemoteEvents(target, agentId, event => {
160
224
  stream.push(event);
161
- this.apply(agentId, event); // fold the event into the run's list row, mirroring the device
225
+ this.apply(agentId, event); // fold the event into the run's list row, mirroring the machine
162
226
  }, () => this.endStream(agentId));
163
227
  this.agents.set(agentId, { target, stream, cancel });
164
228
  }
@@ -166,10 +230,24 @@ export class RelayedAgents {
166
230
  get(agentId) {
167
231
  return agentId ? this.agents.get(agentId)?.stream : undefined;
168
232
  }
169
- /** The device a relayed agent runs on, kept past the event stream so post-run push/PR still reach it. */
233
+ /** The machine a relayed agent runs on, kept past the event stream so post-run push/PR still reach it. */
170
234
  target(agentId) {
171
235
  return agentId ? this.targets.get(agentId) : undefined;
172
236
  }
237
+ /** Whether a run this daemon follows is still at work on the machine at `url`: its events still stream. */
238
+ working(url) {
239
+ for (const agent of this.agents.values())
240
+ if (agent.target.url === url)
241
+ return true;
242
+ return false;
243
+ }
244
+ /** How the machine at `url` is reached since it was added again, for the runs kept from before: this computer's new key there, and the key the machine is known by. */
245
+ rekey(url, key, pin) {
246
+ for (const [agentId, target] of this.targets) {
247
+ if (target.url === url)
248
+ this.targets.set(agentId, { url, key, ...(pin ? { pin } : {}), project: target.project });
249
+ }
250
+ }
173
251
  /** A project's relayed run stubs (#1077), newest-first, so `onAgents` can surface them in the list. */
174
252
  list(projectId) {
175
253
  const rows = [];
@@ -180,7 +258,7 @@ export class RelayedAgents {
180
258
  return rows.sort((a, b) => (a.startedAt < b.startedAt ? 1 : a.startedAt > b.startedAt ? -1 : 0));
181
259
  }
182
260
  /** Fold each relayed event into the agent's list row via the store's own reducer (#1077), so the
183
- * local stub mirrors the device: the terminal status on `end`, the waiting flag while it is parked
261
+ * local stub mirrors the machine: the terminal status on `end`, the waiting flag while it is parked
184
262
  * (#785), the driver once its session starts. Events carry no write time, so this stamps its own. */
185
263
  apply(agentId, event) {
186
264
  const entry = this.metas.get(agentId);
@@ -200,7 +278,7 @@ export class RelayedAgents {
200
278
  if (entry && entry.meta.status === 'running')
201
279
  entry.meta.status = 'stopped';
202
280
  }
203
- /** Stop every pump, close every stream, and forget every device target + list stub, on daemon shutdown. */
281
+ /** Stop every pump, close every stream, and forget every machine target + list stub, on daemon shutdown. */
204
282
  dispose() {
205
283
  for (const [agentId, agent] of this.agents) {
206
284
  agent.cancel();
@@ -216,8 +294,8 @@ function trimSlashes(url) {
216
294
  return url.replace(/\/+$/, '');
217
295
  }
218
296
  /**
219
- * Fold one relayed event into the memory-only row of a run on a device: what the device's own
220
- * card would say, kept here because that card is on the device. The events are the ones a run's
297
+ * Fold one relayed event into the memory-only row of a run on a machine: what the machine's own
298
+ * card would say, kept here because that card is on the machine. The events are the ones a run's
221
299
  * diary yields: the agent's session id, its cost, its end.
222
300
  */
223
301
  export function foldRelayedEvent(meta, event, at) {