一键导入
external-cli-runner
Unified external CLI agent runner — backend detection, command dispatch, retry logic, response parsing
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Unified external CLI agent runner — backend detection, command dispatch, retry logic, response parsing
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | external-cli-runner |
| description | Unified external CLI agent runner — backend detection, command dispatch, retry logic, response parsing |
Reusable infrastructure for spawning external CLI agents (claude, codex, gemini). Handles backend detection, command construction, thinking level mapping, retry-on-failure (up to 3 attempts), and response parsing.
Any skill that needs to delegate work to an external CLI agent should load this skill instead of implementing CLI invocation directly.
Loaded by other skills that need external CLI execution:
plan-consultant — pre-plan gap analysisplan-critic — post-plan reviewThe calling skill MUST provide these parameters:
| Parameter | Example | Description |
|---|---|---|
configPath | review.consultant | Dot-path into .amag/config.json to read cli, model, thinking |
requestFile | .amag/reviews/{id}-consultant-request.md | Path to the request file (already written by caller) |
responseFileRaw | .amag/reviews/{id}-consultant-response-raw.md | Where raw CLI output goes |
responseFile | .amag/reviews/{id}-consultant-response.md | Where cleaned/parsed response goes |
requiredField | verdict: | A string that must appear in a valid response |
attemptLog | .amag/reviews/{id}-consultant-cli-attempts.log | Audit trail — every CLI detection/invocation writes here |
fallbackAction | "Proceed to Self-Review Path (Step 2B)" | What the caller does on total failure |
.amag/config.json via view_file. Navigate to {configPath} to get cli, model, thinking.cli is set, verify availability:
run_command: which <cli_name>
cli is null → report failure to caller.run_command: echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] attempt=detect cli={cli_name} result={found|not_found|null} exit={code}" >> {attemptLog}
Update task_boundary: TaskStatus: "External CLI: detecting backend for {configPath}..."
If CLI was configured but not found on PATH:
task_boundary: TaskStatus: "⚠️ External CLI: {cli_name} not found — caller should fall back"> [!CAUTION]
> **CLI not found**: Configured CLI `{cli_name}` was not found on PATH.
> Falling back to caller's fallback path.
> To install: `npm install -g @openai/codex` or `npm install -g @anthropic-ai/claude-code`
> To disable CLI: set `{configPath}.cli` to `null` in `.amag/config.json`
Read model and thinking from config. Map thinking level, build command, execute.
| Config value | claude --effort | codex -c model_reasoning_effort | gemini behavior |
|---|---|---|---|
max | max | high | Default |
high | high | high | Default |
medium | medium | medium | Default |
low | low | low | Default |
none | low | low | Default |
Claude:
run_command: claude --print --model {model} --effort {thinking_mapped} --fallback-model sonnet --dangerously-skip-permissions < {requestFile} > {responseFileRaw} 2>&1
[!NOTE]
--fallback-model sonnetenables automatic model fallback when the primary model is overloaded or returns a server error. Only works with
Codex:
run_command: codex exec --full-auto -m {model} -c model_reasoning_effort="{thinking_mapped}" < {requestFile} > {responseFileRaw} 2>&1
Gemini CLI:
run_command: cat {requestFile} | gemini -m {model} --yolo > {responseFileRaw} 2>&1
Set WaitMsBeforeAsync: 500 to run async. Poll via command_status at 60s intervals.
[!IMPORTANT] External CLI agents are NOT development commands. They legitimately produce zero stdout for minutes while thinking. Do NOT apply the "2 consecutive polls with no output growth = hung" rule from
error-recovery.mdhere. That rule is for builds, tests, and linters — not AI agent invocations.
Timeout strategy for external CLI agents:
configPath to get the parent section (e.g. debug from debug.consultant), then read {parent}.timeout_ms from .amag/config.json. Convert to minutes. If not set, default to 10 minutes.command_status(WaitDurationSeconds: 60).send_command_input(Terminate=true) → count as a failed attempt.[!IMPORTANT] 3 retries maximum. After 3 failed attempts, return failure to caller.
After each CLI execution, check for errors:
Check both of these:
{responseFileRaw} for:
API Error:Internal server erroroverloadedrate_limittimeout[!IMPORTANT] The
2>&1redirect sends stderr to the raw file, so the exit code alone may not reveal the error. Always scan the raw file content in addition to checking exit code.
attempt = 1
while attempt <= 3:
run CLI command (Step 2)
# Log every attempt to the audit trail:
run_command: echo "[$(date -u +%Y-%m-%dT%H:%M:%SZ)] attempt={attempt}/3 cli={cli_name} result={success|error} exit={code}" >> {attemptLog}
if exit code == 0 AND no error patterns in raw response:
→ proceed to Step 4 (Parse Response)
else:
log: "External CLI attempt {attempt}/3 failed: {error summary}"
attempt += 1
if attempt > 3:
update task_boundary: TaskStatus: "⚠️ External CLI: 3 attempts failed — returning to caller for fallback"
→ return failure to caller (caller executes their fallbackAction)
Update task_boundary on each attempt:
TaskStatus: "External CLI: attempt {N}/3 for {configPath}..."After a successful CLI execution (exit 0, no error patterns):
{responseFileRaw} via view_file{responseFile} via write_to_file{requiredField} exists in the response:
grep_search("{requiredField}", "{responseFile}")
Skills that use this runner should follow this pattern:
### CLI Execution
Load `external-cli-runner` skill. Invoke with:
- configPath: `review.consultant`
- requestFile: `.amag/reviews/{planId}-consultant-request.md`
- responseFileRaw: `.amag/reviews/{planId}-consultant-response-raw.md`
- responseFile: `.amag/reviews/{planId}-consultant-response.md`
- requiredField: `verdict:`
- attemptLog: `.amag/reviews/{planId}-consultant-cli-attempts.log`
- fallbackAction: "Proceed to Self-Review Path (Step 2B)"
If the runner returns success → read responseFile and proceed.
If the runner returns failure → execute fallbackAction.
Pre-generation gap analysis — surface hidden requirements, AI-slop risks, and missing guardrails before the plan is written
Structured codebase search protocol — deep parallel exploration before acting on unfamiliar code
Post-generation plan review — verify references, executability, and acceptance criteria before execution
High-IQ architecture consulting mode — complex trade-offs, hard debugging, read-only analysis
Autonomous exploration and goal-driven execution — read extensively before acting
Anti-AI-slop technical writing — clear prose, human tone, zero filler