diff --git a/.github/workflows/artist-intent-experimental.yml b/.github/workflows/artist-intent-experimental.yml index 9b4355e3..75c76e5b 100644 --- a/.github/workflows/artist-intent-experimental.yml +++ b/.github/workflows/artist-intent-experimental.yml @@ -4,6 +4,9 @@ on: push: branches: - integration/artist-intent-core-2026-10-10 + - integration/live-texture-2026-10-10 + - integration/artist-intent-propagation-2026-10-10 + - integration/modly-next-full-2026-10-10 workflow_dispatch: permissions: @@ -73,6 +76,10 @@ jobs: run: node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs electron/main/storage-directory-guard.test.ts - name: Windows artist-intent regression run: node --test src/areas/workflows/nodes/intent-travel/processor.test.mjs + - name: Windows intent propagation safety tests + run: node --experimental-strip-types --test src/areas/workflows/intentPropagation.test.mjs + - name: Windows texture watcher, IPC and Three.js helper regressions + run: node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs electron/main/texture-watch-service.test.ts electron/preload/texture-watch-preload.test.ts src/areas/generate/components/liveTexture.test.ts - name: Windows main-process typecheck run: npx --no-install tsc --noEmit -p tsconfig.node.json - name: Windows built-ins typecheck diff --git a/docs/experimental-artist-intent-propagation.md b/docs/experimental-artist-intent-propagation.md new file mode 100644 index 00000000..2a5c0e58 --- /dev/null +++ b/docs/experimental-artist-intent-propagation.md @@ -0,0 +1,63 @@ +# Artist Context — Explicit Start, Automatic Stage Carry + +Source: [OmarB97's Modly #252](https://github.com/lightningpixel/modly/pull/252). +This experimental slice stacks on the standalone +[Artist Context core](https://github.com/JayceeB1/modly/pull/6). + +## What changes + +Only a workflow with the **Remember Artist Context** (intent-travel/start) +node is opted in. Its output is a staged image containing a new +\`modly.intent.v1\` sidecar. A processing stage receiving that image or a +derived image/mesh automatically runs intent-travel/carry before publishing +its output, appending a stage event and retaining the immutable request ID, +artist words, style and project. + +The goal is to preserve the original brief through: + +Image → Remember Artist Context → Style → Generator → Rig/Optimize → GLB Export + +The **Carry Artist Context** node also remains available for an explicit +source/destination transfer when a workflow cannot infer the connection. + +## Fail-closed rules + +- Workflows without an explicit start node remain unchanged. +- A generated stage never invents an original request or ancestry. +- Multiple input asset paths must **all** carry the same intent marker. + Mixed tagged/untagged files or different roots produce an explicit error + rather than silently attributing the output to the wrong source. +- Text-only edge inputs do not invalidate one tagged image/mesh. +- Processors can return the original path unchanged (e.g. Full detail); + no copy is needed then. +- If the processor fails to carry the record, the workflow returns an + error rather than declaring completion with missing metadata. +- The renderer cannot choose arbitrary artist-intent sidecar paths; + the underlying process extension rechecks physical workspace location + and sidecar size limits. +- A drag/drop image in \`selectedImageData\` can initialize the record, + with the same image size cap as the source processor. + +## Tests and evidence + +- Seven pure Node regression cases validate the decision logic for opt-in, + common origins, conflicting sources, orphaned/unmarked sources and text. +- The helper is wired into the existing Node test command and runs in + Windows and Linux checks. +- Integration compilation (Electron, TypeScript) ensures the runner and + extension signatures remain compatible. + +## Remaining acceptance work + +- [ ] Real Windows desktop run with a reference PNG and installed generators + (Style → 3D model → optimizer → exporter) +- [ ] Inspect the exported \`.tags.json\`: stable \`intent_id\`, original + sentences, stage events, project, \`derived_from\` unchanged +- [ ] Verify restart/continue and interrupted stage scenarios, including + source-output races and large inputs +- [ ] Review storage retention: staged source image copies currently remain + in \`Workflows/intent-sources\` until cleaned intentionally +- [ ] Validate compatibility with multi-input texture and scene generators + +Not an automatic change to all existing Modly workflows; **not approved for +release** until runtime smoke tests and storage retention policy are reviewed. diff --git a/docs/experimental-live-texture.md b/docs/experimental-live-texture.md new file mode 100644 index 00000000..0cc9346e --- /dev/null +++ b/docs/experimental-live-texture.md @@ -0,0 +1,46 @@ +# Experimental Live Texture Preview — upstream #252 (second slice) + +Source: [OmarB97's PR #252](https://github.com/lightningpixel/modly/pull/252). +Stacked after the explicit Artist Context experiment in [PR #6](https://github.com/JayceeB1/modly/pull/6). + +This is a **candidate**, not an approved release or a replacement for the +original upstream implementation. + +## Behavior + +An explicit "Watch texture" action opens an OS-owned PNG picker. The main +process owns the filesystem watcher per renderer and sends revisioned, bounded +PNG snapshots to the preview. Only a loaded model with a *single painted +texture* is supported; multi-texture assets are rejected with an explanation. +The texture must retain its original dimensions. + +Saving the chosen file emits a coalesced change notification; incomplete +saves are retried. Good changes are applied to the viewer, and invalid saves +show an error without discarding the previous appearance. + +## Additional guardrails relative to source PR + +- No arbitrary watch-path argument from renderer code. The OS picker chooses + the file; only the owning window receives updates. Watchers are cleaned up + on navigation/destruction and app quit. +- Maximum 32 MiB encoded PNG per read, with bounded file-handle reads and a + check for file-size/mtime changes during save. Reject direct symlink files, + oversized dimensions and non-PNG paths. +- Do not forcibly change texture filters or color space: reuse settings from + the model's original map. Restore original maps before freeing live preview + GPU textures on panel unmount; discard stale asynchronous loads. +- Unit regressions cover truncated saves, recovery, per-owner stop, + symlinks, size caps, invalid dimensions, IPC visibility, single/multiple + texture detection, map swaps, and cleanup. + +## Validation + +- [ ] Linux GitHub Actions: full Node/Python, build, lint and TypeScript gates +- [ ] Windows GitHub Actions: watcher/IPC/Three.js tests and desktop bundle +- [ ] Real interactive Electron test: preview texture edit in external editor, + incomplete save, recovery, restart, project change, GPU usage, undo/redo +- [ ] Manual large/animated/UV-transformed GLB cases and image decode failures + +This feature is an **opt-in viewer preview**, not a background image editor or +a guarantee of texture persistence into saved GLBs. It deliberately does not +automatically rewrite any user files, nor import the old global UI-zoom changes. diff --git a/docs/experimental-modly-next-combined.md b/docs/experimental-modly-next-combined.md new file mode 100644 index 00000000..b78e6a47 --- /dev/null +++ b/docs/experimental-modly-next-combined.md @@ -0,0 +1,29 @@ +# Modly Next — combined experimental preview (2026-10-10) + +This branch is the **working integration snapshot** of +[Modly Next's earlier PRs](https://github.com/JayceeB1/modly/pulls) and +the two independent parts of upstream +[OmarB97's Modly #252](https://github.com/lightningpixel/modly/pull/252): + +- **Artist Context:** opt-in \`modly.intent.v1\` record and automatic carrying + of verified intent only when the workflow contains "Remember Artist Context" + ([PR #8](https://github.com/JayceeB1/modly/pull/8)). +- **Live Texture:** OS-picked PNG watcher with bounded reads, recoverable + saves and viewer preview cleanup + ([PR #7](https://github.com/JayceeB1/modly/pull/7)). + +A two-parent Git commit combines those separately reviewed changes without +rewriting either original branch or flattening attribution. + +## Current gates + +- [ ] Run the **combined** Linux full Node, Python, lint, typecheck, build +- [ ] Run combined Windows watcher, intent, filesystem and build checks +- [ ] Real Windows desktop pilot in a disposable workspace +- [ ] Exercise a real image→model→optimizer→export workflow carrying intent +- [ ] Watch a real texture file edited in another program and verify cleanup +- [ ] Verify migration/retention of staged images and \`.tags.json\` files +- [ ] Review existing storage deletion policies before opening real user data + +This is **not** a published release. Do not merge into \`main\` or distribute +an installer without the manual gates above. diff --git a/electron/main/ipc-handlers.ts b/electron/main/ipc-handlers.ts index e1021e24..bda4cd92 100644 --- a/electron/main/ipc-handlers.ts +++ b/electron/main/ipc-handlers.ts @@ -88,6 +88,8 @@ import { import { registerWorkspaceAssetLibraryIpcHandlers } from './artifact-registry-service' import { updatesSupported } from './updater' import { ModelWeightOperations } from './model-weight-operations' +import { TextureWatchService } from './texture-watch-service' +import type { TextureWatchChoice } from '../../src/shared/types/liveTexture' import { readLocalFileBase64 } from './bounded-file-reader' import { encryptSecret, decryptSecret } from './secure-store' import { getHfToken, initHfToken, setHfToken } from './hf-token' @@ -172,6 +174,10 @@ const renameWithRetry = (from: string, to: string, label: string) => renameExtensionWithRetry(from, to, label, logger) export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGetter): void { + const textureWatchService = new TextureWatchService() + const textureWatchOwners = new Set() + app.once('before-quit', () => textureWatchService.stopAll()) + type ActiveDownload = { progress: DownloadProgress & { variantId?: string } done: Promise @@ -475,6 +481,44 @@ export function setupIpcHandlers(pythonBridge: PythonBridge, getWindow: WindowGe } }) + // Only a user-selected PNG may be monitored; the renderer cannot supply + // filesystem paths directly. One watcher is owned by each Electron renderer. + ipcMain.handle('texture:chooseAndWatch', async (event): Promise => { + const win = getWindow() + if (!win || win.webContents.isDestroyed() || event.sender.id !== win.webContents.id) { + return { cancelled: true } + } + + const result = await dialog.showOpenDialog(win, { + title: 'Choose a texture to watch', + filters: [{ name: 'PNG image', extensions: ['png'] }], + properties: ['openFile'], + }) + if (result.canceled || !result.filePaths[0]) return { cancelled: true } + + const ownerId = event.sender.id + if (!textureWatchOwners.has(ownerId)) { + textureWatchOwners.add(ownerId) + event.sender.once('destroyed', () => { + textureWatchOwners.delete(ownerId) + textureWatchService.stop(ownerId) + }) + } + + try { + const update = await textureWatchService.start(ownerId, result.filePaths[0], (next) => { + if (!event.sender.isDestroyed()) event.sender.send('texture:changed', next) + }) + return { cancelled: false, update } + } catch (err) { + return { cancelled: true, error: String(err) } + } + }) + + ipcMain.handle('texture:stopWatching', (event) => { + textureWatchService.stop(event.sender.id) + }) + // Read local file → base64 (bypasses file:// restrictions in the renderer) ipcMain.handle('fs:readFileBase64', (_, filePath: string) => readLocalFileBase64(filePath)) diff --git a/electron/main/model-weight-ipc.test.mjs b/electron/main/model-weight-ipc.test.mjs index b77d75bc..ccfeec04 100644 --- a/electron/main/model-weight-ipc.test.mjs +++ b/electron/main/model-weight-ipc.test.mjs @@ -49,12 +49,17 @@ function fixture(t) { } const stub = new Proxy({}, { get: () => () => {} }) const deps = (name) => { - if (name === 'electron') return { ipcMain: { handle: (id, fn) => handlers.set(id, fn), on: () => {} }, app: { getPath: () => root, on: () => {} } } + if (name === 'electron') return { ipcMain: { handle: (id, fn) => handlers.set(id, fn), on: () => {} }, app: { getPath: () => root, on: () => {}, once: () => {} } } if (name === 'axios') return { post: (...args) => hooks.unload(...args), get: (...args) => hooks.listModels(...args), isAxiosError: (err) => Boolean(err?.isAxiosError), } + // The storage/texture watcher is unrelated to weight removal. Do not start + // real OS watchers in this mocked Electron IPC fixture. + if (name === './texture-watch-service') return { + TextureWatchService: class { stopAll() {} stop() {} }, + } if (name === './model-sources') return realSources if (name === './model-download-plan') return realPlan if (name === './extension-path-guard') return realGuard diff --git a/electron/main/texture-watch-service.test.ts b/electron/main/texture-watch-service.test.ts new file mode 100644 index 00000000..0bde25a1 --- /dev/null +++ b/electron/main/texture-watch-service.test.ts @@ -0,0 +1,127 @@ +import assert from 'node:assert/strict' +import { mkdtemp, rm, writeFile, truncate, symlink } from 'node:fs/promises' +import { tmpdir } from 'node:os' +import { join } from 'node:path' +import test from 'node:test' + +import type { TextureWatchUpdate } from '../../src/shared/types/liveTexture.ts' +import { MAX_TEXTURE_BYTES, readPngInfo, TextureWatchService } from './texture-watch-service.ts' + +const ONE_PIXEL_PNG = Buffer.from( + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNk+A8AAQUBAScY42YAAAAASUVORK5CYII=', + 'base64', +) + +async function waitFor( + updates: TextureWatchUpdate[], + predicate: (update: TextureWatchUpdate) => boolean, + timeoutMs = 3_000, +): Promise { + const started = Date.now() + while (Date.now() - started < timeoutMs) { + const match = updates.find(predicate) + if (match) return match + await new Promise((resolve) => setTimeout(resolve, 20)) + } + throw new Error(`Timed out waiting for texture update. Saw: ${JSON.stringify(updates)}`) +} + +test('reads PNG dimensions and rejects a partial save', () => { + assert.deepEqual(readPngInfo(ONE_PIXEL_PNG), { width: 1, height: 1 }) + assert.throws( + () => readPngInfo(ONE_PIXEL_PNG.subarray(0, 24)), + /invalid PNG header|incomplete PNG file/, + ) +}) + +test('reports a malformed save, keeps watching, and recovers on the next valid save', async () => { + const dir = await mkdtemp(join(tmpdir(), 'modly-texture-watch-')) + const filePath = join(dir, 'paint.png') + const updates: TextureWatchUpdate[] = [] + const service = new TextureWatchService() + + try { + await writeFile(filePath, ONE_PIXEL_PNG) + const initial = await service.start(7, filePath, (update) => updates.push(update)) + assert.equal(initial.state, 'ready') + assert.equal(initial.width, 1) + assert.equal(initial.height, 1) + + await writeFile(filePath, Buffer.from('not an image')) + await waitFor(updates, (update) => update.state === 'reading') + const failed = await waitFor(updates, (update) => update.state === 'error') + assert.match(failed.message ?? '', /could not be read/) + + await writeFile(filePath, ONE_PIXEL_PNG) + const recovered = await waitFor( + updates, + (update) => update.state === 'ready' && update.revision > failed.revision, + ) + assert.equal(recovered.width, 1) + assert.equal(recovered.height, 1) + assert.match(recovered.dataUrl ?? '', /^data:image\/png;base64,/) + } finally { + service.stopAll() + await rm(dir, { recursive: true, force: true }) + } +}) + + +test('rejects oversized PNGs before reading their contents into memory', async () => { + const dir = await mkdtemp(join(tmpdir(), 'modly-texture-cap-')) + const file = join(dir, 'large.png') + const service = new TextureWatchService() + try { + await writeFile(file, ONE_PIXEL_PNG) + await truncate(file, MAX_TEXTURE_BYTES + 1) + const update = await service.start(1, file, () => {}) + assert.equal(update.state, 'error') + assert.match(update.message ?? '', /32 MiB/) + } finally { + service.stopAll() + await rm(dir, { recursive: true, force: true }) + } +}) + +test('rejects invalid dimensions before previewing a PNG', () => { + const invalid = Buffer.from(ONE_PIXEL_PNG) + invalid.writeUInt32BE(8193, 16) + assert.throws(() => readPngInfo(invalid), /incomplete PNG file/) +}) + +test('does not read a symlink substituted for an OS-selected texture', { + skip: process.platform === 'win32', +}, async () => { + const dir = await mkdtemp(join(tmpdir(), 'modly-texture-link-')) + const real = join(dir, 'real.png') + const alias = join(dir, 'alias.png') + const service = new TextureWatchService() + try { + await writeFile(real, ONE_PIXEL_PNG) + await symlink(real, alias) + const update = await service.start(2, alias, () => {}) + assert.equal(update.state, 'error') + } finally { + service.stopAll() + await rm(dir, { recursive: true, force: true }) + } +}) + +test('rejects non-PNG selections and releases sessions when stopped', async () => { + const dir = await mkdtemp(join(tmpdir(), 'modly-texture-stop-')) + const file = join(dir, 'asset.png') + const service = new TextureWatchService() + try { + await writeFile(file, ONE_PIXEL_PNG) + await assert.rejects(() => service.start(8, join(dir, 'asset.jpg'), () => {}), /PNG files/) + const updates: TextureWatchUpdate[] = [] + assert.equal((await service.start(8, file, (x) => updates.push(x))).state, 'ready') + service.stop(8) + await writeFile(file, Buffer.from('invalid')) + await new Promise((resolve) => setTimeout(resolve, 300)) + assert.equal(updates.length, 0) + } finally { + service.stopAll() + await rm(dir, { recursive: true, force: true }) + } +}) diff --git a/electron/main/texture-watch-service.ts b/electron/main/texture-watch-service.ts new file mode 100644 index 00000000..f97c410c --- /dev/null +++ b/electron/main/texture-watch-service.ts @@ -0,0 +1,201 @@ +import { watch as watchDirectory, type FSWatcher } from 'node:fs' +import { lstat, open } from 'node:fs/promises' +import { basename, dirname, extname } from 'node:path' + +import type { TextureWatchUpdate } from '../../src/shared/types/liveTexture' + +const PNG_SIGNATURE = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10]) +const PNG_END = Buffer.from([0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130]) +// The renderer receives data URLs; a hard cap prevents unlimited IPC/memory use. +export const MAX_TEXTURE_BYTES = 32 * 1024 * 1024 +const MAX_TEXTURE_DIMENSION = 8192 +const SAVE_SETTLE_MS = 60 +const RETRY_MS = 120 +const MAX_READ_ATTEMPTS = 6 + +interface WatchedTexture { + ownerId: number + filePath: string + fileName: string + revision: number + watcher: FSWatcher + timer: ReturnType | null + send: (update: TextureWatchUpdate) => void +} + +export interface PngInfo { + width: number + height: number +} + +export function readPngInfo(buffer: Buffer): PngInfo { + if ( + buffer.length < 33 + || !buffer.subarray(0, PNG_SIGNATURE.length).equals(PNG_SIGNATURE) + || buffer.toString('ascii', 12, 16) !== 'IHDR' + || buffer.readUInt32BE(8) !== 13 + ) { + throw new Error('invalid PNG header') + } + + const width = buffer.readUInt32BE(16) + const height = buffer.readUInt32BE(20) + if (width < 1 || height < 1 + || width > MAX_TEXTURE_DIMENSION || height > MAX_TEXTURE_DIMENSION + || !buffer.subarray(-PNG_END.length).equals(PNG_END)) { + throw new Error('incomplete PNG file') + } + + return { width, height } +} + +export class TextureWatchService { + private sessions = new Map() + + async start( + ownerId: number, + filePath: string, + send: (update: TextureWatchUpdate) => void, + ): Promise { + if (extname(filePath).toLowerCase() !== '.png') { + throw new Error('Live texture updates currently support PNG files.') + } + + this.stop(ownerId) + + const fileName = basename(filePath) + const session: WatchedTexture = { + ownerId, + filePath, + fileName, + revision: 0, + watcher: watchDirectory(dirname(filePath), (_eventType, changedName) => { + if (changedName && changedName.toString() !== fileName) return + this.queueRead(session) + }), + timer: null, + send, + } + session.watcher.on('error', () => { + if (this.sessions.get(ownerId) !== session) return + const revision = ++session.revision + send({ + state: 'error', + filePath, + fileName, + revision, + changedAt: Date.now(), + message: 'Texture watching stopped because the file could not be watched. Choose it again to retry.', + }) + this.stop(ownerId) + }) + this.sessions.set(ownerId, session) + + const revision = ++session.revision + return this.readUpdate(session, revision) + } + + stop(ownerId: number): void { + const session = this.sessions.get(ownerId) + if (!session) return + this.sessions.delete(ownerId) + if (session.timer) clearTimeout(session.timer) + session.watcher.close() + } + + stopAll(): void { + for (const ownerId of [...this.sessions.keys()]) this.stop(ownerId) + } + + private queueRead(session: WatchedTexture): void { + if (this.sessions.get(session.ownerId) !== session) return + const revision = ++session.revision + if (session.timer) clearTimeout(session.timer) + session.send({ + state: 'reading', + filePath: session.filePath, + fileName: session.fileName, + revision, + changedAt: Date.now(), + message: 'Checking the saved texture…', + }) + session.timer = setTimeout(() => { + session.timer = null + void this.publishAfterSave(session, revision, 0) + }, SAVE_SETTLE_MS) + } + + private async publishAfterSave( + session: WatchedTexture, + revision: number, + attempt: number, + ): Promise { + if (this.sessions.get(session.ownerId) !== session || session.revision !== revision) return + + const update = await this.readUpdate(session, revision) + if (this.sessions.get(session.ownerId) !== session || session.revision !== revision) return + session.send(update) + + if (update.state === 'error' && attempt + 1 < MAX_READ_ATTEMPTS) { + session.timer = setTimeout(() => { + session.timer = null + void this.publishAfterSave(session, revision, attempt + 1) + }, RETRY_MS) + } + } + + private async readUpdate(session: WatchedTexture, revision: number): Promise { + const changedAt = Date.now() + try { + // Only OS-selected PNGs are watched. Do not follow a symlink swapped in + // between saves, and do not allocate based on an unbounded file size. + const pathStat = await lstat(session.filePath) + if (!pathStat.isFile() || pathStat.isSymbolicLink()) { + throw new Error('Texture is no longer a regular file') + } + const handle = await open(session.filePath, 'r') + let buffer: Buffer + let fileStat: Awaited> + try { + fileStat = await handle.stat() + if (!fileStat.isFile() || fileStat.size < 33 || fileStat.size > MAX_TEXTURE_BYTES) { + throw new Error('Texture exceeds the 32 MiB file limit or is empty') + } + buffer = Buffer.alloc(fileStat.size) + let offset = 0 + while (offset < buffer.length) { + const { bytesRead } = await handle.read(buffer, offset, buffer.length - offset, offset) + if (bytesRead === 0) throw new Error('Incomplete texture save') + offset += bytesRead + } + const after = await handle.stat() + if (after.size !== fileStat.size || after.mtimeMs !== fileStat.mtimeMs) { + throw new Error('Texture changed during a read') + } + } finally { + await handle.close() + } + const { width, height } = readPngInfo(buffer) + return { + state: 'ready', + filePath: session.filePath, + fileName: session.fileName, + revision, + changedAt, + savedAt: fileStat.mtimeMs, + width, + height, + dataUrl: `data:image/png;base64,${buffer.toString('base64')}`, + } + } catch { + return { + state: 'error', + filePath: session.filePath, + fileName: session.fileName, + revision, + changedAt, + message: 'The PNG could not be read (incomplete save, invalid image, or over 32 MiB).', + } + } + } +} diff --git a/electron/preload/electron-api.ts b/electron/preload/electron-api.ts index b6629e36..cd75ce2f 100644 --- a/electron/preload/electron-api.ts +++ b/electron/preload/electron-api.ts @@ -7,6 +7,7 @@ import type { AssetLibraryThumbnailRequest, AssetLibraryThumbnailResult, } from '../../src/shared/types/assetLibrary' +import type { TextureWatchChoice, TextureWatchUpdate } from '../../src/shared/types/liveTexture' export interface IpcRendererLike { invoke(channel: string, ...args: unknown[]): Promise @@ -107,6 +108,17 @@ export function createElectronApi(ipcRenderer: IpcRendererLike, webFrame: WebFra ipcRenderer.invoke('fs:readScreenshotDataUrl', filename) as Promise, }, + texture: { + chooseAndWatch: (): Promise => + ipcRenderer.invoke('texture:chooseAndWatch') as Promise, + stopWatching: (): Promise => + ipcRenderer.invoke('texture:stopWatching') as Promise, + onChange: (cb: (update: TextureWatchUpdate) => void) => { + ipcRenderer.on('texture:changed', (_event, update) => cb(update as TextureWatchUpdate)) + }, + offChange: () => ipcRenderer.removeAllListeners('texture:changed'), + }, + // Secure storage — OS-level encryption for secrets (API keys, …) secureStore: { encrypt: (plainText: string): Promise => ipcRenderer.invoke('secure:encrypt', plainText) as Promise, diff --git a/electron/preload/texture-watch-preload.test.ts b/electron/preload/texture-watch-preload.test.ts new file mode 100644 index 00000000..b6b84c51 --- /dev/null +++ b/electron/preload/texture-watch-preload.test.ts @@ -0,0 +1,39 @@ +import assert from 'node:assert/strict' +import test from 'node:test' + +import type { TextureWatchUpdate } from '../../src/shared/types/liveTexture.ts' +import { createElectronApi } from './electron-api.ts' + +test('renderer sees only scoped texture watching, never a file path argument', async () => { + const invoked: Array<{ channel: string; args: unknown[] }> = [] + const listeners = new Map void>() + const api = createElectronApi({ + invoke: async (channel, ...args) => { + invoked.push({ channel, args }) + return channel === 'texture:chooseAndWatch' + ? { cancelled: false, update: { state: 'reading', revision: 1, filePath: 'chosen.png' } } + : undefined + }, + send: () => undefined, + on: (name, listener) => { listeners.set(name, listener) }, + removeAllListeners: (name) => { listeners.delete(name) }, + }, { setZoomFactor: () => undefined }, { getPathForFile: () => '' }) + + const choice = await api.texture.chooseAndWatch() + assert.equal(choice.cancelled, false) + await api.texture.stopWatching() + assert.deepEqual(invoked, [ + { channel: 'texture:chooseAndWatch', args: [] }, + { channel: 'texture:stopWatching', args: [] }, + ]) + let received: TextureWatchUpdate | null = null + api.texture.onChange((update) => { received = update }) + const update: TextureWatchUpdate = { + state: 'ready', fileName: 'texture.png', filePath: 'texture.png', + revision: 2, changedAt: 1, width: 2, height: 2, + } + listeners.get('texture:changed')?.({}, update) + assert.deepEqual(received, update) + api.texture.offChange() + assert.equal(listeners.has('texture:changed'), false) +}) diff --git a/package.json b/package.json index 7d26c1ba..358ba026 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "prepare-resources": "node scripts/download-python-embed.js", "test": "npm run test:py && npm run test:node", "test:py": "node scripts/run-pytests.mjs", - "test:node": "node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs src/shared/types/assetLibrary.test.ts src/areas/generate/assetLibraryProjection.test.ts src/areas/generate/assetLibraryService.test.ts src/areas/generate/assetLibraryUi.test.ts src/areas/generate/orcaSlicerLink.test.ts electron/main/artifact-registry-service.test.ts electron/main/extension-path-guard.test.ts electron/main/storage-directory-guard.test.ts electron/preload/artifact-registry-preload.test.ts && node --test electron/main/*.test.mjs src/**/*.test.mjs && node --experimental-strip-types --test src/areas/workflows/workflowParamBindings.test.mjs src/areas/workflows/nodes/mesh-exporter/lineage.test.mjs && node --test src/areas/workflows/nodes/intent-travel/processor.test.mjs", + "test:node": "node --test --experimental-strip-types --experimental-loader ./scripts/node-ts-extensionless-loader.mjs src/shared/types/assetLibrary.test.ts src/areas/generate/assetLibraryProjection.test.ts src/areas/generate/assetLibraryService.test.ts src/areas/generate/assetLibraryUi.test.ts src/areas/generate/components/liveTexture.test.ts src/areas/generate/orcaSlicerLink.test.ts electron/main/artifact-registry-service.test.ts electron/main/extension-path-guard.test.ts electron/main/storage-directory-guard.test.ts electron/main/texture-watch-service.test.ts electron/preload/artifact-registry-preload.test.ts electron/preload/texture-watch-preload.test.ts && node --test electron/main/*.test.mjs src/**/*.test.mjs && node --experimental-strip-types --test src/areas/workflows/workflowParamBindings.test.mjs src/areas/workflows/nodes/mesh-exporter/lineage.test.mjs && node --test src/areas/workflows/nodes/intent-travel/processor.test.mjs && node --experimental-strip-types --test src/areas/workflows/intentPropagation.test.mjs", "package": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false npm run build && npm run prepare-resources && electron-builder", "package:mac": "cross-env CSC_IDENTITY_AUTO_DISCOVERY=false npm run build && npm run prepare-resources && electron-builder --mac --arm64", "lint": "eslint ." diff --git a/src/areas/generate/components/LiveTexturePanel.tsx b/src/areas/generate/components/LiveTexturePanel.tsx new file mode 100644 index 00000000..1aeec58e --- /dev/null +++ b/src/areas/generate/components/LiveTexturePanel.tsx @@ -0,0 +1,232 @@ +import { useCallback, useEffect, useRef, useState } from 'react' +import * as THREE from 'three' + +import type { TextureWatchUpdate } from '@shared/types/liveTexture' +import { + findLiveTextureTarget, + prepareLiveTexture, + replaceLiveTexture, + restoreLiveTexture, + type LiveTextureTarget, +} from './liveTexture' + +type PanelState = + | { kind: 'idle' } + | { kind: 'reading'; fileName: string; message: string } + | { kind: 'watching'; fileName: string; updatedAt: number } + | { kind: 'error'; fileName?: string; message: string } + +interface LiveTexturePanelProps { + object: THREE.Object3D | null + onApplied: () => void +} + +function timeLabel(value: number): string { + return new Date(value).toLocaleTimeString([], { + hour: 'numeric', + minute: '2-digit', + second: '2-digit', + }) +} + +export default function LiveTexturePanel({ object, onApplied }: LiveTexturePanelProps): JSX.Element { + const [watching, setWatching] = useState(false) + const [panel, setPanel] = useState({ kind: 'idle' }) + const latestRevision = useRef(0) + const latestTexture = useRef(null) + const targetRef = useRef(null) + // Unmount/stop invalidates in-flight TextureLoader promises. + const epochRef = useRef(0) + const pickerPending = useRef(false) + + const acceptUpdate = useCallback(async (update: TextureWatchUpdate): Promise => { + const epoch = epochRef.current + if (update.revision < latestRevision.current) return + latestRevision.current = update.revision + + if (update.state === 'reading') { + setPanel({ + kind: 'reading', + fileName: update.fileName, + message: update.message ?? 'Checking the saved texture…', + }) + return + } + if (update.state === 'error') { + setPanel({ + kind: 'error', + fileName: update.fileName, + message: update.message ?? 'The saved texture could not be read.', + }) + return + } + + const found = object ? findLiveTextureTarget(object) : null + if (!found?.ok) { + setPanel({ + kind: 'error', + fileName: update.fileName, + message: found?.message ?? 'The model is not ready for texture updates.', + }) + return + } + + const { target } = found + if (update.width !== target.width || update.height !== target.height) { + setPanel({ + kind: 'error', + fileName: update.fileName, + message: `This texture is ${update.width ?? '?'} × ${update.height ?? '?'}. The model uses ${target.width} × ${target.height}. Save it at ${target.width} × ${target.height} to update the preview.`, + }) + return + } + if (!update.dataUrl) { + setPanel({ + kind: 'error', + fileName: update.fileName, + message: 'The saved texture was empty and the preview was not updated.', + }) + return + } + + let texture: THREE.Texture + try { + texture = await new THREE.TextureLoader().loadAsync(update.dataUrl) + } catch { + if (update.revision !== latestRevision.current) return + setPanel({ + kind: 'error', + fileName: update.fileName, + message: 'The saved texture could not be opened. It may still be saving or the file may be damaged.', + }) + return + } + + if (update.revision !== latestRevision.current || epoch !== epochRef.current) { + texture.dispose() + return + } + + prepareLiveTexture(texture, target.texture) + replaceLiveTexture(target, texture) + // All materials have been updated before disposing the previous GPU map. + latestTexture.current?.dispose() + latestTexture.current = texture + targetRef.current = target + onApplied() + + const appliedAt = Date.now() + setPanel({ kind: 'watching', fileName: update.fileName, updatedAt: appliedAt }) + window.dispatchEvent(new CustomEvent('modly:texture-updated', { + detail: { + filePath: update.filePath, + revision: update.revision, + detectedAt: update.changedAt, + savedAt: update.savedAt, + appliedAt, + }, + })) + }, [object, onApplied]) + + useEffect(() => { + window.electron.texture.onChange(acceptUpdate) + return () => window.electron.texture.offChange() + }, [acceptUpdate]) + + useEffect(() => () => { + epochRef.current += 1 + void window.electron.texture.stopWatching() + if (latestTexture.current && targetRef.current) { + restoreLiveTexture(targetRef.current, latestTexture.current) + latestTexture.current.dispose() + } + latestTexture.current = null + targetRef.current = null + }, []) + + const toggleWatching = async (): Promise => { + if (pickerPending.current) return + if (watching) { + epochRef.current += 1 + try { + await window.electron.texture.stopWatching() + } finally { + setWatching(false) + setPanel({ kind: 'idle' }) + latestRevision.current = 0 + } + return + } + + const found = object ? findLiveTextureTarget(object) : null + if (!found?.ok) { + setPanel({ + kind: 'error', + message: found?.message ?? 'The model is not ready for texture updates.', + }) + return + } + + pickerPending.current = true + try { + const choice = await window.electron.texture.chooseAndWatch() + if (choice.cancelled) { + if (choice.error) setPanel({ kind: 'error', message: choice.error }) + return + } + latestRevision.current = 0 + setWatching(true) + await acceptUpdate(choice.update) + } catch (err) { + setPanel({ kind: 'error', message: String(err) }) + } finally { + pickerPending.current = false + } + } + + return ( +
+ + + {panel.kind !== 'idle' && ( +
+

+ {panel.kind === 'error' + ? 'Texture not updated' + : panel.kind === 'reading' + ? `Checking ${panel.fileName}` + : `Watching ${panel.fileName}`} +

+

+ {panel.kind === 'watching' + ? `Updated ${timeLabel(panel.updatedAt)}` + : panel.message} +

+
+ )} +
+ ) +} diff --git a/src/areas/generate/components/Viewer3D.tsx b/src/areas/generate/components/Viewer3D.tsx index 40ba726e..934c309b 100644 --- a/src/areas/generate/components/Viewer3D.tsx +++ b/src/areas/generate/components/Viewer3D.tsx @@ -21,6 +21,7 @@ import { useGeneration } from '@shared/hooks/useGeneration' import { useAppStore } from '@shared/stores/appStore' import { ViewerToolbar, type ViewMode } from './ViewerToolbar' import { MotionBar, type MotionClip } from './MotionBar' +import LiveTexturePanel from './LiveTexturePanel' import type { LightSettings, PointLight } from '@shared/stores/appStore' import { DEFAULT_LIGHT_SETTINGS } from '@shared/stores/appStore' @@ -1391,6 +1392,14 @@ export default function Viewer3D({ /> )} + {modelUrl && !isSplat && ( + setViewMode('solid')} + /> + )} + {/* Bottom-left overlays — mesh stats and the motion bar */} {(meshStats || clips.length > 0) && (
diff --git a/src/areas/generate/components/liveTexture.test.ts b/src/areas/generate/components/liveTexture.test.ts new file mode 100644 index 00000000..29bc3c2a --- /dev/null +++ b/src/areas/generate/components/liveTexture.test.ts @@ -0,0 +1,88 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import * as THREE from 'three' + +import { + findLiveTextureTarget, + prepareLiveTexture, + replaceLiveTexture, + restoreLiveTexture, +} from './liveTexture.ts' + +function texture(width = 2, height = 2): THREE.DataTexture { + return new THREE.DataTexture(new Uint8Array(width * height * 4), width, height) +} + +test('finds one shared painted texture and replaces every material that uses it', () => { + const original = texture() + const first = new THREE.MeshBasicMaterial({ map: original }) + const second = new THREE.MeshBasicMaterial({ map: original }) + const group = new THREE.Group() + group.add( + new THREE.Mesh(new THREE.BoxGeometry(), first), + new THREE.Mesh(new THREE.BoxGeometry(), second), + ) + + const found = findLiveTextureTarget(group) + assert.equal(found.ok, true) + if (!found.ok) return + assert.equal(found.target.width, 2) + assert.equal(found.target.height, 2) + assert.equal(found.target.materials.length, 2) + + original.flipY = false + original.wrapS = THREE.RepeatWrapping + original.wrapT = THREE.MirroredRepeatWrapping + const replacement = texture() + prepareLiveTexture(replacement, original) + replaceLiveTexture(found.target, replacement) + + assert.equal(first.map, replacement) + assert.equal(second.map, replacement) + assert.equal(replacement.flipY, false) + assert.equal(replacement.wrapS, THREE.RepeatWrapping) + assert.equal(replacement.wrapT, THREE.MirroredRepeatWrapping) + assert.equal(replacement.magFilter, original.magFilter) + assert.equal(replacement.minFilter, original.minFilter) + assert.equal(replacement.generateMipmaps, original.generateMipmaps) + assert.equal(replacement.colorSpace, original.colorSpace) + restoreLiveTexture(found.target, replacement) + assert.equal(first.map, original) + assert.equal(second.map, original) +}) + +test('fails visibly when a model has more than one painted texture', () => { + const group = new THREE.Group() + group.add( + new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshBasicMaterial({ map: texture() })), + new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshBasicMaterial({ map: texture() })), + ) + + const found = findLiveTextureTarget(group) + assert.equal(found.ok, false) + if (found.ok) return + assert.match(found.message, /more than one painted texture/) +}) + + +test('does not restore maps that were replaced independently by another editor', () => { + const base = texture() + const independent = texture() + const preview = texture() + const material = new THREE.MeshBasicMaterial({ map: base }) + const mesh = new THREE.Mesh(new THREE.BoxGeometry(), material) + const target = findLiveTextureTarget(mesh) + assert.equal(target.ok, true) + if (!target.ok) return + replaceLiveTexture(target.target, preview) + material.map = independent + restoreLiveTexture(target.target, preview) + assert.equal(material.map, independent) +}) + +test('rejects an untextured model without allocating a new map', () => { + const mesh = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshBasicMaterial()) + const found = findLiveTextureTarget(mesh) + assert.equal(found.ok, false) + if (!found.ok) assert.match(found.message, /no painted texture/) +}) diff --git a/src/areas/generate/components/liveTexture.ts b/src/areas/generate/components/liveTexture.ts new file mode 100644 index 00000000..0e631430 --- /dev/null +++ b/src/areas/generate/components/liveTexture.ts @@ -0,0 +1,111 @@ +import * as THREE from 'three' + +type PaintedMaterial = THREE.Material & { map: THREE.Texture | null } + +export interface LiveTextureTarget { + texture: THREE.Texture + materials: PaintedMaterial[] + width: number + height: number +} + +export type LiveTextureTargetResult = + | { ok: true; target: LiveTextureTarget } + | { ok: false; message: string } + +function materialList(value: THREE.Material | THREE.Material[]): THREE.Material[] { + return Array.isArray(value) ? value : [value] +} + +function hasPaintedTexture(material: THREE.Material): material is PaintedMaterial { + return 'map' in material && material.map instanceof THREE.Texture +} + +function textureSize(texture: THREE.Texture): { width: number; height: number } | null { + const image = texture.image as { width?: unknown; height?: unknown } | undefined + const width = Number(image?.width) + const height = Number(image?.height) + return Number.isFinite(width) && Number.isFinite(height) && width > 0 && height > 0 + ? { width, height } + : null +} + +export function findLiveTextureTarget(object: THREE.Object3D): LiveTextureTargetResult { + const materials = new Set() + const textures = new Set() + + object.traverse((child) => { + if (!(child instanceof THREE.Mesh)) return + const original = child.userData.originalMaterial as THREE.Material | THREE.Material[] | undefined + const source = original ?? child.material + for (const material of materialList(source)) { + if (!hasPaintedTexture(material) || !material.map) continue + materials.add(material) + textures.add(material.map) + } + }) + + if (textures.size === 0) { + return { ok: false, message: 'This model has no painted texture to update.' } + } + if (textures.size > 1) { + return { + ok: false, + message: 'This model uses more than one painted texture. Live updates currently work with one texture at a time.', + } + } + + const texture = [...textures][0] + const size = textureSize(texture) + if (!size) { + return { ok: false, message: 'The model texture size could not be read.' } + } + + return { + ok: true, + target: { + texture, + materials: [...materials].filter((material) => material.map === texture), + width: size.width, + height: size.height, + }, + } +} + +export function prepareLiveTexture(texture: THREE.Texture, source: THREE.Texture): void { + texture.name = source.name + texture.wrapS = source.wrapS + texture.wrapT = source.wrapT + texture.flipY = source.flipY + texture.channel = source.channel + texture.offset.copy(source.offset) + texture.repeat.copy(source.repeat) + texture.center.copy(source.center) + texture.rotation = source.rotation + texture.matrixAutoUpdate = source.matrixAutoUpdate + texture.matrix.copy(source.matrix) + // Respect the original asset's sampling and color-space settings. Forcing + // nearest-neighbor globally made realistic GLBs visibly pixelated. + texture.colorSpace = source.colorSpace + texture.magFilter = source.magFilter + texture.minFilter = source.minFilter + texture.generateMipmaps = source.generateMipmaps + texture.anisotropy = source.anisotropy + texture.needsUpdate = true +} + +export function replaceLiveTexture(target: LiveTextureTarget, texture: THREE.Texture): void { + for (const material of target.materials) { + material.map = texture + material.needsUpdate = true + } +} + +/** Restore the asset's original map when a live-preview panel unmounts. */ +export function restoreLiveTexture(target: LiveTextureTarget, preview: THREE.Texture): void { + for (const material of target.materials) { + if (material.map !== preview) continue + material.map = target.texture + material.needsUpdate = true + } +} diff --git a/src/areas/workflows/intentPropagation.test.mjs b/src/areas/workflows/intentPropagation.test.mjs new file mode 100644 index 00000000..a34b9169 --- /dev/null +++ b/src/areas/workflows/intentPropagation.test.mjs @@ -0,0 +1,49 @@ +import assert from 'node:assert/strict' +import test from 'node:test' +import { assessIntentSources } from './intentPropagation.ts' + +test('opt-out workflows do not receive arbitrary artist intent', () => { + assert.deepEqual(assessIntentSources([]), { source: undefined, conflict: false }) + assert.deepEqual(assessIntentSources([{ filePath: 'external.glb' }]), { source: undefined, conflict: false }) +}) + +test('a single stamped asset propagates its own request', () => { + assert.deepEqual(assessIntentSources([ + { filePath: 'stage.png', intentAssetPath: 'stage.png' }, + ]), { source: 'stage.png', conflict: false }) +}) + +test('two matching stamped copies remain attributable to the same request', () => { + assert.deepEqual(assessIntentSources([ + { filePath: 'stage1.glb', intentAssetPath: 'root.png' }, + { filePath: 'stage2.glb', intentAssetPath: 'root.png' }, + ]), { source: 'root.png', conflict: false }) +}) + +test('two distinct stamped assets fail closed rather than forging ownership', () => { + assert.deepEqual(assessIntentSources([ + { filePath: 'first.glb', intentAssetPath: 'first.png' }, + { filePath: 'second.glb', intentAssetPath: 'second.png' }, + ]), { source: undefined, conflict: true }) +}) + +test('a mixed stamped and unstamped image is an explicit conflict', () => { + assert.deepEqual(assessIntentSources([ + { filePath: 'stamped.glb', intentAssetPath: 'stamped.glb' }, + { filePath: 'other.png' }, + ]), { source: undefined, conflict: true }) +}) + +test('non-file text inputs do not erase attached intent', () => { + assert.deepEqual(assessIntentSources([ + { filePath: 'staged.png', intentAssetPath: 'staged.png' }, + { filePath: undefined }, + undefined, + ]), { source: 'staged.png', conflict: false }) +}) + +test('blank metadata markers are not treated as a source', () => { + assert.deepEqual(assessIntentSources([ + { filePath: 'model.glb', intentAssetPath: '' }, + ]), { source: undefined, conflict: false }) +}) diff --git a/src/areas/workflows/intentPropagation.ts b/src/areas/workflows/intentPropagation.ts new file mode 100644 index 00000000..1ffb5786 --- /dev/null +++ b/src/areas/workflows/intentPropagation.ts @@ -0,0 +1,26 @@ +/** + * Pure, fail-closed resolver for artists' intent provenance across workflow + * edges. A text-only input never dilutes an asset's intent. + */ +export interface IntentBearingOutput { + filePath?: string + intentAssetPath?: string +} + +export type IntentSourceDecision = + | { source: string; conflict: false } + | { source: undefined; conflict: boolean } + +export function assessIntentSources( + inputs: readonly (IntentBearingOutput | undefined)[], +): IntentSourceDecision { + const assets = inputs.filter((value): value is IntentBearingOutput => + typeof value?.filePath === 'string' && value.filePath.length > 0) + const tagged = assets.filter((value) => typeof value.intentAssetPath === 'string' + && value.intentAssetPath.length > 0) + if (tagged.length === 0) return { source: undefined, conflict: false } + if (tagged.length !== assets.length) return { source: undefined, conflict: true } + const sources = new Set(tagged.map((value) => value.intentAssetPath!)) + if (sources.size !== 1) return { source: undefined, conflict: true } + return { source: [...sources][0], conflict: false } +} diff --git a/src/areas/workflows/workflowRunStore.ts b/src/areas/workflows/workflowRunStore.ts index 81346431..35517dea 100644 --- a/src/areas/workflows/workflowRunStore.ts +++ b/src/areas/workflows/workflowRunStore.ts @@ -9,6 +9,7 @@ import type { Workflow, WFNode, WFEdge } from '@shared/types/electron.d' import { isBranchStarter, isSceneOutput, resolveDataSource, reachesSceneOutput, nearestUpstreamWaits } from './nodeBehaviors' import { assignSlotFilePaths } from './slotInputs' import { resolveBoundWorkflowParams } from './workflowParamBindings' +import { assessIntentSources } from './intentPropagation' import type { SlotInputType } from './slotInputs' // ─── Types ──────────────────────────────────────────────────────────────────── @@ -49,7 +50,32 @@ function flushResume(): void { if (fn) fn() } -interface NodeOutput { filePath?: string; text?: string; outputType?: string; sourceAssetPath?: string } +interface NodeOutput { filePath?: string; text?: string; outputType?: string; sourceAssetPath?: string; intentAssetPath?: string } + +/** Carry only an explicitly initiated modly.intent.v1 across generated assets. */ +async function carryArtistIntent( + sourcePath: string, + destinationPath: string, + node: WFNode, + ext: WorkflowExtension, +): Promise { + const result = await window.electron.extensions.runProcess( + 'intent-travel', + { filePath: sourcePath, nodeId: 'carry' }, + { + destinationPath, + stage: node.data.label ?? ext.name, + details: { + node_id: node.id, + extension_id: node.data.extensionId ?? null, + output_type: ext.output, + }, + }, + ) + if (!result.success || !result.result?.filePath) { + throw new Error(result.error ?? 'Artist context could not be carried to the next stage') + } +} function isSceneMeshOutput(output: NodeOutput | undefined): output is NodeOutput & { filePath: string } { return output?.outputType === 'mesh' && typeof output.filePath === 'string' @@ -348,6 +374,10 @@ async function executeExtensionNode( const nodeInputSourceAssetPath = distinctSources.size === 1 ? [...distinctSources][0] : undefined const incomingEdges = workflow.edges.filter((e) => e.target === node.id) + const intentDecision = assessIntentSources(incomingEdges.map((edge) => resolveSource(edge.source))) + if (intentDecision.conflict) { + throw new Error('Artist context has ambiguous inputs. Use a single staged source instead of silently losing attribution.') + } if (ext?.inputs && ext.inputs.length > 1) { // Scene is intentionally a single-input-only model contract. The guard @@ -480,8 +510,12 @@ async function executeExtensionNode( useAppStore.getState().updateCurrentJob({ status: 'generating', progress: st.progress, step: st.step }) } } else { + const isIntentStart = ext?.extensionId === 'intent-travel' && ext?.nodeId === 'start' + if (isIntentStart && !nodeInputPath && selectedImageData) nodeInputText = selectedImageData if (ext?.input === 'mesh' && !nodeInputPath) throw new Error(`${ext.name} needs an incoming mesh connection`) - if (ext?.input === 'image' && !nodeInputPath) throw new Error(`${ext.name} needs an incoming image connection`) + if (ext?.input === 'image' && !nodeInputPath && !(isIntentStart && selectedImageData)) { + throw new Error(`${ext.name} needs an incoming image connection`) + } if (ext?.input === 'audio' && !nodeInputPath) throw new Error(`${ext.name} needs an incoming audio connection`) if (ext?.input === 'text' && !nodeInputText) throw new Error(`${ext.name} needs an incoming text connection`) @@ -518,7 +552,25 @@ async function executeExtensionNode( } const outputType = ext?.output ?? (nodeInputPath ? 'mesh' : undefined) - nodeOutputs.set(node.id, { filePath: nodeInputPath, text: nodeInputText, outputType, sourceAssetPath: nodeInputSourceAssetPath }) + const isArtistStart = ext?.extensionId === 'intent-travel' && ext.nodeId === 'start' + const isArtistCarry = ext?.extensionId === 'intent-travel' && ext.nodeId === 'carry' + let outputIntentPath: string | undefined + if ((isArtistStart || isArtistCarry) && nodeInputPath) { + // The explicit process node verified/created its modly.intent.v1 sidecar. + outputIntentPath = nodeInputPath + } else if ( + intentDecision.source && nodeInputPath && ext + && (outputType === 'image' || outputType === 'mesh') + ) { + if (intentDecision.source !== nodeInputPath) { + await carryArtistIntent(intentDecision.source, nodeInputPath, node, ext) + } + outputIntentPath = nodeInputPath + } + nodeOutputs.set(node.id, { + filePath: nodeInputPath, text: nodeInputText, outputType, + sourceAssetPath: nodeInputSourceAssetPath, intentAssetPath: outputIntentPath, + }) const output = nodeOutputs.get(node.id) const url = isSceneMeshOutput(output) ? toWorkspaceUrl(output.filePath, workspaceDir) : undefined diff --git a/src/shared/types/electron.d.ts b/src/shared/types/electron.d.ts index 56c748b9..1e802e5d 100644 --- a/src/shared/types/electron.d.ts +++ b/src/shared/types/electron.d.ts @@ -10,6 +10,7 @@ import type { AssetLibraryThumbnailRequest, AssetLibraryThumbnailResult, } from './assetLibrary' +import type { TextureWatchChoice, TextureWatchUpdate } from './liveTexture' // ─── Extension types ────────────────────────────────────────────────────────── @@ -226,6 +227,12 @@ declare global { deleteDirectory: (dirPath: string) => Promise<{ success: boolean; error?: string }> readScreenshotDataUrl: (filename: string) => Promise } + texture: { + chooseAndWatch: () => Promise + stopWatching: () => Promise + onChange: (cb: (update: TextureWatchUpdate) => void) => void + offChange: () => void + } settings: { get: () => Promise<{ modelsDir: string; workspaceDir: string; workflowsDir: string; extensionsDir: string; hfToken?: string }> set: (patch: { modelsDir?: string; workspaceDir?: string; workflowsDir?: string; extensionsDir?: string; hfToken?: string }) => Promise<{ modelsDir: string; workspaceDir: string; workflowsDir: string; extensionsDir: string; hfToken?: string }> diff --git a/src/shared/types/liveTexture.ts b/src/shared/types/liveTexture.ts new file mode 100644 index 00000000..655cdc1b --- /dev/null +++ b/src/shared/types/liveTexture.ts @@ -0,0 +1,17 @@ +export type TextureWatchState = 'reading' | 'ready' | 'error' + +export interface TextureWatchUpdate { + state: TextureWatchState + filePath: string + fileName: string + revision: number + changedAt: number + savedAt?: number + width?: number + height?: number + dataUrl?: string + message?: string +} +export type TextureWatchChoice = + | { cancelled: true; error?: string } + | { cancelled: false; update: TextureWatchUpdate } diff --git a/tsconfig.node.json b/tsconfig.node.json index 6c6d0934..65f86df4 100644 --- a/tsconfig.node.json +++ b/tsconfig.node.json @@ -23,6 +23,7 @@ "electron.vite.config.*", "electron/**/*", "src/shared/types/assetLibrary.ts", - "src/shared/types/artifacts.ts" + "src/shared/types/artifacts.ts", + "src/shared/types/liveTexture.ts" ] }