groove-dev 0.27.197 → 0.27.199

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 (76) hide show
  1. package/axom-integration/Screenshot_2026-07-25_at_5.25.30_PM.png +0 -0
  2. package/axom-integration/Screenshot_2026-07-25_at_5.33.26_PM.png +0 -0
  3. package/axom-integration/Screenshot_2026-07-25_at_6.11.53_PM.png +0 -0
  4. package/axom-integration/Screenshot_2026-07-25_at_6.44.56_PM.png +0 -0
  5. package/axom-integration/Screenshot_2026-07-25_at_6.45.35_PM.png +0 -0
  6. package/node_modules/@groove-dev/cli/package.json +1 -1
  7. package/node_modules/@groove-dev/daemon/package.json +1 -1
  8. package/node_modules/@groove-dev/daemon/src/api.js +2 -0
  9. package/node_modules/@groove-dev/daemon/src/axom-connector.js +368 -0
  10. package/node_modules/@groove-dev/daemon/src/axom-install.js +162 -0
  11. package/node_modules/@groove-dev/daemon/src/axom-remote.js +230 -0
  12. package/node_modules/@groove-dev/daemon/src/axom-server.js +249 -0
  13. package/node_modules/@groove-dev/daemon/src/federation.js +6 -0
  14. package/node_modules/@groove-dev/daemon/src/index.js +14 -0
  15. package/node_modules/@groove-dev/daemon/src/innerchat-docs.js +8 -1
  16. package/node_modules/@groove-dev/daemon/src/innerchat-relay.js +89 -0
  17. package/node_modules/@groove-dev/daemon/src/innerchat.js +261 -1
  18. package/node_modules/@groove-dev/daemon/src/introducer.js +1 -1
  19. package/node_modules/@groove-dev/daemon/src/network-guard.js +56 -0
  20. package/node_modules/@groove-dev/daemon/src/process.js +1 -1
  21. package/node_modules/@groove-dev/daemon/src/providers/axom.js +66 -0
  22. package/node_modules/@groove-dev/daemon/src/providers/index.js +2 -0
  23. package/node_modules/@groove-dev/daemon/src/routes/axom.js +267 -0
  24. package/node_modules/@groove-dev/daemon/src/routes/innerchat.js +334 -20
  25. package/node_modules/@groove-dev/daemon/test/axom-connector.test.js +455 -0
  26. package/node_modules/@groove-dev/daemon/test/axom-remote.test.js +115 -0
  27. package/node_modules/@groove-dev/daemon/test/axom-server.test.js +228 -0
  28. package/node_modules/@groove-dev/daemon/test/innerchat-relay.test.js +251 -0
  29. package/node_modules/@groove-dev/gui/dist/assets/index-BbA-X4CE.js +1084 -0
  30. package/node_modules/@groove-dev/gui/dist/assets/index-BbE3qX83.css +1 -0
  31. package/node_modules/@groove-dev/gui/dist/index.html +2 -2
  32. package/node_modules/@groove-dev/gui/package.json +1 -1
  33. package/node_modules/@groove-dev/gui/src/App.jsx +2 -0
  34. package/node_modules/@groove-dev/gui/src/app.css +53 -0
  35. package/node_modules/@groove-dev/gui/src/components/agents/agent-feed.jsx +3 -1
  36. package/node_modules/@groove-dev/gui/src/components/layout/activity-bar.jsx +2 -1
  37. package/node_modules/@groove-dev/gui/src/stores/groove.js +22 -0
  38. package/node_modules/@groove-dev/gui/src/stores/slices/axom-slice.js +279 -0
  39. package/node_modules/@groove-dev/gui/src/views/axom.jsx +1897 -0
  40. package/node_modules/@groove-dev/gui/src/views/settings.jsx +232 -4
  41. package/package.json +2 -2
  42. package/packages/cli/package.json +1 -1
  43. package/packages/daemon/package.json +1 -1
  44. package/packages/daemon/src/api.js +2 -0
  45. package/packages/daemon/src/axom-connector.js +368 -0
  46. package/packages/daemon/src/axom-install.js +162 -0
  47. package/packages/daemon/src/axom-remote.js +230 -0
  48. package/packages/daemon/src/axom-server.js +249 -0
  49. package/packages/daemon/src/federation.js +6 -0
  50. package/packages/daemon/src/index.js +14 -0
  51. package/packages/daemon/src/innerchat-docs.js +8 -1
  52. package/packages/daemon/src/innerchat-relay.js +89 -0
  53. package/packages/daemon/src/innerchat.js +261 -1
  54. package/packages/daemon/src/introducer.js +1 -1
  55. package/packages/daemon/src/network-guard.js +56 -0
  56. package/packages/daemon/src/process.js +1 -1
  57. package/packages/daemon/src/providers/axom.js +66 -0
  58. package/packages/daemon/src/providers/index.js +2 -0
  59. package/packages/daemon/src/routes/axom.js +267 -0
  60. package/packages/daemon/src/routes/innerchat.js +334 -20
  61. package/packages/gui/dist/assets/index-BbA-X4CE.js +1084 -0
  62. package/packages/gui/dist/assets/index-BbE3qX83.css +1 -0
  63. package/packages/gui/dist/index.html +2 -2
  64. package/packages/gui/package.json +1 -1
  65. package/packages/gui/src/App.jsx +2 -0
  66. package/packages/gui/src/app.css +53 -0
  67. package/packages/gui/src/components/agents/agent-feed.jsx +3 -1
  68. package/packages/gui/src/components/layout/activity-bar.jsx +2 -1
  69. package/packages/gui/src/stores/groove.js +22 -0
  70. package/packages/gui/src/stores/slices/axom-slice.js +279 -0
  71. package/packages/gui/src/views/axom.jsx +1897 -0
  72. package/packages/gui/src/views/settings.jsx +232 -4
  73. package/node_modules/@groove-dev/gui/dist/assets/index-Da2nbd6M.js +0 -1043
  74. package/node_modules/@groove-dev/gui/dist/assets/index-zmrIbwNm.css +0 -1
  75. package/packages/gui/dist/assets/index-Da2nbd6M.js +0 -1043
  76. package/packages/gui/dist/assets/index-zmrIbwNm.css +0 -1
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/cli",
3
- "version": "0.27.197",
3
+ "version": "0.27.199",
4
4
  "description": "GROOVE CLI — manage AI coding agents from your terminal",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@groove-dev/daemon",
3
- "version": "0.27.197",
3
+ "version": "0.27.199",
4
4
  "description": "GROOVE daemon — agent orchestration engine",
5
5
  "license": "FSL-1.1-Apache-2.0",
6
6
  "type": "module",
@@ -31,6 +31,7 @@ import { registerInnerChatRoutes } from './routes/innerchat.js';
31
31
  import { registerChatHistoryRoutes } from './routes/chat-history.js';
32
32
  import { registerWatchRoutes } from './routes/watch.js';
33
33
  import { registerAutoAgentRoutes } from './routes/auto-agents.js';
34
+ import { registerAxomRoutes } from './routes/axom.js';
34
35
 
35
36
  const __dirname = dirname(fileURLToPath(import.meta.url));
36
37
  const pkgVersion = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
@@ -183,6 +184,7 @@ export function createApi(app, daemon) {
183
184
  registerChatHistoryRoutes(app, daemon);
184
185
  registerWatchRoutes(app, daemon);
185
186
  registerAutoAgentRoutes(app, daemon);
187
+ registerAxomRoutes(app, daemon);
186
188
 
187
189
 
188
190
  // Token usage
@@ -0,0 +1,368 @@
1
+ // GROOVE — Axom Connector
2
+ // FSL-1.1-Apache-2.0 — see LICENSE
3
+ //
4
+ // Consumes the Axom provider protocol (GROOVE ⇄ Axom Integration Contract v0,
5
+ // Axom-Labs/Axom-Private docs/GROOVE_INTEGRATION.md):
6
+ //
7
+ // GET /about identity + KINDS schema handshake
8
+ // GET /sessions [{session, started, live}]
9
+ // WS /ws/session/{id}?since=<ev-id> envelope stream, verbatim
10
+ // POST /session/{id}/interrupt {text} -> {id, truncated}
11
+ // POST /session/{id}/stop {} -> {ok}
12
+ //
13
+ // The envelope schema is additive-only: unknown kinds are surfaced and passed
14
+ // through, never dropped. GROOVE consumes the protocol; it never imports Axom
15
+ // code. Host-agnostic by contract §5 — an endpoint is a URL, nothing here may
16
+ // assume where the runtime lives.
17
+
18
+ import { WebSocket } from 'ws';
19
+
20
+ export const AXOM_DEFAULT_PORT = 8737;
21
+
22
+ // The frozen KINDS enumeration from Axom's events.py, mirrored for the /about
23
+ // handshake. Drift (either direction) is surfaced on the endpoint status —
24
+ // new kinds still flow through; this list is for visibility, not filtering.
25
+ export const KNOWN_KINDS = Object.freeze([
26
+ 'pipeline_start', 'firing_start', 'step_start', 'firing_end', 'pipeline_done',
27
+ 'thought', 'text', 'action', 'observation', 'resolution',
28
+ 'delegate', 'yield', 'interrupt', 'interrupt_ack',
29
+ 'trace_other', 'tool_start', 'tool_end', 'recall_end',
30
+ 'swarm_start', 'swarm_weights', 'swarm_agent_done', 'swarm_agent_error',
31
+ 'swarm_memory_fused', 'swarm_fused', 'swarm_facts_extracted', 'swarm_done',
32
+ 'leaf_swap', 'stop_requested', 'stop_effected', 'candidate_banked',
33
+ 'narration', 'narration_dropped',
34
+ 'candidate_arrived', 'evidence_scored', 'champion_changed',
35
+ 'confidence_updated', 'verifier_verdict',
36
+ ]);
37
+
38
+ const RING_SIZE = 4096;
39
+ const SESSION_POLL_MS = 15000;
40
+ const BACKOFF_BASE_MS = 1000;
41
+ const BACKOFF_MAX_MS = 30000;
42
+ const FETCH_TIMEOUT_MS = 5000;
43
+
44
+ export function validateEndpoint(entry) {
45
+ if (!entry || typeof entry !== 'object') return 'endpoint must be an object';
46
+ const { name, url } = entry;
47
+ if (!name || typeof name !== 'string' || !/^[a-zA-Z0-9_-]{1,40}$/.test(name)) {
48
+ return 'endpoint name must be 1-40 chars (letters, digits, dash, underscore)';
49
+ }
50
+ if (!url || typeof url !== 'string') return 'endpoint url is required';
51
+ let parsed;
52
+ try { parsed = new URL(url); } catch { return `invalid url: ${url}`; }
53
+ if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
54
+ return 'endpoint url must be http(s)';
55
+ }
56
+ if (parsed.username || parsed.password) return 'credentials in the url are not allowed';
57
+ return null;
58
+ }
59
+
60
+ function seqOf(eventId) {
61
+ if (typeof eventId !== 'string' || !eventId.startsWith('ev-')) return null;
62
+ const n = parseInt(eventId.slice(3), 10);
63
+ return Number.isFinite(n) ? n : null;
64
+ }
65
+
66
+ export class AxomConnector {
67
+ constructor(daemon, opts = {}) {
68
+ this.daemon = daemon;
69
+ this.ringSize = opts.ringSize || RING_SIZE;
70
+ this.backoffBaseMs = opts.backoffBaseMs || BACKOFF_BASE_MS;
71
+ this.sessionPollMs = opts.sessionPollMs || SESSION_POLL_MS;
72
+ this.endpoints = new Map(); // name -> endpoint state
73
+ this.destroyed = false;
74
+ }
75
+
76
+ start() {
77
+ const configured = this.daemon.config?.axom?.endpoints || [];
78
+ this.configure(configured);
79
+ }
80
+
81
+ // Reconcile live connections against a validated endpoint list. Persistence
82
+ // is the caller's job (routes save config); this manages connections only.
83
+ configure(entries) {
84
+ const keep = new Set();
85
+ for (const entry of entries) {
86
+ if (validateEndpoint(entry)) continue; // routes validate; skip defensively
87
+ keep.add(entry.name);
88
+ const existing = this.endpoints.get(entry.name);
89
+ if (existing && existing.url === entry.url.replace(/\/+$/, '')) continue;
90
+ if (existing) this._teardownEndpoint(existing);
91
+ this._connectEndpoint(entry);
92
+ }
93
+ for (const [name, ep] of this.endpoints) {
94
+ if (!keep.has(name)) {
95
+ this._teardownEndpoint(ep);
96
+ this.endpoints.delete(name);
97
+ }
98
+ }
99
+ }
100
+
101
+ _connectEndpoint({ name, url }) {
102
+ const ep = {
103
+ name,
104
+ url: url.replace(/\/+$/, ''),
105
+ status: 'connecting', // connecting | connected | error
106
+ error: null,
107
+ about: null,
108
+ drift: null, // {novel: [], missing: []} vs KNOWN_KINDS
109
+ sessions: new Map(), // sessionId -> session state
110
+ pollTimer: null,
111
+ backoffMs: this.backoffBaseMs,
112
+ };
113
+ this.endpoints.set(name, ep);
114
+ this._handshake(ep);
115
+ return ep;
116
+ }
117
+
118
+ async _fetch(ep, path, options = {}) {
119
+ const controller = new AbortController();
120
+ const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
121
+ try {
122
+ const res = await fetch(`${ep.url}${path}`, { ...options, signal: controller.signal });
123
+ if (!res.ok) throw new Error(`HTTP ${res.status} from ${path}`);
124
+ return await res.json();
125
+ } finally {
126
+ clearTimeout(timer);
127
+ }
128
+ }
129
+
130
+ async _handshake(ep) {
131
+ if (this.destroyed) return;
132
+ try {
133
+ const about = await this._fetch(ep, '/about');
134
+ ep.about = about;
135
+ // Mechanical schema handshake (contract §6): compare, surface, never drop.
136
+ const remote = Array.isArray(about.kinds) ? about.kinds : [];
137
+ ep.drift = {
138
+ novel: remote.filter((k) => !KNOWN_KINDS.includes(k)),
139
+ missing: remote.length ? KNOWN_KINDS.filter((k) => !remote.includes(k)) : [],
140
+ };
141
+ ep.status = 'connected';
142
+ ep.error = null;
143
+ ep.backoffMs = this.backoffBaseMs;
144
+ this._broadcastStatus();
145
+ await this._pollSessions(ep);
146
+ ep.pollTimer = setInterval(() => {
147
+ this._pollSessions(ep).catch(() => this._endpointLost(ep));
148
+ }, this.sessionPollMs);
149
+ } catch (err) {
150
+ ep.status = 'error';
151
+ ep.error = err.message;
152
+ this._broadcastStatus();
153
+ this._scheduleEndpointRetry(ep);
154
+ }
155
+ }
156
+
157
+ _endpointLost(ep) {
158
+ if (this.destroyed || ep.status === 'error') return;
159
+ ep.status = 'error';
160
+ ep.error = 'endpoint unreachable';
161
+ if (ep.pollTimer) { clearInterval(ep.pollTimer); ep.pollTimer = null; }
162
+ this._broadcastStatus();
163
+ this._scheduleEndpointRetry(ep);
164
+ }
165
+
166
+ _scheduleEndpointRetry(ep) {
167
+ if (this.destroyed) return;
168
+ ep.retryTimer = setTimeout(() => {
169
+ ep.backoffMs = Math.min(ep.backoffMs * 2, BACKOFF_MAX_MS);
170
+ this._handshake(ep);
171
+ }, ep.backoffMs);
172
+ }
173
+
174
+ async _pollSessions(ep) {
175
+ const list = await this._fetch(ep, '/sessions');
176
+ if (!Array.isArray(list)) return;
177
+ for (const info of list) {
178
+ const id = info.session;
179
+ if (!id || typeof id !== 'string') continue;
180
+ let s = ep.sessions.get(id);
181
+ if (!s) {
182
+ s = {
183
+ id,
184
+ started: info.started ?? null,
185
+ live: !!info.live,
186
+ ws: null,
187
+ lastSeq: 0,
188
+ ring: [],
189
+ overflow: 0,
190
+ unknownKinds: {},
191
+ reconnectTimer: null,
192
+ };
193
+ ep.sessions.set(id, s);
194
+ }
195
+ // §12: `live` means a turn is in flight; sessions persist between turns
196
+ // and events can start at any moment — stay attached regardless.
197
+ s.live = !!info.live;
198
+ if (!s.ws) this._watchSession(ep, s);
199
+ }
200
+ }
201
+
202
+ _watchSession(ep, s) {
203
+ if (this.destroyed) return;
204
+ const since = s.lastSeq > 0 ? `?since=ev-${String(s.lastSeq).padStart(6, '0')}` : '';
205
+ const wsUrl = `${ep.url.replace(/^http/, 'ws')}/ws/session/${encodeURIComponent(s.id)}${since}`;
206
+ const ws = new WebSocket(wsUrl);
207
+ s.ws = ws;
208
+
209
+ ws.on('message', (data) => {
210
+ let envelope;
211
+ try { envelope = JSON.parse(data.toString()); } catch { return; }
212
+ const seq = seqOf(envelope.id);
213
+ // Dedup on ring-buffer replay after reconnect — ids are monotonic.
214
+ if (seq !== null && seq <= s.lastSeq) return;
215
+ if (seq !== null) s.lastSeq = seq;
216
+ if (s.ring.length >= this.ringSize) {
217
+ s.ring.shift();
218
+ // The ring bounds memory, not delivery: overflow is counted, never
219
+ // silent, and every event still broadcasts — mirrors the runtime.
220
+ s.overflow += 1;
221
+ }
222
+ s.ring.push(envelope);
223
+ if (envelope.kind && !KNOWN_KINDS.includes(envelope.kind)) {
224
+ s.unknownKinds[envelope.kind] = (s.unknownKinds[envelope.kind] || 0) + 1;
225
+ }
226
+ // Verbatim passthrough — the envelope is the contract, GROOVE adds
227
+ // routing metadata around it, never inside it.
228
+ this.daemon.broadcast({ type: 'axom:event', endpoint: ep.name, session: s.id, envelope });
229
+ });
230
+
231
+ const onGone = () => {
232
+ if (s.ws !== ws) return;
233
+ s.ws = null;
234
+ // Identity check, not name check: after configure() replaces an
235
+ // endpoint, a late close from the old socket must not re-arm a
236
+ // reconnect loop on the orphaned object — destroy() could never reach
237
+ // it (this exact leak wedged a test worker into an infinite loop).
238
+ if (this.destroyed || this.endpoints.get(ep.name) !== ep) return;
239
+ s.reconnectTimer = setTimeout(() => this._watchSession(ep, s), ep.backoffMs);
240
+ };
241
+ ws.on('close', onGone);
242
+ ws.on('error', onGone);
243
+ }
244
+
245
+ // §12 message verb: starts a turn (interrupt steers, stop halts). Status is
246
+ // part of the contract (202 accepted / 409 busy / 413 too_long) so this
247
+ // returns {status, body} verbatim instead of throwing on non-2xx.
248
+ async message(endpointName, sessionId, text, clientRef) {
249
+ const ep = this._requireEndpoint(endpointName);
250
+ const res = await fetch(`${ep.url}/session/${encodeURIComponent(sessionId)}/message`, {
251
+ method: 'POST',
252
+ headers: { 'Content-Type': 'application/json' },
253
+ // §15: opaque, echoed back in pipeline_start. Omitted when absent so
254
+ // pre-§15 runtimes see exactly today's payload.
255
+ body: JSON.stringify(clientRef ? { text, client_ref: clientRef } : { text }),
256
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
257
+ });
258
+ const body = await res.json().catch(() => ({}));
259
+ // First message creates the session (caller-chosen id) — poll now so the
260
+ // WS attaches before the turn's first events age out of nothing.
261
+ if (res.status === 202) this._pollSessions(ep).catch(() => {});
262
+ return { status: res.status, body };
263
+ }
264
+
265
+ // §14: ends the RUNTIME (distinct from stop, which halts a turn). 409 when
266
+ // a turn is in flight unless forced; statuses pass through so the GUI can
267
+ // say what happened rather than guess.
268
+ async shutdown(endpointName, { force = false } = {}) {
269
+ const ep = this._requireEndpoint(endpointName);
270
+ const res = await fetch(`${ep.url}/shutdown`, {
271
+ method: 'POST',
272
+ headers: { 'Content-Type': 'application/json' },
273
+ body: JSON.stringify({ force }),
274
+ signal: AbortSignal.timeout(FETCH_TIMEOUT_MS),
275
+ });
276
+ const body = await res.json().catch(() => ({}));
277
+ return { status: res.status, body };
278
+ }
279
+
280
+ async interrupt(endpointName, sessionId, text) {
281
+ const ep = this._requireEndpoint(endpointName);
282
+ return this._fetch(ep, `/session/${encodeURIComponent(sessionId)}/interrupt`, {
283
+ method: 'POST',
284
+ headers: { 'Content-Type': 'application/json' },
285
+ body: JSON.stringify({ text }),
286
+ });
287
+ }
288
+
289
+ async stop(endpointName, sessionId) {
290
+ const ep = this._requireEndpoint(endpointName);
291
+ return this._fetch(ep, `/session/${encodeURIComponent(sessionId)}/stop`, {
292
+ method: 'POST',
293
+ headers: { 'Content-Type': 'application/json' },
294
+ body: JSON.stringify({}),
295
+ });
296
+ }
297
+
298
+ _requireEndpoint(name) {
299
+ // Single-endpoint convenience: an omitted name resolves iff unambiguous.
300
+ if (!name && this.endpoints.size === 1) return this.endpoints.values().next().value;
301
+ const ep = this.endpoints.get(name);
302
+ if (!ep) throw new Error(`No Axom endpoint named "${name}"`);
303
+ return ep;
304
+ }
305
+
306
+ events(endpointName, sessionId, sinceSeq = 0) {
307
+ const ep = this._requireEndpoint(endpointName);
308
+ const s = ep.sessions.get(sessionId);
309
+ if (!s) throw new Error(`No session "${sessionId}" on endpoint "${ep.name}"`);
310
+ const events = sinceSeq > 0 ? s.ring.filter((e) => (seqOf(e.id) || 0) > sinceSeq) : s.ring;
311
+ return { session: s.id, overflow: s.overflow, events };
312
+ }
313
+
314
+ status() {
315
+ // A runtime we spawned can be shut down; one we merely connected to
316
+ // cannot (no signal reaches another machine's process). The GUI needs
317
+ // this to avoid offering a kill switch it can't honor.
318
+ const managed = new Set(
319
+ (this.daemon.axomServer?.list?.() || [])
320
+ .filter((i) => i.status === 'running')
321
+ .map((i) => `http://127.0.0.1:${i.port}`),
322
+ );
323
+ return {
324
+ endpoints: [...this.endpoints.values()].map((ep) => ({
325
+ name: ep.name,
326
+ url: ep.url,
327
+ status: ep.status,
328
+ error: ep.error,
329
+ about: ep.about,
330
+ drift: ep.drift,
331
+ managed: managed.has(ep.url),
332
+ instanceId: (this.daemon.axomServer?.list?.() || [])
333
+ .find((i) => i.status === 'running' && `http://127.0.0.1:${i.port}` === ep.url)?.id || null,
334
+ sessions: [...ep.sessions.values()].map((s) => ({
335
+ session: s.id,
336
+ started: s.started,
337
+ live: s.live,
338
+ watching: !!s.ws,
339
+ lastEventId: s.lastSeq > 0 ? `ev-${String(s.lastSeq).padStart(6, '0')}` : null,
340
+ buffered: s.ring.length,
341
+ overflow: s.overflow,
342
+ unknownKinds: s.unknownKinds,
343
+ })),
344
+ })),
345
+ };
346
+ }
347
+
348
+ _broadcastStatus() {
349
+ this.daemon.broadcast({ type: 'axom:status', data: this.status() });
350
+ }
351
+
352
+ _teardownEndpoint(ep) {
353
+ if (ep.pollTimer) clearInterval(ep.pollTimer);
354
+ if (ep.retryTimer) clearTimeout(ep.retryTimer);
355
+ for (const s of ep.sessions.values()) {
356
+ if (s.reconnectTimer) clearTimeout(s.reconnectTimer);
357
+ // terminate, not close: close() on a CONNECTING socket defers teardown
358
+ // until the connect completes — a live handle that can outlast us.
359
+ if (s.ws) { try { s.ws.terminate(); } catch { /* already gone */ } s.ws = null; }
360
+ }
361
+ }
362
+
363
+ destroy() {
364
+ this.destroyed = true;
365
+ for (const ep of this.endpoints.values()) this._teardownEndpoint(ep);
366
+ this.endpoints.clear();
367
+ }
368
+ }
@@ -0,0 +1,162 @@
1
+ // GROOVE — Axom Installer (manifest-driven)
2
+ // FSL-1.1-Apache-2.0 — see LICENSE
3
+ //
4
+ // Installs the Axom runtime + models against an install manifest per contract
5
+ // §11. The GUI (and this module) NEVER hardcodes a source — dev vs launch is
6
+ // purely a manifest swap. Models are sha256-verified before anything is
7
+ // configured; a failed verify configures nothing.
8
+ //
9
+ // Manifest shape (§11):
10
+ // {runtime: {kind: "pip"|"wheel-url"|"tarball", ref, sha256},
11
+ // models: [{file, url, sha256, bytes}], min_version}
12
+
13
+ import { execFile } from 'child_process';
14
+ import { createHash } from 'crypto';
15
+ import { createWriteStream } from 'fs';
16
+ import { mkdir, rename, rm } from 'fs/promises';
17
+ import { join } from 'path';
18
+ import os from 'os';
19
+ import { pipeline } from 'stream/promises';
20
+ import { Transform } from 'stream';
21
+ import { AXOM_REQUIREMENTS } from './axom-server.js';
22
+
23
+ export class AxomInstaller {
24
+ constructor(daemon, opts = {}) {
25
+ this.daemon = daemon;
26
+ this.pipCommand = opts.pipCommand || ['python3', '-m', 'pip'];
27
+ this.totalRamGbOverride = opts.totalRamGb; // tests inject; prod reads os
28
+ this.status = { phase: 'idle', file: null, receivedBytes: 0, totalBytes: 0, error: null };
29
+ this._running = false;
30
+ }
31
+
32
+ // Availability is a first-class answer, not an error string. A GROOVE build
33
+ // with no manifest configured cannot install Axom at all — the UI must say
34
+ // so up front rather than offering a button that fails on click.
35
+ getStatus() {
36
+ const manifestUrl = this.daemon.config?.axom?.manifestUrl || null;
37
+ return {
38
+ ...this.status,
39
+ available: !!manifestUrl,
40
+ manifestUrl,
41
+ unavailableReason: manifestUrl ? null : 'Coming soon',
42
+ };
43
+ }
44
+
45
+ _update(patch) {
46
+ this.status = { ...this.status, ...patch };
47
+ this.daemon.broadcast({ type: 'axom:install:progress', data: this.getStatus() });
48
+ }
49
+
50
+ async install(manifestUrl) {
51
+ // Gate, don't explain: a build with no configured distribution simply
52
+ // cannot install. The UI shows "Coming soon" and never offers the action;
53
+ // this is the server-side half of the same gate (a hand-crafted POST
54
+ // can't bypass it either).
55
+ const url = manifestUrl || this.daemon.config?.axom?.manifestUrl;
56
+ if (!url) throw new Error('Coming soon — Axom is not yet available for local install.');
57
+ if (this._running) throw new Error('an install is already running');
58
+ // Same hardware floor as the instance manager — never download 4GB of
59
+ // weights onto a machine that can't safely run them. Manifest min_ram_gb
60
+ // (when present) is the authority; the static floor is the fallback.
61
+ if (!this.daemon.config?.axom?.allowUnderspec) {
62
+ const totalRamGb = this.totalRamGbOverride ?? os.totalmem() / 2 ** 30;
63
+ if (totalRamGb < AXOM_REQUIREMENTS.minRamGb) {
64
+ throw new Error(
65
+ `This machine has ${Math.round(totalRamGb)}GB RAM — below Axom's ${AXOM_REQUIREMENTS.minRamGb}GB floor for local inference. `
66
+ + 'Connect to a remote Axom endpoint instead.',
67
+ );
68
+ }
69
+ }
70
+ this._running = true;
71
+ try {
72
+ this._update({ phase: 'manifest', file: null, receivedBytes: 0, totalBytes: 0, error: null });
73
+ const res = await fetch(url, { signal: AbortSignal.timeout(15000) });
74
+ if (res.status === 401 || res.status === 403) {
75
+ throw new Error('This Axom build is private — your account does not have access to the distribution. Connect to an Axom running elsewhere instead.');
76
+ }
77
+ if (res.status === 404) {
78
+ throw new Error(`No Axom distribution found at ${url} — the configured manifest URL is wrong or the release was removed.`);
79
+ }
80
+ if (!res.ok) throw new Error(`manifest fetch failed: HTTP ${res.status}`);
81
+ const manifest = await res.json();
82
+ if (!Array.isArray(manifest.models)) throw new Error('manifest has no models list');
83
+
84
+ if (manifest.runtime) await this._installRuntime(manifest.runtime);
85
+
86
+ const modelDir = this.daemon.axomServer?._modelDir()
87
+ || join(this.daemon.grooveDir, 'axom', 'models');
88
+ await mkdir(modelDir, { recursive: true });
89
+ for (const model of manifest.models) {
90
+ await this._downloadVerified(model, modelDir);
91
+ }
92
+
93
+ this._update({ phase: 'done', file: null });
94
+ this.daemon.audit.log('axom.install.complete', { models: manifest.models.length });
95
+ return { ok: true, models: manifest.models.length };
96
+ } catch (err) {
97
+ this._update({ phase: 'error', error: err.message });
98
+ throw err;
99
+ } finally {
100
+ this._running = false;
101
+ }
102
+ }
103
+
104
+ async _installRuntime(runtime) {
105
+ this._update({ phase: 'runtime', file: runtime.ref || null });
106
+ if (runtime.kind === 'pip') {
107
+ const [cmd, ...base] = this.pipCommand;
108
+ await new Promise((resolve, reject) => {
109
+ execFile(cmd, [...base, 'install', runtime.ref], { timeout: 600000 }, (err, _out, stderr) => {
110
+ if (err) reject(new Error(`pip install failed: ${stderr?.slice(-400) || err.message}`));
111
+ else resolve();
112
+ });
113
+ });
114
+ return;
115
+ }
116
+ // Honest v0 boundary — no silent no-op for kinds we don't handle yet.
117
+ throw new Error(`runtime kind "${runtime.kind}" is not supported by this GROOVE version`);
118
+ }
119
+
120
+ async _downloadVerified({ file, url, sha256, bytes }, modelDir) {
121
+ if (!file || !/^[a-zA-Z0-9._-]+$/.test(file)) throw new Error(`unsafe model filename: ${file}`);
122
+ if (!sha256) throw new Error(`manifest entry ${file} has no sha256 — refusing unverifiable download`);
123
+ const finalPath = join(modelDir, file);
124
+ const tmpPath = `${finalPath}.part`;
125
+ this._update({ phase: 'models', file, receivedBytes: 0, totalBytes: bytes || 0 });
126
+
127
+ const res = await fetch(url);
128
+ if (res.status === 401 || res.status === 403) {
129
+ throw new Error(`${file} is in a private repository your account can't read — the model weights are gated. Nothing was installed.`);
130
+ }
131
+ if (!res.ok || !res.body) throw new Error(`download failed for ${file}: HTTP ${res.status}`);
132
+
133
+ const hash = createHash('sha256');
134
+ let received = 0;
135
+ let lastBroadcast = 0;
136
+ const meter = new Transform({
137
+ transform: (chunk, _enc, cb) => {
138
+ hash.update(chunk);
139
+ received += chunk.length;
140
+ const now = Date.now();
141
+ if (now - lastBroadcast > 500) { // progress, throttled
142
+ lastBroadcast = now;
143
+ this._update({ receivedBytes: received });
144
+ }
145
+ cb(null, chunk);
146
+ },
147
+ });
148
+
149
+ try {
150
+ await pipeline(res.body, meter, createWriteStream(tmpPath));
151
+ const digest = hash.digest('hex');
152
+ if (digest !== sha256.toLowerCase()) {
153
+ throw new Error(`sha256 mismatch for ${file}: expected ${sha256}, got ${digest}`);
154
+ }
155
+ await rename(tmpPath, finalPath);
156
+ this._update({ receivedBytes: received });
157
+ } catch (err) {
158
+ await rm(tmpPath, { force: true });
159
+ throw err;
160
+ }
161
+ }
162
+ }