Skip to content

Fix file associations lost when restoring prompts with conflict resolution - #7

Draft
SegaraRai with Copilot wants to merge 9 commits into
mainfrom
copilot/fix-2
Draft

Fix file associations lost when restoring prompts with conflict resolution#7
SegaraRai with Copilot wants to merge 9 commits into
mainfrom
copilot/fix-2

Conversation

Copilot AI commented Jul 24, 2025

Copy link
Copy Markdown

Problem

When restoring prompts that were linked to files, the system would load the current file content instead of preserving the original prompt that was saved. This caused data loss when files were modified after the prompt was saved, and there was no way for users to choose between the original saved content and the current file content.

Solution

This PR implements a comprehensive conflict resolution system for file restoration:

1. Enhanced Embedding Format

Added a new FILE_DATA: format that preserves original content even for linked files:

// NEW: Preserves original content + enables conflict detection
/*# PROMPT_STUDIO_SRC: FILE_DATA:filename.txt:encoded_original_content */

// LEGACY: Only stores filename reference (still supported)
/*# PROMPT_STUDIO_SRC: FILE:filename.txt */

2. Conflict Detection

The system now automatically detects when saved content differs from current file content:

const result = await extractOriginalPrompt(compiledText, fileAPI, true);
if (result.conflict) {
  // Show conflict resolution dialog
  console.log('Saved:', result.conflict.savedPrompt);
  console.log('Current:', result.conflict.currentFileContent);
}

3. User Choice Dialog

When conflicts are detected, users get a clear dialog with two options:

  • "Keep saved version as untitled": Uses the original saved content, unlinks from file
  • "Use current file content": Uses current file content, maintains file association

4. Robust Edge Case Handling

  • No conflict: Content matches → normal restoration
  • File missing: Uses saved content as untitled (no error)
  • Legacy prompts: Full backward compatibility maintained

Key Features

  • Optional behavior: Controlled by encodeOriginalForLinkedFiles setting (defaults to true)
  • No data loss: Original content is always preserved
  • Backward compatible: Existing saved prompts continue to work
  • Comprehensive testing: Full test coverage for all scenarios
  • Clean UI: Intuitive conflict resolution dialog with side-by-side comparison

Example Usage

// Enable enhanced file restoration (default)
settings.encodeOriginalForLinkedFiles = true;

// When user restores a prompt with conflicts:
// 1. System detects content mismatch automatically
// 2. Shows dialog with both versions
// 3. User chooses preferred option  
// 4. Document state updates accordingly

This implementation ensures that file associations are properly preserved and users never lose their original prompt content, while providing clear choices when conflicts arise.

Fixes #2.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.jsdelivr.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/ComfyUI-Prompt-Studio/ComfyUI-Prompt-Studio/node_modules/.bin/vite build (dns block)
  • eu.posthog.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/ComfyUI-Prompt-Studio/ComfyUI-Prompt-Studio/node_modules/.bin/vite build (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 3 commits July 24, 2025 16:30
Co-authored-by: SegaraRai <29276700+SegaraRai@users.noreply.github.com>
Co-authored-by: SegaraRai <29276700+SegaraRai@users.noreply.github.com>
Co-authored-by: SegaraRai <29276700+SegaraRai@users.noreply.github.com>
Copilot AI changed the title [WIP] File associations are lost when restoring prompts Fix file associations lost when restoring prompts with conflict resolution Jul 24, 2025
Copilot AI requested a review from SegaraRai July 24, 2025 16:57
@SegaraRai

Copy link
Copy Markdown
Owner

@copilot

  • Discard the undo history after restore.
  • If the value is updated during editing and another restore occurs, resulting in a mismatch, display a conflict prompt.
  • Ignore backward compatibility and simplify code

Copilot AI commented Jul 24, 2025

Copy link
Copy Markdown
Author

@copilot

  • Discard the undo history after restore.
    ...

I'll implement these changes:

  1. Discard undo history after restore - Clear the editor's undo history after restoration completes
  2. Handle editing conflicts during restore - Show conflict dialog when restoring differs from current edited content
  3. Simplify code - Remove backward compatibility, always use FILE_DATA format for linked files

Starting implementation now.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.jsdelivr.net
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/ComfyUI-Prompt-Studio/ComfyUI-Prompt-Studio/node_modules/.bin/../vite/bin/vite.js build (dns block)
    • Triggering command: node /home/REDACTED/work/ComfyUI-Prompt-Studio/ComfyUI-Prompt-Studio/node_modules/.bin/../vite/bin/vite.js dev (dns block)
  • eu.posthog.com
    • Triggering command: node (vitest) (dns block)
    • Triggering command: node /home/REDACTED/work/ComfyUI-Prompt-Studio/ComfyUI-Prompt-Studio/node_modules/.bin/../vite/bin/vite.js build (dns block)
    • Triggering command: node /home/REDACTED/work/ComfyUI-Prompt-Studio/ComfyUI-Prompt-Studio/node_modules/.bin/../vite/bin/vite.js dev (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Co-authored-by: SegaraRai <29276700+SegaraRai@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

File associations are lost when restoring prompts

2 participants