cargo-mate 1.8.0

Rust development companion that enhances cargo with intelligent workflows, state management, performance optimization, and comprehensive project monitoring.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
## Anchor Commands

The anchor system provides powerful project state management, allowing you to save and restore complete project snapshots. This includes Git state, file contents, dependencies, and even auto-update capabilities for continuous state tracking.

### Key Features
- **Complete State Capture**: Saves Git commit, Cargo.lock, source files, and environment
- **SHA256 Verification**: Ensures file integrity with cryptographic hashing
- **Auto-Update Mode**: Continuous monitoring and automatic updates of saved anchors
- **Background Operation**: Non-blocking auto-update mode for seamless workflow
- **Easy Restoration**: One-command restoration to any saved state

### `cm anchor save <name> [--message <msg>]`
**Description**: Save current project state as an anchor point

**Usage**:
```bash
cm anchor save before-refactor
cm anchor save v1.0 --message "Pre-release state"
```

**What it saves**:
- Git commit hash
- Cargo.lock snapshot
- Source files (SHA256 verified)
- Environment variables
- Project metadata

---

### `cm anchor restore <name>`
**Description**: Restore project to a saved anchor point

**Usage**:
```bash
cm anchor restore before-refactor
```

**What it restores**:
- Git checkout to saved commit
- Cargo.lock file
- Modified/deleted files
- Working directory state

---

### `cm anchor list`
**Description**: List all saved anchors

**Usage**:
```bash
cm anchor list
```

**Output**:
```
⚓ Saved anchors:
⚓ before-refactor - 2024-01-20 14:30:00 (15 files)
   Major refactoring checkpoint
⚓ v1.0 - 2024-01-19 10:00:00 (23 files)
   Pre-release state
```

---

### `cm anchor show <name>`
**Description**: Show detailed information about an anchor

**Usage**:
```bash
cm anchor show before-refactor
```

---

### `cm anchor diff <name>`
**Description**: Show differences between current state and anchor

**Usage**:
```bash
cm anchor diff before-refactor
```

**Output**:
```
=== Diff from anchor 'before-refactor' ===

✨ Added files:
   + src/new_module.rs

📝 Modified files:
   ~ src/main.rs
   ~ Cargo.toml

🗑️  Deleted files:
   - src/old_module.rs
```

---

### `cm anchor auto [OPTIONS] <name>`
**Description**: Start auto-update mode for anchor (runs in background by default)

**Usage**:
```bash
# Default background mode (recommended)
cm anchor auto my-project
cargo anchor auto my-project

# Foreground mode (blocking)
cm anchor auto my-project --foreground
cargo anchor auto my-project --foreground
```

**Options**:
- `--foreground`: Run in blocking foreground mode instead of background

**Background Mode Features**:
- ✅ Non-blocking: Doesn't interfere with your terminal workflow
- 🔄 Real-time: Updates files immediately when changed
- ⚡ Efficient: Only updates specifically modified files
- 📊 Smart: Monitors only relevant directories automatically
- 🛑 Controllable: Easy start/stop management

**Background Mode Output**:
```
🚀 Starting auto-update for anchor: my-project
📁 Setting up file monitoring...
✅ Auto-update STARTED successfully!
🔄 Files will be updated automatically when changed
🛑 Use 'cargo anchor stop my-project' to stop monitoring

💡 Background daemon running for anchor 'my-project'
```

**Foreground Mode Output**:
```
📁 Monitoring 19 files for changes...
💡 Press Ctrl+C to stop auto-update

👀 Watching 2 directories
✅ Auto-update started! Files will be updated automatically.

🔄 Updated src/main.rs in anchor 'my-project'
```

**File Change Notifications**:
When files are modified in background mode, you'll see:
```
🔄 [14:32:15] Updated src/main.rs in anchor 'my-project'
🔄 [14:33:22] Updated Cargo.toml in anchor 'my-project'
```

**Examples**:
```bash
# Start monitoring your project (background by default)
cargo anchor auto my-rust-project

# Start in foreground if you want to see real-time updates
cargo anchor auto my-rust-project --foreground

# The auto-update runs continuously until stopped
# Edit files, and they'll be automatically saved to the anchor!
```

---

### `cm anchor stop <name>`
**Description**: Stop auto-update mode for anchor

**Usage**:
```bash
cm anchor stop my-project
cargo anchor stop my-project
```

**Output**:
```
🛑 Stopping auto-update for anchor: my-project
⚠️  Note: In this implementation, stopping requires restarting the shell
💡 Future versions will have proper daemon management
```

**Examples**:
```bash
# Stop auto-update for your project
cargo anchor stop my-rust-project
```

---

## Storage and File Management

### Anchor Storage Location
- **Global Storage**: `~/.shipwreck/anchors/`
- **Per-Anchor Directory**: Each anchor gets its own directory
- **File Organization**: Organized by anchor name with timestamp metadata

### What Gets Saved

**Git State**:
- Current commit hash
- Branch information
- Working directory status

**Dependencies**:
- Complete `Cargo.lock` snapshot
- Dependency versions and checksums

**Source Files**:
- All source files with SHA256 verification
- File modification timestamps
- Directory structure

**Environment**:
- Environment variables relevant to build
- Build configuration state

**Metadata**:
- Anchor creation timestamp
- User-provided message
- Project metadata

## Best Practices

### Creating Meaningful Anchors

```bash
# Before major refactoring
cm anchor save before-refactor --message "Pre-refactoring state"

# Before dependency updates
cm anchor save pre-deps-update --message "Before updating dependencies"

# Release checkpoints
cm anchor save v1.0.0 --message "Release v1.0.0 checkpoint"
```

### Using Auto-Update Mode

**When to Use**:
- Long-running development sessions
- Continuous integration workflows
- Experimental feature branches
- Documentation updates

**Workflow**:
```bash
# Start auto-update at beginning of session
cm anchor auto my-feature-branch

# Work normally - changes are automatically saved
# ... edit files ...

# Stop when done
cm anchor stop my-feature-branch
```

### Restoration Workflow

```bash
# Check available anchors
cm anchor list

# See what changed
cm anchor diff before-refactor

# Restore if needed
cm anchor restore before-refactor
```

## Troubleshooting

### Anchor Not Found

```bash
# List all anchors
cm anchor list

# Check storage directory
ls -la ~/.shipwreck/anchors/

# Verify anchor name spelling
cm anchor show <name>
```

### Auto-Update Not Working

```bash
# Check if auto-update is running
ps aux | grep "anchor auto"

# Restart auto-update
cm anchor stop <name>
cm anchor auto <name> --foreground  # Test in foreground first
```

### Restoration Issues

**Git Conflicts**:
```bash
# Check git status before restore
git status

# Stash changes if needed
git stash
cm anchor restore <name>
```

**File Permission Issues**:
```bash
# Check file permissions
ls -la ~/.shipwreck/anchors/

# Fix permissions if needed
chmod -R 755 ~/.shipwreck/anchors/
```

### Storage Space

```bash
# Check anchor storage size
du -sh ~/.shipwreck/anchors/

# Remove old anchors
rm -rf ~/.shipwreck/anchors/old-anchor-name
```

## Technical Details

### File Monitoring

**Auto-Update Monitoring**:
- Monitors only relevant directories (src/, Cargo.toml, etc.)
- Efficient file watching with minimal overhead
- Real-time updates when files change
- Background daemon for non-blocking operation

### SHA256 Verification

**File Integrity**:
- All saved files are verified with SHA256 hashes
- Ensures file integrity during save and restore
- Detects file corruption or tampering
- Automatic verification on restore

### Git Integration

**State Capture**:
- Captures current Git commit hash
- Stores branch information
- Preserves working directory state
- Handles uncommitted changes

### Performance

**Save Operation**:
- Fast file copying with progress indication
- Parallel file processing where possible
- Efficient storage with compression

**Restore Operation**:
- Fast restoration from saved state
- Atomic operations where possible
- Rollback capability on failure

## Integration with Other Features

### With Journeys

```bash
# Record a journey that includes anchor operations
cm journey record feature-workflow
cm anchor save checkpoint-1
# ... work ...
cm anchor save checkpoint-2
```

### With Version Management

```bash
# Save anchor before version bump
cm anchor save pre-version-bump
cm version increment minor
cm anchor save post-version-bump
```

### With Optimize

```bash
# Save state before optimization
cm anchor save pre-optimize
cm optimize aggressive
# Test build
cm anchor restore pre-optimize  # If issues occur
```

## Advanced Usage

### Anchor Comparison

```bash
# Compare two anchors
cm anchor diff anchor-1
cm anchor diff anchor-2

# See detailed differences
cm anchor show anchor-1
cm anchor show anchor-2
```

### Batch Operations

```bash
# Save multiple checkpoints
for checkpoint in dev test prod; do
    cm anchor save $checkpoint --message "Checkpoint: $checkpoint"
done
```

### CI/CD Integration

```bash
# In CI pipeline
cm anchor save ci-checkpoint-$(date +%Y%m%d)
# Run tests
# Restore if tests fail
cm anchor restore ci-checkpoint-$(date +%Y%m%d)
```

## Limitations

### Known Limitations
- **Large Projects**: Very large projects may take longer to save/restore
- **Binary Files**: Large binary files increase storage requirements
- **Network Dependencies**: Network-dependent builds may not fully restore
- **External Services**: Cannot restore state of external services or databases

### Platform Considerations
- **File Permissions**: May need adjustment on different platforms
- **Path Separators**: Handled automatically across platforms
- **Symlinks**: Symlinks are preserved but may need manual handling

## Future Enhancements

Planned features:
- **Incremental Anchors**: Only save changed files
- **Compression**: Automatic compression of anchor storage
- **Remote Storage**: Backup anchors to remote storage
- **Anchor Sharing**: Share anchors between team members
- **Selective Restoration**: Restore only specific files or directories

---