Skip to content

Commit 028c4a8

Browse files
AI Assistantclaude
andcommitted
docs: add comprehensive Phase 2 planning and technical documentation
Phase 2 Planning (PRD & ADRs): - PRD.md (29KB): Product requirements, Phase 1 summary, Phase 2 spec - PHASE2_IMPLEMENTATION.md (58KB): 8-week roadmap, 5 phases - CONFIGURATION_SPEC.md (33KB): .cli-audit.yml schema reference - adr/README.md: ADR process and index - ADR-001: Context-aware installation (workstation/server/ci modes) - ADR-002: Package manager hierarchy (vendor→GitHub→system) - ADR-003: Parallel installation approach (keep both, PATH ordering) - ADR-004: Always-latest version policy (warn on major upgrades) - ADR-005: Environment detection logic (CI/server/workstation) - ADR-006: Configuration file format (YAML, multi-location precedence) Technical Documentation Updates: - INDEX.md: Added Phase 2 planning section, navigation updates - QUICK_REFERENCE.md: One-liners, env vars, jq queries - ARCHITECTURE.md: System design, threading model, cache hierarchy - API_REFERENCE.md: 50+ functions, environment variables - FUNCTION_REFERENCE.md: Categorized function catalog - DEVELOPER_GUIDE.md: Contributing guide, testing strategies - TOOL_ECOSYSTEM.md: 50+ tool catalog with categories - DEPLOYMENT.md: Makefile targets, CI/CD integration - TROUBLESHOOTING.md: Common issues and solutions AI Agent Context: - claudedocs/project_context.md: Quick reference for AI agents - claudedocs/session_summary.md: Session documentation and insights Total: 12 docs files (189KB), 8 ADRs (71KB), 2 AI context files (19KB) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 82662a8 commit 028c4a8

21 files changed

Lines changed: 13871 additions & 0 deletions

claudedocs/project_context.md

Lines changed: 290 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,290 @@
1+
# AI CLI Preparation - Project Context (AI Agent Reference)
2+
3+
**Last Updated:** 2025-10-09
4+
**For:** AI Coding Agents (Claude Code, etc.)
5+
6+
## Quick Reference
7+
8+
**Purpose:** Environment audit tool ensuring AI coding agents have all necessary CLI tools installed and current
9+
10+
**Repository:** github.com/netresearch/coding_agent_cli_toolset
11+
**Primary Language:** Python 3.9+ (dev: 3.14.0rc2)
12+
**Architecture:** Offline-first, parallel, resilient tool version auditing
13+
**Tool Coverage:** 50+ developer tools across 10 categories
14+
15+
## Core Capabilities
16+
17+
- Multi-source version resolution (GitHub, PyPI, crates.io, npm, GNU FTP)
18+
- Installation method detection (uv, pipx, npm, cargo, apt, homebrew, etc.)
19+
- Offline operation via committed cache (latest_versions.json)
20+
- Snapshot-based workflow (separate collection from rendering)
21+
- Parallel execution (16 workers, 3s timeout per tool)
22+
- Role-based presets (agent-core, python-core, security-core, etc.)
23+
24+
## File Structure
25+
26+
```
27+
ai_cli_preparation/
28+
├── cli_audit.py (2375 lines) # Main audit engine
29+
├── smart_column.py (222 lines) # ANSI/emoji-aware formatter
30+
├── latest_versions.json # Manual cache + hints
31+
├── tools_snapshot.json # Audit results snapshot
32+
├── Makefile # Build targets
33+
├── package.json # Claude Code dependency
34+
├── scripts/ # Installation scripts
35+
│ ├── install_core.sh
36+
│ ├── install_python.sh
37+
│ ├── install_node.sh
38+
│ ├── install_go.sh
39+
│ └── ... (9 more)
40+
├── docs/ # Human-focused technical docs
41+
│ ├── INDEX.md
42+
│ ├── ARCHITECTURE.md
43+
│ ├── API_REFERENCE.md
44+
│ ├── DEVELOPER_GUIDE.md
45+
│ ├── TOOL_ECOSYSTEM.md
46+
│ ├── DEPLOYMENT.md
47+
│ └── TROUBLESHOOTING.md
48+
└── claudedocs/ # AI agent context (this directory)
49+
```
50+
51+
## Key Components
52+
53+
### Tool Dataclass (cli_audit.py:729)
54+
```python
55+
@dataclass(frozen=True)
56+
class Tool:
57+
name: str # Display name
58+
candidates: tuple[str, ...] # Executable names
59+
source_kind: str # gh|pypi|crates|npm|gnu|skip
60+
source_args: tuple[str, ...] # Source-specific params
61+
```
62+
63+
### TOOLS Registry (cli_audit.py:738)
64+
Ordered tuple of 50+ Tool definitions, categorized:
65+
1. Runtimes (go, python, rust, node) + package managers
66+
2. Core dev tools (ripgrep, ast-grep, fzf, fd, jq, etc.)
67+
3. Security (semgrep, bandit, gitleaks, trivy)
68+
4. Formatters (black, eslint, prettier, shellcheck)
69+
5. Git tools (git, gh, glab, git-absorb)
70+
6. Cloud/infra (aws, kubectl, terraform, docker)
71+
72+
### Architecture Pattern
73+
```
74+
CLI Entry → Mode Router → Parallel Collection (ThreadPoolExecutor)
75+
↓ ↓
76+
COLLECT/RENDER/NORMAL audit_tool() × 50+
77+
78+
Local Discovery + Upstream APIs
79+
80+
Cache Layer (hints → manual → upstream)
81+
82+
Snapshot Write / Render
83+
```
84+
85+
## Common Operations
86+
87+
### Quick Audit
88+
```bash
89+
# Render from snapshot (no network, <100ms)
90+
make audit
91+
92+
# Update snapshot with fresh data (~10s)
93+
make update
94+
95+
# Interactive upgrade guide
96+
make upgrade
97+
98+
# Offline audit with hints
99+
make audit-offline
100+
```
101+
102+
### Role-Based Audits
103+
```bash
104+
make audit-offline-agent-core # AI agent essentials
105+
make audit-offline-python-core # Python development
106+
make audit-offline-security-core # Security tools
107+
```
108+
109+
### Debug Mode
110+
```bash
111+
CLI_AUDIT_DEBUG=1 python3 cli_audit.py --only ripgrep
112+
CLI_AUDIT_TRACE=1 python3 cli_audit.py
113+
```
114+
115+
## Environment Variables (Key)
116+
117+
**Mode Control:**
118+
- `CLI_AUDIT_COLLECT=1` - Collect-only (no rendering)
119+
- `CLI_AUDIT_RENDER=1` - Render-only (no network)
120+
- `CLI_AUDIT_OFFLINE=1` - Force offline (manual cache only)
121+
122+
**Performance:**
123+
- `CLI_AUDIT_MAX_WORKERS=16` - Concurrency
124+
- `CLI_AUDIT_TIMEOUT_SECONDS=3` - Per-tool timeout
125+
126+
**Output:**
127+
- `CLI_AUDIT_JSON=1` - JSON output
128+
- `CLI_AUDIT_LINKS=1` - OSC 8 hyperlinks
129+
- `CLI_AUDIT_EMOJI=1` - Emoji status icons
130+
131+
**Debug:**
132+
- `CLI_AUDIT_DEBUG=1` - Debug messages
133+
- `CLI_AUDIT_TRACE=1` - Detailed trace
134+
- `CLI_AUDIT_PROGRESS=1` - Progress output
135+
136+
## Integration Points
137+
138+
**Claude Code Dependency:** package.json includes @anthropic-ai/claude-code ^2.0.11
139+
140+
**Use Case:** Ensures Claude Code and other AI agents have access to all necessary developer tools (ripgrep for code search, ast-grep for semantic search, jq for JSON parsing, git/gh for version control, etc.)
141+
142+
**Workflow:**
143+
1. AI agent environment needs verification
144+
2. Run `make audit` to check tool availability
145+
3. If tools missing/outdated, run `make upgrade` for guided installation
146+
4. Re-audit until environment ready
147+
5. AI agent has full tooling access
148+
149+
## Cache Files
150+
151+
### latest_versions.json
152+
```json
153+
{
154+
"__hints__": {
155+
"gh:owner/repo": "latest_redirect", // API method cache
156+
"local_flag:tool": "--version" // Version flag cache
157+
},
158+
"__methods__": {
159+
"tool": "source_kind" // Override upstream source
160+
},
161+
"tool-name": "1.2.3" // Latest version cache
162+
}
163+
```
164+
165+
### tools_snapshot.json
166+
```json
167+
{
168+
"__meta__": {
169+
"schema_version": 1,
170+
"created_at": "2025-10-09T...",
171+
"count": 50
172+
},
173+
"tools": [
174+
{
175+
"tool": "ripgrep",
176+
"installed": "14.1.1 (150ms)",
177+
"installed_method": "rustup/cargo",
178+
"latest_upstream": "14.1.1 (220ms)",
179+
"upstream_method": "github",
180+
"status": "UP-TO-DATE"
181+
}
182+
]
183+
}
184+
```
185+
186+
## Current Git State
187+
188+
**Branch:** main
189+
**Modified:** cli_audit.py, latest_versions.json
190+
**Untracked:** node_modules/
191+
**Remote:** git@github.com:netresearch/coding_agent_cli_toolset.git
192+
193+
**Recent commits:**
194+
- 0c7ade3 - Snapshot-based collect/render modes
195+
- 3dd5082 - Lock ordering fixes (thread safety)
196+
- c160361 - Classification improvements (shebang detection)
197+
- 634c035 - HTTP robustness (retries, backoff)
198+
- 8c04e03 - Smoke testing
199+
200+
## Key Design Patterns
201+
202+
1. **Offline-First:** Works without network via committed cache
203+
2. **Parallel Execution:** 16 concurrent workers, 3s timeout per tool
204+
3. **Graceful Degradation:** Timeouts, retries, fallbacks at every layer
205+
4. **Immutable Data:** Frozen dataclasses, atomic file writes
206+
5. **Lock Ordering:** MANUAL_LOCK → HINTS_LOCK (enforced)
207+
6. **Cache Hierarchy:** hints → manual → upstream (fastest to slowest)
208+
209+
## Threading Model
210+
211+
- **ThreadPoolExecutor:** Parallel tool audits
212+
- **MANUAL_LOCK:** For latest_versions.json updates
213+
- **HINTS_LOCK:** For __hints__ updates (nested in MANUAL_LOCK)
214+
- **Lock Order Rule:** Always acquire MANUAL_LOCK before HINTS_LOCK
215+
216+
## Performance Characteristics
217+
218+
| Scenario | Time | Notes |
219+
|----------|------|-------|
220+
| Collection (online) | ~10s | 50 tools, 16 workers |
221+
| Collection (offline) | ~3s | Cache hits only |
222+
| Render from snapshot | <100ms | No network, pure JSON read |
223+
| Single tool audit | ~300ms | Version check + upstream |
224+
225+
## Extension Points
226+
227+
**Adding new tools:**
228+
1. Add Tool() to TOOLS registry in cli_audit.py
229+
2. Place in appropriate category
230+
3. Add to latest_versions.json for offline fallback
231+
4. Update TOOL_ECOSYSTEM.md documentation
232+
233+
**Adding new upstream sources:**
234+
1. Implement latest_<source>() function
235+
2. Update get_latest() dispatcher
236+
3. Add source_kind to Tool options
237+
238+
## Documentation Map
239+
240+
**For Humans (docs/):**
241+
- INDEX.md - Documentation navigation
242+
- ARCHITECTURE.md - System design, data flows
243+
- API_REFERENCE.md - Functions, environment variables
244+
- DEVELOPER_GUIDE.md - Contributing, adding tools
245+
- TOOL_ECOSYSTEM.md - Complete 50+ tool catalog
246+
- DEPLOYMENT.md - Makefile targets, CI/CD
247+
- TROUBLESHOOTING.md - Common issues, debugging
248+
249+
**For AI Agents (claudedocs/):**
250+
- project_context.md (this file) - Quick reference
251+
- session_summary.md - Current session state
252+
253+
## Quick Troubleshooting
254+
255+
**Network timeouts:**
256+
```bash
257+
CLI_AUDIT_TIMEOUT_SECONDS=10 python3 cli_audit.py
258+
CLI_AUDIT_HTTP_RETRIES=5 python3 cli_audit.py
259+
```
260+
261+
**GitHub rate limiting:**
262+
```bash
263+
export GITHUB_TOKEN=ghp_...
264+
python3 cli_audit.py
265+
```
266+
267+
**Version detection issues:**
268+
```bash
269+
CLI_AUDIT_DEBUG=1 python3 cli_audit.py --only tool-name
270+
```
271+
272+
**Cache corruption:**
273+
```bash
274+
rm latest_versions.json tools_snapshot.json
275+
make update
276+
```
277+
278+
## AI Agent Best Practices
279+
280+
1. **Check tool availability** before attempting to use CLI tools
281+
2. **Use offline mode** for repeated audits (faster)
282+
3. **Reference tool catalog** in TOOL_ECOSYSTEM.md for capabilities
283+
4. **Leverage parallel execution** for efficiency
284+
5. **Handle graceful failures** - tool may be unavailable
285+
286+
## See Also
287+
288+
- Main README: ../README.md (user-focused documentation)
289+
- Technical docs: ../docs/ (comprehensive developer documentation)
290+
- Installation scripts: ../scripts/ (automated tool installation)

0 commit comments

Comments
 (0)