Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-gate-plugins.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:
inputs:
agents:
description: "comma-separated lanes: dsh,pi,codex,opencode,claude"
description: "comma-separated lanes: dsh,pi,codex,opencode,claude (+ dsh matrix/proxy #3475: dsh-responses,dsh-anthropic,dsh-google,dsh-proxy)"
required: false
default: "dsh,pi,codex,opencode,claude"

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ dist/
tmp/
tests/.pp-stamp-state-*/
.tmp/
plugin-lanes/
73 changes: 70 additions & 3 deletions scripts/gate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,68 @@ actually received — internal logs can be fooled by suppression-class bugs
S40 last CODEWORDS markers)
- no `unknown tool` loops

## dsh protocol matrix (#3475)

dsh's model client (pi-ai) speaks all four common protocols, so the dsh lane
expands from one door to four — same headless driver, only the cordis provider
`api` and the baseURL suffix change; the t1→t4 flow and assertions are
unchanged:

| lane | pi-ai api | bili front door | upstream door required |
|------|-----------|-----------------|------------------------|
| `dsh` (original) | openai-completions | `/v1/chat/completions` | chat completions |
| `dsh-responses` | openai-responses | `/v1/responses` | a real `/v1/responses` (404 / mapping 400 → env-blocked) |
| `dsh-anthropic` | anthropic-messages | `/v1/messages` | `/v1/messages` (cross-checks the claude lane) |
| `dsh-google` | google-generative-ai | `/v1beta/models/<id>:streamGenerateContent` | a `/v1beta` google door |
| `dsh-proxy` | openai-completions (**proxy mode**) | `/bili/…/v1/chat/completions` | chat completions (via the `/bili/` prefix) |

`dsh-proxy` is the **other activation path** of the same host (owner add-on):
the profile does **NOT** load the billion-context bundle (its fetch intercept
would stamp `x-bili-plugin` and flip the lane back into plugin mode); dsh
drives the manually started proxy's `/bili/` URL directly — the same shape as
codex/claude. Contrasted with the native `dsh` lane within ONE script:
#3177/#3401-style suppression only exists on the plugin path; in proxy mode
nudge/fold must ride the wire with the acp_summary carrier; window truth =
bili.json (like every prefix lane).

Every door gains a **wire-shape hard assertion**: each recorder POST through
the door must match the protocol's path AND top-level body fields
(chat=`messages` / responses=`input` / anthropic=`system`+blocks /
google=`contents`) — a silent rewire must not read green; the first egress
request is dumped to `<work>/<agent>/egress-sample.json` as round-trip
evidence.

Two known facts:

- **bili does not translate google→chat on egress** — the recorder sees exactly
the google shape dsh sends (`:streamGenerateContent` + contents/parts). The
google lane can only go fully green against an upstream that has a real
google door; requiring "it must come out as chat" would be a new
egress-translation feature for bili — separate issue.
- **blocked demotion rules** (two kinds; the script prints an
`ENV-BLOCKED`/`CLIENT-BLOCKED [lane] <reason>` line at the end):
- **env**: the upstream door is unhealthy — ALL requests on the door are
4xx/5xx/connection errors with no turn completed (the original
opencode2/#3461 rule), OR degraded mid-flow (some 200s at first, then
rejections, the flow never completes — the classic self-hosted
responses→chat mapping-bug shape, #3461 sibling). Traffic + wire shape
stay hard assertions; turn-dependent records drop out of the gate tally.
- **client**: the client version cannot express the api at all (dsh
≤0.2.1-rc.1 cordis schema lists only openai-completions / openai-responses /
anthropic-messages; google-generative-ai exists in the pi-ai library but
dsh's config surface does not expose it) — zero upstream traffic + every
turn dies on a ValidationError. The whole lane drops out of the gate; it
auto-promotes when the client ships the protocol — no script change needed.

Not in the default GATE_AGENTS set; runs only when explicitly listed:
`GATE_AGENTS=dsh,dsh-responses,dsh-anthropic,dsh-google,dsh-proxy`.

## Lane flow

1. **t1 @ big window**: read the corpus, echo the S40 codeword (fold must NOT
fire in this phase)
1. **t1 @ big window**: read the corpus, echo the S40 + S07 codewords (dual
marker proves the corpus middle was really read — models may chunk-read or
elide the middle, and an elided middle turns the later S07 recall assertions
into false reds; fold must NOT fire in this phase)
2. **window shrink**: rewrite the **host's own** model config (dsh cordis /
pi models.json / opencode.json limit / codex config.toml / claude model
alias) — the effective window reaches bili via the
Expand Down Expand Up @@ -66,8 +124,17 @@ node scripts/gate/plugin-lanes.mjs
- `GATE_AGENTS` selects a subset of lanes; `GATE_TURN_TIMEOUT_MS` (default
300000), `GATE_BIG/MID/SMALL_WINDOW`, and `PLUGIN_LANES_WORK` (artifact
dir, default `./plugin-lanes/`) are tunable
- dsh lanes: `GATE_DSH_VERSION` (each lane self-installs
`@deepseek-ai/dsh@<v>`, default latest — system dsh may be too old and a
global billion-context shadows the candidate bundle), `GATE_OUTPUT_TOKENS`
(output budget: bili.json reservation + dsh cordis maxTokens, default 4096;
raise it when a thinking model burns the whole budget on reasoning with no
visible text), `GATE_DSH_SMALL_WINDOW` (fixed override of the t3 small
window; by default derived from the live t2-end payload — dsh's fixed
scaffolding is ~18k tok and a static 24576 minus the output reservation
cannot fit even an empty session)
- per-lane artifacts: `<work>/<agent>/turn-t{1..4}.txt`, `upstream.jsonl`,
`bili.log`
`bili.log`, plus `<work>/<agent>/egress-sample.json` for the dsh family
- the opencode2 lane is not in the default set: transport websocket passes
Responses-WS straight through (HTTP-only upstreams die on the handshake),
and transport http depends on upstream `/v1/responses` quality — see
Expand Down
56 changes: 55 additions & 1 deletion scripts/gate/README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,56 @@ wire 骗不了:
- 折叠前后暗号回忆(corpus 40 段,S07 早段/S40 末段 CODEWORDS 暗号)
- 无 `unknown tool` 空转

## dsh 协议矩阵(#3475)

dsh 的模型客户端 pi-ai 支持全部四种通用协议,dsh 车道因此从一门扩成四门——
同一套 headless 驱动,只换 cordis provider 的 `api` 与 baseURL 后缀,t1→t4
流程和断言不变:

| 车道 | pi-ai api | bili 前门 | 上游门要求 |
|------|-----------|----------|------------|
| `dsh`(原有) | openai-completions | `/v1/chat/completions` | chat completions |
| `dsh-responses` | openai-responses | `/v1/responses` | 真实 `/v1/responses`(404/映射 400 → env-blocked) |
| `dsh-anthropic` | anthropic-messages | `/v1/messages` | `/v1/messages`(claude 车道的交叉验证) |
| `dsh-google` | google-generative-ai | `/v1beta/models/<id>:streamGenerateContent` | `/v1beta` google 门 |
| `dsh-proxy` | openai-completions(**代理模式**) | `/bili/…/v1/chat/completions` | chat completions(经 `/bili/` 前缀) |

`dsh-proxy` 是同一宿主的**另一条激活路径**(owner 加项):profile **不装**
billion-context bundle(装了它的 fetch 拦截会盖 `x-bili-plugin` 头把车道翻回
插件模式),dsh 直连手动起的代理 `/bili/` URL——codex/claude 同款形状。与
native `dsh` 车道同脚本对照:#3177/#3401 类抑制只存在于插件路径,代理模式下
nudge/fold 必须以 acp_summary 载体正常上 wire;窗口真值 = bili.json(与所有
prefix 车道一致)。

每门新增 **wire 形状硬断言**:recorder 里该门的每个 POST 必须路径+顶层体字段
都是该协议形状(chat=`messages` / responses=`input` / anthropic=`system`+blocks /
google=`contents`),防止静默换线假绿;首个出站请求存
`<work>/<agent>/egress-sample.json` 作往返证据。

两个已知事实:

- **bili 出站不做 google→chat 翻译**——recorder 看到的正是 dsh 发出的 google
形状(`:streamGenerateContent` + contents/parts)。google lane 只能在有真
google 门的上游上满绿;要「必须 chat 出」则是给 bili 加出站翻译功能,单独立项。
- **blocked 降级规则**(两种 kind,脚本结尾打印 `ENV-BLOCKED`/`CLIENT-BLOCKED
[lane] <原因>` 行):
- **env**:上游门不健康——门上请求**全部** 4xx/5xx/连接错误且无回合完成
(opencode2/#3461 原规矩),或**中途劣化**(前若干请求 200、后续被拒、流程
未走完——自建服务 responses→chat 映射 bug 的典型形态,#3461 同族)。
traffic + wire 形状仍是硬断言,turn 相关断言不计入 gate 成败。
- **client**:客户端当前版本根本表达不了该 api(dsh ≤0.2.1-rc.1 的 cordis
schema 只列 openai-completions/openai-responses/anthropic-messages 三门,
google-generative-ai 在 pi-ai 库里有实现但 dsh 配置面没暴露)——零上游流量
+ 每回合死于 ValidationError。整条车道不计入 gate,客户端放出该协议后
自动转正,脚本不用改。

不进默认 GATE_AGENTS 集,显式加入才跑:`GATE_AGENTS=dsh,dsh-responses,dsh-anthropic,dsh-google,dsh-proxy`。

## 车道流程

1. **t1 @ 大窗**:读 corpus,回显 S40 暗号(此阶段 fold 必须不触发)
1. **t1 @ 大窗**:读 corpus,回显 S40 + S07 双暗号(双标记验证「真的读全了」——
模型可能照指令分块读、也可能漏读中段,漏读会让后续 S07 回忆断言变成假红;
此阶段 fold 必须不触发)
2. **窗口收缩**:改**宿主自己的**模型配置(dsh cordis / pi models.json /
opencode.json limit / codex config.toml / claude 模型别名)——有效窗口经
`x-bili-plugin-context-window` 头进 bili,native 代理的 zone 端口是粘滞的,
Expand All @@ -55,7 +102,14 @@ node scripts/gate/plugin-lanes.mjs
- `GATE_AGENTS` 选车道子集;`GATE_TURN_TIMEOUT_MS`(默认 300000)、
`GATE_BIG/MID/SMALL_WINDOW`、`PLUGIN_LANES_WORK`(工件目录,默认
`./plugin-lanes/`)可调
- dsh 车道:`GATE_DSH_VERSION`(每车道自装 `@deepseek-ai/dsh@<v>`,默认
latest——系统 dsh 可能太旧且全局 billion-context 会遮蔽候选 bundle)、
`GATE_OUTPUT_TOKENS`(输出预算:bili.json 预留 + dsh cordis maxTokens,
默认 4096;思考型模型吃光预算只出 reasoning 不出正文时调大)、
`GATE_DSH_SMALL_WINDOW`(固定覆盖 t3 小窗;默认从 t2 末尾实际 payload
推导——dsh 固定脚手架 ~18k tok,静态 24576 扣掉输出预留后连空会话都装不下)
- 每车道工件:`<work>/<agent>/turn-t{1..4}.txt`、`upstream.jsonl`、`bili.log`
(dsh 家族另有 `egress-sample.json`)
- opencode2 车道不进默认集:transport websocket 直通 Responses-WS(HTTP-only
上游握手必死)、transport http 依赖上游 /v1/responses 质量——见 #3461;
车道仍断言 tools/claim/流量
Expand Down
Loading
Loading