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

Show what Enhance and Refine with AI send the model

Claude2406c7a2116f
diff --git a/client/src/components/media/PromptEnhancer.jsx b/client/src/components/media/PromptEnhancer.jsx
index b0e6d77082..f9206cd04a 100644
--- a/client/src/components/media/PromptEnhancer.jsx
+++ b/client/src/components/media/PromptEnhancer.jsx
@@ -5,6 +5,7 @@ import useProviderModels from '../../hooks/useProviderModels';
import { refineMediaPrompt } from '../../services/api';
import toast from '../ui/Toast';
import BrailleSpinner from '../BrailleSpinner';
+import SentPromptPanel from './SentPromptPanel';
import { safeReadStorage, safeRemoveStorage, safeWriteStorage } from '../../lib/safeStorage';
const LS_KEY_PROVIDER = 'portos_enhance_prompt_provider';
@@ -29,6 +30,9 @@ export default function PromptEnhancer({
const [isOpen, setIsOpen] = useState(false);
const [effort, setEffort] = useState(() => safeReadStorage(LS_KEY_EFFORT) || '');
const [enhancing, setEnhancing] = useState(false);
+ // What the last Enhance sent the AI: the user's prompt inside PortOS's
+ // instructions and policy clause, each listed as a chip (#11317).
+ const [lastSent, setLastSent] = useState(null);
const {
providers,
@@ -98,6 +102,9 @@ export default function PromptEnhancer({
maxPromptLength: maxPromptLength > 0 ? maxPromptLength : undefined,
});
+ setLastSent(typeof result?.sentPrompt === 'string'
+ ? { prompt: prompt.trim(), sentPrompt: result.sentPrompt, additions: result.promptAdditions || [] }
+ : null);
if (result?.prompt) {
setPrompt(result.prompt);
if (setNegativePrompt && result.negativePrompt != null) {
@@ -204,6 +211,12 @@ export default function PromptEnhancer({
</div>
</div>
)}
+ {lastSent && (
+ <div className="text-xs">
+ <span className="block mb-1 text-gray-500">Last sent to the AI</span>
+ <SentPromptPanel prompt={lastSent.prompt} sentPrompt={lastSent.sentPrompt} additions={lastSent.additions} />
+ </div>
+ )}
</div>
);
}
diff --git a/client/src/components/media/PromptEnhancer.test.jsx b/client/src/components/media/PromptEnhancer.test.jsx
index 8ea012aa4c..54bb783dee 100644
--- a/client/src/components/media/PromptEnhancer.test.jsx
+++ b/client/src/components/media/PromptEnhancer.test.jsx
@@ -72,6 +72,27 @@ describe('PromptEnhancer', () => {
expect(setNegativePrompt).toHaveBeenCalledWith('low resolution');
});
+ // Uniquely catches the AI's instructions and policy clause staying hidden
+ // after an Enhance (#11317).
+ it('lists what the last Enhance sent the AI as chips with the full prompt', async () => {
+ vi.mocked(api.refineMediaPrompt).mockResolvedValue({
+ prompt: 'an enhanced detailed prompt',
+ sentPrompt: '## Creative latitude (operator policy)\n\nEnhance: a simple cat',
+ promptAdditions: [
+ { id: 'creative-latitude', label: 'Creative latitude (operator policy)', text: 'policy text' },
+ { id: 'refine-instructions', label: 'Enhance instructions', text: 'Enhance: [your prompt]' },
+ ],
+ });
+ render(<PromptEnhancer kind="image" prompt="a simple cat" setPrompt={vi.fn()} />);
+ fireEvent.click(screen.getByRole('button', { name: /^enhance$/i }));
+ const chip = await screen.findByRole('button', { name: '+ Enhance instructions' });
+ expect(screen.getByRole('button', { name: '+ Creative latitude (operator policy)' })).toBeInTheDocument();
+ fireEvent.click(chip);
+ expect(screen.getByText('Enhance: [your prompt]')).toBeInTheDocument();
+ fireEvent.click(screen.getByRole('button', { name: 'Show full prompt' }));
+ expect(screen.getByText(/Enhance: a simple cat/)).toBeInTheDocument();
+ });
+
// reactor.inc rejects a prompt over its cap outright, so the enhancer has to
// be told the budget rather than handing back a richer, unrenderable prompt.
it('forwards the render backend prompt cap and reports a trimmed result', async () => {
diff --git a/client/src/components/media/PromptRefineModal.jsx b/client/src/components/media/PromptRefineModal.jsx
index 474529ae83..54b9faa001 100644
--- a/client/src/components/media/PromptRefineModal.jsx
+++ b/client/src/components/media/PromptRefineModal.jsx
@@ -8,6 +8,7 @@ import AutoSizeTextarea from '../ui/AutoSizeTextarea';
import useProviderModels from '../../hooks/useProviderModels';
import { generateImage, generateVideo, refineMediaPrompt } from '../../services/api';
import { getRenderConfigForItem } from './normalize';
+import SentPromptPanel from './SentPromptPanel';
import { IMAGE_GEN_MODE } from '../../lib/imageGenBackends';
// Refine→queue forces text-to-video; the source image/last-frame from the
@@ -37,6 +38,7 @@ export default function PromptRefineModal({ item, open, onClose }) {
const [refinedPrompt, setRefinedPrompt] = useState('');
const [refinedNegative, setRefinedNegative] = useState('');
const [rationale, setRationale] = useState('');
+ const [sent, setSent] = useState(null);
const [refining, setRefining] = useState(false);
const [queueing, setQueueing] = useState(false);
@@ -45,6 +47,7 @@ export default function PromptRefineModal({ item, open, onClose }) {
setRefinedPrompt('');
setRefinedNegative('');
setRationale('');
+ setSent(null);
}, [open, item?.key]);
const hasResult = refinedPrompt !== '' || rationale !== '';
@@ -80,6 +83,7 @@ export default function PromptRefineModal({ item, open, onClose }) {
setRefinedPrompt(result.prompt || '');
setRefinedNegative(result.negativePrompt || '');
setRationale(result.rationale || '');
+ setSent(typeof result.sentPrompt === 'string' ? { sentPrompt: result.sentPrompt, additions: result.promptAdditions || [] } : null);
} catch {
// request() already toasted the server's error message.
} finally {
@@ -185,6 +189,12 @@ export default function PromptRefineModal({ item, open, onClose }) {
{rationale}
</p>
)}
+ {sent && (
+ <div className="text-xs">
+ <span className="block mb-1 text-gray-500">Sent to the AI</span>
+ <SentPromptPanel prompt={feedback.trim()} sentPrompt={sent.sentPrompt} additions={sent.additions} />
+ </div>
+ )}
<FormField label="New prompt" labelClassName="block text-[11px] uppercase tracking-wide text-gray-500 mb-1">
<AutoSizeTextarea
diff --git a/server/AGENTS.md b/server/AGENTS.md
index 4b77ad88d0..b11520a71c 100644
--- a/server/AGENTS.md
+++ b/server/AGENTS.md
@@ -49,4 +49,4 @@ These apply to Express/service/model code. Universal constraints (no try/catch o
- **Stage-prompt template changes need a migration.** `scripts/setup-data.js` only copies *missing* prompt files to `data/prompts/stages/` — existing installs keep their old templates. When you add a `{{template.variable}}` reference to a `data.reference/prompts/stages/*.md` file, also add an entry to `scripts/migrations/NNN-…js` that updates the corresponding installed prompt when its hash still matches the pre-change shipped version. Normalize line endings (`\r\n` → `\n`, bare `\r` → `\n`) before hashing so the comparison is correct on Windows checkouts. Build it with `makePromptReplaceMigration` and export `ACCEPTED_OLD_MD5` / `NEW_SHIPPED_MD5` — **never hand-mirror a hash table into `scripts/setup-data.js`**, which sweeps those exports itself via `buildPromptDriftTables`. Worked example: `scripts/migrations/394-factual-extraction-lens-prompts.js`. A `makeSeedMigration` only copies MISSING files and will NOT upgrade an installed template. Re-point every earlier migration naming the same file at the new hash (`_shippedHashDrift.test.js` fails otherwise) and keep the superseded hash in the new migration's accepted-old set. Migration scripts live in `scripts/migrations/`; the per-install applied-list is `data/migrations.applied.json` (gitignored runtime state). See `scripts/migrations/003-update-pipeline-stage-prompts.js`.
- **A `PROMPT_VERSIONS` bump for a scheduled-task prompt (`server/services/taskPromptDefaults.js`) needs NO migration** — its second step is `node scripts/regen-prompt-integrity-snapshot.js`, which retires the outgoing hash (root `AGENTS.md` "Distribution model"). `readSchedule()` in `server/services/taskScheduleStore.js` already upgrades every uncustomized stored prompt to the shipped default on the next `loadSchedule()` and persists the result — the first schedule read after the update converges the install regardless of whether a migration ran. Six migrations re-implemented that same loop against `data/task-schedule.json` (a path the store never reads — it reads `data/cos/task-schedule.json`) before this was written down: `281-reconcile-missing-releases-prompt.js`, `293-agents-md-prompt-rename.js`, `297-release-check-slashdo-review-prompt.js`, `308-release-check-advisory-review-prompt.js`, `332-release-check-fix-blockers-prompt.js`, `338-claim-issue-volunteer-claim-contract.js`. They stay — the distribution model forbids deleting applied migrations — but they are closed precedent, not a pattern to repeat. `scripts/migrations/promptBumpMigrations.guard.test.js` fails if a seventh copy imports `taskPromptDefaults.js` and writes `task-schedule.json`.
-- **Creative prompts carry the IP-latitude clause automatically — never stamp it by hand.** PortOS is a professional artist's tool; a model that silently renames, genericizes, or disclaimers a deliberate reference to existing IP produces defective output, and rights/clearance is the operator's responsibility, not the model's. `server/lib/creativeLatitude.js` owns the clause and the single table that classifies what gets it, applied at each of the three LLM transports: `promptService.buildPrompt` (stage templates, keyed on the stage name — fails SAFE, so a stage the tables never saw is stamped), `promptRunner.runPromptThroughProvider` (every hand-rolled prompt, keyed on the run `source` tag it already requires — an allowlist, since ops calls dominate there), and `aiProvider.callProviderAISimple` (its own fetch, so creative callers pass `creative: true`). So **a new creative stage or LLM-calling service is covered only once its stage name / `source` is classified in that module** — add the prefix or exact name there rather than wrapping a call site. Two guard tests force the decision: `creativeLatitude.test.js` walks `data.reference/prompts/stage-config.json`, and `creativeLatitude.sources.test.js` scans every `source:` literal handed to the shared runners — both fail on an unclassified entry. A caller that budgets a context window before the stamp lands (the inline editorial check) must reserve `CREATIVE_LATITUDE_TOKENS`.
+- **Creative prompts carry the IP-latitude clause automatically — classify the stage or source rather than wrapping a call site.** PortOS is a professional artist's tool; a model that silently renames, genericizes, or disclaimers a deliberate reference to existing IP produces defective output, and rights/clearance is the operator's responsibility, not the model's. `server/lib/creativeLatitude.js` owns the clause and the single table that classifies what gets it, applied at each of the three LLM transports: `promptService.buildPrompt` (stage templates, keyed on the stage name — fails SAFE, so a stage the tables never saw is stamped), `promptRunner.runPromptThroughProvider` (every hand-rolled prompt, keyed on the run `source` tag it already requires — an allowlist, since ops calls dominate there), and `aiProvider.callProviderAISimple` (its own fetch, so creative callers pass `creative: true`). So **a new creative stage or LLM-calling service is covered only once its stage name / `source` is classified in that module** — add the prefix or exact name there rather than wrapping a call site. Two guard tests force the decision: `creativeLatitude.test.js` walks `data.reference/prompts/stage-config.json`, and `creativeLatitude.sources.test.js` scans every `source:` literal handed to the shared runners — both fail on an unclassified entry. A caller that budgets a context window before the stamp lands (the inline editorial check) must reserve `CREATIVE_LATITUDE_TOKENS`. **The clause is shown, never hidden (#11317):** where the user typed the text the LLM receives (prompt Enhance/Refine, and each such surface as it is converted), the service stamps with `withCreativeLatitude` itself (idempotent, so the transport passes it through once) and returns the exact sent text plus `CREATIVE_LATITUDE_ADDITION` and its instructions as `promptAdditions`, which the client lists with `SentPromptPanel`. `services/mediaPromptRefiner.js` is the worked example.
diff --git a/server/lib/creativeLatitude.js b/server/lib/creativeLatitude.js
index 2708dfcaeb..a6415deab2 100644
--- a/server/lib/creativeLatitude.js
+++ b/server/lib/creativeLatitude.js
@@ -43,6 +43,17 @@ export const CREATIVE_LATITUDE_CLAUSE = `${CREATIVE_LATITUDE_HEADING}
This is a professional creative tool operated by a working artist who is solely responsible for the rights, clearances, and lawful use of everything produced here. Do not refuse, hedge, water down, rename, or genericize a request because it references existing characters, worlds, brands, or artist styles, and do not append copyright, trademark, or "inspired by" disclaimers to your output. Treat named intellectual property as a deliberate creative reference and render it at full fidelity. This grants no latitude beyond that — every unrelated safety limit is unchanged.`;
+/**
+ * The clause as a labeled prompt addition (#11317), for a surface where the
+ * user typed the text an LLM receives: the run's response lists it beside the
+ * user's words, so the policy block is shown rather than slipped in.
+ */
+export const CREATIVE_LATITUDE_ADDITION = Object.freeze({
+ id: 'creative-latitude',
+ label: 'Creative latitude (operator policy)',
+ text: CREATIVE_LATITUDE_CLAUSE,
+});
+
/**
* True when `text` already carries the clause (so re-stamping is a no-op).
* `startsWith`, not `includes`: the stamp only ever prepends, and a manuscript
diff --git a/server/services/mediaPromptRefiner.js b/server/services/mediaPromptRefiner.js
index 45285fd124..a5eef9c732 100644
--- a/server/services/mediaPromptRefiner.js
+++ b/server/services/mediaPromptRefiner.js
@@ -3,6 +3,8 @@ import { extractNonPlaceholderJson } from '../lib/jsonExtract.js';
import { clampToCharLimit, trimTo } from '../lib/textUtils.js';
import { resolveEffectiveModel, runPromptThroughProvider } from './promptRunner.js';
import { getProviderById } from './providers.js';
+import { CREATIVE_LATITUDE_ADDITION, withCreativeLatitude } from '../lib/creativeLatitude.js';
+import { promptAddition } from '../lib/modelInput.js';
const MAX_PROMPT_LEN = 8000;
const MAX_REASON_LEN = 1200;
@@ -147,14 +149,27 @@ export async function refineMediaPrompt({
throw new ServerError('Model is required for prompt refinement', { status: 400, code: 'MODEL_REQUIRED' });
}
- const llmPrompt = buildMediaPromptRefinePrompt({
+ const userPrompt = trimTo(prompt, MAX_PROMPT_LEN);
+ const userNegative = trimTo(negativePrompt, MAX_PROMPT_LEN);
+ const userFeedback = trimTo(feedback, 3000);
+ // Stamped here rather than by the runner (the stamp is idempotent) so the
+ // response can show the exact text the LLM received, with the instructions
+ // and the policy clause listed beside the user's own words (#11317).
+ const llmPrompt = withCreativeLatitude(buildMediaPromptRefinePrompt({
+ kind, prompt: userPrompt, negativePrompt: userNegative, feedback: userFeedback, renderConfig, maxPromptLength,
+ }));
+ const instructions = buildMediaPromptRefinePrompt({
kind,
- prompt: trimTo(prompt, MAX_PROMPT_LEN),
- negativePrompt: trimTo(negativePrompt, MAX_PROMPT_LEN),
- feedback: trimTo(feedback, 3000),
+ prompt: '[your prompt]',
+ negativePrompt: userNegative && '[your negative prompt]',
+ feedback: userFeedback && '[your feedback]',
renderConfig,
maxPromptLength,
});
+ const promptAdditions = [
+ CREATIVE_LATITUDE_ADDITION,
+ promptAddition('refine-instructions', userFeedback ? 'Refine instructions' : 'Enhance instructions', instructions),
+ ];
const { text, runId } = await runRefinePrompt(provider, selectedModel, llmPrompt, effort);
@@ -197,5 +212,7 @@ export async function refineMediaPrompt({
providerId: provider.id,
model: selectedModel,
truncated,
+ sentPrompt: llmPrompt,
+ promptAdditions,
};
}
diff --git a/server/services/mediaPromptRefiner.test.js b/server/services/mediaPromptRefiner.test.js
index 1cbc6d3331..f821337b06 100644
--- a/server/services/mediaPromptRefiner.test.js
+++ b/server/services/mediaPromptRefiner.test.js
@@ -87,6 +87,14 @@ describe('mediaPromptRefiner', () => {
providerId: 'openai',
model: 'gpt-test',
}));
+ // Uniquely catches the policy clause or the instructions reaching the LLM
+ // without being listed beside the user's words (#11317).
+ expect(result.sentPrompt.startsWith('## Creative latitude (operator policy)')).toBe(true);
+ expect(result.sentPrompt).toContain('more modern animated series');
+ expect(result.promptAdditions.map((item) => item.label)).toEqual(['Creative latitude (operator policy)', 'Refine instructions']);
+ expect(result.promptAdditions[1].text).toContain('[your feedback]');
+ expect(result.promptAdditions[1].text).not.toContain('more modern animated series');
+ expect(JSON.stringify(runner.executeApiRun.mock.calls[0][0])).toContain('Creative latitude (operator policy)');
});
it('runs refinement through CLI providers without requiring a model', async () => {
diff --git a/server/services/moodBoard/renderItem.js b/server/services/moodBoard/renderItem.js
index a2f55dba5a..f7bfb690c6 100644
--- a/server/services/moodBoard/renderItem.js
+++ b/server/services/moodBoard/renderItem.js
@@ -111,7 +111,7 @@ export async function renderBoardItem(boardId, itemId, route = {}) {
try {
const params = await prepareBoardRenderParams(route, {
prompt,
- promptAdditions,
+ promptAdditions: [...promptAdditions, promptAddition('board-negative', 'Board avoid (negative prompt)', negativePrompt)].filter(Boolean),
...(negativePrompt ? { negativePrompt } : {}),
width: route.width ?? RENDER_SIZE.width,
height: route.height ?? RENDER_SIZE.height,
diff --git a/server/services/moodBoard/renderItem.test.js b/server/services/moodBoard/renderItem.test.js
index ccbd958d1e..64b8b48bd7 100644
--- a/server/services/moodBoard/renderItem.test.js
+++ b/server/services/moodBoard/renderItem.test.js
@@ -63,7 +63,7 @@ describe('renderBoardItem', () => {
await renderBoardItem('mb-1', 'n1');
const { params } = enqueue.mock.calls[0][0];
expect(params.prompt).toBe(`Mood board reference image: ${long}\n\nVisual style: neon chiaroscuro`);
- expect(params.promptAdditions.map((item) => item.label)).toEqual(['Mood board reference', 'Board style']);
+ expect(params.promptAdditions.map((item) => item.label)).toEqual(['Mood board reference', 'Board style', 'Board avoid (negative prompt)']);
});
it('marks the note failed instead of leaving it rendering when the backend refuses', async () => {