@michelabboud/visual-forge-mcp 0.5.6 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +814 -0
- package/dist/types/generation.d.ts +7 -1
- package/dist/types/generation.d.ts.map +1 -1
- package/dist/utils/image-optimizer.d.ts +91 -0
- package/dist/utils/image-optimizer.d.ts.map +1 -0
- package/dist/utils/image-optimizer.js +241 -0
- package/dist/utils/image-optimizer.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/workflow/workflow-orchestrator.d.ts.map +1 -1
- package/dist/workflow/workflow-orchestrator.js +34 -1
- package/dist/workflow/workflow-orchestrator.js.map +1 -1
- package/docs/guides/README.md +24 -0
- package/docs/guides/backup-system-flow.md +511 -0
- package/docs/guides/backup-system.md +688 -0
- package/docs/guides/development-testing.md +338 -0
- package/docs/guides/html-support.md +548 -0
- package/docs/guides/image-optimization.md +370 -0
- package/docs/guides/testing.md +279 -0
- package/docs/guides/usage-examples.md +101 -0
- package/docs/guides/vf-workflow.md +112 -0
- package/docs/guides/workflow-with-backups.md +471 -0
- package/package.json +15 -3
- package/dist/.gitkeep +0 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Example: Visual Forge MCP Usage
|
|
2
|
+
|
|
3
|
+
This document demonstrates how to define images for generation using Visual Forge MCP.
|
|
4
|
+
|
|
5
|
+
## Hero Image
|
|
6
|
+
|
|
7
|
+
```image
|
|
8
|
+
type: hero
|
|
9
|
+
aspectRatio: 16:9
|
|
10
|
+
section: Introduction
|
|
11
|
+
prompt: Create a vibrant hero image showing a developer at a modern workspace with multiple monitors displaying code and documentation, futuristic tech aesthetic, clean and professional
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Architecture Diagram
|
|
15
|
+
|
|
16
|
+
```image
|
|
17
|
+
type: architecture
|
|
18
|
+
aspectRatio: 16:9
|
|
19
|
+
section: System Architecture
|
|
20
|
+
prompt: System architecture diagram showing microservices architecture with API gateway at center, multiple service pods, message queue, database cluster, and caching layer, modern tech style with clean lines
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Flow Chart
|
|
24
|
+
|
|
25
|
+
```image
|
|
26
|
+
type: flowchart
|
|
27
|
+
aspectRatio: 4:3
|
|
28
|
+
section: User Authentication
|
|
29
|
+
prompt: User authentication flow diagram starting from login page, through credential validation, 2FA verification, session creation, and ending at dashboard, include error paths and retry logic
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Technical Diagram
|
|
33
|
+
|
|
34
|
+
```image
|
|
35
|
+
type: diagram
|
|
36
|
+
aspectRatio: 16:9
|
|
37
|
+
section: Data Pipeline
|
|
38
|
+
alt: Data pipeline architecture
|
|
39
|
+
caption: End-to-end data processing pipeline
|
|
40
|
+
prompt: Data pipeline diagram showing data ingestion from multiple sources, transformation stages, quality checks, and storage in data warehouse, with monitoring and alerting components
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Icon Set
|
|
44
|
+
|
|
45
|
+
```image
|
|
46
|
+
type: icon
|
|
47
|
+
aspectRatio: 1:1
|
|
48
|
+
section: Feature Icons
|
|
49
|
+
prompt: Set of 4 modern minimalist icons representing: code, deployment, monitoring, and security, flat design with blue accent color
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Screenshots
|
|
53
|
+
|
|
54
|
+
```image
|
|
55
|
+
type: screenshot
|
|
56
|
+
aspectRatio: 16:9
|
|
57
|
+
section: User Interface
|
|
58
|
+
prompt: Modern dashboard interface showing analytics charts, user activity metrics, and system health indicators, clean Material Design aesthetic
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage Instructions
|
|
62
|
+
|
|
63
|
+
1. Save this file (or your own markdown files with image blocks)
|
|
64
|
+
2. Start Visual Forge MCP server
|
|
65
|
+
3. Use the MCP tools:
|
|
66
|
+
|
|
67
|
+
```javascript
|
|
68
|
+
// Parse this file
|
|
69
|
+
parse_markdown({ filePaths: ["./example.md"] })
|
|
70
|
+
|
|
71
|
+
// List what was parsed
|
|
72
|
+
list_images()
|
|
73
|
+
|
|
74
|
+
// Generate a single image
|
|
75
|
+
generate_image({
|
|
76
|
+
imageId: "hero-img-01",
|
|
77
|
+
provider: "replicate"
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
// Or generate all images
|
|
81
|
+
start_workflow({
|
|
82
|
+
mode: "bulk",
|
|
83
|
+
provider: "replicate",
|
|
84
|
+
concurrency: 3
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
// Monitor progress
|
|
88
|
+
get_status()
|
|
89
|
+
|
|
90
|
+
// Check costs
|
|
91
|
+
get_cost_summary()
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Tips
|
|
95
|
+
|
|
96
|
+
- Use descriptive prompts with specific details
|
|
97
|
+
- Specify aspect ratio based on where image will be used
|
|
98
|
+
- Include style guidance in prompt (flat, realistic, minimalist, etc.)
|
|
99
|
+
- Consider cost vs quality tradeoffs when choosing provider
|
|
100
|
+
- Start with no-cost providers (Gemini, HuggingFace) for testing
|
|
101
|
+
- Use Replicate/FLUX for production (best value at $0.003/image)
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# VF Parse Workflow - Quick Reference
|
|
2
|
+
|
|
3
|
+
## Complete Steps (26 Total)
|
|
4
|
+
|
|
5
|
+
### Phase 1: Session Setup & File Collection (Steps 1-6)
|
|
6
|
+
1. User initiates VF Parse command
|
|
7
|
+
2. Ask about Git workflow (branch/PR)
|
|
8
|
+
3. Execute Git operations if requested
|
|
9
|
+
4. Ask for additional files
|
|
10
|
+
5. Continue file collection loop
|
|
11
|
+
6. Display file list and get approval
|
|
12
|
+
|
|
13
|
+
### Phase 2: Session Initialization & Context (Steps 7-10)
|
|
14
|
+
7. Create session folder in `~/.visual-forge-mcp/sessions/[id]/`
|
|
15
|
+
8. Ask for global theme/context/style
|
|
16
|
+
9. Build global context pre-prompt
|
|
17
|
+
10. Show theme/context for approval
|
|
18
|
+
|
|
19
|
+
### Phase 3: File Processing & Placeholder Addition (Steps 11-14)
|
|
20
|
+
11. Process each file sequentially
|
|
21
|
+
12. Add image placeholders automatically with "Visual Forge Place Holder" title
|
|
22
|
+
13. Update session tracking
|
|
23
|
+
14. Parse all modified files
|
|
24
|
+
|
|
25
|
+
### Phase 4: Image Generation (Steps 15-17)
|
|
26
|
+
15. Ask for provider selection
|
|
27
|
+
16. Start bulk generation with global context prepended
|
|
28
|
+
17. Monitor generation progress
|
|
29
|
+
|
|
30
|
+
### Phase 5: Automatic Document Update (Steps 18-19)
|
|
31
|
+
18. Replace placeholders with image links automatically
|
|
32
|
+
19. Update session tracking
|
|
33
|
+
|
|
34
|
+
### Phase 6: Review & Refinement (Steps 20-23)
|
|
35
|
+
20. Show completion summary
|
|
36
|
+
21. Ask user to review
|
|
37
|
+
22. Handle user feedback (regenerate/remove/replace)
|
|
38
|
+
23. Continue review loop until satisfied
|
|
39
|
+
|
|
40
|
+
### Phase 7: Finalization (Steps 24-26)
|
|
41
|
+
24. Final approval
|
|
42
|
+
25. Git operations (commit/PR if applicable)
|
|
43
|
+
26. Close session and show summary
|
|
44
|
+
|
|
45
|
+
## Session Recovery
|
|
46
|
+
- All data saved to `~/.visual-forge-mcp/sessions/[session-id]/`
|
|
47
|
+
- Can resume interrupted sessions
|
|
48
|
+
- Ask user if they want to resume incomplete session
|
|
49
|
+
|
|
50
|
+
## Key Files Created Per Session
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
~/.visual-forge-mcp/sessions/[session-id]/
|
|
54
|
+
├── session-info.json # Session state and tracking
|
|
55
|
+
├── global-context.txt # Global theme/style context
|
|
56
|
+
└── [original-files-backup]/ # Optional: backup of originals
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Session Info JSON Structure
|
|
60
|
+
|
|
61
|
+
```json
|
|
62
|
+
{
|
|
63
|
+
"sessionId": "vf-session-20260113-123456",
|
|
64
|
+
"timestamp": "2026-01-13T12:34:56Z",
|
|
65
|
+
"files": ["README.md", "docs/guide.md"],
|
|
66
|
+
"gitBranch": "feature/visual-forge-images-20260113",
|
|
67
|
+
"status": "initializing|processing|parsing_complete|generating|generation_complete|completed",
|
|
68
|
+
"globalContext": "Professional technical documentation style...",
|
|
69
|
+
"provider": "gemini",
|
|
70
|
+
"images": [
|
|
71
|
+
{
|
|
72
|
+
"imageId": "README-img-01",
|
|
73
|
+
"file": "README.md",
|
|
74
|
+
"type": "hero",
|
|
75
|
+
"status": "placeholder_added|generating|generated|failed|inserted_into_document",
|
|
76
|
+
"addedAt": "2026-01-13T12:35:00Z",
|
|
77
|
+
"generatedAt": "2026-01-13T12:38:00Z",
|
|
78
|
+
"insertedAt": "2026-01-13T12:40:00Z",
|
|
79
|
+
"filepath": "generated-images/gemini/README-img-01.png",
|
|
80
|
+
"cost": 0.0
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"totalCost": 0.0,
|
|
84
|
+
"completedAt": "2026-01-13T12:45:00Z"
|
|
85
|
+
}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Important Principles
|
|
89
|
+
|
|
90
|
+
✅ **Always add "Visual Forge Place Holder" title**
|
|
91
|
+
✅ **Prepend global context to all image prompts**
|
|
92
|
+
✅ **Automatically update documents after generation**
|
|
93
|
+
✅ **Track everything in session-info.json**
|
|
94
|
+
✅ **Enable session recovery if interrupted**
|
|
95
|
+
✅ **Ask for approval at key milestones**
|
|
96
|
+
✅ **Support user feedback loop for changes**
|
|
97
|
+
|
|
98
|
+
## VF Command Aliases
|
|
99
|
+
|
|
100
|
+
All these are equivalent:
|
|
101
|
+
- `VF Parse [file]` ✅ DEFAULT
|
|
102
|
+
- `Visual Parse [file]`
|
|
103
|
+
- `Visual Forge Parse [file]`
|
|
104
|
+
- `Visual Forge [file]`
|
|
105
|
+
- `VF [file]`
|
|
106
|
+
|
|
107
|
+
## Quick Commands
|
|
108
|
+
|
|
109
|
+
- `VF status` - Check workflow status
|
|
110
|
+
- `VF costs` - Show cost summary
|
|
111
|
+
- `VF list` - List parsed images
|
|
112
|
+
- `VF providers` - Show available providers
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
# Visual Forge MCP - Workflow with Backup System
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
This document describes how the backup system integrates with the Visual Forge MCP workflow. The backup system provides automatic, transparent protection for your markdown files and generated images during the image generation workflow.
|
|
6
|
+
|
|
7
|
+
## Workflow Phases
|
|
8
|
+
|
|
9
|
+
### Phase 1: Session Start
|
|
10
|
+
|
|
11
|
+
When you start a new Visual Forge session, the system automatically checks for pending backups from previous sessions.
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
// User calls: vf_start_session
|
|
15
|
+
{
|
|
16
|
+
files: ['docs/README.md'],
|
|
17
|
+
createBranch: true
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// System Response:
|
|
21
|
+
{
|
|
22
|
+
success: true,
|
|
23
|
+
sessionId: 'session-abc-123',
|
|
24
|
+
backupReminder: {
|
|
25
|
+
hasReminder: true,
|
|
26
|
+
message: '⏰ Reminder: You have pending backups from a previous session',
|
|
27
|
+
summary: '📸 Backup: backup-xyz-789\n Created: 26 hours ago\n Files: 2 markdown, 5 images',
|
|
28
|
+
actions: {
|
|
29
|
+
approve: 'Call approve_changes to keep modifications',
|
|
30
|
+
restore: 'Call restore_from_backups to undo all changes'
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
**Backup Check Logic:**
|
|
37
|
+
- If a backup is older than 24 hours, a reminder is shown
|
|
38
|
+
- Users are informed about pending backups before starting new work
|
|
39
|
+
- Users can approve or restore previous backups before continuing
|
|
40
|
+
|
|
41
|
+
### Phase 2: Process Files
|
|
42
|
+
|
|
43
|
+
Files are parsed and placeholders are added. No backup is created at this stage since markdown files aren't modified yet.
|
|
44
|
+
|
|
45
|
+
```typescript
|
|
46
|
+
// User calls: vf_process_files
|
|
47
|
+
{
|
|
48
|
+
sessionId: 'session-abc-123'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// System Response:
|
|
52
|
+
{
|
|
53
|
+
success: true,
|
|
54
|
+
filesProcessed: 1,
|
|
55
|
+
placeholdersAdded: 3,
|
|
56
|
+
imagesFound: 3
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Phase 3: Generate Images
|
|
61
|
+
|
|
62
|
+
This is where the backup system activates. After images are generated but **before** modifying markdown files:
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// User calls: vf_generate_session
|
|
66
|
+
{
|
|
67
|
+
sessionId: 'session-abc-123',
|
|
68
|
+
provider: 'gemini',
|
|
69
|
+
mode: 'bulk'
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Internal Workflow:
|
|
73
|
+
1. Generate all images (3 images created)
|
|
74
|
+
2. 🔒 CREATE BACKUP (automatic, transparent)
|
|
75
|
+
- Backup markdown files
|
|
76
|
+
- Backup generated images
|
|
77
|
+
- Store backup metadata in state
|
|
78
|
+
3. Replace placeholders with image references
|
|
79
|
+
4. Update markdown files
|
|
80
|
+
|
|
81
|
+
// System Response:
|
|
82
|
+
{
|
|
83
|
+
success: true,
|
|
84
|
+
imagesGenerated: 3,
|
|
85
|
+
totalCost: 0.45,
|
|
86
|
+
filesUpdated: ['docs/README.md'],
|
|
87
|
+
backup: {
|
|
88
|
+
backupCreated: true,
|
|
89
|
+
backupId: 'backup-def-456',
|
|
90
|
+
filesBackedUp: 4, // 1 markdown + 3 images
|
|
91
|
+
backupMessage: 'Files backed up. To keep changes: call approve_changes. To undo: call restore_from_backups.'
|
|
92
|
+
},
|
|
93
|
+
nextAction: 'Review images. To keep: call approve_changes. To undo: call restore_from_backups. Then call vf_finalize_session to commit.'
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Backup Creation Details:**
|
|
98
|
+
- **When**: After images are generated, before markdown modification
|
|
99
|
+
- **What**: Markdown files + Generated images
|
|
100
|
+
- **Where**: `.vf-bak` files alongside originals
|
|
101
|
+
- **Integrity**: MD5 hash verification
|
|
102
|
+
- **State**: Tracked in StateManager for persistence
|
|
103
|
+
|
|
104
|
+
### Phase 4: Review and Decision
|
|
105
|
+
|
|
106
|
+
Users review the generated images and decide whether to keep or undo the changes.
|
|
107
|
+
|
|
108
|
+
#### Option A: Keep Changes (Approve)
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
// User calls: approve_changes
|
|
112
|
+
{}
|
|
113
|
+
|
|
114
|
+
// System Response:
|
|
115
|
+
{
|
|
116
|
+
success: true,
|
|
117
|
+
message: 'Changes approved successfully',
|
|
118
|
+
filesDeleted: 4,
|
|
119
|
+
backupId: 'backup-def-456'
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Result:
|
|
123
|
+
- Backup files deleted (.vf-bak files removed)
|
|
124
|
+
- Modified files kept
|
|
125
|
+
- Backup moved to history
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
#### Option B: Undo Changes (Restore)
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// User calls: restore_from_backups
|
|
132
|
+
{}
|
|
133
|
+
|
|
134
|
+
// System Response:
|
|
135
|
+
{
|
|
136
|
+
success: true,
|
|
137
|
+
message: 'All files restored successfully',
|
|
138
|
+
filesRestored: 4,
|
|
139
|
+
backupId: 'backup-def-456'
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Result:
|
|
143
|
+
- Original files restored
|
|
144
|
+
- Generated images removed
|
|
145
|
+
- Backup files deleted
|
|
146
|
+
- Backup moved to history
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
### Phase 5: Finalize Session
|
|
150
|
+
|
|
151
|
+
After approving or restoring, finalize the session with git operations.
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
// User calls: vf_finalize_session
|
|
155
|
+
{
|
|
156
|
+
sessionId: 'session-abc-123',
|
|
157
|
+
commit: true,
|
|
158
|
+
createPR: true
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// System Response:
|
|
162
|
+
{
|
|
163
|
+
success: true,
|
|
164
|
+
summary: {
|
|
165
|
+
filesModified: ['docs/README.md'],
|
|
166
|
+
imagesGenerated: 3,
|
|
167
|
+
totalCost: 0.45,
|
|
168
|
+
prUrl: 'https://github.com/user/repo/pull/123'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Backup States and Transitions
|
|
174
|
+
|
|
175
|
+
```
|
|
176
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
177
|
+
│ Backup Lifecycle │
|
|
178
|
+
└─────────────────────────────────────────────────────────────┘
|
|
179
|
+
|
|
180
|
+
NO BACKUP
|
|
181
|
+
↓
|
|
182
|
+
↓ (Images generated)
|
|
183
|
+
↓
|
|
184
|
+
BACKUP CREATED
|
|
185
|
+
├─→ (approve_changes) ─→ APPROVED → History
|
|
186
|
+
└─→ (restore_from_backups) ─→ RESTORED → History
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Backup States
|
|
190
|
+
|
|
191
|
+
| State | Description | Next Actions |
|
|
192
|
+
|-------|-------------|--------------|
|
|
193
|
+
| **No Backup** | No pending backups | Generate images |
|
|
194
|
+
| **Backup Created** | Backup exists, pending decision | approve_changes OR restore_from_backups |
|
|
195
|
+
| **Approved** | Changes kept, backup deleted | Archived in history |
|
|
196
|
+
| **Restored** | Changes undone, backup deleted | Archived in history |
|
|
197
|
+
|
|
198
|
+
## MCP Tools Reference
|
|
199
|
+
|
|
200
|
+
### Check Backup Status
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
// User calls: list_backups
|
|
204
|
+
{}
|
|
205
|
+
|
|
206
|
+
// Response with pending backup:
|
|
207
|
+
{
|
|
208
|
+
hasPendingBackups: true,
|
|
209
|
+
current: {
|
|
210
|
+
id: 'backup-def-456',
|
|
211
|
+
createdAt: '2026-01-13T10:00:00Z',
|
|
212
|
+
markdownFiles: 1,
|
|
213
|
+
imageFiles: 3,
|
|
214
|
+
totalFiles: 4,
|
|
215
|
+
totalSize: 2048576,
|
|
216
|
+
needsReminder: false
|
|
217
|
+
},
|
|
218
|
+
summary: '📸 Backup: backup-def-456\n Created: 2 hours ago\n Files: 1 markdown, 3 images\n Size: 2.00 MB',
|
|
219
|
+
actions: {
|
|
220
|
+
approve: 'Call approve_changes to keep modifications',
|
|
221
|
+
restore: 'Call restore_from_backups to undo all changes'
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### Approve Changes
|
|
227
|
+
|
|
228
|
+
```typescript
|
|
229
|
+
// User calls: approve_changes
|
|
230
|
+
{}
|
|
231
|
+
|
|
232
|
+
// Response:
|
|
233
|
+
{
|
|
234
|
+
success: true,
|
|
235
|
+
message: 'Changes approved successfully',
|
|
236
|
+
filesDeleted: 4,
|
|
237
|
+
backupId: 'backup-def-456'
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Restore from Backups
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
// User calls: restore_from_backups
|
|
245
|
+
{}
|
|
246
|
+
|
|
247
|
+
// Response:
|
|
248
|
+
{
|
|
249
|
+
success: true,
|
|
250
|
+
message: 'All files restored successfully',
|
|
251
|
+
filesRestored: 4,
|
|
252
|
+
backupId: 'backup-def-456'
|
|
253
|
+
}
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
## Configuration
|
|
257
|
+
|
|
258
|
+
### Enable/Disable Backups
|
|
259
|
+
|
|
260
|
+
```bash
|
|
261
|
+
# Enable backups (default)
|
|
262
|
+
export VF_BACKUP_ENABLED=true
|
|
263
|
+
|
|
264
|
+
# Disable backups
|
|
265
|
+
export VF_BACKUP_ENABLED=false
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
When disabled:
|
|
269
|
+
- No backup files created
|
|
270
|
+
- Workflow continues normally
|
|
271
|
+
- No backup-related messages in responses
|
|
272
|
+
- Changes are immediately permanent
|
|
273
|
+
|
|
274
|
+
### Backup File Location
|
|
275
|
+
|
|
276
|
+
Backups are stored alongside original files with `.vf-bak` extension:
|
|
277
|
+
|
|
278
|
+
```
|
|
279
|
+
project/
|
|
280
|
+
├── docs/
|
|
281
|
+
│ ├── README.md ← Modified file
|
|
282
|
+
│ └── README.md.vf-bak ← Backup (if exists)
|
|
283
|
+
├── generated-images/
|
|
284
|
+
│ ├── diagram-001.png ← Generated image
|
|
285
|
+
│ ├── diagram-001.png.vf-bak ← Backup (if exists)
|
|
286
|
+
│ ├── diagram-002.png
|
|
287
|
+
│ └── diagram-002.png.vf-bak
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
## Best Practices
|
|
291
|
+
|
|
292
|
+
### For Users
|
|
293
|
+
|
|
294
|
+
1. **Review Before Approving**: Always review generated images before calling `approve_changes`
|
|
295
|
+
2. **Use Reminders**: Pay attention to 24-hour backup reminders
|
|
296
|
+
3. **Clean Up**: Approve or restore backups promptly to avoid accumulation
|
|
297
|
+
4. **Keep Enabled**: Leave backups enabled (default) for safety
|
|
298
|
+
|
|
299
|
+
### For Developers
|
|
300
|
+
|
|
301
|
+
1. **Check State**: Always check for pending backups in StateManager
|
|
302
|
+
2. **Atomic Operations**: Ensure backup creation is atomic (all-or-nothing)
|
|
303
|
+
3. **Error Handling**: Handle backup failures gracefully, don't block workflow
|
|
304
|
+
4. **Log Operations**: Log backup creation, approval, and restoration for debugging
|
|
305
|
+
|
|
306
|
+
## Error Scenarios
|
|
307
|
+
|
|
308
|
+
### Backup Creation Fails
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
{
|
|
312
|
+
success: true, // Workflow continues
|
|
313
|
+
backup: {
|
|
314
|
+
backupCreated: false,
|
|
315
|
+
error: 'Failed to create backup: Permission denied'
|
|
316
|
+
},
|
|
317
|
+
// ... rest of response
|
|
318
|
+
}
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
**Workflow continues normally** - backup failure doesn't block image generation.
|
|
322
|
+
|
|
323
|
+
### Restore Fails (Partial)
|
|
324
|
+
|
|
325
|
+
```typescript
|
|
326
|
+
{
|
|
327
|
+
success: false,
|
|
328
|
+
filesRestored: 2,
|
|
329
|
+
errors: [
|
|
330
|
+
{
|
|
331
|
+
file: 'docs/GUIDE.md',
|
|
332
|
+
error: 'Backup file not found'
|
|
333
|
+
}
|
|
334
|
+
]
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
**Partial restore** - some files restored, errors reported for failures.
|
|
339
|
+
|
|
340
|
+
## Integration Points
|
|
341
|
+
|
|
342
|
+
### WorkflowTools Integration
|
|
343
|
+
|
|
344
|
+
The backup system is integrated into `WorkflowTools` at these points:
|
|
345
|
+
|
|
346
|
+
1. **handleStartSession()**: Checks for pending backups, shows reminders
|
|
347
|
+
2. **handleGenerateSession()**: Creates backups before modifying markdown
|
|
348
|
+
3. Response messages include backup information and next actions
|
|
349
|
+
|
|
350
|
+
### StateManager Integration
|
|
351
|
+
|
|
352
|
+
The backup system uses `StateManager` for persistence:
|
|
353
|
+
|
|
354
|
+
- **Current Backup**: `stateManager.getCurrentBackup()`
|
|
355
|
+
- **Set Backup**: `stateManager.setCurrentBackup(backupSet)`
|
|
356
|
+
- **Clear Backup**: `stateManager.clearCurrentBackup(action)`
|
|
357
|
+
- **Check Pending**: `stateManager.hasPendingBackups()`
|
|
358
|
+
- **History**: `stateManager.getBackupHistory()`
|
|
359
|
+
|
|
360
|
+
### BackupManager API
|
|
361
|
+
|
|
362
|
+
Core backup operations:
|
|
363
|
+
|
|
364
|
+
- **Create**: `backupManager.createBackup(markdownFiles, imageFiles)`
|
|
365
|
+
- **Restore**: `backupManager.restoreFromBackup(backupSet)`
|
|
366
|
+
- **Approve**: `backupManager.approveChanges(backupSet)`
|
|
367
|
+
- **Check Reminder**: `backupManager.shouldRemind(backupSet)`
|
|
368
|
+
- **Summary**: `backupManager.getBackupSummary(backupSet)`
|
|
369
|
+
- **Verify**: `backupManager.verifyBackup(backupFile)`
|
|
370
|
+
|
|
371
|
+
## Testing
|
|
372
|
+
|
|
373
|
+
### Unit Tests
|
|
374
|
+
|
|
375
|
+
Located in `test/backup/backup-manager.test.ts`:
|
|
376
|
+
- Backup creation (24 tests)
|
|
377
|
+
- Restore operations
|
|
378
|
+
- Approval workflow
|
|
379
|
+
- Reminder system
|
|
380
|
+
- Integrity verification
|
|
381
|
+
|
|
382
|
+
### Integration Tests
|
|
383
|
+
|
|
384
|
+
Located in `test/workflow/workflow-backup-integration.test.ts`:
|
|
385
|
+
- Session start with reminders (14 tests)
|
|
386
|
+
- Backup creation during generation
|
|
387
|
+
- State management
|
|
388
|
+
- Full workflow lifecycle
|
|
389
|
+
- Error handling
|
|
390
|
+
|
|
391
|
+
### Running Tests
|
|
392
|
+
|
|
393
|
+
```bash
|
|
394
|
+
# All backup tests
|
|
395
|
+
npm test -- test/backup/
|
|
396
|
+
|
|
397
|
+
# Integration tests
|
|
398
|
+
npm test -- test/workflow/workflow-backup-integration.test.ts
|
|
399
|
+
|
|
400
|
+
# All tests
|
|
401
|
+
npm test
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
## Troubleshooting
|
|
405
|
+
|
|
406
|
+
### Issue: Backup files remain after approval
|
|
407
|
+
|
|
408
|
+
**Check:**
|
|
409
|
+
```bash
|
|
410
|
+
# Find all backup files
|
|
411
|
+
find . -name "*.vf-bak"
|
|
412
|
+
|
|
413
|
+
# Manually remove
|
|
414
|
+
find . -name "*.vf-bak" -delete
|
|
415
|
+
```
|
|
416
|
+
|
|
417
|
+
### Issue: Can't restore backup
|
|
418
|
+
|
|
419
|
+
**Check:**
|
|
420
|
+
```bash
|
|
421
|
+
# Verify backup files exist
|
|
422
|
+
ls -la docs/*.vf-bak
|
|
423
|
+
|
|
424
|
+
# Check state
|
|
425
|
+
cat ~/.visual-forge-mcp/state.json | grep -A 10 "backups"
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
### Issue: Backups not created
|
|
429
|
+
|
|
430
|
+
**Check:**
|
|
431
|
+
```bash
|
|
432
|
+
# Verify enabled
|
|
433
|
+
echo $VF_BACKUP_ENABLED # Should be "true" or empty
|
|
434
|
+
|
|
435
|
+
# Check logs
|
|
436
|
+
tail -f ~/.visual-forge-mcp/logs/visual-forge.log | grep -i backup
|
|
437
|
+
```
|
|
438
|
+
|
|
439
|
+
## Summary
|
|
440
|
+
|
|
441
|
+
The backup system provides:
|
|
442
|
+
|
|
443
|
+
✅ **Automatic Protection**: Transparent backups without user action
|
|
444
|
+
✅ **User Control**: Explicit approve/restore decisions
|
|
445
|
+
✅ **Persistence**: Survives session restarts
|
|
446
|
+
✅ **Reminders**: 24-hour notifications for pending backups
|
|
447
|
+
✅ **Integrity**: MD5 verification ensures correctness
|
|
448
|
+
✅ **Flexibility**: Enable/disable via environment variable
|
|
449
|
+
|
|
450
|
+
**Default Behavior**: Backups ON, automatic creation, manual approval required
|
|
451
|
+
|
|
452
|
+
**Configuration**: `VF_BACKUP_ENABLED=true` (default)
|
|
453
|
+
|
|
454
|
+
**MCP Tools**: `approve_changes`, `restore_from_backups`, `list_backups`
|
|
455
|
+
|
|
456
|
+
**Storage**: `.vf-bak` files alongside originals
|
|
457
|
+
|
|
458
|
+
**State**: Tracked in `~/.visual-forge-mcp/state.json`
|
|
459
|
+
|
|
460
|
+
---
|
|
461
|
+
|
|
462
|
+
**See Also:**
|
|
463
|
+
- [Backup System Documentation](BACKUP_SYSTEM.md) - Complete backup system reference
|
|
464
|
+
- [MCP Tools Reference](../README.md) - All available MCP tools
|
|
465
|
+
- [Testing Guide](../TESTING_GUIDE.md) - Testing documentation
|
|
466
|
+
|
|
467
|
+
---
|
|
468
|
+
|
|
469
|
+
**Last Updated**: 2026-01-13
|
|
470
|
+
**Version**: 1.0.0
|
|
471
|
+
**Status**: ✅ Implemented and Tested
|