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
address review (codex): manifest-driven approved-only import, status gating, runtime-hash verification
[._.]/ Adam Eivy4826e8fefe46
diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsxindex 1582ad5120..8021b2360d 100644--- a/client/src/pages/Sprites.jsx+++ b/client/src/pages/Sprites.jsx@@ -220,7 +220,9 @@ export default function Sprites() {return (<div className="flex flex-col md:flex-row gap-4 h-full"><aside className="md:w-64 shrink-0 space-y-3">- <ImportPanel onImported={refresh} />+ {/* Re-import while a sprite is open must refresh the open detail too,+ not just the sidebar list. */}+ <ImportPanel onImported={() => { refresh(); if (id) setRetryTick((t) => t + 1); }} />{records === null ? (<p className="text-sm text-gray-500">Loading…</p>) : records.length === 0 ? (diff --git a/server/services/sprites/importer.js b/server/services/sprites/importer.jsindex d5c8ed6c40..01897ab0b4 100644--- a/server/services/sprites/importer.js+++ b/server/services/sprites/importer.js@@ -114,7 +114,72 @@ function relToCharacterDir(manifestPath, characterId) {return rel;}-async function importCharacter({ sourceRoot, characterId, spec, specPath }) {+// Asset references worth importing from a run's manifests: images, previews,+// and packaged manifests — never raw/extracted intermediates or source video.+const ASSET_REF = /\.(png|gif|json)$/i;+const EXCLUDED_RUN_SEGMENTS = /(^|\/)(raw|frames|review)\//;++// Recursively collect importable asset paths referenced anywhere in a+// manifest's JSON (string values that normalize into the character dir).+function collectManifestRefs(node, characterId, out) {+ if (typeof node === 'string') {+ const rel = relToCharacterDir(node, characterId);+ if (rel && ASSET_REF.test(rel) && !EXCLUDED_RUN_SEGMENTS.test(rel)) out.add(rel);+ } else if (Array.isArray(node)) {+ for (const v of node) collectManifestRefs(v, characterId, out);+ } else if (node && typeof node === 'object') {+ for (const v of Object.values(node)) collectManifestRefs(v, characterId, out);+ }+}++async function copyCharFile(srcCharDir, destDir, rel) {+ const src = join(srcCharDir, rel);+ if (!(await pathExists(src))) return false;+ const dest = join(destDir, rel);+ await ensureDir(dirname(dest));+ await copyFile(src, dest);+ return true;+}++/**+ * Import one APPROVED direction of a finalized walk set: the run manifest+ * (hash-verified), then only the assets the run's manifests declare — packed+ * strips, packaged manifests, previews. Works for both grok runs (record at+ * run root, assets under generated/) and imagegen redraw runs (manifest ++ * strips at the version root, surrounded by unselected candidates that must+ * stay behind).+ */+async function importApprovedDirection({ srcCharDir, destDir, characterId, direction, dir, result, hashExpectations }) {+ const manifestRel = relToCharacterDir(dir.runManifest, characterId);+ if (!manifestRel) {+ result.errors.push(`walk set ${direction}: unsafe run path rejected: ${dir.runManifest || dir.runPath}`);+ return;+ }+ if (!(await copyCharFile(srcCharDir, destDir, manifestRel))) {+ result.errors.push(`walk set ${direction}: run manifest missing: ${manifestRel}`);+ return;+ }+ result.files += 1;+ if (dir.runManifestSha256) hashExpectations.push({ relPath: manifestRel, sha256: dir.runManifestSha256 });++ const refs = new Set();+ collectManifestRefs(await readJson(join(srcCharDir, manifestRel)), characterId, refs);+ const runRel = relToCharacterDir(dir.runPath, characterId);+ if (runRel && (await pathExists(join(srcCharDir, `${runRel}/generated/review-preview.json`)))) {+ refs.add(`${runRel}/generated/review-preview.json`);+ }+ // One extra expansion level: packaged manifests / previews the run record+ // names in turn declare the strip files.+ for (const rel of [...refs]) {+ if (rel.endsWith('.json')) collectManifestRefs(await readJson(join(srcCharDir, rel)), characterId, refs);+ }+ refs.delete(manifestRel);+ for (const rel of [...refs].sort()) {+ if (await copyCharFile(srcCharDir, destDir, rel)) result.files += 1;+ }+}++async function importCharacter({ sourceRoot, characterId, spec, specPath, selection }) {const result = { id: characterId, kind: 'character', files: 0, verified: 0, errors: [] };const srcCharDir = join(sourceRoot, 'art-source', 'sprites', characterId);const destDir = spriteDir(characterId);@@ -144,8 +209,9 @@ async function importCharacter({ sourceRoot, characterId, spec, specPath }) {}}- // walk/ — finalized walk-set manifests, then the run files each direction- // references (manifest + packed strip + previews; never raw/ or frames/).+ // walk/ — the manifests themselves are small provenance and copy whole,+ // but ASSETS import only for APPROVED directions of a FINALIZED set. Draft+ // selections / publication records / pending directions contribute nothing.const walkDir = join(srcCharDir, 'walk');if (await pathExists(walkDir)) {const copied = await copyTree(walkDir, join(destDir, 'walk'));@@ -153,35 +219,33 @@ async function importCharacter({ sourceRoot, characterId, spec, specPath }) {for (const rel of copied) {if (!rel.endsWith('.json')) continue;const walkSet = await readJson(join(destDir, 'walk', rel));- for (const [direction, dir] of Object.entries(walkSet?.directions || {})) {- const runRel = relToCharacterDir(dir?.runPath, characterId);- if (!runRel) {- if (dir?.runPath) result.errors.push(`walk set ${direction}: unsafe run path rejected: ${dir.runPath}`);+ if (walkSet?.kind !== 'finalized-eight-direction-walk-set' || walkSet?.status !== 'final') continue;+ for (const [direction, dir] of Object.entries(walkSet.directions || {})) {+ if (dir?.status !== 'approved') {+ result.errors.push(`walk set ${direction}: not approved (${dir?.status ?? 'missing'}) — skipped`);continue;}- const srcRunDir = join(srcCharDir, runRel);- if (!(await pathExists(srcRunDir))) {- result.errors.push(`walk set references missing run: ${runRel}`);- continue;- }- // Root-level files only — manifests, packed strips, previews. The- // run's raw/, frames/, review/, generated/ intermediates stay behind.- const runCopied = await copyTree(srcRunDir, join(destDir, runRel), (r, isDir) => !isDir && !r.includes('/'));- result.files += runCopied.length;- if (dir?.runManifest && dir?.runManifestSha256) {- const manifestRel = relToCharacterDir(dir.runManifest, characterId);- if (manifestRel) hashExpectations.push({ relPath: manifestRel, sha256: dir.runManifestSha256 });- }+ await importApprovedDirection({ srcCharDir, destDir, characterId, direction, dir, result, hashExpectations });}}}- // runtime/ (immutable atlas archives) + imagegen/ (approved redraw sources).- for (const sub of ['runtime', 'imagegen']) {- if (await pathExists(join(srcCharDir, sub))) {- const copied = await copyTree(join(srcCharDir, sub), join(destDir, sub));- result.files += copied.length;- }+ // runtime/ — immutable published atlas archives. (No wholesale imagegen/+ // copy: approved redraw outputs arrive via the walk-set expansion above;+ // the rest of imagegen/ is unselected candidates and raw intermediates.)+ if (await pathExists(join(srcCharDir, 'runtime'))) {+ const copied = await copyTree(join(srcCharDir, 'runtime'), join(destDir, 'runtime'));+ result.files += copied.length;+ }++ // Published-selection provenance: verify the immutable runtime atlas the+ // catalog hash-pins, and bring the published keyed source along.+ if (selection?.characterId === characterId) {+ const imm = selection.selected?.immutableRuntimeArtifact;+ const immRel = relToCharacterDir(imm?.path, characterId);+ if (immRel && imm?.sha256) hashExpectations.push({ relPath: immRel, sha256: imm.sha256 });+ const keyedRel = relToCharacterDir(selection.selected?.keyedSourcePath, characterId);+ if (keyedRel && (await copyCharFile(srcCharDir, destDir, keyedRel))) result.files += 1;}result.verified = await verifyHashes(destDir, hashExpectations, result.errors);@@ -240,6 +304,9 @@ export async function importFromSource({ sourceRoot, characters, includeProps =}await ensureDir(PATHS.sprites);+ // Read the published-selection pointer up front so the matching character's+ // import can verify the hash-pinned runtime artifacts it declares.+ const selection = await readJson(join(sourceRoot, 'art-pipeline', 'catalog', 'runtime-selection.json'));const results = [];// Ids imported THIS run (drives the runtime-selection provenance copy) vs// every character id the specs dir declares (drives the props-loop skip). A@@ -266,7 +333,7 @@ export async function importFromSource({ sourceRoot, characters, includeProps =allSpecCharacterIds.add(characterId);if (wanted && !wanted.has(characterId)) continue;characterIds.add(characterId);- results.push(await importCharacter({ sourceRoot, characterId, spec, specPath }));+ results.push(await importCharacter({ sourceRoot, characterId, spec, specPath, selection }));}}@@ -284,7 +351,6 @@ export async function importFromSource({ sourceRoot, characters, includeProps =// Published-atlas pointer — provenance for the current selection, kept with// the character it points at.- const selection = await readJson(join(sourceRoot, 'art-pipeline', 'catalog', 'runtime-selection.json'));if (selection?.characterId && characterIds.has(selection.characterId)) {const destDir = join(spriteDir(selection.characterId), 'catalog');await ensureDir(destDir);diff --git a/server/services/sprites/importer.test.js b/server/services/sprites/importer.test.jsindex d8fd5471b1..f9313cd46d 100644--- a/server/services/sprites/importer.test.js+++ b/server/services/sprites/importer.test.js@@ -1,9 +1,11 @@/*** Sprite importer against a synthetic source tree (#2895, phase 1). Builds an- * ElsewhereAcres-layout fixture in a tmpdir, imports it into a tmp data root,- * and asserts the selective-copy rules (candidates/raw intermediates stay- * behind), the manifest sha256 verification, and the record upserts. Also- * covers the path-confinement gate in paths.js.+ * ElsewhereAcres-layout fixture in a tmpdir — including the REAL run shape+ * (run record at the run root, assets under generated/, unselected imagegen+ * candidates beside the approved manifest) — imports it into a tmp data root,+ * and asserts the manifest-driven approved-only copy rules, the sha256+ * verification (walk manifests + the catalog's hash-pinned runtime atlas),+ * and the record upserts. Also covers the path-confinement gate in paths.js.*/import { describe, it, expect, vi, beforeAll, afterAll } from 'vitest';@@ -35,9 +37,31 @@ function writeTree(root, files) {}}+const anchorBytes = 'FAKE-PNG-ANCHOR-SOUTH';+// Grok-style run: record at the run root referencing packaged assets under+// generated/ (exact strings so runManifestSha256 matches the copied bytes).+const southRunRecord = JSON.stringify({+ kind: 'grok-walk-animation-run', status: 'candidate', characterId: 'hero', direction: 'south',+ anchorPath: 'art-source/sprites/hero/reference/hero-anchor-south.png',+ stripPreview: 'art-source/sprites/hero/grok/run-1/generated/south-strip.png',+ postprocessManifest: 'art-source/sprites/hero/grok/run-1/generated/south-manifest.json',+}, null, 2);+const southPackagedManifest = JSON.stringify({+ kind: 'deterministically-packaged-grok-walk-video', direction: 'south',+ sourceVideoPath: 'art-source/sprites/hero/grok/run-1/generated/source-video.mp4',+ frames: [{ path: 'art-source/sprites/hero/grok/run-1/generated/frames/f0.png' }],+}, null, 2);+const southReviewPreview = JSON.stringify({+ stripPath: 'art-source/sprites/hero/grok/run-1/generated/south-strip.png', frameCount: 8, fps: 12,+}, null, 2);+// Imagegen-style run (the v19-east shape): manifest + strips at the version+// root, surrounded by unselected candidates that must stay behind.+const eastManifest = JSON.stringify({+ kind: 'imagegen-redraw-manifest', direction: 'east',+ stripPath: 'art-source/sprites/hero/imagegen/v2/east-strip.png',+}, null, 2);+beforeAll(() => {- const anchorBytes = 'FAKE-PNG-ANCHOR-SOUTH';- const runManifest = JSON.stringify({ kind: 'deterministically-packaged-grok-walk-video', direction: 'south' }, null, 2);writeTree(SOURCE_ROOT, {'art-pipeline/characters/hero.json': {schemaVersion: 1, characterId: 'hero', displayName: 'Hero', archetype: 'adult-humanoid-v1',@@ -45,6 +69,7 @@ beforeAll(() => {'art-pipeline/characters/buddy.json': {schemaVersion: 1, characterId: 'buddy', displayName: 'Buddy', archetype: 'adult-humanoid-v1',},+ 'art-pipeline/characters/character-schema-v1.json': { $schema: 'https://json-schema.org/draft/2020-12/schema' },'game/assets/sprites/buddy/buddy-animation-atlas.png': 'BUDDY-PUBLISHED-COPY','art-source/sprites/hero/reference/hero-reference-set-v1.json': {schemaVersion: 1,@@ -64,10 +89,21 @@ beforeAll(() => {south: {status: 'approved',runPath: 'art-source/sprites/hero/grok/run-1',- runManifest: 'art-source/sprites/hero/grok/run-1/south-manifest.json',- runManifestSha256: sha256(runManifest),+ runManifest: 'art-source/sprites/hero/grok/run-1/animation-run.json',+ runManifestSha256: sha256(southRunRecord),+ },+ east: {+ status: 'approved',+ runPath: 'art-source/sprites/hero/imagegen/v2',+ runManifest: 'art-source/sprites/hero/imagegen/v2/east-manifest.json',+ runManifestSha256: sha256(eastManifest),+ },+ west: {+ status: 'pending',+ runPath: 'art-source/sprites/hero/grok/run-3',+ runManifest: 'art-source/sprites/hero/grok/run-3/animation-run.json',},- // Traversal attempt: a crafted runPath must be rejected, never joined+ // Traversal attempt: a crafted path must be rejected, never joined// into a write destination outside data/sprites/.north: {status: 'approved',@@ -77,11 +113,43 @@ beforeAll(() => {},},},- 'art-source/sprites/hero/grok/run-1/south-manifest.json': runManifest,- 'art-source/sprites/hero/grok/run-1/south-strip.png': 'FAKE-STRIP',- 'art-source/sprites/hero/grok/run-1/raw/frame-000.png': 'RAW-INTERMEDIATE',+ // Non-final manifest kinds in walk/: the files copy as provenance, but+ // their directions must contribute NO assets.+ 'art-source/sprites/hero/walk/hero-walk-selection-v1.json': {+ schemaVersion: 1, kind: 'reviewed-directional-walk-selection', characterId: 'hero', status: 'complete',+ directions: {+ south: {+ status: 'approved',+ runPath: 'art-source/sprites/hero/grok/run-decoy',+ runManifest: 'art-source/sprites/hero/grok/run-decoy/animation-run.json',+ },+ },+ },+ 'art-source/sprites/hero/grok/run-1/animation-run.json': southRunRecord,+ 'art-source/sprites/hero/grok/run-1/generated/south-manifest.json': southPackagedManifest,+ 'art-source/sprites/hero/grok/run-1/generated/south-strip.png': 'FAKE-STRIP',+ 'art-source/sprites/hero/grok/run-1/generated/review-preview.json': southReviewPreview,+ 'art-source/sprites/hero/grok/run-1/generated/source-video.mp4': 'FAKE-VIDEO',+ 'art-source/sprites/hero/grok/run-1/generated/raw/frame-000.png': 'RAW-INTERMEDIATE',+ 'art-source/sprites/hero/grok/run-1/generated/frames/f0.png': 'EXTRACTED-FRAME',+ 'art-source/sprites/hero/grok/run-3/animation-run.json': '{"status":"pending-run"}',+ 'art-source/sprites/hero/grok/run-decoy/animation-run.json': '{"status":"decoy"}',+ 'art-source/sprites/hero/grok/run-decoy/generated/decoy-strip.png': 'DECOY-STRIP',+ 'art-source/sprites/hero/imagegen/v2/east-manifest.json': eastManifest,+ 'art-source/sprites/hero/imagegen/v2/east-strip.png': 'FAKE-EAST-STRIP',+ 'art-source/sprites/hero/imagegen/v2/east-candidate-02.png': 'UNSELECTED-CANDIDATE','art-source/sprites/hero/runtime/v1/hero-animation-atlas-v1.png': 'FAKE-ATLAS',- 'art-pipeline/catalog/runtime-selection.json': { selectionId: 's1', characterId: 'hero', status: 'selected' },+ 'art-source/sprites/hero/hero-atlas-keyed.png': 'FAKE-KEYED',+ 'art-pipeline/catalog/runtime-selection.json': {+ selectionId: 's1', characterId: 'hero', status: 'selected',+ selected: {+ keyedSourcePath: 'art-source/sprites/hero/hero-atlas-keyed.png',+ immutableRuntimeArtifact: {+ path: 'art-source/sprites/hero/runtime/v1/hero-animation-atlas-v1.png',+ sha256: sha256('FAKE-ATLAS'),+ },+ },+ },'game/assets/sprites/flora/flora-atlas.png': 'FAKE-FLORA-ATLAS','game/assets/sprites/flora/flora-atlas.png.import': 'GODOT-IMPORT-SIDECAR','game/assets/sprites/flora/README.md': '# flora',@@ -95,39 +163,57 @@ afterAll(() => {});describe('importFromSource', () => {- it('imports approved assets, skips intermediates, verifies hashes, upserts records', async () => {+ it('imports approved assets manifest-driven, skips intermediates/candidates, verifies hashes', async () => {const { results, totals } = await importFromSource({ sourceRoot: SOURCE_ROOT });const hero = results.find((r) => r.id === 'hero');expect(hero.kind).toBe('character');- // one good anchor + the run manifest verify; the tampered east anchor errors- expect(hero.verified).toBe(2);+ // south anchor + south run record + east manifest + hash-pinned runtime atlas+ expect(hero.verified).toBe(4);expect(hero.errors).toEqual([- 'walk set north: unsafe run path rejected: art-source/sprites/hero/../../../../tmp/sprite-escape',+ 'walk set west: not approved (pending) — skipped',+ 'walk set north: unsafe run path rejected: art-source/sprites/hero/../../../../tmp/sprite-escape/x.json','sha256 mismatch: reference/hero-anchor-east.png',]);- expect(existsSync('/tmp/sprite-escape')).toBe(false);const heroDir = join(SPRITES_ROOT, 'hero');- expect(existsSync(join(heroDir, 'character-spec.json'))).toBe(true);+ // reference: locked set without candidatesexpect(existsSync(join(heroDir, 'reference/hero-anchor-south.png'))).toBe(true);expect(existsSync(join(heroDir, 'reference/candidates/reject-1.png'))).toBe(false);+ // walk manifests copy as provenanceexpect(existsSync(join(heroDir, 'walk/hero-walk-set-v1.json'))).toBe(true);- expect(existsSync(join(heroDir, 'grok/run-1/south-strip.png'))).toBe(true);- expect(existsSync(join(heroDir, 'grok/run-1/raw/frame-000.png'))).toBe(false);+ expect(existsSync(join(heroDir, 'walk/hero-walk-selection-v1.json'))).toBe(true);+ // approved grok run: record + manifest-declared assets, never intermediates+ expect(existsSync(join(heroDir, 'grok/run-1/animation-run.json'))).toBe(true);+ expect(existsSync(join(heroDir, 'grok/run-1/generated/south-manifest.json'))).toBe(true);+ expect(existsSync(join(heroDir, 'grok/run-1/generated/south-strip.png'))).toBe(true);+ expect(existsSync(join(heroDir, 'grok/run-1/generated/review-preview.json'))).toBe(true);+ expect(existsSync(join(heroDir, 'grok/run-1/generated/source-video.mp4'))).toBe(false);+ expect(existsSync(join(heroDir, 'grok/run-1/generated/raw/frame-000.png'))).toBe(false);+ expect(existsSync(join(heroDir, 'grok/run-1/generated/frames/f0.png'))).toBe(false);+ // approved imagegen run: manifest + selected strip only+ expect(existsSync(join(heroDir, 'imagegen/v2/east-manifest.json'))).toBe(true);+ expect(existsSync(join(heroDir, 'imagegen/v2/east-strip.png'))).toBe(true);+ expect(existsSync(join(heroDir, 'imagegen/v2/east-candidate-02.png'))).toBe(false);+ // pending direction and non-final manifest contribute nothing+ expect(existsSync(join(heroDir, 'grok/run-3/animation-run.json'))).toBe(false);+ expect(existsSync(join(heroDir, 'grok/run-decoy'))).toBe(false);+ // published artifacts: immutable archive + keyed source + selection copyexpect(existsSync(join(heroDir, 'runtime/v1/hero-animation-atlas-v1.png'))).toBe(true);+ expect(existsSync(join(heroDir, 'hero-atlas-keyed.png'))).toBe(true);expect(existsSync(join(heroDir, 'catalog/runtime-selection.json'))).toBe(true);// props family imported (PNG + README, never the Godot .import sidecar);- // the character's published game dir is NOT double-imported as props.+ // character game dirs are NOT double-imported as props; schema file skipped.const flora = results.find((r) => r.id === 'flora');expect(flora.kind).toBe('props');expect(existsSync(join(SPRITES_ROOT, 'flora/atlas/flora-atlas.png'))).toBe(true);expect(existsSync(join(SPRITES_ROOT, 'flora/atlas/flora-atlas.png.import'))).toBe(false);- expect(results.some((r) => r.id === 'hero' && r.kind === 'props')).toBe(false);+ expect(results.some((r) => r.kind === 'props' && (r.id === 'hero' || r.id === 'buddy'))).toBe(false);+ expect(results.some((r) => r.id === 'character-schema-v1')).toBe(false);expect(totals.subjects).toBe(3); // hero + buddy characters, flora props- expect(totals.errors).toBe(2);+ expect(totals.errors).toBe(3);const record = await getRecord('hero');expect(record).toMatchObject({ kind: 'character', name: 'Hero', status: 'imported', chromaKey: '#FF00FF' });@@ -163,6 +249,7 @@ describe('paths confinement', () => {expect(abs.startsWith(join(SPRITES_ROOT, 'hero'))).toBe(true);const assets = await listSpriteAssets('hero');expect(assets.some((a) => a.path === 'reference/hero-main.png')).toBe(true);+ expect(assets.some((a) => a.path === 'grok/run-1/generated/south-strip.png')).toBe(true);});it('getRecordWithAssets pairs the record with its disk listing', async () => {