Analyzes the codex cache and generates comprehensive statistics about cache performance, storage usage, and health status. Delegates to fractary CLI for cache analysis operations.
Analyzes codex cache performance, storage usage, and health by invoking the fractary CLI cache stats command. Used when you need to check cache hit rates, disk usage, or identify expired documents requiring cleanup.
/plugin marketplace add fractary/claude-plugins/plugin install fractary-codex@fractaryThis skill inherits all available tools. When active, it can use any tool Claude has access to.
scripts/calculate-metrics.shYour responsibility is to analyze the codex cache and generate comprehensive statistics by delegating to the cli-helper skill which invokes the fractary codex cache stats CLI command.
Architecture (v4.0):
cache-metrics skill
↓ (delegates to)
cli-helper skill
↓ (invokes)
fractary codex cache stats
↓ (uses)
@fractary/codex SDK (CacheManager)
This provides comprehensive cache metrics including performance, storage usage, and health status via the TypeScript SDK. </CONTEXT>
<CRITICAL_RULES>
Construct arguments array from inputs:
args = ["cache", "stats"]
// Add category filter if specified
if (category && category !== "all") {
args.push("--category", category)
}
// Add history flag if requested
if (include_history) {
args.push("--include-history")
}
USE SKILL: cli-helper Operation: invoke-cli Parameters:
{
"command": "cache",
"args": ["stats", ...category_filter, ...history_flag],
"parse_output": true
}
The cli-helper will:
fractary codex cache stats [--category <c>] [--include-history] --jsonThe CLI returns JSON like:
{
"status": "success",
"operation": "cache-stats",
"cache": {
"total_documents": 156,
"total_size_bytes": 47411200,
"total_size_mb": 45.2,
"fresh_documents": 142,
"expired_documents": 14,
"fresh_percentage": 91.0,
"last_cleanup": "2025-01-07T14:30:00Z",
"cache_path": ".fractary/codex/cache"
},
"performance": {
"cache_hit_rate": 94.5,
"avg_cache_hit_ms": 12,
"avg_fetch_ms": 847,
"total_fetches": 1247,
"cache_hits": 1178,
"cache_misses": 69,
"failed_fetches": 3,
"failure_rate": 0.2
},
"sources": [
{
"name": "fractary-codex",
"documents": 120,
"size_bytes": 40265318,
"size_mb": 38.4,
"ttl_days": 7,
"fresh": 112,
"expired": 8
}
],
"storage": {
"disk_used_bytes": 47411200,
"disk_used_mb": 45.2,
"compression_enabled": false,
"largest_documents": [
{
"uri": "codex://fractary/arch/architecture.md",
"size_bytes": 2516582,
"size_mb": 2.4
}
],
"growth_rate_mb_per_week": 5.0
},
"health": {
"status": "healthy",
"cache_accessible": true,
"index_valid": true,
"corrupted_entries": 0,
"disk_free_percent": 87
},
"recommendations": [
"Consider enabling compression to save disk space",
"Clear 14 expired documents: /fractary-codex:cache-clear --expired"
]
}
IF status == "success":
IF status == "failure":
IF format == "json":
IF format == "formatted" (default):
Display formatted output to user.
COMPLETION: Operation complete when metrics are shown.
</WORKFLOW><COMPLETION_CRITERIA> Operation is complete when:
✅ For successful metrics:
✅ For failed metrics:
✅ In all cases:
📊 Codex Knowledge Retrieval Metrics
═══════════════════════════════════════════════════════════
CACHE STATISTICS
───────────────────────────────────────
Total Documents: 156
Total Size: 45.2 MB
Fresh Documents: 142 (91.0%)
Expired Documents: 14 (9.0%)
Last Cleanup: 2025-01-07 14:30 UTC
Cache Path: .fractary/codex/cache
PERFORMANCE METRICS
───────────────────────────────────────
Cache Hit Rate: 94.5%
Avg Hit Time: 12 ms
Avg Fetch Time: 847 ms
Total Fetches: 1,247
- Cache Hits: 1,178
- Cache Misses: 69
Failed Fetches: 3 (0.2%)
SOURCE BREAKDOWN
───────────────────────────────────────
fractary-codex:
Documents: 120
Size: 38.4 MB
TTL: 7 days
Fresh: 112 (93.3%)
Expired: 8 (6.7%)
STORAGE USAGE
───────────────────────────────────────
Disk Used: 45.2 MB
Compression: Disabled
Growth Rate: ~5.0 MB/week
Largest Documents:
1. codex://fractary/arch/architecture.md (2.4 MB)
HEALTH STATUS
───────────────────────────────────────
Status: ✓ Healthy
Cache Accessible: Yes
Index Valid: Yes
Corrupted Entries: 0
Disk Free: 87%
═══════════════════════════════════════════════════════════
Recommendations:
• Consider enabling compression to save disk space
• Clear 14 expired documents: /fractary-codex:cache-clear --expired
═══════════════════════════════════════════════════════════
📊 Cache Statistics
───────────────────────────────────────
Total Documents: 156
Total Size: 45.2 MB
Fresh Documents: 142 (91.0%)
Expired Documents: 14 (9.0%)
Last Cleanup: 2025-01-07 14:30 UTC
Returns raw CLI JSON response (see Step 3 for structure).
📊 Codex Knowledge Retrieval Metrics
═══════════════════════════════════════════════════════════
CACHE STATISTICS
───────────────────────────────────────
Cache is empty (0 documents)
───────────────────────────────────────
Use /fractary-codex:fetch to retrieve documents
{
"status": "failure",
"operation": "cache-stats",
"error": "Cache index corrupted",
"cli_error": {
"message": "Failed to parse cache index",
"suggested_fixes": [
"Run: fractary codex cache clear --all",
"Cache will be rebuilt on next fetch"
]
}
}
{
"status": "failure",
"operation": "cache-stats",
"error": "CLI not available",
"suggested_fixes": [
"Install globally: npm install -g @fractary/cli",
"Or ensure npx is available"
]
}
</OUTPUTS>
<ERROR_HANDLING>
When CLI reports cache doesn't exist:
When CLI reports corrupted index:
fractary codex cache clear --allWhen CLI encounters calculation issues:
When cli-helper reports CLI unavailable:
When CLI returns error:
</ERROR_HANDLING>
<DOCUMENTATION> Upon completion, output:Success (Formatted):
🎯 STARTING: cache-metrics
Category: {category}
Format: formatted
───────────────────────────────────────
[Formatted metrics display]
✅ COMPLETED: cache-metrics
Analyzed {count} cache entries
Total size: {size}
Source: CLI (via cli-helper)
───────────────────────────────────────
Success (JSON):
🎯 STARTING: cache-metrics
Category: {category}
Format: json
───────────────────────────────────────
[JSON metrics]
✅ COMPLETED: cache-metrics
Source: CLI (via cli-helper)
───────────────────────────────────────
Failure:
🎯 STARTING: cache-metrics
───────────────────────────────────────
❌ FAILED: cache-metrics
Error: {error_message}
Suggested fixes:
- {fix 1}
- {fix 2}
───────────────────────────────────────
</DOCUMENTATION>
<NOTES>
v3.0 (bash scripts):
cache-metrics
└─ scripts/calculate-metrics.sh
├─ reads cache index
├─ calculates statistics
├─ analyzes performance
└─ generates recommendations
v4.0 (CLI delegation):
cache-metrics
└─ delegates to cli-helper
└─ invokes: fractary codex cache stats
Benefits:
This skill delegates to:
fractary codex cache stats [--category <category>] [--include-history] --json
Via the CLI, this skill benefits from:
CacheManager.getStats() - Statistics calculationCache Statistics:
Performance Metrics:
Source Breakdown:
Storage Usage:
Health Status:
The CLI automatically generates recommendations based on:
To test this skill:
# Ensure CLI installed
npm install -g @fractary/cli
# Populate cache first
fractary codex fetch codex://fractary/codex/README.md
# Test all metrics
USE SKILL: cache-metrics
Parameters: {
"category": "all",
"format": "formatted"
}
# Test specific category
USE SKILL: cache-metrics
Parameters: {
"category": "performance",
"format": "json"
}
If metrics fail:
fractary --versionfractary codex cache listfractary codex cache statsfractary codex health.fractary/codex/cache/.cache-index.json
</NOTES>