---
id: TASK-9.1
title: Implement pre-run rebuild and --norebuild flag for simulation binary runs
status: Done
assignee:
  - '@codex'
created_date: '2026-02-04 09:46'
updated_date: '2026-02-04 09:51'
labels: []
dependencies: []
references:
  - bin/zync
  - lua/zync/api/commands/commands.lua
  - lua/zync/api/manager.lua
parent_task_id: TASK-9
---

## Description

<!-- SECTION:DESCRIPTION:BEGIN -->
Update `zync run` behavior so that when it executes the Zephyr simulator binary directly, it runs a build first by default, with a new `--norebuild/-n` flag to skip the rebuild. Ensure fallback to `ninja run` remains unchanged.
<!-- SECTION:DESCRIPTION:END -->

## Acceptance Criteria
<!-- AC:BEGIN -->
- [x] #1 When the simulator binary is executed directly, `zync run` performs a build first by default.
- [x] #2 Using `--norebuild/-n` skips the pre-run rebuild when executing the simulator binary.
- [x] #3 When `zync run` falls back to `ninja run`, behavior is unchanged from current (no additional build step and no change to run arguments).
- [x] #4 The new `--norebuild/-n` flag is exposed on the `run` command and limited to that command.
<!-- AC:END -->

## Implementation Plan

<!-- SECTION:PLAN:BEGIN -->
1. Add run-only `--norebuild/-n` flag in `lua/zync/api/commands/commands.lua` so it sets `config.norebuild`.
2. Update `Manager.run` in `lua/zync/api/manager.lua` to detect simulator binary with sysbuild-aware path handling. If present and `config.norebuild` is not set, call `Manager.build` before executing the binary.
3. Preserve the current `ninja run` fallback behavior when the binary is missing, and keep sysbuild image selection/working-directory behavior unchanged.
4. No tests in this subtask (tests handled in TASK-9.2).
<!-- SECTION:PLAN:END -->

## Implementation Notes

<!-- SECTION:NOTES:BEGIN -->
Implemented run-only `--norebuild/-n` CLI flag in commands.

Updated Manager.run to detect simulator binary before chdir, run build by default when present unless `norebuild` set, then execute binary; fallback to `ninja run` unchanged.
<!-- SECTION:NOTES:END -->
