Skip to content

Commit 55d2a91

Browse files
committed
Update PAI path resolution to follow XDG base directory standard and decouple from legacy defaults
1 parent 5ff006d commit 55d2a91

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

AGENTS.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The agent's behavior is controlled via environment variables:
2020

2121
| Variable | Description | Default |
2222
| :--- | :--- | :--- |
23-
| `PAI_DIR` | Root directory for PAI skills and history | `~/.claude` |
23+
| `PAI_DIR` | Root directory for PAI skills and history | `$XDG_CONFIG_HOME/opencode` |
2424
| `DA` | Name of your Digital Assistant | `PAI` |
2525
| `ENGINEER_NAME` | Your name/identity | `Engineer` |
2626
| `DA_COLOR` | UI color theme for your DA | `blue` |

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ The plugin centers around the `PAI_DIR` environment variable.
2828

2929
| Variable | Description | Default |
3030
| :--- | :--- | :--- |
31-
| `PAI_DIR` | Root directory for PAI skills and history | `~/.claude` |
31+
| `PAI_DIR` | Root directory for PAI skills and history | `$XDG_CONFIG_HOME/opencode` |
3232
| `DA` | Name of your Digital Assistant | `PAI` |
3333
| `ENGINEER_NAME` | Your name/identity | `Engineer` |
3434
| `DA_COLOR` | UI color theme for your DA | `blue` |

setup.sh

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,35 @@ set -e
66

77
# --- Configuration ---
88
PLUGIN_PACKAGE="${PLUGIN_PACKAGE_OVERRIDE:-github:fpr1m3/opencode-pai-plugin}"
9-
PAI_DIR_DEFAULT="$HOME/.claude"
9+
CONFIG_BASE="${XDG_CONFIG_HOME:-$HOME/.config}"
10+
PAI_DIR_DEFAULT="$CONFIG_BASE/opencode"
1011

1112
# --- UI Helpers ---
1213
info() { echo -e "\033[0;34m[PAI INFO]\033[0m $1"; }
1314
success() { echo -e "\033[0;32m[PAI SUCCESS]\033[0m $1"; }
1415
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+
error() {
17+
echo -e "\033[0;31m[PAI ERROR]\033[0m $1"
18+
exit 1
19+
}
1620

1721
# --- Logic ---
1822

1923
info "Starting PAI Plugin installation..."
2024

2125
# 1. Project Detection
2226
if [ ! -f "package.json" ]; then
23-
error "No package.json found. Please run this script from the root of your OpenCode project."
27+
error "No package.json found. Please run this script from the root of your OpenCode project."
2428
fi
2529

2630
# 2. Dependency Installation
2731
info "Installing plugin package..."
2832
if command -v bun >/dev/null 2>&1; then
29-
bun add "$PLUGIN_PACKAGE"
33+
bun add "$PLUGIN_PACKAGE"
3034
elif command -v npm >/dev/null 2>&1; then
31-
npm install "$PLUGIN_PACKAGE"
35+
npm install "$PLUGIN_PACKAGE"
3236
else
33-
error "Neither bun nor npm found. Please install a package manager."
37+
error "Neither bun nor npm found. Please install a package manager."
3438
fi
3539

3640
# 3. Plugin Registration
@@ -39,14 +43,14 @@ mkdir -p .opencode/plugins
3943

4044
PLUGIN_REG_FILE=".opencode/plugins/pai.ts"
4145
if [ -f "$PLUGIN_REG_FILE" ]; then
42-
warn "$PLUGIN_REG_FILE already exists. Skipping registration."
46+
warn "$PLUGIN_REG_FILE already exists. Skipping registration."
4347
else
44-
cat > "$PLUGIN_REG_FILE" <<EOF
48+
cat >"$PLUGIN_REG_FILE" <<EOF
4549
import { PAIPlugin } from "opencode-pai-plugin";
4650
4751
export default PAIPlugin;
4852
EOF
49-
success "Plugin registered in $PLUGIN_REG_FILE"
53+
success "Plugin registered in $PLUGIN_REG_FILE"
5054
fi
5155

5256
# 4. PAI Infrastructure Check
@@ -55,29 +59,29 @@ CORE_SKILL_FILE="$CURRENT_PAI_DIR/skills/core/SKILL.md"
5559
info "Checking PAI infrastructure at $CURRENT_PAI_DIR..."
5660

5761
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
62+
warn "PAI core identity not found at $CORE_SKILL_FILE"
63+
# Auto-initialize if non-interactive or if user says yes
64+
if [[ "$CI" == "true" ]] || [[ "$PAI_NON_INTERACTIVE" == "true" ]]; then
65+
INITIALIZE_PAI="y"
66+
else
67+
read -p "Would you like to initialize a basic PAI structure now? (y/n) " -n 1 -r
68+
echo ""
69+
INITIALIZE_PAI=$REPLY
70+
fi
6771

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
72+
if [[ $INITIALIZE_PAI =~ ^[Yy]$ ]]; then
73+
mkdir -p "$CURRENT_PAI_DIR/skills/core"
74+
mkdir -p "$CURRENT_PAI_DIR/history/raw-outputs"
75+
mkdir -p "$CURRENT_PAI_DIR/history/sessions"
76+
77+
cat >"$CORE_SKILL_FILE" <<EOF
7478
# PAI Core Identity
7579
You are {{DA}}, a Personal AI Infrastructure.
7680
Your primary engineer is {{ENGINEER_NAME}}.
7781
EOF
78-
info "Created default SKILL.md"
79-
success "PAI structure initialized."
80-
fi
82+
info "Created default SKILL.md"
83+
success "PAI structure initialized."
84+
fi
8185
fi
8286

8387
success "PAI Plugin installation complete!"

src/lib/paths.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import { existsSync } from 'fs';
1616
* Smart PAI_DIR detection with fallback
1717
* Priority:
1818
* 1. PAI_DIR environment variable (if set)
19-
* 2. ~/.claude (standard location)
19+
* 2. $XDG_CONFIG_HOME/opencode (standard XDG location)
20+
* 3. ~/.config/opencode (fallback if XDG_CONFIG_HOME is not set)
2021
*/
22+
const XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME || join(homedir(), '.config');
2123
export const PAI_DIR = process.env.PAI_DIR
2224
? resolve(process.env.PAI_DIR)
23-
: resolve(homedir(), '.claude');
25+
: resolve(XDG_CONFIG_HOME, 'opencode');
2426

2527
/**
2628
* Common PAI directories

0 commit comments

Comments
 (0)