-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·280 lines (243 loc) · 7.68 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·280 lines (243 loc) · 7.68 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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
#!/bin/bash
#
# datacore-messaging installer
# Interactive setup with auto-start of relay and GUI
#
set -e
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
CLAUDE_SETTINGS="$HOME/.claude/settings.json"
echo "╔════════════════════════════════════════════╗"
echo "║ datacore-messaging installer ║"
echo "╚════════════════════════════════════════════╝"
echo ""
# 1. Install Python dependencies
echo "📦 Installing Python dependencies..."
pip3 install --user PyQt6 websockets pyyaml aiohttp >/dev/null 2>&1 || {
echo " Warning: Some dependencies may have failed."
pip3 install --user websockets pyyaml aiohttp >/dev/null 2>&1
}
echo " ✓ Dependencies installed"
echo ""
# 2. Interactive configuration
echo "⚙️ Configuration"
echo ""
# Get username
DEFAULT_USER="${USER:-$(whoami)}"
read -p " Your username [$DEFAULT_USER]: " INPUT_USER
USERNAME="${INPUT_USER:-$DEFAULT_USER}"
# Get relay secret
read -p " Team relay secret (shared with teammates): " RELAY_SECRET
if [ -z "$RELAY_SECRET" ]; then
RELAY_SECRET=$(openssl rand -hex 16)
echo " Generated secret: $RELAY_SECRET"
echo " (Share this with your team members)"
fi
# Get whitelist
echo ""
echo " Who can message your Claude agent? (comma-separated usernames)"
echo " Leave empty to allow everyone, or enter names like: gregor,crt"
read -p " Claude whitelist: " WHITELIST_INPUT
# Get relay URL
echo ""
echo " Relay server - how will your team connect?"
echo ""
echo " ws:// options (no SSL - for LAN/internal use):"
echo " 1) Local only - ws://localhost:8080/ws (testing on this machine)"
echo " 2) LAN host - ws://<your-ip>:8080/ws (you host for team)"
echo " 3) Custom ws:// URL (internal server)"
echo ""
echo " wss:// options (with SSL - for public internet):"
echo " 4) Datafund relay - wss://datacore-messaging-relay.datafund.ai/ws"
echo " 5) Custom wss:// URL (your own SSL relay)"
echo ""
read -p " Choice [4]: " RELAY_CHOICE
case "$RELAY_CHOICE" in
1)
RELAY_URL="ws://localhost:8080/ws"
RELAY_HOST="true"
echo " → Local testing mode, you'll host the relay"
;;
2)
LOCAL_IP=$(ipconfig getifaddr en0 2>/dev/null || hostname -I 2>/dev/null | awk '{print $1}')
echo ""
echo " Your LAN IP: $LOCAL_IP"
echo " Teammates should use: ws://$LOCAL_IP:8080/ws"
RELAY_URL="ws://0.0.0.0:8080/ws"
RELAY_HOST="true"
;;
3)
echo ""
echo " Enter ws:// URL (e.g., ws://192.168.1.100:8080/ws)"
read -p " Relay URL: " RELAY_URL
RELAY_HOST="false"
;;
5)
echo ""
echo " Enter wss:// URL (e.g., wss://relay.yourcompany.com/ws)"
read -p " Relay URL: " RELAY_URL
RELAY_HOST="false"
;;
*)
# Default: Datafund relay (wss://)
RELAY_URL="wss://datacore-messaging-relay.datafund.ai/ws"
RELAY_HOST="false"
echo " → Using Datafund public relay (wss://)"
;;
esac
# Get default space
DEFAULT_SPACE=""
for dir in ~/Data/[1-9]-*/; do
if [ -d "$dir" ]; then
DEFAULT_SPACE=$(basename "$dir")
break
fi
done
DEFAULT_SPACE="${DEFAULT_SPACE:-1-team}"
read -p " Default space [$DEFAULT_SPACE]: " INPUT_SPACE
SPACE="${INPUT_SPACE:-$DEFAULT_SPACE}"
echo ""
# 3. Write settings file
echo "📝 Writing settings.local.yaml..."
# Build whitelist YAML
if [ -n "$WHITELIST_INPUT" ]; then
WHITELIST_YAML="claude_whitelist:"
IFS=',' read -ra USERS <<< "$WHITELIST_INPUT"
for user in "${USERS[@]}"; do
user=$(echo "$user" | xargs) # trim whitespace
WHITELIST_YAML="$WHITELIST_YAML
- $user"
done
else
WHITELIST_YAML="claude_whitelist: [] # Empty = allow everyone"
fi
cat > "$SCRIPT_DIR/settings.local.yaml" << EOF
# datacore-messaging settings
# Generated by install.sh
identity:
name: $USERNAME
# Your Claude agent: @${USERNAME}-claude
messaging:
default_space: $SPACE
# Users allowed to message @${USERNAME}-claude
$WHITELIST_YAML
relay:
secret: "$RELAY_SECRET"
url: "$RELAY_URL"
EOF
echo " ✓ Settings saved to $SCRIPT_DIR/settings.local.yaml"
echo ""
# 4. Install Claude Code hook
echo "🔗 Installing Claude Code hook..."
mkdir -p "$HOME/.claude"
if [ -f "$CLAUDE_SETTINGS" ]; then
if grep -q "inbox-watcher.py" "$CLAUDE_SETTINGS" 2>/dev/null; then
echo " ✓ Hook already installed"
else
cp "$CLAUDE_SETTINGS" "$CLAUDE_SETTINGS.backup"
python3 - "$CLAUDE_SETTINGS" "$SCRIPT_DIR" <<'PYTHON'
import json
import sys
settings_file = sys.argv[1]
script_dir = sys.argv[2]
with open(settings_file, 'r') as f:
settings = json.load(f)
if 'hooks' not in settings:
settings['hooks'] = {}
if 'UserPromptSubmit' not in settings['hooks']:
settings['hooks']['UserPromptSubmit'] = []
hook_cmd = f"{script_dir}/hooks/inbox-watcher.py"
already_added = any(hook_cmd in str(entry) for entry in settings['hooks']['UserPromptSubmit'])
if not already_added:
settings['hooks']['UserPromptSubmit'].append({
"hooks": [{"type": "command", "command": hook_cmd}]
})
with open(settings_file, 'w') as f:
json.dump(settings, f, indent=2)
PYTHON
echo " ✓ Hook added (backup: $CLAUDE_SETTINGS.backup)"
fi
else
cat > "$CLAUDE_SETTINGS" << EOF
{
"hooks": {
"UserPromptSubmit": [
{
"hooks": [
{
"type": "command",
"command": "$SCRIPT_DIR/hooks/inbox-watcher.py"
}
]
}
]
}
}
EOF
echo " ✓ Created $CLAUDE_SETTINGS with hook"
fi
echo ""
# 5. Create launch script
echo "🚀 Creating launch script..."
if [ "$RELAY_HOST" = "true" ]; then
# Hosting: run unified app with --host
cat > "$SCRIPT_DIR/start.sh" << EOF
#!/bin/bash
cd "$SCRIPT_DIR"
echo "Starting Datacore Messaging (hosting relay)..."
RELAY_SECRET="$RELAY_SECRET" python3 datacore-msg.py --host
EOF
else
# Client: just connect
cat > "$SCRIPT_DIR/start.sh" << EOF
#!/bin/bash
cd "$SCRIPT_DIR"
echo "Starting Datacore Messaging..."
python3 datacore-msg.py
EOF
fi
chmod +x "$SCRIPT_DIR/start.sh"
echo " ✓ Created start.sh"
echo ""
# 6. Ask to start now
echo "╔════════════════════════════════════════════╗"
echo "║ Installation complete! ║"
echo "╚════════════════════════════════════════════╝"
echo ""
echo "Your settings:"
echo " Username: @$USERNAME"
echo " Claude: @${USERNAME}-claude"
echo " Space: $SPACE"
echo " Relay: $RELAY_URL"
if [ -n "$WHITELIST_INPUT" ]; then
echo " Whitelist: $WHITELIST_INPUT"
else
echo " Whitelist: (everyone allowed)"
fi
echo ""
echo "To start messaging:"
echo " $SCRIPT_DIR/start.sh"
echo ""
echo "Or directly:"
echo " python3 $SCRIPT_DIR/datacore-msg.py"
if [ "$RELAY_HOST" = "true" ]; then
echo " python3 $SCRIPT_DIR/datacore-msg.py --host # with relay"
fi
echo ""
read -p "Start messaging now? [Y/n]: " START_NOW
if [[ "$START_NOW" != "n" && "$START_NOW" != "N" ]]; then
echo ""
echo "Starting..."
cd "$SCRIPT_DIR"
if [ "$RELAY_HOST" = "true" ]; then
RELAY_SECRET="$RELAY_SECRET" python3 datacore-msg.py --host &
else
python3 datacore-msg.py &
fi
sleep 3
echo ""
echo "✓ Messaging is running!"
echo " Send messages: @username message"
echo " Message your Claude: @claude task"
echo ""
echo "Restart Claude Code to activate the inbox hook."
fi