# Ensure Homebrew and ~/.local/bin are available for non-interactive SSH & Mosh sessions export PATH="/opt/homebrew/bin:/opt/homebrew/sbin:${HOME}/.local/bin:${PATH}"
# Ensure UTF-8 locale for mosh-server over SSH if [[ -z "${LANG:-}" || "${LANG}" == "C" || "${LANG}" == "POSIX" ]]; then export LANG="en_US.UTF-8" fi if [[ -z "${LC_CTYPE:-}" || "${LC_CTYPE}" == "C" || "${LC_CTYPE}" == "POSIX" ]]; then export LC_CTYPE="en_US.UTF-8" fi
set -g mouse on set -g base-index 1 setw -g pane-base-index 1 set -g renumber-windows on set -g default-terminal "tmux-256color" set -ag terminal-overrides ",xterm-256color:RGB"
# 手机远程 & AI Coding Agent 优化 set -g history-limit 50000 set -sg escape-time 10 set -g focus-events on set -g set-clipboard on set -g allow-passthrough on setw -g aggressive-resize on
# 精简底栏适配手机竖屏 set -g status-style bg=colour235,fg=colour250 set -g window-status-style bg=colour235,fg=colour244 set -g window-status-current-style bg=colour39,fg=colour235,bold set -g status-left "#[bg=colour39,fg=colour235,bold] #S #[bg=colour235,fg=colour39]" set -g status-right " #[fg=colour244]%H:%M " set -g status-left-length 15
find_tailscale() { if command -v tailscale >/dev/null 2>&1; then command -v tailscale elif [[ -x "/Applications/Tailscale.app/Contents/MacOS/Tailscale" ]]; then echo "/Applications/Tailscale.app/Contents/MacOS/Tailscale" fi }
is_awake_running() { if [[ -f "${CAFFEINATE_PID_FILE}" ]]; then local pid pid=$(cat "${CAFFEINATE_PID_FILE}" 2>/dev/null || true) if [[ -n "${pid}" ]] && kill -0 "${pid}" 2>/dev/null; then return 0 fi fi return 1 }
cmd_awake() { local action="${1:-start}" case "${action}" in start|on) if is_awake_running; then echo "✅ Mac 防休眠已在运行 (PID: $(cat "${CAFFEINATE_PID_FILE}"))" else nohup caffeinate -dims >/dev/null 2>&1 & echo $! > "${CAFFEINATE_PID_FILE}" echo "✅ 已开启 Mac 防休眠 (caffeinate -dims, PID: $(cat "${CAFFEINATE_PID_FILE}"))" fi ;; stop|off) if is_awake_running; then local pid pid=$(cat "${CAFFEINATE_PID_FILE}") kill "${pid}" 2>/dev/null || true rm -f "${CAFFEINATE_PID_FILE}" echo "🛑 已关闭 Mac 防休眠" else rm -f "${CAFFEINATE_PID_FILE}" echo "ℹ️ 当前未开启 ai-hub 防休眠" fi ;; *) echo "用法: ai-hub awake [start|stop]" exit 1 ;; esac }
cmd_status() { echo "=== Mac 远程 AI 工作台状态 ===" echo ""
local ts_bin ts_ip="" ts_bin="$(find_tailscale || true)" if [[ -n "${ts_bin}" ]]; then ts_ip="$("${ts_bin}" ip -4 2>/dev/null | head -n 1 || true)" if [[ -n "${ts_ip}" ]]; then echo "🌐 Tailscale : ✅ 已连接 (${ts_ip})" else echo "🌐 Tailscale : ⚠️ 已安装但未登录/未连接" fi else echo "🌐 Tailscale : ❌ 未安装" fi
if command -v mosh-server >/dev/null 2>&1; then echo "📡 Mosh : ✅ 已安装 ($(command -v mosh-server))" else echo "📡 Mosh : ❌ 未安装" fi
if is_awake_running; then echo "☕ 防休眠 : ✅ 运行中 (PID: $(cat "${CAFFEINATE_PID_FILE}"))" else echo "☕ 防休眠 : ⚪ 未开启(运行 ai-hub awake 开启)" fi
echo "" echo "🤖 已检测到的 CLI Agent:" for tool in claude opencode pi codex agy; do if command -v "${tool}" >/dev/null 2>&1; then echo " - ${tool}: ✅ $(command -v "${tool}")" else echo " - ${tool}: ❌ 未找到" fi done
echo "" echo "🖥️ tmux 会话:" if tmux list-sessions 2>/dev/null | sed 's/^/ /'; then : else echo " (暂无运行中的会话,运行 ai-hub 启动)" fi
[2] Anthropic: Anthropic. “Prompt engineering best practices for 2026 | Claude by Anthropic.” Anthropic Blog, 2025.(提供了“直白清晰”、“提供背景与动机”、“预填回复 (Prefill)”、“手动 CoT”、以及“XML 标签的现代化替代方案”等最新实践准则)。
-- 语义相似度检索 SELECT*, 1- (embedding <=>CAST(:embedding AS vector)) AS similarity FROM agent_few_shot_examples ORDERBY embedding <=>CAST(:embedding AS vector) LIMIT :limit;
这只是最小示例。生产里还得建索引,不然样本库一大,延迟会很难看:
1 2 3 4
-- HNSW 构建慢一点、吃内存一点,但通常有更好的召回/延迟平衡 CREATE INDEX agent_few_shot_examples_embedding_hnsw ON agent_few_shot_examples USING hnsw (embedding vector_cosine_ops);