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 (claude + codex): never append a trigger into a trailing negation clause
[._.]/ Adam Eivyc978b50bd645
diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex c2e6a4b3f1..55e65fc1d3 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -50,7 +50,7 @@ grep -i "what you want to do" client/src/lib/README.md| `imageCleaners.js` | Mirror of `resolveCleanersFromConfig` from `server/lib/imageClean.js`. Reads `{cleanC2PA, denoise}` off a per-mode settings record. `cleanC2PA` defaults are mode-aware (on for `codex` + `external` — the backends that emit C2PA chunks today — off otherwise, as an allow-list rather than a deny-list); `denoise` defaults off everywhere (lossy, opt-in only). || `reviewerModels.js` | `reviewerModelsFromDefaults` / `reviewerModelsToDefaults` / `reviewerEffortsFromDefaults` / `reviewerEffortsToDefaults` — adapt the Code Review Defaults' per-reviewer SCALARS (`codexModel`, `ollamaModel`, `claudeEffort`, …) to and from the token-keyed maps `ReviewerPicker`'s Model and Effort columns take. Mirrors `reviewerModelsFromDefaults` / `reviewerEffortsFromDefaults` in `server/lib/cosValidation.js`. || `reviewerPins.js` | Client mirrors of the per-reviewer pin vocabularies — `MODEL_SELECTABLE_REVIEWERS` / `EFFORT_SELECTABLE_REVIEWERS` / `REVIEWER_EFFORT_LEVELS` / `reviewerEffortLevels` / `normalizeReviewerSlug` / `sanitizeReviewerModelInput` and their bounds. Dependency-free on purpose: the server suite imports it to pin the mirror against the server's own ladders, so it must not reach for a client-only package. Re-exported by `components/cos/constants.js`. |-| `loraTriggers.js` | Mirror of the trigger-word predicates in `server/lib/loraTriggers.js` (#4665): `firstTriggerWord` (the canonical activation token of a Civitai `trainedWords` list) and `promptHasTriggerWord` (whole-token, case-insensitive presence — `aria_tok` does not match inside `aria_token`). Lets the LoRA picker warn that the server is about to append a token, and keeps ImageGen's "+ trigger" dedupe using the same rule the server weave uses. |+| `loraTriggers.js` | Mirror of the trigger-word predicates in `server/lib/loraTriggers.js` (#4665): `firstTriggerWord` (the canonical activation token of a Civitai `trainedWords` list) and `promptHasTriggerWord` (whole-token, case-insensitive presence — `aria_tok` does not match inside `aria_token`). Plus `appendTriggerWords(prompt, words, effectivePrompt?)` — the "+ trigger" button's append, which adds ALL of a LoRA's words (the server only ever weaves the first) and judges presence against the composed prompt the page will actually submit. Lets the LoRA picker warn that the server is about to append a token, with the button and the hint sharing one presence rule. || `runnerFamilies.js` | Mirror of `server/lib/runners.js`. || `slashdoCatalog.js` | Mirror of `server/lib/slashdoCatalog.js` — the launchable slashdo workflows (`SLASHDO_WORKFLOWS`, `slashdoWorkflowsForApp(isSwiftApp)`, `SLASHDO_APP_TYPES`) driving the app-overview Agent Operations buttons. Adds only the per-button Tailwind classes; pinned by `server/lib/slashdoCatalog.test.js`. || `issueLength.js` | Mirror of `server/lib/issueLength.js`. |diff --git a/client/src/lib/loraTriggers.js b/client/src/lib/loraTriggers.jsindex 8d6a0d7d5f..4a0b2bdc40 100644--- a/client/src/lib/loraTriggers.js+++ b/client/src/lib/loraTriggers.js@@ -38,3 +38,30 @@ export const promptHasTriggerWord = (prompt, word) => {const tail = WORD_CHAR.test(token[token.length - 1]) ? `(?![${WORD_CLASS}])` : '';return new RegExp(`${lead}${escapeRegExp(token)}${tail}`, 'iu').test(text);};++/**+ * The "+ trigger" button's append: add a LoRA's trigger words to the prompt,+ * comma-separated, skipping any already present.+ *+ * Unlike the server weave this appends ALL of the LoRA's trigger words — the+ * user clicked a button whose tooltip lists them, so honoring the list is the+ * point. The server only ever adds the first, and never duplicates.+ *+ * `effectivePrompt` is the text presence is judged against, defaulting to the+ * prompt itself. Pass the STYLED/enveloped prompt when the page composes one+ * before submitting: a trigger the style preset already supplies must not be+ * appended again, or the composed prompt carries it twice — and the picker's+ * hint (which reads the same composed text) would disagree with the button.+ */+export const appendTriggerWords = (prompt, words, effectivePrompt = prompt) => {+ const list = (Array.isArray(words) ? words : [])+ .filter((w) => typeof w === 'string' && w.trim())+ .map((w) => w.trim());+ if (!list.length) return prompt;+ const haystack = typeof effectivePrompt === 'string' ? 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(', ')}`;+};diff --git a/client/src/lib/loraTriggers.test.js b/client/src/lib/loraTriggers.test.jsnew file mode 100644index 0000000000..b4fb259890--- /dev/null+++ b/client/src/lib/loraTriggers.test.js@@ -0,0 +1,51 @@+import { describe, it, expect } from 'vitest';+import { appendTriggerWords } from './loraTriggers.js';++// The predicates (`firstTriggerWord` / `promptHasTriggerWord`) are pinned+// against their server originals in `server/lib/loraTriggers.parity.test.js`.+// This suite covers the client-only "+ trigger" append built on top of them.+describe('appendTriggerWords', () => {+ it('appends ALL of a LoRA\'s trigger words, unlike the server weave', () => {+ // The user clicked a button whose tooltip lists every word — honoring the+ // whole list is the point. The server only ever weaves the first.+ expect(appendTriggerWords('a rooftop', ['aria_tok', 'portrait']))+ .toBe('a rooftop, aria_tok, portrait');+ });++ it('skips a word already present rather than double-weighting it', () => {+ expect(appendTriggerWords('aria_tok, rooftop', ['aria_tok', 'film grain']))+ .toBe('aria_tok, rooftop, film grain');+ });++ it('matches a trigger woven mid-sentence, not just as its own comma segment', () => {+ // The old private helper compared comma segments, so it read this as absent+ // and re-appended it.+ expect(appendTriggerWords('a portrait of aria_tok on a rooftop', ['aria_tok']))+ .toBe('a portrait of aria_tok on a rooftop');+ });++ it('is not fooled by the token appearing inside a longer word', () => {+ expect(appendTriggerWords('a portrait of aria_token', ['aria_tok']))+ .toBe('a portrait of aria_token, aria_tok');+ });++ it('judges presence against effectivePrompt but appends to the raw prompt', () => {+ // The style preset supplies the trigger, so appending it to the raw prompt+ // would make the COMPOSED prompt carry it twice.+ expect(appendTriggerWords('a rooftop', ['aria_tok'], 'aria_tok style. a rooftop'))+ .toBe('a rooftop');+ expect(appendTriggerWords('a rooftop', ['aria_tok', 'portrait'], 'aria_tok style. a rooftop'))+ .toBe('a rooftop, portrait');+ });++ 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');+ expect(appendTriggerWords('a rooftop', [' ', ''])).toBe('a rooftop');+ });++ it('handles an empty prompt and a trailing comma', () => {+ expect(appendTriggerWords('', ['aria_tok'])).toBe('aria_tok');+ expect(appendTriggerWords('a rooftop,', ['aria_tok'])).toBe('a rooftop, aria_tok');+ });+});diff --git a/client/src/pages/ImageGen.jsx b/client/src/pages/ImageGen.jsxindex 38aa9ee9e9..3f9f19ad96 100644--- a/client/src/pages/ImageGen.jsx+++ b/client/src/pages/ImageGen.jsx@@ -21,7 +21,7 @@ import PromptFromMedia from '../components/media/PromptFromMedia';import BackendChipStrip from '../components/media/BackendChipStrip';import { normalizeImage } from '../components/media/normalize';import { RUNNER_FAMILIES, loraCompatKey } from '../lib/runnerFamilies';-import { promptHasTriggerWord } from '../lib/loraTriggers';+import { appendTriggerWords } from '../lib/loraTriggers';import Flux2InstallModal from '../components/imageGen/Flux2InstallModal';import HfTokenBanner from '../components/imageGen/HfTokenBanner';import ImageGenControls from '../components/imageGen/ImageGenControls';@@ -72,30 +72,6 @@ const revokeIfBlob = (url) => {if (url?.startsWith('blob:')) URL.revokeObjectURL(url);};-// Append LoRA trigger words to a prompt comma-separated, skipping any already-// present. Presence uses the SHARED `promptHasTriggerWord` predicate (#4665) so-// the button, the picker's "will be added" hint, and the server-side weave all-// agree on what counts as present: a whole-token, case-insensitive match-// anywhere in the prompt. That matters because a trigger is commonly woven-// mid-sentence ("a portrait of aria_tok on a rooftop"), which the old-// comma-segment comparison read as absent and re-appended — while still not-// false-matching a short trigger like "cat" inside "concatenate".-//-// Unlike the server weave, this appends ALL of the LoRA's trigger words: the-// user clicked "+ trigger" with the full list in the tooltip, so honoring it is-// the point. The server only ever adds the first, and never duplicates.-const appendTriggerWords = (prompt, words) => {- const list = (Array.isArray(words) ? words : [])- .filter((w) => typeof w === 'string' && w.trim())- .map((w) => w.trim());- if (!list.length) return prompt;- const fresh = list.filter((w) => !promptHasTriggerWord(prompt, w));- if (!fresh.length) return prompt;- const trimmed = String(prompt || '').trim();- const sep = !trimmed ? '' : trimmed.endsWith(',') ? ' ' : ', ';- return `${trimmed}${sep}${fresh.join(', ')}`;-};-// User-facing labels for STAGE markers emitted by FLUX.2 (and any future// runner). The keys match what `flux2_macos.py` prints; unknown stages fall// through to the prettified id so adding a new STAGE in Python doesn't@@ -666,6 +642,15 @@ export default function ImageGen() {maxSlots: REFERENCE_SLOT_COUNT,localSupportsReferences: isFlux2Model,});+ // The exact prompt a render would be submitted with right now — the same+ // composition submitGenerationPayload performs. The LoRA picker's #4665+ // trigger-word hint and its "+ trigger" append both judge presence against+ // THIS, not the raw textarea, so neither can disagree with the server-side+ // weave when the style preset already supplies a trigger token.+ const styledPrompt = useMemo(+ () => composeStyledPrompt(prompt, negativePrompt, stylePreset).prompt,+ [prompt, negativePrompt, stylePreset],+ );const activeReferenceImages = useMemo(() => referenceImages.slice(0, referenceSlotCount),[referenceImages, referenceSlotCount],@@ -1310,11 +1295,12 @@ export default function ImageGen() {onChange={setSelectedLoras}currentRunnerFamily={currentRunnerFamily}currentCompatKey={currentCompatKey}- onAppendTrigger={(words) => setPrompt((p) => appendTriggerWords(p, words))}- // The STYLED prompt, not the raw one — that's what submit sends and- // therefore what the server weaves against, so a trigger already- // present in the style preset must not raise a 'will be added' hint.- prompt={composeStyledPrompt(prompt, negativePrompt, stylePreset).prompt}+ // Both the append and the hint judge presence against the STYLED+ // prompt — that's what submit sends, so it's what the server weaves+ // against. A trigger the style preset already supplies must neither+ // raise a hint nor be appended a second time.+ onAppendTrigger={(words) => setPrompt((p) => appendTriggerWords(p, words, styledPrompt))}+ prompt={styledPrompt}disabled={statusLoading}/>)}diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex 03cb68c8c5..4f3e1eb5b1 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -38,6 +38,7 @@import { useState, useEffect, useRef, useCallback, useMemo } from 'react';import { useSearchParams } from 'react-router';import { isMiniMaxH3Runtime, isLtx2FamilyRuntime } from '../lib/runnerFamilies';+import { appendTriggerWords } from '../lib/loraTriggers';import Drawer from '../components/Drawer';import { ImageGenTab } from '../components/settings/ImageGenTab';import LocalSetupPanel from '../components/settings/LocalSetupPanel';@@ -1189,14 +1190,15 @@ export default function VideoGen() {onChange={setSelectedLoras}currentRunnerFamily={loraFamily}currentCompatKey={loraFamily}- onAppendTrigger={(triggers) => setPrompt((p) => {- const add = triggers.join(', ');- return p && p.trim() ? `${p}, ${add}` : add;- })}- // The ENVELOPED prompt (style preset + no-music suffix), not the- // raw textarea — that is the exact text the server weaves against,- // so the hint can never claim an append that will not happen.- prompt={envelopedPrompt}+ // Shared with ImageGen: skips a word already present rather than+ // re-appending it, and judges presence against the ENVELOPED prompt+ // (style preset + no-music suffix) — the exact text the server+ // weaves against, so the button and the hint agree with the render.+ onAppendTrigger={(triggers) => setPrompt((p) => appendTriggerWords(p, triggers, envelopedPrompt))}+ // Grok payloads carry no LoRAs and never reach the local weave, so+ // the hint would promise an append that cannot happen. `null`+ // (not `''`) is the picker's "host didn't opt in" signal.+ prompt={isGrok ? null : envelopedPrompt}disabled={generating}/></div>diff --git a/server/lib/loraTriggers.js b/server/lib/loraTriggers.jsindex 343762bb08..0ebe0560e9 100644--- a/server/lib/loraTriggers.js+++ b/server/lib/loraTriggers.js@@ -55,6 +55,27 @@ export const promptHasTriggerWord = (prompt, word) => {return new RegExp(`${lead}${escapeRegExp(token)}${tail}`, 'iu').test(text);};+/**+ * How the trigger clause attaches to the end of an existing prompt.+ *+ * A single-paragraph prompt gets a plain comma join — the trigger reads as one+ * more subject term, which is what a diffusion prompt wants.+ *+ * A MULTI-paragraph prompt gets its own paragraph instead, because the last+ * line of a structured prompt is frequently a directive the trigger must not be+ * swallowed into. The case that forces this: VideoGen's prompt envelope ends a+ * muted render with a `\n\nno music, no soundtrack` paragraph, so a comma join+ * would produce `no music, no soundtrack, aria_tok` — the activation token+ * lands as the third item of a NEGATION list, and the encoder is as likely to+ * 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) => {+ if (!trimmed) return '';+ if (/\n/.test(trimmed)) return '\n\n';+ return trimmed.endsWith(',') ? ' ' : ', ';+};+/*** Weave the missing activation tokens of the selected LoRAs into `prompt`.*@@ -90,6 +111,5 @@ export const weaveLoraTriggers = (prompt, triggerWordLists) => {}if (!added.length) return { prompt: original, added: [] };const trimmed = original.trim();- const sep = !trimmed ? '' : trimmed.endsWith(',') ? ' ' : ', ';- return { prompt: `${trimmed}${sep}${added.join(', ')}`, added };+ return { prompt: `${trimmed}${separatorFor(trimmed)}${added.join(', ')}`, added };};diff --git a/server/lib/loraTriggers.test.js b/server/lib/loraTriggers.test.jsindex aa45e0ed6d..5a1515cc3f 100644--- a/server/lib/loraTriggers.test.js+++ b/server/lib/loraTriggers.test.js@@ -124,6 +124,23 @@ describe('weaveLoraTriggers', () => {expect(weaveLoraTriggers(' ', [])).toEqual({ prompt: ' ', added: [] });});+ it('appends as its own paragraph when the prompt is multi-paragraph', () => {+ // VideoGen's envelope ends a muted render with a no-music PARAGRAPH. A+ // comma join would make the activation token the third item of a negation+ // list ('no music, no soundtrack, aria_tok') — read as suppressed, not+ // activated, which is the exact inverse of what the weave is for.+ const { prompt } = weaveLoraTriggers(+ 'a rooftop at dusk\n\nno music, no soundtrack',+ [['aria_tok']],+ );+ expect(prompt).toBe('a rooftop at dusk\n\nno music, no soundtrack\n\naria_tok');+ });++ it('still comma-joins a single-paragraph prompt', () => {+ expect(weaveLoraTriggers('a rooftop at dusk', [['aria_tok']]).prompt)+ .toBe('a rooftop at dusk, aria_tok');+ });+it('does not double the separator after a trailing comma', () => {expect(weaveLoraTriggers('a rooftop,', [['aria_tok']]).prompt).toBe('a rooftop, aria_tok');});