Skip to content

Commit 53a3fcd

Browse files
Data-Wiseclaude
andauthored
feat(dot): Secret Management v2.0 Phase 1 (#198)
* feat(dot): add Secret Management v2.0 Phase 1 Implements comprehensive secret lifecycle management for the DOT dispatcher: NEW COMMANDS: - `dot secret add <name>` - Store secrets with hidden input - Supports `--expires <days>` for expiration tracking - Supports `--notes <text>` for metadata - JSON metadata stored in Bitwarden notes field - `dot secret check` - Dashboard showing expiring/expired secrets - Color-coded status (✓ valid, ⚠ expiring, ❌ expired) - Configurable warning threshold (default 30 days) - `dot secret help` - Help text for all secret subcommands - `dot lock` - Lock vault and clear session cache SESSION CACHE (15-MIN IDLE TIMEOUT): - File-based cache at ~/.cache/dot/session - Tracks unlock time and last activity - Auto-locks after 15 min inactivity (configurable via DOT_SESSION_IDLE_TIMEOUT) - `dot` status shows vault state and time remaining - Helper functions: _dot_session_cache_{init,save,touch,expired,clear} ALSO INCLUDES: - v5.1.1 enhancements: ZDOTDIR support, auto-add, file creation - Updated completions for new commands - Updated DOT-DISPATCHER-REFERENCE.md documentation - Added SPEC for Secret Management v2.0 - Test Suite 13 with 22 new tests (93 total) - E2E test suite (14 tests) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * docs: update .STATUS with Secret Management v2.0 Phase 1 completion Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 443d5cf commit 53a3fcd

File tree

8 files changed

+2249
-43
lines changed

8 files changed

+2249
-43
lines changed

.STATUS

Lines changed: 111 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,63 @@
88
## Priority: 1
99
## Progress: 100
1010

11-
## Focus: v5.1.0 Bug Fixes Complete ✅
11+
## Focus: Secret Management v2.0 Phase 1 Complete ✅
12+
13+
## ✅ Just Completed (2026-01-11):
14+
- **Secret Management v2.0 Phase 1** ✅ COMPLETE
15+
- **PR:** #198 (feature/secret-management-v2-phase1 → main)
16+
- **Implementation:** ~350 lines of new functionality
17+
18+
**New Commands:**
19+
- `dot secret add <name>` - Store secrets with hidden input
20+
- `--expires <days>` for expiration tracking
21+
- `--notes <text>` for metadata
22+
- JSON metadata in Bitwarden notes field
23+
- `dot secret check` - Dashboard showing expiring/expired secrets
24+
- Color-coded: ✓ valid, ⚠ expiring, ❌ expired
25+
- Configurable warning threshold (default 30 days)
26+
- `dot secret help` - Help text for all secret subcommands
27+
- `dot lock` - Lock vault and clear session cache
28+
29+
**Session Cache (15-min idle timeout):**
30+
- File-based cache at `~/.cache/dot/session`
31+
- Tracks unlock time and last activity
32+
- Auto-locks after 15 min inactivity
33+
- Configurable via `DOT_SESSION_IDLE_TIMEOUT`
34+
- `dot` status shows vault state + time remaining
35+
- 7 helper functions: `_dot_session_cache_{init,save,touch,expired,clear}`, `_dot_session_time_remaining{,_fmt}`
36+
37+
**Tests:**
38+
- Test Suite 13: 22 new tests for Phase 1 features
39+
- Total: 93 unit tests + 14 E2E tests (all passing)
40+
41+
## ✅ Just Completed (2026-01-10):
42+
- **DOT v5.1.1 Test Suite Created** ✅ COMPLETE
43+
- **Unit Tests:** `test-dot-v5.1.1-unit.zsh` (19 tests, 100% passing)
44+
- **E2E Tests:** `test-dot-v5.1.1-e2e.zsh` (14 tests, 100% passing)
45+
- **Interactive Dogfooding:** `interactive-dot-dogfooding.zsh` (8 dishes, "Dotfile Chef" theme)
46+
- **Total DOT Tests:** 104 automated tests (71 + 19 + 14)
47+
48+
**Test Coverage:**
49+
- `_dot_add_file()` helper function
50+
- `_dot_add()` standalone command
51+
- `_dot_has_bitwarden_template()` detection
52+
- `_dot_print_summary()` with contextual tips
53+
- ZDOTDIR support in security checks
54+
- Path resolution (full paths, tilde, fuzzy)
55+
- File creation with mkdir -p
56+
- Template detection for Bitwarden secrets
57+
58+
- **DOT Secret Management v2.0 SPEC** 📋 DRAFTED
59+
- **File:** `docs/specs/SPEC-dot-secret-management-v2-2026-01-10.md`
60+
- **Scope:** Full token lifecycle (create, store, use, rotate, revoke)
61+
- **Features:**
62+
- Phase 1: `dot secret add`, expiry check, 15-min cache
63+
- Phase 2: Token wizards (github, npm, pypi), dashboard
64+
- Phase 3: Refresh/rotate, direnv integration, CI sync
65+
- **User Story:** Developer managing GH tokens, NPM tokens, PyPI for CI/CD
66+
- **Acceptance:** Full token lifecycle works end-to-end
67+
- **Security:** Time-based 15-min cache, no secrets in history
1268

1369
## ✅ Just Completed (2026-01-11):
1470
- **DOT Dispatcher Bug Fixes** ✅ COMPLETE
@@ -909,12 +965,43 @@ _g_feature_status() {
909965
- 2025-12-25: Legacy 140KB functions archived
910966
- 2025-12-25: Symlink-only external integrations
911967

912-
## wins: v5.0.0 RELEASED (2026-01-09) 🚀, DOT DISPATCHER v1.2.0 SHIPPED, 112+ tests passing, Documentation deployed, Enhancement roadmap ready
913-
## streak: 9
914-
## last_active: 2026-01-09
968+
## wins: Secret Management v2.0 Phase 1, 93 unit tests + 14 E2E tests, Session cache with 15-min timeout
969+
## streak: 11
970+
## last_active: 2026-01-11
915971

916972
## 🎯 Next Action:
917-
**Focus:** v5.0.0 Released - Monitor Homebrew & Plan v5.1.0 🎯
973+
**Focus:** Secret Management v2.0 Phase 2 🎯
974+
975+
**Phase 1 Complete:** ✅
976+
- `dot secret add`, `dot secret check`, `dot lock`
977+
- 15-min session cache with auto-lock
978+
- 22 new tests (Test Suite 13)
979+
980+
**Options:**
981+
982+
**1. Implement Secret Management v2.0 Phase 2** (~3-4 hours)
983+
```bash
984+
# Token wizards from spec:
985+
- dot token github # GitHub PAT creation wizard
986+
- dot token npm # NPM token wizard
987+
- dot token pypi # PyPI token wizard
988+
- dot secrets # Dashboard of all secrets
989+
```
990+
991+
**2. Implement Phase 3** (~2-3 hours)
992+
```bash
993+
# Advanced features:
994+
- dot token <name> --refresh # Token rotation
995+
- dot secrets sync github # Sync to GitHub repo secrets
996+
- dot env init # Generate .envrc for direnv
997+
```
998+
999+
**3. Performance Optimizations** (v5.2.0)
1000+
```bash
1001+
# From enhancement plan:
1002+
- Dashboard status line caching (30s TTL)
1003+
- Git operation batching
1004+
```
9181005

9191006
**✅ v5.0.0 Release Complete (2026-01-09):**
9201007
- **Status:** Released and deployed
@@ -1181,3 +1268,22 @@ dot help # Verify new dispatcher
11811268
- 2026-01-09: DOCS - Live at https://Data-Wise.github.io/flow-cli/
11821269
- 2026-01-09: STATUS - Updated .STATUS with v5.0.0 release completion
11831270
- 2026-01-09: COMPLETE - v5.0.0 fully released (tag, release, docs deployed)
1271+
- 2026-01-10: TEST - Created test-dot-v5.1.1-unit.zsh (19 unit tests for new DOT features)
1272+
- 2026-01-10: TEST - Created test-dot-v5.1.1-e2e.zsh (14 E2E tests with real chezmoi)
1273+
- 2026-01-10: TEST - Created interactive-dot-dogfooding.zsh (8 dishes, "Dotfile Chef" theme)
1274+
- 2026-01-10: TEST - Fixed nullglob for cleanup (no matches error)
1275+
- 2026-01-10: TEST - Fixed read-only variable `status` → `resolve_status`
1276+
- 2026-01-10: TEST - Fixed ask_confirmation Enter handling (newline as default)
1277+
- 2026-01-10: TEST - Total DOT test coverage: 104 automated tests (71 + 19 + 14)
1278+
- 2026-01-10: SPEC - Created SPEC-dot-secret-management-v2-2026-01-10.md
1279+
- 2026-01-10: SPEC - Deep brainstorm: 8 questions, full lifecycle features
1280+
- 2026-01-10: SPEC - Phases: Foundation → Token Wizards → Lifecycle
1281+
- 2026-01-10: SPEC - Features: dot secret add, dot token github/npm/pypi, dot secrets dashboard
1282+
- 2026-01-10: SPEC - Security: 15-min cache, expiration tracking, no secrets in history
1283+
- 2026-01-10: STATUS - Updated .STATUS with test suite and spec completion
1284+
- 2026-01-11: FEAT - Implemented Secret Management v2.0 Phase 1 (dot secret add/check, dot lock)
1285+
- 2026-01-11: FEAT - Added 15-min session cache with auto-lock (7 helper functions)
1286+
- 2026-01-11: FEAT - Added vault status to `dot` status display (time remaining)
1287+
- 2026-01-11: TEST - Added Test Suite 13 with 22 new tests (93 total unit tests)
1288+
- 2026-01-11: DOCS - Updated help text with new secret commands
1289+
- 2026-01-11: PR - Created #198 (feature/secret-management-v2-phase1 → main)

completions/_dot

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ _dot() {
1313
's:Show dotfile sync status (alias)'
1414
'help:Show help message'
1515
'version:Show version information'
16-
'edit:Edit a dotfile with preview'
16+
'add:Add file to chezmoi'
17+
'edit:Edit a dotfile with preview (auto-add/create)'
1718
'e:Edit a dotfile (alias)'
1819
'sync:Pull changes from remote'
1920
'pull:Pull changes from remote (alias)'
@@ -62,8 +63,15 @@ _dot() {
6263
;;
6364
args)
6465
case "$line[1]" in
66+
add)
67+
# Complete file paths (for files not yet tracked)
68+
_files
69+
;;
6570
edit|e)
66-
_describe -t files 'managed file' files
71+
# Complete both managed files AND file paths (for auto-add/create)
72+
_alternative \
73+
'files:managed file:_describe -t files managed\ file files' \
74+
'paths:file path:_files'
6775
;;
6876
diff|d|apply|a)
6977
_describe -t files 'managed file' files

docs/reference/DOT-DISPATCHER-REFERENCE.md

Lines changed: 134 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Command:** `dot`
44
**Purpose:** Dotfile management via chezmoi and Bitwarden
5-
**Version:** v5.1.0 (Critical Improvements)
5+
**Version:** v5.1.1 (Auto-Add & Template Enhancements)
66

77
---
88

@@ -18,6 +18,14 @@ The `dot` dispatcher provides a unified interface for managing dotfiles with che
1818
-**Fast** (< 500ms for most operations)
1919
- 🔌 **Optional** (graceful degradation if tools not installed)
2020

21+
**✨ New in v5.1.1:**
22+
-**`dot add`** - Standalone command to add files to chezmoi
23+
- 🆕 **Auto-add in edit** - `dot edit` offers to add untracked files
24+
- 📁 **File creation** - `dot edit ~/.newrc` creates new files with `mkdir -p`
25+
- 🔐 **Template auto-unlock** - Auto-prompts for BW vault when editing `.tmpl` files
26+
- 📋 **Summary with tips** - Shows next step hints after operations
27+
- 🏠 **ZDOTDIR support** - Uses standard `${ZDOTDIR:-$HOME}` for shell config paths
28+
2129
**✨ New in v5.1.0:**
2230
- 🔍 **Hash-based change detection** - SHA-256 comparison catches all edits (even < 1s)
2331
- 🎯 **Smart error handling** - Specific guidance for each Bitwarden error type
@@ -31,9 +39,18 @@ The `dot` dispatcher provides a unified interface for managing dotfiles with che
3139
# Check dotfile status
3240
dot
3341

42+
# Add a file to chezmoi (v5.1.1+)
43+
dot add ~/.bashrc
44+
3445
# Edit a dotfile (with preview & apply)
3546
dot edit .zshrc
3647

48+
# Edit untracked file (prompts to add - v5.1.1+)
49+
dot edit ~/.bashrc
50+
51+
# Create new file (auto-creates parent dirs - v5.1.1+)
52+
dot edit ~/.config/newapp/config.zsh
53+
3754
# Preview changes without applying (v5.1.0+)
3855
dot apply --dry-run
3956

@@ -87,6 +104,31 @@ Show version information.
87104

88105
### Dotfile Management
89106

107+
#### `dot add FILE` (v5.1.1+)
108+
109+
Add a file to chezmoi for tracking.
110+
111+
**Features:**
112+
- Adds existing files to chezmoi
113+
- Shows source path in chezmoi directory
114+
- Provides next step hint
115+
116+
**Examples:**
117+
```bash
118+
dot add ~/.bashrc # Add bash config
119+
dot add ~/.config/app/config.toml # Add nested config
120+
```
121+
122+
**Output:**
123+
```
124+
✓ Added ~/.bashrc to chezmoi
125+
Source: ~/.local/share/chezmoi/dot_bashrc
126+
127+
💡 Tip: dot edit .bashrc to make changes
128+
```
129+
130+
---
131+
90132
#### `dot edit FILE` / `dot e FILE`
91133

92134
Edit a dotfile with preview and apply workflow.
@@ -97,22 +139,112 @@ Edit a dotfile with preview and apply workflow.
97139
- Shows diff preview
98140
- Prompts to apply changes
99141
- Fuzzy path matching (e.g., `dot edit zshrc` finds `.zshrc`)
142+
- **Auto-add untracked files** (v5.1.1) - Offers to add existing files not yet tracked
143+
- **Create new files** (v5.1.1) - Creates non-existent files with `mkdir -p`
144+
- **Template auto-unlock** (v5.1.1) - Prompts to unlock BW vault for `.tmpl` files
145+
- **Summary with tips** (v5.1.1) - Shows next step hint after operation
100146

101147
**Examples:**
102148
```bash
103149
dot edit .zshrc # Edit ZSH config
104150
dot edit zshrc # Fuzzy match works too
105151
dot e gitconfig # Short alias
152+
dot edit ~/.bashrc # Auto-add if untracked (v5.1.1+)
153+
dot edit ~/.config/new/app.zsh # Create new file (v5.1.1+)
106154
```
107155

108-
**Workflow:**
156+
**Workflow for tracked files:**
109157
1. Calculates SHA-256 hash of file before editing
110158
2. Opens file in editor
111159
3. You make changes and save (even quick edits < 1s are detected!)
112160
4. Compares hash after saving - detects ANY content change
113161
5. Shows diff: `Modified: ~/.zshrc`
114162
6. Prompts: `Apply changes? [Y/n/d(iff)]`
115163
7. If yes: Runs `chezmoi apply`
164+
8. Shows summary with next step tip
165+
166+
**Workflow for untracked files (v5.1.1+):**
167+
```
168+
$ dot edit ~/.bashrc
169+
170+
⚠ File not tracked: ~/.bashrc
171+
172+
a - Add to chezmoi and edit
173+
n - Cancel
174+
175+
Add? [a/n] a
176+
177+
✓ Added ~/.bashrc to chezmoi
178+
ℹ Opening in vim: dot_bashrc
179+
180+
[editor opens, you make changes]
181+
182+
✓ Changes detected!
183+
─────────────────────────────────────────────────
184+
[diff preview]
185+
─────────────────────────────────────────────────
186+
187+
Apply? [Y/n/d] y
188+
189+
✓ Applied changes
190+
191+
📋 ~/.bashrc | Added + Applied
192+
💡 Tip: dot push to sync to remote
193+
```
194+
195+
**Workflow for new files (v5.1.1+):**
196+
```
197+
$ dot edit ~/.config/newapp/config.zsh
198+
199+
⚠ File does not exist: ~/.config/newapp/config.zsh
200+
201+
c - Create, add to chezmoi, and edit
202+
n - Cancel
203+
204+
Create? [c/n] c
205+
206+
⊙ Created directory: ~/.config/newapp
207+
✓ Created ~/.config/newapp/config.zsh
208+
✓ Added ~/.config/newapp/config.zsh to chezmoi
209+
ℹ Opening in vim: dot_config/newapp/config.zsh
210+
```
211+
212+
**Template auto-unlock (v5.1.1+):**
213+
214+
When editing `.tmpl` files that contain `{{ bitwarden ... }}` syntax:
215+
```
216+
$ dot edit .env.tmpl
217+
218+
[editor opens, you make changes]
219+
220+
✓ Changes detected!
221+
222+
🔐 This template uses Bitwarden secrets.
223+
Unlock vault to preview expanded values?
224+
225+
y - Unlock and preview
226+
s - Skip preview (show raw template)
227+
n - Cancel
228+
229+
Unlock? [y/s/n] y
230+
231+
ℹ Unlocking Bitwarden vault...
232+
[password prompt]
233+
✓ Vault unlocked
234+
235+
─────────────────────────────────────────────────
236+
[diff preview with secrets expanded]
237+
─────────────────────────────────────────────────
238+
239+
Apply? [Y/n] y
240+
241+
✓ Applied changes
242+
243+
📋 .env.tmpl | Edited (secrets expanded) + Applied
244+
💡 Tip: dot push to sync to remote
245+
```
246+
247+
If you skip unlock, the diff shows raw template syntax like `{{ bitwarden "item" "field" }}`.
116248

117249
**Why hash-based detection? (v5.1.0)**
118250

0 commit comments

Comments
 (0)