# Roadmap: FanucProgramManager

## Overview

Console tool for CNC program transfer and file management. Fanuc FOCAS base, expanding to multi-CN (Heidenhain LSV2, Siemens FTP, Mitsubishi FTP) with NC program validation.

## Current Milestone

**v0.7 Build Hardening** (v0.7.0)
Status: 🚧 In Progress
Phases: 0 of 2 complete

Theme: Formalizzare pipeline build sicura — obfuscation Release (ConfuserEx), license bypass Debug, fix review findings v0.6 (ISS-012..017).

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 17 | build-pipeline | TBD | Not started | - |
| 18 | review-fixes | TBD | Not started | - |

### Phase 17: build-pipeline

Focus: ConfuserEx Release obfuscation pipeline, Debug license bypass (`#if !DEBUG`), `tools/` gitignore, docs build process.
Plans: TBD (defined during /paul:plan)

### Phase 18: review-fixes

Focus: Chiudere review findings v0.6 — ISS-012 (Fagor ReadActiveProgram), ISS-013 (FanucProgram coupling), ISS-014 (ResolvePath NRE), ISS-015 (file encoding UTF-8 BOM), ISS-016 (validator path fallback), ISS-017 (Ping swallow log).
Plans: TBD (defined during /paul:plan)

---

## Past Milestones

**v0.1 Multi-CN Release** (v0.1.0)
Status: ✅ Complete
Phases: 5 of 5 complete
Completed: 2026-05-13

## Phases

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 1 | cnc-abstraction | 1 | ✅ Complete | 2026-05-13 |
| 2 | heidenhain | 1 | ✅ Complete | 2026-05-13 |
| 3 | siemens | 1 | ✅ Complete | 2026-05-13 |
| 4 | program-wiring | 1 | ✅ Complete | 2026-05-13 |
| 5 | nc-validator | 1 | ✅ Complete | 2026-05-13 |

## Phase Details

### Phase 1: cnc-abstraction ✅

**Goal:** Fix namespace, add all Cnc/ files to csproj, complete ICncMachine + IFanucMachine with 3-file support
**Completed:** 2026-05-13

**Delivered:**
- Namespace `Fanuc_integration.Cnc.*` → `FanucProgramManager.Cnc.*` (29 files)
- `IFocasDialect` extended: `UploadStart`/`DownloadStart` accept `short fileType`
- `IFanucMachine` interface: extends `ICncMachine` with tool offset + work zero R/W
- `CncManufacturer` enum: Fanuc, Heidenhain, Siemens
- All 29 `Cnc/**/*.cs` files added to csproj

### Phase 2: heidenhain ✅

**Goal:** Implement ICncMachine for Heidenhain TNC via LSV2 protocol
**Completed:** 2026-05-13

**Delivered:**
- `HeidenhainConnectionConfig` — IP, port 19000, credentials, timeout
- `Lsv2Client` — TCP framing, CRC-16/CCITT, login (SELECT+LOG_IN), ReceiveFile/SendFile
- `HeidenhainMachine : ICncMachine` — RunGuardedAsync pattern, state machine

### Phase 3: siemens ✅

**Goal:** Implement ICncMachine for Siemens Sinumerik via FTP
**Completed:** 2026-05-13

**Delivered:**
- `SiemensConnectionConfig` — IP, port 21, creds, program dir `/_N_MPF_DIR/`
- `SiemensFtpClient` — FtpWebRequest wrapper, ASCII mode, passive
- `SiemensMachine : ICncMachine`

**Bonus (post-apply):**
- `MitsubishiConnectionConfig` / `MitsubishiFtpClient` / `MitsubishiMachine : ICncMachine`
- `CncManufacturer.Mitsubishi` added to enum + factory + CLI

### Phase 4: program-wiring ✅

**Goal:** Wire all manufacturers into Program.cs + InputArgs
**Completed:** 2026-05-13

**Delivered:**
- `CncMachineFactory` — creates right `ICncMachine` from `InputArgs`
- `InputArgs` — added `manufacturer`, `username`, `password` fields
- `Program.cs` — full rewrite using `ICncMachine` factory; Fanuc 3-file via `IFanucMachine` cast

### Phase 5: nc-validator ✅

**Goal:** Per-manufacturer NC program validator runs inside WriteProgramAsync before upload
**Completed:** 2026-05-13

**Delivered:**
- `ValidationSeverity` / `ValidationError` / `ValidationResult` model types
- `INcProgramValidator` + `NcProgramValidator` with universal + per-manufacturer rules
- Validator injected into all 4 machine classes
- `NcProgramValidatorTests` — 30+ NUnit tests

---

## Next Milestone

**v0.2 NcProgramManager** ✅ Complete
Status: Complete
Phases: 4 of 4 complete
Completed: 2026-05-17

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 06 | rename-cleanup | 1 | ✅ Complete | 2026-05-17 |
| 07 | license-core | 1 | ✅ Complete | 2026-05-17 |
| 08 | license-integration | 1 | ✅ Complete | 2026-05-17 |
| 09 | license-generator | 1 | ✅ Complete | 2026-05-17 |

### Phase 06: rename-cleanup ✅
**Goal:** Rename FanucProgramManager → NcProgramManager (namespace, project files, test folder). Delete dead FANUCMachine.cs.
**Completed:** 2026-05-17
**Plans:** [x] 06-01: Namespace + file rename

### Phase 07: license-core ✅
**Goal:** `IMachineFingerprint`, `ILicenseValidator`, RSA signature verification, `.lic` file model
**Completed:** 2026-05-17
**Plans:** [x] 07-01: RSA core + interfaces + 6 unit tests

### Phase 08: license-integration ✅
**Goal:** Wire license system into Program.cs, delete `checkLicense`, remove `-chiave=`, hardcode `license.lic` next to EXE
**Completed:** 2026-05-17
**Plans:** [x] 08-01: Program.cs wiring

### Phase 09: license-generator ✅
**Goal:** Separate generator console app — reads machine fingerprint, signs, writes `.lic` file
**Completed:** 2026-05-17
**Plans:** [x] 09-01: LicenseGenerator standalone tool + real public key embedded

---

## Standalone Phases (post-v0.2)

| Phase | Name | Plans | Status |
|-------|------|-------|--------|
| 10 | readme-docs | 1 | ✅ Complete | 2026-05-17 |

### Phase 10: readme-docs ✅
**Goal:** Write Italian README for NcProgramManager and LicenseGenerator repos — describe what each does, prerequisites, setup, CLI usage, license workflow.
**Depends on:** Phase 09 (license workflow complete)
**Plans:** [x] 10-01: Italian READMEs for both repos

---

## Milestone v0.3 — Code Quality ✅

Status: Complete
Phases: 2 of 2 complete
Completed: 2026-05-18

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 11 | refactor | 2 | ✅ Complete | 2026-05-18 |
| 12 | docs-cli | 1 | ✅ Complete | 2026-05-18 |

### Phase 11: refactor ✅
**Goal:** Clean Architecture refactor of Program.cs — extract ArgParser, fix error handling in Scarica/Invia (try/finally, surface CncResult.Errors), remove AesCrypt dead code.
**Completed:** 2026-05-18
**Plans:**
- [x] 11-01: Extract ArgParser + clean Program.cs structure
- [x] 11-02: Fix Scarica/Invia error handling

### Phase 12: docs-cli ✅
**Goal:** Complete README parameter table — all 16 CLI args with descriptions; error codes with causa + soluzione.
**Completed:** 2026-05-18
**Plans:**
- [x] 12-01: README complete CLI reference + error codes table

---

## Milestone v0.4 — Robustness ✅

**Status:** Complete
**Phases:** 2 of 2 complete
**Completed:** 2026-05-18

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 13 | robustness-fixes | 1 | ✅ Complete | 2026-05-18 |
| 14 | test-hardening | 1 | ✅ Complete | 2026-05-18 |

### Phase 13: robustness-fixes ✅

**Goal:** Fix ISS-001, ISS-005, ISS-006 — null guard on MachineFingerprint WMI properties, dispose SHA256CryptoServiceProvider, fix Lsv2Client connect timeout to actually abort hung task.
**Issues addressed:** ISS-001, ISS-005, ISS-006
**Completed:** 2026-05-18
**Plans:**
- [x] 13-01: Null guard WMI, SHA256 dispose, LSV2 timeout abort

### Phase 14: test-hardening ✅

**Goal:** Fix ISS-007, ISS-008 — env-var-gated hardware test scaffolding for all 3 machine types; LicenseFile edge-case unit tests; empty-fingerprint guard in LicenseValidator.
**Issues addressed:** ISS-007 (closed), ISS-008 (scaffold complete; full closure requires Windows hardware run)
**Completed:** 2026-05-18
**Plans:**
- [x] 14-01: HardwareTestHelper + LicenseFileTests + Validate_EmptyFingerprint

---

## Milestone v0.5 — Operational Quality ✅

**Status:** Complete
**Phases:** 1 of 1 complete
**Completed:** 2026-05-18

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 15 | logging | 2 | ✅ Complete | 2026-05-18 |

### Phase 15: logging ✅

**Goal:** Add structured logging (ISS-004), surface silent catch blocks (ISS-003), route all operator output through NLog.
**Issues addressed:** ISS-003 (closed), ISS-004 (closed)
**Completed:** 2026-05-18
**Plans:**
- [x] 15-01: NLog 5.2.8 + nlog.config + logger fields in 5 classes + event handler catches + Program.cs error logging
- [x] 15-02: Replace all Console.Write/WriteLine with _log.Info; console target Info-only plain layout

---

## Milestone v0.6 — Fagor Support ✅

**Status:** Complete
**Phases:** 1 of 1 complete
**Completed:** 2026-05-25

| Phase | Name | Plans | Status | Completed |
|-------|------|-------|--------|-----------|
| 16 | fagor-ftp | 2 | ✅ Complete | 2026-05-25 |

### Phase 16: fagor-ftp ✅

**Goal:** Aggiungere supporto Fagor CNC via FTP. Riuso pattern Siemens/Mitsubishi. Refactor validator per gating per-produttore. Modelli supportati: 8060/8065/8070 nativi, 8055 con opzione Ethernet.
**Issues addressed:** —
**Completed:** 2026-05-25
**Plans:**
- [x] 16-01: Fagor FTP machine + validator gating + CLI integration + test scaffold
- [x] 16-02: Fagor fixup post-review (validator extension fix, ñ escape, lock tests Siemens/Heidenhain, factory test)

---
*Roadmap updated: 2026-05-25 — v0.7 Build Hardening milestone created; Phases 17 (build-pipeline) + 18 (review-fixes) scaffolded.*
