titor 0.2.0

A high-performance checkpointing library for time-travel through directory states
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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
# Titor CLI - Time Travel for Your Files

A comprehensive command-line interface demonstrating all features of the Titor checkpointing library. This CLI provides Git-like version control for any directory with powerful time-travel capabilities.

## Features Overview

- **Checkpoint Management**: Create, list, and restore directory snapshots
- **Timeline Navigation**: Visualize and navigate through checkpoint history
- **Branching**: Fork from any checkpoint to create alternative timelines
- **Diffing**: Compare changes between checkpoints
- **Verification**: Ensure data integrity with cryptographic verification
- **Storage Optimization**: Garbage collection and compression
- **Progress Tracking**: Visual feedback for long operations

## Installation

Build the CLI from the project root:

```bash
# Build in release mode for optimal performance
cargo build --example titor_cli --release

# Copy to your PATH (optional)
cp target/release/examples/titor_cli ~/.local/bin/titor

# Or run directly
cargo run --example titor_cli -- --help
```

## Quick Start

```bash
# Initialize Titor in current directory
titor init

# Create your first checkpoint
titor checkpoint -m "Initial project state"

# Make some changes to your files...
echo "new content" > file.txt

# Create another checkpoint
titor checkpoint -m "Added new file"

# View your timeline
titor timeline

# Compare checkpoints
titor diff <checkpoint1> <checkpoint2>

# Restore to previous state
titor restore <checkpoint-id>
```

## Command Reference

### Global Options

- `-p, --path <PATH>`: Target directory (defaults to current)
- `-s, --storage <PATH>`: Storage directory (defaults to .titor)
- `-v, --verbose`: Enable debug output
- `--help`: Show help information
- `--version`: Show version information

### `init` - Initialize Repository

Initialize Titor tracking in a directory.

```bash
titor init [OPTIONS]

Options:
  --compression <MODE>     Compression strategy [none, fast, adaptive] (default: adaptive)
  -i, --ignore <PATTERN>   File patterns to ignore (gitignore syntax)
  --force                  Force initialization even if already initialized
```

**Examples:**

```bash
# Basic initialization
titor init

# Custom compression and ignore patterns
titor init --compression fast -i "*.log" -i "node_modules/"

# Initialize with custom storage location
titor -s /backup/project-titor init
```

### `checkpoint` (alias: `cp`) - Create Checkpoint

Capture the current state of your directory.

```bash
titor checkpoint [OPTIONS]

Options:
  -m, --message <MESSAGE>  Description for the checkpoint
  --progress               Show progress bar
```

**Examples:**

```bash
# Quick checkpoint
titor cp

# With description
titor checkpoint -m "Before major refactoring"

# With progress tracking
titor checkpoint --progress -m "Release v1.0.0"
```

### `restore` (alias: `rs`) - Restore Checkpoint

Restore directory to a previous checkpoint state.

```bash
titor restore <CHECKPOINT> [OPTIONS]

Options:
  --progress  Show progress bar
```

**Examples:**

```bash
# Restore by checkpoint ID (first 8 chars sufficient)
titor restore abc12345

# Restore with progress
titor restore abc12345 --progress
```

### `list` (alias: `ls`) - List Checkpoints

Display all checkpoints with metadata.

```bash
titor list [OPTIONS]

Options:
  -d, --detailed       Show detailed information
  -l, --limit <NUM>    Limit number of results
```

**Examples:**

```bash
# Basic list
titor ls

# Detailed view with file counts
titor list --detailed

# Show only last 10 checkpoints
titor list --limit 10
```

### `timeline` (alias: `tl`) - Show Timeline Tree

Visualize checkpoint history as a tree structure.

```bash
titor timeline [OPTIONS]

Options:
  --ascii  Use ASCII characters for tree drawing
```

**Examples:**

```bash
# Beautiful Unicode tree
titor timeline

# ASCII tree for compatibility
titor timeline --ascii
```

### `fork` - Create Branch

Fork from an existing checkpoint to create a new timeline branch.

```bash
titor fork <CHECKPOINT> [OPTIONS]

Options:
  -m, --message <MESSAGE>  Description for the fork
```

**Examples:**

```bash
# Fork from checkpoint
titor fork abc12345 -m "Experimental feature branch"

# Fork from current checkpoint
titor fork HEAD -m "Alternative approach"
```

### `diff` - Compare Checkpoints

Show differences between two checkpoints.

```bash
titor diff <FROM> <TO> [OPTIONS]

Options:
  -l, --lines              Show line-level differences (like git diff)
  --context <NUM>          Number of context lines (default: 3)
  --stat                   Show only statistics
  --ignore-whitespace      Ignore whitespace changes
```

**Examples:**

```bash
# Basic file-level comparison
titor diff abc12345 def67890

# Line-level diff with git-like output
titor diff abc12345 def67890 --lines

# Custom context lines
titor diff abc12345 def67890 --lines --context 5

# Statistics only
titor diff abc12345 def67890 --stat

# Ignore whitespace changes
titor diff abc12345 def67890 --lines --ignore-whitespace
```

**Output Format:**

With `--lines`, the output shows unified diff format:
```diff
--- a/file.txt
+++ b/file.txt
@@ -1,5 +1,6 @@
 context line
-removed line
+added line
 another context line
```

### `verify` - Verify Integrity

Perform cryptographic verification of checkpoint data.

```bash
titor verify [CHECKPOINT] [OPTIONS]

Options:
  --all  Verify all checkpoints
```

**Examples:**

```bash
# Verify current checkpoint
titor verify

# Verify specific checkpoint
titor verify abc12345

# Verify entire timeline
titor verify --all
```

### `gc` - Garbage Collection

Remove unreferenced objects to free storage space.

```bash
titor gc [OPTIONS]

Options:
  --dry-run  Show what would be deleted without removing
```

**Examples:**

```bash
# Preview cleanup
titor gc --dry-run

# Perform cleanup
titor gc
```

### `status` - Show Status

Display current repository status and statistics.

```bash
titor status
```

### `info` - Checkpoint Information

Show detailed information about a specific checkpoint.

```bash
titor info <CHECKPOINT>
```

**Examples:**

```bash
# Get checkpoint details
titor info abc12345
```

## Advanced Usage

### Working with Large Directories

For directories with many files, use progress tracking:

```bash
# Show progress for checkpoint creation
titor checkpoint --progress -m "Large directory snapshot"

# Show progress for restoration
titor restore abc12345 --progress
```

### Branching Workflows

Create experimental branches without affecting main timeline:

```bash
# Create a fork for experimentation
titor fork abc12345 -m "Try new approach"

# Make changes and checkpoint
echo "experimental" > test.txt
titor cp -m "Experimental change"

# If happy, continue on this branch
# If not, restore to original branch
titor restore abc12345
```

### Automation with Scripts

The CLI is designed for scripting:

```bash
#!/bin/bash
# Auto-checkpoint script

# Create checkpoint with timestamp
titor checkpoint -m "Auto-checkpoint $(date +%Y-%m-%d_%H:%M:%S)"

# Verify integrity
if titor verify; then
    echo "Checkpoint verified successfully"
else
    echo "Checkpoint verification failed!"
    exit 1
fi

# Clean up old objects
titor gc
```

### Integration with CI/CD

```yaml
# Example GitHub Actions workflow
name: Checkpoint on Release

on:
  release:
    types: [created]

jobs:
  checkpoint:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      
      - name: Install Titor
        run: cargo install --example titor_cli
      
      - name: Create release checkpoint
        run: |
          titor init
          titor checkpoint -m "Release ${{ github.event.release.tag_name }}"
      
      - name: Verify checkpoint
        run: titor verify
```

## Performance Tips

1. **Compression Strategy**:
   - Use `adaptive` for mixed content (default)
   - Use `fast` for speed priority
   - Use `none` for already-compressed files

2. **Ignore Patterns**:
   - Exclude build artifacts: `-i "target/" -i "dist/"`
   - Exclude dependencies: `-i "node_modules/" -i "vendor/"`
   - Exclude logs: `-i "*.log" -i "*.tmp"`

3. **Storage Location**:
   - Use SSD for storage directory when possible
   - Consider separate disk for large repositories
   - Network storage works but may be slower

## Troubleshooting

### Common Issues

**"Not a Titor repository"**
- Run `titor init` first
- Check you're in the correct directory
- Verify storage directory exists

**"Checkpoint not found"**
- Use `titor list` to see available checkpoints
- Check checkpoint ID spelling
- First 8 characters are usually sufficient

**"Permission denied"**
- Ensure write access to storage directory
- Check file permissions in target directory
- Run with appropriate user privileges

### Debug Mode

Enable verbose output for troubleshooting:

```bash
titor -v <command>
```

### Storage Inspection

Check storage health:

```bash
# Show storage statistics
titor status

# Verify all checkpoints
titor verify --all

# Check for orphaned objects
titor gc --dry-run
```

## Architecture Overview

The CLI demonstrates all major Titor features:

1. **Content-Addressable Storage**: Files stored by content hash
2. **Merkle Trees**: Cryptographic verification of file integrity
3. **Incremental Snapshots**: Only changed files stored
4. **Compression**: LZ4 compression for efficiency
5. **Deduplication**: Identical files stored once
6. **Atomic Operations**: All-or-nothing checkpoint/restore
7. **Line-Level Diffs**: Git-like unified diff output for text files

## Contributing

This CLI serves as a reference implementation. To extend:

1. Add new commands in the `Commands` enum
2. Implement command handler functions
3. Update help documentation
4. Add tests for new functionality

## License

Same as the Titor library - MIT