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(issue-2951): add pluggable image-to-3D target registry + availability endpoint
[._.]/ Adam Eivy3204469a9f09
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex 352ea40528..a677b99ea4 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -1,5 +1,9 @@# Unreleased+## Internal++- **[issue-2951] Image-to-3D target registry (foundation)** — added a pluggable `server/services/imageTo3d/targets.js` registry (mirroring `imageGen/modes.js`) that models image→3D models as selectable targets with hardware-gated availability resolution, TRELLIS.2 registered as the first target, and a read-only `GET /api/image-to-3d/targets` endpoint. Backend groundwork for the forthcoming 3D page under Create (#2952 install/runner, #2953 page/viewer, #2954 CUDA lane); no user-visible surface yet.+## Music studio- **[issue-2912] Chiptune score edits on two synced machines now show up as a real conflict** — if you compose a chiptune score for the same track on two federated installs before they sync with each other, that divergence now surfaces in Sharing → Conflicts (so you can review and choose which version to keep) instead of one edit silently overwriting the other.diff --git a/server/index.js b/server/index.jsindex b9e95a26c1..a138b48338 100644--- a/server/index.js+++ b/server/index.js@@ -113,6 +113,7 @@ import musicVideoRoutes from './routes/musicVideo.js';import spriteRoutes from './routes/sprites.js';import moodBoardRoutes from './routes/moodBoard.js';import threejsModelsRoutes from './routes/threejsModels.js';+import imageTo3dRoutes from './routes/imageTo3d.js';import privacyRoutes from './routes/privacy.js';import writersRoomRoutes from './routes/writersRoom.js';import universeBuilderRoutes from './routes/universeBuilder.js';@@ -337,6 +338,7 @@ app.use('/api/music-video', musicVideoRoutes);app.use('/api/sprites', spriteRoutes);app.use('/api/mood-boards', moodBoardRoutes);app.use('/api/threejs-models', threejsModelsRoutes);+app.use('/api/image-to-3d', imageTo3dRoutes);app.use('/api/privacy', privacyRoutes);app.use('/api/writers-room', writersRoomRoutes);app.use('/api/universe-builder', universeBuilderRoutes);diff --git a/server/routes/imageTo3d.js b/server/routes/imageTo3d.jsnew file mode 100644index 0000000000..c14d3f26e8--- /dev/null+++ b/server/routes/imageTo3d.js@@ -0,0 +1,21 @@+import { Router } from 'express';+import { asyncHandler } from '../lib/errorHandler.js';+import {+ listTargets,+ detectHostCapabilities,+} from '../services/imageTo3d/targets.js';++const router = Router();++/**+ * The selectable image→3D targets, each annotated with whether it can run on+ * this host (Apple Silicon / memory gating) so the client can render a target+ * selector with disabled / needs-install states. Read-only, no LLM/GPU work —+ * safe to call on load. Later phases add the create/generate/asset endpoints.+ */+router.get('/targets', asyncHandler(async (_req, res) => {+ const capabilities = detectHostCapabilities();+ res.json({ capabilities, targets: listTargets(capabilities) });+}));++export default router;diff --git a/server/routes/imageTo3d.test.js b/server/routes/imageTo3d.test.jsnew file mode 100644index 0000000000..bb1b4523ce--- /dev/null+++ b/server/routes/imageTo3d.test.js@@ -0,0 +1,40 @@+import { describe, expect, it, vi } from 'vitest';+import express from 'express';+import { request } from '../lib/testHelper.js';+import { errorMiddleware } from '../lib/errorHandler.js';++// Mock the service so the route test is deterministic regardless of the test+// host's real arch/memory.+vi.mock('../services/imageTo3d/targets.js', () => ({+ detectHostCapabilities: vi.fn(() => ({ appleSilicon: true, unifiedMemoryGb: 128, cuda: false })),+ listTargets: vi.fn((caps) => [+ {+ id: 'trellis2',+ label: 'TRELLIS.2',+ executionLane: 'local-mps',+ outputKind: 'glb-mesh',+ available: caps.appleSilicon && caps.unifiedMemoryGb >= 24,+ unavailableReason: null,+ },+ ]),+}));++import routes from './imageTo3d.js';++const makeApp = () => {+ const app = express();+ app.use(express.json());+ app.use('/api/image-to-3d', routes);+ app.use(errorMiddleware);+ return app;+};++describe('image-to-3d routes', () => {+ it('GET /targets returns host capabilities and annotated targets', async () => {+ const res = await request(makeApp()).get('/api/image-to-3d/targets');+ expect(res.status).toBe(200);+ expect(res.body.capabilities).toMatchObject({ appleSilicon: true, unifiedMemoryGb: 128 });+ expect(Array.isArray(res.body.targets)).toBe(true);+ expect(res.body.targets[0]).toMatchObject({ id: 'trellis2', available: true });+ });+});diff --git a/server/services/imageTo3d/targets.js b/server/services/imageTo3d/targets.jsnew file mode 100644index 0000000000..108486d240--- /dev/null+++ b/server/services/imageTo3d/targets.js@@ -0,0 +1,179 @@+/**+ * Image-to-3D — pluggable target registry.+ *+ * Single source of truth for the selectable image→3D "processing targets"+ * (TRELLIS.2 today; other models later). Adding a target is a registration+ * here, not a rewrite of the dispatch/install/UI — mirroring the role+ * `imageGen/modes.js` plays for the 2D image backends.+ *+ * This module is intentionally dependency-light: the registry is a set of pure+ * descriptors, and the resolver functions are pure — they take the host's+ * capabilities as an injected argument rather than probing hardware themselves.+ * Only `detectHostCapabilities()` touches the real machine, so it's the one+ * impure boundary (mirroring `platform.js`'s "detect at the route boundary and+ * pass into pure services" contract). Runner/installer wiring for a target is+ * referenced by module path and lands in later phases (see issue #2951); keeping+ * those out of the import graph is what lets this stay a pure, no-side-effect+ * registry that boot and tests can import for free.+ */++import os from 'os';+import { isAppleSilicon } from '../../lib/platform.js';++/**+ * How a target's inference actually runs. A target declares exactly one lane;+ * the lane decides which hardware gate `unavailableReason` applies and (later)+ * which installer/runner the service dispatches to.+ */+export const EXECUTION_LANE = Object.freeze({+ LOCAL_MPS: 'local-mps', // PyTorch MPS on Apple Silicon (on-device, private)+ LOCAL_CUDA: 'local-cuda', // NVIDIA CUDA (Linux/CUDA peer or future hardware)+ HOSTED_API: 'hosted-api', // remote inference endpoint (no local hardware gate)+});++export const EXECUTION_LANES = Object.freeze(Object.values(EXECUTION_LANE));++/** The shape of the artifact a target produces. */+export const OUTPUT_KIND = Object.freeze({+ GLB_MESH: 'glb-mesh', // binary glTF mesh, optionally with PBR materials+});++export const OUTPUT_KINDS = Object.freeze(Object.values(OUTPUT_KIND));++/**+ * The registry. Each entry is a frozen, pure descriptor — no imported runners,+ * no side effects — so a new model is one object added here.+ *+ * `requires` states the hardware floor for the target's declared lane; the pure+ * resolvers below read it. `installerModule`/`runnerModule` are the module paths+ * later phases wire up (they are not imported here — see the file header).+ */+export const IMAGE_TO_3D_TARGETS = Object.freeze({+ trellis2: Object.freeze({+ id: 'trellis2',+ label: 'TRELLIS.2',+ description:+ 'Microsoft TRELLIS.2 — single image to a PBR-textured GLB mesh, run on-device '+ + 'via the Apple Silicon (PyTorch MPS) port.',+ executionLane: EXECUTION_LANE.LOCAL_MPS,+ outputKind: OUTPUT_KIND.GLB_MESH,+ // Floor for the shipped local-MPS lane (the `trellis-mac` port): Apple+ // Silicon (M1+), 24 GB+ unified memory, ~15 GB weights on disk, Python 3.11+.+ requires: Object.freeze({+ appleSilicon: true,+ minUnifiedMemoryGb: 24,+ diskGb: 15,+ python: '3.11',+ }),+ upstream: 'https://github.com/microsoft/TRELLIS.2',+ // Community MPS port that makes the CUDA-only upstream run on Apple Silicon.+ port: 'https://github.com/shivampkumar/trellis-mac',+ weightsRepo: 'microsoft/TRELLIS.2-4B',+ // Wired in later phases (issue #2951); referenced by path, never imported here.+ installerModule: 'server/services/imageTo3d/trellis2Install.js',+ runnerModule: 'server/services/imageTo3d/trellis2.js',+ }),+});++/** Registry keys, for Zod enums and iteration. */+export const IMAGE_TO_3D_TARGET_IDS = Object.freeze(Object.keys(IMAGE_TO_3D_TARGETS));++/** The target selected when a request names none. */+export const DEFAULT_IMAGE_TO_3D_TARGET = 'trellis2';++/**+ * Look up a target descriptor by id.+ * @param {string} id+ * @returns {object|null} the frozen descriptor, or null when unknown.+ */+export function getTarget(id) {+ return (id && IMAGE_TO_3D_TARGETS[id]) || null;+}++/**+ * Why a target can't run on a host — or `null` when it can. Pure: the host's+ * capabilities are passed in, never probed here.+ *+ * @param {string|object} target target id or descriptor.+ * @param {{appleSilicon?: boolean, unifiedMemoryGb?: number, cuda?: boolean}} [caps]+ * @returns {string|null} a stable reason code, or null when available.+ */+export function unavailableReason(target, caps = {}) {+ const t = typeof target === 'string' ? getTarget(target) : target;+ if (!t) return 'unknown-target';+ const req = t.requires || {};+ if (t.executionLane === EXECUTION_LANE.LOCAL_MPS) {+ if (req.appleSilicon && !caps.appleSilicon) return 'requires-apple-silicon';+ if (req.minUnifiedMemoryGb && Number(caps.unifiedMemoryGb) < req.minUnifiedMemoryGb) {+ return 'insufficient-memory';+ }+ } else if (t.executionLane === EXECUTION_LANE.LOCAL_CUDA) {+ if (!caps.cuda) return 'requires-cuda';+ }+ // hosted-api has no local hardware requirement.+ return null;+}++/**+ * Is this target runnable on a host with the given capabilities? Pure.+ * @param {string|object} target+ * @param {object} [caps]+ * @returns {boolean}+ */+export function isTargetAvailable(target, caps = {}) {+ return unavailableReason(target, caps) === null;+}++/**+ * Resolve the effective target for a request. Pure — no fallback to a *different*+ * model is applied here (that's a caller policy); the requested/default target is+ * returned with an availability verdict so the caller can 400 or prompt-to-install.+ *+ * @param {string} [requestedId] the requested target id (falls back to defaultId).+ * @param {object} [caps] host capabilities (see `detectHostCapabilities`).+ * @param {{defaultId?: string}} [opts]+ * @returns {{targetId: string, target: object|null, available: boolean, reason: string|null}}+ */+export function resolveTarget(requestedId, caps = {}, { defaultId = DEFAULT_IMAGE_TO_3D_TARGET } = {}) {+ const targetId = requestedId || defaultId;+ const target = getTarget(targetId);+ if (!target) return { targetId, target: null, available: false, reason: 'unknown-target' };+ const reason = unavailableReason(target, caps);+ return { targetId, target, available: reason === null, reason };+}++/**+ * Every registered target annotated with its availability on a host — the shape+ * the API/UI consume to render a target selector with disabled/needs-install+ * states. Pure.+ * @param {object} [caps]+ * @returns {Array<object>}+ */+export function listTargets(caps = {}) {+ return IMAGE_TO_3D_TARGET_IDS.map((id) => {+ const target = IMAGE_TO_3D_TARGETS[id];+ const reason = unavailableReason(target, caps);+ return { ...target, available: reason === null, unavailableReason: reason };+ });+}++/**+ * The one impure boundary: read this machine's capabilities. Injectable so+ * routes/tests can supply deterministic values. `unifiedMemoryGb` is rounded to+ * the nearest whole GB (physical RAM reads a hair under the marketed size, so a+ * "24 GB" Mac rounds cleanly to 24 rather than tripping the floor at 23.98).+ *+ * @param {{appleSilicon?: boolean, totalMemBytes?: number, cuda?: boolean}} [overrides]+ * @returns {{appleSilicon: boolean, unifiedMemoryGb: number, cuda: boolean}}+ */+export function detectHostCapabilities({+ appleSilicon = isAppleSilicon(),+ totalMemBytes = os.totalmem(),+ cuda = false,+} = {}) {+ return {+ appleSilicon: Boolean(appleSilicon),+ unifiedMemoryGb: Math.round(Number(totalMemBytes) / 1024 ** 3),+ cuda: Boolean(cuda),+ };+}diff --git a/server/services/imageTo3d/targets.test.js b/server/services/imageTo3d/targets.test.jsnew file mode 100644index 0000000000..a7e5e79507--- /dev/null+++ b/server/services/imageTo3d/targets.test.js@@ -0,0 +1,160 @@+import { describe, expect, it } from 'vitest';+import {+ EXECUTION_LANE,+ OUTPUT_KIND,+ IMAGE_TO_3D_TARGETS,+ IMAGE_TO_3D_TARGET_IDS,+ DEFAULT_IMAGE_TO_3D_TARGET,+ getTarget,+ unavailableReason,+ isTargetAvailable,+ resolveTarget,+ listTargets,+ detectHostCapabilities,+} from './targets.js';++// A host that can run TRELLIS.2's local-MPS lane, and one that can't.+const APPLE_128GB = { appleSilicon: true, unifiedMemoryGb: 128, cuda: false };+const APPLE_16GB = { appleSilicon: true, unifiedMemoryGb: 16, cuda: false };+const INTEL_MAC = { appleSilicon: false, unifiedMemoryGb: 64, cuda: false };+const CUDA_BOX = { appleSilicon: false, unifiedMemoryGb: 64, cuda: true };++describe('image-to-3d target registry', () => {+ it('registers trellis2 as the default target with a stable descriptor shape', () => {+ expect(DEFAULT_IMAGE_TO_3D_TARGET).toBe('trellis2');+ expect(IMAGE_TO_3D_TARGET_IDS).toContain('trellis2');+ const t = getTarget('trellis2');+ expect(t).toMatchObject({+ id: 'trellis2',+ label: 'TRELLIS.2',+ executionLane: EXECUTION_LANE.LOCAL_MPS,+ outputKind: OUTPUT_KIND.GLB_MESH,+ });+ expect(t.requires).toMatchObject({ appleSilicon: true, minUnifiedMemoryGb: 24 });+ });++ it('freezes the registry and its descriptors so a target cannot be mutated at runtime', () => {+ expect(Object.isFrozen(IMAGE_TO_3D_TARGETS)).toBe(true);+ expect(Object.isFrozen(IMAGE_TO_3D_TARGETS.trellis2)).toBe(true);+ expect(() => {+ IMAGE_TO_3D_TARGETS.trellis2.label = 'hacked';+ }).toThrow();+ expect(getTarget('trellis2').label).toBe('TRELLIS.2');+ });++ it('returns null for an unknown target id', () => {+ expect(getTarget('does-not-exist')).toBeNull();+ expect(getTarget('')).toBeNull();+ expect(getTarget(undefined)).toBeNull();+ });+});++describe('unavailableReason / isTargetAvailable (local-mps gating)', () => {+ it('is available on Apple Silicon with enough memory', () => {+ expect(unavailableReason('trellis2', APPLE_128GB)).toBeNull();+ expect(isTargetAvailable('trellis2', APPLE_128GB)).toBe(true);+ });++ it('is available at exactly the memory floor', () => {+ expect(isTargetAvailable('trellis2', { appleSilicon: true, unifiedMemoryGb: 24 })).toBe(true);+ });++ it('reports requires-apple-silicon on a non-Apple-Silicon host', () => {+ expect(unavailableReason('trellis2', INTEL_MAC)).toBe('requires-apple-silicon');+ expect(isTargetAvailable('trellis2', INTEL_MAC)).toBe(false);+ });++ it('reports insufficient-memory on an under-spec Apple Silicon host', () => {+ expect(unavailableReason('trellis2', APPLE_16GB)).toBe('insufficient-memory');+ expect(isTargetAvailable('trellis2', APPLE_16GB)).toBe(false);+ });++ it('reports unknown-target for an unregistered id', () => {+ expect(unavailableReason('nope', APPLE_128GB)).toBe('unknown-target');+ expect(isTargetAvailable('nope', APPLE_128GB)).toBe(false);+ });++ it('treats absent capabilities as un-runnable rather than throwing', () => {+ expect(unavailableReason('trellis2')).toBe('requires-apple-silicon');+ expect(isTargetAvailable('trellis2', {})).toBe(false);+ });+});++describe('resolveTarget', () => {+ it('resolves the requested target when available', () => {+ expect(resolveTarget('trellis2', APPLE_128GB)).toMatchObject({+ targetId: 'trellis2',+ available: true,+ reason: null,+ });+ });++ it('falls back to the default target id when none requested', () => {+ const r = resolveTarget(undefined, APPLE_128GB);+ expect(r.targetId).toBe(DEFAULT_IMAGE_TO_3D_TARGET);+ expect(r.available).toBe(true);+ });++ it('returns the target with an unavailable verdict rather than silently swapping models', () => {+ const r = resolveTarget('trellis2', APPLE_16GB);+ expect(r.targetId).toBe('trellis2');+ expect(r.target).not.toBeNull();+ expect(r.available).toBe(false);+ expect(r.reason).toBe('insufficient-memory');+ });++ it('reports unknown-target with a null descriptor for a bad id', () => {+ const r = resolveTarget('ghost', APPLE_128GB);+ expect(r).toMatchObject({ targetId: 'ghost', target: null, available: false, reason: 'unknown-target' });+ });++ it('honors a custom defaultId', () => {+ const r = resolveTarget(undefined, APPLE_128GB, { defaultId: 'trellis2' });+ expect(r.targetId).toBe('trellis2');+ });+});++describe('listTargets', () => {+ it('annotates every registered target with availability for the host', () => {+ const available = listTargets(APPLE_128GB);+ expect(available).toHaveLength(IMAGE_TO_3D_TARGET_IDS.length);+ expect(available.find((t) => t.id === 'trellis2')).toMatchObject({+ available: true,+ unavailableReason: null,+ });++ const blocked = listTargets(CUDA_BOX);+ expect(blocked.find((t) => t.id === 'trellis2')).toMatchObject({+ available: false,+ unavailableReason: 'requires-apple-silicon',+ });+ });+});++describe('detectHostCapabilities', () => {+ it('rounds unified memory to whole GB and normalizes flags', () => {+ const caps = detectHostCapabilities({+ appleSilicon: true,+ totalMemBytes: 128 * 1024 ** 3,+ cuda: false,+ });+ expect(caps).toEqual({ appleSilicon: true, unifiedMemoryGb: 128, cuda: false });+ });++ it('rounds a hair-under-marketed RAM reading up to the marketed size', () => {+ // Physical RAM on a "24 GB" Mac reads slightly under 24*1024^3.+ const caps = detectHostCapabilities({+ appleSilicon: true,+ totalMemBytes: 24 * 1024 ** 3 - 50 * 1024 ** 2,+ cuda: false,+ });+ expect(caps.unifiedMemoryGb).toBe(24);+ expect(isTargetAvailable('trellis2', caps)).toBe(true);+ });++ it('coerces truthy non-boolean overrides to strict booleans', () => {+ const caps = detectHostCapabilities({ appleSilicon: 1, totalMemBytes: 8 * 1024 ** 3, cuda: 'yes' });+ expect(caps.appleSilicon).toBe(true);+ expect(caps.cuda).toBe(true);+ });+});