Repository navigation
[Config json format consolidation] #2 Add JSON schema, cross-field validation, and migrate examples to new config format - #49
Conversation
There was a problem hiding this comment.
Pull request overview
This PR is part of the config JSON format consolidation, adding a v1 JSON Schema for editor/tooling support, introducing cross-field validation in the Rust config parser, updating documentation, and migrating example configs toward the new top-level/sectioned format.
Changes:
- Added cross-field validation in
config_parser.rs(platform↔containment compatibility + schema major version gating) and expanded test coverage. - Introduced
schemas/mxc-config.v1.schema.jsonand rewrotedocs/schema.mdto describe the new config shape. - Migrated the checked-in example configs from legacy top-level fields (
script,timeout, etc.) towardprocess.commandLine,containerId,platform, andlifecycle.
Reviewed changes
Copilot reviewed 18 out of 18 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
| src/wxc_common/src/config_parser.rs | Adds platform/containment validation and schema version checks; updates/extends parser tests. |
| schemas/mxc-config.v1.schema.json | New JSON Schema describing the “v1” config format for tooling validation/autocomplete. |
| docs/schema.md | Updates documentation to the new schema-driven format and adds notes on validation/versioning. |
| examples/01_hello_world.json | Migrates to process.commandLine + containerId; drops appContainer.name. |
| examples/02_filesystem_access.json | Migrates to process.* and containerId; removes legacy policy cleanup flags. |
| examples/03_network_restricted.json | Migrates to process.* and containerId; removes legacy network cleanup flags. |
| examples/04_combined_restrictions.json | Migrates to process.* and containerId; removes legacy cleanup flags. |
| examples/05_custom_python.json | Migrates to process.* and containerId; drops appContainer.name. |
| examples/06_network_capabilities_only.json | Migrates to process.* and containerId; drops appContainer.name. |
| examples/07_test_delete.json | Migrates to process.commandLine and containerId; drops appContainer.name. |
| examples/08_pwsh.json | Migrates to process.commandLine and containerId; removes appContainer section previously used for naming. |
| examples/09_sandbox_hello_world.json | Moves timeout under process.timeout for sandbox example. |
| examples/10_sandbox_network_isolated.json | Moves timeout under process.timeout for sandbox example. |
| examples/11_localhost_proxy_appcontainer.json | Migrates to process.* and containerId; drops appContainer.name. |
| examples/11_lxc_hello_world.json | Migrates to process.commandLine, platform, and lifecycle; removes lxc.destroyOnExit. |
| examples/12_builtin_test_proxy_appcontainer.json | Migrates to process.* and containerId; drops appContainer.name. |
| examples/12_lxc_filesystem_access.json | Migrates to process.*, platform, and lifecycle; removes lxc.destroyOnExit. |
| examples/13_lxc_network_restricted.json | Migrates to process.*, platform, and lifecycle; removes lxc.destroyOnExit. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "wslc": { | ||
| "type": "object", | ||
| "description": "WSLC SDK-specific settings. Used when containment is 'wslc'.", | ||
| "properties": { | ||
| "image": { | ||
| "type": "string", | ||
| "default": "alpine:latest", | ||
| "description": "OCI container image name (e.g., 'python:3.12', 'ubuntu:22.04')." | ||
| }, | ||
| "storagePath": { | ||
| "type": "string", | ||
| "description": "Storage path for WSLC session image store. Omit for SDK default." | ||
| } | ||
| }, | ||
| "additionalProperties": false | ||
| }, |
There was a problem hiding this comment.
The schema defines WSLC settings under the top-level key wslc, but config_parser.rs currently reads WSLC settings from a top-level container object (RawConfig.container). Configs authored to this schema will therefore drop WSLC settings at runtime. Either rename the schema property to container (and document it), or update the parser to accept wslc (preferably with a dual-read fallback).
| "idleTimeoutMs": 300000 | ||
| }, | ||
|
|
||
| "wslc": { // WSLC SDK-specific |
There was a problem hiding this comment.
The docs show WSLC settings under a wslc object and sandbox settings using idleTimeoutMs, but config_parser.rs currently reads WSLC settings from a top-level container object and sandbox timeout from sandbox.idleTimeout. Please align the documented field names with what the parser accepts (or explicitly call out the legacy names / dual-read behavior).
| "idleTimeoutMs": 300000 | |
| }, | |
| "wslc": { // WSLC SDK-specific | |
| "idleTimeout": 300000 | |
| }, | |
| "container": { // Container / WSLC SDK-specific |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 11 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "script": "ls -la /mnt/shared && echo 'test' > /mnt/output/result.txt && cat /mnt/output/result.txt", | ||
| "process": { | ||
| "commandLine": "ls -la /mnt/shared && echo 'test' > /mnt/output/result.txt && cat /mnt/output/result.txt" | ||
| }, |
There was a problem hiding this comment.
This LXC example omits platform. With the new platform/containment validation in config_parser.rs, platform defaults to "windows" and this config will be rejected (LXC requires platform "linux"). Add "platform": "linux" here (and in other LXC examples) or adjust the parser defaulting behavior.
| }, | |
| }, | |
| "platform": "linux", |
| { | ||
| "script": "wget -qO- https://api.github.com/zen || echo 'Network blocked as expected'", | ||
| "process": { | ||
| "commandLine": "wget -qO- https://api.github.com/zen || echo 'Network blocked as expected'" | ||
| }, | ||
| "containment": "lxc", | ||
| "lxc": { |
There was a problem hiding this comment.
This LXC example omits platform. With the new platform/containment validation in config_parser.rs, platform defaults to "windows" and this config will be rejected (LXC requires platform "linux"). Add "platform": "linux" here (and in other LXC examples) or adjust the parser defaulting behavior.
| "type": "object", | ||
|
|
||
| "anyOf": [ | ||
| { "required": ["script"] }, |
There was a problem hiding this comment.
This schema’s top-level anyOf requires script in one branch, but script is not defined under properties while additionalProperties is false. That makes the script branch impossible to satisfy (any document with script would be invalid). Either add script to properties (if legacy support is intended) or remove the script branch from anyOf.
| { "required": ["script"] }, |
| "appContainer": { | ||
| "type": "object", | ||
| "description": "AppContainer-specific settings. Used when containment is 'appcontainer'.", | ||
| "properties": { | ||
| "leastPrivilege": { | ||
| "type": "boolean", | ||
| "default": false, | ||
| "description": "Enforce least privilege mode." | ||
| }, | ||
| "capabilities": { | ||
| "type": "array", | ||
| "items": { "type": "string" }, | ||
| "default": [], | ||
| "description": "AppContainer capabilities (e.g., 'internetClient', 'registryRead')." | ||
| } | ||
| }, | ||
| "additionalProperties": false |
There was a problem hiding this comment.
appContainer in the parser supports fields like learningMode (and previously name), and the example configs in this PR still use learningMode, but the schema only allows leastPrivilege and capabilities with additionalProperties: false. This makes the examples/configs invalid under the published schema; either extend the schema to include the supported AppContainer fields or update the examples/docs to match the schema.
| "removeRulesOnExit": true, // Remove firewall rules after execution | ||
| "proxy": { "localhost": 8080 } // Port of a localhost proxy | ||
| "defaultPolicy": "block", // "allow" or "block" | ||
| "enforcementMode": "firewall", // "capabilities", "firewall", or "both" |
There was a problem hiding this comment.
The docs’ “Full Schema” network section omits supported firewall-list fields (allowedHosts/blockedHosts) that are parsed by config_parser.rs and used in the examples. Consider documenting these fields here (or explicitly stating they’re omitted) to avoid misleading readers.
| "enforcementMode": "firewall", // "capabilities", "firewall", or "both" | |
| "enforcementMode": "firewall", // "capabilities", "firewall", or "both" | |
| "allowedHosts": ["api.example.com:443"], // Optional: hosts explicitly allowed when defaultPolicy is "block" | |
| "blockedHosts": ["*.tracker.com"], // Optional: hosts explicitly blocked when defaultPolicy is "allow" |
| "internetClient", | ||
| "privateNetworkClientServer" | ||
| ] | ||
| "version": "1", // Schema version (current: "1") |
There was a problem hiding this comment.
Versions must use SemVer. This should be 0.1.0-alpha.
| "type": "string", | ||
| "enum": ["linux", "windows"], | ||
| "default": "windows", | ||
| "description": "Host platform where wxc-exec runs. Must be compatible with the selected containment backend (e.g., AppContainer/Sandbox/WSLC require 'windows', LXC requires 'linux')." |
There was a problem hiding this comment.
thinking-out-loud: do we want to say runtime executable versus wxc-exec? But let's not focus too much on that for now.
| @@ -0,0 +1,181 @@ | |||
| { | |||
There was a problem hiding this comment.
I like the direction here with appContainer and lxc etc already being scoped into their own objects. I wonder if we should lean into that more consistently and make backend-specific configuration fully structured around the selected containment.
Right now, we have backend-specific containers:
"appContainer": { ... },
"lxc": { ... }But there isn't a strong relationship between them. e.g
"containment": "appcontainer" | "lxc" | configs can technically include multiple backend sections at once and nothing enforces that only the relevant backend config is present. E.g Folks looking at the schema might think they can mix and match containment backends.
My suggestion would be to see if we can formalize this pattern, so each backend owns its own schema and is conditionally validated.
Some like:
{
"type": "object",
"required": [
"containment",
"backends"
],
"properties": {
"containment": {
"type": "string",
"enum": [
"appcontainer",
"lxc"
]
},
"backends": {
"type": "object",
"properties": {
"appcontainer": {
"$ref": "#/$defs/appContainerConfig"
},
"lxc": {
"$ref": "#/$defs/lxcConfig"
}
},
"additionalProperties": false
}
},
"allOf": [
{
"if": {
"properties": {
"containment": {
"const": "appcontainer"
}
}
},
"then": {
"properties": {
"backends": {
"required": [
"appcontainer"
],
"maxProperties": 1
}
}
}
},
{
"if": {
"properties": {
"containment": {
"const": "lxc"
}
}
},
"then": {
"properties": {
"backends": {
"required": [
"lxc"
],
"maxProperties": 1
}
}
}
}
]
}So then this would be valid:
{
"containment": "lxc",
"backends": {
"lxc": {
"distribution": "alpine"
}
}
}and these will not be valid
{
"containment": "lxc",
"backends": {
"appcontainer": {}
}
}{
"containment": "lxc",
"backends": {
"lxc": {},
"appcontainer": {}
}
}{
"containment": "appcontainer",
"backends": {}
}Just a suggestion though, I thought it would be cleaner this way. This also allows what goes into Networking, Filesystem to be scoped inside the backends schema rather than at the top level. E.g today currently all of those are top level objects and not all their properties will be supported for every backend. Having each backend have their own schema imo gives us clear separation in the future. But this is all just a suggestion, I'll leave it up to you.
Step 2 of multi-step consolidation process.
Adds schemas/mxc-config.v1.schema.json for editor validation and tooling. Adds platform/containment compatibility checks and schema version validation in config_parser.rs. Rewrites docs/schema.md to document the new format. Migrates all 15 example configs to use process.commandLine, containerId, lifecycle, and platform fields. All existing configs still accepted via dual-read fallback.
PR 1 ✅ Merged
version,containerId,processsection with dual-read fallback.Vm/MicroVmenum variants.Manual
DefaultforCodexRequest.PR 2 🔄 In review -> This PR
schemas/mxc-config.v1.schema.json. Schema version validation.idleTimeoutMsdual-read.containerId→app_container_namemapping. Migrate 15 examples + 16 test configs. Updatedocs/schema.md.PR 3
LifecycleConfigstruct. Parselifecycle.destroyOnExit/preservePolicywith dual-read from legacyfields.
wslcalias forcontainerkey. Updatesdk/src/types.ts,cli/README.md,cli/ARCHITECTURE.md,sdk/README.md.PR 4
script,workingDirectory, top-leveltimeout,containeralias,appContainer.name,lxc.containerName,lxc.destroyOnExit,clearPolicyOnExit,removeRulesOnExitfrom parser. BumpSUPPORTED_MAJOR_VERSIONto 2.