Skip to content

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

8.4 KB
Raw Blame
{
  "objective": "See if we should add SuperCollider as an audio creation option. Right now we use Strudel and Tone.js. Assess suitability, alternatives, and what automated setup and safe rendering would require.",
  "diff": "diff --git a/docs/HTML_COMPOSITIONS.md b/docs/HTML_COMPOSITIONS.md\nindex 7d2b0f6be..35f49ffa8 100644\n--- a/docs/HTML_COMPOSITIONS.md\n+++ b/docs/HTML_COMPOSITIONS.md\n@@ -50,6 +50,11 @@ with the same tail fade, and removes the temporary file after completion or\n failure. No music model, Python runtime, downloaded samples or music-library\n write is required. Missing or invalid audio fails the job.\n \n+SuperCollider is a planned optional native code-audio runtime, described in the\n+[integration decision](decisions/2026-10-01-supercollider-code-audio.md). It is not\n+currently installed or enabled by PortOS and cannot run through this JavaScript\n+PCM contract.\n+\n ## Several formats from one timeline\n \n One job can render the same composition at several aspect ratios, so a launch\ndiff --git a/docs/decisions/2026-10-01-supercollider-code-audio.md b/docs/decisions/2026-10-01-supercollider-code-audio.md\nnew file mode 100644\nindex 000000000..d570b05ef\n--- /dev/null\n+++ b/docs/decisions/2026-10-01-supercollider-code-audio.md\n@@ -0,0 +1,114 @@\n+# ADR: Add SuperCollider as an optional offline code-audio engine\n+\n+**Date:** 2026-10-01\n+**Status:** Accepted integration direction; implementation pending\n+**Implementation:** [#9407](https://github.com/atomantic/PortOS/issues/9407)\n+\n+## Decision\n+\n+Add SuperCollider to the Music Designer's **Code** language choices through an\n+optional, contained offline renderer. Keep Strudel as the default. Install and\n+test the runtime only on an explicit setup action; generate or render music only\n+on an explicit request. This assessment does not enable or install SuperCollider.\n+\n+The first implementation will use a PortOS-owned Linux container image with\n+`sclang`, `scsynth`, and the stock class library/plugins. A working Docker engine\n+is a prerequisite, reported separately from the installed image. This trades\n+container setup and disk space for one execution boundary across host platforms.\n+Native installations can remain useful outside PortOS, but will not be an\n+uncontained fallback for generated code.\n+\n+## Current behavior\n+\n+- `server/services/musicCode.js` explicitly accepts `strudel` and `tonejs` and\n+  asks the selected AI provider to write or revise source; it never executes it.\n+- `client/src/components/music/CodePanel.jsx` edits that source and plays or\n+  records it in `strudelFrame.js`'s opaque-origin browser sandbox.\n+- `POST /api/tracks/:id/code/render` accepts a browser-recorded WAV and uses\n+  `saveCodeTakeToTrack()` to append an `engine: 'code'` take.\n+- `server/services/musicEngineCatalog.js` describes model-backed engines;\n+  SuperCollider is a code runtime and must not be presented as a Hugging Face\n+  audio model or inherit their Python/CUDA installation path.\n+- [HTML compositions](../HTML_COMPOSITIONS.md) synthesize through a JavaScript\n+  `renderAudio` contract. Native SuperCollider source cannot run through that\n+  browser contract. Launch-video agents currently cannot install tools or submit\n+  arbitrary binary soundtracks in their composition directory.\n+\n+## Why add it\n+\n+[SuperCollider](https://supercollider.github.io/) separates its composition\n+language (`sclang`) from its native audio engine (`scsynth`). Its\n+[SynthDef graphs](https://docs.supercollider.online/Classes/SynthDef.html) make it\n+a useful choice for custom instruments and algorithmic sound design. The expected\n+benefit is more synthesis options and reusable scores, not a guarantee that\n+AI-authored music will sound better.\n+\n+[Non-realtime synthesis](https://docs.supercollider.online/Guides/Non-Realtime-Synthesis.html)\n+renders a prepared score to a file without a live audio clock or network control\n+connection. Patterns can be converted to scores. This fits bounded music takes\n+and soundtrack production better than keeping an interactive audio server alive.\n+Each score must supply its own synthesis resources; temporary OSC files need\n+explicit cleanup. PortOS will validate actual audio duration rather than trust\n+the requested score duration alone.\n+\n+## Integration contract\n+\n+1. Add `supercollider` to the code-language contract and a dedicated prompt that\n+   produces stock-library `.scd` source for offline rendering. The server controls\n+   duration, sample rate, output path and invocation; source remains editable.\n+2. Provide `npm run setup:supercollider -- --yes` and `--status --json`, following\n+   `scripts/setup-motion.js`'s explicit, idempotent setup shape. Build the managed\n+   image from a checked-in recipe with pinned base/dependency inputs and retain\n+   upstream license/source information. No runtime download or build at boot or\n+   when merely listing languages. Missing Docker yields an actionable setup\n+   state; the installer must not silently change the host's Docker installation.\n+3. Run each render as an unprivileged, disposable container: no network, no\n+   capabilities, no Docker socket, read-only root filesystem, bounded CPU/memory,\n+   PID and wall-time budgets. Mount only frozen source read-only and a bounded\n+   job-private output directory writable. Use private configuration/home/temp\n+   directories, an environment allowlist without provider/API credentials, and\n+   stock library/plugin paths. Kill and remove the whole container on cancellation\n+   or timeout. A working-directory change or source blacklist is not containment.\n+4. Expose setup/readiness and render/cancel/progress through authenticated PortOS\n+   routes and the existing media queue/SSE conventions. Readiness requires a\n+   shipped synthetic offline-render probe under the same containment policy,\n+   cached by runtime/policy version; status reads only the cached result.\n+5. In CodePanel, offer setup when unavailable, then **Render preview**, normal\n+   browser audio playback, cancellation and **Save as take**. Reuse existing WAV\n+   validation and track append boundaries. Previewing must not mutate the active\n+   take; failed/canceled renders must not leave takes or temporary artifacts.\n+6. Preserve source language, source hash, seed, runtime version and render settings\n+   with the take using the existing track persistence contract. Any persisted\n+   schema change must follow the track migration and federation version rules.\n+   Fixed-seed reproducibility is scoped to a tested runtime/platform configuration,\n+   not promised across arbitrary versions or architectures.\n+\n+`sclang` can execute [operating-system commands](https://docs.supercollider.online/Classes/String.html#-unixCmd)\n+and loads a [user startup file](https://docs.supercollider.online/Reference/StartupFile.html).\n+Containment must cover the language compiler as well as audio synthesis. Running\n+`scsynth` in offline mode alone does not protect the host from `sclang`.\n+\n+## Alternatives and limits\n+\n+- A third browser-frame library cannot execute SuperCollider's native language.\n+- Native package installation is feasible (for example, the\n+  [Homebrew cask](https://formulae.brew.sh/cask/supercollider)), but package presence\n+  does not establish a protected execution path. Do not install it during this\n+  assessment or advertise it as ready based only on executable discovery.\n+- Live OSC control, device routing, Quarks, third-party plugins, sample downloads,\n+  and AI singing are outside the first version.\n+- Launch-video and Code Animation consumers can reuse accepted Music-library\n+  takes immediately after implementation. Direct native-score submission needs a\n+  separate adapter that preserves their source snapshot, privacy and audio-evidence\n+  contracts; this decision does not loosen those contracts or their agent prompts.\n+\n+## Required delivery evidence\n+\n+Prove a real stock-synth stereo WAV with bounded duration and nonzero audio,\n+preview and save it through the public workflow, and exercise syntax errors,\n+missing runtime, timeout, cancellation and concurrent jobs. Verify that attempted\n+host-file access, network access, credential reads and output-path escapes fail\n+inside the execution boundary. Record tested platforms/architectures explicitly;\n+do not mark an untested configuration ready. Browser-language regression checks\n+must preserve existing playback and saves. No provider call belongs in setup or\n+the synthetic readiness probe.\n"
}