recovered from aaronjaworski710
This commit is contained in:
@@ -0,0 +1,297 @@
|
||||
# Design: ChatGPT 代码层面对齐开源最佳实践
|
||||
|
||||
**Date:** 2026-07-16
|
||||
**Status:** approved (user: Scope A + Layer C + success B; §1–§2 OK; proceed implement)
|
||||
**Repo:** local `grok-register` / remote register-machine monorepo
|
||||
**Approach:** Core-first 契约扩展(Approach 1)
|
||||
|
||||
## 1. Context
|
||||
|
||||
pxed ChatGPT smoke(2026-07-16)协议路径到 `send_otp` 200,随后 Gmail catch-all **未收到** OpenAI OTP → fail-fast `mail_miss`。对照开源(zhuce6 / open-reg-auto / gpt-free-register):成功关键不是另一套 client_id,而是:
|
||||
|
||||
1. 邮箱投递质量(本轮 **不接** 商业邮箱 API 实现)
|
||||
2. 注册 egress 与邮件路径分离
|
||||
3. OTP 等待可观测 diagnostics
|
||||
4. 节点时间冷却(soft)与业务失败隔离
|
||||
5. 细错误分类(尤其 `registration_disallowed`)
|
||||
|
||||
本设计只做 **代码层能力对齐**;OTP 投递/住宅声誉仍为 Manual-required。
|
||||
|
||||
## 2. Goals / Non-goals
|
||||
|
||||
### Goals
|
||||
|
||||
| ID | 目标 |
|
||||
|---|---|
|
||||
| G1 | OTP diagnostics:poll 次数、扫信数、first_seen/matched 延迟、failure_class |
|
||||
| G2 | 细 `error_kind`:`mail_miss` / `registration_disallowed` / `captcha` / `proxy`/`network` / `provider` / `verify` / `fatal` / `other` |
|
||||
| G3 | 邮件路径默认不继承注册 proxy;可选独立 `mail_proxy` / `EMAIL_PROXY` |
|
||||
| G4 | `NodeManager` 时间冷却 API + 接线(risk/network soft-cool;mail_miss 永不 cool/quarantine) |
|
||||
| G5 | 配置面文档化(`.env.example` / provider README / config 注释) |
|
||||
| G6 | 单测全绿 + pxed COUNT=1 smoke 可解释失败类;**禁止** 空转与误 quarantine |
|
||||
|
||||
### Non-goals
|
||||
|
||||
- 新商业邮箱(MaliAPI / cfmail 实现)
|
||||
- ChatGPT 自动 CPA inject
|
||||
- 保证现有 gmail+clash 必出号
|
||||
- Grok free Build chat 403 / grokbuild-proxy 中转
|
||||
- Approach 3 大重构(EgressPolicy 全家桶)
|
||||
|
||||
### Success standard B(用户选定)
|
||||
|
||||
拆成两道门禁:
|
||||
|
||||
1. **代码门禁(必须):** 契约+实现+单测绿+smoke 诊断诚实
|
||||
2. **出号门禁(尽量):** `ok=1`;若资产不足 → 交付「代码 ✅ / 出号 ⚠️ Manual-required」,不伪造成功
|
||||
|
||||
## 3. Architecture
|
||||
|
||||
```
|
||||
register_core/
|
||||
contracts.py # OtpWaitDiagnostics; error_kind 注释/常量
|
||||
errors.py # MailMissError.diagnostics 可选属性
|
||||
email/base.py # 文档约定 last_wait_diagnostics(Protocol 签名不炸)
|
||||
email/sources/* # gmail_imap / tinyhost 写 diagnostics
|
||||
email/registry.py # get_email_source 支持 mail_proxy 与 register proxy 分离
|
||||
nodes/models.py # cooldown_until / cooldown_reason
|
||||
nodes/manager.py # is_cooling / cooldown() / pick 跳过冷却
|
||||
util/proxy.py # report_attempt_proxy_result → soft cool on risk/network
|
||||
providers/chatgpt_adapter.py # 解耦 mail proxy;放宽 kind allowlist;artifacts.otp_wait
|
||||
providers/chatgpt/protocol/flow.py # registration_disallowed kind;otp_sent_at
|
||||
```
|
||||
|
||||
**原则:** 通用化在 core;ChatGPT 只接线。Grok/MiMo 不受破坏性变更影响(additive)。
|
||||
|
||||
## 4. Error taxonomy
|
||||
|
||||
### 4.1 `error_kind` 权威表
|
||||
|
||||
| kind | 含义 | hard quarantine | soft cooldown | fail-fast |
|
||||
|---|---|---|---|---|
|
||||
| `mail_miss` | OTP 未达/未匹配 | 否 | 否 | 单次停(现状) |
|
||||
| `registration_disallowed` | OpenAI risk code | 否 | **是** | 单次 fail,不整批 fatal |
|
||||
| `captcha` | PoW/人机 | 否 | 可选 | 否 |
|
||||
| `proxy` / `network` | 连接/TLS/隧道 | 计入 fail_count | 是 | 否 |
|
||||
| `provider` | 其它产品流 | 否 | 否 | 否 |
|
||||
| `verify` | 后验能力失败 | 否 | 否 | 否 |
|
||||
| `fatal` | 配置/源耗尽 | 否 | 否 | **整批** |
|
||||
| `other` | 未归类 | 否 | 否 | 否 |
|
||||
|
||||
### 4.2 必改现状
|
||||
|
||||
1. `flow.py` create_account:识别 risk 后 `kind="registration_disallowed"`(现误为 `provider`)
|
||||
2. `chatgpt_adapter` allowlist 纳入 `registration_disallowed` / `proxy` / `network` / `fatal`
|
||||
3. `is_proxy_network_failure` 已排除 risk — **保持**;另增 soft-cooldown 路径
|
||||
4. `RegisterResult.error_kind` 注释同步
|
||||
|
||||
### 4.3 `failure_class`(mail 细分,不进 error_kind 爆炸)
|
||||
|
||||
| failure_class | 何时 |
|
||||
|---|---|
|
||||
| `no_mail` | 窗口内 0 封新信 |
|
||||
| `parse_fail` | 有信无 OTP |
|
||||
| `stale_code` | 码过期/已用 |
|
||||
| `imap_error` | IMAP 层错误(auth 可升 fatal) |
|
||||
| `aborted` | 外部中止 |
|
||||
|
||||
`error_kind` 仍多为 `mail_miss`;细分在 `artifacts["otp_wait"]`。
|
||||
|
||||
## 5. OTP diagnostics 数据模型
|
||||
|
||||
```python
|
||||
@dataclass(slots=True)
|
||||
class OtpWaitDiagnostics:
|
||||
poll_count: int = 0
|
||||
message_scan_count: int = 0
|
||||
empty_rounds: int = 0
|
||||
elapsed_seconds: float = 0.0
|
||||
timeout_s: float = 0.0
|
||||
first_message_seen_at: float | None = None
|
||||
matched_at: float | None = None
|
||||
first_seen_after_seconds: float | None = None
|
||||
matched_after_seconds: float | None = None
|
||||
abort_reason: str = ""
|
||||
failure_class: str = "" # no_mail | parse_fail | stale_code | imap_error | aborted | ""
|
||||
provider: str = ""
|
||||
sender_hint: str = ""
|
||||
notes: str = ""
|
||||
```
|
||||
|
||||
**挂载:**
|
||||
|
||||
- `MailMissError.diagnostics: OtpWaitDiagnostics | None`(`str(exc)` 行为不变)
|
||||
- Source 实例可选 `last_wait_diagnostics`
|
||||
- Adapter:`artifacts["otp_wait"] = asdict(diag)`;public 路径无 raw MIME/token
|
||||
- ChatGPT flow 记 `otp_sent_at` 供延迟字段
|
||||
|
||||
**EmailSource Protocol:** 不强制改 `poll_otp` 签名;约定 `last_wait_diagnostics` 属性。
|
||||
|
||||
## 6. 邮件 / 代理分离
|
||||
|
||||
### 6.1 现状问题
|
||||
|
||||
`chatgpt_adapter` 把 **注册 proxy** 传入 `get_email_source(..., proxy=proxy)` → `TinyhostSource` 经 ProxyHandler 走同一出口;邮件 API 与 OpenAI 风险出口耦合。zhuce 对邮箱路径 `del proxy` 直连。
|
||||
|
||||
### 6.2 规则
|
||||
|
||||
| 路径 | 默认 proxy |
|
||||
|---|---|
|
||||
| OpenAI register(curl_cffi session) | 注册 egress(PROXY_LIST / nodes / CHATGPT_PROXY) |
|
||||
| EmailSource allocate/poll(HTTP API) | **None(直连)**,除非显式 mail proxy |
|
||||
| Gmail IMAP | 本机 IMAP;不走注册 proxy(现状基本已是) |
|
||||
|
||||
### 6.3 配置
|
||||
|
||||
优先级(mail):
|
||||
|
||||
1. `extra["mail_proxy"]`
|
||||
2. `CHATGPT_MAIL_PROXY` / `EMAIL_PROXY` / `MAIL_PROXY`
|
||||
3. 默认 `""`(直连)
|
||||
|
||||
**禁止** 再把 register proxy 静默塞进 email source kwargs(breaking intentional)。
|
||||
|
||||
Adapter:
|
||||
|
||||
```python
|
||||
mail_proxy = resolve_mail_proxy(extra) # never falls back to register proxy
|
||||
source = get_email_source(name, proxy=mail_proxy or None, ...)
|
||||
```
|
||||
|
||||
`artifacts` 增加:`mail_proxy`(redact)、`register_proxy`(已有 proxy 字段)。
|
||||
|
||||
## 7. 节点时间冷却
|
||||
|
||||
### 7.1 与 quarantine 区别
|
||||
|
||||
| 机制 | 触发 | 效果 | 解除 |
|
||||
|---|---|---|---|
|
||||
| hard quarantine | `fail_count >= MAX` 且 last_ok False | 永久跳过直到 probe ok | `check_all` / 手动 |
|
||||
| soft cooldown | risk / 用后 / network 软失败 | `now < cooldown_until` 时 skip pick | 时间到期 |
|
||||
|
||||
### 7.2 Node 字段(runtime + 可持久化)
|
||||
|
||||
```python
|
||||
cooldown_until: float | None = None # epoch
|
||||
cooldown_reason: str = "" # registration_disallowed | per_use | network | ...
|
||||
```
|
||||
|
||||
### 7.3 API
|
||||
|
||||
```python
|
||||
NodeManager.cooldown(url, seconds: float, reason: str = "", *, persist=True) -> Node | None
|
||||
NodeManager.is_cooling(n: Node) -> bool
|
||||
# enabled_nodes / pick: skip is_cooling
|
||||
```
|
||||
|
||||
默认秒数(env):
|
||||
|
||||
- `REGISTER_NODES_COOLDOWN_PER_USE` 默认 `0`(关闭「每次用完都 cool」,避免小池饿死;zhuce 120s 作可选)
|
||||
- `REGISTER_NODES_COOLDOWN_RISK` 默认 `600`(registration_disallowed)
|
||||
- `REGISTER_NODES_COOLDOWN_NETWORK` 默认 `120`(network fail 在 quarantine 前的 soft 层;仍保留 fail_count)
|
||||
|
||||
### 7.4 `report_attempt_proxy_result` 接线
|
||||
|
||||
- `ok` → clear fail_count;可选 per_use cool(仅 env>0)
|
||||
- `registration_disallowed` → **不** quarantine;`cooldown(RISK)`
|
||||
- `mail_miss` / `captcha` / `verify` / `fatal` → 不 cool、不 quarantine
|
||||
- network → 现有 mark fail + 可选 NETWORK cool
|
||||
|
||||
## 8. ChatGPT 接线清单
|
||||
|
||||
| 文件 | 变更 |
|
||||
|---|---|
|
||||
| `register_core/contracts.py` | `OtpWaitDiagnostics`;error_kind 注释;可选 `ALLOWED_ERROR_KINDS` |
|
||||
| `register_core/errors.py` | `MailMissError.__init__(msg, *, diagnostics=None)` |
|
||||
| `register_core/email/sources/gmail_imap.py` | poll 写 last_wait_diagnostics;auth 分类 |
|
||||
| `register_core/email/sources/tinyhost.py` | poll 循环写 diagnostics;默认可不接 register proxy |
|
||||
| `register_core/nodes/models.py` | cooldown 字段序列化 |
|
||||
| `register_core/nodes/manager.py` | cooldown API;pick 跳过 |
|
||||
| `register_core/util/proxy.py` | risk → soft cool |
|
||||
| `register_core/providers/chatgpt_adapter.py` | mail_proxy 分离;kind allowlist;otp_wait artifacts |
|
||||
| `providers/chatgpt/protocol/flow.py` | registration_disallowed;otp_sent_at 日志 |
|
||||
| `providers/chatgpt/README.md` + `.env.example` | 配置说明 |
|
||||
| 新单测 | taxonomy / diagnostics / mail_proxy / cooldown |
|
||||
|
||||
**不变:** 无 CPA inject;fail-fast 不空转;secrets 不进 git。
|
||||
|
||||
## 9. 配置面
|
||||
|
||||
| 变量 | 默认 | 含义 |
|
||||
|---|---|---|
|
||||
| `CHATGPT_EMAIL_SOURCE` | `gmail_imap` | 邮箱源 |
|
||||
| `CHATGPT_OTP_TIMEOUT` | `180` | 总 OTP 预算(秒) |
|
||||
| `CHATGPT_PROXY` / 节点池 | — | **仅**注册 egress |
|
||||
| `CHATGPT_MAIL_PROXY` / `EMAIL_PROXY` | 空=直连 | 邮件 HTTP API |
|
||||
| `REGISTER_NODES_MAX_FAIL` | `3` | hard quarantine |
|
||||
| `REGISTER_NODES_COOLDOWN_RISK` | `600` | risk soft cool |
|
||||
| `REGISTER_NODES_COOLDOWN_NETWORK` | `120` | network soft cool |
|
||||
| `REGISTER_NODES_COOLDOWN_PER_USE` | `0` | 用后 cool(默认关) |
|
||||
|
||||
## 10. 测试与验收
|
||||
|
||||
### 离线(必须)
|
||||
|
||||
- `test_chatgpt_error_kinds.py`(或扩现有):disallowed 不被抹成 provider
|
||||
- cooldown:RISK cool 后 pick 跳过,到期恢复
|
||||
- mail_proxy:adapter 构造 source 时 kwargs.proxy 不等于 register proxy(除非显式 mail)
|
||||
- diagnostics:mail_miss artifacts 含 `otp_wait.failure_class`
|
||||
- 既有 `test_fail_policy` / `test_cpa_remote_inject` 不回归(ChatGPT 无关也勿破坏)
|
||||
|
||||
### pxed smoke(出号门禁)
|
||||
|
||||
```bash
|
||||
# 解析 GMAIL_* 勿 source 整份 .env
|
||||
COUNT=1 hub register.sh chatgpt 1 # 或项目现行入口
|
||||
```
|
||||
|
||||
期望:
|
||||
|
||||
- 若 `ok=1`:tokens 落盘;无 CPA inject
|
||||
- 若仍失败:SUMMARY/`error_kind` + `otp_wait` 可区分 `no_mail` vs `registration_disallowed` vs `proxy`
|
||||
- 节点不会因 mail_miss 被 quarantine
|
||||
|
||||
## 11. Milestone 执行契约
|
||||
|
||||
```text
|
||||
Milestone:ChatGPT 代码层 OSS 对齐(core-first)
|
||||
目标:G1–G6;尽量实测 ok=1
|
||||
P0/P1:taxonomy + diagnostics + mail/proxy 分离 + soft cooldown + 单测 + smoke
|
||||
不做的 P2/P3:商业邮箱源、CPA inject、大重构、Grok chat 403
|
||||
Manual-required:OpenAI OTP 投递与住宅出口声誉
|
||||
阶段上限:3
|
||||
阶段拆分:
|
||||
1) core 契约 + errors + diagnostics 类型 + 单测骨架
|
||||
2) nodes cooldown + proxy 反馈 + email sources/adapter/flow 接线
|
||||
3) 文档 + 全量相关单测 + pxed smoke 记录
|
||||
验收标准:单测绿;smoke 诊断诚实;出号尽量
|
||||
停止条件:P0/P1 完成或 3 阶段耗尽或外部资产阻塞出号(代码仍可交付)
|
||||
```
|
||||
|
||||
## 12. Risks
|
||||
|
||||
| 风险 | 缓解 |
|
||||
|---|---|
|
||||
| 小节点池 + per_use cool 饿死 | 默认 PER_USE=0 |
|
||||
| diagnostics 泄露 MIME | 只存计数/epoch/failure_class;public redact |
|
||||
| gmail_imap 依赖 grok_register_ttk 黑盒 | 外层包 diagnostics;auth 错误字符串分类 |
|
||||
| 出号仍失败 | 诚实 Manual-required;不放宽 inject |
|
||||
|
||||
## 13. Implementation order
|
||||
|
||||
1. contracts + errors + 常量
|
||||
2. Node cooldown + tests
|
||||
3. proxy report 接线
|
||||
4. gmail_imap / tinyhost diagnostics
|
||||
5. chatgpt adapter mail_proxy + allowlist + artifacts
|
||||
6. flow.py kind + otp_sent_at
|
||||
7. docs/env
|
||||
8. pxed smoke
|
||||
|
||||
Commit 风格:`feat(core): …` / `fix(chatgpt): …` / `test: …` / `docs: …`
|
||||
|
||||
## 14. References
|
||||
|
||||
- pxed smoke memory:`project_pxed_smoke_20260716`
|
||||
- zhuce6:`last_wait_diagnostics`、`del proxy` on mail、proxy_pool cooldown 120/600
|
||||
- 本仓库:`register_core/providers/chatgpt_adapter.py`、`providers/chatgpt/protocol/flow.py`、`register_core/util/proxy.py`
|
||||
@@ -0,0 +1,190 @@
|
||||
# Design: free Build chat 经 tebi CPA 中转 probe
|
||||
|
||||
**Date:** 2026-07-16
|
||||
**Status:** approved approach A (user: `a`)
|
||||
**Repo:** `dengyie/ai-register-machine` (local: grok-register)
|
||||
**Related:** [[Grok 注册机与 free Build CPA]], CPA 文档索引, chat entitlement hard gate (`cpa_xai/probe.py`, `writer.py`)
|
||||
|
||||
---
|
||||
|
||||
## 1. Problem
|
||||
|
||||
注册机 mint 后的 **chat gate** 目前 **本地直连** `https://cli-chat-proxy.grok.com/v1`,手搓 `DEFAULT_CLIENT_HEADERS`(已与 grokbuild-proxy 默认常量对齐)。
|
||||
|
||||
生产客户端则走 **tebi CLIProxyAPI**(`:8317` / `cpa.mangoq.ccwu.cc`):CPA 对 free Build 已具备 rewrite(空 / `api.x.ai` → cli-chat-proxy)与 CLI 头注入。
|
||||
|
||||
结果:
|
||||
|
||||
- **双身份路径**:gate 测的是「注册机 + 直连 + 本地头」;线上成功定义是「CPA 中转」。
|
||||
- backlog「grokbuild-proxy / CLIProxyAPI 中转架构」指的是 **统一 mid-tier**,不是再起一个与 tebi CPA 平行的 grokbuild-proxy 生产面。
|
||||
- **L4 403 entitlement** 仍是账号侧问题;中转 **不能** 当解锁手段。
|
||||
|
||||
## 2. Goals
|
||||
|
||||
1. 产品级 `chat_ok` / inject 门禁的 probe,默认经 **现有 tebi CPA** 中转(与 live 路径一致)。
|
||||
2. 写入的 `xai-*.json` 仍保持 CPA 期望的上游 `base_url`(cli-chat-proxy),不把公网 CPA URL 写进 auth 文件。
|
||||
3. 保持现有产品规则:hard gate、`entitlement_denied` fail-fast、禁止无 `chat_ok` live inject。
|
||||
4. 保留 debug 直连开关,便于区分「号问题」与「CPA/网络问题」。
|
||||
|
||||
## 3. Non-goals
|
||||
|
||||
| 不做 | 原因 |
|
||||
|---|---|
|
||||
| 修复 L4 permission-denied | 账号 entitlement / console.x.ai;Manual-required |
|
||||
| 软化 `probe_chat` hard gate | 用户明确保持 |
|
||||
| 部署独立 grokbuild-proxy 服务 | 与 tebi CPA free Build 能力重叠;运维成本高 |
|
||||
| 改 OAuth mint(PKCE / device) | mint 仍打 auth.x.ai;中转只覆盖 **probe HTTP** |
|
||||
| 在 pxed 起生产 CPA | 生产只在 tebi |
|
||||
| 第三方 GrokFree 中转 token | 与官方 OAuth free Build 无关 |
|
||||
|
||||
## 4. Decision
|
||||
|
||||
**选用方案 A:经现有 tebi CLIProxyAPI 做 mid-tier probe。**
|
||||
|
||||
放弃方案 B(独立 grokbuild-proxy)作为本 milestone 交付。
|
||||
方案 C(双 probe)仅以配置开关形式保留诊断能力,不当第二真相源。
|
||||
|
||||
### 4.1 为什么是 A
|
||||
|
||||
- tebi CPA **已支持** free Build rewrite + CLI 身份。
|
||||
- 注册机已有 `cpa_remote_inject` → tebi live/inventory 的运维路径;中转应复用同一生产面。
|
||||
- 头对齐(`grok-pager` / dual UA)已在 `cpa_xai/schema.py` 完成;剩余是 **路径统一**,不是再抄一套 client.go。
|
||||
|
||||
## 5. Architecture
|
||||
|
||||
```text
|
||||
Mac 开发
|
||||
↔ pxed /personal/grok-register (注册 + mint + probe)
|
||||
↔ tebi /personal/cpa + /root/.cli-proxy-api (生产 CPA :8317)
|
||||
公网 cpa.mangoq.ccwu.cc → tebi CPA
|
||||
|
||||
[mint]
|
||||
SSO/PKCE → access_token → write cpa_auths/xai-<email>.json
|
||||
base_url = https://cli-chat-proxy.grok.com/v1 # 上游,供 CPA rewrite
|
||||
|
||||
[probe 默认 cpa_probe_via=cpa]
|
||||
registerer → CPA OpenAI-compatible base (cpa.mangoq.ccwu.cc/v1 或 tunnel)
|
||||
+ CPA API key
|
||||
+ 必须钉到「本账号」凭据(见 §6)
|
||||
→ CPA → cli-chat-proxy(rewrite + headers)
|
||||
→ classify → stamp chat_ok / entitlement_denied / …
|
||||
|
||||
[probe debug cpa_probe_via=direct]
|
||||
registerer → cli-chat-proxy + DEFAULT_CLIENT_HEADERS + Bearer access_token
|
||||
(现行为;保留)
|
||||
|
||||
[inject]
|
||||
仅 chat_ok → live /root/.cli-proxy-api + inventory /personal/cpa/auths
|
||||
cpa_remote_inject_require_chat_ok=true 不变
|
||||
```
|
||||
|
||||
## 6. Credential pinning(P0 语义)
|
||||
|
||||
CPA 默认从 **池** 选 xAI 凭据。若 probe 不钉死「刚 mint 的 email」,会出现:
|
||||
|
||||
- **假阳性**:池里别的 chat_ok 号替测 → 错误 inject
|
||||
- **假阴性**:池里坏号挡枪 → 误杀好号
|
||||
|
||||
### 6.1 策略顺序(实现时按序探测能力)
|
||||
|
||||
1. **Preferred — 管理/API 按 credential 路由**
|
||||
若 tebi 当前 CPA 版本支持按 auth 文件名 / email / credential_id 指定上游凭据:probe 必须带该标识。
|
||||
2. **Fallback — inventory-only + 钉凭据**
|
||||
gate 前只允许写 inventory,不写 live;probe 仍钉该文件。
|
||||
3. **Hybrid(能力不足时的安全默认)**
|
||||
- **账号门禁**(`chat_ok` / `entitlement_denied` stamp)继续 **direct** + 本 token
|
||||
- **中转验证**:inject 后(或 inventory 写入后)再打一枪 CPA 路径 smoke,结果写入可选字段(如 `probe_via_cpa_ok`),**不得**单独作为 inject 放行条件替代 `chat_ok`
|
||||
|
||||
实现计划必须 **先核实 tebi CPA 是否可钉凭据**;不可钉则交付 hybrid,并在 ops 文档标明。
|
||||
|
||||
### 6.2 禁止
|
||||
|
||||
- 为了 probe 先 live inject 再测(循环依赖 + 污染 live 池)
|
||||
- 用池级任意成功响应给当前 email 盖 `chat_ok=true`
|
||||
|
||||
## 7. Config surface
|
||||
|
||||
新增(示例;默认值以实现计划冻结为准):
|
||||
|
||||
| Key | 含义 |
|
||||
|---|---|
|
||||
| `cpa_probe_via` | `cpa` \| `direct`(推荐默认:能力确认后 `cpa`,否则 hybrid 下门禁仍 direct) |
|
||||
| `cpa_probe_base_url` | CPA 对外 OpenAI base,如 `https://cpa.mangoq.ccwu.cc/v1` |
|
||||
| `cpa_probe_api_key` | 调用 CPA 的 API key(非 xAI access_token) |
|
||||
| `cpa_base_url` | **不变语义**:写入 auth 与 direct probe 的上游 base(cli-chat-proxy) |
|
||||
| `cpa_probe_chat` / `cpa_probe_chat_required` | 不变,硬门禁默认 true |
|
||||
|
||||
密钥:优先 env / 已有 secrets 约定;禁止提交真实 key。`config.example.json` 只写注释与占位。
|
||||
|
||||
## 8. Code touch map(实现阶段,非本 spec 交付代码)
|
||||
|
||||
| 区域 | 变更方向 |
|
||||
|---|---|
|
||||
| `cpa_xai/probe.py` | 抽象 transport:`direct_bearer` vs `cpa_openai`;分类逻辑复用 `classify_chat_probe` |
|
||||
| `cpa_xai/mint.py` / `cpa_export.py` | 从 config 传入 probe via / base / key;stamp 字段集合不变 |
|
||||
| `scripts/backfill_chat_stamps.py` | 同 transport,避免 backfill 与 mint 分叉 |
|
||||
| `config.example.json` | 文档化新键 |
|
||||
| 测试 | mock 两种 transport;inject hard gate 仍要求 `chat_ok`;403 仍 entitlement |
|
||||
| Obsidian | 更新「Grok 注册机与 free Build CPA」:mid-tier = tebi CPA |
|
||||
|
||||
**不改:** OAuth PKCE/device、remint skip denied、ledger、`build_chat_stamp_from_result` 禁止 null `chat_ok`。
|
||||
|
||||
## 9. Failure mapping
|
||||
|
||||
| 现象 | 产品分类 | 动作 |
|
||||
|---|---|---|
|
||||
| `/responses` 403 permission-denied | `entitlement_denied` | stamp + ledger;不 remint;不 inject |
|
||||
| 直连 426 version outdated | `auth_or_protocol` | 查头;非账号农场 |
|
||||
| CPA API key 401/403 | 运维配置错误 | 不标 entitlement_denied |
|
||||
| CPA 502 / timeout / 429 中转层 | `transient` / retryable(按现有策略) | 可重试;不 inject |
|
||||
| free-usage-exhausted | `usage_exhausted` | 不 inject;非 entitlement |
|
||||
| 钉不住凭据且未走 hybrid | **实现阻断** | 禁止默认真 `cpa` 门禁 |
|
||||
|
||||
## 10. Risks & mitigations
|
||||
|
||||
| 风险 | 缓解 |
|
||||
|---|---|
|
||||
| 假 `chat_ok`(错凭据) | §6 pinning;否则 hybrid |
|
||||
| pxed→tebi 网络不稳 | 与 inject 同 tunnel(tebi-tunnel);timeout/retry 对齐 |
|
||||
| 双模式分叉 | 单入口 `probe_*` + transport 参数;单测强制两路径分类一致 |
|
||||
| 把中转当成 L4 解药 | 文档 + 验收:denied 号经 CPA 仍 denied |
|
||||
|
||||
## 11. Acceptance criteria
|
||||
|
||||
1. 现有 entitlement / remint / inject / inventory 单测全过。
|
||||
2. 配置 `cpa_probe_via=direct`:行为与当前生产一致(回归)。
|
||||
3. 在 **可钉凭据** 或 **hybrid** 约定下:
|
||||
- 已知 denied 号 → `entitlement_denied`,无 remint 空转
|
||||
- 已知 chat_ok 号 → stamp 后可 inject;经 CPA 客户端 MINT_OK
|
||||
4. auth 文件 `base_url` 仍为 cli-chat-proxy,不被改成 cpa.mangoq。
|
||||
5. 无真实 secret 进入 git。
|
||||
|
||||
## 12. Rollout sketch
|
||||
|
||||
1. 核实 tebi CPA 钉凭据能力(read-only / 文档 / 管理 API)。
|
||||
2. 实现 transport + config + 测试。
|
||||
3. 默认:若可钉 → `cpa`;否则 hybrid + 文档。
|
||||
4. pxed 部署注册机;小流量 backfill/smoke。
|
||||
5. 更新 Obsidian free Build 文与 CPA 索引交叉链接。
|
||||
|
||||
## 13. Open questions (implementation, not design blockers)
|
||||
|
||||
1. tebi 当前 `eceasy/cli-proxy-api` 版本是否暴露 per-credential 路由头/管理字段?
|
||||
2. probe 走公网 `cpa.mangoq.ccwu.cc` 还是 SSH 隧道内网 `:8317`(延迟/鉴权差异)?
|
||||
3. hybrid 时 `probe_via_cpa_ok` 是否写入 auth 文件(可选观测字段)?
|
||||
|
||||
默认实现倾向:优先 tunnel/内网与 inject 一致;观测字段可进 stamp 但不进 inject 门闩。
|
||||
|
||||
## 14. Spec self-review
|
||||
|
||||
- [x] 无 TBD 作为核心行为空洞(open questions 仅实现选型)
|
||||
- [x] 与 hard gate / inject 规则无矛盾
|
||||
- [x] 范围单 milestone:probe 中转统一,不扩 OAuth/新服务
|
||||
- [x] 钉凭据失败路径有明确 hybrid,避免 silent wrong gate
|
||||
|
||||
---
|
||||
|
||||
## Approval
|
||||
|
||||
- Approach: **A** (user message `a`, 2026-07-16)
|
||||
- Next: user review of this file → `writing-plans` → implementation milestone (P0/P1 only)
|
||||
@@ -0,0 +1,117 @@
|
||||
# Target-Aware Node Preflight (L1 ∧ L2) Design
|
||||
|
||||
**Date:** 2026-07-17
|
||||
**Status:** Approved (user: make small milestone + development docs; strategy-group domain preflight before inject)
|
||||
**Goal:** Before seeding the register rotation pool from `nodes.json`, live-probe not only generic egress (ipify) but the **business domains required by the current provider**, and inject only the dual-pass subset.
|
||||
|
||||
## Context
|
||||
|
||||
### Evidence (2026-07-17)
|
||||
|
||||
- Imported auth proxies: **299 unique → pxed probe ok=258** (L1 = `api.ipify.org`).
|
||||
- Grok smoke with one random L1-healthy list node: browser **ERR_EMPTY_RESPONSE / RST** on `accounts.x.ai`.
|
||||
- Sample of 40 L1-healthy catalog nodes → **0** reachable for `accounts.x.ai` (almost all Connection reset).
|
||||
- Clash mixed-port `127.0.0.1:7897` → `accounts.x.ai` **200**.
|
||||
|
||||
Root cause: product “healthy” was **shallow** — “can egress to ipify” ≠ “can reach registration target”.
|
||||
|
||||
### Dual backends (unchanged)
|
||||
|
||||
| Backend | Entry | Probe | Scope of this milestone |
|
||||
|---------|-------|-------|-------------------------|
|
||||
| Clash mihomo (pxed Grok prod) | `preflight-clash-nodes.sh` | controller delay API + strategy groups | **Out of scope** (already target-group aware) |
|
||||
| `nodes.json` list\|auto | `preflight_nodes_for_register` | HTTP via proxy | **In scope** — add L2 business targets |
|
||||
|
||||
## Architecture
|
||||
|
||||
```text
|
||||
nodes import → catalog (schema; optional L1 --check)
|
||||
│
|
||||
pipeline.run(egress=list|auto, provider=P)
|
||||
│
|
||||
preflight_nodes_for_register
|
||||
resolve_probe_targets(P | extra | env)
|
||||
│
|
||||
for each candidate node (smart order, limit):
|
||||
L1: GET https://api.ipify.org?format=json → require 2xx + optional IP
|
||||
L2: GET each business URL through same proxy
|
||||
→ require *transport success* (any HTTP status OK)
|
||||
→ fail on RST / tunnel timeout / empty / connect error
|
||||
│
|
||||
pool_ready = L1 ∧ L2
|
||||
│
|
||||
seed proxy_list = pool_ready only
|
||||
0 pool_ready on list|required → FailFastError (no account burn)
|
||||
│
|
||||
register attempts on pool_ready only
|
||||
│
|
||||
runtime proxy/network fail (incl. ERR_EMPTY_RESPONSE)
|
||||
→ mark/cool/quarantine proxy; never burn email domain
|
||||
```
|
||||
|
||||
### Health layers
|
||||
|
||||
| Layer | Probe | Pass rule | Mutates `last_ok` |
|
||||
|-------|-------|-----------|-------------------|
|
||||
| **L1** egress | `DEFAULT_PROBE_URL` (ipify) | HTTP 2xx | **Yes** (catalog stamp) |
|
||||
| **L2** target | provider business URL(s) | TCP/TLS/HTTP response received (status ignored) | **No** — filters pool only |
|
||||
| **L3** runtime | register outcome | existing `report_attempt_proxy_result` | fail_count / cool / quarantine |
|
||||
|
||||
**Why L2 ignores HTTP status:** registration targets often return 302/403/426 without cookies/CLI headers. That still proves the proxy can open the path. RST / `ERR_EMPTY_RESPONSE` is the failure mode we observed.
|
||||
|
||||
### Default target map (strategy-group analogue)
|
||||
|
||||
| Provider aliases | Default L2 URL(s) |
|
||||
|------------------|-------------------|
|
||||
| `grok`, `xai` | `https://accounts.x.ai/` |
|
||||
| `chatgpt`, `openai` | `https://auth.openai.com/` |
|
||||
| `mimo`, `xiaomi`, `mimo-tts` | `https://api.xiaomimimo.com/` |
|
||||
| unknown / empty | L1 only (backward compatible) |
|
||||
|
||||
### Override order (highest first)
|
||||
|
||||
1. `extra["probe_targets"]` / `extra["nodes_probe_targets"]` — list or comma string
|
||||
2. Env `REGISTER_NODES_PROBE_TARGETS` / `NODES_PROBE_TARGETS` — comma URLs
|
||||
3. Provider map from `extra["provider"]` / `extra["_provider"]` (pipeline injects `self.provider.name`)
|
||||
4. Empty → L1-only (legacy)
|
||||
|
||||
`REGISTER_NODES_PROBE_TARGETS=0` or `none` disables L2 explicitly.
|
||||
|
||||
## Module plan
|
||||
|
||||
| File | Change |
|
||||
|------|--------|
|
||||
| `register_core/nodes/targets.py` | **New** — map + `resolve_probe_targets` |
|
||||
| `register_core/nodes/health.py` | `probe_reachable`; `probe_node_layered` (L1∧L2) |
|
||||
| `register_core/nodes/manager.py` | `check_all` / `preflight` accept `probe_urls`; pool from result when L2 on |
|
||||
| `register_core/util/proxy.py` | resolve targets; pass into manager; empty_response markers |
|
||||
| `register_core/pipeline.py` | stash `provider` name on extra before preflight |
|
||||
| `register_core/nodes/README.md` + `ARCHITECTURE.md` | product contract L1/L2 |
|
||||
| `test_register_core_nodes.py` | L2 filter + empty pool fail-fast + resolve map |
|
||||
|
||||
## Non-goals (P2/P3 backlog)
|
||||
|
||||
- Clash strategy-group rewrite inside monorepo preflight
|
||||
- Persist `last_ok_by_target` on Node (runtime filter is enough for M1)
|
||||
- AND across many L2 URLs beyond first resolved set (defaults are 1 URL)
|
||||
- Soft-inject CPA on chat 403
|
||||
- Changing import to require L2
|
||||
|
||||
## Manual-required
|
||||
|
||||
- Grok production on pxed: keep **Clash 7897** until an L2-ready catalog pool is non-empty for `accounts.x.ai`.
|
||||
- Free Build chat 403 remains account entitlement, unrelated to this milestone.
|
||||
|
||||
## Acceptance
|
||||
|
||||
1. Unit: L1-only path unchanged when no provider/targets.
|
||||
2. Unit: L1 pass + L2 fail → URL **not** in seeded `proxy_list`.
|
||||
3. Unit: all L2 fail on `egress=list` → `FailFastError`.
|
||||
4. Unit: pipeline/extra provider `grok` resolves `accounts.x.ai`.
|
||||
5. Docs: ARCHITECTURE + nodes README describe L1∧L2 gate.
|
||||
6. Runtime markers include empty response / connection reset language.
|
||||
|
||||
## Git
|
||||
|
||||
Single commit preferred:
|
||||
`feat(nodes): target-aware L1+L2 preflight before pool inject`
|
||||
@@ -0,0 +1,252 @@
|
||||
# Register Profile Config Abstraction Design
|
||||
|
||||
**Date:** 2026-07-17
|
||||
**Status:** Approved (approach 1; user: continue without pause)
|
||||
**Goal:** Drive the whole register machine from one profile: mailbox, decode, provider, strategy (runtime + risk), verify, sink, secrets.
|
||||
|
||||
## Context
|
||||
|
||||
Today layers exist (`email/*`, `providers/*`, `verify/*`, `pipeline`) but wiring is scattered across CLI flags, env vars, and `RegisterJob.extra`. ChatGPT is in-process; Grok/MiMo are black-box and ignore `EmailSource`. Operators want:
|
||||
|
||||
1. **Decode** — CF Worker / Gmail / … as config
|
||||
2. **Register** — target site as config
|
||||
3. **Strategy** — runtime + risk/asset policy as config
|
||||
4. **Mailbox** — address allocation separate from decode
|
||||
|
||||
Decisions locked in brainstorming:
|
||||
|
||||
| Topic | Choice |
|
||||
|-------|--------|
|
||||
| Strategy | **D** — runtime + risk/burn in `strategy`; product params on provider |
|
||||
| Config form | **A** — one YAML/JSON profile is authority |
|
||||
| Product scope | **B** — all three products truly share mailbox+decode (phased) |
|
||||
| Mailbox vs decode | **B** — split two layers |
|
||||
| Secrets | **C** — dev may plaintext; prod forces `*_env` refs |
|
||||
| Architecture | **Approach 1** — Profile → RuntimeBundle four-layer runtime |
|
||||
|
||||
## Architecture (end state)
|
||||
|
||||
```text
|
||||
profiles/<name>.yaml # single run authority
|
||||
│
|
||||
ProfileLoader (schema + secrets resolve + CLI overrides)
|
||||
│
|
||||
RuntimeBundle
|
||||
├─ MailboxProvider allocate / release only
|
||||
├─ OtpDecoder wait_otp(mailbox) only
|
||||
├─ RegisterProvider site protocol; consumes mailbox+decoder
|
||||
├─ StrategyEngine fail-fast, egress, burn/cool, mail≠register proxy
|
||||
└─ Verifier + Sink
|
||||
│
|
||||
Pipeline.run(count)
|
||||
```
|
||||
|
||||
### Hard boundaries (production discipline)
|
||||
|
||||
1. Mail proxy never inherits register egress.
|
||||
2. Fail-fast on configured `error_kind`s; no empty retry same IP+domain class.
|
||||
3. Success = this-run attribution only.
|
||||
4. No soft-inject without verify pass.
|
||||
5. Prod profiles: no plaintext secrets.
|
||||
6. Three products share the same Pipeline contracts eventually.
|
||||
|
||||
## Profile schema (v1)
|
||||
|
||||
```yaml
|
||||
# profiles/chatgpt-cf-clash.example.yaml
|
||||
apiVersion: register.v1
|
||||
kind: RegisterProfile
|
||||
metadata:
|
||||
name: chatgpt-cf-clash
|
||||
description: ChatGPT via CF Worker mailbox+decode, Clash egress
|
||||
|
||||
spec:
|
||||
provider:
|
||||
name: chatgpt # chatgpt | grok | mimo
|
||||
# product-local knobs only
|
||||
options:
|
||||
otp_timeout_s: 180
|
||||
headless: true # ignored by chatgpt; used by grok/mimo later
|
||||
|
||||
count: 1
|
||||
|
||||
mailbox:
|
||||
type: cloudflare # cloudflare | tinyhost | gmail_imap | duckmail | local_part
|
||||
# type-specific:
|
||||
domain: mangoqwq.com # optional pin for tinyhost/local_part
|
||||
# local: random | fixed:<name>
|
||||
|
||||
decode:
|
||||
type: cloudflare # cloudflare | gmail_imap | tinyhost | duckmail
|
||||
options:
|
||||
timeout_s: 180
|
||||
poll_interval_s: 2.5
|
||||
sender_hint: "" # optional
|
||||
|
||||
strategy:
|
||||
fail_fast: true
|
||||
fail_fast_kinds:
|
||||
- registration_disallowed
|
||||
- unsupported_email
|
||||
- fatal
|
||||
- verify
|
||||
egress:
|
||||
mode: clash # auto | core | clash | list | direct
|
||||
proxy: "http://127.0.0.1:7897" # optional fixed
|
||||
proxy_list: "" # path or comma URLs
|
||||
rotate_every: 1
|
||||
rotate_required: false
|
||||
mail_proxy: direct # direct | url | env:MAIL_PROXY
|
||||
burn:
|
||||
enabled: true
|
||||
track: [ip, domain]
|
||||
on_kinds: [registration_disallowed, unsupported_email]
|
||||
state_path: ".register/burn_state.json" # optional; empty = memory only
|
||||
cool:
|
||||
soft_seconds: 0 # 0 = off in M1
|
||||
|
||||
verify:
|
||||
enabled: true
|
||||
name: auto # auto = provider default; or noop
|
||||
|
||||
sink:
|
||||
path: "providers/chatgpt/output/pipeline.jsonl" # empty = no sink
|
||||
|
||||
secrets:
|
||||
mode: prod # dev | prod
|
||||
# prod: only env refs allowed for secret fields
|
||||
# map used by mailbox/decode constructors:
|
||||
# cloudflare_api_base_env: CLOUDFLARE_API_BASE
|
||||
# cloudflare_api_key_env: CLOUDFLARE_API_KEY
|
||||
```
|
||||
|
||||
### Compatibility aliases
|
||||
|
||||
- `mailbox.type` / `decode.type`: `cf` → `cloudflare`, `gmail` → `gmail_imap`
|
||||
- If only legacy `email_source: cloudflare` is present (CLI path), loader builds matching mailbox+decode pair of the same type (paired mode).
|
||||
|
||||
### Paired vs split
|
||||
|
||||
| Mode | Meaning |
|
||||
|------|---------|
|
||||
| **paired** | mailbox.type == decode.type and both talk to same backend (CF allocate + CF poll). Default for M1 adapters. |
|
||||
| **split** | Different types (e.g. mailbox local_part@mangoqwq.com + decode gmail_imap). Allowed when both layers can cooperate on the same address. |
|
||||
|
||||
M1 implements paired fully; split is validated only when both types support `Mailbox.token` / address contract (documented per pair). Unsupported splits fail-fast at load.
|
||||
|
||||
## Interfaces
|
||||
|
||||
### MailboxProvider
|
||||
|
||||
```python
|
||||
class MailboxProvider(Protocol):
|
||||
name: str
|
||||
def allocate(self) -> Mailbox: ...
|
||||
def release(self, mailbox: Mailbox, *, success: bool) -> None: ...
|
||||
```
|
||||
|
||||
### OtpDecoder
|
||||
|
||||
```python
|
||||
class OtpDecoder(Protocol):
|
||||
name: str
|
||||
def wait_otp(
|
||||
self,
|
||||
mailbox: Mailbox,
|
||||
*,
|
||||
timeout_s: float = 180,
|
||||
poll_interval_s: float = 3,
|
||||
used_codes: set[str] | None = None,
|
||||
newer_than_epoch: float | None = None,
|
||||
sender_hint: str | None = None,
|
||||
) -> OtpCode: ...
|
||||
# optional: last_wait_diagnostics
|
||||
```
|
||||
|
||||
### Composite EmailSource (compat bridge)
|
||||
|
||||
```python
|
||||
class CompositeEmailSource:
|
||||
"""EmailSource façade over MailboxProvider + OtpDecoder for existing adapters."""
|
||||
name: str # f"{mailbox.name}+{decode.name}" or single if paired
|
||||
def allocate(...): return mailbox.allocate()
|
||||
def poll_otp(...): return decoder.wait_otp(...)
|
||||
def release(...): return mailbox.release(...)
|
||||
```
|
||||
|
||||
Existing `ChatGPTProvider` keeps accepting `EmailSource`; Pipeline injects `CompositeEmailSource` from profile. No adapter rewrite required for M1.
|
||||
|
||||
### StrategyEngine (M2 full; M1 subset)
|
||||
|
||||
M1: read fail_fast + egress + mail_proxy from profile into `RegisterJob` / `extra` (same keys pipeline already understands).
|
||||
M2: burn state file + feedback hooks centralized (today partially in proxy util + ops scripts).
|
||||
|
||||
### RegisterProvider (unchanged signature M1)
|
||||
|
||||
```python
|
||||
def register_one(*, email_source: EmailSource | None = None, extra: dict | None = None) -> RegisterResult
|
||||
```
|
||||
|
||||
M3/M4: Grok/MiMo must consume injected EmailSource (composite); black-box internal mail becomes fallback only when profile says `mailbox.type: provider` / `decode.type: provider`.
|
||||
|
||||
## Loader rules
|
||||
|
||||
1. Accept `.yaml` / `.yml` / `.json`.
|
||||
2. `apiVersion` must be `register.v1`.
|
||||
3. Resolve secrets:
|
||||
- `secrets.mode=prod`: any field ending in secret-like names must be env ref or empty; plaintext non-empty secrets → load error.
|
||||
- `dev`: plaintext allowed.
|
||||
4. CLI overrides (non-secret): `--count`, `--no-verify`, `--egress`, `--proxy`, `--sink`, `--no-fail-fast`.
|
||||
5. Env still fills constructor secrets when profile uses `*_env` keys or legacy env (CLOUDFLARE_API_BASE, GMAIL_IMAP_*).
|
||||
6. Output: `RegisterJob` + resolved RuntimeBundle metadata in `job.extra["_profile"]` (name, path, mailbox, decode types — no secrets).
|
||||
|
||||
## CLI
|
||||
|
||||
```bash
|
||||
# New (preferred)
|
||||
python -m register_core run --profile profiles/chatgpt-cf-clash.yaml
|
||||
|
||||
# Legacy flags still work (build ephemeral profile in memory)
|
||||
python -m register_core run -p chatgpt --email-source cloudflare -n 1 --egress clash
|
||||
```
|
||||
|
||||
When both `--profile` and `-p` are set: profile is base; CLI provider must match or fail-fast.
|
||||
|
||||
## Data flow (one attempt)
|
||||
|
||||
1. Strategy preflight egress (existing nodes preflight).
|
||||
2. Strategy inject attempt proxy into `extra`.
|
||||
3. Provider `register_one(email_source=composite, extra=...)`.
|
||||
4. composite.allocate → site protocol → composite.poll_otp → token.
|
||||
5. Verifier; Sink; Strategy feedback (burn on configured kinds).
|
||||
|
||||
## Migration milestones
|
||||
|
||||
| ID | Deliverable | Done when |
|
||||
|----|-------------|-----------|
|
||||
| **M1** | Schema + Loader + Mailbox/Decode protocols + Composite + ChatGPT via `--profile` | unit tests; offline load; ChatGPT path equivalent to flags |
|
||||
| **M2** | StrategyEngine burn/cool state | burn file updates on registration_disallowed without residual shell |
|
||||
| **M3** | MiMo consumes EmailSource | profile can switch CF/Gmail for MiMo |
|
||||
| **M4** | Grok consumes EmailSource | same |
|
||||
|
||||
## Non-goals (this design)
|
||||
|
||||
- Soft inject / remint spin
|
||||
- Hotmail plus-alias farm
|
||||
- Unifying Grok Drission DOM into curl_cffi
|
||||
- Live chat entitlement unlock
|
||||
- Plugin marketplace / DAG workflow language
|
||||
|
||||
## Testing (M1)
|
||||
|
||||
- Load example profiles (dev + prod secret rejection)
|
||||
- Composite allocate/poll delegates
|
||||
- Pipeline.from_job still works with legacy email_source
|
||||
- Pipeline.from_profile builds job with mail_proxy + egress
|
||||
- ChatGPT verifier still accepts rt.1
|
||||
|
||||
## Example profiles shipped
|
||||
|
||||
- `profiles/chatgpt-cf.example.yaml`
|
||||
- `profiles/chatgpt-tinyhost.example.yaml`
|
||||
- `profiles/chatgpt-gmail.example.yaml`
|
||||
Reference in New Issue
Block a user