Skip to content

feat: add stable stream IDs and deploy-time OpenCode LSP toggle#87

Merged
liujuanjuan1984 merged 8 commits intomainfrom
dev/2026-02-15
Feb 15, 2026
Merged

feat: add stable stream IDs and deploy-time OpenCode LSP toggle#87
liujuanjuan1984 merged 8 commits intomainfrom
dev/2026-02-15

Conversation

@liujuanjuan1984
Copy link
Collaborator

@liujuanjuan1984 liujuanjuan1984 commented Feb 15, 2026

背景

本 PR 汇总了三类改动:

  1. 代码去重与测试脚手架收敛;
  2. 流式输出增加稳定 message_id/event_id 语义;
  3. 部署侧默认关闭 OpenCode LSP,并支持按实例参数开启。

关联 Issues

提交概览

按模块变更

1. 流式协议与事件元数据(src/opencode_a2a_serve/agent.py

  • 为流事件补齐稳定 message_id 回退策略(<task_id>:<context_id>:assistant)。
  • 为每个流事件生成单调 event_id(命名空间 + sequence)。
  • 移除未参与逻辑的 metadata.opencode.event_type
  • last_chunk 仅在 true 时输出,省略 false 以减少冗余字段。

2. App 层请求解析与日志判别去重(src/opencode_a2a_serve/app.py

  • 抽取 JSON body 解析 helper,复用 REST payload 形态判别和敏感方法识别。
  • 删除无效冗余赋值,保持行为不变。

3. OpenCode 文本提取逻辑复用(src/opencode_a2a_serve/text_parts.pysrc/opencode_a2a_serve/opencode_client.pysrc/opencode_a2a_serve/jsonrpc_ext.py

  • 新增共享文本提取 helper,统一 parts -> text 行为。
  • 消除客户端与扩展模块里的重复实现。

4. 部署参数与启动行为(scripts/deploy.shscripts/deploy/setup_instance.shscripts/deploy/run_opencode.sh

  • 新增 opencode_lsp CLI 参数并写入实例配置。
  • 默认 OPENCODE_LSP=false
  • 当未显式设置 OPENCODE_CONFIG_CONTENT 时,自动注入最小配置:
    • {"$schema":"https://opencode.ai/config.json","lsp":<true|false>}
  • 若外部已设置 OPENCODE_CONFIG_CONTENT,保持外部配置优先。

5. 文档同步(docs/deployment.md

  • 补充 opencode_lsp 参数、默认值与使用示例。
  • 更新配置表,说明 OPENCODE_LSP 行为与优先级。

6. 测试体系收敛(tests/helpers.py 及多测试文件)

  • 引入共享测试构造 helper,替换重复 _settings / RequestContext / Dummy*Client 样板。
  • 保持原有断言语义,新增覆盖稳定 message_id/event_id 的关键断言。

验证

  • bash -n scripts/deploy.sh scripts/deploy/run_opencode.sh scripts/deploy/setup_instance.sh
  • uv run pre-commit run --all-files
  • uv run pytest

结果:均通过(60 passed)。

风险与边界

  • 本 PR 对 #89 的覆盖主要在实时流事件标识与元数据收敛;extensions 历史路径与实时路径的全链路一致性仍建议在联调中继续验证。

@liujuanjuan1984
Copy link
Collaborator Author

补充提交已推送到当前 PR(28c5daa),本次继续清理重复实现:

  1. 抽取共享文本提取 helper
  • src/opencode_a2a_serve/text_parts.py
  • opencode_client.pyjsonrpc_ext.py 中复用,统一 parts -> text 行为。
  1. 抽取并复用测试构造器
  • tests/helpers.py 新增 make_request_context_mockconfigure_mock_client_runtime
  • 多个测试文件改为复用该构造器,减少重复样板。

回归结果保持通过:

  • uv run pre-commit run --all-files
  • uv run pytest(59 passed)

@liujuanjuan1984
Copy link
Collaborator Author

补充提交已推送(5edfe3e),本次继续压缩测试重复样板:

  1. 统一测试假客户端
  • tests/helpers.py 增加 DummyChatOpencodeClient / DummySessionQueryOpencodeClient
  • 多个测试文件复用,移除重复类定义。
  1. 统一设置构造
  • test_opencode_client_params.py 去掉本地 _settings wrapper,直接使用 make_settings

回归保持通过:

  • uv run pre-commit run --all-files
  • uv run pytest(59 passed)

@liujuanjuan1984
Copy link
Collaborator Author

补充提交已推送(5a8a2a9):

  1. 新增并复用 make_request_context
  • 统一真实 RequestContext 构造,消除 test_opencode_agent_session_binding.pytest_streaming_output_contract.py 的重复 _context 代码。
  1. session extension 测试设置去重
  • 移除本地 _settings 函数,改为 make_settings + _BASE_SETTINGS

回归保持通过:

  • uv run pre-commit run --all-files
  • uv run pytest(59 passed)

@liujuanjuan1984
Copy link
Collaborator Author

补充提交已推送(d0057a8):

  • test_session_ownership.py 去掉局部 _context 包装,直接复用共享 make_request_context_mock,继续压缩测试重复样板。

回归保持通过:

  • uv run pre-commit run --all-files
  • uv run pytest(59 passed)

@liujuanjuan1984 liujuanjuan1984 changed the title [chore] 清理冗余与重复实现(stream 提取、payload 判别、测试脚手架) chore: deduplicate stream parsing and test scaffolding Feb 15, 2026
@liujuanjuan1984 liujuanjuan1984 changed the title chore: deduplicate stream parsing and test scaffolding feat: add stable stream IDs and deploy-time OpenCode LSP toggle Feb 15, 2026
@liujuanjuan1984 liujuanjuan1984 marked this pull request as ready for review February 15, 2026 15:12
@liujuanjuan1984 liujuanjuan1984 merged commit ceaadc3 into main Feb 15, 2026
1 check passed
@liujuanjuan1984 liujuanjuan1984 deleted the dev/2026-02-15 branch February 15, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant