Skip to main content
This page documents the protocol contract layer of Palyra, specifically the JSON envelope schemas and the automated generation of cross-language stubs. These mechanisms ensure that the Core Daemon, Web Dashboard, Desktop Companion, and external connectors maintain strict type safety and wire-format compatibility across Rust, Kotlin, and Swift environments.

Schema Architecture and Envelopes

Palyra utilizes a dual-protocol approach: Protobuf for high-performance gRPC communication between internal services (Gateway, Browser, Node) and JSON Envelopes for public-facing APIs, webhooks, and state persistence. The JSON schemas define the structure for:
  • Message Envelopes: The standard wrapper for agent-to-user and user-to-agent communication.
  • A2UI Envelopes: Agent-to-UI patches used to dynamically update the React dashboard apps/web/src/components/A2UI#1-20.
  • Webhook Envelopes: Payloads for external platform integrations like Discord and Slack scripts/protocol/generate-stubs.ps1#1-50.
  • Config Export/Import: The schema for migrating and validating RootFileConfig and SQLite-backed state.

Data Flow: Schema to Runtime

The following diagram illustrates how schemas move from definition to cross-language enforcement. Protocol Contract Distribution Sources: scripts/protocol/generate-stubs.ps1#1-40, scripts/protocol/validate-proto.ps1#6-15, .github/workflows/ci.yml#173-180

Stub Generation and Validation

To prevent drift between the Rust implementation and client libraries, Palyra uses a centralized generation script located at scripts/protocol/generate-stubs.ps1 scripts/protocol/generate-stubs.ps1#1-10.

Key Scripts

ScriptPurpose
generate-stubs.ps1Orchestrates the generation of Rust, Kotlin, and Swift code from .proto and JSON schemas.
validate-proto.ps1Uses protoc to verify that all .proto files in schemas/proto are syntactically correct and importable scripts/protocol/validate-proto.ps1#43-66.
validate-rust-stubs.ps1Ensures generated Rust code compiles within the workspace.
validate-kotlin-stubs.ps1Uses kotlinc to verify that ProtocolStubs.kt is valid scripts/protocol/validate-kotlin-stubs.ps1#9-29.
validate-swift-stubs.shUses swiftc to compile the generated ProtocolStubs.swift into a module scripts/protocol/validate-swift-stubs.sh#7-21.
check-generated-stubs.ps1A CI utility that regenerates stubs and checks for git diffs to ensure committed stubs are up-to-date scripts/protocol/check-generated-stubs.ps1#9-21.
Sources: scripts/protocol/validate-proto.ps1#1-72, scripts/protocol/validate-kotlin-stubs.ps1#1-35, scripts/protocol/validate-swift-stubs.sh#1-22, scripts/protocol/check-generated-stubs.ps1#1-24

CI Enforcement and Security Gates

The integrity of protocol contracts is enforced in the GitHub Actions CI and Security Gates workflows.
  1. Stub Parity: The quality job in ci.yml runs check-generated-stubs.ps1. If a developer modifies a schema but forgets to run the generation script, the CI fails scripts/protocol/check-generated-stubs.ps1#16-20.
  2. Schema Validation: Every PR triggers validate-proto.ps1 to ensure that gRPC service definitions for GatewayService, BrowserService, and others remain compatible scripts/protocol/validate-proto.ps1#57-66.
  3. Cross-Platform Compilation: Stubs are compiled on Linux, macOS, and Windows runners to ensure language-specific compiler compatibility (e.g., swiftc on macOS, kotlinc on Ubuntu) .github/workflows/ci.yml#18-23.

System Component Mapping

The following diagram bridges the natural language definitions of the protocol to the specific code entities that handle them. Code-to-System Mapping Sources: .github/workflows/ci.yml#45-50, scripts/protocol/validate-kotlin-stubs.ps1#7-15, scripts/protocol/validate-swift-stubs.sh#5-10

Security and Supply Chain

The protocol layer is subject to high-risk pattern scanning and dependency auditing.
  • Audit Gates: The security-gates job runs cargo audit and npm audit to ensure that serialization libraries (like serde or prost) do not have known vulnerabilities .github/workflows/security.yml#95-99.
  • SBOM Generation: cargo-cyclonedx generates a Software Bill of Materials (SBOM) for all protocol-related crates to track the provenance of the communication stack .github/workflows/security.yml#131-133.
  • High-Risk Patterns: Scripts like check-high-risk-patterns.sh are executed to ensure that no sensitive data (e.g., Vault secrets) is accidentally exposed through the JSON envelope definitions .github/workflows/security.yml#128-129.
Sources: .github/workflows/security.yml#1-156, SECURITY.md#67-73