---
description: "Run Setup: Orchestrated setup with fix-loop, decision log, and reporting"
agdt:
  always: true
---

## User Input

```text
$ARGUMENTS
```

You **MUST** consider the user input before proceeding (if not empty).

## Purpose

Run the full agentic-devtools setup process with automatic fix-loop recovery,
decision logging, and conditional bug/feature reporting. This orchestrator:

1. Invokes `agdt-setup` as its first action
2. Classifies outcomes and applies bounded remedies via the fix-loop
3. Appends every iteration to the decision log
4. Always prints the decision log at the end
5. Gates reporter invocation based on outcome, TTY availability, and satisfaction

## Prerequisites

No prerequisites required — `agdt-setup` handles its own dependency checks.

## Actions

### Step 1: Run Setup

Run the canonical setup command:

```bash
agdt-setup
```

Capture the exit code and stdout/stderr output.

### Step 2: Evaluate Outcome

- **Exit code 0 or 1** (success/warnings): Append a success decision entry, then
  proceed to Step 5 (decision log show).

  ```bash
  agdt-setup-decision-log append \
    --step "success" \
    --question "Did setup complete without fix-loop remediation?" \
    --decision "setup_success" \
    --rationale "agdt-setup exited with code {exit_code}" \
    --auto-resolved true
  ```

- **Exit code ≥ 2**: Proceed to the fix-loop (Step 3).

### Step 3: Fix-Loop (Bounded Retry)

Track two counters:

- `attempts_per_class`: dictionary mapping each error class to its attempt count
- `total_iterations`: total number of fix attempts across all classes

Enforce hard caps: `MAX_ATTEMPTS_PER_CLASS = 2`, `MAX_TOTAL_ITERATIONS = 6`.

For each iteration:

1. **Classify** the outcome by calling
   `classify_outcome(report, exit_code, stdout)`
   from `agentic_devtools.cli.setup.fixloop`
   (where `report` is a small classifier-input dict that contains `error_class`
   only when available, or `None` otherwise; do not assume raw `agdt-setup`
   report output includes that top-level field; `exit_code` is the integer exit
   code, and `stdout` is the captured output string).
   This returns the canonical `ErrorClass` value using the priority chain:
   exit code 0/1 → SUCCESS; report `error_class` field → mapped class; exit-code
   taxonomy; stdout regex fallback; default UNKNOWN.

2. **If `error_class` is `ErrorClass.SUCCESS`**: append the success decision entry
   from Step 2 and proceed directly to Step 5. This is a terminal condition for
   the loop; skip `fixloop.next_action(...)` for this iteration.

3. **Determine action** by calling
   `fixloop.next_action(error_class, attempts_per_class.get(error_class, 0), total_iterations)`
   from `agentic_devtools.cli.setup.fixloop`
   (caps `MAX_ATTEMPTS_PER_CLASS = 2`, `MAX_TOTAL_ITERATIONS = 6` are enforced
   inside the function). This returns a `FixAction` with `give_up`, `remedy`,
   and `re_exec` fields.

4. **If give up**:
   - Set `termination_rationale = "retry cap reached"` when
     `attempts_per_class.get(error_class, 0) >= MAX_ATTEMPTS_PER_CLASS` or
     `total_iterations >= MAX_TOTAL_ITERATIONS`; otherwise set
     `termination_rationale = "permanent failure: {error_class}"`.
   - Append decision log entry:

     ```bash
     agdt-setup-decision-log append \
       --step "{error_class}" \
       --question "Can this error class be retried?" \
       --decision "give_up" \
       --rationale "{termination_rationale}" \
       --auto-resolved true
     ```

   - Proceed to Step 5 (decision log show). Step 6 handles invoking
     `/agdt.report-setup-bug` for the final failure outcome.

5. **If not give up** — apply remedy:
   - Set `attempt_number = attempts_per_class.get(error_class, 0) + 1`, then set
     `attempts_per_class[error_class] = attempt_number` and increment
     `total_iterations`
   - Apply the suggested remedy action
   - Append decision log entry:

     ```bash
     agdt-setup-decision-log append \
       --step "{error_class}" \
       --question "What remedy to apply for {error_class}?" \
       --decision "apply_remedy: {remedy}" \
       --rationale "attempt {attempt_number} of {MAX_ATTEMPTS_PER_CLASS} for this class" \
       --auto-resolved true
     ```

   - If `re_exec` is true: re-run `agdt-setup` immediately after the remedy.
     **If the new exit code is 0 or 1**, append a success decision entry:

     ```bash
     agdt-setup-decision-log append \
       --step "success" \
       --question "Did setup succeed after fix-loop remedy?" \
       --decision "setup_success" \
       --rationale "agdt-setup exited with code {exit_code} after remedy" \
       --auto-resolved true
     ```

     Then proceed to Step 5 (decision log show) — do not re-enter the loop.
     Otherwise, return to step 3.1 to evaluate the new outcome.
   - If `re_exec` is false: skip immediate re-execution; return to step 3.1.
     In that next iteration, run `agdt-setup` first to produce a fresh outcome,
     then classify/evaluate it.

### Step 4: (Reserved for Future Extension)

Extension point for repo-specialized setup expectations (see #2300).

### Step 5: Always Show Decision Log

Regardless of outcome, always print the decision log:

```bash
agdt-setup-decision-log show
```

### Step 6: Gate Reporters

Based on the final outcome:

First, determine the execution mode by evaluating `sys.stdin.isatty()` in Python
(e.g. `python -c "import sys; print(sys.stdin.isatty())"`). A result of `True`
means interactive mode; `False` means non-interactive (headless/pipeline).

- **Success (exit code 0 or 1) AND `sys.stdin.isatty()` is `True`**:
  Ask the user whether they are satisfied with the setup outcome. Invoke
  `/agdt.report-setup-feature` only if the user confirms they are satisfied.

- **Success, `sys.stdin.isatty()` is `True`, but user is not satisfied**:
  Skip the feature reporter.

- **Failure (give up or cap reached)**:
  Invoke `/agdt.report-setup-bug` to file a sanitized bug report.

- **Success but `sys.stdin.isatty()` is `False`** (non-interactive environment):
  Skip the feature reporter. Do not prompt for input.

## Expected Outcome

Setup completes successfully (possibly after automatic remediation), the decision
log is printed, and appropriate reporter(s) are invoked based on the outcome.

## Next Step

Command is complete.
