Skip to content

feat(worker/opencodeserver): turn summary parity — context_window 补全 #778

Description

@hrygo

背景

opencodeserver worker 是三个非-claude worker 中 turn summary 产出最完整的基准(9/11 字段),仅 context_window 受限于上游 API 缺失。

完整 gap 分析见 spec:docs/specs/Worker-Turn-Summary-Parity-Spec.md §5。

Gap 清单

字段 状态 根因
context_window ❌ 恒 0 Gap-O1commands.go:167 queryContextUsage 硬编码 "maxTokens": 0(OCS HTTP API 不暴露模型窗口大小,session_stats.go:134 注释 "OCS scenario" 即指此)
context_pct ❌ 恒 0 派生自 context_window,computeContextPctContextWindow<=0 时返回 0

:OCS 的 context_fillcommands.go:161-166lastInput+lastCacheRead+lastCacheWrite)、token、model(双路径)、tool、cost 全部正常产出。

修复方案

ID 改点 位置 优先级
O1 context_window 补全,优先级:① 查询 OCS model/provider 元数据 API → ② 维护 model→contextWindow 静态映射表(参考 internal/security/model.go 已有模型注册) → ③ 标注协议限制 opencodeserver/commands.go:queryContextUsage P2

待实现时确认

  • OCS 是否有 /model/provider 端点暴露 context window?需对照 ~/opencode 源码确认。若无则采用静态映射表方案。

验收

  1. 常见模型(Sonnet/Opus/Haiku/GPT 系列)对话后 turn summary 卡片显示 context 占比。
  2. opencodeserver/converter_test.go / commands_test.go 覆盖 context_window 产出。
  3. claudecode worker turn summary 回归不破。
  4. 若采用静态映射表,未知模型不得静默归零(显示 "unknown window" 或等价)。

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Critical: production outage, data loss, securityarea/workerScope: Claude Code/OCS/Pi adapters, base workerenhancementFeature: new capabilities or improvements

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions