Skip to content

Commit 9bebb9a

Browse files
authored
Merge pull request #12 from costiash/fix/auto-update-big
fix: resolve auto-update self-destruction bug and remove unused hook
2 parents b59976f + 729ee84 commit 9bebb9a

File tree

14 files changed

+901
-143
lines changed

14 files changed

+901
-143
lines changed

CHANGELOG.md

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,45 @@ All notable changes to the enhanced edition of claude-code-docs will be document
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.4.2] - 2025-11-25
9+
10+
### Fixed
11+
- **Critical Auto-Update Bug**: Fixed issue where `/docs -t` would destroy the installation directory
12+
- Root cause: Running `install.sh` from within `~/.claude-code-docs` caused the script to delete its own working directory
13+
- Solution: Replaced full reinstall with lightweight script sync after `git pull`
14+
- **Template Fallback**: Enhanced helper now gracefully degrades if template is missing instead of failing completely
15+
- **Security: Path Traversal Protection**: Added realpath validation in fallback mode to ensure files stay within docs directory
16+
- Input sanitization removes special characters (already existed)
17+
- New: Resolved path validation ensures no escape from docs directory
18+
- **Silent Failure Logging**: sync_helper_script() now logs failures to stderr for debugging
19+
- Previously errors were silently suppressed with `|| true`
20+
- Now provides feedback when copy or move operations fail
21+
22+
### Removed
23+
- **Useless Hook**: Removed the PreToolUse hook that did nothing (just `exit 0`)
24+
- The hook fired on every Read tool use but provided no functionality
25+
- Updates now happen on-demand via `/docs -t` command
26+
27+
### Added
28+
- **Post-Installation Verification**: Installer now validates all critical components after installation
29+
- Checks helper script, template, docs directory, and command file
30+
- Reports issues instead of silently failing
31+
- **Lock File Mechanism**: Added lock file to prevent concurrent update operations
32+
- Prevents race conditions when multiple `/docs` commands run simultaneously
33+
- Automatically cleans up stale locks (older than 60 seconds)
34+
- **Integration Tests**: Added 9 new tests for critical bug fix scenarios (627 tests total)
35+
- Tests for sync_helper_script() atomic copy behavior
36+
- Tests verifying update doesn't delete working directory
37+
- Tests for template fallback functionality
38+
- Tests for lock file mechanism
39+
- Tests for path traversal protection
40+
41+
### Changed
42+
- **Documentation Accuracy**: Updated README and installer messages to clarify update behavior
43+
- Removed misleading "Auto-updates: Enabled" claims
44+
- Clarified that updates are on-demand via `/docs -t`
45+
- **Test Suite**: Updated from 618 to 627 passing tests (78.7% coverage maintained)
46+
847
## [0.4.1] - 2025-11-24
948

1049
### Fixed
@@ -76,9 +115,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
76115
- Full macOS compatibility
77116
- Linux support (Ubuntu, Debian, Fedora)
78117
- Improved installer
79-
- Automatic documentation updates via GitHub Actions
118+
- Documentation updates via GitHub Actions (repository-side)
80119
- `/docs` slash command integration
81-
- PreToolUse Read hook for automatic updates
82120

83121
---
84122

CONTRIBUTING.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ pip install -e ".[dev]"
125125
~/.claude-code-docs/claude-docs-helper.sh --validate
126126
127127
# Run tests (REQUIRED before submitting PR)
128-
pytest tests/ -v # Should see: 598 passed, 2 skipped
129-
pytest --cov=scripts --cov-report=term # Should see: ~78%
128+
pytest tests/ -v # Should see: 627 passed, 2 skipped
129+
pytest --cov=scripts --cov-report=term # Should see: ~78.7%
130130
131131
# Test specific changes
132132
python scripts/lookup_paths.py "your test query"
@@ -137,7 +137,7 @@ python scripts/fetch_claude_docs.py --help
137137
- `scripts/fetch_claude_docs.py` - Documentation fetcher with auto-regeneration
138138
- `scripts/lookup_paths.py` - Search & validation
139139
- `scripts/build_search_index.py` - Full-text search indexing
140-
- `tests/` - Test suite (600 tests)
140+
- `tests/` - Test suite (629 tests)
141141
142142
## Code Standards
143143
@@ -331,10 +331,10 @@ def test_search_paths_with_limit():
331331
```
332332

333333
**Current test status:**
334-
- Total: 600 tests
335-
- Passing: 598 (99.7%)
334+
- Total: 629 tests
335+
- Passing: 627 (99.7%)
336336
- Skipped: 2 (intentional)
337-
- Coverage: 78.32%
337+
- Coverage: 78.70%
338338

339339
## Pull Request Guidelines
340340

@@ -417,7 +417,7 @@ git push origin v0.x.x
417417

418418
**When to release:**
419419
- New Python features complete
420-
- All tests passing (600/600 or 598/600)
420+
- All tests passing (629/629 or 627/629)
421421
- Documentation updated
422422

423423
**Process:**
@@ -426,7 +426,7 @@ git push origin v0.x.x
426426
pytest
427427

428428
# Check coverage
429-
pytest --cov=scripts --cov-report=term # Should be ~78%
429+
pytest --cov=scripts --cov-report=term # Should be ~78.7%
430430

431431
# Update versions
432432
# Edit install.sh, README.md

README.md

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Claude Code Documentation Tool
22

33
[![Last Update](https://img.shields.io/github/last-commit/costiash/claude-code-docs/main.svg?label=docs%20updated)](https://github.com/costiash/claude-code-docs/commits/main)
4-
[![Tests](https://img.shields.io/badge/tests-618%20passing-success)](https://github.com/costiash/claude-code-docs/actions)
4+
[![Tests](https://img.shields.io/badge/tests-627%20passing-success)](https://github.com/costiash/claude-code-docs/actions)
55
[![Coverage](https://img.shields.io/badge/coverage-78.7%25-green)](https://github.com/costiash/claude-code-docs)
66
[![Python](https://img.shields.io/badge/python-3.9+-blue)](https://www.python.org/)
77
[![Platform](https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey)](https://github.com/costiash/claude-code-docs)
@@ -25,9 +25,20 @@ Stop hunting through scattered docs. This tool provides instant access to **273
2525
- 📚 **Complete Coverage** - 273 active documentation paths, ~266-270 files downloaded (~97% coverage)
2626
- 🔍 **Semantic Understanding** - No primitive keyword matching, leverages Claude's language understanding
2727
-**Auto-Validated** - Continuous validation detects broken links automatically
28-
- 🔄 **Always Fresh** - Auto-updates every 3 hours from official sources
28+
- 🔄 **Always Fresh** - Repository updated every 3 hours; run `/docs -t` to pull latest
2929
- 🎯 **Graceful Degradation** - Works with or without Python
30-
- 🧪 **Well-Tested** - 620 tests (618 passing, 2 skipped), 78.7% coverage
30+
- 🧪 **Well-Tested** - 629 tests (627 passing, 2 skipped), 78.7% coverage
31+
32+
## How It Works
33+
34+
This tool takes a different approach to documentation access:
35+
36+
1. **Local Mirror** - Instead of fetching docs from the web each time, we keep a local copy that's always ready
37+
2. **AI as the Interface** - You ask questions in plain English, Claude figures out which docs to read
38+
3. **Smart Routing** - The `/docs` command understands context ("hooks in agent sdk" vs "cli hooks")
39+
4. **Works Offline** - Once installed, docs are available even without internet
40+
41+
The magic is in combining a simple local file system with Claude's language understanding. No complex search engines or databases - just markdown files and AI smarts.
3142

3243
## What's Included
3344

@@ -61,7 +72,7 @@ curl -fsSL https://raw.githubusercontent.com/costiash/claude-code-docs/main/inst
6172
1. Clones repository to `~/.claude-code-docs`
6273
2. Installs 266 documentation files
6374
3. Sets up `/docs` command in Claude Code
64-
4. Enables auto-updates
75+
4. Verifies installation integrity
6576

6677
**Python features activate automatically if Python 3.9+ is installed.**
6778

@@ -198,7 +209,7 @@ For power users who want direct access to helper functions:
198209
- 273 documentation paths tracked in manifest
199210
- ~266-270 files downloaded (varies based on fetch success)
200211
- 7 Python scripts for enhanced features
201-
- Full test suite (620 tests)
212+
- Full test suite (629 tests)
202213
203214
**Graceful Degradation** - Features adapt to environment:
204215
- **Without Python**: Basic documentation reading via `/docs` command
@@ -210,8 +221,8 @@ For power users who want direct access to helper functions:
210221
211222
Documentation stays current through:
212223
213-
1. **Automated Updates** - GitHub Actions fetches new docs every 3 hours
214-
2. **Pre-Command Check** - `/docs` checks for GitHub updates automatically
224+
1. **Repository Updates** - GitHub Actions fetches new docs every 3 hours
225+
2. **On-Demand Sync** - Run `/docs -t` to check for and pull updates
215226
3. **Auto-Regeneration** - Manifests regenerate from sitemaps on each fetch
216227
4. **Visual Feedback** - See "🔄 Updating documentation..." when updates occur
217228
@@ -313,7 +324,7 @@ See [UNINSTALL.md](UNINSTALL.md) for manual removal instructions.
313324
- You can fork and install from your own repository
314325
315326
**Validation:**
316-
- 618/620 tests passing (99.7% pass rate, 2 skipped)
327+
- 627/629 tests passing (99.7% pass rate, 2 skipped)
317328
- 78.7% code coverage
318329
- Automated security testing in CI/CD
319330
@@ -338,7 +349,7 @@ source .venv/bin/activate
338349
pip install -e ".[dev]"
339350
340351
# Run tests
341-
pytest tests/ -v # Should see: 618 passed, 2 skipped
352+
pytest tests/ -v # Should see: 627 passed, 2 skipped
342353
343354
# Test coverage
344355
pytest --cov=scripts --cov-report=term # Should see: ~78.7%

UNINSTALL.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Navigate to your installation directory and run:
2626
The uninstaller will remove:
2727

2828
1. **The /docs command** from `~/.claude/commands/docs.md`
29-
2. **The auto-update hook** from `~/.claude/settings.json`
29+
2. **Any legacy hooks** from `~/.claude/settings.json` (if present from older versions)
3030
3. **The installation directory**:
3131
- v0.3+: `~/.claude-code-docs`
3232
- v0.2 or older: wherever you installed it
@@ -40,8 +40,8 @@ If you prefer to uninstall manually:
4040
rm -f ~/.claude/commands/docs.md
4141
```
4242

43-
### 2. Remove the hook from Claude settings:
44-
Use /hooks in Claude Code CLI or Edit `~/.claude/settings.json` direction to remove the PreToolUse hook that references claude-code-docs.
43+
### 2. Remove any legacy hooks from Claude settings (if present):
44+
If you installed an older version (v0.4.1 or earlier), check `~/.claude/settings.json` and remove any PreToolUse hooks that reference claude-code-docs. Current versions (v0.4.2+) do not install hooks.
4545

4646
### 3. Remove the installation directory:
4747

enhancements/CAPABILITIES.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ Searches within documentation content (not just path names):
9191
**Implementation**:
9292
- Pre-built search index: `docs/.search_index.json`
9393
- Index builder: `scripts/build_search_index.py`
94-
- Index size: ~45KB for 449 documents
94+
- Index size: ~45KB for 273 documents
9595
- Search speed: <100ms per query
9696

9797
## Validation Features
@@ -109,7 +109,7 @@ Validates HTTP reachability of all documentation paths:
109109
- **Broken link detection**: Identifies and reports unreachable paths
110110

111111
**Validation metrics**:
112-
- Average validation time: ~30 seconds for 449 paths
112+
- Average validation time: ~30 seconds for 273 paths
113113
- Concurrent requests: Configurable (default: 10)
114114
- Request timeout: 10 seconds per path
115115
- Error handling: Retries with exponential backoff
@@ -149,7 +149,7 @@ Efficiently updates only changed documentation:
149149

150150
Advanced fetching with enterprise features:
151151

152-
- **Batch fetching**: Update all 449 paths efficiently
152+
- **Batch fetching**: Update all 273 paths efficiently
153153
- **Category updates**: Update specific categories only
154154
- **Rate limiting**: 0.5s delay between requests
155155
- **Retry logic**: Exponential backoff on failures
@@ -206,7 +206,7 @@ Advanced fetching with enterprise features:
206206
{
207207
"metadata": {
208208
"generated_at": "timestamp",
209-
"total_paths": 449,
209+
"total_paths": 273,
210210
"cleaned_at": "timestamp",
211211
"removed_broken_paths": 10,
212212
"original_total_paths": 459
@@ -246,7 +246,7 @@ Enhanced features integrate seamlessly:
246246

247247
- **Path search**: ~90ms average
248248
- **Content search**: <100ms per query
249-
- **Index build**: ~2 seconds for 449 documents
249+
- **Index build**: ~2 seconds for 273 documents
250250
- **Index size**: ~45KB (minimal disk usage)
251251

252252
### Fetch Performance
@@ -258,7 +258,7 @@ Enhanced features integrate seamlessly:
258258

259259
### Validation Performance
260260

261-
- **Full validation**: ~30 seconds for 449 paths
261+
- **Full validation**: ~30 seconds for 273 paths
262262
- **Parallel requests**: 10 concurrent by default
263263
- **Success rate**: >99%
264264
- **Resource usage**: Low CPU, minimal memory

enhancements/EXAMPLES.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ The system suggests:
230230
/docs --validate
231231
```
232232

233-
Validates that all 449 documentation paths are reachable on docs.anthropic.com.
233+
Validates that all 273 documentation paths are reachable on docs.anthropic.com.
234234

235235
**Output includes**:
236-
- Total paths checked: 449
237-
- Successful: 449
236+
- Total paths checked: 273
237+
- Successful: 273
238238
- Failed: 0
239239
- Validation time: ~30s
240240

enhancements/FEATURES.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Searches across all documentation content, not just path names.
3535

3636
**Command**: `/docs --validate`
3737

38-
Validates all 449 paths are reachable on docs.anthropic.com.
38+
Validates all 273 paths are reachable on docs.anthropic.com.
3939

4040
**Features**:
4141
- HTTP reachability testing
@@ -49,7 +49,7 @@ Validates all 449 paths are reachable on docs.anthropic.com.
4949

5050
**Command**: `/docs --search 'query'`
5151

52-
Fuzzy search across all 449 paths with relevance ranking.
52+
Fuzzy search across all 273 paths with relevance ranking.
5353

5454
**Features**:
5555
- Levenshtein distance matching
@@ -76,7 +76,7 @@ Fuzzy search across all 449 paths with relevance ranking.
7676
**Script**: `scripts/main.py` (662 lines)
7777

7878
**Features**:
79-
- Batch fetching of 449 paths
79+
- Batch fetching of 273 paths
8080
- SHA256-based change detection (only fetch what changed)
8181
- Retry logic with exponential backoff
8282
- Rate limiting (0.5s between requests)
@@ -85,7 +85,7 @@ Fuzzy search across all 449 paths with relevance ranking.
8585

8686
**Usage**:
8787
```bash
88-
python scripts/main.py --update-all # Fetch all 449 docs
88+
python scripts/main.py --update-all # Fetch all 273 docs
8989
python scripts/main.py --update-category core # Update specific category
9090
python scripts/main.py --verify # Check what needs updating
9191
```
@@ -166,7 +166,7 @@ These enhancements are designed to be contributed back to upstream as optional f
166166

167167
**Proposed PRs**:
168168
1. **Optional Enhanced Mode** - Install script with Python features
169-
2. **Extended Path Coverage** - 449 paths manifest (opt-in)
169+
2. **Extended Path Coverage** - 273 paths manifest
170170
3. **Full-Text Search** - Search capability (opt-in)
171171
4. **Testing Framework** - Test suite for validation
172172
5. **Developer Documentation** - Enhanced docs
@@ -189,11 +189,11 @@ These enhancements are designed to be contributed back to upstream as optional f
189189
**Search Performance**:
190190
- Path search: ~90ms average
191191
- Content search: < 100ms per query
192-
- Index build time: ~2 seconds for 449 docs
192+
- Index build time: ~2 seconds for 273 docs
193193
- Index size: ~45KB
194194

195195
**Validation Performance**:
196-
- Full validation: ~30 seconds for 449 paths (parallel)
196+
- Full validation: ~30 seconds for 273 paths (parallel)
197197
- Configurable concurrency
198198

199199
## License

0 commit comments

Comments
 (0)