Skip to content

Commit e71959c

Browse files
Copilotneongreen
andcommitted
tak: Store database in ~/.tak/ and auto-create on first use
- Change database location from current directory to ~/.tak/tak.db - Auto-create database and schema on first use (no need for `tak init`) - Update documentation to reflect new behavior - `tak init` command still works but is optional Co-authored-by: neongreen <1523306+neongreen@users.noreply.github.com>
1 parent 1d87444 commit e71959c

File tree

5 files changed

+48
-21
lines changed

5 files changed

+48
-21
lines changed

tak/IMPLEMENTATION.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Successfully implemented v0 of tak - a system-wide event-sourced task tracker as
1111
- **ULID identifiers**: Lexicographically sortable unique IDs for tasks and events
1212
- **Lamport timestamps**: Logical clock for event ordering
1313
- **WAL mode**: SQLite configured for better concurrency and durability
14+
- **Automatic setup**: Database created in `~/.tak/` on first use
1415

1516
### Event Types
1617
1. **task.created**: Creates a new task with title and creator
@@ -28,8 +29,8 @@ Role hierarchy (highest to lowest authority):
2829
When concurrent claims exist (same Lamport timestamp), the claim with highest authority becomes effective, and lower-authority claims are marked as tentative.
2930

3031
### CLI Commands
31-
- `tak init` - Initialize a new database
32-
- `tak db path` - Show database path
32+
- `tak init` - Initialize a new database (optional, auto-created on first use)
33+
- `tak db path` - Show database path (defaults to `~/.tak/tak.db`)
3334
- `tak new "title"` - Create a new task
3435
- `tak status set <id> <state>` - Set task status (supports --axis and --role flags)
3536
- `tak note <id> "text"` - Add a note to a task
@@ -92,12 +93,13 @@ PASS
9293

9394
Example workflow:
9495
```bash
95-
$ tak init
96-
Database initialized at /tmp/tak-demo/tak.db
97-
96+
# No initialization needed - database is created automatically
9897
$ tak new "Implement authentication"
9998
Created task tak_01K86GH6XWR3RYYY008V84SE8B: Implement authentication
10099

100+
$ tak db path
101+
/home/user/.tak/tak.db
102+
101103
$ tak status set tak_01K86GH6XWR3RYYY008V84SE8B in_progress
102104
Set status for task tak_01K86GH6XWR3RYYY008V84SE8B: generic=in_progress
103105

tak/README.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tak is a command-line tool that tracks tasks system-wide using an append-only ev
99
- **Authority lattice**: Conflicts are resolved based on role authority (human > qa > rel > agent > bot)
1010
- **Multi-valued registers**: Conflicting claims are preserved as tentative/effective
1111
- **SQLite backend**: Durable, inspectable, and portable
12+
- **Automatic setup**: Database is created automatically in `~/.tak/` on first use
1213

1314
## Installation
1415

@@ -27,21 +28,17 @@ mise run //tak:run
2728

2829
## Usage
2930

30-
### Initialize a database
31+
### Database Location
3132

32-
```bash
33-
tak init
34-
```
35-
36-
This creates a `tak.db` file in the current directory.
33+
tak stores its database in `~/.tak/tak.db` by default. The database and directory are created automatically on first use.
3734

3835
### Create a task
3936

4037
```bash
4138
tak new "wire up rc deploy toggle"
4239
```
4340

44-
This creates a new task with a unique ID like `tak_01J3XM4NZ2R72`.
41+
This creates a new task with a unique ID like `tak_01J3XM4NZ2R72`. No initialization is required.
4542

4643
### Set task status
4744

@@ -87,6 +84,14 @@ tak ls --axis generic:in_progress
8784
tak db path
8885
```
8986

87+
### Initialize database (optional)
88+
89+
The database is created automatically when you first use tak. However, you can explicitly initialize it:
90+
91+
```bash
92+
tak init
93+
```
94+
9095
## Concepts
9196

9297
### Events
@@ -122,7 +127,8 @@ Tasks can have multiple status axes. Currently, only the "generic" axis is used,
122127

123128
This is v0 of tak - a minimal claims tracker. The current implementation includes:
124129

125-
- Event store with SQLite backend
130+
- Event store with SQLite backend in `~/.tak/`
131+
- Automatic database initialization
126132
- Basic task lifecycle (create, status, notes)
127133
- Authority-based claim resolution
128134
- CLI for all core operations
@@ -148,6 +154,6 @@ go fmt ./...
148154

149155
Run via mise:
150156
```bash
151-
mise run //tak:run init
152157
mise run //tak:run new "test task"
158+
mise run //tak:run ls
153159
```

tak/db.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ type DB struct {
2121

2222
// OpenDB opens or creates a tak database at the given path
2323
func OpenDB(path string) (*DB, error) {
24+
// Ensure the directory exists
25+
dir := filepath.Dir(path)
26+
if err := os.MkdirAll(dir, 0755); err != nil {
27+
return nil, fmt.Errorf("failed to create directory %s: %w", dir, err)
28+
}
29+
2430
db, err := sql.Open("sqlite3", path)
2531
if err != nil {
2632
return nil, fmt.Errorf("failed to open database: %w", err)
@@ -178,14 +184,15 @@ func (d *DB) Close() error {
178184
return d.db.Close()
179185
}
180186

181-
// GetDBPath returns the database path for the current directory
187+
// GetDBPath returns the database path in ~/.tak/ directory
182188
func GetDBPath() (string, error) {
183-
cwd, err := os.Getwd()
189+
home, err := os.UserHomeDir()
184190
if err != nil {
185-
return "", fmt.Errorf("failed to get current directory: %w", err)
191+
return "", fmt.Errorf("failed to get home directory: %w", err)
186192
}
187193

188-
return filepath.Join(cwd, dbFileName), nil
194+
takDir := filepath.Join(home, ".tak")
195+
return filepath.Join(takDir, dbFileName), nil
189196
}
190197

191198
// DBExists checks if a database exists at the given path

tak/main.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,23 @@ func openExistingDB() (*DB, error) {
350350
return nil, err
351351
}
352352

353-
if !DBExists(path) {
354-
return nil, fmt.Errorf("database not found at %s, run 'tak init' first", path)
353+
// Check if database exists, if not, create it
354+
dbExists := DBExists(path)
355+
356+
db, err := OpenDB(path)
357+
if err != nil {
358+
return nil, err
359+
}
360+
361+
// If database didn't exist, initialize the schema
362+
if !dbExists {
363+
if err := db.InitDB(); err != nil {
364+
db.Close()
365+
return nil, fmt.Errorf("failed to initialize database schema: %w", err)
366+
}
355367
}
356368

357-
return OpenDB(path)
369+
return db, nil
358370
}
359371

360372
func getCurrentUser() (string, error) {

tak/tak

-23.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)