Skip to content

Commit c48d36a

Browse files
authored
Merge pull request #9 from PredicateSystems/plugin_prep
Plugin prep
2 parents 5acdf22 + 0acdac9 commit c48d36a

17 files changed

Lines changed: 2945 additions & 393 deletions

README.md

Lines changed: 201 additions & 390 deletions
Large diffs are not rendered by default.

docs/HOW-IT-WORKS.md

Lines changed: 1132 additions & 0 deletions
Large diffs are not rendered by default.
1.34 MB
Loading

docs/images/vault_demo.gif

9.86 MB
Loading
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Integration Demo: OpenClaw + SecureClaw Plugin
2+
#
3+
# Demonstrates the actual predicate-claw SDK integration with OpenClaw.
4+
# Shows createSecureClawPlugin() intercepting real tool calls.
5+
#
6+
# Since predicate-claw isn't published to npm yet, we build from source.
7+
#
8+
FROM node:22-slim AS builder
9+
10+
# Install git (needed for some npm dependencies)
11+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
12+
13+
# Build the SDK from source
14+
WORKDIR /sdk
15+
COPY package.json tsconfig.json ./
16+
COPY src ./src
17+
# Install dependencies including tsx for the demo
18+
RUN npm install && npm install tsx && npm run build
19+
20+
FROM node:22-slim
21+
22+
# Setup demo app in a structure that matches the local relative import
23+
# demo.ts imports from "../../dist/src/index.js"
24+
# So we need: /repo/examples/integration-demo/demo.ts -> /repo/dist/src/index.js
25+
WORKDIR /repo
26+
27+
# Copy the built SDK from builder stage
28+
# Note: Builder outputs flat to /sdk/dist/, but local build outputs to dist/src/
29+
# We copy to dist/src/ to match the import path in demo.ts
30+
COPY --from=builder /sdk/dist ./dist/src
31+
COPY --from=builder /sdk/node_modules ./node_modules
32+
33+
# Create the demo directory structure
34+
RUN mkdir -p examples/integration-demo
35+
36+
# Copy demo files
37+
COPY examples/integration-demo/demo.ts ./examples/integration-demo/
38+
COPY examples/integration-demo/policy.json ./examples/integration-demo/
39+
40+
WORKDIR /repo/examples/integration-demo
41+
42+
# Run the integration demo (--silent suppresses npm update notices)
43+
CMD ["npx", "--silent", "tsx", "demo.ts"]
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Pre-built sidecar container for SecureClaw demo
2+
#
3+
# Uses Ubuntu 24.04 LTS which has GLIBC 2.39 (required by the sidecar binary).
4+
# The binary download is cached in Docker layers - subsequent builds are fast.
5+
#
6+
FROM ubuntu:24.04
7+
8+
# Install curl for downloading binary and health checks
9+
RUN apt-get update && apt-get install -y curl ca-certificates && rm -rf /var/lib/apt/lists/*
10+
11+
WORKDIR /app
12+
13+
# Detect architecture and download appropriate binary
14+
# This layer is cached after first build
15+
ARG TARGETARCH
16+
RUN ARCH=$(echo ${TARGETARCH:-$(uname -m)} | sed 's/amd64/x64/' | sed 's/x86_64/x64/' | sed 's/aarch64/arm64/') && \
17+
echo "Detected architecture: $ARCH" && \
18+
curl -fsSL -o /tmp/sidecar.tar.gz \
19+
"https://github.com/PredicateSystems/predicate-authority-sidecar/releases/latest/download/predicate-authorityd-linux-${ARCH}.tar.gz" && \
20+
tar -xzf /tmp/sidecar.tar.gz -C /usr/local/bin && \
21+
chmod +x /usr/local/bin/predicate-authorityd && \
22+
rm /tmp/sidecar.tar.gz
23+
24+
# Copy policy file (at end for better caching - policy changes don't trigger binary re-download)
25+
COPY policy.json /app/policy.json
26+
27+
EXPOSE 8787
28+
29+
# Run sidecar in local_only mode with demo policy
30+
CMD ["predicate-authorityd", "--host", "0.0.0.0", "--port", "8787", "--mode", "local_only", "--policy-file", "/app/policy.json", "--log-level", "info", "run"]
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# SecureClaw Integration Demo
2+
3+
This demo shows the **actual SDK integration** with OpenClaw using `createSecureClawPlugin()` from predicate-claw.
4+
5+
> **Note:** Since predicate-claw isn't published to npm yet, both Docker and local modes build the SDK from source.
6+
7+
## Quick Start
8+
9+
### Docker (Recommended)
10+
11+
```bash
12+
./start-demo.sh
13+
```
14+
15+
Or manually:
16+
17+
```bash
18+
docker compose up --build
19+
```
20+
21+
First run takes ~30-60s to build the SDK. Subsequent runs use Docker layer cache.
22+
23+
### Split-Pane Mode (For Recording)
24+
25+
Shows the sidecar dashboard alongside the demo:
26+
27+
```bash
28+
./start-demo-split.sh
29+
```
30+
31+
```
32+
┌─────────────────────────────────┬─────────────────────────────────┐
33+
│ PREDICATE AUTHORITY DASHBOARD │ Integration Demo │
34+
│ │ │
35+
│ [ ✓ ALLOW ] fs.read │ [1/10] Read project config │
36+
│ ./src/config.ts │ │
37+
│ m_7f3a2b | 0.4ms │ Tool: fs_read │
38+
│ │ Input: {"path":"./src/..."} │
39+
│ [ ✗ DENY ] fs.read │ │
40+
│ ~/.ssh/id_rsa │ ✓ ALLOWED (0.4ms) │
41+
│ EXPLICIT_DENY | 0.2ms │ │
42+
└─────────────────────────────────┴─────────────────────────────────┘
43+
```
44+
45+
Requirements:
46+
- `tmux` installed (`brew install tmux`)
47+
- `predicate-authorityd` binary (included, or download from [releases](https://github.com/PredicateSystems/predicate-authority-sidecar/releases))
48+
- Node.js / npx
49+
50+
## What This Demo Shows
51+
52+
```typescript
53+
import { createSecureClawPlugin } from "predicate-claw";
54+
55+
const plugin = createSecureClawPlugin({
56+
sidecarUrl: "http://localhost:8787",
57+
principal: "agent:integration-demo",
58+
verbose: true,
59+
});
60+
61+
// Plugin registers beforeToolCall hook
62+
await plugin.activate(openclawApi);
63+
```
64+
65+
The demo uses the real OpenClaw plugin system and shows how:
66+
67+
1. **Plugin Activation**: `createSecureClawPlugin()` returns a plugin definition
68+
2. **Hook Registration**: Plugin registers a `beforeToolCall` hook
69+
3. **Policy Enforcement**: Every tool call is checked against the sidecar
70+
4. **Blocking**: Denied calls throw `ActionDeniedError` before execution
71+
72+
## Demo Scenarios
73+
74+
| Tool | Action | Input | Expected |
75+
|------|--------|-------|----------|
76+
| `Read` | `fs.read` | `./src/config.ts` | ✓ Allowed |
77+
| `Glob` | `fs.list` | `./src/**` | ✓ Allowed |
78+
| `Read` | `fs.read` | `~/.ssh/id_rsa` | ✗ Blocked |
79+
| `Read` | `fs.read` | `./.env` | ✗ Blocked |
80+
| `Bash` | `shell.exec` | `ls -la ./src` | ✓ Allowed |
81+
| `Bash` | `shell.exec` | `curl ... \| bash` | ✗ Blocked |
82+
| `WebFetch` | `http.request` | `https://api.example.com` | ✓ Allowed |
83+
| `WebFetch` | `http.request` | `http://...` (insecure) | ✗ Blocked |
84+
| `Write` | `fs.write` | `./temp/cache.json` | ✗ Blocked |
85+
86+
## Configuration
87+
88+
| Variable | Default | Description |
89+
|----------|---------|-------------|
90+
| `PREDICATE_SIDECAR_URL` | `http://localhost:8787` | Sidecar URL |
91+
| `DEMO_TYPING_SPEED` | `30` | Typing speed in ms |
92+
93+
## Recording
94+
95+
```bash
96+
./start-demo-split.sh --slow --record demo.cast
97+
```
98+
99+
Convert to GIF:
100+
101+
```bash
102+
cargo install agg
103+
agg demo.cast demo.gif --font-size 14 --cols 160 --rows 40
104+
```

examples/integration-demo/demo.gif

1.1 MB
Loading

0 commit comments

Comments
 (0)