forked from Nomadcxx/opencode-cursor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·148 lines (127 loc) · 5.15 KB
/
install.sh
File metadata and controls
executable file
·148 lines (127 loc) · 5.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
set -e
# OpenCode-Cursor one-line installer
# Usage: curl -fsSL https://raw.githubusercontent.com/Nomadcxx/opencode-cursor/main/install.sh | bash
# With Go: runs TUI installer. Without Go: runs shell-only install (bun + cursor-agent required).
echo "OpenCode-Cursor Installer"
echo "========================="
echo ""
INSTALL_DIR="${HOME}/.local/share/opencode-cursor"
if [ -n "$SUDO_USER" ] && [ "$SUDO_USER" != "root" ]; then
CONFIG_HOME=$(eval echo "~${SUDO_USER}")/.config
else
CONFIG_HOME="${HOME}/.config"
fi
PLUGIN_DIR="${CONFIG_HOME}/opencode/plugin"
CONFIG_PATH="${CONFIG_HOME}/opencode/opencode.json"
if command -v go &>/dev/null; then
echo "Installing to: ${INSTALL_DIR}"
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
echo "Downloading opencode-cursor..."
if [ -d ".git" ]; then
git pull origin main
else
git clone --depth 1 https://github.com/Nomadcxx/opencode-cursor.git .
fi
echo "Building installer..."
go build -o ./installer ./cmd/installer
echo ""
echo "Running installer..."
echo ""
./installer "$@"
EXIT_CODE=$?
else
echo "Go not found; using shell-only install (Bun and cursor-agent required)."
echo ""
if ! command -v bun &>/dev/null; then
echo "Error: bun is not installed. Install with: curl -fsSL https://bun.sh/install | bash"
exit 1
fi
if ! command -v cursor-agent &>/dev/null; then
echo "Error: cursor-agent is not installed. Install with: curl -fsSL https://cursor.com/install | bash"
exit 1
fi
mkdir -p "$INSTALL_DIR"
cd "$INSTALL_DIR"
echo "Downloading opencode-cursor..."
if [ -d ".git" ]; then
git pull origin main
else
git clone --depth 1 https://github.com/Nomadcxx/opencode-cursor.git .
fi
echo "Building plugin..."
bun install
bun run build
if [ ! -s "dist/index.js" ]; then
echo "Error: dist/index.js not found or empty after build"
exit 1
fi
echo "Installing AI SDK in OpenCode..."
mkdir -p "${CONFIG_HOME}/opencode"
(cd "${CONFIG_HOME}/opencode" && bun install "@ai-sdk/openai-compatible")
echo "Creating plugin symlink..."
mkdir -p "$PLUGIN_DIR"
rm -f "${PLUGIN_DIR}/cursor-acp.js"
ln -sf "$(pwd)/dist/index.js" "${PLUGIN_DIR}/cursor-acp.js"
echo "Updating config..."
MODELS_JSON="{}"
if command -v jq &>/dev/null; then
RAW=$(cursor-agent models 2>&1 || true)
CLEAN=$(echo "$RAW" | sed 's/\x1b\[[0-9;]*[a-zA-Z]//g')
while IFS= read -r line; do
line=$(echo "$line" | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')
if [ -z "$line" ] || echo "$line" | grep -qE '^(Available|Tip:)'; then continue; fi
if echo "$line" | grep -qE '^[a-zA-Z0-9._-]+[[:space:]]+[-–—:][[:space:]]+'; then
id=$(echo "$line" | sed -E 's/^([a-zA-Z0-9._-]+)[[:space:]]+[-–—:][[:space:]]+.*/\1/')
name=$(echo "$line" | sed -E 's/^[a-zA-Z0-9._-]+[[:space:]]+[-–—:][[:space:]]+(.+?)([[:space:]]+\((current|default)\))?[[:space:]]*$/\1/' | sed 's/[[:space:]]*$//')
if [ -n "$id" ] && [ -n "$name" ]; then
MODELS_JSON=$(echo "$MODELS_JSON" | jq --arg id "$id" --arg name "$name" '. + {($id): {name: $name}}')
fi
fi
done <<< "$CLEAN"
fi
if [ ! -f "$CONFIG_PATH" ]; then
mkdir -p "$(dirname "$CONFIG_PATH")"
echo '{"plugin":[],"provider":{}}' > "$CONFIG_PATH"
fi
if command -v jq &>/dev/null; then
UPDATED=$(jq --argjson models "$MODELS_JSON" '
.provider["cursor-acp"] = ((.provider["cursor-acp"] // {}) | . + {
name: "Cursor",
npm: "@ai-sdk/openai-compatible",
options: { baseURL: "http://127.0.0.1:32124/v1" },
models: $models
}) | .plugin = ((.plugin // []) | if index("cursor-acp") then . else . + ["cursor-acp"] end)
' "$CONFIG_PATH")
echo "$UPDATED" > "$CONFIG_PATH"
else
bun -e "
const fs=require('fs');
const p=process.argv[1];
let c={};
try{c=JSON.parse(fs.readFileSync(p,'utf8'));}catch(_){}
c.plugin=c.plugin||[];
if(!c.plugin.includes('cursor-acp'))c.plugin.push('cursor-acp');
c.provider=c.provider||{};
c.provider['cursor-acp']={...(c.provider['cursor-acp']||{}),name:'Cursor',npm:'@ai-sdk/openai-compatible',options:{baseURL:'http://127.0.0.1:32124/v1'},models:{}};
fs.writeFileSync(p,JSON.stringify(c,null,2));
" "$CONFIG_PATH"
echo "Note: jq not found; models not synced. Run ./scripts/sync-models.sh after installing jq."
fi
echo ""
echo "Installation complete!"
echo "Plugin: ${PLUGIN_DIR}/cursor-acp.js"
echo "Repository: ${INSTALL_DIR} (uninstall: remove symlink and cursor-acp from opencode.json)"
EXIT_CODE=0
fi
echo ""
if [ $EXIT_CODE -eq 0 ]; then
echo "Repository kept at: ${INSTALL_DIR}"
if command -v go &>/dev/null; then
echo "Uninstall: cd ${INSTALL_DIR} && ./installer --uninstall"
fi
else
echo "Installation failed (exit code $EXIT_CODE). Repository kept at: ${INSTALL_DIR}"
fi
exit $EXIT_CODE