Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
feat: extend install-console logging to MuScriptor + local pip installers (#2432)
Adam Eivyc69ff65fd97c
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex e13007c519..b601166798 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -2,7 +2,7 @@## Changes-- **Runtime/venv install SSE flows now log to the server console too, matching the HF model-download logging (#2432).** The image/video runtime installers (spawning `setup-image-video.sh`) and the FLUX.2 venv bootstrap streamed multi-GB pip/git progress only to the browser via SSE — a headless / PM2 log had no record the install ever ran (the same gap `startHfDownloadStream` had already closed for HF model downloads). A new shared `createInstallLogger` chokepoint (`server/lib/installLogger.js`) now emits a single-line START, throttled heartbeats + `stage` milestones, and the OUTCOME (success/fail/cancel) with installer name, target, and elapsed time — without echoing every raw pip/bash line. Wired into all three install spawn sites in `music.js`, `videoGen.js`, and `imageGen.js`.+- **Runtime/venv install SSE flows now log to the server console too, matching the HF model-download logging (#2432).** The image/video/MuScriptor runtime installers (spawning `setup-image-video.sh`), the FLUX.2 venv bootstrap, and the local image-gen pip installer streamed multi-GB pip/git progress only to the browser via SSE — a headless / PM2 log had no record the install ever ran (the same gap `startHfDownloadStream` had already closed for HF model downloads). A new shared `createInstallLogger` chokepoint (`server/lib/installLogger.js`) now emits a single-line START, throttled heartbeats + `stage` milestones, and the OUTCOME (success/fail/cancel) with installer name, target, and elapsed time — without echoing every raw pip/bash line. Wired into all five install spawn sites in `music.js`, `videoGen.js`, `imageGen.js` (FLUX.2 venv + local pip install), and `midiRuntime.js`.- **The four SSE job-slot hooks now share one implementation.** `useReferenceAudioImport`, `useYoutubeTrackImport`, `useVideoDownload`, and `useMidiTranscription` each hand-rolled the same "kick off a job → stream SSE progress → settle on the terminal frame, with double-click and lost-connection recovery" machinery. That logic now lives in exactly one place — a new generic `useSseJobSlot` hook — and the four feature hooks are thin wrappers that pass their own kickoff/SSE/cancel calls plus per-feature toast copy (and, for MuScriptor, its runtime-install and gated-repo modals). Behavior-preserving refactor deferred from the MuScriptor /simplify pass (#2368); ~150 fewer lines.diff --git a/server/lib/installLogger.js b/server/lib/installLogger.jsindex fe12b92783..2f1e83529d 100644--- a/server/lib/installLogger.js+++ b/server/lib/installLogger.js@@ -76,7 +76,9 @@ export function createInstallLogger({ installer, target } = {}) {const success = (message) => safe(() => finish(true, message));const failure = (message) => safe(() => finish(false, message));const cancel = () => safe(() => {- if (finished) return;+ // A disconnect before start() (e.g. the client closes during a readiness+ // probe that runs before spawn) never began an install — nothing to cancel.+ if (!started || finished) return;finished = true;console.log(`🛑 Install cancelled: ${name}${suffix} after ${elapsed()}`);});diff --git a/server/lib/installLogger.test.js b/server/lib/installLogger.test.jsindex 00e63ee0e4..9c95ddb1e1 100644--- a/server/lib/installLogger.test.js+++ b/server/lib/installLogger.test.js@@ -31,17 +31,26 @@ describe('createInstallLogger', () => {expect(errored()).toHaveLength(0);});- it('logs stage milestones but throttles raw log lines', () => {- const log = createInstallLogger({ installer: 'Example' });- log.start();- log.onEvent({ type: 'stage', stage: 'install', message: 'Installing torch' });- // A burst of raw log lines within the heartbeat window emits at most one- // heartbeat (the first line, since lastHeartbeat was set at start()).- for (let i = 0; i < 50; i += 1) log.onEvent({ type: 'log', message: `line ${i}` });- const stageLines = logged().filter((l) => /Example: install/.test(l));- const heartbeats = logged().filter((l) => /installing…/.test(l));- expect(stageLines).toHaveLength(1);- expect(heartbeats.length).toBeLessThanOrEqual(1);+ it('logs stage milestones but throttles raw log lines to a timed heartbeat', () => {+ vi.useFakeTimers();+ vi.setSystemTime(new Date('2026-01-01T00:00:00Z'));+ try {+ const log = createInstallLogger({ installer: 'Example' });+ log.start();+ log.onEvent({ type: 'stage', stage: 'install', message: 'Installing torch' });+ // A burst of raw log lines inside the heartbeat window emits ZERO+ // heartbeats (lastHeartbeat was set at start(), same instant).+ for (let i = 0; i < 50; i += 1) log.onEvent({ type: 'log', message: `line ${i}` });+ expect(logged().filter((l) => /Example: install/.test(l))).toHaveLength(1);+ expect(logged().filter((l) => /installing…/.test(l))).toHaveLength(0);++ // Cross the heartbeat threshold → the next line emits exactly one heartbeat.+ vi.advanceTimersByTime(16000);+ for (let i = 0; i < 50; i += 1) log.onEvent({ type: 'log', message: `more ${i}` });+ expect(logged().filter((l) => /installing…/.test(l))).toHaveLength(1);+ } finally {+ vi.useRealTimers();+ }});it('logs SUCCESS outcome on a complete event', () => {@@ -76,6 +85,13 @@ describe('createInstallLogger', () => {expect(errored()).toHaveLength(0);});+ it('cancel() before start() is a no-op (nothing was installing)', () => {+ const log = createInstallLogger({ installer: 'Example' });+ log.cancel();+ expect(logged()).toHaveLength(0);+ expect(errored()).toHaveLength(0);+ });+it('survives a malformed event without throwing', () => {const log = createInstallLogger({ installer: 'Example' });log.start();diff --git a/server/routes/imageGen.js b/server/routes/imageGen.jsindex 34a55dab7c..23e71d6c2e 100644--- a/server/routes/imageGen.js+++ b/server/routes/imageGen.js@@ -1076,7 +1076,12 @@ router.get('/setup/install', (req, res) => {// so a late pip-output line (or the promise.then below) doesn't trigger// ERR_STREAM_WRITE_AFTER_END or double-end the response.const { send, safeEnd } = openSseStream(res);- const { promise, kill } = installPackages(parsed.data.pythonPath, parsed.data.packages, send);+ // Server-console visibility for the (multi-GB) local pip install — the SSE+ // stream otherwise surfaces progress only in the browser.+ const installLog = createInstallLogger({ installer: 'Image Gen packages', target: parsed.data.pythonPath });+ const emit = (ev) => { installLog.onEvent(ev); send(ev); };+ installLog.start();+ const { promise, kill } = installPackages(parsed.data.pythonPath, parsed.data.packages, emit);promise.then(() => {// Drop the now-stale setup-check snapshot before the client re-runs the// probe on `complete` — without this it would read the pre-install@@ -1087,7 +1092,7 @@ router.get('/setup/install', (req, res) => {// Client navigation away should kill pip — a torch upgrade can run for// 10+ minutes and would otherwise keep going invisibly.- req.on('close', () => { kill(); safeEnd(); });+ req.on('close', () => { installLog.cancel(); kill(); safeEnd(); });});export default router;diff --git a/server/routes/midiRuntime.js b/server/routes/midiRuntime.jsindex ed8bb7f271..1861d795a5 100644--- a/server/routes/midiRuntime.js+++ b/server/routes/midiRuntime.js@@ -22,6 +22,7 @@ import { asyncHandler } from '../lib/errorHandler.js';import { PATHS } from '../lib/fileUtils.js';import { safeChildProcessEnv } from '../lib/processEnv.js';import { openSseStream } from '../lib/sseDownload.js';+import { createInstallLogger } from '../lib/installLogger.js';import {resolveMuscriptorPython,isMuscriptorRuntimeReady,@@ -41,6 +42,12 @@ let installInFlight = null;router.get('/install', asyncHandler(async (req, res) => {const { send, safeEnd } = openSseStream(res);+ // Server-console visibility for the multi-GB install (start / heartbeat /+ // outcome) — the SSE stream otherwise surfaces progress only in the browser.+ // `start()` isn't called until spawn, so events before then (already-installed+ // short-circuit) and a pre-spawn disconnect no-op through the logger.+ const installLog = createInstallLogger({ installer: MUSCRIPTOR_LABEL, target: MUSCRIPTOR_VENV_DEFAULT });+ const emit = (ev) => { installLog.onEvent(ev); send(ev); };if (installInFlight) {send({ type: 'error', message: 'A MuScriptor install is already running. Wait for it to finish or restart PortOS.' });@@ -59,6 +66,7 @@ router.get('/install', asyncHandler(async (req, res) => {// outer var so this handler kills the process group once it exists.req.on('close', () => {clientGone = true;+ installLog.cancel();if (finished) return;if (child) {if (!child.killed && child.pid) {@@ -109,6 +117,7 @@ router.get('/install', asyncHandler(async (req, res) => {}send({ type: 'log', message: `Starting MuScriptor install via ${MUSCRIPTOR_INSTALL_ENV}=1 bash scripts/setup-image-video.sh` });+ installLog.start();// `detached: true` puts bash in its own process group so a cancel (client// closing the SSE stream) can SIGTERM uv / pip / git children too — otherwise// a multi-GB download keeps burning bandwidth after the modal closes.@@ -122,7 +131,7 @@ router.get('/install', asyncHandler(async (req, res) => {const onChunk = (chunk) => {for (const line of chunk.toString().split(/[\r\n]+/)) {const t = line.trimEnd();- if (t) send({ type: 'log', message: t });+ if (t) emit({ type: 'log', message: t });}};child.stdout.on('data', onChunk);@@ -130,7 +139,7 @@ router.get('/install', asyncHandler(async (req, res) => {child.on('error', (err) => {finished = true;installInFlight = null;- send({ type: 'error', message: `Installer failed to spawn: ${err.message}` });+ emit({ type: 'error', message: `Installer failed to spawn: ${err.message}` });safeEnd();});child.on('close', async (code) => {@@ -143,11 +152,11 @@ router.get('/install', asyncHandler(async (req, res) => {invalidateMuscriptorPython();const ready = await isMuscriptorRuntimeReady();if (code === 0 && ready) {- send({ type: 'complete', message: `MuScriptor ready: ${resolveMuscriptorPython()}` });+ emit({ type: 'complete', message: `MuScriptor ready: ${resolveMuscriptorPython()}` });} else if (code === 0) {- send({ type: 'error', message: `Installer exited 0 but MuScriptor can't be imported from ${MUSCRIPTOR_VENV_DEFAULT}. Re-run from a terminal to see what happened.` });+ emit({ type: 'error', message: `Installer exited 0 but MuScriptor can't be imported from ${MUSCRIPTOR_VENV_DEFAULT}. Re-run from a terminal to see what happened.` });} else {- send({ type: 'error', message: `Installer exited with code ${code}.` });+ emit({ type: 'error', message: `Installer exited with code ${code}.` });}safeEnd();});