mirror of
https://git.openapi.site/https://github.com/desirecore/market.git
synced 2026-12-05 12:59:21 +08:00
probe-node.sh 和 dev-environment-setup 的 probe.sh 直接把路径写进 JSON。路径带双引号或反斜杠时(比如 Windows 上的 DESIRECORE_ROOT)输出不合法,jq 和 Agent 都解析不了,违反 probe-snapshot.md 的「JSON 必合法」约定。 - 两个脚本加 json_escape,写法与 probe-python.sh 相同 - probe-node.sh 转义 system_node、system_npm、volta_path、nvm_path、fnm_path、registry、proxy;probe.sh 转义 tools.*.path - probe.ps1 用 ConvertTo-Json,不受影响 - 版本 nodejs-runtime 1.0.4 → 1.0.5、dev-environment-setup 2.0.6 → 2.0.7,sidecar 同步;技能正文没变,source_hash 不变 Escape paths written into the JSON output of probe-node.sh and probe.sh, so double quotes and backslashes no longer produce invalid JSON. 验证:含引号和反斜杠的路径修复前报 JSON 解析错误,修复后合法且值能还原、能执行;普通布局输出不变;i18n、catalog 校验 0 error,translate --check 通过。控制字符不处理。私有敏感词扫描未执行,经用户确认后合并。
82 lines
2.4 KiB
Bash
Executable File
82 lines
2.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# dev-environment-setup probe: 输出系统级环境快照(JSON)
|
|
# 协议:见 ../references/probe-snapshot.md
|
|
|
|
set +e
|
|
|
|
# ── 工具检测 ─────────────────────────────
|
|
json_escape() {
|
|
printf '%s' "$1" | sed 's/\\/\\\\/g; s/"/\\"/g'
|
|
}
|
|
|
|
detect_tool() {
|
|
local name="$1"
|
|
local version_flag="${2:---version}"
|
|
local path
|
|
path=$(command -v "$name" 2>/dev/null)
|
|
if [ -z "$path" ]; then
|
|
printf '{"available":false}'
|
|
return
|
|
fi
|
|
local version
|
|
version=$("$name" $version_flag 2>&1 | head -n1 | grep -oE '[0-9]+\.[0-9]+(\.[0-9]+)?' | head -n1)
|
|
printf '{"available":true,"path":"%s","version":"%s"}' "$(json_escape "$path")" "${version:-}"
|
|
}
|
|
|
|
# ── 平台 ────────────────────────────────
|
|
case "$(uname -s)" in
|
|
Darwin) PLATFORM="darwin" ;;
|
|
Linux) PLATFORM="linux" ;;
|
|
*) PLATFORM="other" ;;
|
|
esac
|
|
ARCH=$(uname -m)
|
|
case "$ARCH" in
|
|
arm64|aarch64) ARCH="arm64" ;;
|
|
x86_64|amd64) ARCH="x64" ;;
|
|
esac
|
|
|
|
# ── DesireCore API 探测 ─────────────────
|
|
PORT_FILE="${DESIRECORE_ROOT}/agent-service.port"
|
|
DESIRECORE_API=""
|
|
PORT_FILE_EXISTS="false"
|
|
if [ -r "$PORT_FILE" ]; then
|
|
PORT_FILE_EXISTS="true"
|
|
PORT=$(cat "$PORT_FILE" 2>/dev/null | tr -d '[:space:]')
|
|
if [ -n "$PORT" ]; then
|
|
if curl -sk --max-time 0.5 "https://127.0.0.1:${PORT}/api/runtime/environment" >/dev/null 2>&1; then
|
|
DESIRECORE_API="https://127.0.0.1:${PORT}"
|
|
fi
|
|
fi
|
|
fi
|
|
|
|
# ── 工具检测结果 ────────────────────────
|
|
PY=$(detect_tool python3)
|
|
[ "$(echo "$PY" | grep -o false)" = "false" ] && PY=$(detect_tool python)
|
|
PIP=$(detect_tool pip3)
|
|
[ "$(echo "$PIP" | grep -o false)" = "false" ] && PIP=$(detect_tool pip)
|
|
NODE=$(detect_tool node)
|
|
NPM=$(detect_tool npm)
|
|
DOCKER=$(detect_tool docker)
|
|
PODMAN=$(detect_tool podman)
|
|
GIT=$(detect_tool git)
|
|
|
|
# ── 输出 JSON ───────────────────────────
|
|
cat <<EOF
|
|
{
|
|
"platform": "${PLATFORM}",
|
|
"arch": "${ARCH}",
|
|
"desirecore_api": "${DESIRECORE_API}",
|
|
"desirecore_port_file": ${PORT_FILE_EXISTS},
|
|
"tools": {
|
|
"python3": ${PY},
|
|
"pip3": ${PIP},
|
|
"node": ${NODE},
|
|
"npm": ${NPM},
|
|
"docker": ${DOCKER},
|
|
"podman": ${PODMAN},
|
|
"git": ${GIT}
|
|
},
|
|
"wsl": null
|
|
}
|
|
EOF
|