fix(installer): atomic plugins write and valid json defaults for install flags
This commit is contained in:
@@ -14,8 +14,8 @@ NO_REPLY_PROVIDER_ID="${NO_REPLY_PROVIDER_ID:-custom-127-0-0-1-8787}"
|
||||
NO_REPLY_MODEL_ID="${NO_REPLY_MODEL_ID:-whispergate-no-reply-v1}"
|
||||
NO_REPLY_BASE_URL="${NO_REPLY_BASE_URL:-http://127.0.0.1:8787/v1}"
|
||||
NO_REPLY_API_KEY="${NO_REPLY_API_KEY:-wg-local-test-token}"
|
||||
BYPASS_USER_IDS_JSON="${BYPASS_USER_IDS_JSON:-["561921120408698910","1474088632750047324"]}"
|
||||
END_SYMBOLS_JSON="${END_SYMBOLS_JSON:-["🔚"]}"
|
||||
BYPASS_USER_IDS_JSON="${BYPASS_USER_IDS_JSON:-[\"561921120408698910\",\"1474088632750047324\"]}"
|
||||
END_SYMBOLS_JSON="${END_SYMBOLS_JSON:-[\"🔚\"]}"
|
||||
|
||||
STATE_DIR="${STATE_DIR:-$HOME/.openclaw/whispergate-install-records}"
|
||||
LATEST_RECORD_LINK="${LATEST_RECORD_LINK:-$HOME/.openclaw/whispergate-install-record-latest.json}"
|
||||
@@ -110,7 +110,7 @@ run_install() {
|
||||
echo "[whispergate] backup: $BACKUP_PATH"
|
||||
|
||||
local prev_paths_json
|
||||
prev_paths_json="$(python3 - <<'PY'
|
||||
prev_paths_json="$(PATH_PLUGINS_LOAD="$PATH_PLUGINS_LOAD" PATH_PLUGIN_ENTRY="$PATH_PLUGIN_ENTRY" PROVIDER_PATH="$PROVIDER_PATH" python3 - <<'PY'
|
||||
import json, os, subprocess
|
||||
|
||||
def get(path):
|
||||
@@ -128,32 +128,31 @@ print(json.dumps(payload,ensure_ascii=False))
|
||||
PY
|
||||
)"
|
||||
|
||||
# 1) plugins.load.paths append and dedupe
|
||||
local current_paths_json new_paths_json
|
||||
if openclaw config get "$PATH_PLUGINS_LOAD" --json >/tmp/wg_paths.json 2>/dev/null; then
|
||||
current_paths_json="$(cat /tmp/wg_paths.json)"
|
||||
# 1+2) set plugins object in one write (avoid transient schema failure)
|
||||
local current_plugins_json new_plugins_json
|
||||
if openclaw config get plugins --json >/tmp/wg_plugins.json 2>/dev/null; then
|
||||
current_plugins_json="$(cat /tmp/wg_plugins.json)"
|
||||
else
|
||||
current_paths_json="[]"
|
||||
current_plugins_json='{}'
|
||||
fi
|
||||
|
||||
new_paths_json="$(CURRENT_PATHS_JSON="$current_paths_json" PLUGIN_PATH="$PLUGIN_PATH" python3 - <<'PY'
|
||||
new_plugins_json="$(CURRENT_PLUGINS_JSON="$current_plugins_json" PLUGIN_PATH="$PLUGIN_PATH" BYPASS_USER_IDS_JSON="$BYPASS_USER_IDS_JSON" END_SYMBOLS_JSON="$END_SYMBOLS_JSON" NO_REPLY_PROVIDER_ID="$NO_REPLY_PROVIDER_ID" NO_REPLY_MODEL_ID="$NO_REPLY_MODEL_ID" python3 - <<'PY'
|
||||
import json, os
|
||||
cur=json.loads(os.environ['CURRENT_PATHS_JSON'])
|
||||
if not isinstance(cur,list):
|
||||
cur=[]
|
||||
pp=os.environ['PLUGIN_PATH']
|
||||
if pp not in cur:
|
||||
cur.append(pp)
|
||||
print(json.dumps(cur,ensure_ascii=False))
|
||||
PY
|
||||
)"
|
||||
oc_set_json "$PATH_PLUGINS_LOAD" "$new_paths_json"
|
||||
plugins=json.loads(os.environ['CURRENT_PLUGINS_JSON'])
|
||||
if not isinstance(plugins,dict):
|
||||
plugins={}
|
||||
|
||||
# 2) plugin entry
|
||||
local plugin_entry_json
|
||||
plugin_entry_json="$(BYPASS_USER_IDS_JSON="$BYPASS_USER_IDS_JSON" END_SYMBOLS_JSON="$END_SYMBOLS_JSON" NO_REPLY_PROVIDER_ID="$NO_REPLY_PROVIDER_ID" NO_REPLY_MODEL_ID="$NO_REPLY_MODEL_ID" python3 - <<'PY'
|
||||
import json, os
|
||||
entry={
|
||||
load=plugins.setdefault('load',{})
|
||||
paths=load.get('paths')
|
||||
if not isinstance(paths,list):
|
||||
paths=[]
|
||||
pp=os.environ['PLUGIN_PATH']
|
||||
if pp not in paths:
|
||||
paths.append(pp)
|
||||
load['paths']=paths
|
||||
|
||||
entries=plugins.setdefault('entries',{})
|
||||
entries['whispergate']={
|
||||
'enabled': True,
|
||||
'config': {
|
||||
'enabled': True,
|
||||
@@ -164,10 +163,11 @@ entry={
|
||||
'noReplyModel': os.environ['NO_REPLY_MODEL_ID'],
|
||||
}
|
||||
}
|
||||
print(json.dumps(entry,ensure_ascii=False))
|
||||
|
||||
print(json.dumps(plugins,ensure_ascii=False))
|
||||
PY
|
||||
)"
|
||||
oc_set_json "$PATH_PLUGIN_ENTRY" "$plugin_entry_json"
|
||||
oc_set_json "plugins" "$new_plugins_json"
|
||||
|
||||
# 3) provider
|
||||
local provider_json
|
||||
@@ -198,7 +198,7 @@ PY
|
||||
openclaw config get "$PROVIDER_PATH" --json >/dev/null
|
||||
|
||||
local next_paths_json
|
||||
next_paths_json="$(python3 - <<'PY'
|
||||
next_paths_json="$(PATH_PLUGINS_LOAD="$PATH_PLUGINS_LOAD" PATH_PLUGIN_ENTRY="$PATH_PLUGIN_ENTRY" PROVIDER_PATH="$PROVIDER_PATH" python3 - <<'PY'
|
||||
import json, os, subprocess
|
||||
|
||||
def get(path):
|
||||
|
||||
Reference in New Issue
Block a user