@johnhenry/browsermesh-apps 0.11.0 → 0.12.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.
@@ -1,9 +1,13 @@
1
1
  /**
2
2
  * mesh-orchestrator-tools.mjs -- Phase 4 of the agent-runtime plan (issues
3
- * #90/#92): registers `orchestrator.mjs`'s 8 real `Meshctl*Tool` classes
3
+ * #90/#92): registers `orchestrator.mjs`'s 15 real `Meshctl*Tool` classes
4
4
  * (`MeshctlPodsTool`/`MeshctlStatusTool`/`MeshctlExecTool`/`MeshctlDeployTool`/
5
5
  * `MeshctlTopTool`/`MeshctlComputeTool`/`MeshctlExposeTool`/`MeshctlDrainTool`,
6
- * built via that file's own `createMeshctlTools(orchestrator)` helper) into a
6
+ * plus issue #185 §8a item 4's hosted-pods control surface five --
7
+ * `MeshctlSpawnTool`/`MeshctlSnapshotTool`/`MeshctlRestoreTool`/
8
+ * `MeshctlHostedPodsTool`/`MeshctlHostsTool` -- plus item 6's supervisor two
9
+ * -- `MeshctlSuperviseTool`/`MeshctlSupervisedTool` -- built via that file's
10
+ * own `createMeshctlTools(orchestrator)` helper) into a
7
11
  * `compat.mjs` `BrowserToolRegistry` (Phase 1), wired against a real, attached
8
12
  * `MeshOrchestrator` (Phase 3, `mesh-orchestrator.mjs`'s `createOrchestratorService()`).
9
13
  * Once registered, `agent-runtime.mjs`'s `createAgentRuntime({registry, llmFn})`
@@ -112,6 +116,52 @@
112
116
  * protocol first (out of scope here, exactly per this plan's Phase 4 section).
113
117
  *
114
118
  * ---------------------------------------------------------------------------
119
+ * `meshctl_spawn`/`meshctl_snapshot`/`meshctl_restore`/`meshctl_hosted_pods`/
120
+ * `meshctl_hosts` -- issue #185 §8a item 4's hosted-pods control surface,
121
+ * ALSO ALWAYS WIRED STRAIGHT TO THE RAW INSTANCE, BUT FOR A DIFFERENT REASON
122
+ * THAN COMPUTE/EXPOSE
123
+ *
124
+ * `MeshctlSpawnTool`/`MeshctlSnapshotTool`/`MeshctlRestoreTool`/
125
+ * `MeshctlHostedPodsTool` call `orchestrator.spawnPod()`/`.snapshotPod()`/
126
+ * `.restorePod()`/`.listHostedPods()`; `MeshctlHostsTool` calls
127
+ * `orchestrator.listPodHosts()`. Like compute/expose, none of these five are
128
+ * part of `mesh-orchestrator.mjs`'s `RISKY_ACTIONS` wire protocol (still
129
+ * exactly `['exec', 'deploy', 'drain']`), so there is no `api.spawnPod`/etc.
130
+ * gated equivalent to prefer -- they are wired straight to the raw
131
+ * instance's own methods here regardless of which input shape is supplied.
132
+ *
133
+ * Unlike compute/expose, this is NOT a gating gap: `spawnPod()`/
134
+ * `snapshotPod()`/`restorePod()`/`listHostedPods()` dispatch over `pod-host-
135
+ * service.mjs`'s OWN mesh protocol (`createPodHostClient()` -> a real
136
+ * `sendTo()` round trip to the target host), and that service gates every
137
+ * verb itself via `ctx.registry.checkAccess(pubKey, resource, verb)` on the
138
+ * HOST side -- the real authorization path for hosted pods, independent of
139
+ * `mesh-orchestrator.mjs`'s own `RISKY_ACTIONS` gate entirely. An EACCES
140
+ * from a refused host surfaces through these tools exactly as it does
141
+ * calling `spawnPod()` directly (see `orchestrator.mjs`'s
142
+ * `formatPodHostError()`); nothing here re-adds or bypasses that gate.
143
+ * `meshctl_hosts` is the one read with no gate anywhere, by design -- it
144
+ * reads `describe()`-derived runtime-registry peers, and `describe()`
145
+ * itself is deliberately ungated (`pod-host-service.mjs`'s module doc
146
+ * comment: a peer must be able to find a host before asking to be granted
147
+ * anything on it).
148
+ *
149
+ * ---------------------------------------------------------------------------
150
+ * `meshctl_supervise`/`meshctl_supervised` -- issue #185 item 6, SAME
151
+ * REASONING AS THE FIVE ABOVE, ONE LEVEL UP
152
+ *
153
+ * `MeshctlSuperviseTool`/`MeshctlSupervisedTool` call
154
+ * `orchestrator.getSupervisor()` and then the returned `PodSupervisor`'s own
155
+ * `supervise()`/`list()` (`pod-supervisor.mjs`). `getSupervisor()` is
156
+ * ALWAYS wired straight to the raw instance here too -- not part of
157
+ * `RISKY_ACTIONS`, same as `spawnPod()` and friends. The gate a restart
158
+ * actually goes through is still `pod-host-service.mjs`'s `checkAccess()`,
159
+ * because `PodSupervisor#supervise()`/its restart path call
160
+ * `orchestrator.spawnPod()` internally -- "a restart is a new spawn request
161
+ * the host may refuse" (`pod-supervisor.mjs`'s own module doc comment)
162
+ * means there is nothing new to gate here either.
163
+ *
164
+ * ---------------------------------------------------------------------------
115
165
  * No browser-only imports at module level.
116
166
  */
117
167
 
@@ -179,6 +229,21 @@ function buildToolFacade(orchestrator) {
179
229
  // instance either way.
180
230
  runComputeTask: (...args) => raw.runComputeTask(...args),
181
231
  exposePod: (...args) => raw.exposePod(...args),
232
+ // meshctl_spawn/meshctl_snapshot/meshctl_restore/meshctl_hosted_pods/
233
+ // meshctl_hosts (issue #185 §8a item 4) -- gated by pod-host-
234
+ // service.mjs's own checkAccess() on the host side, not by this
235
+ // service's RISKY_ACTIONS; straight to the raw instance either way
236
+ // (see module doc comment's dedicated section for these five).
237
+ spawnPod: (...args) => raw.spawnPod(...args),
238
+ snapshotPod: (...args) => raw.snapshotPod(...args),
239
+ restorePod: (...args) => raw.restorePod(...args),
240
+ listHostedPods: (...args) => raw.listHostedPods(...args),
241
+ listPodHosts: (...args) => raw.listPodHosts(...args),
242
+ // meshctl_supervise/meshctl_supervised (issue #185 item 6) -- see the
243
+ // dedicated section above.
244
+ getSupervisor: (...args) => raw.getSupervisor(...args),
245
+ // MeshctlSpawnTool's auto host selection reads this too.
246
+ listComputeCandidates: (...args) => raw.listComputeCandidates(...args),
182
247
  // MeshctlExposeTool reads `this.#orchestrator.peerNode` directly for
183
248
  // its own default-podId fallback.
184
249
  get peerNode() { return raw.peerNode },
@@ -200,11 +265,12 @@ function buildToolFacade(orchestrator) {
200
265
  }
201
266
 
202
267
  /**
203
- * Construct all 8 `Meshctl*Tool` instances (`orchestrator.mjs`'s own
268
+ * Construct all 15 `Meshctl*Tool` instances (`orchestrator.mjs`'s own
204
269
  * `createMeshctlTools()`) against `orchestrator` and register each into
205
270
  * `registry`. See module doc comment for the full design writeup (the two
206
- * accepted `orchestrator` shapes, the exec/deploy/drain gating decision, and
207
- * the compute/expose "not wired by Phase 3 at all" note).
271
+ * accepted `orchestrator` shapes, the exec/deploy/drain gating decision, the
272
+ * compute/expose "not wired by Phase 3 at all" note, and the hosted-pods
273
+ * control surface's own gating section, including the supervisor pair).
208
274
  *
209
275
  * @param {import('./compat.mjs').BrowserToolRegistry} registry - REQUIRED.
210
276
  * Duck-typed (`.register` a function), matching this package's established
@@ -213,9 +279,10 @@ function buildToolFacade(orchestrator) {
213
279
  * @param {object} orchestrator - REQUIRED. Either `mesh-orchestrator.mjs`'s
214
280
  * service `api` (recommended -- e.g. `node.orchestrator.api`) or a raw
215
281
  * `MeshOrchestrator` instance -- see module doc comment.
216
- * @returns {import('./orchestrator.mjs').BrowserTool[]} the 8 registered tool
217
- * instances, in `createMeshctlTools()`'s own order (pods, status, exec,
218
- * deploy, top, compute, expose, drain).
282
+ * @returns {import('./orchestrator.mjs').BrowserTool[]} the 15 registered
283
+ * tool instances, in `createMeshctlTools()`'s own order (pods, status,
284
+ * exec, deploy, top, compute, expose, drain, spawn, snapshot, restore,
285
+ * hosted_pods, hosts, supervise, supervised).
219
286
  */
220
287
  export function registerOrchestratorTools(registry, orchestrator) {
221
288
  if (!registry || typeof registry.register !== 'function') {
@@ -235,11 +302,11 @@ export function registerOrchestratorTools(registry, orchestrator) {
235
302
 
236
303
  /**
237
304
  * Convenience factory: build a brand-new `BrowserToolRegistry` and
238
- * pre-populate it with all 8 `Meshctl*Tool`s via `registerOrchestratorTools()`.
305
+ * pre-populate it with all 15 `Meshctl*Tool`s via `registerOrchestratorTools()`.
239
306
  * Equivalent to `registerOrchestratorTools(new BrowserToolRegistry(), orchestrator)`,
240
307
  * for a caller who doesn't already have a registry of their own to reuse (see
241
308
  * `registerOrchestratorTools()` directly if you do -- e.g. to add
242
- * non-orchestrator tools into the same registry alongside these 8).
309
+ * non-orchestrator tools into the same registry alongside these 15).
243
310
  *
244
311
  * @param {object} orchestrator - See `registerOrchestratorTools()`.
245
312
  * @returns {import('./compat.mjs').BrowserToolRegistry}
@@ -72,7 +72,7 @@
72
72
  * arbitrary content deployed to this node's filesystem-adjacent skill
73
73
  * store, and forcibly disconnecting/migrating this node's own workload,
74
74
  * respectively) -- exactly `orchestrator.mjs`'s own header comment's
75
- * "eight `meshctl`-CLI-shaped agent tools", the three whose `BrowserTool`
75
+ * "thirteen `meshctl`-CLI-shaped agent tools", the three whose `BrowserTool`
76
76
  * subclasses (`MeshctlExecTool`/`MeshctlDeployTool`/`MeshctlDrainTool`)
77
77
  * already declare `get permission() { return 'network' }` (vs. `'read'` for
78
78
  * the pods/status/top query tools). Before honoring an inbound
@@ -609,9 +609,9 @@ export function createTorrentService({
609
609
  await bucket.take(bytes.length)
610
610
 
611
611
  let sent = true
612
- // Piece data should ride the bulk lane so it cannot starve control traffic.
613
- // #198 lands the `{ channel: 'bulk' }` option on ctx.sendTo; until then the
614
- // extra argument is ignored and everything uses the default lane.
612
+ // Piece data rides the bulk lane so it cannot starve control traffic
613
+ // (`ctx.sendTo(..., { channel: 'bulk' })`, #198). A transport with no bulk
614
+ // lane ignores the option.
615
615
  await respond({ data: toBase64(bytes) }, { channel: 'bulk' }).catch((err) => {
616
616
  sent = false
617
617
  log('mesh-torrent:chunk-response-send-failed', { to: fromPubKey, cid: msg.cid, error: err?.message || String(err) })