🐛 don't overwrite story bible with new suggestions

This commit is contained in:
2026-03-03 11:12:06 +10:00
parent cc00c40214
commit 4ab1dc74c9
7 changed files with 82 additions and 20 deletions

View File

@@ -40,18 +40,16 @@ export function ChatMessageItem({ message, linkedAnnotations }: Props): JSX.Elem
}, [message.role, message.content])
const handleApplyToBible = async (): Promise<void> => {
await window.api.writeStoryBible(message.content)
// If the story bible is currently open, update the editor directly.
// setActiveFile(samePath, …) doesn't trigger the MarkdownEditor's sync effect
// (which only watches activeFilePath changes), so we use currentEditorView
// instead — the same pattern used by RevisionPanel.restore().
// writeStoryBible merges the new content into the existing bible by ## section
// and returns the full merged document.
const merged = await window.api.writeStoryBible(message.content)
// If the story bible is currently open, update the editor to show the merged result.
if (activeFilePath?.endsWith('Story Bible.md')) {
const view = currentEditorView
if (view) {
view.dispatch({
changes: { from: 0, to: view.state.doc.length, insert: message.content }
changes: { from: 0, to: view.state.doc.length, insert: merged }
})
// File is already saved — clear the dirty flag the dispatch just set
markSaved()
}
}
@@ -116,7 +114,7 @@ export function ChatMessageItem({ message, linkedAnnotations }: Props): JSX.Elem
<button
className="chat-apply-btn"
onClick={handleApplyToBible}
title="Replace Story Bible.md with this content"
title="Merge into Story Bible"
>
Apply to Story Bible
</button>

View File

@@ -25,11 +25,11 @@ const BIBLE_PROMPTS = {
Base everything strictly on what is in the manuscript text.`,
characters: `Read the full manuscript and write character profiles for the Story Bible's Characters section. For each named character include: role, physical description, personality traits, key relationships, and arc. Format as markdown subsections (### Name).`,
characters: `Read the full manuscript and write character profiles for the Story Bible. Begin your response with the heading \`## Characters\` followed by a blank line. For each named character include: role, physical description, personality traits, key relationships, and arc. Format each character as a ### subsection.`,
timeline: `Read the full manuscript and extract all significant events in chronological order for the Story Bible Timeline section. Reference chapters where helpful. Format as a markdown numbered list.`,
timeline: `Read the full manuscript and extract all significant events in chronological order for the Story Bible. Begin your response with the heading \`## Timeline\` followed by a blank line. Reference chapters where helpful. Format as a numbered list.`,
world: `Read the full manuscript and write a World & Setting entry for the Story Bible. Cover: the Basque Country geography and atmosphere, the historical period and cultural context, and key locations described in the text. Format as markdown.`
world: `Read the full manuscript and write a World & Setting section for the Story Bible. Begin your response with the heading \`## World & Setting\` followed by a blank line. Cover: the Basque Country geography and atmosphere, the historical period and cultural context, and key locations described in the text.`
}
function countWords(text: string): number {
@@ -98,9 +98,7 @@ export function AnalysisToolbar(): JSX.Element {
conversationHistory: chatHistory
.slice(-10)
.map((m) => ({ role: m.role, content: m.content })),
userMessage: prompt,
projectMode: true,
storyBibleMode: false
userMessage: prompt
},
(chunk: string) => {
appendToLastAssistantMessage(chunk)