design-docs/prompt-history-refactor.md
Simplify edit prompt history so we no longer reconstruct conversation state from commit ancestry and index parity.
The new model is:
sourceVersionNumber field is required.
Before this refactor:
extractHistory(...) by walking commit parent links.assistant for even, user for odd).Each variant now carries its own history:
Variant.history: VariantHistoryMessage[]VariantHistoryMessage:
role: "user" | "assistant"text: stringimageAssetIds: string[]videoAssetIds: string[]This history is authoritative for that variant.
Frontend keeps media in one shared map:
assetsById: Record<string, PromptAsset>PromptAsset:
idtype: "image" | "video"dataUrlVariant history references media by ID, not by embedding large base64 strings directly.
App.tsxPrompt-history/media helper logic moved to:
frontend/src/lib/prompt-history.tsKey helpers:
cloneVariantHistory(...)registerAssetIds(...)toRequestHistory(...)buildUserHistoryMessage(...)buildAssistantHistoryMessage(...)variantHistory with a single user message.assetsById and referenced by IDs in the variant history.prompt (create input)variantHistory (for local commit state)user update message (+ optional media IDs).role, text, images, videos) via toRequestHistory(...).On variant completion:
assistant history message for that specific variant.We still keep flat version labels (v1, v2, ...), but edits can branch from any selected version/variant.
Important detail:
When sending an edit, frontend sends explicit role history like:
history[i].role: "user" or "assistant"history[i].text: textual instruction or generated codehistory[i].images: data URLs for image inputs for that messagehistory[i].videos: data URLs for video inputs for that messageBackend does not infer roles by index anymore; it uses the provided role directly.
Raw request normalization moved into:
backend/prompts/request_parsing.pyFunctions:
parse_prompt_content(raw_prompt)parse_prompt_history(raw_history)generate_code.py now calls these helpers, so the route file is smaller and parsing is centralized.
backend/prompts/builders.py now:
PromptHistoryMessage entries.role directly (no index parity inference).system messageImported-code update logic now works with explicit role history and chooses the latest relevant user instruction cleanly.
PROMPT SUMMARY logging from generation path.PROMPT PREVIEW logging before model execution.backend/tests/test_prompts.pybackend/tests/test_prompts_additional.pybackend/tests/test_request_parsing.pybackend/tests/test_prompt_summary.pyextractHistory tests and updated fixtures:
frontend/src/components/history/utils.test.tsfrontend/src/lib/prompt-history.test.tsThe prompt-history pipeline is now explicit, variant-local, and much easier to reason about: