Repository navigation
refactor(protocol): generate TypeScript contracts and enforce complete tool policies - #389
Draft
NianJiuZst wants to merge 6 commits into
Draft
NianJiuZst wants to merge 6 commits into
NianJiuZst wants to merge 6 commits into
Conversation
…licies Refs Tencent#388. Derive extension contracts and validators from the Rust catalog, enforce exhaustive handler and execution policies, and preserve evaluation settlement across caller deadlines.
This branch has not been deployed
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.
Closes #388 when the agreed implementation is merged.
Draft for design discussion. The architecture, compatibility policy, and rollout still need maintainer agreement.
Problem and resulting behavior
Protocol changes currently require updating Rust payloads, handwritten TypeScript mirrors, JSON Schema files, dispatcher registrations, and method classifications separately. These copies can drift: the old TypeScript error union omitted Rust's
user_aborted, and the checked-in handshake/session-stop schemas omitted fields already sent on the wire.This PR uses the Rust method catalog and payload types as the shared source, generates extension contracts, validates the transport boundary, and requires complete handler and local-policy coverage. Evaluation retains the existing bounded timeout/cancellation behavior; an unresolved evaluation does not retain the session queue indefinitely.
Implementation
Methodusing named fields. Effect-classification rationale remains next toeffect().scripts/protocol.mjsgenerates 44 extension methods, 220 contract definitions, and 114 standalone JSON Schemas. Schemars 1.2.2 exports receiving and sending contracts separately.protocol:generateupdates both generated directories;protocol:checkdetects missing, changed, or unexpected files in either directory without modifying source files.dump-schemaderives method roots from the catalog, skips unconstrained daemon-private payloads by schema/ownership rather than a hardcoded Schemars type name, and supports boolean schema roots. Checked-in schemas includeaudit_enabled, handshake audit responses, andwindow_released.protocol_errorwitheffect_state: "unknown"on mismatch; a malformed result does not prove that the action had no effect. Failed session-start result validation cleans up the allocated session.Generate and check
Standalone schemas are compared from a temporary export. The substantial JSON diff includes regeneration under Schemars 1.x, including ordering and description formatting changes.
Validation — 2026-10-20
Merged upstream main
e8777ab71bb851196895515b53eea2481462dd57into the original branch. Environment: macOS ARM64, Rust 1.94.1, Node 26.10.0, pnpm 10.17.0, Chrome for Testing 153.0.8010.12.protocol:checkA fresh private daemon, installed production extension and isolated Chrome exercised snapshot, element wait, extraction via a discovered target handle, and video list/start/stop/discard through the real CLI. During active video, a same-task
tool.record_startsent through daemon IPC was rejected; the resulting video remained ready with nonzero bytes. These calls passed the generated request/result boundary. No new probes, fixtures, screenshots or logs are committed; existing tests only received interface adaptations.Check boundary: all-target local Clippy hits
redundant_iter_clonedin the unchanged updater test atcrates/bsk-cli/src/cli/update.rs:1428. The same failure was reproduced on untouched maine8777ab; production-target Clippy and the full Rust tests pass. Browser-gated skips and untested released-peer combinations are not counted as passes. Hosted CI is tracked separately on the current PR head.Compatibility and remaining design decisions
1.4and minimum compatible protocol1.0match current main. Strict validation is a behavior change; these checks do not establish compatibility with every released peer or all real-browser result shapes.entries: []; Serde readers still accept omission. More precise debug enums and result structures constrain previously permissive shapes.