---
id: TASK-17.1
title: Add sysbuild image discovery and resolution logic
status: Done
assignee:
  - codex
created_date: '2026-02-27 08:46'
updated_date: '2026-02-27 08:52'
labels: []
dependencies: []
references:
  - docs/zync/README.md
  - docs/zync/lua/zync/api/manager.lua
  - src/core/cmd.rs
parent_task_id: TASK-17
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Implement image discovery and resolution for sysbuild projects, including default image selection and numeric image selection, and integrate it into cmd run/flash.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 Sysbuild images are discovered from the build dir, excluding non-image directories (e.g., `zephyr`, `modules`, `_sysbuild`).
- [x] #2 `--image` accepts image name or 1-based index; invalid selections return a clear error.
- [x] #3 If no image is selected, the first non-bootloader image (e.g., not `mcuboot`) is chosen by default for sysbuild projects.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
Plan:
1) Implement a `resolve_sysbuild_image` helper in `src/core/cmd.rs` to select default images (first non-`mcuboot`), map numeric `--image` values to 1-based index, and validate name selections with clear errors.
2) Integrate the resolver into `cmd_run` and `cmd_flash` for sysbuild projects.
3) Add/adjust unit tests to cover default selection and index/name validation.
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Implemented sysbuild image resolution helper: default to first non-mcuboot, accept 1-based index or name, error on invalid/empty. Integrated into cmd_run/cmd_flash; updated list output format; added tests for defaults/index/name/invalid selections. `just test` passes (75 tests).
<!-- SECTION:NOTES:END -->

## Final Summary

<!-- SECTION:FINAL_SUMMARY:BEGIN -->
Added sysbuild image resolution logic (default non-mcuboot, 1-based index or name, invalid selection errors) and integrated it into cmd run/flash. Updated list output format and added unit tests covering defaults and validation. `just test` passes.

Tests: `just test`
<!-- SECTION:FINAL_SUMMARY:END -->
