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

feat([issue-2964]): share anchor correction across reference + asset-card re-rolls

[._.]/ Adam Eivy7a50a982e73b
diff --git a/client/src/components/sprites/AssetCollection.jsx b/client/src/components/sprites/AssetCollection.jsx
index 84e8864084..24b508921d 100644
--- a/client/src/components/sprites/AssetCollection.jsx
+++ b/client/src/components/sprites/AssetCollection.jsx
@@ -16,8 +16,9 @@
*/
import { useMemo, useState } from 'react';
-import { FolderOpen, RefreshCw, Scissors, Sparkles, Film, FileJson } from 'lucide-react';
+import { FolderOpen, RefreshCw, Scissors, Sparkles, Film, FileJson, NotebookPen } from 'lucide-react';
import AssetInspector from './AssetInspector.jsx';
+import CorrectionNote from './CorrectionNote.jsx';
import SpritePreview from './SpritePreview.jsx';
import { hasSpritePreview } from './spriteAssets.js';
import { groupSpriteAssetsByRole } from '../../lib/spriteFacets.js';
@@ -42,7 +43,7 @@ function StatusBadge({ status }) {
);
}
-function AssetCard({ recordId, asset, actions, onInspect }) {
+function AssetCard({ recordId, asset, actions, corrections, onCorrectionChange, onInspect }) {
const { facets } = asset;
const name = asset.path.split('/').pop();
const regenerate = actions?.regenerateFor(asset);
@@ -52,6 +53,16 @@ function AssetCard({ recordId, asset, actions, onInspect }) {
// links to its own build metadata — geometry, chroma key, provenance.
const manifest = asset.manifest;
+ // Inline anchor-correction note (#2964): an anchor re-roll can carry the same
+ // per-direction correction the ReferenceWorkflow grid drives, so a note typed
+ // on either surface is visible on both and rides the re-roll. Only reference
+ // regenerates expose a `direction`; walk regenerates and non-character records
+ // (no `onCorrectionChange`) never show the affordance.
+ const correctionDir = regenerate?.kind === 'reference' ? regenerate.direction : null;
+ const canCorrect = Boolean(correctionDir && onCorrectionChange);
+ const correctionValue = canCorrect ? (corrections?.[correctionDir] || '') : '';
+ const [noteOpen, setNoteOpen] = useState(Boolean(correctionValue));
+
return (
<div className="bg-port-bg border border-port-border rounded p-1 space-y-1">
<button
@@ -85,6 +96,18 @@ function AssetCard({ recordId, asset, actions, onInspect }) {
{regenerate.pending ? 'Rendering…' : 'Regenerate'}
</button>
)}
+ {canCorrect && (
+ <button
+ type="button"
+ onClick={() => setNoteOpen((o) => !o)}
+ aria-expanded={noteOpen}
+ aria-label={`${noteOpen ? 'Hide' : 'Show'} correction note for ${name}`}
+ title={correctionValue ? `Correction: ${correctionValue}` : 'Add a correction for this anchor re-roll'}
+ className={`px-1.5 py-0.5 text-[10px] bg-port-card border rounded hover:border-port-accent ${correctionValue ? 'border-port-accent text-port-accent' : 'border-port-border text-gray-300'}`}
+ >
+ <NotebookPen className="w-3 h-3" />
+ </button>
+ )}
{trim && (
<button
type="button"
@@ -109,6 +132,14 @@ function AssetCard({ recordId, asset, actions, onInspect }) {
)}
</div>
)}
+ {canCorrect && noteOpen && (
+ <CorrectionNote
+ direction={correctionDir}
+ value={correctionValue}
+ onChange={onCorrectionChange}
+ className="text-[10px]"
+ />
+ )}
</div>
);
}
@@ -116,8 +147,14 @@ function AssetCard({ recordId, asset, actions, onInspect }) {
/**
* `actions` is null for a non-character record (props families have no walk /
* reference workflow to re-fire). Shape:
- * { regenerateFor(asset) → { run, disabled, pending, title, kind } | null,
- * trimFor(asset) → { run } | null }
+ * { regenerateFor(asset) → { kind, disabled, pending, title, onClick, direction? } | null,
+ * trimFor(asset) → { onClick } | null }
+ *
+ * `corrections` / `onCorrectionChange` (#2964) are the page-owned per-direction
+ * anchor correction map and its setter, shared with `ReferenceWorkflow` so a
+ * note typed on an anchor card is visible on the reference-workflow grid (and
+ * vice versa) and rides the re-roll as `correctionPrompt`. Both are null for a
+ * non-character record.
*
* `approvedRunIds` (#2938) is the set of run ids the walk selection has
* approved. A run's strip/frames never move on approval — approval lives in
@@ -127,7 +164,10 @@ function AssetCard({ recordId, asset, actions, onInspect }) {
* here in the caller: an asset whose `runId` is an approved run is promoted to
* `approved` for its badge, keeping the classifier free of workflow state.
*/
-export default function AssetCollection({ recordId, assets, actions = null, approvedRunIds, onDeleted = null }) {
+export default function AssetCollection({
+ recordId, assets, actions = null, approvedRunIds,
+ corrections = null, onCorrectionChange = null, onDeleted = null,
+}) {
const [inspecting, setInspecting] = useState(null);
const groups = useMemo(() => {
const grouped = groupSpriteAssetsByRole(assets);
@@ -164,6 +204,8 @@ export default function AssetCollection({ recordId, assets, actions = null, appr
recordId={recordId}
asset={asset}
actions={actions}
+ corrections={corrections}
+ onCorrectionChange={onCorrectionChange}
onInspect={setInspecting}
/>
))}
diff --git a/client/src/components/sprites/AssetCollection.test.jsx b/client/src/components/sprites/AssetCollection.test.jsx
index a25b8af08a..6ef267457f 100644
--- a/client/src/components/sprites/AssetCollection.test.jsx
+++ b/client/src/components/sprites/AssetCollection.test.jsx
@@ -162,3 +162,59 @@ describe('AssetCollection inline actions', () => {
expect(screen.getByText('Copy path')).toBeTruthy();
});
});
+
+describe('AssetCollection anchor correction note (#2964)', () => {
+ const CANDIDATE = 'reference/candidates/walk-east-candidate-1.png';
+ // An anchor re-roll is only offered for an UNLOCKED candidate.
+ const unlockedEast = { reference: { manifest: { anchors: [{ direction: 'east', status: 'pending' }] } } };
+ const candidateAssets = [image(CANDIDATE)];
+ const candidateCard = () => screen.getByTitle(CANDIDATE).parentElement;
+
+ it('shows a correction-note toggle only when the card can write the shared state', () => {
+ // No onCorrectionChange → no affordance even though the re-roll is offered.
+ render(
+ <AssetCollection recordId="example-walker" assets={candidateAssets} actions={actionsFor(unlockedEast)} />,
+ );
+ expect(within(candidateCard()).queryByRole('button', { name: /correction note/i })).toBeNull();
+ });
+
+ it('binds the note to the shared per-direction corrections map and writes through it', async () => {
+ const onCorrectionChange = vi.fn();
+ render(
+ <AssetCollection
+ recordId="example-walker"
+ assets={candidateAssets}
+ actions={actionsFor(unlockedEast)}
+ corrections={{ east: 'no pocket on the right sleeve' }}
+ onCorrectionChange={onCorrectionChange}
+ />,
+ );
+ const card = candidateCard();
+ // An existing correction auto-opens the note and prefills the shared value.
+ const textarea = within(card).getByLabelText(/Correction guidance for the east pose/i);
+ expect(textarea).toHaveValue('no pocket on the right sleeve');
+ // Typing routes an updater up to the page-owned state that merges by
+ // direction key, preserving sibling directions' notes.
+ await userEvent.type(textarea, '!');
+ expect(onCorrectionChange).toHaveBeenCalled();
+ const updater = onCorrectionChange.mock.calls[0][0];
+ const merged = updater({ west: 'keep me' });
+ expect(merged.west).toBe('keep me');
+ expect(merged).toHaveProperty('east');
+ });
+
+ it('keeps the note collapsed by default when no correction exists yet', () => {
+ render(
+ <AssetCollection
+ recordId="example-walker"
+ assets={candidateAssets}
+ actions={actionsFor(unlockedEast)}
+ corrections={{}}
+ onCorrectionChange={vi.fn()}
+ />,
+ );
+ const card = candidateCard();
+ expect(within(card).queryByLabelText(/Correction guidance/i)).toBeNull();
+ expect(within(card).getByRole('button', { name: /Show correction note/i })).toBeTruthy();
+ });
+});
diff --git a/client/src/components/sprites/CorrectionNote.jsx b/client/src/components/sprites/CorrectionNote.jsx
new file mode 100644
index 0000000000..ee80da9e59
--- /dev/null
+++ b/client/src/components/sprites/CorrectionNote.jsx
@@ -0,0 +1,24 @@
+/**
+ * Shared per-direction anchor correction note (#2964).
+ *
+ * The ReferenceWorkflow anchor grid and the asset-collection card render the
+ * SAME control writing the SAME page-owned `corrections` map (lifted to
+ * `Sprites.jsx`), so the placeholder, aria-label, and updater shape live in one
+ * place and can't drift between the two surfaces. `className` lets each host
+ * keep its own chrome (full grid tile vs. compact toggle-revealed card).
+ *
+ * `onChange` receives a setState-style updater so it composes with the
+ * page-owned `setCorrections` while preserving sibling directions' notes.
+ */
+export default function CorrectionNote({ direction, value, onChange, className = '' }) {
+ return (
+ <textarea
+ value={value || ''}
+ onChange={(e) => onChange((prev) => ({ ...prev, [direction]: e.target.value }))}
+ rows={2}
+ aria-label={`Correction guidance for the ${direction} pose`}
+ placeholder="Correction (optional), e.g. no pocket on the right sleeve"
+ className={`w-full px-1.5 py-1 bg-port-bg border border-port-border rounded text-gray-300 placeholder-gray-600 resize-y focus:border-port-accent focus:outline-none ${className}`}
+ />
+ );
+}
diff --git a/client/src/components/sprites/ReferenceWorkflow.jsx b/client/src/components/sprites/ReferenceWorkflow.jsx
index f40dbe5236..873b158c1f 100644
--- a/client/src/components/sprites/ReferenceWorkflow.jsx
+++ b/client/src/components/sprites/ReferenceWorkflow.jsx
@@ -10,6 +10,7 @@ import SpritePreview from './SpritePreview.jsx';
import GalleryImagePicker from '../imageGen/GalleryImagePicker.jsx';
import SpriteReferencePicker from './SpriteReferencePicker.jsx';
import ForkSpriteModal from './ForkSpriteModal.jsx';
+import CorrectionNote from './CorrectionNote.jsx';
// Reference workflow (issue #2896): generate main-reference candidates from
// text + optional uploaded design image, freeze the approved main, then
@@ -72,7 +73,7 @@ function CandidateTile({ recordId, candidate, locking, onLock, clipRisk }) {
);
}
-export default function ReferenceWorkflow({ record, reference, renders, backends, mode, onModeChange, onChanged, onForked }) {
+export default function ReferenceWorkflow({ record, reference, renders, corrections, onCorrectionChange, backends, mode, onModeChange, onChanged, onForked }) {
const recordId = record.id;
const manifest = reference?.manifest || null;
const candidates = reference?.candidates || [];
@@ -88,10 +89,10 @@ export default function ReferenceWorkflow({ record, reference, renders, backends
const allAnchorsLocked = anchorList.length > 0 && anchorList.every((a) => a.status === 'locked');
const [anchorsOpen, setAnchorsOpen] = useState(!allAnchorsLocked);
// Reset the default on record switch only (deps: recordId), so it never
- // fights a user toggle within one character. Also drop any per-direction
- // correction text — the 8 anchor direction keys are identical across
- // characters, so a leftover note would otherwise bleed into the next sprite.
- useEffect(() => { setAnchorsOpen(!allAnchorsLocked); setCorrections({}); }, [recordId]);
+ // fights a user toggle within one character. The per-direction correction
+ // text is now page-owned (#2964) and reset there on record switch, so this
+ // effect no longer clears it.
+ useEffect(() => { setAnchorsOpen(!allAnchorsLocked); }, [recordId]);
// Image-backend availability + the selected `mode` are page-owned (#2938) so
// that the Sprites page's asset-card Regenerate re-rolls through the SAME
@@ -111,7 +112,9 @@ export default function ReferenceWorkflow({ record, reference, renders, backends
// Per-direction free-text correction re-appended to an anchor re-roll (e.g.
// "no pocket on the right sleeve"). Keyed by direction because the anchor
// grid renders all directions at once — unlike the single main designPrompt.
- const [corrections, setCorrections] = useState({});
+ // Page-owned (#2964) and passed in as `corrections` / `onCorrectionChange` so
+ // this grid and the asset-collection Regenerate button share one source: a
+ // note typed on either surface is visible on the other and rides the re-roll.
const [galleryOpen, setGalleryOpen] = useState(false);
const [spritePickerOpen, setSpritePickerOpen] = useState(false);
const [forkOpen, setForkOpen] = useState(false);
@@ -420,14 +423,13 @@ export default function ReferenceWorkflow({ record, reference, renders, backends
<div className="space-y-1.5">
{/* Optional correction guidance re-appended to the prompt on
each re-roll — without it, regenerating with the same
- inputs tends to reproduce the same mistake. */}
- <textarea
- value={corrections[anchor.direction] || ''}
- onChange={(e) => setCorrections((prev) => ({ ...prev, [anchor.direction]: e.target.value }))}
- rows={2}
- aria-label={`Correction guidance for the ${anchor.direction} pose`}
- placeholder="Correction (optional), e.g. no pocket on the right sleeve"
- className="w-full px-1.5 py-1 text-[11px] bg-port-bg border border-port-border rounded text-gray-300 placeholder-gray-600 resize-y focus:border-port-accent focus:outline-none"
+ inputs tends to reproduce the same mistake. Shared with
+ the asset card so both surfaces write one source (#2964). */}
+ <CorrectionNote
+ direction={anchor.direction}
+ value={corrections[anchor.direction]}
+ onChange={onCorrectionChange}
+ className="text-[11px]"
/>
<button
onClick={() => generate(anchor.direction)}
diff --git a/client/src/lib/spriteCollectionActions.js b/client/src/lib/spriteCollectionActions.js
index ddfd42e720..bd40a706e9 100644
--- a/client/src/lib/spriteCollectionActions.js
+++ b/client/src/lib/spriteCollectionActions.js
@@ -39,7 +39,9 @@ const WALK_OUTPUT_ROLES = new Set(['strip', 'animation', 'frame']);
* @param mode the workflow-selected image backend id, threaded
* into the anchor re-roll so it matches the workflow
* @returns `{ regenerateFor(asset), trimFor(asset) }`, each returning null for
- * an asset it can't act on.
+ * an asset it can't act on. A reference regenerate also carries the
+ * asset's `direction` so the caller can bind an inline correction note
+ * to the shared per-direction corrections state (#2964).
*/
export function buildCollectionActions({
detail, walkPending = {}, referencePending = {},
@@ -95,6 +97,10 @@ export function buildCollectionActions({
const pending = Boolean(referencePending[direction]);
return {
kind: 'reference',
+ // Surfaced so the asset card can bind an inline correction note to the
+ // shared per-direction corrections state (#2964) — the same note the
+ // ReferenceWorkflow anchor grid shows — before firing generateAnchor.
+ direction,
pending,
disabled: !hasBackend || locked || pending,
title: !hasBackend
diff --git a/client/src/lib/spriteCollectionActions.test.js b/client/src/lib/spriteCollectionActions.test.js
index d594384ec4..ec4cf97746 100644
--- a/client/src/lib/spriteCollectionActions.test.js
+++ b/client/src/lib/spriteCollectionActions.test.js
@@ -90,6 +90,12 @@ describe('regenerateFor — reference anchors', () => {
r.onClick();
});
+ it('exposes the anchor direction so the card can bind a shared correction note (#2964)', () => {
+ const r = build({ reference: { manifest: { anchors: [{ direction: 'east', status: 'pending' }] } } })
+ .regenerateFor(CANDIDATE_EAST);
+ expect(r.direction).toBe('east');
+ });
+
it('disables the re-roll once the anchor is locked — locks are irreversible', () => {
expect(build().regenerateFor(CANDIDATE_EAST).disabled).toBe(true);
});
diff --git a/client/src/pages/Sprites.jsx b/client/src/pages/Sprites.jsx
index d9f603da2a..af7f3b08b4 100644
--- a/client/src/pages/Sprites.jsx
+++ b/client/src/pages/Sprites.jsx
@@ -436,6 +436,16 @@ export default function Sprites() {
onChanged: onWorkflowChanged,
});
+ // Per-direction anchor correction guidance is page-owned (#2964) so the
+ // ReferenceWorkflow anchor grid and the asset-collection Regenerate button
+ // read/write ONE source: a correction typed on either surface applies to the
+ // other AND rides along as `correctionPrompt` on whichever re-roll fires.
+ // Keyed by direction — the 8 anchor keys are identical across characters, so
+ // reset on record switch to keep a leftover note from bleeding into the next
+ // sprite (the reset ReferenceWorkflow used to own before the state was lifted).
+ const [corrections, setCorrections] = useState({});
+ useEffect(() => { setCorrections({}); }, [id]);
+
// Workspace tab (Library / Loop Trimmer) and the run the trimmer is open for
// live in the URL (#2933) so the active workspace is deep-linkable
// (`?spriteTab=trimmer&run=<runId>`) — the same "URL is the source of truth
@@ -546,14 +556,21 @@ export default function Sprites() {
// `mode` is the workflow-selected backend, threaded from the asset card via
// buildCollectionActions (#2938) so a re-roll uses the same backend the
// Reference workflow would, not the server default. Falls back to the
- // page-level selection when a caller omits it.
- const generateAnchor = useCallback((direction, mode) => submitRender(
- refBegin, refResolve, refCancel, direction,
- () => generateSpriteReference(id, {
- target: direction, ...((mode || imageMode) ? { mode: mode || imageMode } : {}),
- }, { silent: true }),
- `Failed to queue ${direction} render`,
- ), [id, imageMode, refBegin, refResolve, refCancel, submitRender]);
+ // page-level selection when a caller omits it. The direction's shared
+ // correction (#2964) rides along as `correctionPrompt` so the asset-card
+ // re-roll sends the SAME guidance the ReferenceWorkflow anchor re-roll does.
+ const generateAnchor = useCallback((direction, mode) => {
+ const correction = corrections[direction]?.trim();
+ return submitRender(
+ refBegin, refResolve, refCancel, direction,
+ () => generateSpriteReference(id, {
+ target: direction,
+ ...((mode || imageMode) ? { mode: mode || imageMode } : {}),
+ ...(correction ? { correctionPrompt: correction } : {}),
+ }, { silent: true }),
+ `Failed to queue ${direction} render`,
+ );
+ }, [id, imageMode, corrections, refBegin, refResolve, refCancel, submitRender]);
const collectionActions = useMemo(() => {
if (detail?.record?.kind !== 'character') return null;
@@ -673,6 +690,8 @@ export default function Sprites() {
record={detail.record}
reference={detail.reference}
renders={referenceRenders}
+ corrections={corrections}
+ onCorrectionChange={setCorrections}
backends={imageBackends}
mode={imageMode}
onModeChange={setImageMode}
@@ -713,6 +732,8 @@ export default function Sprites() {
assets={detail.assets}
actions={collectionActions}
approvedRunIds={approvedRunIds}
+ corrections={corrections}
+ onCorrectionChange={setCorrections}
onDeleted={onWorkflowChanged}
/>
)}