Skip to content

feat(run): Add smart short ID resolution for templates and playlist items#48

Open
proboscis wants to merge 1 commit intomainfrom
issue/ISSUE-033/run-20260119-011347
Open

feat(run): Add smart short ID resolution for templates and playlist items#48
proboscis wants to merge 1 commit intomainfrom
issue/ISSUE-033/run-20260119-011347

Conversation

@proboscis
Copy link
Owner

Summary

  • Add smart resolution to runbox run <short_id> that can resolve any executable reference (template or playlist item) by short ID
  • Display clear resolution info before execution showing what was matched
  • Provide clear error messages for ambiguous matches with all candidates listed

Changes Made

Storage Layer (runbox-core/src/storage.rs)

  • Added ResolvedTarget enum with Template and PlaylistItem variants
  • Added ResolveTargetError enum for resolution failures (NotFound, Ambiguous, Storage)
  • Added Storage::resolve_target() method implementing smart resolution:
    1. Templates: exact match on template_id
    2. Templates: prefix match on normalized ID
    3. Playlist items: prefix match on hex short ID
  • Added 4 unit tests for resolve_target functionality

CLI (runbox-cli/src/main.rs)

  • Updated runbox run command to accept optional [TARGET] positional argument
  • Added cmd_run_smart() function that:
    • Resolves the target to template or playlist item
    • Displays resolution info (what matched, template, command)
    • Delegates to template execution
  • Updated help text with examples for smart resolution

Examples

# Smart resolution by template prefix
$ runbox run echo
Resolved: template "Echo Message" (tpl_echo)
  Template: Echo Message (tpl_echo)
  Command:  ["echo", "Hello, {name}!"]

# Smart resolution by playlist item short ID
$ runbox run a1b2c3d4
Resolved: playlist "daily" (daily) item 0 "Echo Hello" (tpl_echo)
  Template: Echo Message (tpl_echo)
  Command:  ["echo", "Hello, {name}!"]

# Ambiguous short ID
$ runbox run test
Error: Ambiguous short ID "test" matches 2 items:
  [template]       test_sec  "Test Second" (tpl_test_second)
  [template]       test_ech  "Test Echo" (tpl_test_echo)

Use more characters or specify explicitly:
  runbox run --template <id>
  runbox playlist run <playlist> <item>

# Explicit template (bypasses smart resolution)
$ runbox run --template tpl_echo

Acceptance Criteria

  • runbox run <short_id> resolves templates by prefix
  • runbox run <short_id> resolves playlist items by hex short ID
  • Ambiguous matches produce clear error with all candidates
  • Resolution info displayed before execution (what matched, template, command)
  • --template flag still works as explicit override
  • -- <command> direct execution still works
  • Dry run shows resolution + what would execute

Testing

  • All 55 unit tests pass
  • All CLI integration tests pass
  • Manual testing confirms resolution works correctly

Closes: ISSUE-033

…tems

- Add ResolvedTarget enum and resolve_target() function in storage.rs
- Update 'runbox run' to accept optional [TARGET] positional argument
- Smart resolution order: template exact match -> template prefix -> playlist item short ID
- Show resolution info before execution (what matched, template, command)
- Clear ambiguity error messages with all candidates listed
- Add tests for resolve_target functionality

Closes: ISSUE-033
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant