Skip to content

Commit b982ee4

Browse files
0xbeekeeperclaude
andcommitted
fix: improve cross-platform compatibility for SKILL.md and setup.sh
SKILL.md: - Add "Resolving Script Paths" section — Agent must cd to skill dir before running scripts (fixes path issues in OpenClaw/Docker) - Widen allowed-tools patterns to support absolute paths - Step 4: require cd <skill_directory> before running checkup-report.js - Step 6: always output MEDIA:<filepath> for Telegram/Discord file delivery via OpenClaw sendDocument, in addition to channel-specific setup.sh: - Auto-detect platform: Claude Code (~/.claude) vs OpenClaw (~/.openclaw) - Copy scripts/ directory + node_modules to skill install target - Install npm dependencies in the target (avoids symlink issues) - Support --uninstall across all platform locations - Show platform-specific next-step instructions Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7cf9734 commit b982ee4

2 files changed

Lines changed: 124 additions & 47 deletions

File tree

setup.sh

Lines changed: 84 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
set -euo pipefail
33

44
# GoPlus AgentGuard — One-click setup
5-
# Installs GoPlus AgentGuard as a Claude Code skill with automatic security hooks.
5+
# Supports: Claude Code, OpenClaw, ClawHub
6+
# Detects the platform and installs to the correct location.
67

78
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
9+
SKILL_SRC="$SCRIPT_DIR/skills/agentguard"
810
AGENTGUARD_DIR="$HOME/.agentguard"
9-
CLAUDE_DIR="$HOME/.claude"
10-
SKILLS_DIR="$CLAUDE_DIR/skills/agentguard"
1111
MIN_NODE_VERSION=18
1212

1313
echo ""
@@ -36,21 +36,55 @@ if ! command -v npm &>/dev/null; then
3636
exit 1
3737
fi
3838

39+
# ---- Detect platform ----
40+
detect_platform() {
41+
# Check OpenClaw first (workspace skills or managed skills)
42+
if [ -d "$HOME/.openclaw" ]; then
43+
# Prefer workspace skills if workspace exists
44+
if [ -d "$HOME/.openclaw/workspace" ]; then
45+
SKILLS_DIR="$HOME/.openclaw/workspace/skills/agentguard"
46+
PLATFORM="openclaw-workspace"
47+
else
48+
SKILLS_DIR="$HOME/.openclaw/skills/agentguard"
49+
PLATFORM="openclaw-managed"
50+
fi
51+
return
52+
fi
53+
54+
# Check Claude Code
55+
if [ -d "$HOME/.claude" ]; then
56+
SKILLS_DIR="$HOME/.claude/skills/agentguard"
57+
PLATFORM="claude-code"
58+
return
59+
fi
60+
61+
# Fallback: create Claude Code dir (most common)
62+
SKILLS_DIR="$HOME/.claude/skills/agentguard"
63+
PLATFORM="claude-code"
64+
}
65+
66+
detect_platform
67+
echo " Platform detected: $PLATFORM"
68+
echo " Install target: $SKILLS_DIR"
69+
echo ""
70+
3971
# ---- Uninstall mode ----
4072
if [ "${1:-}" = "--uninstall" ] || [ "${1:-}" = "uninstall" ]; then
4173
echo " Uninstalling GoPlus AgentGuard..."
4274
rm -rf "$SKILLS_DIR" 2>/dev/null && echo " Removed skill from $SKILLS_DIR" || true
75+
# Also clean up other possible locations
76+
rm -rf "$HOME/.claude/skills/agentguard" 2>/dev/null || true
77+
rm -rf "$HOME/.openclaw/skills/agentguard" 2>/dev/null || true
78+
rm -rf "$HOME/.openclaw/workspace/skills/agentguard" 2>/dev/null || true
4379
rm -rf "$AGENTGUARD_DIR" 2>/dev/null && echo " Removed config from $AGENTGUARD_DIR" || true
4480
echo ""
4581
echo " GoPlus AgentGuard has been uninstalled."
46-
echo " If you added it as a Claude Code plugin, also run:"
47-
echo " claude plugin remove agentguard"
4882
echo ""
4983
exit 0
5084
fi
5185

5286
# ---- Step 1: Build the project ----
53-
echo "[1/4] Building GoPlus AgentGuard..."
87+
echo "[1/5] Building GoPlus AgentGuard..."
5488
if [ -f "$SCRIPT_DIR/package.json" ]; then
5589
cd "$SCRIPT_DIR"
5690
npm install --ignore-scripts 2>/dev/null
@@ -62,25 +96,47 @@ else
6296
fi
6397

6498
# ---- Step 2: Install CLI dependencies ----
65-
echo "[2/4] Installing CLI dependencies..."
66-
if [ -d "$SCRIPT_DIR/skills/agentguard/scripts" ]; then
67-
cd "$SCRIPT_DIR/skills/agentguard/scripts"
99+
echo "[2/5] Installing CLI dependencies..."
100+
if [ -d "$SKILL_SRC/scripts" ]; then
101+
cd "$SKILL_SRC/scripts"
68102
npm install 2>/dev/null
69103
echo " OK: CLI dependencies installed"
70104
fi
71105

72-
# ---- Step 3: Copy skill to personal skills directory ----
73-
echo "[3/4] Installing skill..."
106+
# ---- Step 3: Copy skill files ----
107+
echo "[3/5] Installing skill files..."
74108
mkdir -p "$SKILLS_DIR"
75-
cp "$SCRIPT_DIR/skills/agentguard/SKILL.md" "$SKILLS_DIR/"
76-
cp "$SCRIPT_DIR/skills/agentguard/scan-rules.md" "$SKILLS_DIR/" 2>/dev/null || true
77-
cp "$SCRIPT_DIR/skills/agentguard/action-policies.md" "$SKILLS_DIR/" 2>/dev/null || true
78-
cp "$SCRIPT_DIR/skills/agentguard/web3-patterns.md" "$SKILLS_DIR/" 2>/dev/null || true
79-
cp "$SCRIPT_DIR/skills/agentguard/evals.md" "$SKILLS_DIR/" 2>/dev/null || true
80-
echo " OK: Skill installed to $SKILLS_DIR"
81-
82-
# ---- Step 4: Create config directory ----
83-
echo "[4/4] Setting up configuration..."
109+
for f in SKILL.md README.md scan-rules.md action-policies.md web3-patterns.md evals.md patrol-checks.md .clawignore; do
110+
[ -f "$SKILL_SRC/$f" ] && cp "$SKILL_SRC/$f" "$SKILLS_DIR/" 2>/dev/null || true
111+
done
112+
echo " OK: Skill files installed"
113+
114+
# ---- Step 4: Copy scripts + node_modules ----
115+
echo "[4/5] Installing scripts and dependencies..."
116+
mkdir -p "$SKILLS_DIR/scripts"
117+
118+
# Copy script files
119+
for f in checkup-report.js guard-hook.js auto-scan.js trust-cli.ts action-cli.ts package.json package-lock.json; do
120+
[ -f "$SKILL_SRC/scripts/$f" ] && cp "$SKILL_SRC/scripts/$f" "$SKILLS_DIR/scripts/" 2>/dev/null || true
121+
done
122+
123+
# Copy data directory
124+
if [ -d "$SKILL_SRC/scripts/data" ]; then
125+
mkdir -p "$SKILLS_DIR/scripts/data"
126+
cp -r "$SKILL_SRC/scripts/data/"* "$SKILLS_DIR/scripts/data/" 2>/dev/null || true
127+
fi
128+
129+
# Install node_modules in the target (avoids symlink issues in containers)
130+
cd "$SKILLS_DIR/scripts"
131+
if [ -f "package.json" ]; then
132+
npm install 2>/dev/null
133+
echo " OK: Scripts and dependencies installed"
134+
else
135+
echo " WARN: No package.json found in scripts directory"
136+
fi
137+
138+
# ---- Step 5: Create config directory ----
139+
echo "[5/5] Setting up configuration..."
84140
mkdir -p "$AGENTGUARD_DIR"
85141
if [ ! -f "$AGENTGUARD_DIR/config.json" ]; then
86142
echo '{"level":"balanced"}' > "$AGENTGUARD_DIR/config.json"
@@ -97,7 +153,11 @@ echo " ━━━━━━━━━━━━━━━━━━━━━━━━
97153
echo " 🦞 NEXT STEP: Run your first security checkup"
98154
echo " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
99155
echo ""
100-
echo " Open Claude Code and type:"
156+
if [ "$PLATFORM" = "claude-code" ]; then
157+
echo " Open Claude Code and type:"
158+
else
159+
echo " Send your OpenClaw bot:"
160+
fi
101161
echo ""
102162
echo " /agentguard checkup"
103163
echo ""
@@ -109,15 +169,13 @@ echo " • Deliver the report directly to you"
109169
echo ""
110170
echo " ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
111171
echo ""
172+
echo " Installed to: $SKILLS_DIR"
173+
echo " Platform: $PLATFORM"
174+
echo ""
112175
echo " Other commands:"
113176
echo " /agentguard scan <path> Scan code for security risks"
114177
echo " /agentguard trust list View trusted skills"
115178
echo " /agentguard report View security event log"
116179
echo ""
117-
echo " Protection levels:"
118-
echo " /agentguard config strict Block all risky actions"
119-
echo " /agentguard config balanced Block dangerous, confirm risky (default)"
120-
echo " /agentguard config permissive Only block critical threats"
121-
echo ""
122180
echo " To uninstall: ./setup.sh --uninstall"
123181
echo ""

skills/agentguard/SKILL.md

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,27 @@ metadata:
88
version: "1.1"
99
optional_env: "GOPLUS_API_KEY, GOPLUS_API_SECRET (for Web3 transaction simulation only)"
1010
user-invocable: true
11-
allowed-tools: Read, Grep, Glob, Bash(node scripts/trust-cli.ts *) Bash(node scripts/action-cli.ts *) Bash(node scripts/checkup-report.js) Bash(openclaw *) Bash(ss *) Bash(lsof *) Bash(ufw *) Bash(iptables *) Bash(crontab *) Bash(systemctl list-timers *) Bash(find *) Bash(stat *) Bash(env) Bash(sha256sum *)
11+
allowed-tools: Read, Grep, Glob, Bash(node *trust-cli.ts *) Bash(node *action-cli.ts *) Bash(*checkup-report.js) Bash(echo *checkup-report.js) Bash(cat *checkup-report.js) Bash(openclaw *) Bash(ss *) Bash(lsof *) Bash(ufw *) Bash(iptables *) Bash(crontab *) Bash(systemctl list-timers *) Bash(find *) Bash(stat *) Bash(env) Bash(sha256sum *) Bash(node *) Bash(cd *)
1212
argument-hint: "[scan|action|patrol|trust|report|config|checkup] [args...]"
1313
---
1414

1515
# GoPlus AgentGuard — AI Agent Security Framework
1616

1717
You are a security auditor powered by the GoPlus AgentGuard framework. Route the user's request based on the first argument.
1818

19+
## Important: Resolving Script Paths
20+
21+
All commands in this skill reference `scripts/` as a relative path. You **MUST** resolve this to the absolute path of this skill's directory before running any command. To find the skill directory:
22+
23+
1. This SKILL.md file's parent directory **is** the skill directory
24+
2. If this file is at `/path/to/agentguard/SKILL.md`, then scripts are at `/path/to/agentguard/scripts/`
25+
3. Before running any `node scripts/...` command, **always `cd` into the skill directory first**, or use the full absolute path
26+
27+
Example: if this SKILL.md is at `~/.openclaw/skills/agentguard/SKILL.md`, run:
28+
```bash
29+
cd ~/.openclaw/skills/agentguard && node scripts/checkup-report.js
30+
```
31+
1932
## Command Routing
2033

2134
Parse `$ARGUMENTS` to determine the subcommand:
@@ -721,12 +734,12 @@ Assemble the results into a JSON object and pipe it to the report generator:
721734
}
722735
```
723736

724-
Execute:
737+
Execute (remember to `cd` into the skill directory first — see "Resolving Script Paths" above):
725738
```bash
726-
echo '<json>' | node scripts/checkup-report.js
739+
cd <skill_directory> && echo '<json>' | node scripts/checkup-report.js
727740
```
728741

729-
The script outputs the HTML file path to stdout and opens it in the browser automatically.
742+
The script outputs the HTML file path to stdout (e.g. `/tmp/agentguard-checkup-1234567890.html`). Capture this path — you will need it for delivery in Step 6.
730743

731744
### Step 5: Terminal Summary
732745

@@ -754,28 +767,34 @@ After the report generates, output a brief summary in the terminal:
754767

755768
### Step 6: Deliver the Report to the User
756769

757-
After printing the terminal summary, deliver the HTML report file to the user. Detect the current channel and use the most appropriate method:
770+
After printing the terminal summary, deliver the HTML report file. You **MUST** always output the `MEDIA:` token, and then also deliver via the appropriate channel method.
771+
772+
#### 6a. MEDIA token (required — always do this)
773+
774+
Output the following line on its **own line** in your response:
775+
776+
```
777+
MEDIA:<file_path>
778+
```
779+
780+
For example: `MEDIA:/tmp/agentguard-checkup-1234567890.html`
758781

759-
**Detection logic** — infer from context clues:
760-
- If the `Write` tool is available and you can write to `~/Desktop` or `~/Downloads` → you are in **Claude Code (local)**
761-
- If you can produce artifact/file outputs (rich UI, download button) → you are in **Claude.ai web**
762-
- If neither is clearly available → you are in **API / headless mode**
782+
This is how platforms like OpenClaw automatically deliver the file as a Telegram/Discord/WhatsApp attachment via `sendDocument`. The platform strips this line from visible text — the user won't see it. **Always output this regardless of what channel you think you're in.**
763783

764-
**Delivery by channel:**
784+
#### 6b. Channel-specific delivery (in addition to MEDIA token)
765785

766-
1. **Claude Code (local desktop)**
767-
- Use the `Write` tool to copy the HTML to `~/Desktop/agentguard-checkup-<YYYY-MM-DD>.html`
768-
- Tell the user: "✅ Report saved to your Desktop: `agentguard-checkup-<date>.html` — double-click to open it in your browser."
769-
- The browser should already be open from Step 4. If not, run `open ~/Desktop/agentguard-checkup-<date>.html` (macOS) or `xdg-open` (Linux).
786+
**Claude Code (local desktop)**
787+
- The browser should already be open from Step 4.
788+
- Also copy to Desktop: `cp <file_path> ~/Desktop/agentguard-checkup-$(date +%Y-%m-%d).html`
789+
- Tell the user: "✅ Report saved to your Desktop and opened in browser."
770790

771-
2. **Claude.ai web**
772-
- Read the generated HTML file using the `Read` tool, then output the full HTML content as a **code artifact** (language: `html`) so the user can preview it inline or download it.
773-
- Tell the user: "✅ Your report is attached above — click the download icon to save it."
791+
**Claude.ai web**
792+
- Read the generated HTML file and output it as a **code artifact** (language: `html`).
793+
- Tell the user: "✅ Your report is attached above — click the download icon to save it."
774794

775-
3. **API / headless / MCP**
776-
- Read the generated HTML file and return the full content inline, prefixed with:
777-
`<!-- AgentGuard Checkup Report | Score: <n>/100 | <date> -->`
778-
- Also print the file path so the caller can retrieve it from disk.
795+
**API / headless / Telegram / other**
796+
- The `MEDIA:` token above handles file delivery automatically.
797+
- Also print the file path for reference.
779798

780799
Regardless of channel, always end with:
781800
```

0 commit comments

Comments
 (0)