hindsight-git 0.1.1

Git log processing for hindsight-mcp
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
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
# hindsight-mcp

An MCP server for AI-assisted coding that leverages development history.

## Overview

**hindsight-mcp** consolidates various "development data" stored locally (git logs, nextest test results, and GitHub Copilot logs) into a well-structured, searchable SQLite database, making it accessible to an AI assistant through MCP tool calls within VS Code. It is designed to help Rust developers and an AI assistant gain insights into their coding history, find relevant information quickly, and improve productivity by providing context-aware assistance.

## Quick Start

### Installation

**Option A: Install from crates.io** (recommended)
```bash
cargo install hindsight-mcp
```

**Option B: Build from source**
```bash
git clone https://github.com/Rbfinch/hindsight-mcp.git
cd hindsight-mcp
cargo build --release

# The binary is at ./target/release/hindsight-mcp
```

### Configure VS Code

Add to `.vscode/mcp.json` in your project:

```json
{
  "servers": {
    "hindsight": {
      "type": "stdio",
      "command": "hindsight-mcp",
      "args": ["--workspace", "${workspaceFolder}"]
    }
  }
}
```

> **Note:** If installed via `cargo install`, `hindsight-mcp` will be in your PATH. Otherwise, use the full path to the binary.

### First Run

On first use, ingest your development history:

```bash
# Option A: Run the server directly (it auto-creates the database)
hindsight-mcp -w /path/to/your/project
```

Then ask Copilot to use the `hindsight_ingest` tool, or ingest happens automatically on first query.

**That's it!** You can now ask Copilot questions like:
- "What have I been working on recently?" → uses `hindsight_timeline`
- "Find commits about authentication" → uses `hindsight_search`
- "What tests are failing?" → uses `hindsight_failing_tests`
- "Summarise my activity this week" → uses `hindsight_activity_summary`

### Available Tools

| Tool | Purpose |
|------|---------|
| `hindsight_timeline` | Chronological view of commits, tests, Copilot sessions |
| `hindsight_search` | Full-text search across commits and messages |
| `hindsight_failing_tests` | Currently failing tests from recent runs |
| `hindsight_activity_summary` | Aggregate stats for a time period |
| `hindsight_commit_details` | Detailed commit info with linked test runs |
| `hindsight_ingest` | Trigger data ingestion from git/copilot |

## Usage

### Command Line Options

```
hindsight-mcp [OPTIONS] [COMMAND]

Commands:
  ingest    Ingest data from various sources (e.g., test results)
  help      Print help for commands

Options:
  -d, --database <PATH>   Path to SQLite database file
                          [env: HINDSIGHT_DATABASE]
                          [default: ~/.hindsight/hindsight.db]

  -w, --workspace <PATH>  Default workspace path for queries
                          [env: HINDSIGHT_WORKSPACE]
                          [default: current directory]

  -v, --verbose           Enable verbose logging (debug level)

  -q, --quiet             Suppress info-level logs (errors/warnings only)

      --skip-init         Skip database initialization/migration check

  -h, --help              Print help

  -V, --version           Print version
```

### Environment Variables

| Variable | Description |
|----------|-------------|
| `HINDSIGHT_DATABASE` | Path to SQLite database (alternative to `--database`) |
| `HINDSIGHT_WORKSPACE` | Default workspace path (alternative to `--workspace`) |

### Ingest Subcommand

The `ingest` command imports test results from stdin:

```
hindsight-mcp ingest [OPTIONS]

Options:
      --tests             Ingest test results from stdin (nextest JSON format)
      --commit <SHA>      Git commit SHA to associate with test results
  -h, --help              Print help
```

**Example:**
```bash
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run --message-format libtest-json | \
  hindsight-mcp ingest --tests --commit $(git rev-parse HEAD)
```

## MCP Tools

hindsight-mcp exposes 6 tools for AI-assisted development:

### `hindsight_timeline`

Get a chronological view of development activity (commits, test runs, Copilot sessions).

```
Arguments:
  limit (integer): Maximum events to return (default: 50)
  workspace (string): Filter by workspace path (optional)
```

### `hindsight_search`

Full-text search across commits and Copilot messages using FTS5 syntax.

```
Arguments:
  query (string): Search query (required)
  source (string): "all", "commits", or "messages" (default: "all")
  limit (integer): Maximum results (default: 20)
```

### `hindsight_failing_tests`

Get currently failing tests from recent test runs, optionally filtered by commit.

```
Arguments:
  limit (integer): Maximum tests to return (default: 50)
  workspace (string): Filter by workspace (optional)
  commit (string): Filter by commit SHA - full or partial (optional)
```

### `hindsight_activity_summary`

Get aggregate activity statistics for a time period.

```
Arguments:
  days (integer): Number of days to summarize (default: 7)
```

### `hindsight_commit_details`

Get detailed information about a specific commit including linked test runs.

```
Arguments:
  sha (string): Full or partial commit SHA (required)
```

### `hindsight_ingest`

Trigger data ingestion from sources (git, Copilot).

```
Arguments:
  workspace (string): Workspace path to ingest (required)
  source (string): "git", "copilot", or "all" (default: "all")
  incremental (boolean): Only ingest new data (default: true)
  limit (integer): Max items to ingest (optional)
```

## Data Sources

### Git Commits

Automatically ingests commit history including:
- SHA, author, message, timestamp
- Parent commit references
- Optional diff statistics

### Test Results

Ingests cargo-nextest output:
- Test run metadata (pass/fail counts)
- Individual test outcomes
- Duration and output capture

#### Ingesting Test Results

Test results require piping nextest JSON output to the CLI:

```bash
# Run tests and ingest results
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run --message-format libtest-json 2>/dev/null | \
  hindsight-mcp --database ~/.hindsight/hindsight.db --workspace /path/to/project ingest --tests

# Ingest specific test targets
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run --package my-crate --message-format libtest-json 2>/dev/null | \
  hindsight-mcp --database ~/.hindsight/hindsight.db --workspace /path/to/project ingest --tests

# Associate test run with a specific commit
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run --message-format libtest-json 2>/dev/null | \
  hindsight-mcp --workspace /path/to/project ingest --tests --commit abc123def
```

**Note:** The `2>/dev/null` redirects compiler warnings/errors to avoid mixing them with the JSON output.

### GitHub Copilot Sessions

Parses VS Code Copilot chat history:
- User prompts and assistant responses
- Attached files and selections
- Session timestamps

## Examples

This section demonstrates common workflows using hindsight-mcp with Copilot.

### Exploring Your Development Timeline

Ask Copilot to show recent activity:

```
"What have I been working on recently?"
"Show me the last 20 commits"
"What happened in this project today?"
```

The `hindsight_timeline` tool returns a chronological view:

```json
[
  {
    "type": "commit",
    "timestamp": "2026-01-18T10:30:00Z",
    "sha": "abc123",
    "message": "feat: add user authentication"
  },
  {
    "type": "test_run",
    "timestamp": "2026-01-18T10:35:00Z",
    "passed": 42,
    "failed": 0
  },
  {
    "type": "copilot_session",
    "timestamp": "2026-01-18T11:00:00Z",
    "message_count": 5
  }
]
```

### Searching Your Codebase History

Use natural language to search commits and Copilot conversations:

```
"Find commits about authentication"
"Search for error handling changes"
"What did I discuss about the database schema?"
```

The `hindsight_search` tool uses FTS5 full-text search:

```
hindsight_search(query: "authentication", source: "commits", limit: 10)
```

Returns matching commits with context:

```json
[
  {
    "sha": "abc123def",
    "message": "feat: add user authentication with JWT tokens",
    "author": "developer@example.com",
    "timestamp": "2026-01-15T14:22:00Z"
  },
  {
    "sha": "def456ghi",
    "message": "fix: authentication token expiry handling",
    "author": "developer@example.com",
    "timestamp": "2026-01-16T09:15:00Z"
  }
]
```

### Querying Failing Tests

After ingesting test results, query for failures using the MCP tool or Copilot:

```
# Ask Copilot:
"What tests are failing?"
"Show me the failing test output"
"Which tests failed in the last run?"
"What tests failed for commit abc123?"
```

The `hindsight_failing_tests` tool returns:
- Test name and suite
- Duration and timestamp
- Failure output (panic messages, assertion errors)
- Associated commit SHA (if linked)

**Example queries:**
- All failing tests: `hindsight_failing_tests()`
- For a specific commit: `hindsight_failing_tests(commit: "a566594")`
- Combined filters: `hindsight_failing_tests(workspace: "/path/to/project", commit: "abc123")`

### Linking Tests to Commits

This workflow demonstrates ingesting test results linked to a specific commit, then querying those failures:

**Step 1: Get the current commit SHA**
```bash
git rev-parse HEAD
# Output: a5665945a0efb9f59fea1392dbdbdcc7e5ce48c6
```

**Step 2: Run tests and ingest with commit linkage**
```bash
NEXTEST_EXPERIMENTAL_LIBTEST_JSON=1 cargo nextest run --message-format libtest-json 2>/dev/null | \
  hindsight-mcp --workspace /path/to/project ingest --tests --commit a5665945a0efb9f59fea1392dbdbdcc7e5ce48c6
```

Output:
```
Ingested 6 test results in 1 test run(s)
```

**Step 3: Query failing tests for that commit**

Using the MCP tool (via Copilot or directly):
```
hindsight_failing_tests(commit: "a5665945")
```

Returns failures linked to that specific commit:
```json
[
  {
    "commit_sha": "a5665945a0efb9f59fea1392dbdbdcc7e5ce48c6",
    "full_name": "test_assertion_failure",
    "duration_ms": 8,
    "output_json": "assertion `left == right` failed: left: 2, right: 3"
  },
  {
    "commit_sha": "a5665945a0efb9f59fea1392dbdbdcc7e5ce48c6",
    "full_name": "test_panic_failure",
    "duration_ms": 8,
    "output_json": "panicked at: This test panics on purpose"
  }
]
```

**Step 4: View commit details with linked test runs**
```
hindsight_commit_details(sha: "a5665945")
```

Returns commit info including all associated test runs:
```json
{
  "sha": "a5665945a0efb9f59fea1392dbdbdcc7e5ce48c6",
  "message": "feat: add commit filter to hindsight_failing_tests",
  "test_runs": [
    { "passed": 2, "failed": 4, "timestamp": "2026-01-17T23:38:43Z" }
  ]
}
```

This enables powerful queries like:
- "Which commit introduced these test failures?"
- "Did the tests pass after this fix?"
- "Show me all failures from yesterday's commits"

### Weekly Activity Summary

Get an overview of your development activity:

```
"Summarise my activity this week"
"How productive was I last month?"
"Give me stats for the past 30 days"
```

The `hindsight_activity_summary` tool aggregates statistics:

```
hindsight_activity_summary(days: 7)
```

Returns:

```json
{
  "period_days": 7,
  "commits": 23,
  "test_runs": 45,
  "tests_passed": 1250,
  "tests_failed": 12,
  "copilot_sessions": 8,
  "copilot_messages": 67
}
```

### Investigating a Specific Commit

Get detailed information about any commit:

```
"Tell me about commit abc123"
"What tests ran for the last commit?"
"Show details for the authentication fix"
```

The `hindsight_commit_details` tool provides full context:

```
hindsight_commit_details(sha: "abc123")
```

Returns:

```json
{
  "sha": "abc123def456789",
  "message": "feat: add OAuth2 support for GitHub login",
  "author": "developer@example.com",
  "timestamp": "2026-01-17T15:30:00Z",
  "parents": ["parent123"],
  "test_runs": [
    {
      "timestamp": "2026-01-17T15:35:00Z",
      "passed": 156,
      "failed": 0,
      "skipped": 2
    }
  ]
}
```

### Refreshing Data

Trigger manual ingestion when you want the latest data:

```
"Refresh the development history"
"Ingest new commits"
"Update the Copilot session data"
```

The `hindsight_ingest` tool supports selective ingestion:

```
# Ingest everything
hindsight_ingest(workspace: "/path/to/project", source: "all")

# Just git commits
hindsight_ingest(workspace: "/path/to/project", source: "git")

# Just Copilot sessions
hindsight_ingest(workspace: "/path/to/project", source: "copilot")

# Limit to recent items
hindsight_ingest(workspace: "/path/to/project", source: "git", limit: 50)
```

## Database Location

Default database path by platform:

| Platform | Path |
|----------|------|
| macOS | `~/Library/Application Support/hindsight/hindsight.db` |
| Linux | `~/.local/share/hindsight/hindsight.db` |
| Windows | `%LOCALAPPDATA%\hindsight\hindsight.db` |

Override with `--database` or `HINDSIGHT_DATABASE`.

## Troubleshooting

### Server doesn't start

1. Check the binary path is correct
2. Verify write permissions for database directory
3. Run with `--verbose` for debug logs:
   ```bash
   hindsight-mcp --verbose --database /tmp/test.db
   ```

### No data showing

1. Run ingestion manually via the `hindsight_ingest` tool
2. Ensure workspace path points to a git repository
3. Check database exists: `ls ~/.hindsight/`

### Logs interference

The server logs to stderr to avoid interfering with MCP stdio transport. Use `--quiet` in production.

## Dependencies

hindsight-mcp bundles its native dependencies for ease of installation:

| Dependency | Purpose | Notes |
|------------|---------|-------|
| `rusqlite` | SQLite database | Bundled; no system SQLite required |
| `git2` | Git repository access | Uses bundled libgit2 |
| `rust-mcp-sdk` | MCP protocol | Pure Rust |
| `tokio` | Async runtime | Pure Rust |

### System Requirements

- **Rust**: 1.89 or later (for building from source)
- **OS**: Linux, macOS, or Windows
- **No additional system libraries required** — all native dependencies are bundled

## Workspace Structure

```
hindsight/
├── Cargo.toml              # Workspace manifest
├── crates/
│   ├── hindsight-mcp/      # Binary crate - MCP server
│   ├── hindsight-git/      # Library - Git log processing
│   ├── hindsight-tests/    # Library - Test result processing
│   └── hindsight-copilot/  # Library - Copilot log processing
```

## Crates

### hindsight-mcp (binary)
The main MCP server that bridges AI and development history.
- Dependencies: `rust-mcp-sdk`, `rusqlite`, `clap`, `tokio`

### hindsight-git (library)
Processes git logs for consumption by hindsight-mcp.
- Dependencies: `git2`

### hindsight-tests (library)
Processes test logs (particularly from cargo-nextest).
- Dependencies: `nextest-metadata`

### hindsight-copilot (library)
Processes GitHub Copilot logs and chat sessions.
- Dependencies: `serde_json`, `lsp-types`, `tracing-subscriber`

## Development

This project uses [cargo-nextest](https://nexte.st/) as its test runner for faster, more reliable test execution.

### Prerequisites

```bash
# Install cargo-nextest (required for running tests)
cargo install cargo-nextest
```

### Building

```bash
cargo build --workspace
```

### Testing

```bash
# Run tests with nextest (recommended)
cargo nextest run --workspace

# Or use standard cargo test for doc tests
cargo test --workspace --doc
```

### Benchmarks

```bash
cargo bench --workspace
```

### Fuzzing

The `hindsight-tests` and `hindsight-copilot` crates have fuzz targets for their parsing functions. To run:

```bash
cd crates/hindsight-tests
cargo +nightly fuzz run fuzz_nextest_run

cd crates/hindsight-copilot
cargo +nightly fuzz run fuzz_session_json
```

## License

MIT