feat(build): WIT-driven IPC topic schemas - #644
Conversation
Add wit-parser to extract JSON Schemas from capsule WIT record definitions at install time. Capsule authors declare wit_type on [[topic]] entries in Capsule.toml to reference a WIT record by name. The build system parses the record's fields and /// doc comments into a JSON Schema that is baked into meta.json. At runtime, WasmEngine reads baked schemas and populates the SchemaCatalog for A2UI consumption. - Add wit-parser 0.227 workspace dependency - New astrid-build::wit_schema module: WIT record -> JSON Schema converter with support for primitives, option, list, tuple, enum, flags, variant, result, nested records, and type aliases - Add wit_type: Option<String> field to TopicDef (Capsule.toml) - Extend bake_topics() to resolve wit_type from capsule wit/ dir - Extract read_schema_file() helper from bake_topics() - Update SchemaCatalog::register_topics() to accept baked schemas - Wire schema catalog population into WasmEngine::load() via meta.json Closes #643
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces a significant enhancement to how Inter-Process Communication (IPC) topic schemas are managed within the system. It enables the use of WebAssembly Interface Type (WIT) records as a source for defining these schemas, allowing for a more integrated and automated approach to schema generation. The change streamlines the process of providing structured data definitions for topics, ensuring that these definitions are consistently available at runtime for various system components, including AI-to-UI interactions. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. From WIT's clear form, a schema springs, For IPC, new order brings. With types defined, and docs so neat, Our data flows, a structured feat. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a WIT record to JSON Schema converter to support IPC topic schemas defined in WIT. It adds a new wit_schema module in astrid-build, updates the capsule manifest to include a wit_type field, and modifies the installation process to bake these schemas into meta.json. Feedback focuses on ensuring WIT result unit types are explicitly mapped to null in the generated schema for accuracy and replacing a potential panic in file size conversion with proper error handling during the installation process.
- Use Resolve::push_dir() instead of per-file push_str() to handle multi-file WIT packages correctly (single package split across multiple .wit files in a directory) - Add MAX_TYPE_DEPTH (32) guard to prevent stack overflow on deeply nested type aliases or circular references in type_to_json_schema - Move schema catalog registration outside the capsule_registry guard so topics are registered unconditionally (schema_catalog is always present, even when registry is None in tests) - Guard push_dir against empty directories (no .wit files)
- Use {"type": "null"} for WIT result unit types (was {} or
{"type": "string"}) per review feedback
- Replace .expect() with .with_context()? for file size conversion
in read_schema_file()
Linked Issue
Closes #643
Summary
Add WIT-driven IPC topic schema extraction. Capsule authors declare
wit_typeon[[topic]]entries to reference a WIT record. At install time, the record's fields and///doc comments are converted to JSON Schema and baked intometa.json. At runtime,WasmEnginepopulates theSchemaCatalogfor A2UI consumption.Changes
wit-parser = "0.227"workspace dependencyastrid-build::wit_schemamodule — WIT record → JSON Schema converter (primitives, option, list, tuple, enum, flags, variant, result, nested records, type aliases)wit_type: Option<String>field toTopicDefinCapsule.tomlbake_topics()to resolvewit_typefrom capsulewit/directoryread_schema_file()helper frombake_topics()SchemaCatalog::register_topics()to accept baked schemas mapWasmEngine::load()viameta.jsonResolve::push_dir()for proper multi-file WIT package handlingMAX_TYPE_DEPTH(32) guard against recursive type aliasescapsule_registrypresence)Test Plan
Automated
cargo test --workspacepasseswit_schematests: simple record, empty dir, nonexistent dir, unknown type errorChecklist
[Unreleased]