pocket-cli 0.6.1

A CLI tool for saving, organizing, and retrieving code snippets with integrated version control
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
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# Pocket Version Control System (VCS) Specification

## Overview

This document specifies the integration of a custom version control system into the Pocket CLI tool. This is not a Git wrapper but a standalone, purpose-built VCS designed to complement Pocket's existing functionality while introducing novel approaches to version control.

The Pocket VCS aims to provide a simpler, more intuitive version control experience with modern features that address common pain points in existing systems. While maintaining conceptual familiarity for users of Git, it introduces innovations that improve workflow and reduce cognitive load.

## Core Concepts

### Laundry Rooms ("Rooms")

A Pocket rooms is a directory containing files under version control. Unlike Git, Pocket rooms are designed to be more self-contained and user-friendly:

- `.pocket/` directory contains all version control data (similar to `.git/`)
- Repository metadata is stored in a structured, human-readable format
- No detached HEAD states or complex concepts that confuse beginners

### Piles

A "pile" is the staging area concept (similar to Git's index/staging area). Files are "piled up" before being committed:

- Each pile is a collection of changes that will form a commit
- Piles can be modified, split, combined, or abandoned before committing
- Piles have a more visual representation to users than Git's staging area

### Shoves

A "shove" is a commit - a snapshot of changes that have been "piled up" and then permanently stored in the repository:

- Each shove has a unique ID, timestamp, author, and message
- Shoves form a directed acyclic graph (DAG) like Git commits
- Shoves can be tagged, annotated, and organized into collections

### Timelines

Instead of branches, Pocket uses "timelines" - parallel development paths that can diverge and merge:

- Timelines are more visually intuitive than branches
- Default timeline is "main" (rather than "master")
- Timelines are designed to be created and merged with less friction

### Snapshots

A snapshot is a complete picture of the repository at a specific point in time (a shove). Users can "back" to any snapshot to restore the repository to that state.

### UX

pocket's VCS will still be within the terminal, but it would be nice to have pretty icons especially when things are branching out, or viewing timelines, or diffs. it would make the UX more appealing

## Command Specification

### Repository Management

#### `pocket new repo`

Create a new Pocket repository in the current directory.

**Usage:**
```bash
pocket new repo [--template <template-name>]
```

**Options:**
- `--template <template-name>`: Initialize with a predefined template (no defined templates yet)
- `--no-default`: Don't create default files like README.md or .pocketignore (usually we want the default files to show up but it depends)

**Behavior:**
- Creates a `.pocket/` directory with necessary subdirectories
- Initializes an empty repository with no shoves
- Creates a default "main" timeline
- Sets up user configuration based on global settings

**Structure Created:**
```
.pocket/
  ├── config.toml       # Repository configuration
  ├── timelines/        # Timeline definitions
  │   └── main.toml     # Default timeline
  ├── objects/          # Stored file objects (content-addressable)
  ├── shoves/           # Commit history
  ├── piles/            # Staging area state
  └── snapshots/        # Named snapshots for easy referencing
```

#### `pocket status`

Display the current state of the repository.

**Usage:**
```bash
pocket status [--verbose]
```

**Output:**
- Current timeline
- Files in the current pile (staged changes)
- Unstaged changes
- Recent shoves
- Conflicts (if any)

### Change Management

#### `pocket pile`

Add files to the current pile (staging area).

**Usage:**
```bash
pocket pile [file1] [file2] ... # Specific files
pocket pile --all               # All changes
pocket pile --pattern "*.rs"    # Files matching pattern
```

**Options:**
- `--all`: Add all changes (similar to `git add .`)
- `--interactive`: Interactive mode to select chunks
- `--pattern <pattern>`: Add files matching the glob pattern

**Behavior:**
- Tracks both new files and changes to existing files
- Creates file snapshots in the `.pocket/piles/` directory
- Updates the pile index
- Shows a summary of what was added to the pile

#### `pocket unpile`

Remove files from the current pile (unstage changes).

**Usage:**
```bash
pocket unpile [file1] [file2] ... # Specific files
pocket unpile --all               # All staged changes
```

**Options:**
- `--all`: Remove all files from the pile

#### `pocket pile-diff`

Show the difference between what's in the pile and the last shove.

**Usage:**
```bash
pocket pile-diff [file]
```

#### `pocket shove`

Create a permanent snapshot (commit) from the current pile.

**Usage:**
```bash
pocket shove -m "Commit message"  # With inline message
pocket shove -e                   # Open editor for message
```

**Options:**
- `-m, --message <msg>`: Specify commit message inline
- `-e, --editor`: Open the default editor for the message
- `--tag <tag-name>`: Immediately tag this shove
- `--no-verify`: Skip any pre-shove hooks

**Behavior:**
- Creates a new shove object in `.pocket/shoves/`
- Generates a unique ID for the shove
- Updates the current timeline to point to the new shove
- Clears the pile after successful shove
- Records author, timestamp, and message

#### `pocket back`

Return the repository to a previous state (snapshot/shove).

**Usage:**
```bash
pocket back <shove-id>            # Back to specific shove
pocket back --shoves 3            # Back 3 shoves
pocket back --tag <tag-name>      # Back to a tagged shove
```

**Options:**
- `--soft`: Keep changes in the working directory
- `--hard`: Discard all changes in the working directory
- `--pile`: Keep changes but add them to the pile

**Behavior:**
- Updates working directory to reflect the state at the specified shove
- Moves the timeline pointer to the specified shove
- Can create a new timeline automatically if backing to a non-head shove

### Timeline Management

#### `pocket timeline`

List, create, or switch timelines (branches).

**Usage:**
```bash
pocket timeline                   # List all timelines
pocket timeline new <name>        # Create new timeline
pocket timeline switch <name>     # Switch to timeline
```

**Options:**
- `--based-on <shove-id>`: Create timeline from specific shove
- `--track`: Set up tracking relationship for remote timelines

#### `pocket merge`

Merge another timeline into the current one.

**Usage:**
```bash
pocket merge <timeline>
```

**Options:**
- `--strategy <strategy>`: Specify merge strategy
- `--no-shove`: Don't automatically create a merge shove

### History and Inspection

#### `pocket log`

Show the shove history.

**Usage:**
```bash
pocket log [--graph] [--limit <n>]
```

**Options:**
- `--graph`: Show ASCII graph visualization
- `--limit <n>`: Limit to n entries
- `--timeline <name>`: Show history for specific timeline
- `--format <format>`: Custom format for output

#### `pocket show`

Show details about a specific shove.

**Usage:**
```bash
pocket show <shove-id>
```

**Output:**
- Shove ID
- Author and timestamp
- Full message
- List of changed files
- Diff of changes

### Collaboration

#### `pocket remote`

Manage remote repositories.

**Usage:**
```bash
pocket remote add <name> <url>    # Add remote
pocket remote remove <name>       # Remove remote
pocket remote list                # List remotes
```

#### `pocket fish`

Get updates from a remote repository.

**Usage:**
```bash
pocket fish [remote]
```

#### `pocket yank`

Fetch and merge changes from a remote timeline.

**Usage:**
```bash
pocket yank [remote] [timeline]
```

#### `pocket push`

Send local timelines to a remote repository.

**Usage:**
```bash
pocket push [remote] [timeline]
```

## Innovative Features

### 1. Smart Conflict Resolution

Unlike Git's conflict markers that modify files directly, Pocket uses a smarter approach:

- **Conflict Files**: Conflicts are stored separately in `.pocket/conflicts/` without modifying working files
- **Visual Conflict Resolution**: Built-in tools to visualize and resolve conflicts
- **Resolution Suggestions**: AI-assisted conflict resolution that suggests the most likely correct merge

```bash
pocket resolve [file]  # Interactive conflict resolution
```

### 2. Undo Anything

Pocket maintains a comprehensive history of all operations, making it possible to undo virtually any action:

```bash
pocket undo                # Undo last operation
pocket redo                # Redo previously undone operation
pocket undo --list         # List undo history
pocket undo --to <id>      # Undo multiple operations
```

This works for all operations including:
- Shoves
- Merges
- Timeline switches
- Pile operations

### 3. Time Machine Mode

A more intuitive way to navigate repository history:

```bash
pocket timemachine
```

This launches an interactive mode where users can:
- See a visualization of the repository over time
- Scroll through different shoves to see the state at any point
- Extract files or content from any historical state without switching the whole repo
- Compare any two points in time visually

### 4. Smart Ignores

Instead of requiring a `.pocketignore` file, Pocket has context-aware ignore patterns (although users can include a `.pocketignore` if they'd like):

- Automatically detects project type and suggests appropriate ignores
- Learns from user behavior which files are frequently ignored
- Separates temporary ignores from permanent ones

```bash
pocket ignore add "*.log"          # Add a permanent ignore pattern
pocket ignore temp "node_modules/" # Ignore temporarily
pocket ignore suggest              # Get suggestions based on project
```

### 5. Shove Squashing and Reordering

Unlike Git's complex rebase operation, Pocket offers intuitive history manipulation:

```bash
pocket combine <from-id> <to-id>    # Combine range of shoves
pocket reorder                      # Interactive timeline reordering
```

The UI makes it clear what is happening, with visual representations of the before and after states.

### 6. Timeline Management

Improved workflow for parallel development:

- **Timeline Groups**: Organize related timelines together
- **Timeline Stacks**: Push/pop timeline states like a stack
- **Smart Merges**: Detect when a timeline can be fast-forwarded automatically

```bash
pocket timeline group create "feature-x"
pocket timeline stack save "quick-fix"
pocket timeline stack pop
```

### 7. Partial Shoves (pretty big)

Commit only parts of files without complex patch selection:

```bash
pocket pile --lines file.rs:10-25  # Add only lines 10-25
pocket pile --function file.rs:myFunction # Add only a specific function
```

Built-in understanding of programming language syntax allows for function/class level tracking.

## Technical Implementation

### Storage Format

Unlike Git's loose objects and packfiles, Pocket uses a more structured approach:

1. **Shove Storage**:
   - Shoves are stored as structured JSON/TOML files
   - File content is stored using content-addressable storage
   - Metadata is stored separately from content for better performance

2. **Delta Compression**:
   - Changes between versions are stored as deltas
   - Periodic full snapshots prevent delta chains from becoming too long
   - Binary files use specialized delta algorithms

3. **Indexing**:
   - B-tree indexes for fast lookup of files, shoves, and objects
   - Full-text search capability across shove messages and file contents
   - Timeline-specific indexes for improved performance

### Core Components (Rust Implementation)

#### Repository Module
```rust
pub struct Repository {
    path: PathBuf,
    config: Config,
    current_timeline: Timeline,
    pile: Pile,
}

impl Repository {
    pub fn new(path: &Path) -> Result<Self>;
    pub fn open(path: &Path) -> Result<Self>;
    pub fn status(&self) -> RepoStatus;
    // Additional methods...
}
```

#### Pile Module
```rust
pub struct Pile {
    base_shove: Option<ShoveId>,
    entries: HashMap<PathBuf, PileEntry>,
}

pub struct PileEntry {
    status: PileStatus,
    object_id: ObjectId,
    original_path: PathBuf,
}

impl Pile {
    pub fn add_path(&mut self, path: &Path) -> Result<()>;
    pub fn remove_path(&mut self, path: &Path) -> Result<()>;
    pub fn clear(&mut self) -> Result<()>;
    // Additional methods...
}
```

#### Shove Module
```rust
pub struct Shove {
    id: ShoveId,
    parent_ids: Vec<ShoveId>,
    author: Author,
    timestamp: DateTime<Utc>,
    message: String,
    root_tree_id: ObjectId,
}

impl Shove {
    pub fn new(
        pile: &Pile,
        parent_ids: Vec<ShoveId>,
        author: Author,
        message: &str,
    ) -> Result<Self>;
    
    pub fn get_changes(&self) -> Result<Vec<FileChange>>;
    // Additional methods...
}
```

#### Timeline Module
```rust
pub struct Timeline {
    name: String,
    head: ShoveId,
    remote: Option<RemoteTracking>,
}

impl Timeline {
    pub fn new(name: &str, head: ShoveId) -> Self;
    pub fn switch_to(&mut self, repo: &Repository) -> Result<()>;
    pub fn merge(&mut self, other: &Timeline) -> Result<MergeResult>;
    // Additional methods...
}
```

#### Object Storage Module
```rust
pub struct ObjectStore {
    base_path: PathBuf,
}

impl ObjectStore {
    pub fn store_file(&self, path: &Path) -> Result<ObjectId>;
    pub fn get_file(&self, id: &ObjectId) -> Result<Vec<u8>>;
    pub fn store_tree(&self, tree: &Tree) -> Result<ObjectId>;
    // Additional methods...
}
```

### Database Schema

Pocket uses a combination of file-system storage and embedded database:

1. **Config Database**:
   - Repository settings
   - User preferences
   - Ignore patterns

2. **Object Database**:
   - Content-addressable storage for file contents
   - Tree structures representing directories
   - Delta-compressed storage for efficient space usage

3. **Timeline Database**:
   - Timeline definitions and metadata
   - Relationships between timelines
   - Remote tracking information

4. **Shove Database**:
   - Shove metadata (author, timestamp, message)
   - Parent-child relationships
   - Tags and annotations

## Security Considerations

### Cryptographic Verification

- All shoves can be cryptographically signed
- Content integrity is verified using secure hashes
- Support for verifying external contributions

### Access Control

- Fine-grained permissions for who can modify timelines
- Protected timelines that require approval for changes
- Audit logging of all operations

### Secure Collaboration

- Built-in support for SSH and HTTPS protocols
- Credential management without storing plaintext passwords
- Integration with external authentication systems

## Migration from Git (mildly important since we have no way to host the repo other than on github or similar)

To ease adoption, Pocket provides Git migration tools:

```bash
pocket import-git [path]  # Import a Git repository
pocket export-git [path]  # Export to Git format
```

The importer preserves:
- Full commit history
- Branches and tags
- Author information
- Signed commits

## Future Extensions

### Distributed Workflow Enhancement

- Improved handling of simultaneous changes
- Better conflict prediction and prevention
- Offline-first approach with robust synchronization

### Large File Handling

- Transparent handling of large binary files
- Chunking and deduplicated storage
- Lazy loading of large repositories

### Integration with Pocket's Core Features

- Version control for snippets in pocket storage
- Applying versioned snippets to files
- Timeline-aware snippet search

## Conclusion

The Pocket VCS provides a fresh approach to version control that maintains familiarity for Git users while introducing innovations that make version control more intuitive and less error-prone. By focusing on real-world developer workflows and pain points, Pocket VCS aims to be a significant improvement over existing solutions while maintaining the power and flexibility expected from a modern version control system.