Improve data skill routing and tool organization

This commit is contained in:
武阳
2026-05-06 21:46:09 +08:00
parent 4d3981cccd
commit 1aafc0fce7
16 changed files with 1342 additions and 955 deletions
+38 -11
View File
@@ -10,10 +10,14 @@ ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
RUN_DIR="${ROOT_DIR}/.port_sessions"
BACKEND_HOST="${CLAW_BACKEND_HOST:-127.0.0.1}"
BACKEND_PORT="${CLAW_BACKEND_PORT:-8765}"
FRONTEND_HOST="${CLAW_FRONTEND_HOST:-127.0.0.1}"
FRONTEND_HOST="${CLAW_FRONTEND_HOST:-0.0.0.0}"
FRONTEND_PORT="${CLAW_FRONTEND_PORT:-3000}"
BACKEND_URL="http://${BACKEND_HOST}:${BACKEND_PORT}"
FRONTEND_URL="http://${FRONTEND_HOST}:${FRONTEND_PORT}"
PYTHON_BIN="${CLAW_PYTHON_BIN:-${ROOT_DIR}/.venv/bin/python}"
if [[ ! -x "${PYTHON_BIN}" ]]; then
PYTHON_BIN="python3"
fi
mkdir -p "${RUN_DIR}"
@@ -41,6 +45,31 @@ stop_pid_file() {
rm -f "${pid_file}"
}
stop_port_listener() {
local port="$1"
local name="$2"
local pids
pids="$(lsof -tiTCP:"${port}" -sTCP:LISTEN 2>/dev/null || true)"
if [[ -z "${pids}" ]]; then
return
fi
echo "Stopping ${name} listener(s) on port ${port}: ${pids//$'\n'/ }..."
while IFS= read -r pid; do
[[ -z "${pid}" ]] && continue
kill "${pid}" 2>/dev/null || true
done <<<"${pids}"
for _ in {1..20}; do
if ! lsof -tiTCP:"${port}" -sTCP:LISTEN >/dev/null 2>&1; then
return
fi
sleep 0.1
done
while IFS= read -r pid; do
[[ -z "${pid}" ]] && continue
kill -9 "${pid}" 2>/dev/null || true
done <<<"${pids}"
}
wait_for_url() {
local url="$1"
local name="$2"
@@ -60,6 +89,8 @@ wait_for_url() {
stop_pid_file "${RUN_DIR}/webui-frontend.pid" "frontend"
stop_pid_file "${RUN_DIR}/webui-backend.pid" "backend"
stop_port_listener "${FRONTEND_PORT}" "frontend"
stop_port_listener "${BACKEND_PORT}" "backend"
export OPENAI_API_KEY="${OPENAI_API_KEY:-sk-Jxoh5lf1jWg6HQZYYyfyagXudGxUXNAgkZklxMnnXHn7pFmU}"
export OPENAI_BASE_URL="${OPENAI_BASE_URL:-http://model.mify.ai.srv/v1}"
@@ -69,27 +100,23 @@ BACKEND_LOG="${RUN_DIR}/webui-backend.log"
FRONTEND_LOG="${RUN_DIR}/webui-frontend.log"
echo "Starting backend on ${BACKEND_URL}..."
(
cd "${ROOT_DIR}"
exec python3 -m src.gui \
cd "${ROOT_DIR}"
nohup "${PYTHON_BIN}" -m src.gui \
--host "${BACKEND_HOST}" \
--port "${BACKEND_PORT}" \
--cwd "${ROOT_DIR}" \
--session-dir "${RUN_DIR}/agent" \
--allow-write \
--allow-shell \
--no-browser
) >"${BACKEND_LOG}" 2>&1 &
--no-browser >"${BACKEND_LOG}" 2>&1 &
echo "$!" >"${RUN_DIR}/webui-backend.pid"
wait_for_url "${BACKEND_URL}/api/state" "backend" "${BACKEND_LOG}"
echo "Starting frontend on ${FRONTEND_URL}..."
(
cd "${ROOT_DIR}/frontend/app"
export CLAW_API_URL="${BACKEND_URL}"
exec npm run dev -- --hostname "${FRONTEND_HOST}" --port "${FRONTEND_PORT}"
) >"${FRONTEND_LOG}" 2>&1 &
cd "${ROOT_DIR}/frontend/app"
export CLAW_API_URL="${BACKEND_URL}"
nohup npm run dev -- --hostname "${FRONTEND_HOST}" --port "${FRONTEND_PORT}" >"${FRONTEND_LOG}" 2>&1 &
echo "$!" >"${RUN_DIR}/webui-frontend.pid"
wait_for_url "${FRONTEND_URL}" "frontend" "${FRONTEND_LOG}"