diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index e2bf921e..a3b986c6 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -221,6 +221,8 @@ jobs:
run: |
bash e2e/package-notices.sh
python3 -m unittest discover -s e2e -p 'test_release_notices.py' -v
+ - name: Test Markdown report integrity checks
+ run: python3 -m unittest discover -s scripts -p 'test_report_integrity_check.py' -v
- name: Test patched Norma SDK
working-directory: third_party/norma
run: go test ./... -count=1
diff --git a/db/config.go b/db/config.go
index 0d54320f..f5c91ba0 100644
--- a/db/config.go
+++ b/db/config.go
@@ -4,10 +4,12 @@ import (
"context"
"database/sql"
"encoding/json"
+ "strings"
+ "time"
+
"github.com/Autumn-27/artex/llmnet"
"github.com/Autumn-27/artex/locale"
"github.com/Autumn-27/artex/opencodesdk"
- "time"
)
// ---------- LLM profiles ----------
@@ -163,7 +165,7 @@ ORDER BY is_default DESC, priority DESC, id ASC`)
return out, rows.Err()
}
-// SaveProfile inserts (id==0) or updates a profile. Empty apiKey on update keeps existing.
+// SaveProfile inserts (id==0) or updates a profile, retaining an omitted key when its scope allows.
func (d *DB) SaveProfile(p *LLMProfile) (int64, error) {
if p.Format == opencodesdk.Format && !opencodesdk.ValidModel(p.Model) {
return 0, locale.NewError("OpenCode SDK model must be providerID/modelID")
@@ -184,24 +186,30 @@ VALUES ($1,$2,NULLIF($3,''),NULLIF($4,''),$5,NULLIF($6,''),NULLIF($7,''),$8,$9,$
r.Connect.Attempts, r.Connect.IntervalMS, r.Empty.Attempts, r.Empty.IntervalMS, r.Stream.Attempts, r.Stream.IntervalMS, p.KeepAlive, p.MaxConcurrent).Scan(&id)
return id, err
}
- if p.APIKey == "" {
- // Lock the credential scope and update key/hint together; concurrent edits cannot reuse a token from another bridge.
+ if strings.TrimSpace(p.APIKey) == "" {
+ // Lock the credential scope and update key/hint together so concurrent edits use the current endpoint.
tx, err := d.Begin()
if err != nil {
return p.ID, err
}
defer tx.Rollback()
var oldFormat, oldURL string
- if err = tx.QueryRow(`SELECT format,COALESCE(base_url,'') FROM llm_profiles WHERE id=$1 FOR UPDATE`, p.ID).Scan(&oldFormat, &oldURL); err != nil {
+ var active bool
+ if err = tx.QueryRow(`SELECT format,COALESCE(base_url,''),is_default FROM llm_profiles WHERE id=$1 FOR UPDATE`, p.ID).Scan(&oldFormat, &oldURL, &active); err != nil {
if err == sql.ErrNoRows {
return p.ID, nil
}
return p.ID, err
}
clearSDK := (oldFormat == opencodesdk.Format || p.Format == opencodesdk.Format) && (oldFormat != p.Format || !opencodesdk.SameEndpoint(oldURL, p.BaseURL))
+ crossesGateway := llmnet.CrossesCheaperInferenceOrigin(oldURL, p.BaseURL)
+ if active && crossesGateway && (p.Format == opencodesdk.Format || (p.Format != "ollama" && !llmnet.IsLocalEndpoint(p.BaseURL))) {
+ return p.ID, ErrActiveLLMProfileKeyRequired
+ }
+ clearKey := clearSDK || crossesGateway
_, err = tx.Exec(`UPDATE llm_profiles SET name=$1,format=$2,api_key=CASE WHEN $26 OR ($2='ollama' AND format<>'ollama') THEN NULL ELSE api_key END,api_key_hint=CASE WHEN $26 OR ($2='ollama' AND format<>'ollama') THEN NULL ELSE api_key_hint END,base_url=NULLIF($3,''),proxy=NULLIF($4,''),model=$5,rate_per_second=$6,rate_per_minute=$7,context_window_k=$8,reasoning_effort=$9,priority=$10,pool_exclude=$11,thinking_type=$12,streaming=$13,max_tokens=$14,max_tokens_field=$15,session_header_key=$16,retry_connect_attempts=$17,retry_connect_interval_ms=$18,retry_empty_attempts=$19,retry_empty_interval_ms=$20,retry_stream_attempts=$21,retry_stream_interval_ms=$22,keep_alive=$23,llm_max_concurrent=$24 WHERE id=$25`,
p.Name, p.Format, p.BaseURL, p.Proxy, p.Model, p.RatePerSecond, p.RatePerMinute, p.ContextWindowK, p.ReasoningEffort, p.Priority, p.PoolExclude, p.ThinkingType, p.Streaming, p.MaxTokens, p.MaxTokensField, p.SessionHeaderKey,
- r.Connect.Attempts, r.Connect.IntervalMS, r.Empty.Attempts, r.Empty.IntervalMS, r.Stream.Attempts, r.Stream.IntervalMS, p.KeepAlive, p.MaxConcurrent, p.ID, clearSDK)
+ r.Connect.Attempts, r.Connect.IntervalMS, r.Empty.Attempts, r.Empty.IntervalMS, r.Stream.Attempts, r.Stream.IntervalMS, p.KeepAlive, p.MaxConcurrent, p.ID, clearKey)
if err != nil {
return p.ID, err
}
@@ -215,6 +223,7 @@ VALUES ($1,$2,NULLIF($3,''),NULLIF($4,''),$5,NULLIF($6,''),NULLIF($7,''),$8,$9,$
var (
ErrActiveLLMProfileDelete = locale.NewError("cannot delete the active LLM profile; activate another profile first")
+ ErrActiveLLMProfileKeyRequired = locale.NewError("API key was not provided")
ErrLLMProfileReferencesChanged = locale.NewError("LLM profile references changed while deleting; retry the request")
ErrLLMProfileNotFound = locale.NewError("LLM profile not found")
)
diff --git a/db/config_sdk_test.go b/db/config_sdk_test.go
index c4602f66..a82d57b8 100644
--- a/db/config_sdk_test.go
+++ b/db/config_sdk_test.go
@@ -1,11 +1,12 @@
package db
import (
+ "errors"
"fmt"
"testing"
)
-func TestSDKProfileCredentialTransitions(t *testing.T) {
+func TestProfileCredentialTransitions(t *testing.T) {
d, err := Open(testDSN(t))
if err != nil {
t.Fatal(err)
@@ -21,10 +22,16 @@ func TestSDKProfileCredentialTransitions(t *testing.T) {
{"cloud to SDK", "openai", "https://api.openai.com/v1", "opencode-sdk", "http://localhost:4097", "", ""},
{"SDK explicit replacement", "opencode-sdk", "http://localhost:4097/a", "opencode-sdk", "http://localhost:4097/b", "new-token", "new-token"},
{"cloud unchanged behavior", "openai", "https://one.example/v1", "openai", "https://two.example/v1", "", "old-token"},
+ {"cloud to Cheaper Inference", "openai", "https://api.openai.com/v1", "openai", "https://api.cheaperinference.com/v1", "", ""},
+ {"Cheaper Inference to cloud", "openai", "https://api.cheaperinference.com/v1", "openai", "", "", ""},
+ {"Cheaper Inference same origin", "openai", "https://api.cheaperinference.com/v1", "openai", "https://API.CHEAPERINFERENCE.COM.:443/custom", "", "old-token"},
+ {"Cheaper Inference different scheme", "openai", "https://api.cheaperinference.com/v1", "openai", "http://api.cheaperinference.com/v1", "", ""},
+ {"Cheaper Inference different port", "openai", "https://api.cheaperinference.com/v1", "openai", "https://api.cheaperinference.com:8443/v1", "", ""},
+ {"Cheaper Inference explicit replacement", "openai", "https://api.openai.com/v1", "openai", "https://api.cheaperinference.com/v1", "new-token", "new-token"},
}
for i, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
- p := &LLMProfile{Name: fmt.Sprintf("sdk-token-transition-%d", i), Format: tc.oldFormat, BaseURL: tc.oldURL, Model: "opencode/test", APIKey: "old-token", Streaming: true}
+ p := &LLMProfile{Name: fmt.Sprintf("credential-transition-%d", i), Format: tc.oldFormat, BaseURL: tc.oldURL, Model: "opencode/test", APIKey: "old-token", Streaming: true}
id, e := d.SaveProfile(p)
if e != nil {
t.Fatal(e)
@@ -57,6 +64,69 @@ func TestSDKProfileCredentialTransitions(t *testing.T) {
}
}
+func TestActiveGatewayCredentialTransitionRequiresKey(t *testing.T) {
+ d, err := Open(testDSN(t))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer d.Close()
+ previousActive, err := d.ActiveProfile()
+ if err != nil {
+ t.Fatal(err)
+ }
+ if previousActive != nil {
+ defer d.SetActiveProfile(previousActive.ID)
+ }
+
+ const gateway = "https://api.cheaperinference.com/v1"
+ for _, tc := range []struct {
+ name, format, target, key string
+ wantError bool
+ }{
+ {"cloud default needs a key", "openai", "", "", true},
+ {"whitespace is not a key", "openai", "", " ", true},
+ {"SDK bridge needs a key", "opencode-sdk", "http://127.0.0.1:4097", "", true},
+ {"local API can be keyless", "openai", "http://127.0.0.1:8080/v1", "", false},
+ {"Ollama can be keyless", "ollama", "http://127.0.0.1:11434", "", false},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ p := &LLMProfile{Name: "active-gateway-scope", Format: "openai", BaseURL: gateway, Model: "opencode/test", APIKey: "old-token"}
+ id, err := d.SaveProfile(p)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer d.Exec(`DELETE FROM llm_profiles WHERE id=$1`, id)
+ if err := d.SetActiveProfile(id); err != nil {
+ t.Fatal(err)
+ }
+
+ p.ID, p.Format, p.BaseURL, p.APIKey = id, tc.format, tc.target, tc.key
+ _, err = d.SaveProfile(p)
+ wantFormat, wantURL, wantKey, wantHint := tc.format, tc.target, "", ""
+ if tc.wantError {
+ if !errors.Is(err, ErrActiveLLMProfileKeyRequired) {
+ t.Fatalf("save error = %v, want active profile key required", err)
+ }
+ wantFormat, wantURL, wantKey, wantHint = "openai", gateway, "old-token", "…oken"
+ } else if err != nil {
+ t.Fatal(err)
+ }
+
+ got, err := d.ActiveProfile()
+ if err != nil || got == nil {
+ t.Fatalf("active profile = %v, err = %v", got, err)
+ }
+ var hint string
+ if err := d.QueryRow(`SELECT COALESCE(api_key_hint,'') FROM llm_profiles WHERE id=$1`, id).Scan(&hint); err != nil {
+ t.Fatal(err)
+ }
+ if got.ID != id || got.Format != wantFormat || got.BaseURL != wantURL || got.APIKey != wantKey || hint != wantHint {
+ t.Fatalf("active credential or endpoint differs from expected state: id=%d format=%q url=%q hint=%q", got.ID, got.Format, got.BaseURL, hint)
+ }
+ })
+ }
+}
+
func TestSDKFormatUpgradePreservesExistingProfiles(t *testing.T) {
d, err := Open(testDSN(t))
if err != nil {
diff --git a/docs/es/llm-providers.md b/docs/es/llm-providers.md
index 3a44792a..3f92b141 100644
--- a/docs/es/llm-providers.md
+++ b/docs/es/llm-providers.md
@@ -114,6 +114,24 @@ SCOPEWEAVER_LLM_MODEL=glm-5.3-flash
`SCOPEWEAVER_LLM_PROVIDER=opencode-go` se resuelve al formato de protocolo OpenAI Chat Completions; la URL base y el modelo no definidos usan los valores de la tabla anterior.
+## Cheaper Inference (pasarela compatible con OpenAI)
+
+Abre **LLM → Nuevo → Plantilla de configuración** y elige **Cheaper Inference · gpt-5.4-mini**.
+
+| Campo | Valor |
+| --- | --- |
+| Formato | OpenAI Chat Completions |
+| URL base | `https://api.cheaperinference.com/v1` |
+| Modelo | `gpt-5.4-mini` |
+| Pensamiento | omitido (predeterminado del modelo) |
+| Esfuerzo de razonamiento | omitido (predeterminado del modelo) |
+| Ventana de contexto (K) | `0` (200K por defecto) |
+| Límite de salida | `16384`, enviado como `max_completion_tokens` |
+
+Cheaper Inference es una pasarela LLM compatible con OpenAI; una sola clave de API da acceso a modelos de varios laboratorios. El ID del modelo y sus límites (contexto de 400K, salida de 128K) se comprobaron en la lista pública de modelos `https://api.cheaperinference.com/public/models` el 2026-11-05. Los modelos GPT-5.4 reciben el límite de salida como `max_completion_tokens`; la plantilla omite el esfuerzo para usar el predeterminado del modelo. **Cargar modelos** lee la lista `/v1/models` de la pasarela, que requiere la clave; el campo sigue editable para otros ID como `deepseek-v4-flash` o `claude-sonnet-5`.
+
+**Credencial:** crea una clave en https://cheaperinference.com (documentación: https://cheaperinference.com/docs). Al elegir esta plantilla, o al cambiar la **URL base** hacia o desde la pasarela, se borra la clave que ya hubiera en el formulario, de modo que una clave de otro endpoint nunca se envía a la pasarela ni una clave de la pasarela a otro destino. Después de elegir la plantilla, pega tu clave de Cheaper Inference en **Clave API**; **Cargar modelos**, **Probar conexión** y el guardado se detienen con un aviso de clave ausente hasta que la introduzcas. Volver a elegir la plantilla o cambiar solo la ruta en la pasarela conserva la clave introducida. La plantilla no guarda ni activa nada. La plantilla usa la ruta existente de OpenAI Chat Completions; está cubierta por pruebas unitarias de la plantilla, no por llamadas reales.
+
## Controlar el uso de tokens
Cada turno de agente reenvía las instrucciones de sistema, esquemas de herramientas y conversación acumulada. La entrada crece turno a turno hasta que la compresión acorta el historial, y la caché del proveedor determina cuánto se factura a la tarifa menor de caché. Esta sección responde a la [incidencia #24](https://github.com/cskwork/scopeweaver/issues/24) para perfiles de nube. Ollama nativo tiene protecciones propias descritas [abajo](#protecciones-durante-la-ejecución).
diff --git a/docs/ja/llm-providers.md b/docs/ja/llm-providers.md
index 5b6ad0fa..995b6c2f 100644
--- a/docs/ja/llm-providers.md
+++ b/docs/ja/llm-providers.md
@@ -119,6 +119,25 @@ SCOPEWEAVER_LLM_MODEL=glm-5.3-flash
`SCOPEWEAVER_LLM_PROVIDER=opencode-go` は OpenAI Chat Completions の通信形式に対応し、ベース URL とモデルが未設定なら上記表の既定値を使います。
+
+## Cheaper Inference(OpenAI 互換ゲートウェイ)
+
+**LLM → 新規 → 設定テンプレート**で **Cheaper Inference · gpt-5.4-mini** を選択します。
+
+| フィールド | 値 |
+| --- | --- |
+| 形式 | OpenAI Chat Completions |
+| ベース URL | `https://api.cheaperinference.com/v1` |
+| モデル | `gpt-5.4-mini` |
+| 思考機能 | 省略(モデルの既定値)|
+| 推論強度 | 省略(モデルの既定値)|
+| コンテキストウィンドウ(K)| `0`(既定 200K)|
+| 出力上限 | `16384`、`max_completion_tokens` として送信 |
+
+Cheaper Inference は OpenAI 互換の LLM ゲートウェイで、1 つの API キーで複数のラボのモデルを使えます。モデル ID と上限(コンテキスト 400K、出力 128K)は 2026-11-05 に公開モデル一覧 `https://api.cheaperinference.com/public/models` で確認しました。GPT-5.4 モデルは出力上限を `max_completion_tokens` で受け取ります。テンプレートは推論強度を省略し、モデルの既定値を使います。**モデルを読み込む**はゲートウェイの `/v1/models` 一覧を取得し、キーが必要です。モデル欄は `deepseek-v4-flash` や `claude-sonnet-5` など他の ID に編集できます。
+
+**認証情報:** https://cheaperinference.com でキーを作成してください(ドキュメント: https://cheaperinference.com/docs)。このテンプレートを選ぶか、**ベース URL** をゲートウェイへ、またはゲートウェイから変更すると、フォームに入力済みのキーは消去されます。これにより、別のエンドポイント用のキーがゲートウェイへ、ゲートウェイのキーが他の宛先へ送られることはありません。テンプレートを選んだ後、Cheaper Inference のキーを **API キー**に明示的に貼り付けてください。入力するまで、**モデルを読み込む**、**接続テスト**、保存はキー未入力のメッセージで停止します。テンプレートを選び直す場合や、ゲートウェイ上でパスだけを変更する場合は、入力済みのキーを保持します。テンプレートは何も保存・有効化しません。テンプレートは既存の OpenAI Chat Completions の経路を使い、確認はテンプレートの単体テストのみで、実際の呼び出しでは確認していません。
+
## トークン使用量の管理
diff --git a/docs/ko/llm-providers.md b/docs/ko/llm-providers.md
index 9f79cb07..02493b61 100644
--- a/docs/ko/llm-providers.md
+++ b/docs/ko/llm-providers.md
@@ -116,6 +116,24 @@ SCOPEWEAVER_LLM_MODEL=glm-5.3-flash
`SCOPEWEAVER_LLM_PROVIDER=opencode-go`는 OpenAI Chat Completions 와이어 형식으로 해석되며, 기본 URL과 모델이 비어 있으면 위 표의 기본값을 사용합니다.
+## Cheaper Inference(OpenAI 호환 게이트웨이)
+
+**LLM → 새로 만들기 → 설정 템플릿**에서 **Cheaper Inference · gpt-5.4-mini**를 고르세요.
+
+| 필드 | 값 |
+| --- | --- |
+| 형식 | OpenAI Chat Completions |
+| 기본 URL | `https://api.cheaperinference.com/v1` |
+| 모델 | `gpt-5.4-mini` |
+| 추론 | 생략(모델 기본값) |
+| 강도 | 생략(모델 기본값) |
+| 문맥 창(K) | `0`(기본 200K) |
+| 출력 한도 | `16384`, `max_completion_tokens`로 전송 |
+
+Cheaper Inference는 OpenAI 호환 LLM 게이트웨이이며, API 키 하나로 여러 연구소의 모델을 사용할 수 있습니다. 모델 ID와 한도(문맥 400K, 출력 128K)는 2026-11-05에 공개 모델 목록 `https://api.cheaperinference.com/public/models`에서 확인했습니다. GPT-5.4 모델은 출력 한도를 `max_completion_tokens`로 받으며, 템플릿은 강도를 생략해 모델 기본값을 따릅니다. **모델 불러오기**는 게이트웨이의 `/v1/models` 목록을 읽으며 키가 필요합니다. 모델 필드는 `deepseek-v4-flash`, `claude-sonnet-5` 같은 다른 ID로 수정할 수 있습니다.
+
+**자격 증명:** https://cheaperinference.com 에서 키를 만드세요(문서: https://cheaperinference.com/docs). 이 템플릿을 고르거나 **기본 URL**을 게이트웨이로 또는 게이트웨이에서 바꾸면 폼에 있던 키를 지워, 다른 엔드포인트용 키가 게이트웨이로 가거나 게이트웨이 키가 다른 곳으로 가지 않게 합니다. 템플릿을 고른 뒤 Cheaper Inference 키를 **API 키**에 직접 붙여넣으세요. 키를 입력하기 전에는 **모델 불러오기**, **연결 테스트**, 저장이 키 누락 메시지와 함께 멈춥니다. 템플릿을 다시 고르거나 게이트웨이에서 경로만 바꾸면 입력한 키가 유지됩니다. 템플릿은 아무것도 저장하거나 활성화하지 않습니다. 템플릿은 기존 OpenAI Chat Completions 경로를 사용하며, 실제 호출이 아니라 템플릿 단위 테스트로만 확인했습니다.
+
## 토큰 사용량 줄이기
에이전트는 턴마다 시스템 프롬프트, 도구 스키마, 지금까지의 대화를 다시 보냅니다. 그래서 입력은 압축으로 기록이 줄어들 때까지 턴마다 늘어나고, 반복되는 입력 중 얼마가 더 싼 캐시 요금으로 과금되는지는 제공자의 프롬프트 캐시가 정합니다. 이 절은 클라우드 프로필 기준으로 [이슈 #24](https://github.com/cskwork/scopeweaver/issues/24)에 답합니다. 기본 Ollama의 보호 장치는 [아래](#실행-중-보호-장치)에 따로 설명합니다.
diff --git a/docs/llm-providers.md b/docs/llm-providers.md
index 3510ff58..07842539 100644
--- a/docs/llm-providers.md
+++ b/docs/llm-providers.md
@@ -116,6 +116,24 @@ SCOPEWEAVER_LLM_MODEL=glm-5.3-flash
`SCOPEWEAVER_LLM_PROVIDER=opencode-go` resolves to the OpenAI Chat Completions wire format; an unset base URL and model default to the values in the table above.
+## Cheaper Inference (OpenAI-compatible gateway)
+
+Open **LLM → New → Configuration template** and choose **Cheaper Inference · gpt-5.4-mini**.
+
+| Field | Value |
+| --- | --- |
+| Format | OpenAI Chat Completions |
+| Base URL | `https://api.cheaperinference.com/v1` |
+| Model | `gpt-5.4-mini` |
+| Thinking | omitted (model default) |
+| Reasoning effort | omitted (model default) |
+| Context window (K) | `0` (200K default) |
+| Output limit | `16384`, sent as `max_completion_tokens` |
+
+Cheaper Inference is an OpenAI-compatible LLM gateway; one API key gives access to models from several labs. The model id and its limits (400K context, 128K output) were checked in the public model list at `https://api.cheaperinference.com/public/models` on 2026-11-05. GPT-5.4 models take the output limit as `max_completion_tokens`; the template omits effort so the model default applies. **Load models** reads the gateway's `/v1/models` list, which requires the key; the model field stays editable for other ids such as `deepseek-v4-flash` or `claude-sonnet-5`.
+
+**Credential:** create a key at https://cheaperinference.com (documentation: https://cheaperinference.com/docs). Choosing this template, or changing **Base URL** to or from the gateway, clears any key already in the form so a key for another endpoint is never sent to the gateway, and a gateway key is never sent elsewhere. After choosing the template, paste your Cheaper Inference key into **API key**; **Load models**, **Test connection** and saving stop with a missing-key message until you enter it. Re-selecting the template or changing only the path on the gateway keeps an entered key. The template does not save or activate anything. The template uses the existing OpenAI Chat Completions path; it is covered by template unit tests, not by live calls.
+
## Controlling token use
Every agent turn resends the system prompt, the tool schemas and the conversation so far. Input therefore grows turn by turn until compaction shortens the history, and provider prompt caching decides how much of the repeated input is billed at the cheaper cached rate. This section answers [issue #24](https://github.com/cskwork/scopeweaver/issues/24) for cloud profiles. Native Ollama has its own safeguards, described [below](#runtime-safeguards).
diff --git a/docs/zh-Hans/llm-providers.md b/docs/zh-Hans/llm-providers.md
index abb8d329..52703c17 100644
--- a/docs/zh-Hans/llm-providers.md
+++ b/docs/zh-Hans/llm-providers.md
@@ -126,6 +126,26 @@ SCOPEWEAVER_LLM_MODEL=glm-5.3-flash
`SCOPEWEAVER_LLM_PROVIDER=opencode-go` 解析为 OpenAI Chat Completions 传输格式;未设基础 URL 与模型时采上表默认值。
+
+
+## Cheaper Inference(OpenAI 兼容网关)
+
+开启「LLM → 新增 → 配置模板」,选择「Cheaper Inference · gpt-5.4-mini」。
+
+| 字段 | 值 |
+| --- | --- |
+| 格式 | OpenAI Chat Completions |
+| 基础 URL | `https://api.cheaperinference.com/v1` |
+| 模型 | `gpt-5.4-mini` |
+| 思考 | 省略(模型默认) |
+| 推理强度 | 省略(模型默认) |
+| 上下文视窗(K) | `0`(默认 200K) |
+| 输出上限 | `16384`,以 `max_completion_tokens` 传送 |
+
+Cheaper Inference 是兼容 OpenAI 的 LLM 网关;一个 API 密钥即可使用多家实验室的模型。模型 ID 及其上限(上下文 400K、输出 128K)于 2026-11-05 在公开模型清单 `https://api.cheaperinference.com/public/models` 中检查。GPT-5.4 模型以 `max_completion_tokens` 接收输出上限;模板省略推理强度,沿用模型默认值。「加载模型」读取网关的 `/v1/models` 清单,需要密钥;模型栏仍可输入 `deepseek-v4-flash`、`claude-sonnet-5` 等其他 ID。
+
+**凭证:** 在 https://cheaperinference.com 创建密钥(文档:https://cheaperinference.com/docs)。选择此模板,或将「基础 URL」改为网关或从网关改为其他地址时,会清除表单中已有的密钥,确保其他端点的密钥不会发送到网关,网关密钥也不会发送到其他地址。选择模板后,请将 Cheaper Inference 密钥明确贴入「API 密钥」;输入前,「加载模型」「测试连接」和保存都会以缺少密钥的提示停止。重新选择此模板或只修改网关上的路径时,会保留已输入的密钥。模板不保存也不启用任何配置。模板使用现有的 OpenAI Chat Completions 路径,仅由模板单元测试覆盖,未经实际调用验证。
+
## 控制 token 用量
diff --git a/docs/zh-Hant/llm-providers.md b/docs/zh-Hant/llm-providers.md
index 8dd7033d..8f56d018 100644
--- a/docs/zh-Hant/llm-providers.md
+++ b/docs/zh-Hant/llm-providers.md
@@ -126,6 +126,26 @@ SCOPEWEAVER_LLM_MODEL=glm-5.3-flash
`SCOPEWEAVER_LLM_PROVIDER=opencode-go` 解析為 OpenAI Chat Completions 傳輸格式;未設基底 URL 與模型時採上表預設值。
+
+
+## Cheaper Inference(OpenAI 相容閘道)
+
+開啟「LLM → 新增 → 設定範本」,選擇「Cheaper Inference · gpt-5.4-mini」。
+
+| 欄位 | 值 |
+| --- | --- |
+| 格式 | OpenAI Chat Completions |
+| 基底 URL | `https://api.cheaperinference.com/v1` |
+| 模型 | `gpt-5.4-mini` |
+| 思考 | 省略(模型預設) |
+| 推理強度 | 省略(模型預設) |
+| 上下文視窗(K) | `0`(預設 200K) |
+| 輸出上限 | `16384`,以 `max_completion_tokens` 傳送 |
+
+Cheaper Inference 是相容 OpenAI 的 LLM 閘道;一組 API 金鑰即可使用多家實驗室的模型。模型 ID 及其上限(上下文 400K、輸出 128K)於 2026-11-05 在公開模型清單 `https://api.cheaperinference.com/public/models` 中檢查。GPT-5.4 模型以 `max_completion_tokens` 接收輸出上限;範本省略推理強度,沿用模型預設值。「載入模型」讀取閘道的 `/v1/models` 清單,需要金鑰;模型欄仍可輸入 `deepseek-v4-flash`、`claude-sonnet-5` 等其他 ID。
+
+**憑證:** 在 https://cheaperinference.com 建立金鑰(文件:https://cheaperinference.com/docs)。選擇此範本,或將「基底 URL」改為閘道或從閘道改為其他位址時,會清除表單中已有的金鑰,確保其他端點的金鑰不會傳送到閘道,閘道金鑰也不會傳送到其他位址。選擇範本後,請將 Cheaper Inference 金鑰明確貼入「API 金鑰」;輸入前,「載入模型」「測試連線」和儲存都會以缺少金鑰的提示停止。重新選擇此範本或只修改閘道上的路徑時,會保留已輸入的金鑰。範本不儲存也不啟用任何設定。範本使用現有的 OpenAI Chat Completions 路徑,僅由範本單元測試涵蓋,未經實際呼叫驗證。
+
## 控制 token 用量
diff --git a/llmnet/credential_origin.go b/llmnet/credential_origin.go
new file mode 100644
index 00000000..d92591df
--- /dev/null
+++ b/llmnet/credential_origin.go
@@ -0,0 +1,47 @@
+package llmnet
+
+import (
+ "net/url"
+ "strconv"
+ "strings"
+
+ "golang.org/x/net/idna"
+)
+
+const cheaperInferenceHost = "api.cheaperinference.com"
+
+// CrossesCheaperInferenceOrigin reports whether a destination change must discard a
+// Cheaper Inference key or the key from the previous endpoint. Paths do not change origin.
+func CrossesCheaperInferenceOrigin(previousURL, nextURL string) bool {
+ previous, next := parseEndpointOrigin(previousURL), parseEndpointOrigin(nextURL)
+ return (previous.host == cheaperInferenceHost || next.host == cheaperInferenceHost) && previous != next
+}
+
+type endpointOrigin struct {
+ scheme string
+ host string
+ port uint16
+}
+
+func parseEndpointOrigin(raw string) endpointOrigin {
+ u, err := url.Parse(strings.TrimSpace(raw))
+ if err != nil || (u.Scheme != "http" && u.Scheme != "https") {
+ return endpointOrigin{}
+ }
+ host, err := idna.Lookup.ToASCII(u.Hostname())
+ host = strings.TrimRight(strings.ToLower(host), ".")
+ if err != nil || host == "" {
+ return endpointOrigin{}
+ }
+ port := uint64(443)
+ if u.Scheme == "http" {
+ port = 80
+ }
+ if value := u.Port(); value != "" {
+ port, err = strconv.ParseUint(value, 10, 16)
+ if err != nil {
+ return endpointOrigin{}
+ }
+ }
+ return endpointOrigin{scheme: u.Scheme, host: host, port: uint16(port)}
+}
diff --git a/llmnet/credential_origin_test.go b/llmnet/credential_origin_test.go
new file mode 100644
index 00000000..8b2ccce4
--- /dev/null
+++ b/llmnet/credential_origin_test.go
@@ -0,0 +1,35 @@
+package llmnet
+
+import "testing"
+
+func TestCrossesCheaperInferenceOrigin(t *testing.T) {
+ const gateway = "https://api.cheaperinference.com/v1"
+ tests := []struct {
+ name string
+ previous string
+ next string
+ wantCrossings bool
+ }{
+ {"paths", gateway, "https://api.cheaperinference.com/custom", false},
+ {"HTTPS default port and host casing", gateway, " HTTPS://API.CHEAPERINFERENCE.COM..:00443/custom ", false},
+ {"HTTP default port", "http://api.cheaperinference.com/v1", "http://api.cheaperinference.com:80", false},
+ {"internationalized hostname", gateway, "https://api。cheaperinference。com/v1", false},
+ {"scheme", gateway, "http://api.cheaperinference.com/v1", true},
+ {"port", gateway, "https://api.cheaperinference.com:8443/v1", true},
+ {"other provider", gateway, "https://other.example/v1", true},
+ {"implicit provider default", gateway, "", true},
+ {"non HTTP destination", gateway, "ftp://api.cheaperinference.com/v1", true},
+ {"lookalike suffix", "https://api.cheaperinference.com.example/v1", "https://other.example/v1", false},
+ {"unrelated providers", "https://one.example/v1", "http://two.example/v2", false},
+ }
+ for _, tc := range tests {
+ t.Run(tc.name, func(t *testing.T) {
+ if got := CrossesCheaperInferenceOrigin(tc.previous, tc.next); got != tc.wantCrossings {
+ t.Errorf("forward crossing = %t, want %t", got, tc.wantCrossings)
+ }
+ if got := CrossesCheaperInferenceOrigin(tc.next, tc.previous); got != tc.wantCrossings {
+ t.Errorf("reverse crossing = %t, want %t", got, tc.wantCrossings)
+ }
+ })
+ }
+}
diff --git a/scripts/report_integrity_check.py b/scripts/report_integrity_check.py
new file mode 100755
index 00000000..9f1c7d37
--- /dev/null
+++ b/scripts/report_integrity_check.py
@@ -0,0 +1,322 @@
+#!/usr/bin/env python3
+"""Check Markdown finding IDs, bold totals, and an optional JSON CVSS appendix.
+
+Use a separate Markdown heading for each finding (for example, ## KDT-01).
+Totals can use English or Indonesian labels such as "Total findings",
+"Confirmed findings", "Total temuan", or "Jumlah temuan", or bold counts
+such as **2 findings** or **2 temuan**. A report without IDs needs a zero total.
+Only IDs passed to --merged are excluded. Matching heading titles produce
+a warning so a reviewer can check for duplicate coverage.
+"""
+
+import argparse
+from collections import defaultdict
+from decimal import Decimal, InvalidOperation
+import json
+import math
+from pathlib import Path
+import re
+
+
+FLAGS = re.IGNORECASE
+TOTAL_LABEL = r"(?:(?:total|confirmed)\s+findings?|(?:total|jumlah)\s+temuan)"
+FINDING_NOUN = r"(?:(?:(?:total|unique|confirmed)\s+)?findings?|temuan(?:\s+unik)?)"
+TOTAL_PATTERNS = (
+ re.compile(rf"\*\*\s*{TOTAL_LABEL}\s*[:=]\s*([^*]+?)\s*\*\*", FLAGS),
+ re.compile(rf"\*\*\s*{TOTAL_LABEL}\s*:?\s*\*\*\s*(?:[:=|]\s*)?"
+ r"(?:\*\*\s*([^*]+?)\s*\*\*|([^\s|*]+))", FLAGS),
+ re.compile(rf"(?" if comment else "",
+ " **0 findings**", "\t**0 findings**"):
+ with self.subTest(markdown=markdown):
+ self.check(markdown, error="no active finding IDs or explicit zero finding total")
+ self.check("# Report\n\n**0 findings**", appendix=[])
+ self.check("**0 temuan**\n" + FINDING, error="finding total 0")
+
+ def test_headings_for_each_active_id(self):
+ self.check(FINDING + "\nSee also KDT-02.", error="KDT-02 needs exactly one heading, found 0")
+ self.check(FINDING + FINDING, error="KDT-01 needs exactly one heading, found 2")
+ self.check("## KDT-01 and KDT-02", error="distinct headings required")
+ self.check("KDT-01 — Access policy\n=======================\n")
+ self.check("See KDT-01.\n\n KDT-01 — Example\n---", error="found 0")
+ self.check("See KDT-01.\n\n```markdown\n" + FINDING + "```", error="found 0")
+
+ def test_examples_and_comments_do_not_count_as_findings(self):
+ self.check(
+ "**1 finding**\n"
+ "\n"
+ "````markdown