#!/usr/bin/env bash# 开发态:启动 OpenCode 后端 + ide-host + Web 前端set -euo pipefailROOT="$(cd "$(dirname "0ドル")/.." && pwd)"cd "$ROOT"sync_skills_mcp() {if [[ "${SKIP_SYNC:-}" == "1" ]]; thenecho "Skipping skills/mcp sync (SKIP_SYNC=1)"returnfiecho "Syncing skills & MCP config to global ..."bun run "$ROOT/script/sync-global.ts" || echo "warning: sync-global failed (non-fatal)"}BACKEND_PORT="${BACKEND_PORT:-4096}"FRONTEND_PORT="${FRONTEND_PORT:-3000}"IDE_HOST_PORT="${IDE_HOST_PORT:-3080}"if [[ ! -d "$ROOT/packages/opencode/src" ]]; thenecho "error: packages/opencode not found. Run: bash script/vendor/import-opencode.sh" >&2exit 1fisync_skills_mcpPIDS=()port_listener_pid() {local port="1ドル"lsof -iTCP:"$port" -sTCP:LISTEN -t 2>/dev/null | head -1 || true}preflight_ports() {local busy=falsefor spec in "$BACKEND_PORT:Backend (OpenCode)" "$FRONTEND_PORT:Frontend (Web UI)"; dolocal port="${spec%%:*}"local label="${spec#*:}"local pidpid="$(port_listener_pid "$port")"if [[ -n "$pid" ]]; thenecho "error: $label port :$port already in use (PID $pid)." >&2busy=truefidoneif [[ "$busy" == true ]]; thenecho " Run: bun run dev:stop" >&2echo " Then: bun run dev:with-preview" >&2exit 1fi}start_backend() {echo "Starting backend (opencode serve) on :$BACKEND_PORT ..."local backend_pidbun run --cwd "$ROOT/packages/opencode" --conditions=browser src/index.ts serve --port "$BACKEND_PORT" &backend_pid=$!PIDS+=("$backend_pid")local ifor i in $(seq 1 60); doif curl -fsS "http://127.0.0.1:${BACKEND_PORT}/global/health" >/dev/null 2>&1; thenecho "Backend ready: http://127.0.0.1:${BACKEND_PORT}"returnfiif lsof -iTCP:"${BACKEND_PORT}" -sTCP:LISTEN -t >/dev/null 2>&1; thenecho "Backend listening on :$BACKEND_PORT (health pending)"returnfiif ! kill -0 "$backend_pid" 2>/dev/null; thenecho "error: backend exited during startup (often port :$BACKEND_PORT already in use)." >&2echo " Run: bun run dev:stop" >&2exit 1fisleep 0.2doneecho "error: backend did not start on :$BACKEND_PORT within timeout." >&2echo " Run: bun run dev:stop && bun run dev:with-preview" >&2exit 1}start_ide_host() {if [[ "${IDE_HOST_SKIP:-}" == "1" ]]; thenecho "Skipping ide-host (IDE_HOST_SKIP=1)"returnfiif [[ "${IDE_HOST_LAZY:-0}" == "1" ]]; thenecho "ide-host lazy start (IDE_HOST_LAZY=1) — OpenVSCode starts when you switch to IDE mode"returnfiecho "Starting ide-host at dev boot (set IDE_HOST_LAZY=1 to defer until IDE mode) ..."if [[ -n "${IDE_HOST_BIN:-}" ]] || [[ -x "${CODE_AGENT_DATA_DIR:-$HOME/.code-agent}/openvscode/current/bin/openvscode-server" ]]; thenecho "Starting ide-host (native) on :$IDE_HOST_PORT ..."IDE_HOST_PORT="$IDE_HOST_PORT" bun run --cwd "$ROOT/packages/ide-host" start &PIDS+=($!)if ! IDE_HOST_PORT="$IDE_HOST_PORT" IDE_HOST_WAIT_TIMEOUT="${IDE_HOST_WAIT_TIMEOUT:-8}" bash "$ROOT/script/wait-ide-host.sh"; thenecho "warning: ide-host did not become ready." >&2fireturnfiif [[ "${IDE_HOST_DOCKER:-}" == "1" ]] || [[ "$(uname -s)" == "Darwin" ]]; thenif command -v docker >/dev/null 2>&1; thenif ! docker info >/dev/null 2>&1; thenecho "warning: Docker is installed but the daemon is not running." >&2echo " Start Docker Desktop, or use: IDE_HOST_LAZY=1 bun run dev" >&2echo " Skip IDE for QA: IDE_HOST_SKIP=1 bun run dev" >&2returnfiecho "Starting ide-host (Docker) on 127.0.0.1:$IDE_HOST_PORT ..."echo " macOS: OpenVSCode has no native tarball — using Docker."echo " If folders fail to open, run: IDE_HOST_MOUNT_HOME=1 bun run dev"if ! IDE_HOST_PORT="$IDE_HOST_PORT" IDE_HOST_DOCKER_DETACHED=1 bash "$ROOT/script/ide-host-docker.sh"; thenecho "warning: ide-host Docker start failed; IDE mode unavailable until Docker is fixed." >&2echo " Continue with: IDE_HOST_LAZY=1 or IDE_HOST_SKIP=1" >&2returnfiif ! IDE_HOST_PORT="$IDE_HOST_PORT" IDE_HOST_WAIT_TIMEOUT="${IDE_HOST_WAIT_TIMEOUT:-8}" bash "$ROOT/script/wait-ide-host.sh"; thenecho "warning: ide-host did not become ready yet; IDE mode may error until Docker finishes starting." >&2echo " check: docker logs code-agent-openvscode" >&2fireturnfiecho "warning: Docker not found; IDE mode will not work until ide-host is available." >&2returnfiecho "Starting ide-host (native) on :$IDE_HOST_PORT ..."IDE_HOST_PORT="$IDE_HOST_PORT" bun run --cwd "$ROOT/packages/ide-host" start &PIDS+=($!)}start_kb_control() {if [[ "${KB_CONTROL_SKIP:-}" == "1" ]]; thenecho "Skipping kb control (KB_CONTROL_SKIP=1)"returnfilocal port="${KB_CONTROL_PORT:-3090}"local kb_health="http://127.0.0.1:${port}/kb/health"local tasks_health="http://127.0.0.1:${port}/tasks/health"local req_health="http://127.0.0.1:${port}/req/health"local design_health="http://127.0.0.1:${port}/design/health"local api_wiki_health="http://127.0.0.1:${port}/api-wiki/health"local kb_ok=falselocal tasks_ok=falselocal req_ok=falselocal design_ok=falselocal api_wiki_ok=falseif curl -fsS "$kb_health" >/dev/null 2>&1; then kb_ok=true; fiif curl -fsS "$tasks_health" >/dev/null 2>&1; then tasks_ok=true; fiif curl -fsS "$req_health" >/dev/null 2>&1; then req_ok=true; fiif curl -fsS "$design_health" >/dev/null 2>&1; then design_ok=true; fiif curl -fsS "$api_wiki_health" >/dev/null 2>&1; then api_wiki_ok=true; fiif [[ "$kb_ok" == true && "$tasks_ok" == true && "$req_ok" == true && "$design_ok" == true && "$api_wiki_ok" == true ]]; thenecho "Knowledge control API already running on :${port}"returnfiif [[ "$kb_ok" == true && ("$tasks_ok" != true || "$req_ok" != true || "$design_ok" != true || "$api_wiki_ok" != true) ]]; thenecho "warning: control API on :${port} is stale (missing workbench routes); restarting ..." >&2filocal stalestale="$(lsof -tiTCP:"${port}" -sTCP:LISTEN 2>/dev/null || true)"if [[ -n "$stale" ]]; thenecho "warning: port ${port} occupied by stale process(es); stopping ${stale} ..." >&2kill $stale 2>/dev/null || truesleep 0.5fiecho "Starting knowledge control API on :${port} ..."KB_CONTROL_PORT="$port" bun run --cwd "$ROOT/packages/knowledge" control &PIDS+=($!)if ! KB_CONTROL_PORT="$port" bash "$ROOT/script/wait-kb-control.sh"; thenecho "warning: kb control did not become ready; Knowledge workbench will error until it starts." >&2fi}start_ubml_preview() {if [[ "${UBML_PREVIEW_DEV:-}" != "1" ]]; thenreturnfilocal preview_port="${UBML_PREVIEW_PORT:-3100}"if curl -fsS "http://127.0.0.1:${preview_port}/ubml-preview/" >/dev/null 2>&1; thenecho "UBML preview already running on :${preview_port}"returnfilocal stalestale="$(port_listener_pid "$preview_port")"if [[ -n "$stale" ]]; thenecho "warning: preview port :${preview_port} occupied by PID ${stale}; stopping ..." >&2kill "$stale" 2>/dev/null || truesleep 0.4fiecho "Starting UBML preview on :${preview_port} (UBML_PREVIEW_DEV=1) ..."UBML_PREVIEW_PORT="$preview_port" bun run --cwd "$ROOT/packages/extension" preview:dev &PIDS+=($!)if ! UBML_PREVIEW_PORT="$preview_port" bash "$ROOT/script/wait-ubml-preview.sh"; thenecho "warning: UBML preview did not become ready; /ubml-preview/ proxy will fail until it starts." >&2fi}start_frontend() {echo "Starting frontend (@code-agent/extension) on :$FRONTEND_PORT ..."IDE_HOST_PORT="$IDE_HOST_PORT" VITE_IDE_HOST_LAZY="${IDE_HOST_LAZY:-}" VITE_IDE_HOST_IDLE_MS="${IDE_HOST_IDLE_MS:-}" \bun run --cwd "$ROOT/packages/extension" dev -- --port "$FRONTEND_PORT" --strictPort &PIDS+=($!)local ifor i in $(seq 1 80); doif curl -fsS -o /dev/null "http://127.0.0.1:${FRONTEND_PORT}/" 2>/dev/null; thenecho "Frontend ready: http://127.0.0.1:${FRONTEND_PORT}"returnfisleep 0.25doneecho "warning: frontend not responding on :$FRONTEND_PORT yet (Vite may still be compiling)." >&2}preflight_portsecho "Syncing farris skills + MCP to OpenCode global config ..."bun run "$ROOT/script/sync-global.ts" || echo "warning: sync-global failed; farris skills may need manual sync" >&2start_backendstart_kb_controlstart_ubml_previewstart_frontendstart_ide_hostshutdown() {echo ""echo "Shutting down ..."for pid in "${PIDS[@]}"; dokill "$pid" 2>/dev/null || truedonedocker rm -f code-agent-openvscode 2>/dev/null || truefor pid in "${PIDS[@]}"; dowait "$pid" 2>/dev/null || truedoneexit 0}trap shutdown SIGINT SIGTERMecho ""echo "Services running. Press Ctrl+C to stop."echo " Backend: http://localhost:$BACKEND_PORT"echo " IDE host: http://127.0.0.1:$IDE_HOST_PORT/ide/ (proxied at http://localhost:$FRONTEND_PORT/ide/)"echo " KB ctrl: http://127.0.0.1:${KB_CONTROL_PORT:-3090}/kb/ (proxied at http://localhost:$FRONTEND_PORT/kb/)"echo " Tasks: http://127.0.0.1:${KB_CONTROL_PORT:-3090}/tasks/ (proxied at http://localhost:$FRONTEND_PORT/tasks/)"echo " Req: http://127.0.0.1:${KB_CONTROL_PORT:-3090}/req/ (proxied at http://localhost:$FRONTEND_PORT/req/)"echo " Design: http://127.0.0.1:${KB_CONTROL_PORT:-3090}/design/ (proxied at http://localhost:$FRONTEND_PORT/design/)"echo " API Wiki: http://127.0.0.1:${KB_CONTROL_PORT:-3090}/api-wiki/ (proxied at http://localhost:$FRONTEND_PORT/api-wiki/)"echo " Frontend: http://localhost:$FRONTEND_PORT"if [[ "${UBML_PREVIEW_DEV:-}" == "1" ]]; thenecho " Preview: http://127.0.0.1:${UBML_PREVIEW_PORT:-3100}/ubml-preview/ (proxied at http://localhost:$FRONTEND_PORT/ubml-preview/)"fiecho ""echo "Linux native binary: bun run --cwd packages/ide-host download"echo "macOS: uses Docker automatically (or IDE_HOST_DOCKER=1)"echo ""wait
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型