Skip to content

Commit ac427de

Browse files
committed
Merge PR #2: Add modular formatter architecture for CLI commands
Extract beautiful color gradients and formatting logic from `forest edges propose` into reusable components. Establishes 3-layer architecture for consistent, maintainable command output. Phase 1 Complete: Color utilities ready to use - src/cli/formatters/colors.ts - HSL gradients, themes, utilities - src/cli/formatters/edges.ts - Edge-specific table formatters - src/cli/formatters/index.ts - Clean public API Key Benefits: - Reusability: Use colorize.* in any command - Consistency: All commands use FOREST_THEMES palette - Maintainability: Update colors in one place - Testability: Pure functions (data → string) Documentation: - MODULAR_COMMANDS_GUIDE.md - Quick start and phased migration - FORMATTING_ARCHITECTURE.md - Full architectural spec - src/cli/formatters/README.md - Module usage guide - PR_SUMMARY.md - Complete PR overview Dependencies: - Add chalk@^4.1.2 (already used, now explicit) - Add @clack/prompts@^0.7.0 (already used, now explicit) Non-breaking: Pure additive changes, existing commands unchanged. Ready to use: Commands can import colorize.* immediately. Next phases: Extract core functions, migrate commands systematically.
2 parents 7fa7acb + c01acf4 commit ac427de

18 files changed

Lines changed: 2958 additions & 27 deletions

CLAUDE.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,112 @@ export function registerNodeCommands(cli: ClercInstance, clerc: ClercModule) {
155155
}
156156
```
157157

158+
### Git-Style Node References
159+
160+
Forest uses **Git-inspired progressive abbreviation** for node and edge IDs, optimizing for both brevity and backward compatibility.
161+
162+
#### Display vs. Acceptance
163+
164+
**What Forest displays** (optimized for current graph size):
165+
```bash
166+
$ forest explore
167+
ID TITLE EDGES
168+
7fa7 Optimize UUIDs 12 # Shows 4-7 chars (enough for uniqueness)
169+
ef3a Progressive IDs 8
170+
```
171+
172+
**What Forest accepts** (any unique prefix):
173+
```bash
174+
$ forest node read 7fa7 # 4 chars ✅
175+
$ forest node read 7fa7acb2 # 8 chars ✅ (backward compatible!)
176+
$ forest node read 7fa7acb2-ed4a-4f3b-9c1e-8a2b3c4d5e6f # full UUID ✅
177+
```
178+
179+
All lengths work! Forest accepts **any unique prefix**, even if display shows shorter.
180+
181+
#### Reference Types
182+
183+
Forest supports multiple reference patterns (unified resolution in `src/cli/shared/utils.ts:resolveNodeReference()`):
184+
185+
**1. UUID Prefixes** (case-insensitive, works with/without dashes):
186+
```bash
187+
forest node read 7fa7 # Short prefix
188+
forest node read 7fa7acb2 # 8-char prefix
189+
forest node read 7fa7acb2-ed4a # Longer prefix
190+
```
191+
192+
**2. Recency References** (Git-style `HEAD~N`):
193+
```bash
194+
forest node read @ # Last updated node (@ or @0)
195+
forest node read @1 # Second most recently updated
196+
forest node read @2 # Third most recently updated
197+
forest node link @ @1 # Link two recent nodes
198+
```
199+
200+
**3. Tag Search** (exact match, finds unique node):
201+
```bash
202+
forest node read #typescript # Node tagged with 'typescript'
203+
forest node read #api-design # Node tagged with 'api-design'
204+
```
205+
206+
**4. Title Search** (substring match, must be unique):
207+
```bash
208+
forest node read "UUID short" # Finds node with "UUID short" in title
209+
forest node read "api" # Finds node with "api" in title (if unique)
210+
```
211+
212+
#### Disambiguation
213+
214+
When a reference matches multiple nodes, Forest shows **Git-style disambiguation**:
215+
216+
```bash
217+
$ forest node read 7fa
218+
✖ Ambiguous ID '7fa' matches 3 nodes:
219+
7fa7acb2 "Optimize UUID shortcodes" (2025-10-21)
220+
7fa2103e "Add progressive IDs" (2025-10-20)
221+
7fa8ef29 "Update scoring algorithm" (2025-10-19)
222+
223+
Use a longer prefix to disambiguate.
224+
```
225+
226+
Similar disambiguation for tag and title searches shows matching nodes with IDs for easy selection.
227+
228+
#### Progressive Display
229+
230+
**Node IDs**: Use `formatNodeIdProgressive()` in `src/cli/shared/utils.ts`
231+
- Minimum 4 chars, grows as needed to maintain uniqueness
232+
- Implementation: `src/lib/progressive-id.ts` with `buildNodePrefixMap()`
233+
234+
**Edge IDs**: Already use progressive abbreviation (4+ chars)
235+
- Stable hash generation via FNV-1a
236+
- Minimal prefix display in `forest edges` output
237+
238+
#### Backward Compatibility
239+
240+
**Zero breaking changes**: All existing 8-char references continue to work!
241+
242+
- External docs with `7fa7acb2` keep resolving correctly
243+
- Scripts using full UUIDs remain valid
244+
- API responses can return any length (recommended: 8 chars or full UUID)
245+
- `--long` flag available for full UUIDs when needed
246+
247+
#### Tab Completion
248+
249+
Shell completion scripts available in `completions/`:
250+
- `forest.bash` - Bash completion
251+
- `forest.zsh` - Zsh completion
252+
- Supports command, flag, and recency reference completion
253+
254+
**Installation**:
255+
```bash
256+
# Bash
257+
source completions/forest.bash
258+
259+
# Zsh (add to ~/.zshrc)
260+
fpath=(path/to/forest/completions $fpath)
261+
autoload -Uz compinit && compinit
262+
```
263+
158264
### 3-Layer Architecture: CLI/API Feature Parity
159265

160266
Forest uses a **3-layer architecture** to maintain feature parity between the CLI and REST API:

0 commit comments

Comments
 (0)