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
Git URL Detection
Checked before isRemoteUrl — HTTPS .git URLs would otherwise match remote URL 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 |
| Git repo URL | No | Yes | Clone repo, install from clone |
| Git repo URL | Yes | No | ERROR: Cannot combine git with --offline |
| Local path | No | Yes | Use local source |
| Local path | Yes | Yes | Use local source (offline mode) |
Git Clone Process
When the source is a Git URL:
- Parse ref — split
url#refinto repo URL and optional branch/tag - Inject token — if
PAIR_GIT_TOKENis set and URL is HTTPS, rewrite URL with token - Shallow clone —
git clone --depth 1 [--branch ref] <url> <tempDir> - Install from clone — copy dataset from temp dir to
~/.pair/kb/{version}/ - Cleanup — remove temp clone directory
Auth strategy:
- Default: git inherits system auth (SSH keys, credential manager,
gh auth) - Override:
PAIR_GIT_TOKENenv var injects token into HTTPS URLs
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 |
| E008 | Git clone failed | 2 | Clone error (auth, network, missing git) | Check git config, set PAIR_GIT_TOKEN, or use SSH |
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_GIT_TOKEN | Token injected into HTTPS git clone URLs for private repos | Not set |
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