[躺着,让你更好的看我自己动]opencode+oh-my-opencode+Tmux 集成

Tmux 集成说明

在单独的 tmux 窗格中运行后台子代理,实现可视化的多代理执行。观看您的代理并行工作,每个代理各自在自己的终端窗格中。


食用教程(需要先参考 https://linux.do/t/topic/1513858 进行基础配置)

1.在oh-my-opencode.json 中启用 tmux 集成

{
  "tmux": {
    "enabled": true,
    "layout": "main-vertical",
    "main_pane_size": 60,
    "main_pane_min_width": 120,
    "agent_pane_min_width": 40
  }
}
详细参数

2.安装 tmux

mac 系统直接运行: brew install tmux

linux 系统:apt install tmux 或者 yum install tmux

win 系统请安装 linux/wsl 或者更换 mac 电脑

3.配置 Bash/Zsh

编辑# ~/.bashrc 或者 ~/.zshrc在文件尾部添加

# ~/.bashrc or ~/.zshrc
oc() {
    local base_name=$(basename "$PWD")
    local path_hash=$(echo "$PWD" | md5sum | cut -c1-4)
    local session_name="${base_name}-${path_hash}"
    
    # Find available port
    local port=4096
    while [ $port -lt 5096 ]; do
        if ! lsof -i :$port >/dev/null 2>&1; then
            break
        fi
        port=$((port + 1))
    done
    
    export OPENCODE_PORT=$port
    
    if [ -n "$TMUX" ]; then
        opencode --port $port "$@"
    else
        local oc_cmd="OPENCODE_PORT=$port opencode --port $port $*; exec $SHELL"
        if tmux has-session -t "$session_name" 2>/dev/null; then
            tmux new-window -t "$session_name" -c "$PWD" "$oc_cmd"
            tmux attach-session -t "$session_name"
        else
            tmux new-session -s "$session_name" -c "$PWD" "$oc_cmd"
        fi
    fi
}

然后在终端输入 oc 即可食用
出现子代理窗口即为成功


参考内容:

40 个赞

万恶之源

https://linux.do/t/topic/1513858

那我躺了,你快动

3 个赞

:distorted_face: :distorted_face: :distorted_face:

这里应该是4096吧

1 个赞

这是 github 那个文档上的,不过也没错,4096 端口被占用就尝试port + 1,直到 5096

1 个赞

fish user 只是路过就被
:distorted_face:

好厉害的样子

2 个赞

厉害 :eyes::tieba_013:

自己动起来!!!

1 个赞

试了下,牛逼啊,谢谢大佬!

大佬,安装OMO后,思考过程如何设置成中文?我把OMO不启用,就能中文,启用后就是英文,设置提示词也么用

:rofl::rofl::rofl:

1 个赞

提供一下fish的脚本

# ~/.config/fish/config.fish
function oc
    set base_name (basename (pwd))
    set path_hash (echo (pwd) | md5sum | cut -c1-4)
    set session_name "$base_name-$path_hash"
    
    # Find available port starting from 4096
    function __oc_find_port
        set port 4096
        while test $port -lt 5096
            if not lsof -i :$port >/dev/null 2>&1
                echo $port
                return 0
            end
            set port (math $port + 1)
        end
        echo 4096
    end
    
    set oc_port (__oc_find_port)
    set -x OPENCODE_PORT $oc_port
    
    if set -q TMUX
        # Already inside tmux - just run with port
        opencode --port $oc_port $argv
    else
        # Create tmux session and run opencode
        set oc_cmd "OPENCODE_PORT=$oc_port opencode --port $oc_port $argv; exec fish"
        if tmux has-session -t "$session_name" 2>/dev/null
            tmux new-window -t "$session_name" -c (pwd) "$oc_cmd"
            tmux attach-session -t "$session_name"
        else
            tmux new-session -s "$session_name" -c (pwd) "$oc_cmd"
        end
    end
    
    functions -e __oc_find_port
end
2 个赞

任务结束(窗口自动关闭)的子代理被再次调用的时候不会再次出现新窗口

1 个赞

佬 我发现子窗口没办法显示多个(右侧只能显示一个,你遇到过这种情况吗)

非常酷炫! 这里需要重新打开终端,或者 source

2 个赞

牛,亲测还可以,用了两天发现我差的不是工具,差的是更多的模型:rofl:

头像上会动的 flair 咋弄上去的啊 佬儿

去 虫洞广场 ,加入一个群组就可以设置了

3 个赞