From ba126989083dd2141ac7b09b9cf7565503f69032 Mon Sep 17 00:00:00 2001 From: aomukai Date: Sun, 16 Nov 2025 02:57:30 +0900 Subject: [PATCH] feat: Add 'Always in Context' checkbox and enhance compendium entry resolution logic --- main.html | 18 ++++++++++++- src/modules/beat-mentions.js | 42 ++++++++++++++++++++++--------- src/modules/compendium-manager.js | 3 ++- src/save-utils.js | 5 ++++ 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/main.html b/main.html index 107ffe4..6830d0d 100644 --- a/main.html +++ b/main.html @@ -338,7 +338,7 @@
@@ -1432,6 +1432,22 @@
+ + +
+ +

+ When enabled, this entry will be automatically included in all prose + generation prompts (useful for style guides, world rules, etc.) +

+
diff --git a/src/modules/beat-mentions.js b/src/modules/beat-mentions.js index e6e691b..c4c3846 100644 --- a/src/modules/beat-mentions.js +++ b/src/modules/beat-mentions.js @@ -245,29 +245,47 @@ /** * Parse beatInput for @[Title] mentions and return resolved compendium rows + * Also includes entries marked with alwaysInContext flag * @param {Object} app - Alpine app instance * @param {string} beatText - Beat text to parse * @returns {Promise} Array of compendium entries */ async resolveCompendiumEntriesFromBeat(app, beatText) { try { - if (!beatText) return []; const ids = new Set(); - // Parse @[Title] mentions and look up IDs from our mapping - const reMention = /@\[([^\]]+)\]/g; - let m; - while ((m = reMention.exec(beatText)) !== null) { - const title = m[1]; - if (app.beatCompendiumMap[title]) { - ids.add(app.beatCompendiumMap[title]); + // First, add all entries marked as "always in context" for the current project + if (app.currentProject && app.currentProject.id) { + try { + const alwaysInContext = await db.compendium + .where('projectId') + .equals(app.currentProject.id) + .filter(e => e.alwaysInContext === true) + .toArray(); + for (const entry of alwaysInContext) { + ids.add(entry.id); + } + } catch (e) { + console.warn('Failed to fetch alwaysInContext entries:', e); } } - // Also support legacy formats for backward compatibility - const reLegacy = /\[\[comp:([^\]]+)\]\]/g; - while ((m = reLegacy.exec(beatText)) !== null) { - if (m[1]) ids.add(m[1]); + // Parse @[Title] mentions and look up IDs from our mapping + if (beatText) { + const reMention = /@\[([^\]]+)\]/g; + let m; + while ((m = reMention.exec(beatText)) !== null) { + const title = m[1]; + if (app.beatCompendiumMap[title]) { + ids.add(app.beatCompendiumMap[title]); + } + } + + // Also support legacy formats for backward compatibility + const reLegacy = /\[\[comp:([^\]]+)\]\]/g; + while ((m = reLegacy.exec(beatText)) !== null) { + if (m[1]) ids.add(m[1]); + } } const out = []; diff --git a/src/modules/compendium-manager.js b/src/modules/compendium-manager.js index c1b3a89..7067cdc 100644 --- a/src/modules/compendium-manager.js +++ b/src/modules/compendium-manager.js @@ -112,7 +112,8 @@ title: app.currentCompEntry.title || '', body: app.currentCompEntry.body || '', tags: JSON.parse(JSON.stringify(app.currentCompEntry.tags || [])), - imageUrl: app.currentCompEntry.imageUrl || null + imageUrl: app.currentCompEntry.imageUrl || null, + alwaysInContext: app.currentCompEntry.alwaysInContext || false }; await window.Compendium.updateEntry(app.currentCompEntry.id, updates); await this.loadCompendiumCategory(app, app.currentCompCategory); diff --git a/src/save-utils.js b/src/save-utils.js index 71839e3..7997f39 100644 --- a/src/save-utils.js +++ b/src/save-utils.js @@ -52,6 +52,11 @@ wordCount }; + // Track mentioned compendium entries from beat field + if (app.beatCompendiumMap && Object.keys(app.beatCompendiumMap).length > 0) { + scenePatch.mentionedEntries = Object.values(app.beatCompendiumMap); + } + // If the content changed and there was an existing summary, mark the summary stale try { const contentChanged = prevContent && (prevContent.text || '') !== (scene.content || '');