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

address review (claude round 2): mirror the paragraph rule to the '+ trigger' button, clear weave provenance on a prompt edit

[._.]/ Adam Eivy8408bc5579cb
diff --git a/client/src/lib/loraTriggers.js b/client/src/lib/loraTriggers.js
index 4a0b2bdc40..4f5f336221 100644
--- a/client/src/lib/loraTriggers.js
+++ b/client/src/lib/loraTriggers.js
@@ -39,6 +39,21 @@ export const promptHasTriggerWord = (prompt, word) => {
return new RegExp(`${lead}${escapeRegExp(token)}${tail}`, 'iu').test(text);
};
+/**
+ * How a trigger clause attaches to the end of an existing prompt. Mirrors
+ * `server/lib/loraTriggers.js#separatorFor` — the button and the server weave
+ * MUST agree here, because whichever one lands the token first makes the other
+ * a no-op. A single-paragraph prompt gets a comma join; a multi-paragraph one
+ * gets its own paragraph, so the token can't be swallowed into a trailing
+ * directive (`…\n\nno text, no watermark, aria_tok` reads the activation
+ * token as one more thing to avoid).
+ */
+export const separatorFor = (trimmed) => {
+ if (!trimmed) return '';
+ if (/\n/.test(trimmed)) return '\n\n';
+ return trimmed.endsWith(',') ? ' ' : ', ';
+};
+
/**
* The "+ trigger" button's append: add a LoRA's trigger words to the prompt,
* comma-separated, skipping any already present.
@@ -62,6 +77,5 @@ export const appendTriggerWords = (prompt, words, effectivePrompt = prompt) => {
const fresh = list.filter((w) => !promptHasTriggerWord(haystack, w));
if (!fresh.length) return prompt;
const trimmed = String(prompt || '').trim();
- const sep = !trimmed ? '' : trimmed.endsWith(',') ? ' ' : ', ';
- return `${trimmed}${sep}${fresh.join(', ')}`;
+ return `${trimmed}${separatorFor(trimmed)}${fresh.join(', ')}`;
};
diff --git a/client/src/lib/loraTriggers.test.js b/client/src/lib/loraTriggers.test.js
index b4fb259890..50e3abdde8 100644
--- a/client/src/lib/loraTriggers.test.js
+++ b/client/src/lib/loraTriggers.test.js
@@ -38,6 +38,14 @@ describe('appendTriggerWords', () => {
.toBe('a rooftop, portrait');
});
+ it('appends as its own paragraph on a multi-paragraph prompt', () => {
+ // Whichever of the button and the server weave lands the token first makes
+ // the other a no-op, so the button must not bury it in a trailing directive
+ // — nothing downstream would repair it. Mirrors separatorFor on the server.
+ const multi = 'a rooftop at dusk\n\nno text, no watermark';
+ expect(appendTriggerWords(multi, ['aria_tok'])).toBe(`${multi}\n\naria_tok`);
+ });
+
it('returns the prompt untouched when there is nothing to add', () => {
expect(appendTriggerWords('a rooftop', [])).toBe('a rooftop');
expect(appendTriggerWords('a rooftop', null)).toBe('a rooftop');
diff --git a/server/lib/loraTriggers.js b/server/lib/loraTriggers.js
index 0ebe0560e9..34e40369e9 100644
--- a/server/lib/loraTriggers.js
+++ b/server/lib/loraTriggers.js
@@ -70,7 +70,7 @@ export const promptHasTriggerWord = (prompt, word) => {
* read it as suppressed as activated. That is the exact inverse of the point.
* The pipeline's `\n\nFeaturing <Name> (<trigger>).` clause has the same shape.
*/
-const separatorFor = (trimmed) => {
+export const separatorFor = (trimmed) => {
if (!trimmed) return '';
if (/\n/.test(trimmed)) return '\n\n';
return trimmed.endsWith(',') ? ' ' : ', ';
diff --git a/server/lib/loraTriggers.parity.test.js b/server/lib/loraTriggers.parity.test.js
index dc1b088cf7..149c3f6e26 100644
--- a/server/lib/loraTriggers.parity.test.js
+++ b/server/lib/loraTriggers.parity.test.js
@@ -16,10 +16,14 @@ import { describe, it, expect } from 'vitest';
import {
firstTriggerWord as serverFirstTriggerWord,
promptHasTriggerWord as serverPromptHasTriggerWord,
+ separatorFor as serverSeparatorFor,
+ weaveLoraTriggers,
} from './loraTriggers.js';
import {
firstTriggerWord as clientFirstTriggerWord,
promptHasTriggerWord as clientPromptHasTriggerWord,
+ separatorFor as clientSeparatorFor,
+ appendTriggerWords as clientAppendTriggerWords,
} from '../../client/src/lib/loraTriggers.js';
// Every shape the two implementations must agree on: the whole-token boundary
@@ -71,6 +75,36 @@ describe('LoRA trigger words — server↔client parity', () => {
}
});
+ it('agrees on how a trigger clause attaches to the end of a prompt', () => {
+ // The server weave and the client's '+ trigger' button both append. Whichever
+ // lands the token first makes the other a no-op, so a separator that drifts
+ // means one of them can bury the activation token in a trailing directive
+ // with nothing downstream to repair it.
+ const SEPARATOR_CASES = [
+ 'a rooftop at dusk',
+ 'a rooftop at dusk,',
+ '',
+ 'cinematic. a rooftop\n\nno music, no soundtrack',
+ 'a rooftop\nsecond line',
+ ];
+ for (const trimmed of SEPARATOR_CASES) {
+ expect(
+ clientSeparatorFor(trimmed),
+ `separatorFor drifted for ${JSON.stringify(trimmed)}`,
+ ).toBe(serverSeparatorFor(trimmed));
+ }
+ });
+
+ it('pins the multi-paragraph rule in BOTH the weave and the button', () => {
+ // A mutual regression would slip past the equality check above, so pin the
+ // behavior: a token must never join a trailing negation list.
+ const multi = 'a rooftop at dusk\n\nno text, no watermark';
+ expect(weaveLoraTriggers(multi, [['aria_tok']]).prompt)
+ .toBe(`${multi}\n\naria_tok`);
+ expect(clientAppendTriggerWords(multi, ['aria_tok']))
+ .toBe(`${multi}\n\naria_tok`);
+ });
+
it('pins the boundary rule both copies encode (not just that they match)', () => {
// A mutual regression — both copies losing the boundary together — would
// slip past the equality assertions above, so pin the behavior itself.
diff --git a/server/services/videoGen/local.js b/server/services/videoGen/local.js
index fcd97c3c53..17a739f7cf 100644
--- a/server/services/videoGen/local.js
+++ b/server/services/videoGen/local.js
@@ -102,6 +102,12 @@ export async function updateHistoryItemPrompt(id, prompt) {
const trimmedPrompt = typeof prompt === 'string' ? prompt.trim() : '';
if (trimmedPrompt) item.prompt = trimmedPrompt;
else delete item.prompt;
+ // The trigger-weave provenance (#4665) describes the prompt this render was
+ // MADE with, so it can't survive an edit to that prompt — leaving it would
+ // have the row claim a `renderPrompt` derived from text that is no longer
+ // there, and name tokens as "added" to a prompt they were never added to.
+ delete item.renderPrompt;
+ delete item.addedTriggerWords;
result = { id, prompt: trimmedPrompt };
return history;
});
diff --git a/server/services/videoGen/local.test.js b/server/services/videoGen/local.test.js
index 38f42431df..a68fcd625b 100644
--- a/server/services/videoGen/local.test.js
+++ b/server/services/videoGen/local.test.js
@@ -361,6 +361,7 @@ vi.mock('../../lib/detachedSpawn.js', () => ({
// ─── module under test ───────────────────────────────────────────────────────
// Import AFTER all vi.mock calls so the hoisted mocks are in place.
+let updateHistoryItemPrompt;
let generateChainedVideo;
let generateVideo;
let extractLastFrame;
@@ -369,7 +370,7 @@ let videoGenEvents;
beforeEach(async () => {
vi.resetModules();
// Re-import fresh copies so mock reset above applies cleanly
- ({ generateChainedVideo, generateVideo, extractLastFrame } = await import('./local.js'));
+ ({ generateChainedVideo, generateVideo, extractLastFrame, updateHistoryItemPrompt } = await import('./local.js'));
({ videoGenEvents } = await import('./events.js'));
});
@@ -4865,3 +4866,39 @@ describe('generateVideo — first render child dies during the accelerator hando
expect(failures).toHaveLength(1);
});
});
+
+describe('updateHistoryItemPrompt — trigger-weave provenance (#4665)', () => {
+ const seedHistory = async (item) => {
+ const { readJSONFile, atomicWrite } = await import('../../lib/fileUtils.js');
+ vi.mocked(readJSONFile).mockResolvedValue([item]);
+ vi.mocked(atomicWrite).mockClear();
+ return () => {
+ const calls = vi.mocked(atomicWrite).mock.calls;
+ return calls[calls.length - 1]?.[1]?.[0];
+ };
+ };
+
+ it('drops renderPrompt + addedTriggerWords when the user edits the prompt', async () => {
+ // The provenance describes the prompt this render was MADE with. Leaving it
+ // after an edit has the row claim a renderPrompt derived from text that is
+ // no longer there, and name tokens as "added" to a prompt they never were.
+ const written = await seedHistory({
+ id: 'woven-1',
+ prompt: 'a rooftop at dusk',
+ renderPrompt: 'a rooftop at dusk, fox_tok',
+ addedTriggerWords: ['fox_tok'],
+ });
+ await updateHistoryItemPrompt('woven-1', 'a beach at noon');
+ const item = written();
+ expect(item.prompt).toBe('a beach at noon');
+ expect(item.renderPrompt).toBeUndefined();
+ expect(item.addedTriggerWords).toBeUndefined();
+ });
+
+ it('leaves an un-woven row otherwise untouched', async () => {
+ const written = await seedHistory({ id: 'plain-1', prompt: 'a rooftop', seed: 42 });
+ await updateHistoryItemPrompt('plain-1', 'a beach');
+ const item = written();
+ expect(item).toEqual({ id: 'plain-1', prompt: 'a beach', seed: 42 });
+ });
+});