Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

Merge remote-tracking branch 'origin/main' into cos/task-ms3syw3v/agent-d2ae0352

[._.]/ Adam Eivyeae9b4ba510c
diff --cc server/services/sprites/atlas.js
index e54d543f3d,df08197c5a..eb496df0b6
--- a/server/services/sprites/atlas.js
+++ b/server/services/sprites/atlas.js
@@@ -51,17 -51,9 +51,17 @@@ import
} from './walkPostprocess.js';
import { ATLAS_IDLE_COLUMN } from './walkBounds.js';
import {
- WALK_TRACK, SCANNER_TRACK, AMBIENT_TRACK, ANIMATION_TRACKS,
+ WALK_TRACK, SCANNER_TRACK, AMBIENT_TRACK,
- kindSupportsTrack, getAnimationTrack, primaryTrackForKind,
+ tracksForKind, primaryTrackForKind,
} from './animationTracks.js';
- // #3152 — `scanner` and `ambient` are now STORED rows, not compiled ones, so the
- // two bespoke evidence chains below (which still name them, because existing
- // on-disk sets carry their exact `setKind` strings) must resolve through the
- // effective table or every lookup would throw as unknown. The span-order sweep
- // likewise walks the effective id list, so a user's track gets a stable span.
- import {
- getEffectiveAnimationTracks, getEffectiveAnimationTrackIds,
- } from './animationTrackStore.js';
++// #3152 — the DEFAULT registry table is the EFFECTIVE one (compiled `walk` + the
++// user-defined store), not the compiled constant. Load-bearing now that #3158 made
++// this compiler fully generic: it walks `tracksForKind` to find every track a
++// record may carry, so with a compiled-only default a `place` record would resolve
++// NO primary track (ambient is a stored row) and every ambient compile would fail
++// with "has no animation track to compile". `animationTracks` stays an explicit
++// parameter — still the injection seam the multi-track tests use.
++import { getEffectiveAnimationTracks } from './animationTrackStore.js';
import {
buildAtlasGrid, resolveTrackUniformity, compiledGridUpToDate, trackDirections,
} from './atlasGrid.js';
@@@ -269,20 -261,22 +269,22 @@@ function sharedRowPasteX(anchoredX, bou
}
/**
- * Revalidate the full evidence chain: finalized walk set → selection →
- * per-direction run manifests → packaged frame bytes, plus the locked
- * reference set's anchors. Returns everything the compiler consumes.
+ * Revalidate every registered track's evidence chain: finalized set →
+ * selection → run manifests → packaged frame bytes, plus the locked reference
+ * source. Returns everything the compiler consumes.
*/
- export async function validateForCompile(recordId) {
- const recordForTrack = await getRecord(recordId);
- // Which evidence chain a record compiles through follows its PRIMARY track —
- // the one whose finalized set it can't publish without. Asked of the registry
- // (`primaryTrackForKind`) rather than spelled as "ambient-and-not-walk", so it
- // is the same definition `spriteRuntimeContractSchema` requires a frame count
- // for; the two used to agree only by coincidence.
- if (recordForTrack && primaryTrackForKind(recordForTrack.kind, getEffectiveAnimationTracks())?.id === AMBIENT_TRACK) {
- return validateAmbientForCompile(recordId, recordForTrack);
-export async function validateForCompile(recordId, animationTracks = ANIMATION_TRACKS) {
++export async function validateForCompile(recordId, animationTracks = getEffectiveAnimationTracks()) {
+ return validateForCompileWithTracks(recordId, animationTracks);
+ }
+
+ async function validateForCompileWithTracks(recordId, animationTracks) {
+ const record = await getRecord(recordId);
+ const primary = primaryTrackForKind(record?.kind, animationTracks);
+ const registryRows = tracksForKind(record?.kind, animationTracks);
+ if (!primary || !registryRows.length) {
+ throw compileError(`Sprite kind '${String(record?.kind)}' has no animation track to compile`);
}
+
// Every hashed input is read exactly once: verify the bytes in memory and
// hand those same bytes to the compiler, so the pixels compiled are
// provably the pixels verified (no re-read between check and use). Paths
@@@ -863,7 -650,33 +658,33 @@@ export function compileAtlas(recordId,
return withWalkWriteTail(recordId, () => compileAtlasInTail(recordId, options));
}
- export async function compileAtlasInTail(recordId, { geometry: geometryOverride } = {}) {
+ const trackSetSha256s = (validated) => Object.fromEntries(
+ Object.values(validated.tracks).map((track) => [track.id, track.setSha256]),
+ );
+
+ const persistedTrackSetSha256s = (persisted) => {
+ if (persisted?.trackSetSha256s && typeof persisted.trackSetSha256s === 'object'
+ && !Array.isArray(persisted.trackSetSha256s)) {
+ return persisted.trackSetSha256s;
+ }
+ return {
+ ...(persisted?.walkSetSha256 ? { [WALK_TRACK]: persisted.walkSetSha256 } : {}),
+ ...(persisted?.scannerSetSha256 ? { [SCANNER_TRACK]: persisted.scannerSetSha256 } : {}),
+ ...(persisted?.ambientSetSha256 ? { [AMBIENT_TRACK]: persisted.ambientSetSha256 } : {}),
+ };
+ };
+
+ const trackSetsUpToDate = (persisted, validated) => {
+ const current = persistedTrackSetSha256s(persisted);
+ const expected = trackSetSha256s(validated);
+ const ids = new Set([...Object.keys(current), ...Object.keys(expected)]);
+ return [...ids].every((id) => current[id] === expected[id]);
+ };
+
+ export async function compileAtlasInTail(recordId, {
+ geometry: geometryOverride,
- tracks: animationTracks = ANIMATION_TRACKS,
++ tracks: animationTracks = getEffectiveAnimationTracks(),
+ } = {}) {
// The track-presence gate (#3017), not a literal kind check: a record may
// compile an atlas when its kind carries at least one registered animation
// track. Walk is character-only, so this refuses exactly what it always did —
diff --cc server/services/sprites/atlas.test.js
index ad6331e842,280b46eca4..baa138961b
--- a/server/services/sprites/atlas.test.js
+++ b/server/services/sprites/atlas.test.js
@@@ -18,6 -17,6 +18,7 @@@ import { createHash } from 'crypto'
import { lockAllAnchors as lockAllAnchorsFixture, placeCandidate, trackSpan as fullSpan } from './spriteTestFixtures.js';
const TEST_ROOT = mkdtempSync(join(tmpdir(), 'sprite-atlas-test-'));
++const SPRITES_DIR = dirname(fileURLToPath(import.meta.url));
vi.mock('../../lib/fileUtils.js', async (importOriginal) => {
const actual = await importOriginal();
@@@ -46,10 -45,9 +47,13 @@@ const { compileAtlas, getAtlasState, AT
const { SPRITE_DIRECTIONS } = await import('./prompts.js');
const { WALK_PHASES, walkPhaseLabels, WALK_FPS } = await import('./walkPostprocess.js');
const { buildAtlasGrid, compiledGridUpToDate } = await import('./atlasGrid.js');
+const { getAnimationTrack, SCANNER_TRACK, AMBIENT_TRACK } = await import('./animationTracks.js');
- const { __resetAnimationTrackStore } = await import('./animationTrackStore.js');
-
- const SPRITES_DIR = dirname(fileURLToPath(import.meta.url));
++// #3152 — `scanner`/`ambient` are seeded STORE rows, so the compiler's real table
++// is the merge. Resolved once; the store caches its read.
+ const {
- ANIMATION_TRACKS, getAnimationTrack, SCANNER_TRACK, AMBIENT_TRACK,
-} = await import('./animationTracks.js');
++ getEffectiveAnimationTracks, __resetAnimationTrackStore,
++} = await import('./animationTrackStore.js');
++const EFFECTIVE_TRACKS = getEffectiveAnimationTracks();
let seq = 0;
const newId = () => `atlas-char-${++seq}`;
@@@ -329,67 -333,55 +339,117 @@@ describe('compileAtlas', () =>
}
});
+ // #3152's stated "regression that matters": `scanner`/`ambient` stopped being
- // compiled rows and became rows in `data/sprites/animation-tracks.json`. The
++ // compiled rows and became rows in `data/sprites/animation-tracks.json`. The two
+ // cases above prove the PRE-migration state compiles (no store file → the
- // data.reference seed answers). These two prove the POST-migration state does
- // too, with a real user-owned store on disk — which is the shape every upgraded
- // install actually runs, and the one where a broken store→registry hand-off
- // would surface as "unknown animation track 'scanner'" on a record that
- // compiled fine yesterday.
++ // data.reference seed answers). These prove the POST-migration state does too,
++ // with a real user-owned store on disk — the shape every upgraded install runs,
++ // and the one where a broken store→registry hand-off surfaces as "unknown
++ // animation track 'scanner'" on a record that compiled fine yesterday.
+ describe('after migration 211 materializes the user-owned store (#3152)', () => {
- // A byte copy of the shipped seed, exactly as the migration writes it — so
- // this asserts the migration's OUTPUT is sufficient, not merely that some
++ // A byte copy of the shipped seed, exactly as the migration writes it — so this
++ // asserts the migration's OUTPUT is sufficient, not merely that some
+ // hand-written store works.
+ const installUserStore = async () => {
+ const seed = await readFile(join(SPRITES_DIR, '..', '..', '..', 'data.reference', 'sprites', 'animation-tracks.json'), 'utf-8');
+ await mkdir(join(TEST_ROOT, 'sprites'), { recursive: true });
+ await writeFile(join(TEST_ROOT, 'sprites', 'animation-tracks.json'), seed);
+ __resetAnimationTrackStore();
+ };
+ // Restore the seed-fallback state the rest of this file compiles under, so
+ // ordering between suites can't matter.
+ afterEach(async () => {
+ await rm(join(TEST_ROOT, 'sprites', 'animation-tracks.json'), { force: true });
+ __resetAnimationTrackStore();
+ });
+
+ it('still compiles an approved scanner set beside the walk span', async () => {
+ const id = newId();
+ await lockAllAnchors(id);
+ await buildFinalizedWalkSet(id, { frameCount: 12, fps: 10 });
+ await buildFinalizedScannerSet(id);
+ await installUserStore();
+
+ const result = await compileAtlas(id);
+ const manifest = JSON.parse(await readFile(join(TEST_ROOT, 'sprites', id, result.manifestPath), 'utf8'));
- // Identical geometry to the compiled-row era: the span order, the column
- // labels, and the frame count all still resolve from the (now stored) row.
++ // Identical geometry to the compiled-row era: span order, column labels and
++ // frame count all still resolve from the (now stored) row.
+ expect(manifest.geometry.columns).toEqual([
+ 'idle', ...walkPhaseLabels(12), 'scanner-00', 'scanner-01', 'scanner-02', 'scanner-03',
+ ]);
+ expect(manifest.geometry.tracks.scanner).toMatchObject({ start: 13, count: 4, rows: 8 });
+ expect(manifest.geometry.scannerFrameCount).toBe(4);
+ });
+
+ it('still compiles an approved ambient loop for a place record', async () => {
+ const id = await finalizedAmbientPlace();
+ await installUserStore();
+
+ const result = await compileAtlas(id);
+ const manifest = JSON.parse(await readFile(join(TEST_ROOT, 'sprites', id, result.manifestPath), 'utf8'));
- // The ambient dispatch runs off `primaryTrackForKind('place')`, which is
- // now answered by a STORED row — a compiled-table lookup there returns null
- // and silently routes a place into the walk evidence chain, failing with
- // "No finalized walk set" on a record that has no walk at all.
++ // The compile dispatch runs off `primaryTrackForKind('place')`/`tracksForKind`,
++ // now answered by a STORED row — a compiled-table lookup there finds no track
++ // for `place` and refuses the compile outright on a record that has one.
+ expect(manifest.kind).toBe('reviewed-ambient-set-runtime-atlas');
+ expect(manifest.geometry).toMatchObject({
+ columns: ['idle', 'ambient-00', 'ambient-01', 'ambient-02'],
+ ambientFrameCount: 3,
+ });
+ });
+ });
+
+ it('compiles and invalidates on a synthetic third registry track without compiler changes', async () => {
+ const trackId = 'jetpack';
++ // #3152 — built off the EFFECTIVE table: `scanner` is a stored row now, so
++ // `ANIMATION_TRACKS[SCANNER_TRACK]` is undefined and spreading it would
++ // silently produce a row with no bounds at all.
+ const customTracks = {
- ...ANIMATION_TRACKS,
++ ...EFFECTIVE_TRACKS,
+ [trackId]: {
- ...ANIMATION_TRACKS[SCANNER_TRACK],
++ ...EFFECTIVE_TRACKS[SCANNER_TRACK],
+ id: trackId,
+ label: 'Jetpack burst',
+ contractFrameCountField: 'jetpackFrameCount',
+ selectionKind: 'reviewed-directional-jetpack-selection',
+ setKind: 'finalized-eight-direction-jetpack-set',
+ finalErrorCode: 'JETPACK_SET_FINAL',
+ },
+ };
+ const id = newId();
+ await lockAllAnchors(id);
+ await buildFinalizedWalkSet(id, { frameCount: 8, fps: 10 });
+ await buildFinalizedScannerSet(id, {
+ trackId,
+ frameCount: 3,
+ selectionKind: customTracks[trackId].selectionKind,
+ setKind: customTracks[trackId].setKind,
+ });
+
+ const first = await compileAtlas(id, { tracks: customTracks });
+ const manifest = JSON.parse(await readFile(join(TEST_ROOT, 'sprites', id, first.manifestPath), 'utf8'));
+ expect(manifest.geometry.columns).toEqual([
+ 'idle', ...WALK_PHASES, 'jetpack-00', 'jetpack-01', 'jetpack-02',
+ ]);
+ expect(manifest.geometry.tracks.jetpack).toEqual({ start: 9, count: 3, rows: 8 });
+ expect(manifest.trackSets.jetpack.setSha256).toMatch(/^[0-9a-f]{64}$/);
+ for (const row of manifest.directions) {
+ expect(row.cells.filter((cell) => cell.column.startsWith('jetpack-'))).toHaveLength(3);
+ }
+
+ const unchanged = await compileAtlas(id, { tracks: customTracks });
+ expect(unchanged.created).toBe(false);
+
+ // A finalized set is part of the evidence identity even when its frame
+ // bytes are unchanged. Any track's set change must invalidate the pointer,
+ // not just the historical walk/scanner/ambient fields.
+ const setAbs = join(TEST_ROOT, 'sprites', id, `${trackId}/${id}-${trackId}-set-v1.json`);
+ const set = JSON.parse(await readFile(setAbs, 'utf8'));
+ await writeFile(setAbs, JSON.stringify({ ...set, note: 're-finalized' }));
+ const changed = await compileAtlas(id, { tracks: customTracks });
+ expect(changed.created).toBe(true);
+ expect(changed.version).toBe(first.version + 1);
+ });
+
it('compiles the 9×8 player atlas with full provenance and a current pointer', async () => {
const id = await finalizedCharacter();
const result = await compileAtlas(id);
diff --cc server/services/sprites/walkFrames.js
index 3c8f59055e,f74af2aae0..f3ab7254f1
--- a/server/services/sprites/walkFrames.js
+++ b/server/services/sprites/walkFrames.js
@@@ -36,15 -36,16 +36,24 @@@ import
} from './paths.js';
import { sha256Buffer } from './walkPostprocess.js';
import { WALK_TRACK, getAnimationTrack } from './animationTracks.js';
- // #3152 — a manifest's `track` may name a user-defined row, so the id is resolved
- // against the effective table rather than the compiled `walk`-only default.
+import { getEffectiveAnimationTracks } from './animationTrackStore.js';
import { trackColumnLabels } from './atlasGrid.js';
const compileFrameError = (message) =>
new ServerError(message, { status: 422, code: 'ATLAS_COMPILE_INVALID' });
- export async function verifyPackagedFrames(recordId, manifest, { bytes = false, track = manifest?.track || WALK_TRACK } = {}) {
+ export async function verifyPackagedFrames(recordId, manifest, {
+ bytes = false,
+ track = manifest?.track || WALK_TRACK,
- tracks,
++ // #3152 — an omitted `tracks` defaults to the EFFECTIVE table (compiled `walk` +
++ // the user-defined store), not to `getAnimationTrack`'s compiled-only default:
++ // `track` comes off a MANIFEST on disk, so it routinely names a stored row
++ // (scanner/ambient/any user track), and letting it fall through to the compiled
++ // table would throw "unknown animation track" while verifying a set that was
++ // authored and approved perfectly well. Still an explicit parameter — callers
++ // mid-compile pass the exact table they validated against.
++ tracks = getEffectiveAnimationTracks(),
+ } = {}) {
const dir = spriteDir(recordId);
const frames = Array.isArray(manifest?.frames) ? manifest.frames : [];
const total = frames.length;