|
| 1 | +# Stash System |
| 2 | + |
| 3 | +Sistema de gestão de conflitos e backups para vibe-devtools, inspirado no `git stash`. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +O Stash System permite que você gerencie arquivos durante instalação/atualização de packages com controle total sobre o que sobrescrever, manter ou arquivar. |
| 8 | + |
| 9 | +### Features |
| 10 | + |
| 11 | +- ✅ Detecção automática de conflitos via SHA-256 hash |
| 12 | +- ✅ Backup seguro com full copy (não patch) |
| 13 | +- ✅ Comandos CLI familiares (inspirados no git stash) |
| 14 | +- ✅ FILO ordering com renumeração automática |
| 15 | +- ✅ Logging completo em JSONL |
| 16 | +- ✅ Dry-run support |
| 17 | +- ✅ Integration com install e update commands |
| 18 | + |
| 19 | +## Quick Start |
| 20 | + |
| 21 | +### Install com Detecção de Conflitos |
| 22 | + |
| 23 | +```bash |
| 24 | +npx vibe-devtools install @vibe-devtools/basic |
| 25 | +``` |
| 26 | + |
| 27 | +Se houver conflitos, você verá: |
| 28 | + |
| 29 | +``` |
| 30 | +⚠️ Conflicts detected (3 files) |
| 31 | +
|
| 32 | + 1. vibes/configs/constitution.md |
| 33 | + Local: abc123... |
| 34 | + Package: def456... |
| 35 | +
|
| 36 | +How to resolve conflicts? |
| 37 | + [1] Overwrite with package version |
| 38 | + [2] Stash local and install package |
| 39 | + [3] Cancel installation |
| 40 | +``` |
| 41 | + |
| 42 | +Escolha opção 2 para criar backup automático. |
| 43 | + |
| 44 | +### Update com Stash |
| 45 | + |
| 46 | +```bash |
| 47 | +npx vibe-devtools update @vibe-devtools/basic --latest |
| 48 | +npx vibe-devtools update @vibe-devtools/basic --version 1.0.3 |
| 49 | +npx vibe-devtools update @vibe-devtools/basic --dry-run |
| 50 | +``` |
| 51 | + |
| 52 | +### Dry Run |
| 53 | + |
| 54 | +Preview mudanças sem instalar: |
| 55 | + |
| 56 | +```bash |
| 57 | +npx vibe-devtools install @vibe-devtools/basic --dry-run |
| 58 | +``` |
| 59 | + |
| 60 | +## Comandos Stash |
| 61 | + |
| 62 | +### List |
| 63 | + |
| 64 | +Lista todos os stashes: |
| 65 | + |
| 66 | +```bash |
| 67 | +npx vibe-devtools stash list |
| 68 | +``` |
| 69 | + |
| 70 | +Output: |
| 71 | +``` |
| 72 | +stash{0} - @vibe-devtools/basic |
| 73 | + install • 2025-10-23 14:30 • 3 files |
| 74 | +
|
| 75 | +stash{1} - manual |
| 76 | + manual • 2025-10-23 15:45 • 2 files |
| 77 | +
|
| 78 | +Total: 2 stashes |
| 79 | +``` |
| 80 | + |
| 81 | +### Show |
| 82 | + |
| 83 | +Mostra detalhes de um stash: |
| 84 | + |
| 85 | +```bash |
| 86 | +npx vibe-devtools stash show 0 |
| 87 | +``` |
| 88 | + |
| 89 | +### Apply |
| 90 | + |
| 91 | +Aplica stash (mantém no histórico): |
| 92 | + |
| 93 | +```bash |
| 94 | +npx vibe-devtools stash apply 0 |
| 95 | +``` |
| 96 | + |
| 97 | +### Pop |
| 98 | + |
| 99 | +Aplica stash e remove do histórico: |
| 100 | + |
| 101 | +```bash |
| 102 | +npx vibe-devtools stash pop 0 |
| 103 | +``` |
| 104 | + |
| 105 | +### Remove |
| 106 | + |
| 107 | +Remove um stash: |
| 108 | + |
| 109 | +```bash |
| 110 | +npx vibe-devtools stash remove 0 |
| 111 | +``` |
| 112 | + |
| 113 | +### Diff |
| 114 | + |
| 115 | +Mostra diferenças entre stash e arquivos atuais: |
| 116 | + |
| 117 | +```bash |
| 118 | +npx vibe-devtools stash diff 0 |
| 119 | +npx vibe-devtools stash diff 0 --editor # abre no IDE |
| 120 | +``` |
| 121 | + |
| 122 | +### Save |
| 123 | + |
| 124 | +Cria stash manual: |
| 125 | + |
| 126 | +```bash |
| 127 | +npx vibe-devtools stash save file1.ts file2.ts |
| 128 | +npx vibe-devtools stash save # prompt interativo |
| 129 | +``` |
| 130 | + |
| 131 | +### Clear |
| 132 | + |
| 133 | +Remove todos os stashes: |
| 134 | + |
| 135 | +```bash |
| 136 | +npx vibe-devtools stash clear |
| 137 | +npx vibe-devtools stash clear --force # sem confirmação |
| 138 | +``` |
| 139 | + |
| 140 | +## Architecture |
| 141 | + |
| 142 | +### Components |
| 143 | + |
| 144 | +- **HashCalculator**: SHA-256 hash calculation |
| 145 | +- **StashLogger**: JSONL logging system |
| 146 | +- **StashManager**: Core lifecycle management |
| 147 | +- **ConflictDetector**: Hash-based conflict detection |
| 148 | +- **ConflictResolver**: CLI prompts & diff display |
| 149 | + |
| 150 | +### Storage |
| 151 | + |
| 152 | +``` |
| 153 | +~/.vibes/stash/ |
| 154 | +├── index.json # Lista de stashes |
| 155 | +├── stash-0/ |
| 156 | +│ ├── metadata.json # Metadata do stash |
| 157 | +│ └── files/ # Full copy dos arquivos |
| 158 | +└── stash-1/ |
| 159 | + ├── metadata.json |
| 160 | + └── files/ |
| 161 | +``` |
| 162 | + |
| 163 | +### Logging |
| 164 | + |
| 165 | +``` |
| 166 | +~/.vibes/logs/stash.log |
| 167 | +``` |
| 168 | + |
| 169 | +Format: JSONL (1 JSON per line) |
| 170 | + |
| 171 | +## Technical Details |
| 172 | + |
| 173 | +### Hash Algorithm |
| 174 | + |
| 175 | +SHA-256 via Node.js crypto (nativo) |
| 176 | + |
| 177 | +### Storage Strategy |
| 178 | + |
| 179 | +Full copy (não patch) para: |
| 180 | +- Simplicidade e confiabilidade |
| 181 | +- Suporte a qualquer tipo de arquivo |
| 182 | +- Sempre funciona (não corrompe) |
| 183 | + |
| 184 | +### Ordering |
| 185 | + |
| 186 | +FILO (First In Last Out) com renumeração: |
| 187 | +- `stash{0}` é sempre o mais recente |
| 188 | +- Após `pop` ou `remove`, IDs são renumerados |
| 189 | +- Igual ao `git stash` |
| 190 | + |
| 191 | +## Error Handling |
| 192 | + |
| 193 | +### Permission Denied |
| 194 | + |
| 195 | +Se erro de permissão em `~/.vibes/stash/`: |
| 196 | + |
| 197 | +```bash |
| 198 | +sudo chown -R $USER ~/.vibes |
| 199 | +``` |
| 200 | + |
| 201 | +### Stash Corrupted |
| 202 | + |
| 203 | +Sistema valida integridade via hash antes de aplicar. Se corrompido: |
| 204 | + |
| 205 | +```bash |
| 206 | +npx vibe-devtools stash remove <stash-id> |
| 207 | +``` |
| 208 | + |
| 209 | +### Disk Full |
| 210 | + |
| 211 | +Libere espaço ou: |
| 212 | + |
| 213 | +```bash |
| 214 | +npx vibe-devtools stash clear |
| 215 | +``` |
| 216 | + |
| 217 | +## Performance |
| 218 | + |
| 219 | +- Hash calculation: < 100ms (arquivos < 1MB) |
| 220 | +- Stash creation: < 1s (< 100 arquivos) |
| 221 | +- Stash apply: < 1s (< 100 arquivos) |
| 222 | + |
| 223 | +## Dependencies |
| 224 | + |
| 225 | +- `inquirer@^9.2.0` - CLI prompts |
| 226 | +- `diff@^5.1.0` - Diff display |
| 227 | + |
| 228 | +## Compatibility |
| 229 | + |
| 230 | +- Node.js >= 18.0.0 |
| 231 | +- Works on: macOS, Linux, Windows |
| 232 | + |
0 commit comments