thoughts-tool 0.7.0

Flexible thought management using filesystem mounts for git repositories
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
# Thoughts Tool v2

A flexible thought management tool that helps developers organize notes and documentation across git repositories using filesystem mounts (mergerfs on Linux, fuse-t on macOS) with a three-space architecture.

## What is Thoughts Tool?

Thoughts Tool creates a unified filesystem view of documentation through three distinct mount spaces:
- **thoughts/** - Your personal workspace for work documents, plans, and research
- **context/** - Team-shared documentation and context repositories
- **references/** - Read-only external code repositories for reference

It automatically mounts and syncs git-backed directories, allowing you to access all your project notes, decisions, and documentation from a single location while keeping them versioned with their respective repositories.

## Key Features

- 🗂️ **Three-Space Architecture**: Organized separation of thoughts, context, and references
- 🔄 **Automatic Git Sync**: Keep your documentation synchronized across repositories
- 🖥️ **Cross-Platform**: Works on Linux (mergerfs) and macOS (fuse-t)
- 📚 **Reference Management**: Read-only mounts for external code repositories
- 🌿 **Branch-Based Work Organization**: Automatic directory structure based on current branch
- 🔧 **Repository Integration**: Seamlessly integrates with existing git workflows
- 🎯 **Worktree Support**: Full support for git worktrees
- 🚀 **Auto-Mount System**: Automatic mount management for all three spaces

## Installation

### Prerequisites

#### Linux
- mergerfs installed (`apt install mergerfs` or `yum install mergerfs`)
- FUSE support enabled
- Git installed

#### macOS
- fuse-t installed (`brew install macos-fuse-t/homebrew-cask/fuse-t`)
- Git installed

### Building from Source

```bash
# Clone the repository
git clone <repository-url>
cd thoughts_tool

# Build the project
just build

# Install globally
cargo install --path .
```

## Quick Start

### 1. Initialize Thoughts for Your Repository

```bash
cd /path/to/your/project
thoughts init
```

This creates:
- `.thoughts/` directory for configuration
- `.thoughts-data/` directory for mount storage
- Three symlinks: `thoughts/`, `context/`, and `references/` pointing to the mount spaces

### 2. Configure Your Thoughts Mount (optional)

Edit `.thoughts/config.json` to add your personal workspace repository:

```json
{
  "version": "2.0",
  "thoughts_mount": {
    "remote": "git@github.com:user/my-thoughts.git",
    "sync": "auto"
  }
}
```

### 3. Add Context Mounts

```bash
# Add a team documentation repository
thoughts mount add https://github.com/team/docs-repo.git team-docs
```

### 4. Add Reference Repositories

```bash
# Add a reference repository (automatically organized by org/repo)
thoughts references add https://github.com/rust-lang/rust
```

### 5. Update All Mounts

```bash
# Mount everything configured
thoughts mount update

# Sync all git repositories
thoughts sync --all
```

### 6. Start Working

```bash
# Initialize a work directory for current branch
thoughts work init
```

## Usage

### Command Structure

```bash
thoughts [COMMAND] [OPTIONS]
```

### Available Commands

#### Core Commands
- `init` - Initialize thoughts for a repository
- `sync [<mount>]` - Sync specific mount or all with --all
- `status` - Show current mount status and configuration

#### Mount Management (Context Mounts)
- `mount add <source> <name>` - Add a new context mount
- `mount remove <name>` - Remove a context mount
- `mount list` - List all configured mounts
- `mount update` - Update/refresh all active mounts
- `mount clone <url> [<path>]` - Clone a repository to local path

#### Reference Management
- `references add <url>` - Add a reference repository
- `references remove <url>` - Remove a reference repository
- `references list` - List all configured references
- `references sync` - Clone missing reference repositories

#### Work Management
- `work init` - Initialize work directory for current branch
- `work complete` - Move current work to completed with date range
- `work list [--recent N]` - List active and completed work directories

#### Configuration Management
- `config create` - Create a new configuration
- `config show` - Display current configuration
- `config edit` - Edit configuration with $EDITOR
- `config validate` - Validate configuration syntax

## Configuration

Thoughts Tool uses a repository-based configuration system with automatic v1 to v2 migration support.

### Configuration Structure

The configuration file (`.thoughts/config.json`) defines:
- **thoughts_mount** - Your personal workspace repository (optional)
- **context_mounts** - Team-shared documentation repositories
- **references** - External code repositories for reference
- **mount_dirs** - Directory names for the three spaces (defaults: thoughts, context, references)

### v2 Configuration Example

```json
{
  "version": "2.0",
  "mount_dirs": {
    "thoughts": "thoughts",
    "context": "context",
    "references": "references"
  },
  "thoughts_mount": {
    "remote": "git@github.com:user/my-thoughts.git",
    "subpath": "projects/current",
    "sync": "auto"
  },
  "context_mounts": [
    {
      "remote": "https://github.com/team/shared-docs.git",
      "mount_path": "team-docs",
      "sync": "auto"
    },
    {
      "remote": "git@github.com:company/architecture.git",
      "mount_path": "architecture",
      "subpath": "docs",
      "sync": "auto"
    }
  ],
  "references": [
    "https://github.com/rust-lang/rust",
    "git@github.com:tokio-rs/tokio.git"
  ]
}
```

### Migration from v1

**Automatic migration happens on the first write operation** (e.g., `thoughts init`, `thoughts mount add`, `thoughts references add`):

- V1 configs are automatically converted to v2 format
- A timestamped backup is created if you have non-empty mounts or rules (`.thoughts/config.v1.bak-*.json`)
- Migration rules:
  - Mounts with `sync: none` or paths starting with `references/` → become references
  - Other mounts → become context mounts
  - Rules field → dropped (preserved in backup only)
- One-line message confirms migration with link to full guide

You can also explicitly migrate with:
```bash
thoughts config migrate-to-v2 --dry-run  # Preview
thoughts config migrate-to-v2 --yes      # Execute
```

For detailed migration instructions, see [MIGRATION_V1_TO_V2.md](./MIGRATION_V1_TO_V2.md).

## Architecture

### Three-Space Design
The tool organizes all mounts into three distinct spaces:

1. **Thoughts Space** (`thoughts/`)
   - Single git repository for personal work
   - Organized by branch name with `completed/` directory for archives
   - Supports subpath mounting for monorepo scenarios

2. **Context Space** (`context/`)
   - Multiple team-shared repositories
   - Each mount gets its own subdirectory
   - Full read-write access for collaboration

3. **References Space** (`references/`)
   - Read-only external code repositories
   - Auto-organized by `{org}/{repo}` structure
   - Never synced to prevent accidental modifications

### Platform Abstraction
The tool automatically detects your platform and uses the appropriate mount technology:
- **Linux**: Uses mergerfs for high-performance union filesystem
- **macOS**: Uses fuse-t for FUSE support on Apple Silicon and Intel Macs

### Mount Resolution
1. Uses type-safe `MountSpace` enum for mount identification
2. Resolves to unique paths under `.thoughts-data/`
3. Handles automatic cloning for missing repositories
4. Maintains mappings in `~/.thoughts/repos.json`

### Git Integration
- Full support for worktrees (see Git Worktree Support section)
- Automatic detection of repository boundaries
- Smart sync strategies (auto for thoughts/context, none for references)
- Branch-based work organization

## Git Worktree Support

thoughts_tool automatically detects and handles git worktrees. When you run `thoughts init` in a worktree:

1. It detects you're in a worktree
2. Verifies the main repository is initialized
3. Creates a symlink to share the main repository's mounts
4. No duplicate FUSE mounts are created

### Usage

```bash
# Initialize main repository first
cd /path/to/main/repo
thoughts init

# Create a worktree
git worktree add ../my-feature-branch

# Initialize the worktree (shares main repo's mounts)
cd ../my-feature-branch
thoughts init
```

### How It Works

Worktrees use a simple symlink approach:
- `.thoughts-data` -> Points to main repository's `.thoughts-data`
- The `thoughts`, `context`, and `references` symlinks are already tracked in git

This ensures:
- No duplicate mounts
- Consistent access to all three spaces across worktrees
- Automatic cleanup when worktree is removed

## Development

### Building and Testing

```bash
# Run checks (fmt + clippy)
just check

# Run tests
just test

# Build the project
just build

# Format code
just fmt

# Output mode variants
OUTPUT_MODE=normal just test    # Full cargo output
OUTPUT_MODE=verbose just test   # Verbose output

# Run specific test types via cargo
cargo test --lib                              # Unit tests only
THOUGHTS_INTEGRATION_TESTS=1 just test        # Integration tests included
```

### Project Structure

```
thoughts_tool/
├── src/
│   ├── commands/      # CLI command implementations
│   ├── config/        # Configuration management
│   ├── git/          # Git integration
│   ├── mount/        # Mount implementations
│   ├── platform/     # Platform detection and abstraction
│   └── utils/        # Utility functions
├── tests/            # Integration tests
└── justfile         # Build automation
```

## Advanced Features

### Branch Protection

All branch-specific workspace operations are blocked on 'main' and 'master' branches. Create a feature branch first, then re-run:

```bash
git checkout -b my/feature
thoughts work init
```

Legacy weekly directories (e.g., `2025-W01/`) are automatically archived to `completed/` on first run. If a completed item already exists with the same name, a `-migrated` suffix will be used to avoid collisions.

Branch-agnostic commands like `thoughts work list` and `thoughts references list` remain available on main.

### Work Organization

The work commands help organize your documentation by branch:

```bash
# On feature branch - creates thoughts/my-feature/
thoughts work init

# Complete work - moves to thoughts/completed/2025-01-15_to_2025-01-22_my-feature/
thoughts work complete
```

Each work directory includes:
- `research/` - Investigation notes and findings
- `plans/` - Design documents and implementation plans
- `artifacts/` - Generated files, diagrams, exports
- `manifest.json` - Metadata about the work session

### Reference Repository Management

References are read-only external repositories organized by org/repo:

```bash
# Add multiple references
thoughts references add https://github.com/rust-lang/rust
thoughts references add https://github.com/tokio-rs/tokio

# They mount to:
# references/rust-lang/rust/
# references/tokio-rs/tokio/

# Sync all references (clones if missing)
thoughts references sync
```

### Subpath Mounting

Mount specific subdirectories from larger repositories:

```json
{
  "thoughts_mount": {
    "remote": "git@github.com:user/monorepo.git",
    "subpath": "projects/current",
    "sync": "auto"
  },
  "context_mounts": [{
    "remote": "git@github.com:company/docs.git",
    "mount_path": "api-docs",
    "subpath": "api/v2",
    "sync": "auto"
  }]
}
```

## Troubleshooting

### Mount Permission Issues
If you encounter permission errors:
1. Ensure FUSE is properly installed and configured
2. Check that your user has permission to mount filesystems
3. On Linux, you may need to add your user to the `fuse` group

### Platform Detection Failed
The tool will inform you if required mount utilities are missing:
- Linux: Install mergerfs
- macOS: Install fuse-t via Homebrew

### Git Sync Conflicts
When sync conflicts occur:
1. The tool will notify you of conflicts
2. Resolve conflicts in the affected repository
3. Run `thoughts sync` again

## Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

### Development Setup

1. Fork the repository
2. Create a feature branch
3. Make your changes
4. Run tests: `just test`
5. Format code: `just fmt`
6. Submit a pull request

## License

MIT - See [LICENSE](../LICENSE) in the root of the repository.

## Acknowledgments

Built with excellent Rust libraries:
- [clap]https://github.com/clap-rs/clap for CLI parsing
- [git2]https://github.com/rust-lang/git2-rs for Git operations
- [serde]https://github.com/serde-rs/serde for serialization
- [tokio]https://github.com/tokio-rs/tokio for async runtime
- [tracing]https://github.com/tokio-rs/tracing for structured logging