ReferenceSpecs
KB Source Resolution
Technical specification for the Knowledge Base source resolution algorithm in pair-cli.
Technical specification for the Knowledge Base (KB) source resolution algorithm in pair-cli.
Resolution Algorithm
Precedence Order
KB source is resolved in the following order (highest to lowest priority):
- CLI flag
--source <url|path>— Explicit user-provided source - Monorepo default —
packages/knowledge-hub/dataset(when running from monorepo) - GitHub release auto-download — Latest release from configured repository
Decision Tree
Source Type Detection
URL Detection
Local Path Detection
Monorepo Detection
Option Validation
Constraint: --offline + --source Combination
--source value | --offline | Valid? | Action |
|---|---|---|---|
| Not provided | No | Yes | Auto-download or use monorepo |
| Not provided | Yes | No | ERROR: --offline requires --source |
| HTTP/HTTPS URL | No | Yes | Download from URL |
| HTTP/HTTPS URL | Yes | No | ERROR: Cannot combine URL with --offline |
| Local path | No | Yes | Use local source |
| Local path | Yes | Yes | Use local source (offline mode) |
Resolution Implementation
Error Catalog
| Code | Error | Exit | Cause | Resolution |
|---|---|---|---|---|
| E001 | Offline without source | 1 | --offline without --source | Provide --source |
| E002 | Offline with remote URL | 1 | --offline with HTTP URL | Use local path |
| E003 | Source path not found | 1 | --source points to missing path | Verify path |
| E004 | Invalid source format | 1 | Source is neither URL nor path | Use valid format |
| E005 | Download network error | 2 | Network failure | Check connectivity |
| E006 | Checksum validation failed | 2 | SHA256 mismatch | Retry download |
| E007 | Auto-download in offline | 1 | No source + offline mode | Provide local source |
Download Process
When requiresDownload: true for URL sources:
- HEAD request — Fetch URL metadata
- Fetch checksum — Download
.sha256checksum file - Download KB — GET request with progress tracking
- Validate SHA256 — Verify integrity (if checksum available)
- Extract to cache — Store at
~/.pair/kb/{version}/
Cache Strategy
Cache Location: ~/.pair/kb/{version}/
Downloaded KBs are cached to avoid redundant downloads. Cache key is derived from the download URL or version string.
Configuration
Environment Variables
| Variable | Description | Default |
|---|---|---|
PAIR_KB_CACHE_DIR | Override KB cache directory | ~/.pair/kb |
PAIR_KB_DEFAULT_URL | Override default GitHub release URL | GitHub latest release |
PAIR_DIAG | Enable diagnostic logging | 0 (disabled) |
Related
- CLI Commands Reference — Complete command documentation
- CLI Contracts Spec — Command contracts and validation
- CLI Help Examples — Practical usage examples