-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·201 lines (176 loc) · 6.28 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·201 lines (176 loc) · 6.28 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env bash
set -euo pipefail
LABEL="com.lpcpaul.feishu-claude-code-bridge"
PROJECT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
RUNTIME_DIR="${FEISHU_CLAUDE_CODE_RUNTIME_DIR:-${HOME}/Library/Application Support/FeishuClaudeCodeBridge}"
APP_DIR="${RUNTIME_DIR}/app"
ENV_FILE="${APP_DIR}/.env.feishu"
PLIST_PATH="${HOME}/Library/LaunchAgents/${LABEL}.plist"
PYTHON_BIN="${PYTHON_BIN:-$(command -v python3 || true)}"
if [[ "$(uname -s)" != "Darwin" ]]; then
echo "This installer currently supports macOS launchd only." >&2
exit 1
fi
if [[ -z "$PYTHON_BIN" ]]; then
echo "python3 is required. Install Python 3 and run this installer again." >&2
exit 1
fi
detect_file() {
local pattern="$1"
ls -1d $pattern 2>/dev/null | sort | tail -n 1 || true
}
detect_claude() {
command -v claude 2>/dev/null || detect_file "${HOME}/.nvm/versions/node/*/bin/claude"
}
detect_node() {
command -v node 2>/dev/null || detect_file "${HOME}/.nvm/versions/node/*/bin/node"
}
prompt_secret() {
local label="$1"
local current="${2:-}"
if [[ -n "$current" ]]; then
printf '%s' "$current"
return
fi
read -r -s -p "$label: " current
echo >&2
printf '%s' "$current"
}
prompt_value() {
local label="$1"
local current="${2:-}"
if [[ -n "$current" ]]; then
printf '%s' "$current"
return
fi
read -r -p "$label: " current
printf '%s' "$current"
}
cat <<'NOTICE'
Before installing, make sure the Feishu app has these initial permissions/events:
im:message.p2p_msg:readonly
im:message.group_at_msg:readonly
im:message:send_as_bot
im.message.receive_v1
Recommended if you want cards, docs, or group creation later:
card.action.trigger
cardkit:card:write
docx:document or docx:document:create
im:chat:create
im:chat
See docs/initial-permissions.md for the import JSON.
NOTICE
FEISHU_APP_ID="$(prompt_value "Feishu App ID" "${FEISHU_APP_ID:-}")"
FEISHU_APP_SECRET="$(prompt_secret "Feishu App Secret" "${FEISHU_APP_SECRET:-}")"
if [[ -z "$FEISHU_APP_ID" || -z "$FEISHU_APP_SECRET" ]]; then
echo "FEISHU_APP_ID and FEISHU_APP_SECRET are required." >&2
exit 1
fi
NODE_BIN="${NODE_BIN:-$(detect_node)}"
CLAUDE_BIN="${CLAUDE_BIN:-$(detect_claude)}"
FEISHU_CLAUDE_CODE_WORKDIR="${FEISHU_CLAUDE_CODE_WORKDIR:-${HOME}}"
CLAUDE_PERMISSION_MODE="${CLAUDE_PERMISSION_MODE:-auto}"
if [[ -z "$CLAUDE_BIN" ]]; then
echo "Claude Code CLI was not found. Install and log in to Claude Code first, then rerun install.sh." >&2
exit 1
fi
mkdir -p "$APP_DIR" "$(dirname "$PLIST_PATH")"
if command -v rsync >/dev/null 2>&1; then
rsync -a \
--exclude ".git/" \
--exclude "__pycache__/" \
--exclude ".env.feishu" \
--exclude "*.sqlite" \
--exclude "*.sqlite-*" \
"$PROJECT_DIR/" "$APP_DIR/"
else
cp -R "$PROJECT_DIR"/. "$APP_DIR/"
rm -rf "$APP_DIR/.git" "$APP_DIR/__pycache__"
fi
if ! "$PYTHON_BIN" - <<'PY' >/dev/null 2>&1
import lark_oapi
PY
then
"$PYTHON_BIN" -m pip install --user -r "$APP_DIR/requirements.txt"
fi
export FEISHU_APP_ID FEISHU_APP_SECRET FEISHU_CLAUDE_CODE_WORKDIR RUNTIME_DIR NODE_BIN CLAUDE_BIN
export CLAUDE_PERMISSION_MODE CLAUDE_MODEL CLAUDE_EFFORT CLAUDE_MAX_BUDGET_USD
export CLAUDE_ALLOWED_TOOLS CLAUDE_DISALLOWED_TOOLS CLAUDE_EXTRA_ARGS
"$PYTHON_BIN" - "$ENV_FILE" <<'PY'
import os
import shlex
import sys
from pathlib import Path
env_path = Path(sys.argv[1])
values = {
"FEISHU_APP_ID": os.environ["FEISHU_APP_ID"],
"FEISHU_APP_SECRET": os.environ["FEISHU_APP_SECRET"],
"FEISHU_CLAUDE_CODE_WORKDIR": os.environ["FEISHU_CLAUDE_CODE_WORKDIR"],
"FEISHU_CLAUDE_CODE_RUNTIME_DIR": os.environ["RUNTIME_DIR"],
"PYTHON_BIN": os.environ["PYTHON_BIN"],
"NODE_BIN": os.environ.get("NODE_BIN", ""),
"CLAUDE_BIN": os.environ["CLAUDE_BIN"],
"CLAUDE_PERMISSION_MODE": os.environ.get("CLAUDE_PERMISSION_MODE", "auto"),
"CLAUDE_MODEL": os.environ.get("CLAUDE_MODEL", ""),
"CLAUDE_EFFORT": os.environ.get("CLAUDE_EFFORT", ""),
"CLAUDE_MAX_BUDGET_USD": os.environ.get("CLAUDE_MAX_BUDGET_USD", ""),
"CLAUDE_ALLOWED_TOOLS": os.environ.get("CLAUDE_ALLOWED_TOOLS", ""),
"CLAUDE_DISALLOWED_TOOLS": os.environ.get("CLAUDE_DISALLOWED_TOOLS", ""),
"CLAUDE_EXTRA_ARGS": os.environ.get("CLAUDE_EXTRA_ARGS", ""),
"FEISHU_TOPIC_IDLE_SECONDS": os.environ.get("FEISHU_TOPIC_IDLE_SECONDS", "7200"),
"FEISHU_TOPIC_NOTICE_ENABLED": os.environ.get("FEISHU_TOPIC_NOTICE_ENABLED", "1"),
"FEISHU_TASK_PROGRESS_SECONDS": os.environ.get("FEISHU_TASK_PROGRESS_SECONDS", "7200"),
"FEISHU_ACK_TEXT": os.environ.get("FEISHU_ACK_TEXT", "收到,我要开始干活了,稍等我"),
}
env_path.write_text(
"\n".join(f"{key}={shlex.quote(value)}" for key, value in values.items()) + "\n",
encoding="utf-8",
)
PY
chmod 600 "$ENV_FILE"
cat > "$PLIST_PATH" <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>${LABEL}</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>${APP_DIR}/start_feishu_claude_code_bridge.sh</string>
</array>
<key>WorkingDirectory</key>
<string>${APP_DIR}</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>${RUNTIME_DIR}/feishu_claude_code_bridge.log</string>
<key>StandardErrorPath</key>
<string>${RUNTIME_DIR}/feishu_claude_code_bridge.log</string>
</dict>
</plist>
PLIST
launchctl bootout "gui/$(id -u)/${LABEL}" >/dev/null 2>&1 || true
launchctl bootout "gui/$(id -u)" "$PLIST_PATH" >/dev/null 2>&1 || true
launchctl bootstrap "gui/$(id -u)" "$PLIST_PATH"
launchctl kickstart -k "gui/$(id -u)/${LABEL}"
echo "FeishuClaudeCodeBridge installed."
echo "Service: ${LABEL}"
echo "Runtime: ${RUNTIME_DIR}"
echo "Logs: ${RUNTIME_DIR}/feishu_claude_code_bridge.log"
cat <<'NEXT'
Next required Feishu app checks:
1. In Feishu Developer Console, open Development Config > Events and Callbacks.
2. Use long connection for events/callbacks.
3. Add im.message.receive_v1 under subscribed events.
4. Add card.action.trigger under subscribed callbacks.
5. Publish a new app version after saving.
Then verify locally:
./bridge status
./bridge logs 30
Full checklist: docs/post-install.md
If card buttons show code 200340, card.action.trigger is not reaching this Bridge yet.
NEXT