Skip to content

Relative asset paths resolve against the process CWD, not the scenario file #186

Description

@LeadcodeDev

Symptom

"src": "assets/dot.png" in a scenario resolves relative to wherever the process was launched, not to the scenario file. The same file renders or fails depending on the shell's directory.

cd /tmp/rmchk && rustmotion render -f rel.json -o a.png --frame 0    # ok
cd /       && rustmotion render -f /tmp/rmchk/rel.json -o b.png --frame 0
# Error: views[0].scenes[0].children[0].src: file not found 'assets/dot.png'

This is the single cause behind a whole family of "component X does not render" reports: authoring a scenario from its own directory works, then the studio — launched from the repo root — resolves nothing.

Why it is surprising

include already resolves relative to the including file. Two path-like fields in the same document following two different rules is the trap. Every asset field is affected: image.src, video.src, gif.src, audio.src, lottie.src, svg.src, mockup

The consequence is also inconsistent per component: a hard validation error for image and gif, a warning for video ("could not be decoded"), and nothing at all for an audio track feeding waveform before #181.

Proposed fix

Resolve asset paths against the scenario file's directory, like include, with the CWD as a fallback for compatibility:

  1. Thread the scenario's own directory (already known to the loader — included_paths proves it is tracked) into resolution.
  2. Add one helper, resolve_asset(base_dir, src), that returns src unchanged when absolute, tries base_dir/src, then falls back to cwd/src.
  3. Warn once when the CWD fallback is what matched, so existing scenarios keep working but the ambiguity is visible.
  4. Stdin scenarios (no file) keep the current behaviour.

Document the rule in SKILL.md next to include.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions