Files
zeekay ae2f901ec0 merge: just-every/code upstream/main (preserve Hanzo brand)
# Conflicts:
#	.github/pull_request_template.md
#	.github/workflows/Dockerfile.bazel
#	.github/workflows/bazel.yml
#	.github/workflows/cargo-deny.yml
#	.github/workflows/ci.yml
#	.github/workflows/close-stale-contributor-prs.yml
#	.github/workflows/codespell.yml
#	.github/workflows/issue-deduplicator.yml
#	.github/workflows/issue-labeler.yml
#	.github/workflows/rust-ci-full.yml
#	.github/workflows/rust-ci.yml
#	.github/workflows/rust-release-prepare.yml
#	.github/workflows/rust-release-windows.yml
#	.github/workflows/rust-release-zsh.yml
#	.github/workflows/rust-release.yml
#	.github/workflows/sdk.yml
#	.vscode/extensions.json
#	.vscode/settings.json
#	AGENTS.md
#	AGENTS.md~upstream_main
#	NOTICE
#	code-rs/app-server-protocol/schema/json/DynamicToolCallParams.json
#	code-rs/app-server-protocol/schema/json/v2/ErrorNotification.json
#	code-rs/app-server-protocol/schema/json/v2/ItemCompletedNotification.json
#	code-rs/app-server-protocol/schema/json/v2/ItemStartedNotification.json
#	code-rs/app-server-protocol/schema/json/v2/ReviewStartResponse.json
#	code-rs/app-server-protocol/schema/json/v2/ThreadListResponse.json
#	code-rs/app-server-protocol/schema/json/v2/ThreadReadResponse.json
#	code-rs/app-server-protocol/schema/json/v2/ThreadRollbackResponse.json
#	code-rs/app-server-protocol/schema/json/v2/ThreadStartedNotification.json
#	code-rs/app-server-protocol/schema/json/v2/ThreadUnarchiveResponse.json
#	code-rs/app-server-protocol/schema/json/v2/TurnCompletedNotification.json
#	code-rs/app-server-protocol/schema/json/v2/TurnStartResponse.json
#	code-rs/app-server-protocol/schema/json/v2/TurnStartedNotification.json
#	code-rs/app-server-protocol/schema/typescript/CodexErrorInfo.ts
#	code-rs/app-server-protocol/schema/typescript/DynamicToolCallRequest.ts
#	code-rs/app-server-protocol/schema/typescript/TurnItem.ts
#	code-rs/app-server-protocol/schema/typescript/v2/CodexErrorInfo.ts
#	code-rs/app-server-protocol/schema/typescript/v2/DynamicToolCallParams.ts
#	code-rs/app-server-protocol/schema/typescript/v2/DynamicToolSpec.ts
#	code-rs/app-server-protocol/schema/typescript/v2/ThreadItem.ts
#	code-rs/app-server-protocol/schema/typescript/v2/ToolsV2.ts
#	code-rs/app-server-protocol/src/protocol/thread_history.rs
#	code-rs/code-version/Cargo.toml
#	code-rs/core/src/http_client.rs
#	code-rs/tui/src/bottom_pane/auto_drive_settings_view.rs
#	codex-cli/scripts/build_npm_package.py
#	docs/contributing.md
#	hanzo-dev/chatgpt/src/chatgpt_token.rs
#	hanzo-dev/tui/src/clipboard_copy.rs
#	scripts/codex_package/archive.py
#	scripts/codex_package/cargo.py
#	scripts/codex_package/cli.py
#	scripts/codex_package/layout.py
#	scripts/codex_package/test_cargo.py
#	scripts/codex_package/v8.py
#	scripts/stage_npm_packages.py
2026-06-01 18:52:56 -07:00
..

hanzo-protocol

Crates.io Documentation License: MIT

Core protocol types for Hanzo AI agents.

Overview

This crate defines the fundamental types used throughout the Hanzo AI ecosystem, including:

  • AskForApproval - Human-in-the-loop approval policies
  • SandboxPolicy - Filesystem and execution sandboxing
  • Protocol messages - Internal communication types
  • Configuration - Agent configuration schemas

Installation

[dependencies]
hanzo-protocol = "0.6"

Key Types

AskForApproval

Controls when the agent pauses to request human confirmation:

use hanzo_protocol::AskForApproval;

let policy = AskForApproval::OnRequest; // Model decides when to ask

match policy {
    AskForApproval::Never => { /* Full autonomy */ }
    AskForApproval::OnFailure => { /* Ask only on errors */ }
    AskForApproval::OnRequest => { /* Model decides */ }
    AskForApproval::UnlessTrusted => { /* Ask for risky operations */ }
}
Policy Description
Never Full autonomy - never ask
OnFailure Ask only when operations fail
OnRequest Model decides based on risk assessment
UnlessTrusted Ask unless operation is known-safe

SandboxPolicy

Controls what operations are physically allowed:

use hanzo_protocol::SandboxPolicy;

let policy = SandboxPolicy::WorkspaceWrite {
    writable_roots: vec![],
    network_access: true,
    exclude_tmpdir_env_var: false,
    exclude_slash_tmp: false,
    allow_git_writes: true,
};

match policy {
    SandboxPolicy::DangerFullAccess => { /* No restrictions */ }
    SandboxPolicy::ReadOnly => { /* Read-only filesystem */ }
    SandboxPolicy::WorkspaceWrite { .. } => { /* Write to workspace only */ }
}
Policy Filesystem Network Processes
DangerFullAccess Full Full Full
WorkspaceWrite Read all, write workspace Configurable Allowed
ReadOnly Read only Blocked Limited

Modules

Module Description
config_types Configuration schemas
protocol Core protocol definitions
models Data models
mcp_protocol MCP-specific types
responses Response structures
tool_config Tool configuration

Example: Agent Configuration

use hanzo_protocol::{AskForApproval, SandboxPolicy, AgentConfig};

let config = AgentConfig {
    approval_policy: AskForApproval::OnRequest,
    sandbox_policy: SandboxPolicy::WorkspaceWrite {
        writable_roots: vec!["/home/user/project".into()],
        network_access: true,
        exclude_tmpdir_env_var: false,
        exclude_slash_tmp: false,
        allow_git_writes: true,
    },
    timeout_ms: 30000,
    ..Default::default()
};

TypeScript Bindings

This crate uses ts-rs to generate TypeScript type definitions:

cargo test --features ts-rs
# Generates TypeScript bindings in ./bindings/

License

MIT License - Copyright 2025 Hanzo AI Inc.