Skip to content

Commit 6e4230f

Browse files
committed
feat: add tui "clockwork tui" views for CRUD operations over the terminal
1 parent fcaa2da commit 6e4230f

16 files changed

Lines changed: 2331 additions & 136 deletions

File tree

CLAUDE.md

Lines changed: 88 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
44

55
## Project Overview
66

7-
Clockwork is an MCP (Model Context Protocol) server that automatically tracks work time based on git commits. It aggregates commits into worklog entries and calculates durations.
7+
Clockwork is a dual-mode time tracking system that automatically tracks work time based on git commits:
8+
9+
1. **MCP Server Mode** - Exposes time tracking as MCP tools for integration with Claude and other LLM applications
10+
2. **TUI Mode** - Interactive terminal user interface for direct interaction with keyboard navigation
11+
12+
Both modes share the same embedded bbolt database and business logic.
813

914
**Module Path:** `github.com/techthos/clockwork`
1015

11-
## Build and Test Commands
16+
## Build and Run Commands
1217

1318
```bash
1419
# Build binary
@@ -17,6 +22,12 @@ go build -o clockwork ./cmd/clockwork
1722
# Install to GOPATH/bin
1823
go install ./cmd/clockwork
1924

25+
# Run MCP server mode (default)
26+
./clockwork
27+
28+
# Run TUI mode
29+
./clockwork tui
30+
2031
# Run all tests
2132
go test ./...
2233

@@ -26,6 +37,7 @@ go test -cover ./...
2637
# Run specific package tests
2738
go test ./internal/db -v
2839
go test ./internal/git -v
40+
go test ./internal/tui -v
2941

3042
# Tidy dependencies
3143
go mod tidy
@@ -112,6 +124,46 @@ The core workflow aggregates git commits into worklog entries:
112124
- `GetLatestCommitHash()` runs `git rev-parse HEAD`
113125
- All operations require absolute repo paths (`filepath.Abs()`)
114126

127+
### TUI Architecture
128+
129+
`internal/tui/` implements a terminal user interface using tview:
130+
131+
**Main Components:**
132+
- `app.go` - Application shell with page management and navigation
133+
- `projects.go` - Projects list view (table with CRUD operations)
134+
- `entries.go` - Entries list view with filtering and summary footer
135+
- `stats.go` - Statistics dashboard with breakdowns
136+
- `project_form.go` - Project create/edit modal forms
137+
- `entry_form.go` - Entry create/edit with git/manual modes
138+
- `modals.go` - Reusable error/confirm/info dialogs
139+
- `theme.go` - Color scheme constants
140+
- `helpers.go` - Formatting utilities (duration, dates, percentages)
141+
142+
**Navigation Flow:**
143+
```
144+
Projects View (default)
145+
→ Entries View (filtered by project)
146+
→ Statistics View (with filters)
147+
→ Entry Forms (git/manual modes)
148+
→ Project Forms (create/edit)
149+
```
150+
151+
**Keyboard Shortcuts:**
152+
- Global: `Ctrl+C`/`Ctrl+Q` = quit, `Esc` = close modal
153+
- Projects: `n` = new, `e` = edit, `d` = delete, `Enter` = view entries, `q` = quit
154+
- Entries: `n` = new, `e` = edit, `d` = delete, `i` = toggle invoiced, `f` = filter, `s` = stats, `q` = back
155+
- Stats: `f` = filter, `r` = refresh, `q` = back
156+
157+
**Filtering:**
158+
- `FilterOptions` struct tracks current filters (project, date range, invoiced status)
159+
- Filters persist within a session, reset between entries/stats views
160+
- Uses `store.ListEntriesFiltered()` and `store.GetStatistics()` with filter parameters
161+
162+
**TUI vs MCP Mode:**
163+
- Both use same `db.Store` interface - no database layer changes needed
164+
- Entry point (`main.go`) checks for `tui` argument to determine mode
165+
- Only one mode can run at a time due to bbolt's single-writer file lock
166+
115167
## Key Implementation Details
116168

117169
### MCP Server Initialization
@@ -138,14 +190,47 @@ Entry point (`cmd/clockwork/main.go`) → `server.New()`:
138190

139191
## Dependencies
140192

193+
**Core:**
141194
- **github.com/mark3labs/mcp-go v0.9.0** - MCP protocol (stdio transport)
142195
- **go.etcd.io/bbolt v1.3.11** - Embedded key-value database
143196
- **github.com/google/uuid v1.6.0** - UUID generation
197+
198+
**TUI:**
199+
- **github.com/rivo/tview v0.42.0** - Terminal UI framework (high-level widgets)
200+
- **github.com/gdamore/tcell/v2 v2.8.1** - Terminal cell-based view (tview dependency)
201+
202+
**System:**
144203
- System **git** command required (not a Go dependency)
145204

146205
## Database Location
147206

148207
Production: `~/.local/clockwork/default.db`
149208
Tests: `t.TempDir()/<testname>.db`
150209

151-
Only one instance can hold the database lock at a time (bbolt limitation).
210+
**Important Limitation:** Only one instance can hold the database lock at a time (bbolt limitation). This means:
211+
- Cannot run MCP server and TUI simultaneously
212+
- Attempting to start TUI while MCP server is running will fail with "timeout" error
213+
- Attempting to start MCP server while TUI is running will fail with "timeout" error
214+
- This is by design for data integrity - bbolt ensures single-writer safety
215+
216+
## TUI Usage
217+
218+
After building, launch the TUI:
219+
220+
```bash
221+
./clockwork tui
222+
```
223+
224+
**Quick Start:**
225+
1. Press `n` in Projects view to create first project
226+
2. Enter project name and git repository path
227+
3. Press `Enter` on project to view entries
228+
4. Press `n` to create entry (choose Git or Manual mode)
229+
5. Git mode: automatically aggregates commits since last entry
230+
6. Manual mode: enter duration (e.g., "1h 30m") and message
231+
7. Press `s` from entries view to see statistics
232+
8. Press `f` to apply filters (project, date range, invoiced status)
233+
234+
**Entry Creation Modes:**
235+
- **Git Mode**: Fetches commits since last entry, auto-calculates duration, generates message from commit summaries
236+
- **Manual Mode**: User enters duration and message manually (for non-git work like meetings)

0 commit comments

Comments
 (0)