gitview 0.1.3__tar.gz → 0.7.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. gitview-0.7.1/PKG-INFO +1355 -0
  2. gitview-0.7.1/README.md +1311 -0
  3. {gitview-0.1.3 → gitview-0.7.1}/examples/basic_usage.py +5 -5
  4. gitview-0.7.1/examples/hierarchical_example.py +106 -0
  5. {gitview-0.1.3 → gitview-0.7.1}/gitview/__init__.py +1 -1
  6. gitview-0.7.1/gitview/adaptive/__init__.py +35 -0
  7. gitview-0.7.1/gitview/adaptive/agent.py +722 -0
  8. gitview-0.7.1/gitview/adaptive/decision_engine.py +492 -0
  9. gitview-0.7.1/gitview/adaptive/discovery_extractor.py +705 -0
  10. gitview-0.7.1/gitview/adaptive/models.py +363 -0
  11. {gitview-0.1.3 → gitview-0.7.1}/gitview/backends/__init__.py +2 -0
  12. gitview-0.7.1/gitview/backends/anthropic_backend.py +112 -0
  13. gitview-0.7.1/gitview/backends/claude_cli_backend.py +109 -0
  14. {gitview-0.1.3 → gitview-0.7.1}/gitview/backends/router.py +32 -8
  15. gitview-0.7.1/gitview/branch_comparator.py +467 -0
  16. gitview-0.7.1/gitview/cache.py +380 -0
  17. {gitview-0.1.3 → gitview-0.7.1}/gitview/chunker.py +21 -8
  18. gitview-0.7.1/gitview/cli.py +695 -0
  19. gitview-0.7.1/gitview/commands/__init__.py +37 -0
  20. gitview-0.7.1/gitview/commands/analyze.py +1184 -0
  21. gitview-0.7.1/gitview/commands/base.py +87 -0
  22. gitview-0.7.1/gitview/commands/brief.py +450 -0
  23. gitview-0.7.1/gitview/commands/chunk.py +98 -0
  24. gitview-0.7.1/gitview/commands/compare_branches.py +113 -0
  25. gitview-0.7.1/gitview/commands/extract.py +53 -0
  26. gitview-0.7.1/gitview/commands/file_history.py +102 -0
  27. gitview-0.7.1/gitview/commands/graph.py +124 -0
  28. gitview-0.7.1/gitview/commands/inject_history.py +130 -0
  29. gitview-0.7.1/gitview/commands/motifs.py +110 -0
  30. gitview-0.7.1/gitview/commands/observe.py +94 -0
  31. gitview-0.7.1/gitview/commands/remove_history.py +109 -0
  32. gitview-0.7.1/gitview/commands/storyline/__init__.py +15 -0
  33. gitview-0.7.1/gitview/commands/storyline/export.py +90 -0
  34. gitview-0.7.1/gitview/commands/storyline/list.py +149 -0
  35. gitview-0.7.1/gitview/commands/storyline/report.py +75 -0
  36. gitview-0.7.1/gitview/commands/storyline/show.py +70 -0
  37. gitview-0.7.1/gitview/commands/storyline/timeline.py +55 -0
  38. gitview-0.7.1/gitview/commands/track_files.py +211 -0
  39. gitview-0.7.1/gitview/commands/worklog.py +377 -0
  40. gitview-0.7.1/gitview/evidence.py +627 -0
  41. {gitview-0.1.3 → gitview-0.7.1}/gitview/extractor.py +218 -71
  42. gitview-0.7.1/gitview/file_ai_summarizer.py +379 -0
  43. gitview-0.7.1/gitview/file_tracker.py +731 -0
  44. gitview-0.7.1/gitview/github_enricher.py +502 -0
  45. gitview-0.7.1/gitview/github_graphql.py +979 -0
  46. gitview-0.7.1/gitview/graph/__init__.py +36 -0
  47. gitview-0.7.1/gitview/graph/analysis/__init__.py +5 -0
  48. gitview-0.7.1/gitview/graph/analysis/stats.py +22 -0
  49. gitview-0.7.1/gitview/graph/builder.py +72 -0
  50. gitview-0.7.1/gitview/graph/models.py +109 -0
  51. gitview-0.7.1/gitview/graph/projections/__init__.py +5 -0
  52. gitview-0.7.1/gitview/graph/projections/file_cochange.py +62 -0
  53. gitview-0.7.1/gitview/graph/store.py +618 -0
  54. gitview-0.7.1/gitview/graph/updater.py +140 -0
  55. gitview-0.7.1/gitview/hierarchical_storyteller.py +183 -0
  56. gitview-0.7.1/gitview/hierarchical_summarizer.py +285 -0
  57. gitview-0.7.1/gitview/history_cache.py +117 -0
  58. gitview-0.7.1/gitview/history_injector.py +436 -0
  59. gitview-0.7.1/gitview/motifs/__init__.py +15 -0
  60. gitview-0.7.1/gitview/motifs/base.py +32 -0
  61. gitview-0.7.1/gitview/motifs/engine.py +58 -0
  62. gitview-0.7.1/gitview/motifs/historical.py +73 -0
  63. gitview-0.7.1/gitview/motifs/models.py +164 -0
  64. gitview-0.7.1/gitview/motifs/structural.py +204 -0
  65. {gitview-0.1.3 → gitview-0.7.1}/gitview/remote.py +96 -6
  66. gitview-0.7.1/gitview/significance_analyzer.py +282 -0
  67. gitview-0.7.1/gitview/storyline/__init__.py +56 -0
  68. gitview-0.7.1/gitview/storyline/detector.py +881 -0
  69. gitview-0.7.1/gitview/storyline/extractor.py +259 -0
  70. gitview-0.7.1/gitview/storyline/models.py +468 -0
  71. gitview-0.7.1/gitview/storyline/parser.py +384 -0
  72. gitview-0.7.1/gitview/storyline/reporter.py +439 -0
  73. gitview-0.7.1/gitview/storyline/state_machine.py +235 -0
  74. gitview-0.7.1/gitview/storyline/tracker.py +497 -0
  75. {gitview-0.1.3 → gitview-0.7.1}/gitview/storyteller.py +385 -62
  76. gitview-0.7.1/gitview/structural/__init__.py +36 -0
  77. gitview-0.7.1/gitview/structural/graphify.py +284 -0
  78. gitview-0.7.1/gitview/structural/models.py +123 -0
  79. gitview-0.7.1/gitview/structural/observe.py +58 -0
  80. gitview-0.7.1/gitview/structural/provider.py +73 -0
  81. gitview-0.7.1/gitview/summarizer.py +639 -0
  82. {gitview-0.1.3 → gitview-0.7.1}/gitview/writer.py +104 -5
  83. gitview-0.7.1/gitview.egg-info/PKG-INFO +1355 -0
  84. gitview-0.7.1/gitview.egg-info/SOURCES.txt +118 -0
  85. {gitview-0.1.3 → gitview-0.7.1}/pyproject.toml +4 -1
  86. {gitview-0.1.3 → gitview-0.7.1}/setup.py +7 -1
  87. gitview-0.7.1/tests/test_adaptive_agent.py +474 -0
  88. gitview-0.7.1/tests/test_analyze_preflight.py +18 -0
  89. gitview-0.7.1/tests/test_anthropic_backend.py +100 -0
  90. gitview-0.7.1/tests/test_backends.py +94 -0
  91. gitview-0.7.1/tests/test_brief.py +444 -0
  92. gitview-0.7.1/tests/test_commit_record.py +146 -0
  93. gitview-0.7.1/tests/test_cost_estimate.py +28 -0
  94. gitview-0.7.1/tests/test_evidence.py +347 -0
  95. gitview-0.7.1/tests/test_extraction_counting.py +92 -0
  96. gitview-0.7.1/tests/test_github_enricher.py +344 -0
  97. gitview-0.7.1/tests/test_github_graphql.py +439 -0
  98. gitview-0.7.1/tests/test_graph.py +337 -0
  99. gitview-0.7.1/tests/test_motifs.py +262 -0
  100. gitview-0.7.1/tests/test_phase_cache.py +22 -0
  101. gitview-0.7.1/tests/test_story_cache.py +24 -0
  102. gitview-0.7.1/tests/test_storyline.py +709 -0
  103. gitview-0.7.1/tests/test_structural.py +338 -0
  104. {gitview-0.1.3 → gitview-0.7.1}/verify_installation.py +20 -19
  105. gitview-0.1.3/PKG-INFO +0 -616
  106. gitview-0.1.3/README.md +0 -572
  107. gitview-0.1.3/gitview/backends/anthropic_backend.py +0 -66
  108. gitview-0.1.3/gitview/cli.py +0 -1209
  109. gitview-0.1.3/gitview/summarizer.py +0 -325
  110. gitview-0.1.3/gitview.egg-info/PKG-INFO +0 -616
  111. gitview-0.1.3/gitview.egg-info/SOURCES.txt +0 -33
  112. {gitview-0.1.3 → gitview-0.7.1}/INSTALL.md +0 -0
  113. {gitview-0.1.3 → gitview-0.7.1}/LICENSE +0 -0
  114. {gitview-0.1.3 → gitview-0.7.1}/MANIFEST.in +0 -0
  115. {gitview-0.1.3 → gitview-0.7.1}/bin/gitview +0 -0
  116. {gitview-0.1.3 → gitview-0.7.1}/gitview/backends/base.py +0 -0
  117. {gitview-0.1.3 → gitview-0.7.1}/gitview/backends/ollama_backend.py +0 -0
  118. {gitview-0.1.3 → gitview-0.7.1}/gitview/backends/openai_backend.py +0 -0
  119. {gitview-0.1.3 → gitview-0.7.1}/gitview/branches.py +0 -0
  120. {gitview-0.1.3 → gitview-0.7.1}/gitview/index_writer.py +0 -0
  121. {gitview-0.1.3 → gitview-0.7.1}/gitview.egg-info/dependency_links.txt +0 -0
  122. {gitview-0.1.3 → gitview-0.7.1}/gitview.egg-info/entry_points.txt +0 -0
  123. {gitview-0.1.3 → gitview-0.7.1}/gitview.egg-info/not-zip-safe +0 -0
  124. {gitview-0.1.3 → gitview-0.7.1}/gitview.egg-info/requires.txt +0 -0
  125. {gitview-0.1.3 → gitview-0.7.1}/gitview.egg-info/top_level.txt +0 -0
  126. {gitview-0.1.3 → gitview-0.7.1}/requirements.txt +0 -0
  127. {gitview-0.1.3 → gitview-0.7.1}/setup.cfg +0 -0
gitview-0.7.1/PKG-INFO ADDED
@@ -0,0 +1,1355 @@
1
+ Metadata-Version: 2.4
2
+ Name: gitview
3
+ Version: 0.7.1
4
+ Summary: Git history analyzer with LLM-powered narrative generation
5
+ Home-page: https://github.com/carstenbund/gitview
6
+ Author: GitView Contributors
7
+ Author-email:
8
+ Maintainer: GitView Contributors
9
+ License: MIT
10
+ Project-URL: Homepage, https://github.com/carstenbund/gitview
11
+ Project-URL: Documentation, https://github.com/carstenbund/gitview/blob/main/README.md
12
+ Project-URL: Repository, https://github.com/carstenbund/gitview
13
+ Project-URL: Issues, https://github.com/carstenbund/gitview/issues
14
+ Keywords: git,history,analyzer,llm,narrative,ai,claude,openai,ollama
15
+ Classifier: Development Status :: 3 - Alpha
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Intended Audience :: Information Technology
18
+ Classifier: Topic :: Software Development :: Version Control :: Git
19
+ Classifier: Topic :: Software Development :: Documentation
20
+ Classifier: Topic :: Text Processing :: Markup :: Markdown
21
+ Classifier: License :: OSI Approved :: MIT License
22
+ Classifier: Programming Language :: Python :: 3
23
+ Classifier: Programming Language :: Python :: 3.8
24
+ Classifier: Programming Language :: Python :: 3.9
25
+ Classifier: Programming Language :: Python :: 3.10
26
+ Classifier: Programming Language :: Python :: 3.11
27
+ Classifier: Programming Language :: Python :: 3.12
28
+ Classifier: Operating System :: OS Independent
29
+ Classifier: Environment :: Console
30
+ Requires-Python: >=3.8
31
+ Description-Content-Type: text/markdown
32
+ License-File: LICENSE
33
+ Requires-Dist: anthropic>=0.39.0
34
+ Requires-Dist: openai>=1.0.0
35
+ Requires-Dist: requests>=2.31.0
36
+ Requires-Dist: gitpython>=3.1.40
37
+ Requires-Dist: python-dateutil>=2.8.2
38
+ Requires-Dist: click>=8.1.7
39
+ Requires-Dist: rich>=13.7.0
40
+ Requires-Dist: pydantic>=2.5.0
41
+ Dynamic: home-page
42
+ Dynamic: license-file
43
+ Dynamic: requires-python
44
+
45
+ # GitView
46
+
47
+ [![Github-CI][github-ci]][github-link]
48
+ [![Coverage Status][codecov-badge]][codecov-link]
49
+ [![PyPI][pypi-badge]][pypi-link]
50
+ [![PyPI - Downloads][install-badge]][install-link]
51
+
52
+
53
+ **Git history analyzer with LLM-powered narrative generation**
54
+
55
+ GitView extracts your repository's git history and uses AI to generate compelling narratives about how your codebase evolved. Instead of manually reading through thousands of commits, get a comprehensive story of your project's journey.
56
+
57
+ Example run on this repository:
58
+
59
+ [[(https://github.com/carstenbund/gitview/blob/main/output/history_story.md)]
60
+ ](https://github.com/carstenbund/gitview/blob/main/output/history_story.md)
61
+
62
+ ## Features
63
+
64
+ - **Comprehensive History Extraction**: Extracts commit metadata, LOC changes, language breakdown, README evolution, comment analysis, and more
65
+ - **GitHub PR/Review Enrichment**: Optionally enrich commits with Pull Request context, review comments, and collaboration data via GitHub's GraphQL API
66
+ - **Smart Chunking**: Automatically divides history into meaningful "phases" or "epochs" based on significant changes
67
+ - **LLM-Powered Summaries**: Uses Claude to generate narrative summaries for each phase
68
+ - **Global Story Generation**: Combines phase summaries into executive summaries, timelines, technical retrospectives, and deletion stories
69
+ - **Storyline Tracking**: Track narrative threads (features, refactoring efforts, bug campaigns) across phases with automatic detection and lifecycle management
70
+ - **Agent Brief**: Compile a compact, no-LLM project history digest (`gitview brief`) meant to be committed and read once per session — a token-efficient substitute for an AI coding agent re-deriving project history from scratch
71
+ - **Repository Graph**: Build a persistent, incremental SQLite graph of commits, files, authors, PRs and file co-change coupling (`gitview graph`) — deterministic structure that later stages interpret instead of rediscovering
72
+ - **Structural Evidence & Motifs**: Optionally store what an external code analyser (Graphify first) sees at a commit, then detect recurring motifs — hidden coupling, emerging dependencies, centrality growth — by combining history with structure (`gitview observe`, `gitview motifs`). Fully usable with no analyser installed
73
+ - **Evidence-First Analysis**: The graph and motifs are built before any model call, so routine phases are written from repository evidence, two report sections need no model at all, and every prompt that is sent carries established facts (`--llm-budget`)
74
+ - **Four LLM Backends**: Anthropic, OpenAI, Ollama, and a logged-in local Claude Code CLI (`--backend claude-cli`, billed to the Claude plan, no API key)
75
+ - **Multiple Output Formats**: Generates markdown reports, JSON data, and timelines
76
+ - **Critical Examination Mode**: Objective assessment focused on gaps, technical debt, and alignment with project goals (perfect for project leads)
77
+
78
+ ## Commands
79
+
80
+ | Command | What it does | LLM |
81
+ |---|---|---|
82
+ | `analyze` | Full pipeline: extract, chunk, summarize, narrate, write the report | yes |
83
+ | `brief` | Compact project history digest for an AI agent to read once per session | no |
84
+ | `graph` | Build or update the persistent repository graph (`.gitview/graph.sqlite`) | no |
85
+ | `observe` | Store a structural observation from an external code analyser | no |
86
+ | `motifs` | Detect recurring historical and architectural motifs | no |
87
+ | `extract` | Extract git history to JSONL | no |
88
+ | `chunk` | Chunk an extracted history into phases | no |
89
+ | `storyline` | Inspect storylines tracked across phases | no |
90
+ | `worklog` | Work log from GitHub commits across branches, for a date range | no |
91
+ | `track-files` | Per-file change history, optionally with AI summaries | optional |
92
+ | `file-history` | Show the change history of one file | no |
93
+ | `inject-history` / `remove-history` | Write that history into file headers, or remove it | no |
94
+ | `compare-branches` | Compare file histories between two branches | no |
95
+
96
+ Run `gitview <command> --help` for the options of each.
97
+
98
+ ## Installation
99
+
100
+ ### Option 1: Install from PyPI (recommended)
101
+
102
+ Install the published package directly from PyPI to add the `gitview` command to your PATH:
103
+
104
+ ```bash
105
+ pip3 install gitview
106
+
107
+ # Confirm the CLI is available
108
+ gitview --version
109
+ gitview --help
110
+ ```
111
+
112
+ ### Option 2: Install from source (editable)
113
+
114
+ This installs directly from the repository in editable mode so local changes take effect immediately:
115
+
116
+ ```bash
117
+ # Clone the repository
118
+ git clone https://github.com/yourusername/gitview.git
119
+ cd gitview
120
+
121
+ # Install in editable mode with dependencies
122
+ pip install -e .
123
+
124
+ # The gitview command is now available system-wide
125
+ gitview --version
126
+ gitview --help
127
+ ```
128
+
129
+ **How it works:** The `pip install -e .` command reads `pyproject.toml` and `setup.py`, which define an entry point that creates `/usr/local/bin/gitview` (or similar on Windows) that calls `gitview.cli:main`.
130
+
131
+ ### Option 3: Run directly from repo (no installation)
132
+
133
+ Use the executable wrapper in `bin/`:
134
+
135
+ ```bash
136
+ # Clone the repository
137
+ git clone https://github.com/yourusername/gitview.git
138
+ cd gitview
139
+
140
+ # Install dependencies only
141
+ pip install -r requirements.txt
142
+
143
+ # Run directly from the repo
144
+ ./bin/gitview --version
145
+ ./bin/gitview analyze
146
+
147
+ # Or add bin/ to your PATH
148
+ export PATH="$PWD/bin:$PATH"
149
+ gitview analyze
150
+ ```
151
+
152
+ ### Option 4: Run as Python module
153
+
154
+ ```bash
155
+ # Install dependencies
156
+ pip install -r requirements.txt
157
+
158
+ # Run as a module
159
+ python -m gitview.cli --help
160
+ python -m gitview.cli analyze
161
+ ```
162
+
163
+ ### Verify Installation
164
+
165
+ Run the verification script to check everything is set up correctly:
166
+
167
+ ```bash
168
+ python verify_installation.py
169
+ ```
170
+
171
+ This will check:
172
+ - Python version (3.8+ required)
173
+ - All required dependencies
174
+ - `gitview` command availability
175
+ - LLM backend configuration (API keys, Ollama server)
176
+
177
+ ### Troubleshooting Installation
178
+
179
+ If `gitview` command is not found after installation:
180
+
181
+ ```bash
182
+ # Option 1: Use full path to module
183
+ python -m gitview.cli analyze
184
+
185
+ # Option 2: Reinstall in editable mode
186
+ pip uninstall gitview -y
187
+ pip install -e .
188
+
189
+ # Option 3: Check if it's in your PATH
190
+ which gitview # Unix/Linux/Mac
191
+ where gitview # Windows
192
+ ```
193
+
194
+ ## Quick Start
195
+
196
+ ```bash
197
+ # Using Anthropic Claude (default)
198
+ export ANTHROPIC_API_KEY="your-api-key-here"
199
+ gitview analyze
200
+
201
+ # Using OpenAI GPT
202
+ export OPENAI_API_KEY="your-api-key-here"
203
+ gitview analyze --backend openai
204
+
205
+ # Using local Ollama (no API key needed)
206
+ gitview analyze --backend ollama --model llama3
207
+
208
+ # With GitHub PR/review enrichment (richer narratives!)
209
+ export GITHUB_TOKEN="ghp_your_token_here"
210
+ gitview analyze --repo owner/repo --github-token $GITHUB_TOKEN
211
+
212
+ # Critical examination mode (for project leads)
213
+ gitview analyze --critical --todo GOALS.md
214
+
215
+ # Skip LLM summarization (just extract and chunk)
216
+ gitview analyze --skip-llm
217
+ ```
218
+
219
+ ## Usage
220
+
221
+ ### Full Analysis Pipeline
222
+
223
+ The main command runs the complete pipeline: extract → chunk → summarize → story → output
224
+
225
+ ```bash
226
+ gitview analyze [OPTIONS]
227
+
228
+ Options:
229
+ -r, --repo PATH Path to git repository (default: current directory)
230
+ -o, --output PATH Output directory (default: "output")
231
+ -s, --strategy STRATEGY Chunking strategy: fixed, time, or adaptive (default: adaptive)
232
+ --chunk-size INTEGER Chunk size for fixed strategy (default: 50)
233
+ --max-commits INTEGER Maximum commits to analyze
234
+ --branch TEXT Branch to analyze (default: HEAD)
235
+ -b, --backend BACKEND LLM backend: anthropic, openai, or ollama (auto-detected)
236
+ -m, --model TEXT Model identifier (uses backend defaults if not specified)
237
+ --api-key TEXT API key for the backend (defaults to env var)
238
+ --ollama-url TEXT Ollama API URL (default: http://localhost:11434)
239
+ --repo-name TEXT Repository name for output
240
+ --skip-llm Skip LLM summarization (extract and chunk only)
241
+ --todo PATH Path to goals/todo file for critical examination mode
242
+ --critical Enable critical examination mode (focus on gaps and issues)
243
+ --directives TEXT Additional plain text directives for LLM analysis
244
+ --github-token TEXT GitHub token for PR/review enrichment (or GITHUB_TOKEN env var)
245
+ ```
246
+
247
+ ### Extract Only
248
+
249
+ Extract git history to JSONL file without LLM processing:
250
+
251
+ ```bash
252
+ gitview extract --repo /path/to/repo --output history.jsonl
253
+ ```
254
+
255
+ ### Chunk Only
256
+
257
+ Chunk an extracted JSONL file into phases:
258
+
259
+ ```bash
260
+ gitview chunk history.jsonl --output ./phases --strategy adaptive
261
+ ```
262
+
263
+ ### Agent Brief (No LLM)
264
+
265
+ Compile a compact, agent-oriented history digest — commit stats, a phase
266
+ timeline, and detected storylines — into a single markdown file. Unlike
267
+ `analyze`, this never calls an LLM: it's meant to be generated once (and
268
+ regenerated cheaply after a batch of new commits) and then just read, so an
269
+ AI coding agent doesn't have to re-derive project history from `git log`
270
+ and file exploration at the start of every session.
271
+
272
+ ```bash
273
+ # Write ./AGENT_BRIEF.md (skips automatically if HEAD hasn't moved)
274
+ gitview brief
275
+
276
+ # Always regenerate, even if already up to date
277
+ gitview brief --force
278
+
279
+ # Check freshness only (exit 1 if stale); doesn't write anything
280
+ gitview brief --check
281
+
282
+ # Custom output path
283
+ gitview brief -o docs/BRIEF.md
284
+
285
+ # Build/update the persistent repository graph (no LLM)
286
+ gitview graph # Build or update .gitview/graph.sqlite, print counts
287
+ gitview graph --stats # Also list most changed / most coupled / most connected files
288
+ gitview graph --rebuild # Drop and rebuild from scratch
289
+ gitview graph --json # Machine-readable output
290
+ ```
291
+
292
+ ### Evidence-First Analysis (Fewer LLM Calls)
293
+
294
+ `gitview analyze` builds the repository graph and runs the motif catalogue
295
+ *before* it talks to a model, then spends model calls only where the evidence
296
+ says a narrative is worth it:
297
+
298
+ | `--llm-budget` | Phase summaries | Story sections |
299
+ |----------------|-----------------|----------------|
300
+ | `full` | every phase goes to the model, with an evidence block in the prompt | 3 model calls; technical evolution and deletions are rendered from evidence |
301
+ | `balanced` (default) | routine phases (docs churn, small config runs, no motifs, no PR narrative) are written from evidence; the rest go to the model | 3 model calls |
302
+ | `minimal` | only phases with strong signals (significant commits, motifs, PR narratives) go to the model | 3 model calls |
303
+
304
+ A phase's signal score adds up: a significant commit (an addition or deletion
305
+ over 1,000 lines, or a refactor with real churn) 0.35; a motif *event* landing
306
+ in the phase (ownership handover, a dependency first appearing, a split, a
307
+ centrality jump) 0.20; PR narratives 0.15; two or more kinds of activity 0.15;
308
+ a large phase (15+ commits or 3,000+ changed lines) 0.10. Standing patterns
309
+ such as repeated co-change or a stable interface are shown to the model as
310
+ context but never trigger a call on their own. `balanced` narrates at 0.35,
311
+ `minimal` at 0.6.
312
+
313
+ Every story prompt (executive summary, timeline, full narrative) ends with a
314
+ block of hard facts taken from git — the exact date span, the complete list of
315
+ contributors, submodules from `.gitmodules`, top-level directories, most
316
+ changed files and version strings seen in commit subjects — followed by rules:
317
+ nothing after the last commit, no technologies that are not in the facts or
318
+ the summaries, plans are not implementations. Long histories are split into
319
+ batches that are stitched chronologically; the former merge call, which saw
320
+ only prose and invented the connecting tissue, is gone.
321
+
322
+ Line counts follow git's own arithmetic: merge commits carry no churn (the
323
+ merged branch's commits are already counted, as with `git log --numstat`) and
324
+ renames are detected, so a moved file is not a deletion plus an insertion.
325
+ Caches carry an extraction version; history extracted by an older GitView is
326
+ re-extracted automatically, and `gitview graph` rebuilds once.
327
+
328
+ With `--hierarchical`, per-cluster mini-summaries come from evidence too, so a
329
+ narrated phase costs one call instead of one per cluster plus one. The report
330
+ gains an *Architectural Motifs* section, every prompt that is sent carries the
331
+ established facts (clusters, hot files, coupling, motifs), and the run ends
332
+ with `LLM calls this run: N`. `--no-evidence` restores the previous behaviour.
333
+
334
+ ### Structural Evidence & Motifs (No LLM)
335
+
336
+ GitView's graph is built from git history alone. A *structural provider* — an
337
+ external code analyser — can add the present shape of the code (which file
338
+ imports, calls or inherits from which) at one commit. GitView translates that
339
+ into its own neutral model (`StructuralSnapshot`, `StructuralNode`,
340
+ `StructuralEdge`) and stores it in `.gitview/graph.sqlite` with provenance:
341
+ provider, provider version, the commit it observed and a hash of the raw
342
+ output. Nothing in GitView's core names the analyser; Graphify is simply the
343
+ first implementation of the `StructuralProvider` seam.
344
+
345
+ ```bash
346
+ gitview observe --structural graphify # store graphify-out/graph.json as an observation
347
+ gitview observe --structural graphify --refresh # let GitView run `graphify update` first
348
+ gitview graph --structural graphify # build the graph and observe in one go
349
+ gitview motifs # detect motifs
350
+ gitview motifs --list # motif catalog with evidence requirements
351
+ gitview motifs --only hidden_coupling --json
352
+ ```
353
+
354
+ Motifs declare the evidence they need and are skipped, with the reason, when it
355
+ is missing — so `gitview motifs` always works, just with fewer motifs:
356
+
357
+ | Evidence | Motifs |
358
+ |----------|--------|
359
+ | History only | repeated co-change, ownership transition |
360
+ | History + one observation | hidden coupling, confirmed coupling, stable interface |
361
+ | History + observations at two or more commits | emerging dependency, architectural split, centrality growth |
362
+
363
+ In a multi-repository layout (git submodules), build Graphify once at the
364
+ superproject root; `gitview observe` run inside a module finds that graph on
365
+ its own and re-bases it under the module's path, so each module's history is
366
+ matched against the structure of the whole system. Edges into other modules
367
+ are dropped (they have no counterpart in this module's history), and the
368
+ observation records the module's own commit.
369
+
370
+ Observe again after significant work (or from an older commit via `--source`)
371
+ to enable the series motifs; GitView orders observations by their commit's
372
+ position in the history graph and reports, for example, how many commits of
373
+ co-change preceded a dependency becoming explicit in the source.
374
+ ```
375
+
376
+ Commit the result so future sessions (yours or an agent's) can read it
377
+ instead of re-analyzing the repository. `--repo` accepts a local path only
378
+ (unlike `analyze`/`worklog`, which also accept GitHub shortcuts/URLs).
379
+
380
+ ### Work Log (GitHub, No LLM)
381
+
382
+ Generate a chronological work log from GitHub commit history across **all**
383
+ branches — useful for billing, timesheets, and status reports. `worklog`
384
+ queries GitHub's GraphQL API, deduplicates commits by SHA (a commit merged to
385
+ multiple branches is counted once), resolves the best associated Pull Request
386
+ for each commit, and renders the result as Markdown (default) or CSV. Like
387
+ `brief`, it never calls an LLM.
388
+
389
+ ```bash
390
+ # Markdown work log for a date range (writes an auto-named file)
391
+ gitview worklog --repo org/repo --since 2024-01-01 --until 2024-01-31
392
+
393
+ # Current directory (auto-detects the GitHub remote)
394
+ gitview worklog --repo . --since 2024-01-01 --until 2024-01-31
395
+
396
+ # Filter by a GitHub login and export CSV to a specific file
397
+ gitview worklog --repo . --since 2024-01-01 --until 2024-01-31 \
398
+ --author octocat --format csv -o jan.csv
399
+
400
+ # Pipe to stdout (auto-detected when output is not a terminal)
401
+ gitview worklog --repo org/repo --since 2024-01-01 --until 2024-01-31 | less
402
+ ```
403
+
404
+ **Options:**
405
+
406
+ ```
407
+ -r, --repo TEXT Repository: local path, GitHub shortcut (org/repo), or full URL (default: .)
408
+ --since TEXT Start date: YYYY-MM-DD or ISO-8601 timestamp (required)
409
+ --until TEXT End date: YYYY-MM-DD or ISO-8601 timestamp, inclusive (required)
410
+ --author TEXT Filter commits by GitHub login (optional)
411
+ --format [markdown|csv] Output format (default: markdown)
412
+ -o, --output PATH Output file path (default: auto-named in current directory)
413
+ --github-token TEXT GitHub token (defaults to GITHUB_TOKEN env var)
414
+ ```
415
+
416
+ **Notes:**
417
+ - A GitHub token with at least `repo` read scope is required — pass
418
+ `--github-token` or set `GITHUB_TOKEN`.
419
+ - Dates accept both `YYYY-MM-DD` and full ISO-8601 timestamps. `--since`
420
+ defaults to `00:00:00` UTC and `--until` to `23:59:59` UTC.
421
+ - When output is redirected (not a terminal), the log is printed to stdout so
422
+ it can be piped; otherwise it is written to an auto-named file such as
423
+ `worklog_org_repo_2024-01-01_2024-01-31.md`.
424
+
425
+ ## File History Tracking & Header Injection
426
+
427
+ GitView provides powerful file-level change tracking with AI-powered summaries and the ability to inject change histories directly into source files as header comments. This is ideal for deep code analysis, debugging, accountability, and understanding individual file evolution.
428
+
429
+ ### Features
430
+
431
+ - **Per-File Change Tracking**: Track detailed change history for every file in your repository
432
+ - **AI-Powered Summaries**: Generate intelligent summaries of changes using LLMs (with caching for cost optimization)
433
+ - **Multi-Language Header Injection**: Inject history as comments into source files (18+ languages supported)
434
+ - **Branch Comparison**: Compare file histories between branches with divergence analysis
435
+ - **Incremental Processing**: Checkpoint-based system only processes new commits
436
+ - **Cost Optimization**: 99.9% cost reduction through hash-based caching
437
+
438
+ ### Quick Start - File Tracking
439
+
440
+ ```bash
441
+ # Track all file changes in your repository
442
+ gitview track-files
443
+
444
+ # Track with AI-powered summaries
445
+ gitview track-files --with-ai
446
+
447
+ # View history for a specific file
448
+ gitview file-history gitview/cli.py
449
+
450
+ # Inject history as header comment into a file
451
+ gitview inject-history gitview/cli.py
452
+
453
+ # Remove injected header
454
+ gitview remove-history gitview/cli.py
455
+
456
+ # Compare file histories between branches
457
+ gitview compare-branches main feature-branch
458
+ ```
459
+
460
+ ### Phase 1: Core File Tracking
461
+
462
+ Track detailed change history for every file in your repository with incremental processing.
463
+
464
+ ```bash
465
+ # Basic file tracking
466
+ gitview track-files
467
+
468
+ # Track specific file patterns
469
+ gitview track-files --pattern "*.py"
470
+
471
+ # Limit commits per file
472
+ gitview track-files --max-commits 50
473
+ ```
474
+
475
+ **Output Structure:**
476
+ ```
477
+ output/file_histories/
478
+ ├── checkpoint.json # Resume tracking from last processed commit
479
+ ├── files/
480
+ │ ├── gitview_cli.py.history # Human-readable history
481
+ │ └── gitview_cli.py.json # Machine-readable JSON
482
+ └── index.json # Index of all tracked files
483
+ ```
484
+
485
+ **File History Content:**
486
+ - Commit-by-commit changes with full metadata
487
+ - Lines added/removed per change
488
+ - Author information and timestamps
489
+ - Diff snippets for each change
490
+ - AI summaries (if enabled)
491
+
492
+ ### Phase 2: AI-Powered Summaries
493
+
494
+ Generate intelligent summaries of file changes using LLMs with cost optimization.
495
+
496
+ ```bash
497
+ # Track with AI summaries (uses caching)
498
+ gitview track-files --with-ai
499
+
500
+ # Cost estimate before running
501
+ gitview track-files --with-ai --dry-run
502
+ ```
503
+
504
+ **Supported LLM Backends:**
505
+ - **Anthropic Claude** (claude-sonnet-5, claude-haiku-4-5)
506
+ - **Claude Code CLI** (a logged-in local `claude`, billed to the plan)
507
+ - **OpenAI GPT** (gpt-4o, gpt-4o-mini)
508
+ - **Ollama** (llama3, mistral, codellama - runs locally, free)
509
+
510
+ **Cost Optimization:**
511
+ - Hash-based caching prevents duplicate summaries
512
+ - Incremental processing only analyzes new commits
513
+ - Cache hit rate typically >95% on reruns
514
+ - Estimated cost: $0.10-0.50 per 1000 files (using gpt-4o-mini)
515
+
516
+ **Cache Location:**
517
+ ```
518
+ output/file_histories/summaries_cache.json
519
+ ```
520
+
521
+ **Example AI Summary:**
522
+ ```
523
+ Modified FileHistoryTracker.get_file_history() to support incremental
524
+ processing with checkpoint system. Added since_commit parameter to
525
+ iter_commits() to only process new commits after last checkpoint.
526
+ Breaking change: requires checkpoint.json for resume functionality.
527
+ ```
528
+
529
+ ### Phase 3: Header Injection
530
+
531
+ Inject file change histories as header comments into source files for debugging and accountability.
532
+
533
+ ```bash
534
+ # Inject history into a Python file
535
+ gitview inject-history gitview/file_tracker.py
536
+
537
+ # Inject with limited entries
538
+ gitview inject-history gitview/file_tracker.py --max-entries 5
539
+
540
+ # Preview without writing (dry-run)
541
+ gitview inject-history gitview/file_tracker.py --dry-run
542
+
543
+ # Inject into multiple files
544
+ gitview inject-history gitview/*.py
545
+
546
+ # Remove injected headers
547
+ gitview remove-history gitview/file_tracker.py
548
+ ```
549
+
550
+ **Supported Languages (18+):**
551
+ - Python, JavaScript, TypeScript, Java, Go, Rust, C/C++, C#
552
+ - Ruby, PHP, Swift, Kotlin, Scala, Shell, SQL, R, Perl, Lua, YAML
553
+
554
+ **Header Format Example (Python):**
555
+ ```python
556
+ # ==============================================================================
557
+ # FILE CHANGE HISTORY
558
+ # ==============================================================================
559
+ # File: gitview/file_tracker.py
560
+ # Total changes: 15 commits
561
+ # Authors: John Doe (10), Jane Smith (5)
562
+ #
563
+ # [Recent Changes - Last 10 of 15]
564
+ #
565
+ # 2026-01-22 | abc123f | John Doe
566
+ # Add incremental checkpoint system for resumable tracking
567
+ # Changes: +45 -12 lines
568
+ #
569
+ # Summary: Implemented checkpoint-based resume functionality...
570
+ #
571
+ # 2026-01-20 | def456a | Jane Smith
572
+ # Fix diff parsing for binary files
573
+ # Changes: +8 -3 lines
574
+ #
575
+ # ==============================================================================
576
+ # END FILE CHANGE HISTORY
577
+ # ==============================================================================
578
+
579
+ # Your actual code starts here...
580
+ ```
581
+
582
+ **Use Cases:**
583
+ - Add accountability headers to critical files
584
+ - Include change context in code reviews
585
+ - Debug issues by understanding file evolution
586
+ - Onboarding - new developers see file history inline
587
+ - Compliance and audit trails
588
+
589
+ ### Phase 4: Branch Comparison
590
+
591
+ Compare file histories between branches with divergence analysis and AI-powered comparison.
592
+
593
+ ```bash
594
+ # Compare two branches
595
+ gitview compare-branches main feature-branch
596
+
597
+ # Compare with AI analysis of divergences
598
+ gitview compare-branches main feature-branch --with-ai
599
+
600
+ # Custom output location
601
+ gitview compare-branches main dev --output ./branch-analysis
602
+ ```
603
+
604
+ **Output Structure:**
605
+ ```
606
+ output/branch_comparisons/
607
+ ├── branches/
608
+ │ ├── main/
609
+ │ │ ├── files/
610
+ │ │ │ ├── gitview_cli.py.json
611
+ │ │ │ └── gitview_tracker.py.json
612
+ │ │ └── branch_metadata.json
613
+ │ └── feature_branch/
614
+ │ ├── files/
615
+ │ └── branch_metadata.json
616
+ └── comparisons/
617
+ └── main_vs_feature_branch/
618
+ ├── summary.json
619
+ ├── divergences.json
620
+ ├── report.txt
621
+ └── ai_analysis.json (if --with-ai used)
622
+ ```
623
+
624
+ **Divergence Analysis:**
625
+ - Files unique to each branch
626
+ - Commits that diverged between branches
627
+ - Line change differences
628
+ - Divergence score (0-100) for each file
629
+
630
+ **Example Report:**
631
+ ```
632
+ Branch Comparison: main vs feature-branch
633
+ ==========================================
634
+
635
+ Summary:
636
+ Files in main: 45
637
+ Files in feature-branch: 47
638
+ Files in both: 43
639
+ Files only in main: 2
640
+ Files only in feature-branch: 4
641
+
642
+ Top Divergent Files (score 0-100):
643
+ 1. gitview/file_tracker.py Score: 87.5
644
+ - 12 commits only in main
645
+ - 8 commits only in feature-branch
646
+ - +234 -156 lines difference
647
+
648
+ 2. gitview/cli.py Score: 65.3
649
+ - 5 commits only in main
650
+ - 3 commits only in feature-branch
651
+ - +89 -45 lines difference
652
+ ```
653
+
654
+ **AI Analysis (with --with-ai):**
655
+ - Semantic comparison of divergent changes
656
+ - Identifies conflicting implementations
657
+ - Suggests merge strategies
658
+ - Highlights breaking changes
659
+
660
+ ### Complete Workflow Example
661
+
662
+ ```bash
663
+ # 1. Initial file tracking with AI summaries
664
+ gitview track-files --with-ai
665
+
666
+ # 2. View history for a specific file
667
+ gitview file-history gitview/file_tracker.py
668
+
669
+ # 3. Inject history into critical files
670
+ gitview inject-history gitview/file_tracker.py gitview/cli.py
671
+
672
+ # 4. Switch to feature branch and track
673
+ git checkout feature-branch
674
+ gitview track-files --with-ai
675
+
676
+ # 5. Compare branches
677
+ gitview compare-branches main feature-branch --with-ai
678
+
679
+ # 6. Review divergences and make decisions
680
+ cat output/branch_comparisons/comparisons/main_vs_feature_branch/report.txt
681
+
682
+ # 7. After merge, update file histories
683
+ git checkout main
684
+ git merge feature-branch
685
+ gitview track-files --with-ai
686
+
687
+ # 8. Update injected headers
688
+ gitview inject-history gitview/file_tracker.py
689
+ ```
690
+
691
+ ### Configuration
692
+
693
+ File tracking uses the same LLM backend configuration as the main analysis:
694
+
695
+ ```bash
696
+ # Use Anthropic Claude (default)
697
+ export ANTHROPIC_API_KEY="your-key"
698
+ gitview track-files --with-ai
699
+
700
+ # Use OpenAI GPT
701
+ export OPENAI_API_KEY="your-key"
702
+ gitview track-files --with-ai --backend openai --model gpt-4o-mini
703
+
704
+ # Use Ollama (local, free)
705
+ ollama serve
706
+ gitview track-files --with-ai --backend ollama --model llama3
707
+ ```
708
+
709
+ ### Performance & Costs
710
+
711
+ **Incremental Processing:**
712
+ - First run: Processes entire git history
713
+ - Subsequent runs: Only processes new commits since last checkpoint
714
+ - 10,000 commit repo: ~5 minutes first run, ~10 seconds for updates
715
+
716
+ **AI Summary Costs (estimated):**
717
+ - 1,000 files with gpt-4o-mini: ~$0.15-0.30
718
+ - 1,000 files with claude-haiku: ~$0.40-0.80
719
+ - 1,000 files with Ollama: $0 (local)
720
+ - Cache hit rate >95% on reruns = virtually free
721
+
722
+ **Storage:**
723
+ - Each file history: ~5-50KB depending on commit count
724
+ - AI cache: ~1KB per cached summary
725
+ - 1,000 files: ~50-100MB total
726
+
727
+ ## Critical Examination Mode
728
+
729
+ For project leads who need objective assessment rather than celebratory narratives, GitView offers a critical examination mode that focuses on gaps, technical debt, and alignment with project goals.
730
+
731
+ ### What Changes in Critical Mode?
732
+
733
+ **Tone & Focus:**
734
+ - Removes flowery, achievement-focused language
735
+ - Emphasizes objective assessment over celebration
736
+ - Focuses on gaps, issues, and misalignments
737
+ - Identifies what's missing or incomplete
738
+
739
+ **Analysis:**
740
+ - Evaluates progress against stated objectives
741
+ - Highlights incomplete features and technical debt
742
+ - Questions architectural decisions objectively
743
+ - Identifies delays and resource misalignment
744
+ - Notes concerning patterns and risks
745
+
746
+ ### Usage
747
+
748
+ **Basic Critical Mode:**
749
+ ```bash
750
+ gitview analyze --critical
751
+ ```
752
+
753
+ **With Project Goals/TODO File:**
754
+ ```bash
755
+ # Create a goals file (e.g., GOALS.md)
756
+ cat > GOALS.md <<EOF
757
+ # Project Goals Q1 2025
758
+ - Implement user authentication system
759
+ - Add API rate limiting
760
+ - Improve test coverage to 80%
761
+ - Migrate from SQLite to PostgreSQL
762
+ - Complete API documentation
763
+ EOF
764
+
765
+ # Analyze against goals
766
+ gitview analyze --critical --todo GOALS.md
767
+ ```
768
+
769
+ **With Custom Directives:**
770
+ ```bash
771
+ # Add specific analysis focus
772
+ gitview analyze --critical \
773
+ --todo GOALS.md \
774
+ --directives "Focus on security vulnerabilities and performance bottlenecks"
775
+ ```
776
+
777
+ **Combined Example:**
778
+ ```bash
779
+ # Critical assessment with all options
780
+ gitview analyze \
781
+ --critical \
782
+ --todo PROJECT_ROADMAP.md \
783
+ --directives "Emphasize testing gaps and code quality issues" \
784
+ --output ./critical-review
785
+ ```
786
+
787
+ ### Output in Critical Mode
788
+
789
+ The LLM will generate:
790
+
791
+ 1. **Critical Executive Summary** - Assesses progress against goals, identifies gaps and delays
792
+ 2. **Critical Timeline** - Highlights goal alignment/misalignment per phase
793
+ 3. **Critical Technical Assessment** - Identifies architectural flaws and technical debt
794
+ 4. **Critical Deletion Analysis** - Notes incomplete cleanup and lingering technical debt
795
+ 5. **Comprehensive Critical Assessment** - Full project review with actionable insights
796
+
797
+ ### When to Use Critical Mode
798
+
799
+ - **Project Reviews**: Objective assessment of development progress
800
+ - **Technical Audits**: Identify technical debt and architectural issues
801
+ - **Goal Alignment**: Measure actual work against stated objectives
802
+ - **Resource Planning**: Understand where effort was spent vs. planned
803
+ - **Risk Assessment**: Identify concerning patterns and project risks
804
+ - **Leadership Reports**: Provide factual assessment to stakeholders
805
+
806
+ ## Storyline Tracking
807
+
808
+ GitView tracks "storylines" - narrative threads that span multiple phases of development. Instead of just seeing isolated phase summaries, you can follow the arc of features, refactoring efforts, bug fix campaigns, and other initiatives across your project's history.
809
+
810
+ ### What Are Storylines?
811
+
812
+ Storylines are development threads that GitView automatically detects and tracks:
813
+
814
+ - **Features**: New functionality being built across multiple phases
815
+ - **Refactoring**: Code cleanup and restructuring efforts
816
+ - **Bug Fixes**: Bug fix campaigns and stability improvements
817
+ - **Tech Debt**: Debt reduction initiatives
818
+ - **Infrastructure**: CI/CD, tooling, and deployment improvements
819
+ - **Documentation**: Documentation efforts
820
+ - **Migrations**: Database or framework migrations
821
+ - **Performance**: Performance optimization work
822
+ - **Security**: Security hardening initiatives
823
+
824
+ ### Multi-Signal Detection
825
+
826
+ Storylines are detected from multiple sources with confidence scoring:
827
+
828
+ | Source | Confidence | Description |
829
+ |--------|------------|-------------|
830
+ | PR Labels | 0.9 | GitHub PR labels (feature, bug, refactor) |
831
+ | PR Title Patterns | 0.8 | Patterns like "feat:", "fix:", "[WIP]" |
832
+ | File Clusters | 0.7 | Related files changing together |
833
+ | Commit Messages | 0.6 | Conventional commit patterns |
834
+ | LLM Extraction | 0.5 | AI-detected storylines from summaries |
835
+
836
+ ### Storyline Lifecycle
837
+
838
+ Storylines progress through states automatically:
839
+
840
+ ```
841
+ EMERGING → ACTIVE → PROGRESSING → COMPLETED
842
+ ↘ STALLED → ABANDONED
843
+ ```
844
+
845
+ - **Emerging**: New storyline detected, building confidence
846
+ - **Active**: Confirmed storyline with ongoing work
847
+ - **Progressing**: Active work continues phase-over-phase
848
+ - **Completed**: Storyline reached completion (explicit or inferred)
849
+ - **Stalled**: No activity for 3+ phases
850
+ - **Abandoned**: Stalled for 6+ phases
851
+
852
+ ### CLI Commands
853
+
854
+ GitView provides a `storyline` command group for exploring tracked storylines:
855
+
856
+ ```bash
857
+ # List all storylines
858
+ gitview storyline list
859
+
860
+ # Filter by status
861
+ gitview storyline list --status active
862
+ gitview storyline list --status completed
863
+
864
+ # Filter by category
865
+ gitview storyline list --category feature
866
+ gitview storyline list --category refactor
867
+
868
+ # Show details for a specific storyline
869
+ gitview storyline show <storyline-id>
870
+ gitview storyline show oauth-impl # partial ID match works
871
+
872
+ # Generate comprehensive report
873
+ gitview storyline report
874
+ gitview storyline report --save storyline-report.md
875
+
876
+ # View ASCII timeline visualization
877
+ gitview storyline timeline
878
+
879
+ # Export to JSON or CSV
880
+ gitview storyline export --format json
881
+ gitview storyline export --format csv --dest storylines.csv
882
+ ```
883
+
884
+ ### Example Output
885
+
886
+ **Storyline List:**
887
+ ```
888
+ ┌────────┬──────────────────────────┬────────────┬────────┬──────┬──────────────┐
889
+ │ Status │ Title │ Category │ Phases │ Conf │ ID │
890
+ ├────────┼──────────────────────────┼────────────┼────────┼──────┼──────────────┤
891
+ │ ✓ │ OAuth Implementation │ feature │ 1→3 │ 90% │ oauth-impl.. │
892
+ │ ● │ API Rate Limiting │ feature │ 2→4 │ 85% │ api-rate-l.. │
893
+ │ ▶ │ Test Coverage Expansion │ tech_debt │ 3→4 │ 75% │ test-cover.. │
894
+ │ ◌ │ Legacy Migration │ migration │ 1→2 │ 70% │ legacy-mig.. │
895
+ └────────┴──────────────────────────┴────────────┴────────┴──────┴──────────────┘
896
+ ```
897
+
898
+ **ASCII Timeline:**
899
+ ```
900
+ Storyline 1 2 3 4 5
901
+ ────────────────────────────────────────────────────────
902
+ OAuth Implementation ┌────┘
903
+ API Rate Limiting ┌────→
904
+ Test Coverage Expansion ┌──→
905
+ Legacy Migration ┌──╳
906
+
907
+ Legend: ┌─ start, ─┘ completed, ─→ ongoing, ─╳ stalled
908
+ ```
909
+
910
+ ### Output in Reports
911
+
912
+ When you run `gitview analyze`, storylines are automatically:
913
+
914
+ 1. **Detected** from commits, PRs, and file patterns
915
+ 2. **Tracked** across phases with state transitions
916
+ 3. **Included** in the main `history_story.md` report
917
+ 4. **Persisted** to `output/phases/storylines.json` for incremental analysis
918
+
919
+ The storyline section in your report includes:
920
+ - Summary of completed, active, and stalled storylines
921
+ - Timeline visualization
922
+ - Cross-phase theme analysis
923
+ - Category breakdown
924
+
925
+ ### Persistence & Incremental Analysis
926
+
927
+ Storyline data is persisted to `output/phases/storylines.json`, enabling:
928
+
929
+ - **Incremental updates**: New phases add to existing storyline data
930
+ - **State continuity**: Storyline states persist across runs
931
+ - **Export capabilities**: Use the data in other tools
932
+
933
+ ## GitHub Enrichment (PR & Review Context)
934
+
935
+ GitView can enrich commit history with Pull Request context from GitHub's GraphQL API, providing richer narratives based on actual PR descriptions and review feedback rather than just commit messages.
936
+
937
+ ### What GitHub Enrichment Provides
938
+
939
+ - **PR Titles & Descriptions**: Use the "why" from PR descriptions instead of terse commit messages
940
+ - **Review Comments**: Include reviewer feedback and discussion context
941
+ - **Reviewer Attribution**: Track who reviewed and approved changes
942
+ - **PR Labels**: Categorize work by type (feature, bug, refactor, etc.)
943
+ - **Branch Information**: Understand feature branch to main branch flow
944
+
945
+ ### Getting Started
946
+
947
+ 1. **Generate a GitHub Token**:
948
+ - Go to https://github.com/settings/tokens
949
+ - Create "Personal access token (classic)"
950
+ - Select `repo` scope for private repos (or `public_repo` for public only)
951
+ - Copy the token
952
+
953
+ 2. **Use with GitView**:
954
+
955
+ ```bash
956
+ # Set as environment variable
957
+ export GITHUB_TOKEN="ghp_your_token_here"
958
+ gitview analyze --repo owner/repo --github-token $GITHUB_TOKEN
959
+
960
+ # Or pass directly
961
+ gitview analyze --repo owner/repo --github-token "ghp_your_token_here"
962
+ ```
963
+
964
+ ### Example with GitHub Enrichment
965
+
966
+ ```bash
967
+ # Analyze a GitHub repository with PR context
968
+ export GITHUB_TOKEN="ghp_..."
969
+ gitview analyze \
970
+ --repo carstenbund/gitview \
971
+ --github-token $GITHUB_TOKEN \
972
+ --output ./enriched-analysis
973
+
974
+ # The resulting narratives will include:
975
+ # - PR descriptions explaining WHY changes were made
976
+ # - Review feedback providing context on design decisions
977
+ # - Labels helping categorize types of work
978
+ ```
979
+
980
+ ### How It Improves Narratives
981
+
982
+ **Without GitHub Enrichment:**
983
+ > "Commit abc123: Fix bug in login flow"
984
+
985
+ **With GitHub Enrichment:**
986
+ > "PR #42 'Fix authentication race condition' addressed a critical issue where users could be logged out during token refresh. The fix was reviewed by @alice who suggested the retry mechanism that was ultimately implemented. Labels: [bug, security, priority-high]"
987
+
988
+ ### Caching
989
+
990
+ GitHub API responses are cached locally in `~/.gitview/cache/github` for 24 hours to:
991
+ - Reduce API calls on repeated runs
992
+ - Improve performance for large repositories
993
+ - Stay within GitHub's rate limits
994
+
995
+ ### Rate Limits
996
+
997
+ GitHub GraphQL API has a points-based rate limit (5,000 points/hour). GitView:
998
+ - Uses efficient batched queries
999
+ - Caches responses to minimize API calls
1000
+ - Gracefully falls back if rate limited
1001
+
1002
+ ## Chunking Strategies
1003
+
1004
+ GitView supports three chunking strategies:
1005
+
1006
+ ### 1. **Adaptive** (Recommended)
1007
+
1008
+ Automatically splits history when significant changes occur:
1009
+ - LOC changes by >30%
1010
+ - Large deletions/additions detected
1011
+ - README rewrites
1012
+ - Major refactorings
1013
+
1014
+ ```bash
1015
+ gitview analyze --strategy adaptive
1016
+ ```
1017
+
1018
+ ### 2. **Fixed Size**
1019
+
1020
+ Splits history into fixed-size chunks (e.g., 50 commits per phase):
1021
+
1022
+ ```bash
1023
+ gitview analyze --strategy fixed --chunk-size 50
1024
+ ```
1025
+
1026
+ ### 3. **Time-Based**
1027
+
1028
+ Splits by time periods (week, month, quarter, year):
1029
+
1030
+ ```bash
1031
+ gitview analyze --strategy time --period quarter
1032
+ ```
1033
+
1034
+ ## Output Files
1035
+
1036
+ GitView generates several output files:
1037
+
1038
+ ```
1039
+ output/
1040
+ ├── repo_history.jsonl # Raw commit data
1041
+ ├── phases/ # Phase data
1042
+ │ ├── phase_01.json
1043
+ │ ├── phase_02.json
1044
+ │ ├── phase_index.json
1045
+ │ └── storylines.json # Storyline tracking data
1046
+ ├── history_story.md # Main narrative report
1047
+ ├── timeline.md # Simple timeline
1048
+ └── history_data.json # Complete data in JSON
1049
+ ```
1050
+
1051
+ ### Main Report (`history_story.md`)
1052
+
1053
+ Contains:
1054
+ - **Executive Summary**: High-level overview for stakeholders
1055
+ - **Timeline**: Chronological phases with descriptive headings
1056
+ - **Full Narrative**: Complete story of the codebase evolution
1057
+ - **Technical Evolution**: Architectural journey and key decisions
1058
+ - **Story of Deletions**: What was removed and why
1059
+ - **Storylines**: Cross-phase narrative threads with timeline visualization
1060
+ - **Phase Details**: Detailed breakdown of each phase
1061
+ - **Statistics**: Comprehensive metrics
1062
+
1063
+ ## How It Works
1064
+
1065
+ ### Phase 1: Extract Raw History
1066
+
1067
+ Analyzes git commits and extracts:
1068
+ - Commit metadata (hash, author, date, message)
1069
+ - Lines of code changes (insertions/deletions)
1070
+ - File statistics
1071
+ - Language breakdown
1072
+ - README state and changes
1073
+ - Code comments and density
1074
+ - Detection of large changes, refactors, etc.
1075
+
1076
+ ### Phase 2: Chunk into Epochs
1077
+
1078
+ Divides history into meaningful phases based on:
1079
+ - Significant LOC changes
1080
+ - Large deletions or additions
1081
+ - Language mix changes
1082
+ - README rewrites
1083
+ - Major refactorings
1084
+
1085
+ ### Phase 3: Summarize Each Phase
1086
+
1087
+ Uses Claude to generate narrative summaries for each phase, answering:
1088
+ - What were the main activities?
1089
+ - Why were changes made?
1090
+ - What was deleted/added and why?
1091
+ - How did documentation evolve?
1092
+ - What do commit messages reveal?
1093
+
1094
+ ### Phase 4: Generate Global Story
1095
+
1096
+ Combines phase summaries to create:
1097
+ - Executive summary for non-technical readers
1098
+ - Chronological timeline with meaningful headings
1099
+ - Technical retrospective
1100
+ - Story of code deletions and cleanups
1101
+ - Full detailed narrative
1102
+
1103
+ ## Examples
1104
+
1105
+ ### Analyze a Large Open Source Project
1106
+
1107
+ ```bash
1108
+ gitview analyze \
1109
+ --repo /path/to/large-project \
1110
+ --output ./project-analysis \
1111
+ --strategy adaptive \
1112
+ --repo-name "My Project"
1113
+ ```
1114
+
1115
+ ### Quick Analysis Without LLM
1116
+
1117
+ Perfect for quick exploration or when you don't have an API key:
1118
+
1119
+ ```bash
1120
+ gitview analyze --skip-llm --output ./quick-analysis
1121
+ ```
1122
+
1123
+ ### Extract and Process Later
1124
+
1125
+ ```bash
1126
+ # Extract once
1127
+ gitview extract --repo /path/to/repo --output history.jsonl
1128
+
1129
+ # Experiment with different chunking strategies
1130
+ gitview chunk history.jsonl --strategy adaptive --output ./adaptive-phases
1131
+ gitview chunk history.jsonl --strategy fixed --chunk-size 25 --output ./fixed-phases
1132
+ ```
1133
+
1134
+ ### Critical Project Assessment
1135
+
1136
+ ```bash
1137
+ # Create a goals file for your project
1138
+ cat > PROJECT_GOALS.md <<EOF
1139
+ # Q1 2025 Objectives
1140
+ - Complete user authentication with OAuth2
1141
+ - Implement API rate limiting (1000 req/hour)
1142
+ - Achieve 80% test coverage
1143
+ - Migrate database to PostgreSQL
1144
+ - Document all public APIs
1145
+ EOF
1146
+
1147
+ # Run critical analysis
1148
+ gitview analyze \
1149
+ --critical \
1150
+ --todo PROJECT_GOALS.md \
1151
+ --directives "Focus on security issues and incomplete features" \
1152
+ --output ./project-review-q1
1153
+
1154
+ # Review the critical assessment
1155
+ cat ./project-review-q1/history_story.md
1156
+ ```
1157
+
1158
+ ## Architecture
1159
+
1160
+ ```
1161
+ ┌─────────────────────┐
1162
+ │ Git Repository │
1163
+ └──────────┬──────────┘
1164
+
1165
+ v
1166
+ ┌─────────────────────┐
1167
+ │ Extractor │ Analyzes commits, extracts metadata
1168
+ │ (extractor.py) │ Output: repo_history.jsonl
1169
+ └──────────┬──────────┘
1170
+
1171
+ v
1172
+ ┌─────────────────────┐
1173
+ │ Chunker │ Splits into meaningful phases
1174
+ │ (chunker.py) │ Strategies: adaptive, fixed, time
1175
+ └──────────┬──────────┘
1176
+
1177
+ v
1178
+ ┌─────────────────────┐ ┌─────────────────────┐
1179
+ │ Evidence Ledger │<────│ Repository Graph │ commits, files, authors,
1180
+ │ (evidence.py) │ │ (graph/) │ PRs, co-change coupling
1181
+ │ Decides which │ └──────────┬──────────┘
1182
+ │ phases need a │ │
1183
+ │ model call, and │ ┌──────────v──────────┐ ┌──────────────────┐
1184
+ │ supplies the facts │<────│ Motifs │<────│ Structural │
1185
+ │ every prompt gets │ │ (motifs/) │ │ (structural/) │
1186
+ └──────────┬──────────┘ └─────────────────────┘ │ optional, via a │
1187
+ │ │ provider seam │
1188
+ │ └──────────────────┘
1189
+ v
1190
+ ┌─────────────────────┐ ┌─────────────────────┐
1191
+ │ Summarizer │────>│ Storyline Tracker │
1192
+ │ (summarizer.py) │ │ (storyline/) │
1193
+ └──────────┬──────────┘ │ Multi-signal │
1194
+ │ │ detection & state │
1195
+ v │ machine lifecycle │
1196
+ ┌─────────────────────┐ └──────────┬──────────┘
1197
+ │ StoryTeller │<───────────────┘
1198
+ │ (storyteller.py) │ Generates global narratives
1199
+ └──────────┬──────────┘ with storyline context
1200
+
1201
+ v
1202
+ ┌─────────────────────┐
1203
+ │ Writer │ Outputs markdown, JSON, etc.
1204
+ │ (writer.py) │ Includes storyline reports
1205
+ └─────────────────────┘
1206
+ ```
1207
+
1208
+ ## Requirements
1209
+
1210
+ - Python 3.8+
1211
+ - Git repository with commit history
1212
+ - **One of the following LLM backends** (not needed for `brief`, `graph`, `observe`, `motifs`, `extract`, `chunk`, `worklog`):
1213
+ - **Anthropic Claude** (requires API key)
1214
+ - **Claude Code CLI** (a logged-in local `claude`; billed to the Claude plan, no API key)
1215
+ - **OpenAI GPT** (requires API key)
1216
+ - **Ollama** (runs locally, no API key needed)
1217
+ - Optional: a structural analyser such as [Graphify](https://github.com/carstenbund/graphify) for structural motifs
1218
+ - Dependencies: gitpython, anthropic, openai, requests, click, rich, pydantic
1219
+
1220
+ ## LLM Backend Configuration
1221
+
1222
+ GitView supports four LLM backends. Without `--backend`, it picks the first available:
1223
+ `ANTHROPIC_API_KEY`, then `OPENAI_API_KEY`, then a logged-in `claude` CLI, then Ollama.
1224
+
1225
+ ### Anthropic Claude (Default)
1226
+
1227
+ Get an API key from [Anthropic](https://www.anthropic.com/)
1228
+
1229
+ ```bash
1230
+ export ANTHROPIC_API_KEY="your-api-key-here"
1231
+ gitview analyze
1232
+ ```
1233
+
1234
+ Default model: `claude-sonnet-5`. Pass `--model` for another, for example
1235
+ `claude-opus-5` (more capable) or `claude-haiku-4-5` (cheaper).
1236
+
1237
+ ### Claude Code CLI
1238
+
1239
+ Runs generation through a locally installed, logged-in `claude` (Claude Code)
1240
+ in print mode, so a Claude plan covers the usage and no `ANTHROPIC_API_KEY` is
1241
+ needed.
1242
+
1243
+ ```bash
1244
+ claude /login # once
1245
+ gitview analyze --backend claude-cli
1246
+ ```
1247
+
1248
+ The model is a CLI alias (`sonnet` by default, `--model opus` for another).
1249
+ No transcript is written, and `max_tokens` and `temperature` have no CLI
1250
+ equivalent, so they are ignored.
1251
+
1252
+ ### OpenAI GPT
1253
+
1254
+ Get an API key from [OpenAI](https://platform.openai.com/)
1255
+
1256
+ ```bash
1257
+ export OPENAI_API_KEY="your-api-key-here"
1258
+ gitview analyze --backend openai
1259
+ ```
1260
+
1261
+ Default model: `gpt-4o-mini`. Pass `--model gpt-4o` for a stronger one.
1262
+
1263
+ ### Ollama (Local)
1264
+
1265
+ Install [Ollama](https://ollama.ai/) and pull a model:
1266
+
1267
+ ```bash
1268
+ # Install Ollama
1269
+ curl -fsSL https://ollama.ai/install.sh | sh
1270
+
1271
+ # Pull a model
1272
+ ollama pull llama3
1273
+
1274
+ # Start Ollama server
1275
+ ollama serve
1276
+
1277
+ # Use with GitView (no API key needed)
1278
+ gitview analyze --backend ollama --model llama3
1279
+ ```
1280
+
1281
+ Popular Ollama models:
1282
+ - `llama3` (default, balanced)
1283
+ - `mistral` (fast, good quality)
1284
+ - `codellama` (optimized for code)
1285
+ - `mixtral` (large, powerful)
1286
+
1287
+ ### Custom Configuration
1288
+
1289
+ ```bash
1290
+ # Specify custom model
1291
+ gitview analyze --backend anthropic --model claude-opus-5
1292
+
1293
+ # Use custom Ollama URL
1294
+ gitview analyze --backend ollama --ollama-url http://192.168.1.100:11434
1295
+
1296
+ # Pass API key directly (instead of env var)
1297
+ gitview analyze --backend openai --api-key "your-key"
1298
+ ```
1299
+
1300
+ ## Use Cases
1301
+
1302
+ ### Standard Mode (Celebratory Narrative)
1303
+ - **Technical Documentation**: Automatically generate project history documentation
1304
+ - **Onboarding**: Help new developers understand codebase evolution
1305
+ - **Retrospectives**: Review what worked and what didn't
1306
+ - **Project Reports**: Create compelling narratives for stakeholders
1307
+ - **Code Archaeology**: Understand why code evolved the way it did
1308
+ - **Cleanup Planning**: Identify what to remove based on deletion history
1309
+
1310
+ ### Critical Examination Mode
1311
+ - **Project Leadership**: Objective assessment for project leads and managers
1312
+ - **Technical Audits**: Identify technical debt and architectural issues
1313
+ - **Goal Tracking**: Measure actual progress against roadmap objectives
1314
+ - **Resource Analysis**: Understand where development effort was spent
1315
+ - **Risk Management**: Identify concerning patterns and project risks
1316
+ - **Stakeholder Reports**: Provide factual, critical assessment to executives
1317
+
1318
+ ### Storyline Tracking
1319
+ - **Feature Tracking**: Follow features from inception to completion across phases
1320
+ - **Refactoring Visibility**: Track long-running refactoring efforts and their progress
1321
+ - **Stalled Work Detection**: Identify initiatives that have stalled or been abandoned
1322
+ - **Cross-Phase Analysis**: Understand how work threads connect across time
1323
+ - **Project Health**: See the balance of active, completed, and stalled storylines
1324
+ - **Timeline Visualization**: ASCII timeline showing storyline arcs
1325
+
1326
+ ### File Tracking & Header Injection
1327
+ - **Deep Code Analysis**: Inject complete change history into files for debugging complex issues
1328
+ - **Compliance & Accountability**: Track who changed what and when with inline headers
1329
+ - **Code Reviews**: Include file evolution context directly in reviewed files
1330
+ - **Developer Onboarding**: New team members see file history without leaving their editor
1331
+ - **Branch Divergence Analysis**: Identify conflicts before merging feature branches
1332
+ - **Refactoring Decisions**: Understand file evolution patterns to guide architecture changes
1333
+ - **Bug Investigation**: Trace file changes to identify when bugs were introduced
1334
+ - **Technical Debt Tracking**: Compare branch histories to assess divergence costs
1335
+ - **Documentation**: Generate per-file change logs for critical components
1336
+ - **AI-Powered Insights**: Get intelligent summaries of complex code changes
1337
+
1338
+ ## Contributing
1339
+
1340
+ Contributions welcome! Please open an issue or submit a pull request.
1341
+
1342
+ ## License
1343
+
1344
+ MIT License - see LICENSE file for details
1345
+
1346
+
1347
+
1348
+ [github-ci]: https://github.com/carstenbund/gitview/actions/workflows/test.yml/badge.svg?branch=main
1349
+ [github-link]: https://github.com/carstenbund/gitview
1350
+ [pypi-badge]: https://img.shields.io/pypi/v/gitview.svg
1351
+ [pypi-link]: https://pypi.org/project/gitview
1352
+ [codecov-badge]: https://codecov.io/gh/carstenbund/gitview/branch/master/graph/badge.svg
1353
+ [codecov-link]: https://codecov.io/gh/carstenbund/gitview
1354
+ [install-badge]: https://img.shields.io/pypi/dw/gitview?label=pypi%20installs
1355
+ [install-link]: https://pypistats.org/packages/gitview