Skip to content

Find host CLIs outside PATH, and never show an empty model list - #608

Merged
Stahl-G merged 1 commit into
mainfrom
codex/host-bin-and-empty-catalog
Sep 10, 2026
Merged

Find host CLIs outside PATH, and never show an empty model list#608
Stahl-G merged 1 commit into
mainfrom
codex/host-bin-and-empty-catalog

Conversation

@Stahl-G

@Stahl-G Stahl-G commented Sep 10, 2026

Copy link
Copy Markdown
Owner

切到 Opencode 后模型下拉是空的。复现出来是 /api/models?backend=opencode 返回 400「Opencode CLI 未安装」,而 CLI 明明装在 ~/.opencode/bin/opencode(1.18.30,服务也在跑)——服务启动时 PATH 里没有这个目录,于是"装好并登录过的宿主"被当成没装,功能静默消失。

这次修的是这一类问题,不只这一例:

  • 找 CLI 不再只看 PATH。 新增 host_bins.find():先查 PATH,再查各宿主常用的安装目录(~/.opencode/bin/opt/homebrew/bin~/.local/bin~/.bun/bin~/.npm-global/bin~/.dsh/bin 等)。Codex、Opencode、Node 以及 briefloop doctor 全部走同一个解析,找不到时的报错也会说明查过哪些位置。实测:把服务的 PATH 设成只有 /usr/bin:/bin,仍然能找到 opencode / codex / node / pdftotext。
  • 空列表不再静默。 模型目录为空或读取失败时,输入区下拉里会出现一条禁用说明(例如「opencode:未找到 Opencode CLI;已查找 PATH、~/.opencode/bin(可直接输入模型 ID)」),可搜索面板里同样显示原因,而不是只显示"输入其他模型 ID"。
  • 测试:新增「不在 PATH 里的可执行文件仍能被找到」和「空目录渲染说明项」两条行为测试。

验证:python -m pytest -q 182 passed;node tests/frontend_model_selection.mjs 通过;本机服务重启后 /api/models?backend=opencode 返回 396 个模型。

Switching the chat to Opencode showed no models: the service had been started
without ~/.opencode/bin on PATH, so a CLI that is installed and authenticated
looked "not installed" and the picker rendered blank with no explanation.

- host_bins.find() searches PATH first, then the well-known install dirs each
  host uses (~/.opencode/bin, /opt/homebrew/bin, ~/.local/bin, …). Codex,
  Opencode, Node and `briefloop doctor` all resolve through it, and the
  not-found messages say where we looked.
- The model picker explains an empty or failed catalogue instead of showing a
  blank list, both inline in the composer and in the searchable picker.
- Tests: a binary outside PATH is still found; an empty catalogue renders a
  disabled explanation entry.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Stahl-G
Stahl-G merged commit 4ae8676 into main Sep 10, 2026
2 checks passed
@Stahl-G
Stahl-G deleted the codex/host-bin-and-empty-catalog branch September 10, 2026 10:48
@cursor

cursor Bot commented Sep 10, 2026

Copy link
Copy Markdown

Review(已合入,作跟进记录)

复现路径对:服务 PATH 里没有 ~/.opencode/bin 时,已安装的 Opencode 被当成没装,/api/models 400,下拉空白。host_bins.find() PATH 优先、再扫常见安装目录,Codex / Opencode / Node / doctor 走同一套,空目录有说明项。这个切片该合,方向没问题。

跟进(不必回滚)

1. 实际用 pdftotext / curl 的路径还在 shutil.which sources.py 抽 PDF、调 curl 仍只看 PATH;doctor 已经能在 /opt/homebrew/bin 找到 pdftotext,抽取却仍当没装。和「PATH 只有 /usr/bin:/bin 仍能找到 pdftotext」的实测不完全一致。同一套 host_bins.find 应收口。

2. 可搜索面板仍不像下拉那样说明原因。 refreshInlineModelPickers 会加禁用的「未找到 Opencode CLI…」项;renderModelPicker 成功但 0 条时仍是「· 0 个模型」+「没有匹配的模型」,成功路径没用 catalog.diagnostic。PR 正文写了两处都解释,browse 面板还差一截。

3. 未覆盖的安装位置。 没有 nvm(~/.nvm/versions/node/.../bin)、也没有 Windows .exe。对本机 launchd 场景,缺 nvm 时 Node bridge 仍会找不到。可以以后补,不必为此重开。

app_server.py / opencode_server.py / runtime_bridge.pyshutil 若已不再使用,顺手删即可。

结论: 已合入的修复对「切到 Opencode 下拉是空的」够用。pdftotext 抽取和 browse 面板诊断值得另开一小笔。

Comment thread frontend/app.js
const models=modelCatalogs.get(modelTargetBackend(input?.id))?.models||[];
const backend=modelTargetBackend(input?.id),catalog=modelCatalogs.get(backend),models=catalog?.models||[];
for(const model of models)select.add(new Option(model.name+' · '+model.id,model.id));
if(!models.length){const warn=new Option(emptyCatalogLabel(backend,catalog),'__empty__');warn.disabled=true;select.add(warn)}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

内联下拉有禁用说明项,很好。可搜索面板(renderModelPicker)成功但 0 条时仍是「0 个模型」+「没有匹配的模型」,没用 catalog.diagnostic。PR 正文写了两处都解释,browse 还差这一截。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant