Skip to content

feat(env): proxy_env_extra — proxyctl env 额外导出 agent 专用代理变量 - #4

Merged
crhan merged 2 commits into
mainfrom
feat/proxy-env-extra
Sep 23, 2026
Merged

crhan merged 2 commits into
mainfrom
feat/proxy-env-extra

Conversation

@crhan

@crhan crhan commented Sep 23, 2026

Copy link
Copy Markdown
Owner

背景

omp 18.2.11 的 Anthropic 模型请求走 transport-fetch.ts → cowork transport,代理只取 PI_PROXY_<PROVIDER> / PI_PROXY,不读 HTTPS_PROXY。缺这个变量就直连,受限地区返回 403 Request not allowed。根因在 omp 上游(transportFetch 没有回退到标准代理变量);上游修好之后这项配置可以直接删掉。

改动

  • 新配置 proxy_env_extra(list 或逗号分隔字符串,默认空)。
  • proxyctl env:在原有输出之后,为每个变量名追加 export <NAME>=http://127.0.0.1:<proxy_port>;。
  • proxyctl env --unset:这些变量一起 unset。
  • 输出会被 eval,所以变量名必须是合法的 shell 标识符,否则跳过并在 stderr 警告;与内置代理变量同名的项也跳过(避免 ALL_PROXY 被改写成 HTTP 地址)。
  • 文档:config.yaml.example、README 配置示例、explain env、man、CHANGELOG [Unreleased]。
# ~/.config/proxyctl/config.yaml
proxy_env_extra: [PI_PROXY_ANTHROPIC]
eval "$(proxyctl env)"   # 放进 ~/.zprofile,新开的 shell 都会带上

与 #3 的区别(替代 #3)

  • 值是静态的,和 HTTPS_PROXY 一样指向引擎端口。引擎停了就是连接被拒(fail-closed),不会删掉变量退回直连。
  • 不再维护契约文件、生命周期自动刷新、shell rc 注入、status 段和 3 条 doctor 规则;也不按存活情况切到兜底 daemon(环境变量只在进程启动时读取,对运行中的进程做不到 failover)。
  • 不写死任何工具的变量前缀;默认空,需要时自己配。
  • proxyctl env 在 --json / PROXYCTL_AGENT=1 下的行为不变,仍输出可 eval 的 export 行。

兼容性

  • 没配 proxy_env_extra 时,proxyctl env / --unset 的输出和之前完全一致。
  • cmd_env(config, unset=...) 签名不变。

验证

  • uv run pytest -q → 814 passed。新增 2 条:导出 / 清除的契约;非法变量名不进 stdout、内置变量不被改写。
  • zsh 实跑(临时 HOME,配置里有 PI_PROXY_ANTHROPIC 和非法名 PI_PROXY;id):
警告:proxy_env_extra 跳过非法变量名 'PI_PROXY;id'
set:   PI_PROXY_ANTHROPIC=http://127.0.0.1:7890 https_proxy=http://127.0.0.1:7890
unset: PI_PROXY_ANTHROPIC=<unset> https_proxy=<unset>
agent mode extra line: export PI_PROXY_ANTHROPIC=http://127.0.0.1:7890;

omp 的 anthropic-messages transport 只读 PI_PROXY_<PROVIDER> / PI_PROXY,
不读 HTTPS_PROXY,缺了就直连(受限地区 403 Request not allowed)。

新增 proxy_env_extra 配置:列出的变量名由 `proxyctl env` 导出为引擎的
HTTP 代理地址(http://127.0.0.1:<proxy_port>),`env --unset` 一并清除。
默认为空,现有输出不变;输出会被 eval,非法变量名跳过并在 stderr 提示,
与内置代理变量同名的项不重复导出。

替代 #3:不再维护契约文件、生命周期刷新、shell rc 注入与 doctor 规则。
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-23T09:54:26.467795Z 3d10b03 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 7e0009ff92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/proxyctl/cli.py Outdated
YAML 会把 yes/no/on/off/true/false/null 解析成 bool/None,str() 之后
变成 True/None 能通过变量名校验,于是被导出成 True=… / None=…。
现在列表里的非字符串项跳过并在 stderr 提示加引号;整个值既不是列表
也不是字符串时忽略并提示,不再在迭代时抛 TypeError。
@crhan

crhan commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: 3d10b037b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@crhan
crhan merged commit ad07283 into main Sep 23, 2026
9 checks passed
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