---
phase: 11-refactor
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
  - InputArgs.cs
  - Program.cs
  - AesCrypt.cs
autonomous: true
---

<objective>
## Goal
Extract arg parsing into dedicated `ArgParser` static class; clean `Program.cs` control flow; delete dead `AesCrypt.cs`.

## Purpose
Program.cs currently mixes arg parsing, license check, business dispatch, and output formatting in one file. Separating concerns makes each part testable and readable. No behavior change — same inputs produce same outputs.

## Output
- New `ArgParser.cs` (static class, pure function: `string[] → InputArgs`)
- `Program.cs` simplified: Main calls `ArgParser.Parse`, then dispatches
- `AesCrypt.cs` deleted
- All existing tests still pass
</objective>

<context>
@.paul/PROJECT.md
@Program.cs
@InputArgs.cs
@AesCrypt.cs
</context>

<acceptance_criteria>

## AC-1: ArgParser extracted
```gherkin
Given string[] args with valid parameters
When ArgParser.Parse(args) is called
Then returns populated InputArgs with correct field values
```

## AC-2: Program.cs simplified
```gherkin
Given Program.cs
When read
Then Main has no inline regex or arg-parsing logic — delegates entirely to ArgParser.Parse
```

## AC-3: AesCrypt deleted
```gherkin
Given AesCrypt.cs (dead code, nothing references it)
When file is deleted
Then project still compiles with no errors
```

</acceptance_criteria>

<tasks>

<task type="auto">
  <name>Task 1: Create ArgParser.cs</name>
  <files>ArgParser.cs</files>
  <action>
    Create static class `NcProgramManager.ArgParser` with single public method:
    `public static InputArgs Parse(string[] args)`

    Move ALL logic from `parseArgomenti` in Program.cs into this method verbatim,
    then adapt signature (returns InputArgs instead of mutating field).

    Rules:
    - Keep same regex patterns and substring offsets — no behavior change
    - Throw same exceptions on parse failure (caller catches in Main)
    - Class is internal static, method is internal static
    - No new dependencies
  </action>
  <verify>ArgParser.cs compiles; `ArgParser.Parse(new[]{"-help"}).mostraHelp == true`</verify>
  <done>AC-1 satisfied: ArgParser.Parse returns correct InputArgs</done>
</task>

<task type="auto">
  <name>Task 2: Simplify Program.cs</name>
  <files>Program.cs</files>
  <action>
    Replace `parseArgomenti` call with `inputArgs = ArgParser.Parse(args)`.
    Delete `parseArgomenti` method body from Program.cs entirely.
    Remove the `private static InputArgs inputArgs = new InputArgs()` field —
    declare `InputArgs inputArgs` as local variable in Main instead.
    Pass `inputArgs` explicitly to `Scarica(machine, inputArgs)` and `Invia(machine, inputArgs)`.
    Update Scarica/Invia signatures to accept `InputArgs` parameter (no longer use static field).
    `vediErrore` already uses `inputArgs.debugMode` — pass it as parameter too,
    or make vediErrore accept `bool debugMode`.

    Do NOT change license check, MostraAiuto, vediErrore content, or error codes.
  </action>
  <verify>Project compiles. `dotnet build` (or msbuild) reports 0 errors. Scarica/Invia no longer reference static field.</verify>
  <done>AC-2 satisfied: Main delegates to ArgParser, no inline regex</done>
</task>

<task type="auto">
  <name>Task 3: Delete AesCrypt.cs</name>
  <files>AesCrypt.cs</files>
  <action>
    Verify no file in the project references `AesCrypt` (grep before deleting).
    Delete AesCrypt.cs.
    Remove its entry from NcProgramManager.csproj `<Compile>` list if present.
  </action>
  <verify>
    grep -r "AesCrypt" . --include="*.cs" returns no results.
    Project compiles.
  </verify>
  <done>AC-3 satisfied: dead code removed, project still compiles</done>
</task>

</tasks>

<boundaries>

## DO NOT CHANGE
- Cnc/* — all machine implementation files
- Licensing/* — license system
- FanucProgram.cs, fwlib32.cs
- Error codes in vediErrore
- MostraAiuto content (README task handles docs)
- NcProgramManager.Tests/*

## SCOPE LIMITS
- No behavior change — same CLI args produce same results
- Do not refactor Scarica/Invia error handling (that is Plan 11-02)
- Do not add new error messages or change exit codes

</boundaries>

<verification>
Before declaring plan complete:
- [ ] grep -r "AesCrypt" . --include="*.cs" returns 0 results
- [ ] grep "parseArgomenti" Program.cs returns 0 results
- [ ] Project compiles (msbuild or dotnet build)
- [ ] ArgParser.cs exists at project root
- [ ] All tests pass (NcProgramManager.Tests)
</verification>

<success_criteria>
- ArgParser.cs created, all parsing logic moved
- Program.cs Main has no regex or substring parsing
- AesCrypt.cs deleted and removed from csproj
- Zero compilation errors
- Zero test regressions
</success_criteria>

<output>
After completion, create `.paul/phases/11-refactor/11-01-SUMMARY.md`
</output>
