@kolivri/memoreal-mcp 1.0.2 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/install.sh CHANGED
@@ -8,10 +8,28 @@ CONFIG_ENV="$MEMOREAL_DIR/config.env"
8
8
  LEGACY_CONFIG_ENV="$MEMORIA_DIR/config.env"
9
9
  SETTINGS_JSON="$HOME/.claude/settings.json"
10
10
  COMMANDS_DIR="$HOME/.claude/commands"
11
- OPENCODE_DIR="$HOME/.config/opencode"
11
+ OPENCODE_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/opencode"
12
12
  OPENCODE_JSON="$OPENCODE_DIR/opencode.json"
13
13
  SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
14
14
 
15
+ is_placeholder_key() {
16
+ local lower
17
+ lower="$(printf '%s' "$1" | tr '[:upper:]' '[:lower:]')"
18
+ case "$lower" in
19
+ ""|mem_dev_your_key_here*|mem_dev_...*|your_api_key*|todo*|xxx*|replace_with_your_key*)
20
+ return 0
21
+ ;;
22
+ esac
23
+ if printf '%s' "$lower" | grep -Eq '^<[a-z0-9_.-]+>$'; then
24
+ return 0
25
+ fi
26
+ return 1
27
+ }
28
+
29
+ has_jq() {
30
+ [ "${MEMOREAL_NO_JQ:-0}" != "1" ] && [ "${MEMORIA_NO_JQ:-0}" != "1" ] && type jq >/dev/null 2>&1
31
+ }
32
+
15
33
  # Preserve existing API key from ~/.memoreal/config.env or ~/.memoria/config.env
16
34
  EXISTING_API_KEY=""
17
35
  EXISTING_API_URL=""
@@ -19,6 +37,9 @@ for cfg in "$CONFIG_ENV" "$LEGACY_CONFIG_ENV"; do
19
37
  if [ -f "$cfg" ]; then
20
38
  if [ -z "$EXISTING_API_KEY" ]; then
21
39
  EXISTING_API_KEY="$(grep -E '^(MEMOREAL_API_KEY|MEMORIA_API_KEY|MEMOREAL_KEY|MEMORIA_KEY)=' "$cfg" 2>/dev/null | tail -n 1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" || true)"
40
+ if is_placeholder_key "$EXISTING_API_KEY"; then
41
+ EXISTING_API_KEY=""
42
+ fi
22
43
  fi
23
44
  if [ -z "$EXISTING_API_URL" ]; then
24
45
  EXISTING_API_URL="$(grep -E '^(MEMOREAL_API_URL|MEMORIA_API_URL|MEMOREAL_URL|MEMORIA_URL)=' "$cfg" 2>/dev/null | tail -n 1 | cut -d= -f2- | sed -e 's/^"//' -e 's/"$//' -e "s/^'//" -e "s/'$//" || true)"
@@ -26,15 +47,12 @@ for cfg in "$CONFIG_ENV" "$LEGACY_CONFIG_ENV"; do
26
47
  fi
27
48
  done
28
49
 
29
- # Memoreal Cloud MCP and HTTP API endpoints (defaulting to https://memoria.kolivri.com until DNS transition):
30
- MEMOREAL_URL="${MEMOREAL_URL:-${MEMORIA_URL:-https://memoria.kolivri.com/v1/mcp}}"
50
+ # Memoreal Cloud MCP and HTTP API endpoints:
51
+ MEMOREAL_URL="${MEMOREAL_URL:-${MEMORIA_URL:-https://memoreal.kolivri.com/v1/mcp}}"
31
52
  DEFAULT_API_URL="${MEMOREAL_URL%/v1/mcp}"
32
53
  DEFAULT_API_URL="${DEFAULT_API_URL%/}"
33
54
  MEMOREAL_API_URL="${MEMOREAL_API_URL:-${MEMORIA_API_URL:-${EXISTING_API_URL:-$DEFAULT_API_URL}}}"
34
55
  MEMOREAL_API_KEY="${MEMOREAL_API_KEY:-${MEMORIA_API_KEY:-${MEMOREAL_KEY:-${MEMORIA_KEY:-$EXISTING_API_KEY}}}}"
35
- MEMORIA_URL="$MEMOREAL_URL"
36
- MEMORIA_API_URL="$MEMOREAL_API_URL"
37
- MEMORIA_API_KEY="$MEMOREAL_API_KEY"
38
56
 
39
57
  # Validate URLs (require HTTPS for all remote hosts; allow HTTP only on local loopback for tests)
40
58
  validate_url() {
@@ -51,20 +69,200 @@ if ! validate_url "$MEMOREAL_URL" || ! validate_url "$MEMOREAL_API_URL"; then
51
69
  exit 1
52
70
  fi
53
71
 
54
- if [ -n "$MEMOREAL_API_KEY" ] && ! printf '%s' "$MEMOREAL_API_KEY" | grep -Eq '^[A-Za-z0-9_.-]+$'; then
55
- echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
56
- exit 1
72
+ if [ -n "$MEMOREAL_API_KEY" ]; then
73
+ if printf '%s' "$MEMOREAL_API_KEY" | grep -Eq '[;&|`$()]'; then
74
+ echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
75
+ exit 1
76
+ fi
77
+ if is_placeholder_key "$MEMOREAL_API_KEY"; then
78
+ MEMOREAL_API_KEY=""
79
+ fi
80
+ if [ -n "$MEMOREAL_API_KEY" ] && ! printf '%s' "$MEMOREAL_API_KEY" | grep -Eq '^[A-Za-z0-9_.-]+$'; then
81
+ echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
82
+ exit 1
83
+ fi
84
+ fi
85
+
86
+ # Interactive 3-Option TTY Setup Wizard
87
+ if [ -t 0 ] && [ -t 1 ] && [ "${MEMOREAL_NONINTERACTIVE:-0}" != "1" ] && [ "${MEMORIA_NONINTERACTIVE:-0}" != "1" ] && [ -z "$MEMOREAL_API_KEY" ]; then
88
+ echo ""
89
+ echo "Memoreal Cloud Authentication"
90
+ echo "----------------------------"
91
+ echo "No API key configured. Choose an authentication method:"
92
+ echo " 1) Connect via browser (recommended — 1-click device pairing)"
93
+ echo " 2) Paste existing API key"
94
+ echo " 3) Skip for now (configure later with /memoreal-connect)"
95
+ echo ""
96
+ printf "Select [1-3] (default: 1): "
97
+ read -r AUTH_CHOICE || AUTH_CHOICE=""
98
+ AUTH_CHOICE="${AUTH_CHOICE:-1}"
99
+
100
+ case "$AUTH_CHOICE" in
101
+ 1)
102
+ echo ""
103
+ echo "Initiating device pairing with $MEMOREAL_API_URL..."
104
+ CURL_FLAGS=(--connect-timeout 10 -m 30)
105
+ case "$MEMOREAL_API_URL" in
106
+ https://*)
107
+ CURL_FLAGS=(--proto =https --tlsv1.2 --connect-timeout 10 -m 30)
108
+ ;;
109
+ esac
110
+
111
+ START_RESP=""
112
+ if command -v curl >/dev/null 2>&1; then
113
+ START_RESP="$(curl -sS "${CURL_FLAGS[@]}" -X POST "$MEMOREAL_API_URL/v1/auth/device/start" \
114
+ -H "Content-Type: application/json" \
115
+ -d '{"client_name":"install.sh"}' 2>/dev/null || true)"
116
+ fi
117
+
118
+ DEVICE_INFO=""
119
+ if [ -n "$START_RESP" ]; then
120
+ if command -v node >/dev/null 2>&1; then
121
+ DEVICE_INFO="$(node -e '
122
+ try {
123
+ const d = JSON.parse(process.argv[1]);
124
+ if (d.device_code) {
125
+ console.log([d.device_code, d.user_code || "", d.verification_uri_complete || d.verification_uri || "", d.interval || 5, d.expires_in || 300].join("\t"));
126
+ }
127
+ } catch(e) {}
128
+ ' "$START_RESP" 2>/dev/null || true)"
129
+ elif has_jq; then
130
+ DEVICE_INFO="$(printf '%s' "$START_RESP" | jq -r '[.device_code, (.user_code // ""), (.verification_uri_complete // .verification_uri // ""), (.interval // 5), (.expires_in // 300)] | @tsv' 2>/dev/null || true)"
131
+ fi
132
+ fi
133
+
134
+ if [ -n "$DEVICE_INFO" ]; then
135
+ DEV_CODE="$(printf '%s' "$DEVICE_INFO" | cut -f1)"
136
+ DEV_USER_CODE="$(printf '%s' "$DEVICE_INFO" | cut -f2)"
137
+ DEV_URI="$(printf '%s' "$DEVICE_INFO" | cut -f3)"
138
+ DEV_INTERVAL="$(printf '%s' "$DEVICE_INFO" | cut -f4)"
139
+ DEV_EXPIRES="$(printf '%s' "$DEVICE_INFO" | cut -f5)"
140
+ DEV_INTERVAL="${DEV_INTERVAL:-5}"
141
+ DEV_EXPIRES="${DEV_EXPIRES:-300}"
142
+
143
+ if [ -z "$DEV_CODE" ] || ! printf '%s' "$DEV_CODE" | grep -Eq '^[A-Za-z0-9_.-]+$'; then
144
+ echo " Invalid device authorization response. Skipping browser flow."
145
+ else
146
+ echo ""
147
+ if [ -n "$DEV_USER_CODE" ]; then
148
+ echo " One-time code: $DEV_USER_CODE"
149
+ fi
150
+ echo " Authorize at: $DEV_URI"
151
+ echo ""
152
+
153
+ if [ "${MEMOREAL_SKIP_BROWSER_OPEN:-0}" != "1" ] && [ "${MEMORIA_SKIP_BROWSER_OPEN:-0}" != "1" ]; then
154
+ if printf '%s' "$DEV_URI" | grep -Eq '^(https://|http://localhost|http://127\.0\.0\.1)' && ! printf '%s' "$DEV_URI" | grep -Eq '[[:space:];&|`$()<>]'; then
155
+ if [ "$(uname -s 2>/dev/null)" = "Darwin" ]; then
156
+ open "$DEV_URI" 2>/dev/null || true
157
+ elif command -v xdg-open >/dev/null 2>&1; then
158
+ xdg-open "$DEV_URI" 2>/dev/null || true
159
+ elif command -v rundll32.exe >/dev/null 2>&1; then
160
+ rundll32.exe url.dll,FileProtocolHandler "$DEV_URI" 2>/dev/null || true
161
+ fi
162
+ fi
163
+ fi
164
+
165
+ echo "Waiting for authorization in browser (Ctrl+C to skip)..."
166
+ ELAPSED=0
167
+ while [ "$ELAPSED" -lt "$DEV_EXPIRES" ]; do
168
+ sleep "$DEV_INTERVAL"
169
+ ELAPSED=$((ELAPSED + DEV_INTERVAL))
170
+ POLL_RESP="$(curl -sS "${CURL_FLAGS[@]}" -X POST "$MEMOREAL_API_URL/v1/auth/device/poll" \
171
+ -H "Content-Type: application/json" \
172
+ -d "{\"device_code\":\"$DEV_CODE\"}" 2>/dev/null || true)"
173
+
174
+ POLL_KEY=""
175
+ POLL_STATUS=""
176
+ if [ -n "$POLL_RESP" ]; then
177
+ if command -v node >/dev/null 2>&1; then
178
+ POLL_KEY="$(node -e '
179
+ try {
180
+ const d = JSON.parse(process.argv[1]);
181
+ console.log(d.api_key || d.token || "");
182
+ } catch(e) {}
183
+ ' "$POLL_RESP" 2>/dev/null || true)"
184
+ POLL_STATUS="$(node -e '
185
+ try {
186
+ const d = JSON.parse(process.argv[1]);
187
+ console.log(d.error || d.status || "");
188
+ } catch(e) {}
189
+ ' "$POLL_RESP" 2>/dev/null || true)"
190
+ elif has_jq; then
191
+ POLL_KEY="$(printf '%s' "$POLL_RESP" | jq -r '(.api_key // .token // empty)' 2>/dev/null || true)"
192
+ POLL_STATUS="$(printf '%s' "$POLL_RESP" | jq -r '(.error // .status // empty)' 2>/dev/null || true)"
193
+ fi
194
+ fi
195
+
196
+ POLL_STATUS_LOWER="$(printf '%s' "$POLL_STATUS" | tr '[:upper:]' '[:lower:]')"
197
+ case "$POLL_STATUS_LOWER" in
198
+ denied|expired|access_denied|expired_token)
199
+ echo " Device authorization $POLL_STATUS. Skipping."
200
+ break
201
+ ;;
202
+ esac
203
+
204
+ if [ -n "$POLL_KEY" ]; then
205
+ if printf '%s' "$POLL_KEY" | grep -Eq '^[A-Za-z0-9_.-]+$' && ! is_placeholder_key "$POLL_KEY"; then
206
+ MEMOREAL_API_KEY="$POLL_KEY"
207
+ MEMORIA_API_KEY="$POLL_KEY"
208
+ echo " Successfully authorized via browser!"
209
+ break
210
+ fi
211
+ fi
212
+ done
213
+ fi
214
+ else
215
+ echo " Could not reach authorization endpoint. Skipping browser flow."
216
+ fi
217
+ ;;
218
+ 2)
219
+ echo ""
220
+ printf "Paste your API key (input hidden): "
221
+ stty -echo 2>/dev/null || true
222
+ read -r -s PASTED_KEY || PASTED_KEY=""
223
+ stty echo 2>/dev/null || true
224
+ printf "\n"
225
+ PASTED_KEY="$(printf '%s' "$PASTED_KEY" | tr -d '\r\n ')"
226
+ if [ -z "$PASTED_KEY" ]; then
227
+ echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
228
+ exit 1
229
+ fi
230
+ if printf '%s' "$PASTED_KEY" | grep -Eq '[;&|`$()]'; then
231
+ echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
232
+ exit 1
233
+ fi
234
+ if is_placeholder_key "$PASTED_KEY"; then
235
+ echo "Error: Placeholder key detected. Please provide a valid API key." >&2
236
+ exit 1
237
+ fi
238
+ if ! printf '%s' "$PASTED_KEY" | grep -Eq '^[A-Za-z0-9_.-]+$'; then
239
+ echo "Error: Invalid MEMOREAL_KEY format (only alphanumeric, '_', '.', '-' allowed)." >&2
240
+ exit 1
241
+ fi
242
+ MEMOREAL_API_KEY="$PASTED_KEY"
243
+ MEMORIA_API_KEY="$PASTED_KEY"
244
+ echo "API key set."
245
+ ;;
246
+ 3|*)
247
+ echo ""
248
+ echo "Skipping authentication. You can run /memoreal-connect later."
249
+ ;;
250
+ esac
57
251
  fi
58
252
 
253
+ MEMORIA_URL="$MEMOREAL_URL"
254
+ MEMORIA_API_URL="$MEMOREAL_API_URL"
255
+ MEMORIA_API_KEY="$MEMOREAL_API_KEY"
256
+
59
257
  echo "Memoreal - Claude Code & OpenCode Cloud Plugin"
60
258
  echo "=============================================="
61
259
  echo ""
62
260
  echo "Cloud API: $MEMOREAL_API_URL"
63
261
  echo "Cloud MCP: $MEMOREAL_URL"
64
262
  if [ -n "$MEMOREAL_API_KEY" ]; then
65
- echo "API Key: ${MEMOREAL_API_KEY:0:12}..."
263
+ echo "API Key: (configured — saved to config.env, mode 0600)"
66
264
  else
67
- echo "API Key: (not set — pass MEMOREAL_KEY=mem_dev_... to authenticate)"
265
+ echo "API Key: (not set — In-Chat Setup Wizard will run in Claude Code / OpenCode)"
68
266
  fi
69
267
  echo ""
70
268
 
@@ -76,13 +274,20 @@ chmod 700 "$MEMOREAL_DIR" "$BIN_DIR" 2>/dev/null || true
76
274
  if [ ! -e "$MEMORIA_DIR" ]; then
77
275
  ln -s "$MEMOREAL_DIR" "$MEMORIA_DIR" 2>/dev/null || mkdir -p "$MEMORIA_DIR"
78
276
  fi
277
+ if [ -d "$MEMORIA_DIR" ] && [ ! -L "$MEMORIA_DIR" ]; then
278
+ chmod 700 "$MEMORIA_DIR" 2>/dev/null || true
279
+ mkdir -p "$MEMORIA_DIR/bin" 2>/dev/null || true
280
+ chmod 700 "$MEMORIA_DIR/bin" 2>/dev/null || true
281
+ fi
79
282
 
80
283
  # --- Persist cloud configuration for SessionStart hooks and slash commands ---
81
284
  printf 'MEMOREAL_URL="%s"\nMEMOREAL_API_URL="%s"\nMEMOREAL_API_KEY="%s"\nMEMORIA_URL="%s"\nMEMORIA_API_URL="%s"\nMEMORIA_API_KEY="%s"\n' \
82
285
  "$MEMOREAL_URL" "$MEMOREAL_API_URL" "$MEMOREAL_API_KEY" \
83
- "$MEMOREAL_URL" "$MEMOREAL_API_URL" "$MEMOREAL_API_KEY" > "$CONFIG_ENV"
286
+ "$MEMORIA_URL" "$MEMORIA_API_URL" "$MEMORIA_API_KEY" > "$CONFIG_ENV"
84
287
  chmod 600 "$CONFIG_ENV" 2>/dev/null || true
85
- if [ ! -L "$MEMORIA_DIR" ] && [ -d "$MEMORIA_DIR" ] && [ "$MEMORIA_DIR" != "$MEMOREAL_DIR" ]; then
288
+ if [ ! -L "$LEGACY_CONFIG_ENV" ] && [ "$LEGACY_CONFIG_ENV" != "$CONFIG_ENV" ]; then
289
+ mkdir -p "$MEMORIA_DIR" 2>/dev/null || true
290
+ chmod 700 "$MEMORIA_DIR" 2>/dev/null || true
86
291
  cp "$CONFIG_ENV" "$LEGACY_CONFIG_ENV" 2>/dev/null || true
87
292
  chmod 600 "$LEGACY_CONFIG_ENV" 2>/dev/null || true
88
293
  fi
@@ -97,7 +302,7 @@ if [ -f "$BIN_DIR/memoreal-mcp" ]; then
97
302
  rm -f "$BIN_DIR/memoreal-mcp"
98
303
  fi
99
304
 
100
- # --- Install memoreal-ns and memoria-ns helpers ---
305
+ # --- Install memoreal-ns, memoria-ns, and hook helpers ---
101
306
  if [ -f "$SCRIPT_DIR/bin/memoreal-ns" ]; then
102
307
  cp "$SCRIPT_DIR/bin/memoreal-ns" "$BIN_DIR/memoreal-ns"
103
308
  chmod +x "$BIN_DIR/memoreal-ns"
@@ -106,6 +311,37 @@ if [ -f "$SCRIPT_DIR/bin/memoria-ns" ]; then
106
311
  cp "$SCRIPT_DIR/bin/memoria-ns" "$BIN_DIR/memoria-ns"
107
312
  chmod +x "$BIN_DIR/memoria-ns"
108
313
  fi
314
+ if [ -f "$SCRIPT_DIR/bin/memoreal-ns.mjs" ]; then
315
+ cp "$SCRIPT_DIR/bin/memoreal-ns.mjs" "$BIN_DIR/memoreal-ns.mjs"
316
+ chmod +x "$BIN_DIR/memoreal-ns.mjs" 2>/dev/null || true
317
+ fi
318
+ if [ -f "$SCRIPT_DIR/bin/memoreal-ns.cmd" ]; then
319
+ cp "$SCRIPT_DIR/bin/memoreal-ns.cmd" "$BIN_DIR/memoreal-ns.cmd"
320
+ fi
321
+ if [ -f "$SCRIPT_DIR/bin/memoreal-hook.mjs" ]; then
322
+ cp "$SCRIPT_DIR/bin/memoreal-hook.mjs" "$BIN_DIR/memoreal-hook.mjs"
323
+ chmod +x "$BIN_DIR/memoreal-hook.mjs" 2>/dev/null || true
324
+ fi
325
+
326
+ # Also maintain $MEMORIA_DIR/bin if separate directory
327
+ if [ ! -L "$MEMORIA_DIR" ] && [ "$MEMORIA_DIR/bin" != "$BIN_DIR" ]; then
328
+ mkdir -p "$MEMORIA_DIR/bin"
329
+ chmod 700 "$MEMORIA_DIR/bin" 2>/dev/null || true
330
+ for f in memoreal-ns memoria-ns memoreal-ns.mjs memoreal-ns.cmd memoreal-hook.mjs; do
331
+ if [ -f "$SCRIPT_DIR/bin/$f" ]; then
332
+ cp "$SCRIPT_DIR/bin/$f" "$MEMORIA_DIR/bin/$f"
333
+ if [ "${f%.cmd}" = "$f" ]; then
334
+ chmod +x "$MEMORIA_DIR/bin/$f" 2>/dev/null || true
335
+ fi
336
+ fi
337
+ done
338
+ fi
339
+
340
+ mkdir -p "$OPENCODE_DIR/bin"
341
+ if [ -f "$SCRIPT_DIR/bin/memoreal-ns.mjs" ]; then
342
+ cp "$SCRIPT_DIR/bin/memoreal-ns.mjs" "$OPENCODE_DIR/bin/memoreal-ns.mjs"
343
+ chmod +x "$OPENCODE_DIR/bin/memoreal-ns.mjs" 2>/dev/null || true
344
+ fi
109
345
 
110
346
  # --- Register MCP server (HTTP transport, shared across all Claude Code sessions) ---
111
347
  echo ""
@@ -116,14 +352,16 @@ if [ "${MEMOREAL_SKIP_CLAUDE_CLI:-${MEMORIA_SKIP_CLAUDE_CLI:-0}}" != "1" ] && co
116
352
  claude mcp remove -s user memoreal 2>/dev/null || true
117
353
  if [ -n "$MEMOREAL_API_KEY" ]; then
118
354
  claude mcp add -s user --transport http memoreal "$MEMOREAL_URL" --header "Authorization: Bearer $MEMOREAL_API_KEY"
355
+ claude mcp add -s user --transport http memoria "$MEMORIA_URL" --header "Authorization: Bearer $MEMORIA_API_KEY"
119
356
  else
120
357
  claude mcp add -s user --transport http memoreal "$MEMOREAL_URL"
358
+ claude mcp add -s user --transport http memoria "$MEMORIA_URL"
121
359
  fi
122
360
  echo " MCP registered (user scope, transport=http, url=$MEMOREAL_URL)"
123
361
  else
124
362
  echo " 'claude' CLI skipped or not found. Register manually:"
125
363
  if [ -n "$MEMOREAL_API_KEY" ]; then
126
- echo " claude mcp add -s user --transport http memoreal $MEMOREAL_URL --header \"Authorization: Bearer $MEMOREAL_API_KEY\""
364
+ echo " claude mcp add -s user --transport http memoreal $MEMOREAL_URL --header \"Authorization: Bearer \$MEMOREAL_API_KEY\""
127
365
  else
128
366
  echo " claude mcp add -s user --transport http memoreal $MEMOREAL_URL"
129
367
  fi
@@ -148,28 +386,49 @@ echo ""
148
386
  echo "Installing hooks..."
149
387
  HOOKS_JSON="$SCRIPT_DIR/hooks/hooks.json"
150
388
 
151
- if command -v jq >/dev/null 2>&1 && [ -f "$HOOKS_JSON" ]; then
152
- if [ -f "$SETTINGS_JSON" ]; then
153
- cp "$SETTINGS_JSON" "$SETTINGS_JSON.bak"
154
- jq --slurpfile plugin_hooks "$HOOKS_JSON" '
155
- .hooks //= {} |
156
- reduce ($plugin_hooks[0].hooks | to_entries[]) as $entry (
157
- .;
158
- .hooks[$entry.key] = (
159
- [(.hooks[$entry.key] // [])[] | select(
160
- (.hooks | tostring | test("\\[(memoreal|memoria)[\\]-]")) | not
161
- )] + $entry.value
389
+ if [ -f "$HOOKS_JSON" ]; then
390
+ if has_jq; then
391
+ if [ -f "$SETTINGS_JSON" ]; then
392
+ cp "$SETTINGS_JSON" "$SETTINGS_JSON.bak"
393
+ jq --slurpfile plugin_hooks "$HOOKS_JSON" '
394
+ .hooks //= {} |
395
+ reduce ($plugin_hooks[0].hooks | to_entries[]) as $entry (
396
+ .;
397
+ .hooks[$entry.key] = (
398
+ [(.hooks[$entry.key] // [])[] | select(
399
+ (.hooks | tostring | test("\\[(memoreal|memoria)[\\]-]")) | not
400
+ )] + $entry.value
401
+ )
162
402
  )
163
- )
164
- ' "$SETTINGS_JSON.bak" > "$SETTINGS_JSON"
403
+ ' "$SETTINGS_JSON.bak" > "$SETTINGS_JSON"
404
+ echo " Hooks merged into $SETTINGS_JSON"
405
+ else
406
+ mkdir -p "$(dirname "$SETTINGS_JSON")"
407
+ jq --slurpfile plugin_hooks "$HOOKS_JSON" -n '{ hooks: $plugin_hooks[0].hooks }' > "$SETTINGS_JSON"
408
+ echo " Created $SETTINGS_JSON with hooks"
409
+ fi
410
+ elif command -v node >/dev/null 2>&1; then
411
+ node -e '
412
+ const fs = require("fs");
413
+ const settingsFile = process.argv[1];
414
+ const hooksFile = process.argv[2];
415
+ let settings = {};
416
+ if (fs.existsSync(settingsFile)) {
417
+ try { settings = JSON.parse(fs.readFileSync(settingsFile, "utf8")); } catch(e) {}
418
+ } else {
419
+ const path = require("path");
420
+ fs.mkdirSync(path.dirname(settingsFile), { recursive: true });
421
+ }
422
+ settings.hooks = settings.hooks || {};
423
+ const pluginHooks = JSON.parse(fs.readFileSync(hooksFile, "utf8")).hooks || {};
424
+ for (const [key, val] of Object.entries(pluginHooks)) {
425
+ const existing = (settings.hooks[key] || []).filter(h => !/\[(memoreal|memoria)[\-]/.test(JSON.stringify(h)));
426
+ settings.hooks[key] = existing.concat(val);
427
+ }
428
+ fs.writeFileSync(settingsFile, JSON.stringify(settings, null, 2) + "\n");
429
+ ' "$SETTINGS_JSON" "$HOOKS_JSON"
165
430
  echo " Hooks merged into $SETTINGS_JSON"
166
- else
167
- mkdir -p "$(dirname "$SETTINGS_JSON")"
168
- jq --slurpfile plugin_hooks "$HOOKS_JSON" -n '{ hooks: $plugin_hooks[0].hooks }' > "$SETTINGS_JSON"
169
- echo " Created $SETTINGS_JSON with hooks"
170
431
  fi
171
- else
172
- echo " Warning: jq not found, skipping hook installation"
173
432
  fi
174
433
 
175
434
  # --- Install CLAUDE.md and OpenCode AGENTS.md instructions ---
@@ -217,116 +476,300 @@ if [ -f "$SCRIPT_DIR/opencode/memoria-hooks.js" ]; then
217
476
  echo " Installed $OPENCODE_DIR/plugins/memoria-hooks.js"
218
477
  fi
219
478
 
220
- if command -v jq >/dev/null 2>&1; then
221
- if [ -f "$OPENCODE_JSON" ]; then
222
- cp "$OPENCODE_JSON" "$OPENCODE_JSON.bak"
223
- jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
224
- .mcp //= {} |
225
- .mcp.memoreal = ((.mcp.memoreal // {}) + { "type": "remote", "url": $url, "enabled": true } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
226
- ' "$OPENCODE_JSON.bak" > "$OPENCODE_JSON"
227
- chmod 600 "$OPENCODE_JSON" 2>/dev/null || true
228
- echo " Updated MCP server in $OPENCODE_JSON"
229
- else
230
- jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
231
- "$schema": "https://opencode.ai/config.json",
232
- "mcp": {
233
- "memoreal": ({
234
- "type": "remote",
235
- "url": $url,
236
- "enabled": true
237
- } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
479
+ upsert_opencode_json() {
480
+ mkdir -p "$(dirname "$OPENCODE_JSON")"
481
+ if has_jq; then
482
+ local tmp
483
+ tmp="$(mktemp 2>/dev/null || echo "$OPENCODE_JSON.tmp")"
484
+ if [ -f "$OPENCODE_JSON" ]; then
485
+ cp "$OPENCODE_JSON" "$OPENCODE_JSON.bak"
486
+ jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
487
+ .mcp //= {} |
488
+ .mcp.memoreal = (
489
+ ((.mcp.memoreal // {}) + { "type": "remote", "url": $url, "enabled": true })
490
+ | if ($key | length) > 0 then .headers = { "Authorization": ("Bearer " + $key) } else del(.headers) end
491
+ ) |
492
+ .mcp.memoria = (
493
+ ((.mcp.memoria // {}) + { "type": "remote", "url": $url, "enabled": true })
494
+ | if ($key | length) > 0 then .headers = { "Authorization": ("Bearer " + $key) } else del(.headers) end
495
+ )
496
+ ' "$OPENCODE_JSON.bak" > "$tmp" && mv "$tmp" "$OPENCODE_JSON"
497
+ else
498
+ jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
499
+ "$schema": "https://opencode.ai/config.json",
500
+ "mcp": {
501
+ "memoreal": ({ "type": "remote", "url": $url, "enabled": true } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end)),
502
+ "memoria": ({ "type": "remote", "url": $url, "enabled": true } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
503
+ }
504
+ }' > "$tmp" && mv "$tmp" "$OPENCODE_JSON"
505
+ fi
506
+ elif command -v node >/dev/null 2>&1; then
507
+ node -e '
508
+ const fs = require("fs");
509
+ const file = process.argv[1];
510
+ const url = process.argv[2];
511
+ const key = process.argv[3];
512
+ let doc = { "$schema": "https://opencode.ai/config.json", mcp: {} };
513
+ if (fs.existsSync(file)) {
514
+ try { doc = JSON.parse(fs.readFileSync(file, "utf8")); } catch(e) {}
238
515
  }
239
- }' > "$OPENCODE_JSON"
240
- chmod 600 "$OPENCODE_JSON" 2>/dev/null || true
241
- echo " Created $OPENCODE_JSON with Memoreal Cloud MCP"
516
+ doc.mcp = doc.mcp || {};
517
+ const base = { type: "remote", url, enabled: true };
518
+ doc.mcp.memoreal = Object.assign({}, doc.mcp.memoreal || {}, base);
519
+ doc.mcp.memoria = Object.assign({}, doc.mcp.memoria || {}, base);
520
+ if (key) {
521
+ doc.mcp.memoreal.headers = { Authorization: "Bearer " + key };
522
+ doc.mcp.memoria.headers = { Authorization: "Bearer " + key };
523
+ } else {
524
+ delete doc.mcp.memoreal.headers;
525
+ delete doc.mcp.memoria.headers;
526
+ }
527
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
528
+ ' "$OPENCODE_JSON" "$MEMOREAL_URL" "$MEMOREAL_API_KEY"
242
529
  fi
530
+ chmod 600 "$OPENCODE_JSON" 2>/dev/null || true
531
+ echo " Updated MCP servers in $OPENCODE_JSON"
532
+ }
243
533
 
244
- upsert_mcp_servers_json() {
245
- local TARGET_JSON="$1"
246
- local LABEL="$2"
247
- mkdir -p "$(dirname "$TARGET_JSON")"
534
+ upsert_mcp_servers_json() {
535
+ local TARGET_JSON="$1"
536
+ local LABEL="$2"
537
+ mkdir -p "$(dirname "$TARGET_JSON")"
538
+ if has_jq; then
539
+ local tmp
540
+ tmp="$(mktemp 2>/dev/null || echo "$TARGET_JSON.tmp")"
248
541
  if [ -f "$TARGET_JSON" ]; then
249
542
  cp "$TARGET_JSON" "$TARGET_JSON.bak"
250
543
  jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
251
544
  .mcpServers //= {} |
252
- .mcpServers.memoreal = ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
253
- ' "$TARGET_JSON.bak" > "$TARGET_JSON"
254
- chmod 600 "$TARGET_JSON" 2>/dev/null || true
545
+ .mcpServers.memoreal = (
546
+ ((.mcpServers.memoreal // {}) + { "type": "http", "url": $url })
547
+ | if ($key | length) > 0 then .headers = { "Authorization": ("Bearer " + $key) } else del(.headers) end
548
+ ) |
549
+ .mcpServers.memoria = (
550
+ ((.mcpServers.memoria // {}) + { "type": "http", "url": $url })
551
+ | if ($key | length) > 0 then .headers = { "Authorization": ("Bearer " + $key) } else del(.headers) end
552
+ )
553
+ ' "$TARGET_JSON.bak" > "$tmp" && mv "$tmp" "$TARGET_JSON"
255
554
  echo " Updated $LABEL MCP config in $TARGET_JSON"
256
555
  else
257
556
  jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
258
557
  "mcpServers": {
259
- "memoreal": ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
558
+ "memoreal": ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end)),
559
+ "memoria": ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
260
560
  }
261
- }' > "$TARGET_JSON"
262
- chmod 600 "$TARGET_JSON" 2>/dev/null || true
561
+ }' > "$tmp" && mv "$tmp" "$TARGET_JSON"
263
562
  echo " Configured $LABEL MCP in $TARGET_JSON"
264
563
  fi
265
- }
266
-
267
- upsert_mcp_servers_json "$HOME/.cursor/mcp.json" "Cursor"
268
- upsert_mcp_servers_json "$HOME/.codeium/windsurf/mcp_config.json" "Windsurf"
269
- upsert_mcp_servers_json "$HOME/.codex/mcp.json" "OpenAI Codex CLI"
270
- upsert_mcp_servers_json "$HOME/.gemini/settings.json" "Gemini CLI"
271
- upsert_mcp_servers_json "$HOME/.vscode/mcp.json" "VS Code / GitHub Copilot"
272
- upsert_mcp_servers_json "$HOME/.cline/mcp_settings.json" "Cline"
273
- upsert_mcp_servers_json "$HOME/.roo/mcp.json" "Roo Code"
274
- upsert_mcp_servers_json "$HOME/.kilocode/mcp.json" "Kilo Code"
275
- upsert_mcp_servers_json "$HOME/.continue/mcpServers/memoreal.json" "Continue.dev"
276
- upsert_mcp_servers_json "$HOME/.config/goose/mcp.json" "Goose"
277
- upsert_mcp_servers_json "$HOME/.config/amp/settings.json" "Amp"
278
-
279
- # Zed uses .context_servers.memoreal
280
- ZED_SETTINGS="$HOME/.config/zed/settings.json"
281
- mkdir -p "$(dirname "$ZED_SETTINGS")"
282
- if [ -f "$ZED_SETTINGS" ]; then
283
- cp "$ZED_SETTINGS" "$ZED_SETTINGS.bak"
284
- jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
285
- .context_servers //= {} |
286
- .context_servers.memoreal = ({ "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
287
- ' "$ZED_SETTINGS.bak" > "$ZED_SETTINGS" 2>/dev/null || cp "$ZED_SETTINGS.bak" "$ZED_SETTINGS"
288
- chmod 600 "$ZED_SETTINGS" 2>/dev/null || true
289
- echo " Updated Zed MCP config in $ZED_SETTINGS"
290
- else
291
- jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
292
- "context_servers": {
293
- "memoreal": ({ "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
564
+ elif command -v node >/dev/null 2>&1; then
565
+ node -e '
566
+ const fs = require("fs");
567
+ const file = process.argv[1];
568
+ const url = process.argv[2];
569
+ const key = process.argv[3];
570
+ let doc = { mcpServers: {} };
571
+ if (fs.existsSync(file)) {
572
+ try { doc = JSON.parse(fs.readFileSync(file, "utf8")); } catch(e) {}
573
+ }
574
+ doc.mcpServers = doc.mcpServers || {};
575
+ const base = { type: "http", url };
576
+ doc.mcpServers.memoreal = Object.assign({}, doc.mcpServers.memoreal || {}, base);
577
+ doc.mcpServers.memoria = Object.assign({}, doc.mcpServers.memoria || {}, base);
578
+ if (key) {
579
+ doc.mcpServers.memoreal.headers = { Authorization: "Bearer " + key };
580
+ doc.mcpServers.memoria.headers = { Authorization: "Bearer " + key };
581
+ } else {
582
+ delete doc.mcpServers.memoreal.headers;
583
+ delete doc.mcpServers.memoria.headers;
294
584
  }
295
- }' > "$ZED_SETTINGS"
296
- chmod 600 "$ZED_SETTINGS" 2>/dev/null || true
297
- echo " Configured Zed MCP in $ZED_SETTINGS"
585
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
586
+ ' "$TARGET_JSON" "$MEMOREAL_URL" "$MEMOREAL_API_KEY"
587
+ echo " Configured $LABEL MCP in $TARGET_JSON"
298
588
  fi
589
+ chmod 600 "$TARGET_JSON" 2>/dev/null || true
590
+ }
299
591
 
300
- if [ "$(uname -s 2>/dev/null || echo '')" = "Darwin" ]; then
301
- upsert_mcp_servers_json "$HOME/Library/Application Support/Claude/claude_desktop_config.json" "Claude Desktop"
302
- else
303
- upsert_mcp_servers_json "$HOME/.config/Claude/claude_desktop_config.json" "Claude Desktop"
592
+ upsert_continue_json() {
593
+ local TARGET_JSON="$1"
594
+ local SERVER_NAME="$2"
595
+ mkdir -p "$(dirname "$TARGET_JSON")"
596
+ if has_jq; then
597
+ local tmp
598
+ tmp="$(mktemp 2>/dev/null || echo "$TARGET_JSON.tmp")"
599
+ jq -n --arg name "$SERVER_NAME" --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
600
+ "name": $name,
601
+ "type": "http",
602
+ "url": $url,
603
+ "mcpServers": {
604
+ ($name): ({ "type": "http", "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
605
+ }
606
+ } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end)' > "$tmp" && mv "$tmp" "$TARGET_JSON"
607
+ elif command -v node >/dev/null 2>&1; then
608
+ node -e '
609
+ const fs = require("fs");
610
+ const file = process.argv[1];
611
+ const name = process.argv[2];
612
+ const url = process.argv[3];
613
+ const key = process.argv[4];
614
+ const entry = { type: "http", url };
615
+ if (key) entry.headers = { Authorization: "Bearer " + key };
616
+ const doc = {
617
+ name,
618
+ type: "http",
619
+ url,
620
+ mcpServers: { [name]: entry }
621
+ };
622
+ if (key) doc.headers = { Authorization: "Bearer " + key };
623
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
624
+ ' "$TARGET_JSON" "$SERVER_NAME" "$MEMOREAL_URL" "$MEMOREAL_API_KEY"
304
625
  fi
626
+ chmod 600 "$TARGET_JSON" 2>/dev/null || true
627
+ echo " Configured Continue.dev ($SERVER_NAME) MCP in $TARGET_JSON"
628
+ }
629
+
630
+ upsert_zed_json() {
631
+ local TARGET_JSON="$HOME/.config/zed/settings.json"
632
+ mkdir -p "$(dirname "$TARGET_JSON")"
633
+ if has_jq; then
634
+ local tmp
635
+ tmp="$(mktemp 2>/dev/null || echo "$TARGET_JSON.tmp")"
636
+ if [ -f "$TARGET_JSON" ]; then
637
+ cp "$TARGET_JSON" "$TARGET_JSON.bak"
638
+ jq --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '
639
+ .context_servers //= {} |
640
+ .context_servers.memoreal = (
641
+ ((.context_servers.memoreal // {}) + { "url": $url })
642
+ | if ($key | length) > 0 then .headers = { "Authorization": ("Bearer " + $key) } else del(.headers) end
643
+ ) |
644
+ .context_servers.memoria = (
645
+ ((.context_servers.memoria // {}) + { "url": $url })
646
+ | if ($key | length) > 0 then .headers = { "Authorization": ("Bearer " + $key) } else del(.headers) end
647
+ )
648
+ ' "$TARGET_JSON.bak" > "$tmp" 2>/dev/null && mv "$tmp" "$TARGET_JSON" || cp "$TARGET_JSON.bak" "$TARGET_JSON"
649
+ echo " Updated Zed MCP config in $TARGET_JSON"
650
+ else
651
+ jq -n --arg url "$MEMOREAL_URL" --arg key "$MEMOREAL_API_KEY" '{
652
+ "context_servers": {
653
+ "memoreal": ({ "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end)),
654
+ "memoria": ({ "url": $url } + (if ($key | length) > 0 then { "headers": { "Authorization": ("Bearer " + $key) } } else {} end))
655
+ }
656
+ }' > "$tmp" 2>/dev/null && mv "$tmp" "$TARGET_JSON"
657
+ echo " Configured Zed MCP in $TARGET_JSON"
658
+ fi
659
+ elif command -v node >/dev/null 2>&1; then
660
+ node -e '
661
+ const fs = require("fs");
662
+ const file = process.argv[1];
663
+ const url = process.argv[2];
664
+ const key = process.argv[3];
665
+ let doc = { context_servers: {} };
666
+ if (fs.existsSync(file)) {
667
+ try { doc = JSON.parse(fs.readFileSync(file, "utf8")); } catch(e) {}
668
+ }
669
+ doc.context_servers = doc.context_servers || {};
670
+ const base = { url };
671
+ doc.context_servers.memoreal = Object.assign({}, doc.context_servers.memoreal || {}, base);
672
+ doc.context_servers.memoria = Object.assign({}, doc.context_servers.memoria || {}, base);
673
+ if (key) {
674
+ doc.context_servers.memoreal.headers = { Authorization: "Bearer " + key };
675
+ doc.context_servers.memoria.headers = { Authorization: "Bearer " + key };
676
+ } else {
677
+ delete doc.context_servers.memoreal.headers;
678
+ delete doc.context_servers.memoria.headers;
679
+ }
680
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
681
+ ' "$TARGET_JSON" "$MEMOREAL_URL" "$MEMOREAL_API_KEY"
682
+ echo " Configured Zed MCP in $TARGET_JSON"
683
+ fi
684
+ chmod 600 "$TARGET_JSON" 2>/dev/null || true
685
+ }
686
+
687
+ upsert_opencode_json
688
+ upsert_mcp_servers_json "$HOME/.cursor/mcp.json" "Cursor"
689
+ upsert_mcp_servers_json "$HOME/.codeium/windsurf/mcp_config.json" "Windsurf"
690
+ upsert_mcp_servers_json "$HOME/.codex/mcp.json" "OpenAI Codex CLI"
691
+ upsert_mcp_servers_json "$HOME/.gemini/settings.json" "Gemini CLI"
692
+ upsert_mcp_servers_json "$HOME/.vscode/mcp.json" "VS Code / GitHub Copilot"
693
+ upsert_mcp_servers_json "$HOME/.cline/mcp_settings.json" "Cline"
694
+ upsert_mcp_servers_json "$HOME/.roo/mcp.json" "Roo Code"
695
+ upsert_mcp_servers_json "$HOME/.kilocode/mcp.json" "Kilo Code"
696
+ upsert_continue_json "$HOME/.continue/mcpServers/memoreal.json" "memoreal"
697
+ upsert_continue_json "$HOME/.continue/mcpServers/memoria.json" "memoria"
698
+ upsert_mcp_servers_json "$HOME/.config/goose/mcp.json" "Goose"
699
+ upsert_mcp_servers_json "$HOME/.config/amp/settings.json" "Amp"
700
+ upsert_zed_json
701
+
702
+ if [ "$(uname -s 2>/dev/null || echo '')" = "Darwin" ]; then
703
+ upsert_mcp_servers_json "$HOME/Library/Application Support/Claude/claude_desktop_config.json" "Claude Desktop"
704
+ else
705
+ upsert_mcp_servers_json "$HOME/.config/Claude/claude_desktop_config.json" "Claude Desktop"
305
706
  fi
306
707
 
307
708
  # --- Clean up stale config from old installs ---
308
709
  STALE_MCP="$HOME/.claude/.mcp.json"
309
- if [ -f "$STALE_MCP" ] && command -v jq >/dev/null 2>&1; then
310
- if jq -e '.mcpServers.memoria // .mcpServers.memoreal' "$STALE_MCP" >/dev/null 2>&1; then
311
- jq 'del(.mcpServers.memoria) | del(.mcpServers.memoreal) | if .mcpServers == {} then del(.mcpServers) else . end' "$STALE_MCP" > "$STALE_MCP.tmp"
312
- if [ "$(jq 'length' "$STALE_MCP.tmp" 2>/dev/null)" = "0" ]; then
313
- rm -f "$STALE_MCP" "$STALE_MCP.tmp"
314
- else
315
- mv "$STALE_MCP.tmp" "$STALE_MCP"
710
+ if [ -f "$STALE_MCP" ]; then
711
+ if has_jq; then
712
+ if jq -e '.mcpServers.memoria // .mcpServers.memoreal' "$STALE_MCP" >/dev/null 2>&1; then
713
+ jq 'del(.mcpServers.memoria) | del(.mcpServers.memoreal) | if .mcpServers == {} then del(.mcpServers) else . end' "$STALE_MCP" > "$STALE_MCP.tmp"
714
+ if [ "$(jq 'length' "$STALE_MCP.tmp" 2>/dev/null)" = "0" ]; then
715
+ rm -f "$STALE_MCP" "$STALE_MCP.tmp"
716
+ else
717
+ mv "$STALE_MCP.tmp" "$STALE_MCP"
718
+ fi
719
+ echo " Cleaned stale .mcp.json"
316
720
  fi
317
- echo " Cleaned stale .mcp.json"
721
+ elif command -v node >/dev/null 2>&1; then
722
+ node -e '
723
+ const fs = require("fs");
724
+ const file = process.argv[1];
725
+ try {
726
+ const doc = JSON.parse(fs.readFileSync(file, "utf8"));
727
+ if (doc.mcpServers && (doc.mcpServers.memoria || doc.mcpServers.memoreal)) {
728
+ delete doc.mcpServers.memoria;
729
+ delete doc.mcpServers.memoreal;
730
+ if (Object.keys(doc.mcpServers).length === 0) delete doc.mcpServers;
731
+ if (Object.keys(doc).length === 0) {
732
+ fs.unlinkSync(file);
733
+ } else {
734
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
735
+ }
736
+ }
737
+ } catch(e) {}
738
+ ' "$STALE_MCP"
318
739
  fi
319
740
  fi
320
741
 
321
- if [ -f "$SETTINGS_JSON" ] && command -v jq >/dev/null 2>&1; then
322
- if jq -e '.mcpServers.memoria' "$SETTINGS_JSON" >/dev/null 2>&1; then
323
- cp "$SETTINGS_JSON" "$SETTINGS_JSON.bak"
324
- jq 'del(.mcpServers.memoria)' "$SETTINGS_JSON.bak" > "$SETTINGS_JSON"
325
- echo " Cleaned stale mcpServers from settings"
326
- fi
327
- if jq -e '.enabledPlugins["memoria@local-plugins"]' "$SETTINGS_JSON" >/dev/null 2>&1; then
328
- jq 'del(.enabledPlugins["memoria@local-plugins"])' "$SETTINGS_JSON" > "$SETTINGS_JSON.tmp" \
329
- && mv "$SETTINGS_JSON.tmp" "$SETTINGS_JSON"
742
+ if [ -f "$SETTINGS_JSON" ]; then
743
+ if has_jq; then
744
+ if jq -e '.mcpServers.memoria' "$SETTINGS_JSON" >/dev/null 2>&1; then
745
+ cp "$SETTINGS_JSON" "$SETTINGS_JSON.bak"
746
+ jq 'del(.mcpServers.memoria)' "$SETTINGS_JSON.bak" > "$SETTINGS_JSON"
747
+ echo " Cleaned stale mcpServers from settings"
748
+ fi
749
+ if jq -e '.enabledPlugins["memoria@local-plugins"]' "$SETTINGS_JSON" >/dev/null 2>&1; then
750
+ jq 'del(.enabledPlugins["memoria@local-plugins"])' "$SETTINGS_JSON" > "$SETTINGS_JSON.tmp" \
751
+ && mv "$SETTINGS_JSON.tmp" "$SETTINGS_JSON"
752
+ fi
753
+ elif command -v node >/dev/null 2>&1; then
754
+ node -e '
755
+ const fs = require("fs");
756
+ const file = process.argv[1];
757
+ try {
758
+ const doc = JSON.parse(fs.readFileSync(file, "utf8"));
759
+ let modified = false;
760
+ if (doc.mcpServers && doc.mcpServers.memoria) {
761
+ delete doc.mcpServers.memoria;
762
+ modified = true;
763
+ }
764
+ if (doc.enabledPlugins && doc.enabledPlugins["memoria@local-plugins"]) {
765
+ delete doc.enabledPlugins["memoria@local-plugins"];
766
+ modified = true;
767
+ }
768
+ if (modified) {
769
+ fs.writeFileSync(file, JSON.stringify(doc, null, 2) + "\n");
770
+ }
771
+ } catch(e) {}
772
+ ' "$SETTINGS_JSON"
330
773
  fi
331
774
  fi
332
775
 
@@ -340,7 +783,10 @@ echo " Cloud MCP: $MEMOREAL_URL"
340
783
  echo " Clients: Claude Code, Cursor, Windsurf, OpenCode, Claude Desktop, Codex CLI, Gemini CLI, VS Code, Zed, Cline, Roo Code, Kilo Code, Continue, Goose, Amp"
341
784
  echo " Config: $CONFIG_ENV (fallback: $LEGACY_CONFIG_ENV)"
342
785
  echo " Hooks: $SETTINGS_JSON & $OPENCODE_DIR/plugins/memoreal-hooks.js"
343
- echo " Commands: /memoreal-sync, /memoreal-sync-code, /memoreal-wrap-up, /memoreal-doctor (aliases: /memoria-*)"
786
+ echo " Commands: /memoreal-connect, /memoreal-sync, /memoreal-sync-code, /memoreal-wrap-up, /memoreal-doctor (aliases: /memoria-*)"
787
+ if [ -z "$MEMOREAL_API_KEY" ]; then
788
+ echo " Wizard: Unregistered — run /memoreal-connect or click the In-Chat Setup Wizard to activate 1,000 free calls"
789
+ fi
344
790
  echo ""
345
791
  echo "Restart your AI coding client to activate."
346
792
  echo ""