Skip to content

feat(opencode): 支持旧版协议向后兼容 - #29

Merged
yororoA merged 4 commits into
mainfrom
feat/opencode-legacy-protocol-compatibility
Sep 29, 2026
Merged

yororoA merged 4 commits into
mainfrom
feat/opencode-legacy-protocol-compatibility

Conversation

@yororoA

@yororoA yororoA commented Sep 29, 2026 •

Copy link
Copy Markdown
Owner

概述

  • 新增 OpenCode current / legacy 协议 profile,按实际端点、envelope 与 schema 能力选择适配器,不再只按主版本判断。
  • 支持 v2 2.0.0 legacy 路由与 v1 1.16.0 / 1.17.0 legacy schema;未收录但兼容的版本仍需通过隔离往返验证。
  • 在 migration plan / manifest 中绑定 protocolRule 与 protocolHash,避免同方言不同 profile 被混用,同时兼容已有 manifest。
  • 补充旧版 POSIX launcher 解析、v2 managed-server 启动回退、删除契约与真实 schema fixture。
  • 同步 README、兼容性文档、操作手册、故障说明与宣传网站文案。

安全边界

  • opencode-ai@1.15.x 缺少 Session metadata,无法保留迁移所有权证据,继续拒绝。
  • opencode-ai@1.14.x 未暴露完整会话 schema,继续拒绝。
  • legacy profile 仍执行 import/export 回读、重复冲突、父子关系、删除保护与回滚验证,不绕过协议检查或直写数据库。

验证

  • 480 项测试、lint、TypeScript、版本一致性、build 与 smoke
  • tarball 安装和 package 内容验证
  • v2 2.0.0 / 2.0.2、v1 1.16.0 / 1.17.0 真实二进制迁移、verify、resume 与 rollback
  • Quality CI:macOS / Linux / Windows × Node.js 18.20.8 / 22

CI: https://github.com/yororoA/Trae2OpenCode/actions/runs/36517960124

Summary by Sourcery

Support safely migrating sessions to legacy OpenCode protocol profiles by selecting adapters from verified routes and schemas rather than relying solely on major versions.

New Features:

  • Add current and legacy OpenCode protocol profiles with capability-based selection for v2 HTTP and v1 CLI session transfers.
  • Support validated legacy OpenCode releases including v2 2.0.0 and v1 1.16.0/1.17.0 while retaining rejection boundaries for unsafe older schemas.

Bug Fixes:

  • Prevent migration plans, manifests, resume operations, and rollbacks from being reused across different protocol profiles.
  • Restore managed-server startup for legacy v2 installations without service descriptors and resolve older POSIX launchers to their embedded native binaries.

Enhancements:

  • Bind protocol rules and hashes to migration target identity while preserving compatibility with existing manifests.
  • Apply profile-specific schemas, routes, deletion contracts, adapters, and isolated round-trip validation across migration, verification, conflict detection, and rollback.

CI:

  • Extend cross-platform quality CI with real legacy v2 and v1 binaries, startup fallback checks, round-trip verification, and uploaded compatibility reports.

Documentation:

  • Update README, compatibility guidance, operation manuals, troubleshooting, implementation plans, and website messaging with legacy support and safety boundaries.

Tests:

  • Add fixtures and contract tests for legacy schemas, routes, deletion behavior, profile selection, manifest validation, launcher resolution, and end-to-end migration recovery.

Chores:

  • Include legacy schema and contract fixtures in published package contents and add a dedicated legacy startup verification command.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @yororoA, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 1 day and 2 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 29, 2026

Copy link
Copy Markdown

Reviewer's Guide

本 PR 引入基于实际协议证据的 OpenCode current/legacy profile 体系,新增 v2 2.0.0 与 v1 1.16/1.17 的安全向后兼容;profile 身份贯穿能力探测、适配、迁移 manifest、删除与回滚校验,并配套旧版启动回退、真实 fixture、CI 回归和文档更新。

Sequence diagram for protocol profile detection and migration

sequenceDiagram
    participant CLI
    participant Probe as CapabilityProbe
    participant Server as OpenCodeServer
    participant Adapter as ProfileAdapter
    participant Migration
    participant Manifest

    CLI->>Probe: probeOpenCodeCapabilities()
    Probe->>Server: GET version and OpenAPI evidence
    Probe->>Probe: Match route, envelope, schema and protocolRule
    Probe-->>CLI: capabilities(protocolRule, protocolHash, schemaHash)
    CLI->>Migration: buildMigrationPlan(protocolRule)
    Migration->>Adapter: importSession()
    Adapter->>Server: Profile-specific import route or CLI import
    Server-->>Adapter: imported session
    Adapter->>Server: Profile-specific export/readback
    Server-->>Adapter: exported session
    Adapter->>Adapter: Reconcile and validate deletion contract
    Migration->>Manifest: Persist protocolRule and protocolHash
    Manifest-->>Migration: Resume and rollback require matching profile
Loading

Sequence diagram for legacy v2 managed-server startup fallback

sequenceDiagram
    participant Migrator
    participant Binary as OpenCode2_0_0
    participant Descriptor as ServiceDescriptor
    participant Health as LegacyHealthEndpoint

    Migrator->>Descriptor: Discover managed service
    Descriptor-->>Migrator: Descriptor unavailable
    Migrator->>Binary: serve --hostname 127.0.0.1 --port
    Binary-->>Migrator: Loopback URL and process output
    Migrator->>Health: GET /api/health with authorization
    Health-->>Migrator: healthy=true, version=2.0.0
    Migrator-->>Migrator: Use managed server and clean up process/state
Loading

Flow diagram for safe legacy-version admission

flowchart TD
    Start[Inspect OpenCode binary and server]
    Candidates[Select same-major profile candidates]
    Evidence[Match actual routes, envelope and schema]
    Boundary{安全契约满足?}
    Isolated[Run isolated import/export roundtrip]
    Checks[Verify readback, conflicts, parent-child relations, deletion and rollback]
    Admit[Admit migration with protocolRule and protocolHash]
    Reject[Reject without writing target]

    Start --> Candidates --> Evidence --> Boundary
    Boundary -- 否 --> Reject
    Boundary -- 是 --> Isolated --> Checks
    Checks -- 通过 --> Admit
    Checks -- 失败 --> Reject
Loading

File-Level Changes

Change Details Files
将 OpenCode 协议适配从按主版本选择改为按实际端点、envelope 和 schema 能力选择 current/legacy profile。
  • 新增 v2 legacy HTTP 路由及独立 transfer schema,覆盖 2.0.0,并保留未收录版本的隔离往返准入。
  • 新增 v1 legacy session schema,覆盖 1.16.0/1.17.0;对缺少 metadata 或完整 schema 的旧版本继续拒绝。
  • 扩展能力探测以依次尝试同主版本候选 profile,并记录选中的 profile、schemaHash 和 protocolHash。
  • 让 native v1/v2 adapter、mapping、删除契约和回读校验按选定 profile 执行。
src/target/opencode/protocol-rules.ts
src/target/opencode/capability-probe.ts
src/target/opencode/contract.ts
src/target/opencode/native-adapter.ts
src/target/opencode/v1/contract.ts
src/target/opencode/v1/adapter.ts
src/target/opencode/dialect.ts
src/target/opencode/deletion.ts
fixtures/opencode/1.16.0/evidence/session.schema.json
fixtures/opencode/2.0.0/evidence/transfer.schema.json
fixtures/opencode/2.0.0/evidence/deletion.contract.json
将协议 profile 身份纳入迁移计划、manifest 和执行时目标校验,防止同方言不同 profile 混用并兼容旧 manifest。
  • 在 plan、target descriptor 和 manifest 中保存 protocolRule/protocolHash。
  • 迁移、恢复和回滚前校验 profile 与 protocolHash;跨 profile 目标变化被拒绝。
  • 旧 manifest 在核心目标证据未变化时继续有效,但不会丢弃新的 profile 绑定。
src/migration/plan.ts
src/migration/target.ts
src/migration/manifest.ts
src/migration/executor.ts
src/migration/rollback.ts
src/cli/commands.ts
src/target/opencode/compatibility.ts
增强旧版 OpenCode 的启动、二进制解析和端到端验证能力。
  • POSIX launcher 解析到 npm 包内嵌的 .opencode 原生二进制,Windows shim 行为保持兼容。
  • v2 managed-server 在 service descriptor 启动失败时回退到旧版 serve 启动方式,并验证 loopback health。
  • CI 增加 v2 2.0.0、v1 1.16.0 的真实 roundtrip、startup、resume、rollback 和 package fixture 验证。
src/target/opencode/binary.ts
src/cli/interactive-migrate.ts
scripts/verify-legacy-managed-server.ts
scripts/verify-version-contract.ts
scripts/verify-opencode-v1.ts
scripts/verify-package.ts
.github/workflows/quality.yml
src/target/__tests__/opencode-binary.test.ts
补充 profile、契约边界和安全拒绝路径的单元测试及真实 schema/deletion fixture。
  • 覆盖 legacy profile 探测、schema hash、未收录版本隔离准入和 1.15.x 拒绝。
  • 覆盖删除保护契约、跨 profile manifest/plan/target 复用拒绝及旧 manifest 兼容。
  • 将新 fixture 纳入 npm package 内容白名单。
src/target/__tests__/opencode-capability.test.ts
src/target/__tests__/opencode-v1-capability.test.ts
src/target/__tests__/opencode-contract.test.ts
src/target/__tests__/opencode-deletion.test.ts
src/migration/__tests__/executor.test.ts
src/migration/__tests__/manifest.test.ts
src/migration/__tests__/plan.test.ts
src/migration/__tests__/target.test.ts
package.json
同步用户文档、兼容性说明、运维故障处理和宣传网站中的旧协议支持范围。
  • 公布 current/legacy 基线、自动探测规则和隔离往返准入条件。
  • 明确 1.15.x、1.14.x 及更早版本的拒绝边界,不提供数据库直写绕过。
  • 更新迁移计划与 CI 验收记录。
README.md
docs/implementation-plan.md
docs/m4-1-opencode-capability.md
docs/m7-2-version-contract.md
docs/opencode-compatibility.md
docs/operation-manual.md
docs/troubleshooting.md
website/app.js
website/index.html

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@yororoA
yororoA merged commit 4da31d0 into main Sep 29, 2026
14 checks passed
yororoA added a commit that referenced this pull request Sep 29, 2026
此 PR 由 release-please 自动维护。合并后将创建对应 tag 与 GitHub Release。
---


##
[1.3.0](v1.2.0...v1.3.0)
(2026-09-29)


### Added

* **opencode:** 支持旧版协议profile迁移
([be5d537](be5d537))
* **opencode:** 支持旧版协议向后兼容
([#29](#29))
([4da31d0](4da31d0))


### Fixed

* **opencode:** 使用目标平台规则解析POSIX启动器
([357582a](357582a))


### Documentation

* **opencode:** 说明旧协议支持与拒绝边界
([ff8c8ca](ff8c8ca))

---
版本号、Changelog 和网站版本由 release-please 统一更新,请勿手工修改。

## Summary by Sourcery

Release version 1.3.0 with legacy protocol compatibility, migration
support, and improved launcher handling.

New Features:
- Add migration and backward compatibility support for legacy OpenCode
protocol profiles.

Bug Fixes:
- Correct POSIX launcher parsing to follow target-platform rules.

Build:
- Update the package release metadata to version 1.3.0.

Documentation:
- Document legacy protocol support and its rejection boundaries.

Chores:
- Synchronize the changelog, package lockfile, release manifest, and
website version metadata for the 1.3.0 release.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant