Goal: unify "temporary exposure + management panel + port management" into a single command entry point to avoid port chaos.
✅ Recommended entry point (unified Bun CLI)
bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts
Command overview
# 启动临时暴露(等同 share start)
bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts start --dir ./demos/html
# 暴露已有端口
bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts start --port 8766
Expose a single file
bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts start --file ./demos/html/index.html --route /index.html
Start/stop/view the panelbun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts panel start --port 8788 --host 127.0.0.1 bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts panel status bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts panel stop
Overall status (share + panel)bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts status
Stop (stops all by default)bun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts stop
Stop only sharebun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts stop --share
Stop only panelbun ~/.pi/agent/skills/cf-tunnel/scripts/cf.ts stop --panel
---
## 功能特性
- 统一入口:`cf.ts` 同时管理 share / panel
- 端口自动避让:面板端口占用时自动切换到下一个可用端口
- 会话清晰:固定 tmux session 名
- `cf-share-web`
- `cf-share-tunnel`
- `cf-share-panel`
- 状态聚合:一个命令看完整状态(本地服务 / tunnel / panel / 公网 URL)
- 向后兼容:`share.ts`、`panel.ts` 仍可直接使用
---
## 底层命令(兼容保留)
```bash
# share 底层
bun ~/.pi/agent/skills/cf-tunnel/scripts/share.ts start --dir ./demos/html
bun ~/.pi/agent/skills/cf-tunnel/scripts/share.ts status
bun ~/.pi/agent/skills/cf-tunnel/scripts/share.ts stop
# panel 底层
bun ~/.pi/agent/skills/cf-tunnel/scripts/panel.ts --port 8788 --host 127.0.0.1
It is recommended to prioritize using
cf.ts; the underlying commands are mainly for debugging.
API and panel
Default address after starting the panel:
http://127.0.0.1:8788(if occupied, it will automatically avoid the port)
API:
GET /api/statuscurrent statusPOST /api/startstart (body supportsport/dir/file/route)POST /api/stopstopGET /api/logslog tailGET /api/historyhistoryPOST /api/history/clearclear history
Dependencies
# Cloudflared(如未安装)
wget -q https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb
sudo dpkg -i cloudflared-linux-amd64.deb
Local static service priority:python3 > bunx > npx(fails directly when no tool is available)
Troubleshooting
cf.ts statusFirst check whether the three session types are online- If the tunnel has no URL: check
~/.cf-tunnel/share-tunnel.log - If the panel cannot be opened:
cf.ts panel statuscheck the actual port (it may have automatically avoided the port) - Full reset:
cf.ts stop --allthen restartstart