Add chapter checkpoint feature

- New feature: bookmark messages to exclude earlier history from context
- Saves tokens by marking chapter start points in long chats
- Uses SillyTavern's /hide and /unhide slash commands
- Persists checkpoint across page reloads and generation events
- UI: bookmark icon in message menus with visual indicators
- Debounced restore function prevents concurrent executions
- Pre-generation checkpoint application ensures messages stay hidden
- Clean production-ready code with proper error handling
This commit is contained in:
Spicy_Marinara
2025-12-18 01:59:14 +01:00
parent 8645bbde98
commit 3ded104218
13 changed files with 870 additions and 236 deletions
+24 -2
View File
@@ -90,6 +90,12 @@ import {
import {
initTrackerEditor
} from './src/systems/ui/trackerEditor.js';
import {
initChapterCheckpointUI,
injectCheckpointButton,
updateAllCheckpointIndicators
} from './src/systems/ui/checkpointUI.js';
import { restoreCheckpointOnLoad } from './src/systems/features/chapterCheckpoint.js';
import {
togglePlotButtons,
updateCollapseToggleIcon,
@@ -129,7 +135,8 @@ import {
onCharacterChanged,
onMessageSwiped,
updatePersonaAvatar,
clearExtensionPrompts
clearExtensionPrompts,
onGenerationEnded
} from './src/systems/integration/sillytavern.js';
// Old state variable declarations removed - now imported from core modules
@@ -366,6 +373,11 @@ async function initUI() {
saveSettings();
});
$('#rpg-save-tracker-history').on('change', function() {
extensionSettings.saveTrackerHistory = $(this).prop('checked');
saveSettings();
});
$('#rpg-toggle-plot-buttons').on('change', function() {
extensionSettings.enablePlotButtons = $(this).prop('checked');
// console.log('[RPG Companion] Toggle enablePlotButtons changed to:', extensionSettings.enablePlotButtons);
@@ -478,6 +490,7 @@ async function initUI() {
$('#rpg-custom-highlight').val(extensionSettings.customColors.highlight);
$('#rpg-generation-mode').val(extensionSettings.generationMode);
$('#rpg-skip-guided-mode').val(extensionSettings.skipInjectionsForGuided);
$('#rpg-save-tracker-history').prop('checked', extensionSettings.saveTrackerHistory);
updatePanelVisibility();
updateSectionVisibility();
@@ -515,6 +528,10 @@ async function initUI() {
setupContentEditableScrolling();
initInventoryEventListeners();
// Initialize chapter checkpoint UI
initChapterCheckpointUI();
injectCheckpointButton();
// Setup Memory Recollection button in World Info
setupMemoryRecollectionButton();
@@ -683,7 +700,9 @@ jQuery(async () => {
[event_types.MESSAGE_SENT]: onMessageSent,
[event_types.GENERATION_STARTED]: onGenerationStarted,
[event_types.MESSAGE_RECEIVED]: onMessageReceived,
[event_types.CHAT_CHANGED]: [onCharacterChanged, updatePersonaAvatar],
[event_types.GENERATION_STOPPED]: onGenerationEnded,
[event_types.GENERATION_ENDED]: onGenerationEnded,
[event_types.CHAT_CHANGED]: [onCharacterChanged, updatePersonaAvatar, restoreCheckpointOnLoad],
[event_types.MESSAGE_SWIPED]: onMessageSwiped,
[event_types.USER_MESSAGE_RENDERED]: updatePersonaAvatar,
[event_types.SETTINGS_UPDATED]: updatePersonaAvatar
@@ -693,6 +712,9 @@ jQuery(async () => {
throw error; // This is critical - can't continue without events
}
// Restore checkpoint state if one exists
await restoreCheckpointOnLoad();
console.log('[RPG Companion] ✅ Extension loaded successfully');
} catch (error) {
console.error('[RPG Companion] ❌ Critical initialization failure:', error);