Claude-skill-registry cli-helper
Shared utility skill for invoking fractary CLI codex commands
git clone https://github.com/majiayu000/claude-skill-registry
T=$(mktemp -d) && git clone --depth=1 https://github.com/majiayu000/claude-skill-registry "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/data/cli-helper" ~/.claude/skills/majiayu000-claude-skill-registry-cli-helper && rm -rf "$T"
skills/data/cli-helper/SKILL.mdYou are a shared utility skill that other codex skills delegate to when they need to invoke fractary CLI commands. You provide a clean abstraction layer between the plugin architecture and the @fractary/cli, handling CLI invocation, error handling, and output parsing.
Key Responsibilities:
- Validate CLI installation (global or npx)
- Execute CLI commands with proper arguments
- Parse JSON output from CLI
- Handle errors gracefully with helpful messages
- Support both global and npx installations
Architecture Role:
</CONTEXT>Other Codex Skills ↓ (delegates to) cli-helper ↓ (invokes) @fractary/cli ↓ (uses) @fractary/codex SDK
<CRITICAL_RULES>
- NEVER execute operations yourself - Always delegate to fractary CLI
- ALWAYS use --json flag when invoking CLI commands
- ALWAYS validate CLI availability before invocation
- NEVER bypass the CLI - Don't implement direct SDK calls or bash workarounds
- ALWAYS preserve CLI exit codes for proper error propagation
- ALWAYS return structured JSON for calling skills to parse
- Support both global and npx - Automatic fallback, but recommend global </CRITICAL_RULES>
{ "operation": "invoke-cli", "parameters": { "command": "fetch|cache|health|sync|...", "args": ["arg1", "arg2", ...], "parse_output": true } }
Common Commands:
- Fetch document by codex:// URIfetch <uri>
- List cached documentscache list
- Clear cache entriescache clear [--all|--expired]
- Get cache statisticscache stats
- Run health checkshealth
- Sync projectsync project [name]
- Sync organizationsync org
- Initialize configurationinit
- Migrate configurationmigrate
- Validate references </INPUTS>check
High-Level Process
Step 1: Validate CLI Availability
Run validation script:
./scripts/validate-cli.sh
Check response:
- If
→ proceedcli_available: true - If
→ return error with installation instructionscli_available: false
Step 2: Build CLI Command
Construct command:
./scripts/invoke-cli.sh <command> [args...]
The script automatically:
- Checks for global
commandfractary - Falls back to
if needednpx @fractary/cli - Adds
flag for programmatic output--json
Step 3: Execute CLI Command
Run the command and capture output:
output=$(./scripts/invoke-cli.sh "$command" "${args[@]}") exit_code=$?
Step 4: Parse Output (if requested)
If calling skill needs parsed fields:
status=$(echo "$output" | ./scripts/parse-output.sh status) message=$(echo "$output" | ./scripts/parse-output.sh message) data=$(echo "$output" | ./scripts/parse-output.sh data)
Step 5: Return Results
Return to calling skill:
</WORKFLOW>{ "status": "success|failure", "cli_exit_code": 0, "raw_output": "...", "parsed": { "status": "...", "message": "...", "data": {...} } }
<COMPLETION_CRITERIA> Operation is complete when:
✅ For successful invocation:
- CLI command executed successfully
- Output captured and parsed (if requested)
- Results returned to calling skill
- Exit code = 0
✅ For failed invocation:
- Error message captured from CLI
- Installation instructions provided (if CLI not available)
- Suggested fixes included
- Exit code preserved from CLI
✅ In all cases:
- Structured JSON response returned
- No exceptions thrown
- Calling skill has actionable information </COMPLETION_CRITERIA>
Success Response
{ "status": "success", "operation": "invoke-cli", "command": "fetch", "cli_exit_code": 0, "cli_output": { "status": "success", "uri": "codex://fractary/project/file.md", "content": "...", "metadata": { "fromCache": true, "fetchedAt": "2025-12-14T..." } } }
Failure Response: CLI Not Available
{ "status": "failure", "operation": "invoke-cli", "error": "CLI not available", "cli_available": false, "cli_source": "none", "suggested_fixes": [ "Install globally: npm install -g @fractary/cli", "Or ensure npx is available (comes with npm 5.2+)" ] }
Failure Response: Command Failed
{ "status": "failure", "operation": "invoke-cli", "command": "fetch", "cli_exit_code": 1, "cli_output": { "status": "failure", "message": "Document not found: codex://fractary/invalid/path.md", "suggested_fixes": [ "Check URI format", "Verify document exists in repository" ] } }
Info Response: npx Fallback Used
</OUTPUTS>{ "status": "success", "operation": "invoke-cli", "command": "health", "cli_exit_code": 0, "cli_source": "npx", "info": "Using npx fallback - consider installing globally for better performance", "cli_output": {...} }
<ERROR_HANDLING> Handle errors gracefully:
CLI Not Installed
When neither global nor npx available:
- Return structured error response
- Include installation instructions
- Suggest global install for best performance
- Exit with code 1
Command Execution Failed
When CLI returns non-zero exit code:
- Preserve the CLI's exit code
- Return the CLI's error message verbatim
- Include suggested fixes if CLI provides them
- Don't attempt to fix or retry
JSON Parsing Failed
When CLI output isn't valid JSON:
- Return the raw output
- Log parsing error
- Suggest checking CLI version
- Exit with code 1
Invalid Command
When command name is invalid:
- Return error with valid command list
- Suggest closest match if possible
- Exit with code 1 </ERROR_HANDLING>
Logging
Log key information:
- CLI command invoked
- CLI source (global vs npx)
- Execution time
- Exit code
- Whether output was parsed
Examples
✓ CLI validated (global, v0.3.2) ✓ Executed: fractary codex fetch codex://fractary/project/file.md ✓ Exit code: 0 ✓ Execution time: 87ms ✓ Output parsed successfully
⚠ CLI not found globally, using npx fallback ✓ Executed: npx @fractary/cli codex health ✓ Exit code: 0 ✓ Execution time: 1243ms (includes npm download) ℹ Recommend global install for better performance
</DOCUMENTATION> <NOTES> ## Performance✗ CLI command failed ✗ Executed: fractary codex fetch codex://invalid/uri ✗ Exit code: 1 ✗ Error: Invalid URI format
- Global install: Recommended for production (< 100ms overhead)
- npx fallback: Useful for dev/testing (~500-1000ms first run, ~200ms cached)
- First npx invocation downloads package (slow), subsequent calls use cache
Installation Recommendations
Recommend users install globally:
npm install -g @fractary/cli
Benefits:
- Faster startup (no npm overhead)
- Offline capability (no npm registry check)
- Explicit version control
CLI Version Compatibility
This skill works with:
v0.3.2 or higher@fractary/cli
v0.1.3 or higher (transitive)@fractary/codex
CLI automatically manages SDK dependencies.
Delegation Pattern
Other skills should invoke cli-helper via the Skill tool:
USE SKILL: cli-helper Operation: invoke-cli Parameters: { "command": "fetch", "args": ["codex://fractary/project/file.md"], "parse_output": true }
Never call scripts directly - always go through the skill invocation. </NOTES>