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

keep a clipped re-aim tag unique, and send only the values that changed

Adam Eivy6fa14643e8e1
diff --git a/client/src/components/cos/JobCard.jsx b/client/src/components/cos/JobCard.jsx
index a1274ca3a8..0f9ab71ea2 100644
--- a/client/src/components/cos/JobCard.jsx
+++ b/client/src/components/cos/JobCard.jsx
@@ -323,13 +323,17 @@ export default function JobCard({
toast.error(`Fill in ${missing.map(field => field.label || field.key).join(', ')}`);
return;
}
- // Always an options object, so a caller can forward it to the API wrapper
- // unconditionally. Send a configuration ONLY when the dial was actually
- // turned: an untouched card would otherwise transmit its own copy of the
- // saved values, which the server merges over the job it just read — so a
- // value changed from another surface since this card rendered would be
- // silently reverted for that run. Sending nothing means "run as saved".
- onTrigger(job.id, runValuesDirty ? { formValues: runFormValues } : {});
+ // Send ONLY the fields this card actually changed, and let the server's
+ // merge supply the rest from the job it just read. Transmitting the whole
+ // snapshot instead would push this card's copy of the UNTOUCHED fields over
+ // the stored ones, silently reverting — for that run — anything edited from
+ // another surface since this card rendered. An empty projection means "run
+ // as saved". Always an options object, so a caller can forward it to the API
+ // wrapper unconditionally.
+ const changedRunValues = Object.fromEntries(
+ Object.keys(runValues || {}).filter(key => runValues[key] !== savedFormValues[key]).map(key => [key, runValues[key]])
+ );
+ onTrigger(job.id, Object.keys(changedRunValues).length ? { formValues: changedRunValues } : {});
};
const startEditing = () => {
diff --git a/server/lib/jobFormFields.js b/server/lib/jobFormFields.js
index d040fe4878..fdc7dbd664 100644
--- a/server/lib/jobFormFields.js
+++ b/server/lib/jobFormFields.js
@@ -18,6 +18,7 @@
* `cosValidation.js` can validate against it without a lib → services inversion.
*/
+import { createHash } from 'node:crypto';
import { z } from 'zod';
/**
@@ -184,15 +185,37 @@ export function describeReaimedValues(fields, savedValues, runValues) {
&& comparableValue(field, runValues?.[field.key]) !== comparableValue(field, savedValues?.[field.key]));
if (changed.length === 0) return '';
+ // Whether the readable form below dropped anything — a clipped value, a
+ // collapsed newline, or a field past the cap. It decides the digest at the end.
+ let lossy = changed.length > REAIM_MAX_FIELDS;
+
const parts = changed.slice(0, REAIM_MAX_FIELDS).map((field) => {
const label = String(field.label || field.key).trim();
+ const raw = comparableValue(field, runValues?.[field.key]).trim();
// Collapse newlines: this rides on the description's FIRST line, and a
// multi-line value would push the rest out of the dedupe key entirely.
- const text = comparableValue(field, runValues?.[field.key]).replace(/\s+/g, ' ').trim();
+ const text = raw.replace(/\s+/g, ' ');
+ if (text !== raw) lossy = true;
if (!text) return `${label}: (cleared)`;
- return `${label}: ${text.length > REAIM_VALUE_CHARS ? `${text.slice(0, REAIM_VALUE_CHARS)}…` : text}`;
+ if (text.length > REAIM_VALUE_CHARS) {
+ lossy = true;
+ return `${label}: ${text.slice(0, REAIM_VALUE_CHARS)}…`;
+ }
+ return `${label}: ${text}`;
});
if (changed.length > REAIM_MAX_FIELDS) parts.push(`+${changed.length - REAIM_MAX_FIELDS} more`);
+
+ // A clipped or truncated tag can render two genuinely different aims
+ // identically — and an identical first line is precisely what gets deduped
+ // away, which is the silent drop this whole function exists to prevent. When
+ // the readable form lost information, carry a digest of the FULL changed set
+ // so the identity stays distinct even though the label no longer shows why.
+ if (lossy) {
+ // JSON rather than a joined string: any separator character can itself occur
+ // inside a value, which would let two different changed sets encode alike.
+ const full = JSON.stringify(changed.map((field) => [field.key, comparableValue(field, runValues?.[field.key])]));
+ parts.push(createHash('sha1').update(full).digest('hex').slice(0, 8));
+ }
return parts.join(', ');
}
diff --git a/server/lib/jobFormFields.test.js b/server/lib/jobFormFields.test.js
index 190476ad26..f6078307fc 100644
--- a/server/lib/jobFormFields.test.js
+++ b/server/lib/jobFormFields.test.js
@@ -5,6 +5,7 @@ import {
jobFormValuesSchema,
formatJobFormValues,
appendJobFormValues,
+ describeReaimedValues,
} from './jobFormFields.js';
const textField = { key: 'topic', label: 'Topic', type: 'text' };
@@ -114,3 +115,59 @@ describe('appendJobFormValues', () => {
expect(prompt).toContain('- Topic: tides');
});
});
+
+describe('describeReaimedValues', () => {
+ const subject = { key: 'subject', label: 'Subject', type: 'text' };
+ const brief = { key: 'brief', label: 'Brief', type: 'textarea' };
+ const depth = { key: 'depth', label: 'Depth', type: 'select', options: [{ value: 'deep', label: 'Deep dive' }] };
+
+ it('returns nothing when the run matches what is saved', () => {
+ expect(describeReaimedValues([subject], { subject: 'a' }, { subject: 'a' })).toBe('');
+ expect(describeReaimedValues([], {}, { subject: 'a' })).toBe('');
+ expect(describeReaimedValues(undefined, {}, {})).toBe('');
+ });
+
+ it('names a changed value by its label, and a cleared one as cleared', () => {
+ expect(describeReaimedValues([subject], { subject: 'old' }, { subject: 'new' })).toBe('Subject: new');
+ expect(describeReaimedValues([subject], { subject: 'old' }, { subject: '' })).toBe('Subject: (cleared)');
+ });
+
+ it('renders a select by its option label, not its stored value', () => {
+ expect(describeReaimedValues([depth], { depth: '' }, { depth: 'deep' })).toBe('Depth: Deep dive');
+ });
+
+ it('never emits a newline, so the whole tag stays inside the deduped first line', () => {
+ const tag = describeReaimedValues([brief], { brief: '' }, { brief: 'line one\nline two' });
+ expect(tag).not.toContain('\n');
+ expect(tag).toContain('line one line two');
+ });
+
+ it('summarizes past the field cap', () => {
+ const fields = ['a', 'b', 'c', 'd'].map(key => ({ key, label: key.toUpperCase(), type: 'text' }));
+ const tag = describeReaimedValues(fields, {}, { a: '1', b: '2', c: '3', d: '4' });
+ expect(tag).toContain('+1 more');
+ });
+
+ // The point of the tag: two different aims must never render identically, or
+ // the second is rejected as a duplicate and silently never runs.
+ it('stays distinct when the readable form clips a long value', () => {
+ const shared = 'x'.repeat(60);
+ const first = describeReaimedValues([brief], { brief: '' }, { brief: `${shared}AAA` });
+ const second = describeReaimedValues([brief], { brief: '' }, { brief: `${shared}BBB` });
+ expect(first).toContain('…');
+ expect(first).not.toBe(second);
+ });
+
+ it('stays distinct when the difference is past the field cap', () => {
+ const fields = ['a', 'b', 'c', 'd'].map(key => ({ key, label: key.toUpperCase(), type: 'text' }));
+ const first = describeReaimedValues(fields, {}, { a: '1', b: '2', c: '3', d: '4' });
+ const second = describeReaimedValues(fields, {}, { a: '1', b: '2', c: '3', d: '9' });
+ expect(first).not.toBe(second);
+ });
+
+ it('stays distinct when two values collapse to the same single line', () => {
+ const first = describeReaimedValues([brief], { brief: '' }, { brief: 'a\nb' });
+ const second = describeReaimedValues([brief], { brief: '' }, { brief: 'a b' });
+ expect(first).not.toBe(second);
+ });
+});