feat(protocol): add Trace v3 with v2-compatible negotiation - #101
Draft
shnpd wants to merge 3 commits into
Draft
Conversation
Define Trace v3 wire types and generated schemas while keeping protocol 1.1 peers compatible with 1.0. Default record start still produces Trace v2, and only an explicit trace_version=3 request enables the new shape. Refs #90 Co-authored-by: Cursor <cursoragent@cursor.com>
Require Trace v3 version const 3, reject mixed pages/states payloads, and align TypeScript selection optionality with the generated schema. Trace v2 on main already records hover steps, so the frozen v2 schema must accept them instead of dropping them during reduction. Co-authored-by: Cursor <cursoragent@cursor.com>
shnpd
force-pushed
the
feat/trace-v3-protocol
branch
from
August 17, 2026 12:30
f94f579 to
ad64eeb
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a new Trace v3 protocol model (state → action → state) alongside an explicit Trace v2 compatibility model, and updates protocol/version negotiation so new/old CLI, daemon, and extension can interoperate during a phased rollout.
Changes:
- Add Trace v3 types (states, step result linking, recorder metadata, stop reason, navigation cause/fill commit/scroll) plus
RecordedTrace(v2|v3) classification and schemas. - Preserve Trace v2 as an isolated model (
record_v2.rs) with its own schema output, including legacyhoversupport. - Bump protocol version to 1.1 and update handshake/status/test expectations; update CLI to handle
RecordedTrace.
Reviewed changes
Copilot reviewed 30 out of 30 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/bsk-protocol/src/tools/record.rs | Defines Trace v3 model, negotiation params, and RecordedTrace (v2/v3) classification. |
| crates/bsk-protocol/src/tools/record_v2.rs | Adds isolated Trace v2 wire model (legacy pages[], page refs, v2 steps incl. hover). |
| crates/bsk-protocol/src/tools/mod.rs | Exposes the new record_v2 module. |
| crates/bsk-protocol/src/bin/dump-schema.rs | Extends schema dumper to emit standalone trace_v2 schema. |
| crates/bsk-protocol/schema/trace.json | Updates committed Trace schema to v3 (version=3, states, recorder, stopped_by). |
| crates/bsk-protocol/schema/trace_v2.json | Adds committed standalone Trace v2 schema. |
| crates/bsk-protocol/schema/trace_step.json | Updates step schema for v3 fields (state/result/cause/commit/scroll). |
| crates/bsk-protocol/schema/tool_record_stop_result.json | Updates stop result schema to return RecordedTrace (v2 or v3). |
| crates/bsk-protocol/schema/tool_record_start_params.json | Adds record start negotiation fields (trace_version, token/redaction knobs). |
| crates/bsk-protocol/schema/tool_record_await_result.json | Updates await result schema to return RecordedTrace (v2 or v3). |
| crates/bsk-cli/tests/ws_handshake.rs | Updates test handshake params/expectations for protocol 1.1. |
| crates/bsk-cli/tests/tools_m9_ipc.rs | Updates IPC handshake test params for protocol 1.1. |
| crates/bsk-cli/tests/tools_m8_ipc.rs | Updates IPC handshake test params for protocol 1.1. |
| crates/bsk-cli/tests/tools_m7_ipc.rs | Updates IPC handshake test params for protocol 1.1. |
| crates/bsk-cli/tests/tools_ipc.rs | Updates IPC handshake test params for protocol 1.1. |
| crates/bsk-cli/tests/status_cmd.rs | Updates bsk status JSON protocol_version expectation to 1.1. |
| crates/bsk-cli/tests/sessions_ipc.rs | Updates session IPC handshake test params for protocol 1.1. |
| crates/bsk-cli/tests/session_user_interrupt.rs | Updates handshake params for protocol 1.1 in interrupt test. |
| crates/bsk-cli/tests/per_session_queue.rs | Updates handshake params for protocol 1.1 in queue test. |
| crates/bsk-cli/tests/handshake_compat.rs | Updates/extends protocol compatibility matrix tests (skew/reject scenarios). |
| crates/bsk-cli/tests/cancel_forwarding.rs | Updates handshake params for protocol 1.1 in cancel forwarding test. |
| crates/bsk-cli/tests/browser_wait.rs | Updates handshake params for protocol 1.1 in browser wait test. |
| crates/bsk-cli/src/daemon/state.rs | Bumps daemon PROTOCOL_VERSION constant to 1.1. |
| crates/bsk-cli/src/daemon/start.rs | Uses unified PROTOCOL_VERSION in daemon status reporting. |
| crates/bsk-cli/src/cli/record.rs | Updates CLI to write/render RecordedTrace and compute step counts for v2/v3. |
| crates/bsk-cli/src/cli/doctor.rs | Updates doctor tests/fixtures for protocol 1.1 reporting. |
| apps/extension/src/transport/types.ts | Adds TS v3 protocol types + RecordedTrace union, keeps v2 types/aliases. |
| apps/extension/src/transport/handshake.ts | Bumps extension PROTOCOL_VERSION to 1.1 (floor remains 1.0). |
| apps/extension/src/transport/tests/handshake.test.ts | Updates handshake test expectations for protocol 1.1. |
| apps/extension/src/lib/tests/connection-controller.test.ts | Updates connection-state compat tests for protocol 1.1 scenarios. |
Suppressed comments (1)
crates/bsk-protocol/src/tools/record.rs:151
Stepdoes not use#[serde(deny_unknown_fields)], so v3 steps can silently accept legacy v2-only keys (e.g.page/effect) without failing deserialization. This weakens the “no mixed v2/v3 payloads” validation guarantee and can hide producer bugs.
/// One recorded user action — discriminated union by `op`.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "op", rename_all = "snake_case")]
pub enum Step {
Navigate {
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
shnpd
marked this pull request as draft
August 18, 2026 09:16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
在 #100 提供的录制安全 VOM 观察能力之上,引入 Trace v3 协议模型、版本协商和 v2/v3 兼容层。
本 PR 只定义并验证协议边界,不启用 Trace v3 录制流程。省略
trace_version时仍使用 Trace v2,后续 PR 将实现 v3 状态捕获、trace reduction 和目录 bundle 导出。Refs #90
Changes
Trace v3 protocol
新增状态—动作—状态形式的 Trace v3:
version: 3states[]页面观察字典state和result.state关联动作前后状态recorder记录 bsk 与 VOM 格式版本stopped_by区分用户完成和 CLI 停止NavigationCause、FillCommit和scrollstepref、role、name、ctx和unmatchedRust 和 TypeScript 定义保持一致,包括:
TraceV3StepV3TargetDescriptorV3TraceStateRecorderInfoStopReasonNavigationCauseFillCommitTrace v2 compatibility
将现有 Trace v2 格式保留为独立协议模型:
record_v2.rsversion的pages[]格式TraceV2、StepV2和相关 TypeScript aliaseshover是现有 v2 协议的一部分,本 PR 明确保留其 Rust、TypeScript 和 JSON Schema 支持。Version negotiation
协议版本从
1.0提升到1.1,兼容下限保持为1.0:PROTOCOL_VERSION这允许新旧 CLI、daemon 和 extension 在 Trace v3 分阶段发布期间继续协作。
Trace format negotiation
RecordStartParams新增:trace_versionmax_page_tokensredact_values行为约定:
trace_version:请求 Trace v2trace_version: 3:请求 Trace v3RecordStopResult和RecordAwaitResult通过RecordedTrace支持返回 v2 或 v3。Validation
强化协议载荷校验:
version必须严格等于3version: 3的载荷不能包含 legacypages[]states[]oneOfschema 保持一致Generated schemas
新增或更新:
trace_v2.jsontrace.jsontrace_step.jsontool_record_start_params.jsontool_record_stop_result.jsontool_record_await_result.jsondump-schema现在也会生成独立的 Trace v2 schema。CLI compatibility
CLI 可以反序列化并保存
RecordedTrace::V2或RecordedTrace::V3,同时分别计算 step 数量。本 PR 不切换到 Trace v3 bundle 输出;目录结构导出由后续 PR 实现。
Compatibility matrix
trace_version: 3: reserved for the upcoming v3 recorder implementationVerification
Review focus
Please focus review on:
RecordedTraceclassification boundaries