Coding CLI Management
This skill enables the Manager to execute AI coding CLI tools (claude/gemini/qodercli) on behalf of Workers. Workers generate precise prompts; the Manager runs the CLI in the Worker's workspace and returns the result.
Config File
Path: INLINECODE0
CODEBLOCK0
| INLINECODE1 | INLINECODE2 | Meaning |
|---|
| INLINECODE3 | any | Admin declined; use normal task flow |
| INLINECODE4 |
"claude" /
"gemini" /
"qodercli" | Active — use this CLI |
Step 1: First-Time Detection (before assigning a coding task)
Run when ~/coding-cli-config.json does not exist:
CODEBLOCK1
If no CLIs are available (available array is empty):
echo '{"enabled":false,"cli":null,"confirmed_at":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' \
> ~/coding-cli-config.json
Proceed with normal task assignment (Worker codes on their own).
If CLIs are available, ask the admin via the primary channel or Matrix DM — in the language the admin used:
I found the following AI coding CLI tools available: [list]. Would you like to enable CLI delegation mode? Workers will generate coding prompts, and I'll use the CLI tool to make the code changes. Reply with the tool name (claude/gemini/qodercli) to enable, or 'no' to have workers code on their own.
On admin reply:
- - Tool name (
claude / gemini / qodercli):
echo '{"enabled":true,"cli":"<chosen-tool>","confirmed_at":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' \
> ~/coding-cli-config.json
echo '{"enabled":false,"cli":null,"confirmed_at":"'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"}' \
> ~/coding-cli-config.json
Step 2: Assigning a Coding Task (CLI mode enabled)
When coding-cli-config.json has enabled: true:
- 1. Ensure the Worker has the
coding-cli skill. Check workers-registry.json:
cat ~/hiclaw-fs/agents/manager/workers-registry.json | jq '.workers[] | select(.name=="<worker>") | .skills'
If
coding-cli is missing, distribute it:
CODEBLOCK6
- 2. Add a "Coding CLI Mode" section to spec.md (see template below).
Step 3: Handling a coding-request: Message
When a Worker sends a message containing coding-request: (in their Worker Room or a Project Room):
Parse the message:
CODEBLOCK7
Execute:
CODEBLOCK8
On success — send to Worker in the same Room:
CODEBLOCK9
On failure (exit ≠ 0 or timeout) — see Step 4.
Step 4: Handling Failure
Notify Worker in the task Room:
CODEBLOCK10
Notify Human Admin via escalate-to-admin.sh or primary channel:
CODEBLOCK11
Record in config (optional, for heartbeat diagnostics):
jq --arg ts "$(date -u +%Y-%m-%dT%H:%M:%SZ)" --arg tid "$task_id" \
'.last_failure = {task_id: $tid, failed_at: $ts}' \
~/coding-cli-config.json > /tmp/cfg.json && \
mv /tmp/cfg.json ~/coding-cli-config.json
Spec.md Coding CLI Mode Template
Append to the end of spec.md when CLI mode is enabled:
CODEBLOCK13
Coding CLI 管理
此技能使管理者能够代表工作者执行 AI 编码 CLI 工具(claude/gemini/qodercli)。工作者生成精确的提示词;管理者在工作者的工作空间中运行 CLI 并返回结果。
配置文件
路径:~/coding-cli-config.json
json
{
enabled: true,
cli: claude,
confirmed_at: 2026-02-23T10:00:00Z
}
| enabled | cli | 含义 |
|---|
| false | 任意 | 管理员拒绝;使用正常任务流程 |
| true |
claude / gemini / qodercli | 已激活 — 使用此 CLI |
步骤 1:首次检测(在分配编码任务之前)
当 ~/coding-cli-config.json 不存在时运行:
bash
bash /opt/hiclaw/agent/skills/coding-cli-management/scripts/detect-available-cli.sh
如果没有可用的 CLI(available 数组为空):
bash
echo {enabled:false,cli:null,confirmed_at:$(date -u +%Y-%m-%dT%H:%M:%SZ)} \
> ~/coding-cli-config.json
继续正常任务分配(工作者自行编码)。
如果有可用的 CLI,通过主频道或 Matrix 私信询问管理员 — 使用管理员使用的语言:
我发现以下 AI 编码 CLI 工具可用:[列表]。您是否要启用 CLI 委托模式?工作者将生成编码提示词,我将使用 CLI 工具进行代码修改。回复工具名称(claude/gemini/qodercli)以启用,或回复 no 让工作者自行编码。
管理员回复后:
- - 工具名称(claude / gemini / qodercli):
bash
echo {enabled:true,cli:
,confirmed_at:$(date -u +%Y-%m-%dT%H:%M:%SZ)} \
> ~/coding-cli-config.json
bash
echo {enabled:false,cli:null,confirmed_at:$(date -u +%Y-%m-%dT%H:%M:%SZ)} \
> ~/coding-cli-config.json
步骤 2:分配编码任务(CLI 模式已启用)
当 coding-cli-config.json 中 enabled: true 时:
- 1. 确保工作者拥有 coding-cli 技能。 检查 workers-registry.json:
bash
cat ~/hiclaw-fs/agents/manager/workers-registry.json | jq .workers[] | select(.name==) | .skills
如果缺少 coding-cli,则分发它:
bash
bash /opt/hiclaw/agent/skills/worker-management/scripts/push-worker-skills.sh \
--worker --skill coding-cli
- 2. 在 spec.md 中添加 Coding CLI 模式 部分(参见下方模板)。
步骤 3:处理 coding-request: 消息
当工作者发送包含 coding-request: 的消息时(在其工作者房间或项目房间中):
解析消息:
task-{task-id} coding-request:
workspace: ~/hiclaw-fs/shared/tasks/{task-id}/workspace
---PROMPT---
{prompt content}
---END---
执行:
bash
1. 从 MinIO 同步工作空间
task_id=task-YYYYMMDD-HHMMSS
workspace=/root/hiclaw-fs/shared/tasks/${task_id}/workspace
mc mirror hiclaw/hiclaw-storage/shared/tasks/${taskid}/ /root/hiclaw-fs/shared/tasks/${taskid}/
2. 检查处理标记(任务协调)
bash /opt/hiclaw/agent/skills/task-coordination/scripts/check-processing-marker.sh $task_id
if [ $? -ne 0 ]; then
# 另一个进程正在处理此任务
echo 任务 ${task_id} 正在被其他操作处理。稍后重试。
exit 1
fi
3. 创建处理标记
bash /opt/hiclaw/agent/skills/task-coordination/scripts/create-processing-marker.sh $task_id manager 15
4. 将提示词保存到文件
timestamp=$(date +%Y%m%d-%H%M%S)
promptdir=/root/hiclaw-fs/shared/tasks/${taskid}/coding-prompts
mkdir -p $prompt_dir
promptfile=$promptdir/${timestamp}.txt
cat > $promptfile << PROMPTEOF
{extracted prompt content}
PROMPT_EOF
5. 获取配置的 CLI
cli=$(jq -r .cli ~/coding-cli-config.json)
6. 运行 CLI
bash /opt/hiclaw/agent/skills/coding-cli-management/scripts/run-coding-cli.sh \
--cli $cli \
--workspace $workspace \
--prompt-file $prompt_file \
--timeout 600
exit_code=$?
7. 移除处理标记
bash /opt/hiclaw/agent/skills/task-coordination/scripts/remove-processing-marker.sh $task_id
8. 成功时(退出码 0):推送变更到 MinIO
if [ $exit_code -eq 0 ]; then
mc mirror /root/hiclaw-fs/shared/tasks/${taskid}/workspace/ hiclaw/hiclaw-storage/shared/tasks/${taskid}/workspace/ --overwrite
fi
成功时 — 在同一房间发送给工作者:
@{worker}:DOMAIN task-{task-id} coding-result:
CLI 工具已完成编码。请同步工作目录并 review 变更:
bash /opt/hiclaw/agent/skills/file-sync/scripts/hiclaw-sync.sh
变更记录:~/hiclaw-fs/shared/tasks/{task-id}/workspace/coding-cli-logs/
失败时(退出码 ≠ 0 或超时)— 参见步骤 4。
步骤 4:处理失败
通知工作者 在任务房间中:
@{worker}:DOMAIN task-{task-id} coding-failed:
CLI 工具执行失败(exit code: {code})。请自行完成编码任务。
你生成的提示词已保存于:~/hiclaw-fs/shared/tasks/{task-id}/coding-prompts/
通知人类管理员 通过 escalate-to-admin.sh 或主频道:
Worker {worker-name} 的编码委托任务 {task-id} 中,{cli} 工具执行失败。
错误信息:{last lines from log file}
建议检查:
- - ~/.{cli}/ 凭证是否有效(token 是否过期)
- /host-share/.{cli}/ 软链是否正常(ls -la /root/.{cli})
- {cli} binary 是否在容器内可用(which {cli})
记录到配置中(可选,用于心跳诊断):
bash
jq --arg ts $(date -u +%Y-%m-%dT%H:%M:%SZ) --arg tid $task_id \
.lastfailure = {taskid: $tid, failed_at: $ts} \
~/coding-cli-config.json > /tmp/cfg.json && \
mv /tmp/cfg.json ~/coding-cli-config.json
Spec.md Coding CLI 模式模板
当 CLI 模式启用时,追加到 spec.md 末尾:
markdown
Coding CLI 模式
本任务涉及代码修改。请使用 Coding CLI 委托模式 完成:
- 1. 克隆/准备代码到工作目录:~/hiclaw-fs/shared/tasks/{task-id}/workspace/
- 推送到 MinIO:mc mirror ~/hiclaw-fs/shared/tasks/{task-id}/workspace/ hiclaw/hiclaw-storage/shared/tasks/{task-id}/workspace/
- 根据你的理解和 coding-cli 技能生成编码提示词,发送给我
- 等待我执行 CLI 工具并返回结果
- Sync 拉取变更:bash /opt/hiclaw/agent/skills/file-sync/scripts/hiclaw-sync.sh
- Review 变更并报告完成
如收到 coding-failed:,请自行完成编码工作。