Skip to content

Commit 5ff006d

Browse files
committed
Add automated setup script and E2E verification suite
1 parent b15afc1 commit 5ff006d

File tree

4 files changed

+212
-0
lines changed

4 files changed

+212
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,32 @@ The plugin centers around the `PAI_DIR` environment variable.
3535

3636
## Installation
3737

38+
The easiest way to install the plugin and initialize your PAI infrastructure is using the setup script:
39+
40+
```bash
41+
curl -sSL https://raw.githubusercontent.com/fpr1m3/opencode-pai-plugin/main/setup.sh | bash
42+
```
43+
44+
Or, if you have already cloned the repository:
45+
46+
```bash
47+
./setup.sh
48+
```
49+
50+
## Manual Installation
51+
3852
```bash
3953
bun add github:fpr1m3/opencode-pai-plugin
4054
```
4155

56+
## Development & Testing
57+
58+
We provide scripts to verify the installation flow in a pristine environment:
59+
60+
* `./scripts/create-test-env.sh`: Creates a fresh, isolated OpenCode project for testing.
61+
* `./scripts/test-full-flow.sh`: Runs a complete E2E installation and verification.
62+
63+
4264
## Usage
4365

4466
Register the plugin in your `.opencode/plugins.ts` (or equivalent):

scripts/create-test-env.sh

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# create-test-env.sh - Setup a pristine OpenCode test environment
3+
# Usage: ./scripts/create-test-env.sh [target_dir]
4+
5+
set -e
6+
7+
TARGET_DIR="${1:-/tmp/opencode-pristine-$(date +%s)}"
8+
PAI_TEST_DIR="$TARGET_DIR/local-pai"
9+
10+
echo "🚀 Creating pristine OpenCode environment..."
11+
echo "📍 Project Root: $TARGET_DIR"
12+
echo "🏠 Local PAI_DIR: $PAI_TEST_DIR"
13+
14+
mkdir -p "$TARGET_DIR"
15+
mkdir -p "$PAI_TEST_DIR"
16+
17+
# Ensure we're absolute
18+
TARGET_DIR=$(cd "$TARGET_DIR" && pwd)
19+
PAI_TEST_DIR=$(cd "$PAI_TEST_DIR" && pwd)
20+
21+
cd "$TARGET_DIR"
22+
23+
# 1. Initialize Git (OpenCode needs a worktree)
24+
git init -q
25+
26+
# 2. Create basic package.json
27+
cat > package.json <<EOF
28+
{
29+
"name": "pristine-opencode-project",
30+
"version": "1.0.0",
31+
"description": "A fresh OpenCode project for testing PAI plugin",
32+
"private": true
33+
}
34+
EOF
35+
36+
# 3. Setup .opencode directory
37+
mkdir -p .opencode/plugins
38+
39+
# 4. Create a dummy README
40+
echo "# Pristine Test Project" > README.md
41+
42+
echo ""
43+
echo "✅ Pristine environment established."
44+
echo "------------------------------------------------"
45+
echo "To begin testing:"
46+
echo "export PAI_DIR=$PAI_TEST_DIR"
47+
echo "cd $TARGET_DIR"
48+
echo "------------------------------------------------"
49+
50+
# Output the path for other scripts to capture
51+
echo "$TARGET_DIR" > /tmp/last_opencode_test_env

scripts/test-full-flow.sh

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/bin/bash
2+
# test-full-flow.sh - End-to-end test for PAI Plugin setup
3+
4+
set -e
5+
6+
REPO_ROOT=$(pwd)
7+
TEST_DIR="/tmp/opencode-full-test-$(date +%s)"
8+
9+
# --- Cleanup ---
10+
cleanup() {
11+
echo "🧹 Cleaning up test directory..."
12+
rm -rf "$TEST_DIR"
13+
}
14+
# trap cleanup EXIT # Uncomment if you want auto-cleanup
15+
16+
# 1. Establish Pristine Environment
17+
./scripts/create-test-env.sh "$TEST_DIR"
18+
19+
# 2. Preparation for Setup
20+
# We override the package to point to the local repo for the test
21+
export PLUGIN_PACKAGE_OVERRIDE="$REPO_ROOT"
22+
export PAI_DIR="$TEST_DIR/local-pai"
23+
24+
cd "$TEST_DIR"
25+
26+
echo "🛠️ Running setup script inside test environment..."
27+
export PAI_NON_INTERACTIVE="true"
28+
"$REPO_ROOT/setup.sh"
29+
30+
# 3. Verification
31+
echo "🔍 Verifying installation artifacts..."
32+
33+
if [ ! -f ".opencode/plugins/pai.ts" ]; then
34+
echo "❌ Error: Plugin registration file (.opencode/plugins/pai.ts) not found."
35+
exit 1
36+
fi
37+
38+
if [ ! -f "local-pai/skills/core/SKILL.md" ]; then
39+
echo "❌ Error: PAI identity file (local-pai/skills/core/SKILL.md) not found."
40+
exit 1
41+
fi
42+
43+
if ! grep -q "Personal AI Infrastructure" local-pai/skills/core/SKILL.md; then
44+
echo "❌ Error: SKILL.md content is invalid or empty."
45+
exit 1
46+
fi
47+
48+
# Check if dependencies were added to package.json
49+
if ! grep -q "opencode-pai-plugin" package.json; then
50+
echo "❌ Error: Plugin not found in package.json dependencies."
51+
exit 1
52+
fi
53+
54+
echo "✅ End-to-end verification successful!"
55+
echo "📍 Test project remains at: $TEST_DIR"

setup.sh

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash
2+
# PAI Plugin Setup Script
3+
# Installs the PAI plugin into an OpenCode project
4+
5+
set -e
6+
7+
# --- Configuration ---
8+
PLUGIN_PACKAGE="${PLUGIN_PACKAGE_OVERRIDE:-github:fpr1m3/opencode-pai-plugin}"
9+
PAI_DIR_DEFAULT="$HOME/.claude"
10+
11+
# --- UI Helpers ---
12+
info() { echo -e "\033[0;34m[PAI INFO]\033[0m $1"; }
13+
success() { echo -e "\033[0;32m[PAI SUCCESS]\033[0m $1"; }
14+
warn() { echo -e "\033[0;33m[PAI WARN]\033[0m $1"; }
15+
error() { echo -e "\033[0;31m[PAI ERROR]\033[0m $1"; exit 1; }
16+
17+
# --- Logic ---
18+
19+
info "Starting PAI Plugin installation..."
20+
21+
# 1. Project Detection
22+
if [ ! -f "package.json" ]; then
23+
error "No package.json found. Please run this script from the root of your OpenCode project."
24+
fi
25+
26+
# 2. Dependency Installation
27+
info "Installing plugin package..."
28+
if command -v bun >/dev/null 2>&1; then
29+
bun add "$PLUGIN_PACKAGE"
30+
elif command -v npm >/dev/null 2>&1; then
31+
npm install "$PLUGIN_PACKAGE"
32+
else
33+
error "Neither bun nor npm found. Please install a package manager."
34+
fi
35+
36+
# 3. Plugin Registration
37+
info "Registering PAI Plugin..."
38+
mkdir -p .opencode/plugins
39+
40+
PLUGIN_REG_FILE=".opencode/plugins/pai.ts"
41+
if [ -f "$PLUGIN_REG_FILE" ]; then
42+
warn "$PLUGIN_REG_FILE already exists. Skipping registration."
43+
else
44+
cat > "$PLUGIN_REG_FILE" <<EOF
45+
import { PAIPlugin } from "opencode-pai-plugin";
46+
47+
export default PAIPlugin;
48+
EOF
49+
success "Plugin registered in $PLUGIN_REG_FILE"
50+
fi
51+
52+
# 4. PAI Infrastructure Check
53+
CURRENT_PAI_DIR="${PAI_DIR:-$PAI_DIR_DEFAULT}"
54+
CORE_SKILL_FILE="$CURRENT_PAI_DIR/skills/core/SKILL.md"
55+
info "Checking PAI infrastructure at $CURRENT_PAI_DIR..."
56+
57+
if [ ! -f "$CORE_SKILL_FILE" ]; then
58+
warn "PAI core identity not found at $CORE_SKILL_FILE"
59+
# Auto-initialize if non-interactive or if user says yes
60+
if [[ "$CI" == "true" ]] || [[ "$PAI_NON_INTERACTIVE" == "true" ]]; then
61+
INITIALIZE_PAI="y"
62+
else
63+
read -p "Would you like to initialize a basic PAI structure now? (y/n) " -n 1 -r
64+
echo ""
65+
INITIALIZE_PAI=$REPLY
66+
fi
67+
68+
if [[ $INITIALIZE_PAI =~ ^[Yy]$ ]]; then
69+
mkdir -p "$CURRENT_PAI_DIR/skills/core"
70+
mkdir -p "$CURRENT_PAI_DIR/history/raw-outputs"
71+
mkdir -p "$CURRENT_PAI_DIR/history/sessions"
72+
73+
cat > "$CORE_SKILL_FILE" <<EOF
74+
# PAI Core Identity
75+
You are {{DA}}, a Personal AI Infrastructure.
76+
Your primary engineer is {{ENGINEER_NAME}}.
77+
EOF
78+
info "Created default SKILL.md"
79+
success "PAI structure initialized."
80+
fi
81+
fi
82+
83+
success "PAI Plugin installation complete!"
84+
info "You can now run 'opencode' to start using your Personal AI Infrastructure."

0 commit comments

Comments
 (0)