feat(local): 本地自建 office 预览网关,技能恢复服务器同源行为

- 新增 local/preview-gateway.js:零依赖复刻 executor :3100 的数据面(/preview 转发、SSE 与
  /api/* 按 Referer 认领槽位、4 槽 LRU + 闲置回收、缺二进制给安装页而不是无限转圈),
  不复刻 unshare/nsenter/mount 牢笼——本地没有沙箱,命令与 watch 本就同机同盘
- local/start.sh:选空闲端口起网关,经 PREVIEW_PROXIES 登记进 core 反代;端口写入
  .runtime/preview.port;local/stop.sh 兜底清理时一并收掉
- skills/office 回到 v2.5.0 行为:本地也发预览卡片、watch 族照旧隐藏,不再有 LOCAL 分支;
  binary missing 的报错改为指向技能自己的 AGENTS.md(平台中立)
- 网关按平台分支:进程回收(POSIX 进程组 / Windows taskkill /T)、二进制名(.exe、也认
  officecli-* 资产名)、POSIX 自动补 chmod +x;会话目录解析修正为读 {session:{work_dir}} 并限流
- 文档:docs/local-mode.md 补 4.15 与验证结果,local/README.md 补预览、日志与端口
This commit is contained in:
2026-11-11 22:12:14 +08:00
parent 8effba36dd
commit b3a0d5370c
7 changed files with 537 additions and 91 deletions
+6 -3
View File
@@ -17,6 +17,9 @@ PIDFILE="$RUNTIME/supervisor.pid"
PORT="${PORT:-8090}"
# 与 start.sh 的默认值一致;用 MCP_*_PORT 改过端口时这里也要跟着改(否则兜底那步找不到它们)。
MCP_PORTS="${MCP_WEB_PORT:-8091} ${MCP_IMAGE_PORT:-8092} ${MCP_VIDEO_PORT:-8093} ${MCP_ASR_PORT:-8094}"
# 预览网关端口是启动时从 3100 往后找的第一个空闲口,只能读它写下的记录。
pv_port=$(cat "$RUNTIME/preview.port" 2>/dev/null || printf '')
case "$pv_port" in ''|*[!0-9]*) pv_port='3100';; esac
stopped=0
@@ -81,7 +84,7 @@ if [ "$stopped" = 0 ]; then
fi
# 3) 兜底:还占着端口的直接收(启动器已经死了,剩下的都是孤儿)。
for p in "$PORT" $MCP_PORTS; do
for p in "$PORT" $MCP_PORTS "$pv_port"; do
for pid in $(pids_on_port "$p"); do
stop_pid "$pid" "端口 $p 上的进程"
done
@@ -89,7 +92,7 @@ done
[ "$stopped" = 1 ] && sleep 2
# 4) 收尾:仍占着端口的强制结束,避免下次启动被判「端口被占用」。
for p in "$PORT" $MCP_PORTS; do
for p in "$PORT" $MCP_PORTS "$pv_port"; do
for pid in $(pids_on_port "$p"); do
kill -KILL "$pid" 2>/dev/null || true
done
@@ -98,5 +101,5 @@ done
if [ "$stopped" = 1 ]; then
say '已停止'
else
say "没有在运行($PORT 与 MCP 端口 $MCP_PORTS 都空闲)"
say "没有在运行($PORT、MCP 端口 $MCP_PORTS、预览端口 $pv_port 都空闲)"
fi