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 (claude): filtered-import props corruption, Windows traversal, ~ expansion, stale-async detail fetch
[._.]/ Adam Eivy15316a298a3a
diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsxindex ffbd862fe1..1582ad5120 100644--- a/client/src/pages/Sprites.jsx+++ b/client/src/pages/Sprites.jsx@@ -193,22 +193,29 @@ export default function Sprites() {const navigate = useNavigate();const [records, setRecords] = useState(null);const [detail, setDetail] = useState(null);- const [detailMissing, setDetailMissing] = useState(false);+ // 'missing' (404 — record really doesn't exist) vs 'error' (transient/server+ // failure — the record may be fine, offer a retry instead of lying).+ const [detailState, setDetailState] = useState('idle');+ const [retryTick, setRetryTick] = useState(0);const refresh = useCallback(() => {- listSpriteRecords().then(setRecords);+ // request() already toasted; settle to an empty list so the sidebar+ // doesn't spin forever.+ listSpriteRecords().then(setRecords).catch(() => setRecords([]));}, []);useEffect(() => { refresh(); }, [refresh]);useEffect(() => {- if (!id) { setDetail(null); setDetailMissing(false); return; }+ if (!id) { setDetail(null); setDetailState('idle'); return undefined; }+ let stale = false; // rapid A→B clicks: a late A response must not clobber BsetDetail(null);- setDetailMissing(false);+ setDetailState('loading');getSpriteRecord(id, { silent: true })- .then(setDetail)- .catch(() => setDetailMissing(true));- }, [id]);+ .then((d) => { if (!stale) { setDetail(d); setDetailState('loaded'); } })+ .catch((err) => { if (!stale) setDetailState(err?.status === 404 || err?.status === 400 ? 'missing' : 'error'); });+ return () => { stale = true; };+ }, [id, retryTick]);return (<div className="flex flex-col md:flex-row gap-4 h-full">@@ -227,11 +234,16 @@ export default function Sprites() {<section className="flex-1 min-w-0">{!id ? (<p className="text-sm text-gray-500">Select a sprite to browse its reference set, animation strips, and atlases.</p>- ) : detailMissing ? (+ ) : detailState === 'missing' ? (<div className="text-sm text-gray-400">Sprite not found.{' '}<button onClick={() => navigate('/media/sprites')} className="text-port-accent hover:underline">Back to library</button></div>+ ) : detailState === 'error' ? (+ <div className="text-sm text-gray-400">+ Failed to load this sprite.{' '}+ <button onClick={() => setRetryTick((t) => t + 1)} className="text-port-accent hover:underline">Retry</button>+ </div>) : !detail ? (<p className="text-sm text-gray-500">Loading…</p>) : (diff --git a/server/services/sprites/importer.js b/server/services/sprites/importer.jsindex aa9ee925d9..d5c8ed6c40 100644--- a/server/services/sprites/importer.js+++ b/server/services/sprites/importer.js@@ -23,7 +23,7 @@import { join, basename, dirname } from 'path';import { readdir, copyFile } from 'fs/promises';-import { PATHS, ensureDir, sha256File, atomicWrite, pathExists, readJSONFile } from '../../lib/fileUtils.js';+import { PATHS, ensureDir, sha256File, atomicWrite, pathExists, readJSONFile, expandHome } from '../../lib/fileUtils.js';import { ServerError } from '../../lib/errorHandler.js';import { upsertImportedRecord } from './records.js';import { spriteDir } from './paths.js';@@ -108,7 +108,9 @@ function relToCharacterDir(manifestPath, characterId) {const marker = `sprites/${characterId}/`;const idx = manifestPath.indexOf(marker);const rel = idx >= 0 ? manifestPath.slice(idx + marker.length) : manifestPath.replace(/^\/+/, '');- if (!rel || rel.split('/').some((seg) => seg === '..' || seg === '')) return null;+ // Split on BOTH separators — on Windows a `..\` segment would otherwise ride+ // through the check as one opaque segment and still traverse in join().+ if (!rel || rel.split(/[\\/]/).some((seg) => seg === '..' || seg === '')) return null;return rel;}@@ -223,6 +225,9 @@ async function importPropsFamily({ sourceRoot, familyId, srcFamilyDir }) {* Returns { results: [...perSubject], totals: { subjects, files, verified, errors } }.*/export async function importFromSource({ sourceRoot, characters, includeProps = true }) {+ // The UI placeholder suggests a ~/… path; resolve it before probing, or a+ // correct tilde path 400s with a misleading "not a sprite pipeline".+ sourceRoot = expandHome(sourceRoot);const specsDir = join(sourceRoot, 'art-pipeline', 'characters');const propsDir = join(sourceRoot, 'game', 'assets', 'sprites');const hasSpecs = await pathExists(specsDir);@@ -236,7 +241,13 @@ export async function importFromSource({ sourceRoot, characters, includeProps =await ensureDir(PATHS.sprites);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+ // filtered import must still exclude ALL characters' game dirs from the+ // props walk — otherwise `characters: ['a']` treats character b's published+ // atlas dir as a props family and overwrites b's record with kind:'props'.const characterIds = new Set();+ const allSpecCharacterIds = new Set();if (hasSpecs) {const wanted = Array.isArray(characters) && characters.length ? new Set(characters) : null;@@ -252,6 +263,7 @@ export async function importFromSource({ sourceRoot, characters, includeProps =results.push({ id: characterId, kind: 'character', files: 0, verified: 0, errors: ['invalid character id'] });continue;}+ allSpecCharacterIds.add(characterId);if (wanted && !wanted.has(characterId)) continue;characterIds.add(characterId);results.push(await importCharacter({ sourceRoot, characterId, spec, specPath }));@@ -262,8 +274,9 @@ export async function importFromSource({ sourceRoot, characters, includeProps =for (const entry of (await readdir(propsDir, { withFileTypes: true })).sort((a, b) => a.name.localeCompare(b.name))) {if (!entry.isDirectory()) continue;// A character's published atlas dir duplicates what runtime/ archives —- // only non-character families import from the game tree.- if (characterIds.has(entry.name)) continue;+ // only non-character families import from the game tree. Excludes every+ // spec-declared character, imported this run or not.+ if (allSpecCharacterIds.has(entry.name)) continue;if (!isValidSpriteId(entry.name)) continue;results.push(await importPropsFamily({ sourceRoot, familyId: entry.name, srcFamilyDir: join(propsDir, entry.name) }));}diff --git a/server/services/sprites/importer.test.js b/server/services/sprites/importer.test.jsindex f793ca412d..d8fd5471b1 100644--- a/server/services/sprites/importer.test.js+++ b/server/services/sprites/importer.test.js@@ -42,6 +42,10 @@ beforeAll(() => {'art-pipeline/characters/hero.json': {schemaVersion: 1, characterId: 'hero', displayName: 'Hero', archetype: 'adult-humanoid-v1',},+ 'art-pipeline/characters/buddy.json': {+ schemaVersion: 1, characterId: 'buddy', displayName: 'Buddy', archetype: 'adult-humanoid-v1',+ },+ 'game/assets/sprites/buddy/buddy-animation-atlas.png': 'BUDDY-PUBLISHED-COPY','art-source/sprites/hero/reference/hero-reference-set-v1.json': {schemaVersion: 1,mainReference: { path: 'art-source/sprites/hero/reference/hero-main.png' },@@ -122,7 +126,7 @@ describe('importFromSource', () => {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(totals.subjects).toBe(2);+ expect(totals.subjects).toBe(3); // hero + buddy characters, flora propsexpect(totals.errors).toBe(2);const record = await getRecord('hero');@@ -130,6 +134,14 @@ describe('importFromSource', () => {expect(record.spec.archetype).toBe('adult-humanoid-v1');});+ it('a filtered character import never treats other characters\' game dirs as props', async () => {+ const { results } = await importFromSource({ sourceRoot: SOURCE_ROOT, characters: ['hero'], includeProps: true });+ expect(results.some((r) => r.id === 'buddy')).toBe(false);+ const buddy = await getRecord('buddy');+ expect(buddy.kind).toBe('character'); // not overwritten to a spec-less props record+ expect(buddy.name).toBe('Buddy');+ });+it('re-import preserves user-managed record fields', async () => {await updateRecord('hero', { notes: 'reviewed', chromaKey: '#00FF00' });await importFromSource({ sourceRoot: SOURCE_ROOT, characters: ['hero'], includeProps: false });