Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ and the `three_live_gym_reset` / `three_live_gym_step` / `three_live_gym_close`
closed-loop agent gym):

```bash
# 1. Static + Spatial Linting (Structured JSON Diagnostics TL100-TL402 + Frustum/Grounding/Lighting)
# 1. Static + Spatial + Accessibility Linting (Structured JSON Diagnostics TL100-TL606 + Frustum/Grounding/Lighting/A11y)
three-live-cli validate scene.js --json

# 2. Visual Verification (2x2 Orthographic + Camera Contact Sheet with 1m Grid & AABB Annotations)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ enum Commands {
format: Option<Format>,
},

/// Validate Three.js script or HTML file and report compiler/schema/spatial diagnostics
/// Validate Three.js script or HTML file and report compiler/schema/spatial/a11y diagnostics
Validate {
/// Input JavaScript (.js) or HTML (.html) file path
input: PathBuf,
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ fn mcp_tool_definitions_base() -> Value {
json!([
{
"name": "three_live_validate",
"description": "Validate a Three.js script (.js), HTML document (<three-live>/<xr-live>), or .glb binary and run the 3D spatial, camera frustum, grounding, AABB collision, and lighting linter (TL100-TL402).",
"description": "Validate a Three.js script (.js), HTML document (<three-live>/<xr-live>), or .glb binary and run the 3D spatial, camera frustum, grounding, AABB collision, lighting, and 3D/XR accessibility linter (TL100-TL606).",
"inputSchema": {
"type": "object",
"properties": {
Expand Down
346 changes: 344 additions & 2 deletions compiler/src/spatial_lint.rs

Large diffs are not rendered by default.

127 changes: 127 additions & 0 deletions compiler/tests/three_compiler_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5721,3 +5721,130 @@ fn test_stage3_science_crystal_miller_planes_and_callouts() {
assert!(usda.contains("HydrogenBondDashes"));
assert!(usda.contains("BondAngleArc"));
}

#[test]
fn test_a11y_linter_tl601_to_tl606() {
use serde_json::json;
use three_live_compiler::{handle_mcp_request, validate_and_lint_scene};

let a11y_script = r#"
scene.add(new THREE.AmbientLight(0xffffff, 0.8));
const sun = new THREE.DirectionalLight(0xffffff, 1.4);
sun.position.set(2, 4, 3);
scene.add(sun);

// TL601: Low non-text contrast (< 3.0:1 against #0d1629 dark studio background)
const darkChip = new THREE.Mesh(
new THREE.BoxGeometry(0.6, 0.2, 0.6),
new THREE.MeshStandardMaterial({ color: 0x334155, metalness: 0.4, roughness: 0.5 })
);
darkChip.name = 'DarkGullWingIC';
darkChip.position.set(-1.2, 0.1, 0);
scene.add(darkChip);

// TL602: 3D text / label contrast (< 4.5:1 WCAG AA text threshold)
const dimLabel = new THREE.Mesh(
new THREE.BoxGeometry(0.5, 0.2, 0.05),
new THREE.MeshStandardMaterial({ color: 0x64748b, roughness: 0.5 })
);
dimLabel.name = 'StatusLabel';
dimLabel.position.set(0, 0.8, 0);
dimLabel.userData.xr = { text: { text: 'LOW CONTRAST', size: 0.12 } };
scene.add(dimLabel);

// TL603 (tiny interactive target < 0.4% coverage) + TL604 (missing accessible name)
const tinyUnnamedBtn = new THREE.Mesh(
new THREE.SphereGeometry(0.03, 12, 8),
new THREE.MeshStandardMaterial({ color: 0x38bdf8 })
);
tinyUnnamedBtn.position.set(0.8, 0.5, -1.5);
tinyUnnamedBtn.userData.xr = { grab: true };
scene.add(tinyUnnamedBtn);

// TL605: Vestibular comfort (orbit speed > 2.5 rad/s)
const fastSpinner = new THREE.Mesh(
new THREE.BoxGeometry(0.4, 0.4, 0.4),
new THREE.MeshStandardMaterial({ color: 0xfacc15 })
);
fastSpinner.name = 'RapidOrbitOrb';
fastSpinner.position.set(1.2, 0.5, 0);
fastSpinner.userData.xr = { orbit: { radius: 0.5, speed: 4.2 } };
scene.add(fastSpinner);

// TL606: Red-green interactive siblings of identical dimensions
const redBtn = new THREE.Mesh(
new THREE.BoxGeometry(0.35, 0.35, 0.35),
new THREE.MeshStandardMaterial({ color: 0xdc2626 })
);
redBtn.name = 'StopButton';
redBtn.position.set(-0.35, 0.2, 0.5);
redBtn.userData.xr = { grab: '1-hand' };
scene.add(redBtn);

const greenBtn = new THREE.Mesh(
new THREE.BoxGeometry(0.35, 0.35, 0.35),
new THREE.MeshStandardMaterial({ color: 0x16a34a })
);
greenBtn.name = 'StartButton';
greenBtn.position.set(0.35, 0.2, 0.5);
greenBtn.userData.xr = { grab: '1-hand' };
scene.add(greenBtn);

camera.position.set(0, 1.2, 3.5);
camera.lookAt(0, 0.4, 0);
"#;

let report = validate_and_lint_scene(a11y_script, "a11y.js", 1.5);
assert!(
report.valid,
"Default validation should keep valid=true when only warnings/infos are present: {:?}",
report.diagnostics
);

for expected_code in ["TL601", "TL602", "TL603", "TL604", "TL605", "TL606"] {
assert!(
report.diagnostics.iter().any(|d| d.code == expected_code),
"Expected {} diagnostic in report, got: {:?}",
expected_code,
report.diagnostics
);
}

// Verify severities: TL601–TL603 are warnings; TL604–TL606 are info suggestions
for warn_code in ["TL601", "TL602", "TL603"] {
let diag = report.diagnostics.iter().find(|d| d.code == warn_code).unwrap();
assert_eq!(diag.severity, "warning", "{} should be warning by default", warn_code);
assert!(diag.hint.is_some(), "{} should include an actionable hint", warn_code);
}
for info_code in ["TL604", "TL605", "TL606"] {
let diag = report.diagnostics.iter().find(|d| d.code == info_code).unwrap();
assert_eq!(diag.severity, "info", "{} should be info suggestion by default", info_code);
assert!(diag.hint.is_some(), "{} should include an actionable hint", info_code);
}

// Verify MCP `three_live_validate` returns the TL601–TL606 diagnostics in its JSON report
let mcp_req = json!({
"jsonrpc": "2.0",
"id": 601,
"method": "tools/call",
"params": {
"name": "three_live_validate",
"arguments": {
"code": a11y_script
}
}
});
let mcp_resp = handle_mcp_request(&mcp_req).expect("MCP response");
assert_eq!(mcp_resp["result"]["isError"], false);
let mcp_report: serde_json::Value =
serde_json::from_str(mcp_resp["result"]["content"][0]["text"].as_str().unwrap()).unwrap();
assert_eq!(mcp_report["valid"], true);
let mcp_diags = mcp_report["diagnostics"].as_array().unwrap();
for expected_code in ["TL601", "TL602", "TL603", "TL604", "TL605", "TL606"] {
assert!(
mcp_diags.iter().any(|d| d["code"] == expected_code),
"MCP three_live_validate missing {}",
expected_code
);
}
}
19 changes: 18 additions & 1 deletion docs/llm-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ For scripts and RL harnesses, `three-live-cli gym play level.js` prints the
(`{"actions": [...], "ticks": 30, "frame": "f.png"}`) and prints one observation
(or `{"error": ...}`) per line, keeping state in memory.

### Diagnostic Code Summary (`TL100–TL402`)
### Diagnostic Code Summary (`TL100-TL606`)

| Code | Category | Meaning & Fix |
| :------ | :------- | :----------------------------------- |
Expand Down Expand Up @@ -550,3 +550,20 @@ For scripts and RL harnesses, `three-live-cli gym play level.js` prints the
: : : (`xr-hands`, `gemini-live`, :
: : : `plugins`, `slot="spatial"`) placed :
: : : on `<three-live>`. :
| `TL601` | A11y | Foreground mesh luminance contrast |
: : : `< 3.0:1` (WCAG 2.1 SC 1.4.11) :
: : : against dark studio viewport. :
| `TL602` | A11y | 3D text / label contrast `< 4.5:1` |
: : : (WCAG 2.1 SC 1.4.3). :
| `TL603` | A11y | Interactive target covers `< 0.4%` |
: : : of viewport (`< 2.5°` XR visual :
: : : angle, WCAG 2.2 SC 2.5.8). :
| `TL604` | A11y | Interactive node missing descriptive |
: : : `mesh.name` or `userData.xr.label` :
: : : (`info` suggestion). :
| `TL605` | A11y | Continuous `orbit.speed > 2.5 rad/s` |
: : : or `follow.stiffness > 25` (`info` :
: : : vestibular comfort suggestion). :
| `TL606` | A11y | Interactive siblings of identical |
: : : size rely on red-green hue alone :
: : : (`info` CVD suggestion). :
Loading
Loading