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 (local gate): guard the sidecar destination against files PortOS never wrote
[._.]/ Adam Eivy603c0c5c6e63
diff --git a/.changelog/NEXT.md b/.changelog/NEXT.mdindex ac28a9bce1..7468ffaefb 100644--- a/.changelog/NEXT.md+++ b/.changelog/NEXT.md@@ -25,7 +25,7 @@## Sprite Manager-- **[issue-2982] Publishing an atlas your game can't read now stops instead of silently breaking it** — the atlas PNG used to be the *entire* export: nothing described how many walk frames were in it, so a game with an 8-frame walk baked in as a constant would happily accept a 12-frame publish and then draw the wrong frames from the wrong columns forever, with no crash and no log. Two things fix that. A publish target can now declare the grid it was built against (`runtimeContract`: walk frame count, cell size, column count), and a publish whose compiled atlas disagrees is refused with a message naming both numbers — "Atlas has 14 columns (12 walk frames) but Example App expects 10 (8 walk frames)" — plus the two ways to resolve it. And every publish now writes a small `….layout.json` file beside the atlas describing the grid PortOS actually produced: cell size, ordered column names, per-track column spans (so a future multi-frame scanner or ambient action is additive, not a rewrite), row order, and the atlas checksum — so the game can resolve columns by name and verify what it loaded instead of trusting a constant. Targets with no declared contract publish exactly as before. Also documented: playback **fps in PortOS is preview-only**. It ships in the sidecar labeled as authoring metadata, because the consuming game drives its walk from movement distance and has no frame-rate concept at all — a 6 fps preview and a 24 fps preview export byte-identical atlases. See `docs/features/sprite-export-contract.md`.+- **[issue-2982] Publishing an atlas your game can't read now stops instead of silently breaking it** — the atlas PNG used to be the *entire* export: nothing described how many walk frames were in it, so a game with an 8-frame walk baked in as a constant would happily accept a 12-frame publish and then draw the wrong frames from the wrong columns forever, with no crash and no log. Two things fix that. A publish target can now declare the grid it was built against (`runtimeContract`: walk frame count, cell size, column count), and a publish whose compiled atlas disagrees is refused with a message naming both numbers — "Atlas has 14 columns (12 walk frames) but Example App expects 10 (8 walk frames)" — plus the two ways to resolve it. And every publish now writes a small `….layout.json` file beside the atlas describing the grid PortOS actually produced: cell size, ordered column names, per-track column spans (so a future multi-frame scanner or ambient action is additive, not a rewrite), row order, and the atlas checksum — so the game can resolve columns by name and verify what it loaded instead of trusting a constant. Targets with no declared contract publish exactly as before. Also documented: playback **fps in PortOS is preview-only**. It ships in the sidecar labeled as authoring metadata, because the consuming game drives its walk from movement distance and has no frame-rate concept at all — a 6 fps preview and a 24 fps preview export byte-identical atlases. See `docs/features/sprite-export-contract.md`.- **[issue-2977] Loop Trimmer frames now render pixel-crisp** — the frame thumbnails and the playback preview in the Loop Trimmer looked soft and washed-out, as if the artwork had been compressed, which made it impossible to judge a frame before saving a trim. Your artwork was never affected — the trimmer was shrinking each frame to a fraction of its real size to draw it, then blurrily stretching that back up. Frames now draw at their full source resolution with the same crisp pixel scaling every other sprite view uses, so what you review is exactly what gets saved. The transparency checkerboard behind each frame is drawn by the page now instead of being baked into the shrunken frame, so its squares stay crisp and a fixed size rather than coming out blurry and oversized.- **[issue-2978] Saving a loop trim now works on imported characters** — for a character whose walk cycles came in through the source-pipeline import, the Loop Trimmer would load, scrub, and play the animation perfectly, then fail on **Save trim** with "Packaged run manifest is missing or inconsistent" — after you'd already picked your frames, and with nothing saved. The imported artwork was never damaged; PortOS was simply looking for the packaged manifest under the wrong folder and giving up. Trims now save on imported characters, keep the real gait-phase labels (left-contact, left-passing, …) for each kept frame, and record the correct source strip. A run whose manifest went missing entirely now falls back to the strip's own geometry and still trims, while a manifest that's genuinely corrupt still refuses loudly instead of quietly guessing. The same lookup fixed approving an imported walk direction, which would have failed the same way.- **Steer a directional-anchor re-roll with a correction note** — when a directional anchor comes out wrong (say the north-east pose grew a pocket on the arm that has none in every other view), re-rolling it with the same inputs tended to just reproduce the same mistake. Each unlocked anchor tile now has a small **Correction (optional)** box: type what to fix ("no pocket on the right sleeve") and hit **Regenerate**, and the note is appended to that pose's prompt as an explicit override so the new render actually diverges. The button reads **Generate** on the first render and **Regenerate** once candidates exist, the correction is per-direction (so eight different fixes don't collide), and it rides into the candidate's saved prompt so the image preview shows exactly what was asked for. Main-reference iteration is unchanged — it already has its own design-prompt box.diff --git a/docs/features/sprite-export-contract.md b/docs/features/sprite-export-contract.mdindex 5f6e245f14..568075e8b4 100644--- a/docs/features/sprite-export-contract.md+++ b/docs/features/sprite-export-contract.md@@ -60,7 +60,7 @@ Consumer guidance:- **Resolve columns by name, not by constant.** `tracks` gives each animation track a column span, so a walk of any length — and any future track (a four-frame scanner action, a three-frame ambient loop) — is additive rather than a breaking re-read. `columns` is the flat list for anything that wants raw names.- **Verify before you trust.** `sourceAtlasSha256` identifies the atlas the layout describes. The sidecar is written *before* the PNG on each publish, so a partially-completed publish is detectable (hash mismatch) rather than silent.- **The sidecar carries no timestamp** — identical geometry produces byte-identical content, so an unchanged republish rewrites nothing.-- The sidecar shares the PNG's per-repo write serialization and destination guards; an atlas whose sidecar was deleted gets it back on the next publish.+- The sidecar shares the PNG's per-repo write serialization and destination guards; an atlas whose sidecar was deleted gets it back on the next publish, and a file at that path PortOS didn't write (no `kind: portos-sprite-atlas-layout`) is never replaced without an explicit overwrite acknowledgment.## Playback speed belongs to the consuming appdiff --git a/server/services/sprites/atlasLayout.js b/server/services/sprites/atlasLayout.jsindex 4e5200567c..199c55ff4c 100644--- a/server/services/sprites/atlasLayout.js+++ b/server/services/sprites/atlasLayout.js@@ -115,7 +115,7 @@ export function deriveTracks(columns, walkFrameCount) {* Deliberately carries NO publish timestamp: the payload is a pure function of* the atlas bytes and their geometry, so an unchanged republish produces* byte-identical content and the sidecar write stays idempotent (the publish- * path compares hashes to decide whether anything actually changed).+ * path compares the encoded bytes to decide whether anything actually changed).*/export function buildAtlasLayout({characterId, geometry, atlasSha256, version, atlasDestPath,diff --git a/server/services/sprites/publish.js b/server/services/sprites/publish.jsindex 420fd68036..1f2e253024 100644--- a/server/services/sprites/publish.js+++ b/server/services/sprites/publish.js@@ -33,7 +33,7 @@import { join, resolve } from 'path';import { readFile, stat } from 'fs/promises';import {- atomicWrite, isPathInsideDir, readJSONFile, sha256File, pathExists,+ atomicWrite, isPathInsideDir, readJSONFile, safeJSONParse, sha256File, pathExists,} from '../../lib/fileUtils.js';import { ServerError } from '../../lib/errorHandler.js';import { createKeyCachedQueue } from '../../lib/createKeyCachedQueue.js';@@ -46,7 +46,9 @@ import { withWalkWriteTail } from './walk.js';import { compileAtlasInTail } from './atlas.js';import { sha256Buffer } from './walkPostprocess.js';import { spriteRuntimeContractSchema } from '../../lib/validation.js';-import { buildAtlasLayout, layoutSidecarPath, runtimeContractMismatch } from './atlasLayout.js';+import {+ ATLAS_LAYOUT_KIND, buildAtlasLayout, layoutSidecarPath, runtimeContractMismatch,+} from './atlasLayout.js';// Per-repo serialization: keyed by the resolved repoPath (matching// appDeployer's `deployingApps` key), so two app records pointing at the@@ -271,9 +273,24 @@ async function publishAtlasImpl(recordId, { acknowledgeOverwrite = false } = {})// changes nothing stays a genuine no-op. Returns whether the repo was// mutated — an atlas already at the destination but MISSING its sidecar// still gets one, so the two can never be permanently out of step.+ //+ // Occupied-destination guard, mirroring the atlas's: PortOS owns files it+ // stamped with its own `kind`, and will regenerate one freely, but a JSON+ // file it never wrote sitting at that path is somebody else's — replacing+ // it needs the same explicit acknowledgment replacing a foreign atlas does.const writeLayoutSidecar = async () => {const existing = await readFile(layoutAbs).catch(() => null);if (existing?.equals(layoutBuffer)) return false;+ // A malformed/non-JSON file at that path counts as foreign too — parse+ // failure must not become a 500, and must not license an overwrite.+ if (existing+ && safeJSONParse(existing.toString('utf8'))?.kind !== ATLAS_LAYOUT_KIND+ && !acknowledgeOverwrite) {+ throw new ServerError(+ `${layoutDestPath} already exists and was not written by PortOS — confirm the overwrite to replace it.`,+ { status: 409, code: 'PUBLISH_LAYOUT_OCCUPIED' },+ );+ }await atomicWrite(layoutAbs, layoutBuffer);return true;};diff --git a/server/services/sprites/publish.test.js b/server/services/sprites/publish.test.jsindex 086c08e994..33dcc7113d 100644--- a/server/services/sprites/publish.test.js+++ b/server/services/sprites/publish.test.js@@ -502,6 +502,21 @@ describe('layout sidecar (#2982)', () => {});});+ it('refuses to replace a sidecar PortOS did not write unless acknowledged', async () => {+ const { id } = await characterWithAtlas();+ await setPublishBinding(id, BINDING);+ await mkdir(join(APP_REPO, 'assets/sprites/hero'), { recursive: true });+ await writeFile(join(APP_REPO, sidecarPath(BINDING.atlasDestPath)), '{"kind":"someone-elses-file"}');++ await expect(publishAtlas(id)).rejects.toMatchObject({ status: 409, code: 'PUBLISH_LAYOUT_OCCUPIED' });+ // The refusal aborts before the atlas lands.+ expect(await readFile(join(APP_REPO, BINDING.atlasDestPath)).catch(() => null)).toBeNull();++ const acked = await publishAtlas(id, { acknowledgeOverwrite: true });+ expect(acked.published).toBe(true);+ expect((await readSidecar(BINDING.atlasDestPath)).kind).toBe('portos-sprite-atlas-layout');+ });+it('refuses to publish an atlas whose geometry carries no column layout', async () => {const { id } = await characterWithAtlas('atlas-png-bytes-nogeo', undefined);compileAtlasInTail.mockResolvedValue({