一键导入
openclaw-add-script
Scaffold a new deterministic shell script for an OpenClaw agent with JSON output, error handling, and the json-response library
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Scaffold a new deterministic shell script for an OpenClaw agent with JSON output, error handling, and the json-response library
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Add a messaging channel binding (Telegram, Slack, WhatsApp, or GChat) to an existing OpenClaw agent
Create a new scheduled cron job for an OpenClaw agent (recurring, interval, or one-shot)
Add a new secret to the OpenClaw keychain and update the appropriate launcher/secrets script
Set up nightly dream routine (memory distillation) for an OpenClaw agent including DREAM-ROUTINE.md, cron job, and archive pipeline
Create a new OpenClaw agent with all required directive files, directory structure, and config registration
Restart OpenClaw gateway(s) — handles stow conflicts and verifies channels reconnect. Supports single-gateway and multi-gateway (per-tier) deployments.
| name | openclaw-add-script |
| description | Scaffold a new deterministic shell script for an OpenClaw agent with JSON output, error handling, and the json-response library |
Scaffold a new script $1 for agent $0.
Read ~/.openclaw/workspace/skills/03-deterministic-scripts.md for the full pattern.
OPENCLAW_REPO=$(readlink ~/.openclaw/openclaw.json 2>/dev/null | sed 's|/.openclaw/openclaw.json||')
TIER_CONFIGS=(~/.openclaw/configs/openclaw-*.json)
[[ -f "${TIER_CONFIGS[0]}" ]] && MULTI_GATEWAY=true || MULTI_GATEWAY=false
If multi-gateway, resolve the agent's tier for restart:
for cfg in ~/.openclaw/configs/openclaw-*.json; do
if grep -q "\"id\": *\"$0\"" "$cfg" 2>/dev/null; then
TIER=$(basename "$cfg" | sed 's/openclaw-//;s/.json//')
break
fi
done
$OPENCLAW_REPO/.openclaw/agents/$0/scripts/lib/json-response.sh exists. If not, create it:mkdir -p "$OPENCLAW_REPO/.openclaw/agents/$0/scripts/lib"
Then write the standard library with these functions:
log() — redirect to stderrjson_timestamp() — ISO 8601 UTCjson_success <operation> <data_json> — structured success outputjson_error <operation> <code> <message> [details] — structured error outputparse_quiet_flag — parse --quiet from argsSee ~/.openclaw/workspace/skills/03-deterministic-scripts.md for the complete library source.
Ask the user what the script should do. Get:
Create the script at $OPENCLAW_REPO/.openclaw/agents/$0/scripts/$1.sh using this template:
#!/usr/bin/env bash
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SCRIPT_DIR/lib/json-response.sh"
# ── Args ──────────────────────────────────────
parse_quiet_flag "$@"
set -- "${REMAINING_ARGS[@]}"
ARG1="${1:-}"
if [[ -z "$ARG1" ]]; then
json_error "<operation-name>" "MISSING_ARG" "Usage: $0 <arg1>"
exit 1
fi
# ── Main Logic ────────────────────────────────
log "Starting <operation> for $ARG1..."
# TODO: Implement the actual logic here
# - All logging goes to stderr via log()
# - Only final JSON goes to stdout
# - Check exit codes of all commands
# - Use jq for JSON construction
RESULT="placeholder"
# ── Output ────────────────────────────────────
json_success "<operation-name>" "$(jq -n --arg r "$RESULT" '{result: $r}')"
Implement the logic based on user's description, following these rules:
log() for all human-readable output (goes to stderr)json_success() or json_error() to stdoutjq for JSON construction (never echo raw JSON strings)Make it executable:
chmod +x "$OPENCLAW_REPO/.openclaw/agents/$0/scripts/$1.sh"
$OPENCLAW_REPO/.openclaw/agents/$0/TOOLS.md:### $1.sh
**Usage:** `bash scripts/$1.sh <args>`
**Output:** JSON with `{success, operation, timestamp, data: {...}}`
**Exit codes:** 0 = success, 1 = error
## MANDATORY
NEVER <do the thing manually> — use `scripts/$1.sh`
rm -f ~/.openclaw/cron/jobs.json
cd "$OPENCLAW_REPO" && stow --no-folding -t ~ .
launchctl kickstart -k gui/$(id -u)/ai.openclaw.gateway.$TIER
launchctl kickstart -k gui/$(id -u)/ai.openclaw.gateway
log() liberally