Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true

strategy:
matrix:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ on:
jobs:
build:
runs-on: ubuntu-latest
env:
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
permissions:
contents: write

Expand Down
178 changes: 0 additions & 178 deletions docs/ARCHITECTURE.md

This file was deleted.

45 changes: 45 additions & 0 deletions docs/architecture/01-scenarios-view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# 1. Scenarios View (+1 View)

## Context
This view illustrates how the FlyCLI system is used from the perspective of external actors (Human Pilots and AI Agents) interacting with the Flight Controller hardware.

## 1.1 Core CLI Execution Scenario (Global)
This represents the primary use case: sending atomic text commands and retrieving structured results.

```mermaid
graph TD
User([Pilot / AI Agent]) -- "CLI Commands (e.g., status, dump)" --> FlyCLI[FlyCLI Tool]
FlyCLI -- "Serial/MSP Protocol" --> FC[Flight Controller]
FC -- "Telemetry / CLI Data" --> FlyCLI
FlyCLI -- "Parsed JSON or Text" --> User
```

## 1.2 Interactive RC Calibration Scenario (New Feature)
This flow highlights orchestration: the AI Agent triggers an interactive command, but the Human provides the physical input. FlyCLI acts as the bridge, providing visual feedback to the Human while collecting structured data for the Agent.

```mermaid
sequenceDiagram
actor Human as Pilot
participant Agent as AI Agent
participant CLI as FlyCLI Process
participant FC as Flight Controller

Agent->>CLI: flycli wizard rx <port> --json
CLI->>FC: Open Serial Port
CLI->>CLI: Initialize State Machine

loop Every 50ms (Polling)
CLI->>FC: Request MSP_RC (ID: 105)
FC-->>CLI: Binary Channel Data
CLI->>Human: Render ANSI Progress Bars (via process.stderr)
Human->>Human: Observes live feedback
end

Human->>FC: Moves Transmitter Sticks Physically
CLI->>CLI: State Machine detects min/max limits reached

CLI->>FC: Close Serial Port
CLI->>CLI: Clear ANSI terminal lines
CLI-->>Agent: Print JSON Summary (via process.stdout)
Agent->>Human: Confirm successful connection via Chat
```
70 changes: 70 additions & 0 deletions docs/architecture/02-logical-view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# 2. Logical View

## Context
This view outlines the primary abstractions, components, and the clean architecture that drives the business logic of FlyCLI. We use hexagonal architecture (Ports and Adapters) to ensure business logic independence.

## 2.1 Hexagonal Architecture (Global System)

```mermaid
graph TD
subgraph Delivery [Delivery Layer / Composition Root]
CLI[src/interfaces/cli/*.js]
end

subgraph Application [Application Layer]
UC[ExecuteCliUseCase]
WIZ[RxCalibrationMachine]
end

subgraph Infrastructure [Infrastructure Layer]
SFC[SerialFlightController]
MSP[MspProtocol]
end

subgraph Domain [Domain Layer]
IFC((IFlightController))
CP[CliParser]
end

CLI -- "Injects" --> SFC
CLI -- "Initializes" --> UC
CLI -- "Initializes" --> WIZ
UC -- "Uses" --> IFC
WIZ -- "Uses" --> MSP
SFC -- "Implements" --> IFC
UC -- "Uses" --> CP
```

### Layers:
- **Domain Layer**: Entities and interfaces (`IFlightController`, `CliParser`).
- **Application Layer**: Use Cases that implement specific scenarios (`ExecuteCliUseCase`, `RxCalibrationMachine`).
- **Infrastructure Layer**: Implementation of Serial communication (`SerialFlightController`) and binary protocol parsing (`MspProtocol`).
- **Delivery Layer**: CLI interfaces in `src/interfaces/cli/`. This is the only place where infrastructure connects with the application.

## 2.2 Interactive RC State Machine (Feature Logic)
The `RxCalibrationMachine` governs the RC wizard lifecycle.

```mermaid
stateDiagram-v2
[*] --> INIT: Execution Started
INIT --> CONNECTING: Open Port
CONNECTING --> POLLING: Port Opened Successfully
CONNECTING --> ERROR: Port Failure

state POLLING {
[*] --> READ_MSP
READ_MSP --> RENDER_UI
RENDER_UI --> CHECK_LIMITS
CHECK_LIMITS --> READ_MSP: Sticks haven't reached min/max
}

POLLING --> ANALYZING: All 4 axes hit edges (or Timeout)
ANALYZING --> SUCCESS: Data Valid
ANALYZING --> TIMEOUT: Data Invalid / Incomplete

SUCCESS --> DONE: Prepare JSON
TIMEOUT --> DONE: Prepare Error JSON
ERROR --> DONE

DONE --> [*]: process.exit(0/1)
```
48 changes: 48 additions & 0 deletions docs/architecture/03-process-view.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 3. Process View

## Context
This view explains the flow of data across asynchronous processes, focusing on hardware communication resilience and output stream separation.

## 3.1 Hardware Interaction (Command Lifecycle)
FlyCLI implements resilient processing of asynchronous events and fragmented data.

```mermaid
sequenceDiagram
participant CLI as interfaces/cli/execute.js
participant UC as ExecuteCliUseCase
participant SFC as SerialFlightController
participant HW as Flight Controller

CLI->>SFC: new SerialFlightController(...)
CLI->>UC: new ExecuteCliUseCase(SFC, ...)
CLI->>UC: execute("status")

UC->>SFC: connect()
SFC->>HW: MSP Handshake (API_VERSION)
HW-->>SFC: ACK (0x65)

UC->>SFC: sendRaw("status\n")
HW-->>SFC: Data Chunks...
HW-->>SFC: Final Prompt "# "

SFC-->>UC: Full Response String
UC-->>CLI: Parsed JSON/Text
```

### Implementation Realities:
- **Data Fragmentation:** USB-VCP requires processing chunks of 64/128 bytes. `SerialFlightController` accumulates data in `#buffer` until the prompt pattern appears.
- **Debounce:** A delay of **300ms** is added in `ExecuteCliUseCase` after prompt detection to collect the "tail" of data.

## 3.2 Data Stream Separation (Interactive UI)
For interactive features (like the RC Wizard), visual elements must not corrupt machine-readable output formats.

```mermaid
graph TD
A[FlyCLI Process] -->|Asynchronous Event Loop| B(MSP Polling Timer ~20Hz)
B --> C{Output Routing}
C -->|Visual Progress Bars| D[process.stderr / TTY]
C -->|Final JSON payload| E[process.stdout]
```

- `process.stderr.write` is used synchronously to draw ANSI bars.
- `console.log` (stdout) is strictly reserved for the final output string/JSON.
Loading
Loading