1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! flodl-cli — library side of the `fdl` binary.
//!
//! This crate is both a library and a binary. The binary (`fdl`) is the
//! user-facing driver; the library exposes the pieces that other crates
//! (e.g. a flodl-based training binary) need to integrate with the
//! `fdl` ecosystem:
//!
//! - [`FdlArgs`] — derive macro + trait for argv parsing and schema emission
//! - [`parse_or_schema`] — intercepts `--fdl-schema` / `--help` and dispatches
//! - [`Schema`], [`OptionSpec`], [`ArgSpec`] — the canonical schema shape
//!
//! # Example
//!
//! ```no_run
//! use flodl_cli::{FdlArgs, parse_or_schema};
//!
//! /// My training binary.
//! #[derive(FdlArgs, Debug)]
//! struct Cli {
//! /// Model to run.
//! #[option(short = 'm', default = "all")]
//! model: String,
//!
//! /// Write a report instead of training.
//! #[option(default = "runs/report.md")]
//! report: Option<String>,
//! }
//!
//! fn main() {
//! let cli: Cli = parse_or_schema();
//! // ... use cli.model, cli.report, etc.
//! }
//! ```
// Self-alias: the `#[derive(FdlArgs)]` macro emits `::flodl_cli::...`
// paths. That resolves automatically when the derive is used from a
// downstream crate (or from `main.rs`, which sees the lib as an external
// dep), but inside the library itself the compiler only knows the
// crate by its `crate`-root name. The alias makes `::flodl_cli::...`
// resolve to ourselves so `builtins.rs` can derive the same trait.
extern crate self as flodl_cli;
// Internal modules — shared by lib consumers and the fdl binary.
/// Structured API reference for flodl itself (`fdl api-ref`), used by
/// AI porting tools and as a machine-readable surface index.
/// Argv parsing primitives and the [`FdlArgsTrait`] contract that
/// `#[derive(FdlArgs)]` implements.
/// Built-in `fdl` sub-commands (setup, install, completions, schema,
/// config, libtorch, diagnose, init, skill, ...).
/// Shell completion script generation and per-project completion
/// enrichment driven by cached schemas.
/// `fdl.yml` manifest loading, validation, and resolved-command types.
/// Cluster-mode env preparation. fdl-cli sets `FLODL_INTERNAL_FULL_CLUSTER_JSON`
/// + `FLODL_INTERNAL_FDL_CMD` + `FDL_ENV` on its process env so the user binary
/// inherits them and detects launcher role via
/// `flodl::distributed::launcher::dispatch`. Fan-out, log fan-in, and
/// ClusterController all live on the flodl side.
/// Entry point [`cluster::prepare_cluster_env`]; recursion guard via
/// [`cluster::should_dispatch`].
/// `--gpus` flag parsing + single-host cluster envelope synthesis (loopback,
/// one host, N ranks). Used when `--gpus` is set on a cluster-aware command
/// and no `cluster:` block is configured in YAML.
/// Cross-cutting context passed to sub-command handlers (resolved config,
/// verbosity, overlay selection, working directory, ...).
/// Top-level command dispatch: routing argv to built-ins vs. manifest
/// entries, resolving the three command kinds (run / path / preset).
/// Hardware and compatibility diagnostics (`fdl diagnose`).
/// Cluster readiness probe (`fdl probe`): GPU + libtorch arch +
/// shared-data path + NCCL discovery. Pre-training gate; the
/// foundation for `fdl deploy` and the transparent launcher dispatch.
/// Live run status (`fdl status`): fetches the controller's
/// `state.json` (membership + lifecycle phase) and pretty-prints it.
/// Project scaffolding (`fdl init`): generates Dockerfile, `fdl.yml`,
/// training template, `.gitignore`.
/// Ecosystem-crate scaffolding (`fdl add <target>`): drops a
/// configured sub-project inside a flodl project for hands-on
/// discovery. Currently supports `flodl-hf`.
/// libtorch variant management (download, build, list, activate, remove,
/// info) used by both `fdl libtorch` and the standalone-manager flow.
/// NCCL source builds (`fdl nccl build`). Drops a standalone libnccl.so
/// into `libtorch/nccl/builds/<ver>-<archs>/` for the LD_PRELOAD bridge
/// pattern used by cross-host heterogeneous-arch clusters.
/// Environment overlay loader (`@env`, `--env`, `FDL_ENV`) with
/// per-field origin annotations for `fdl config show`.
/// Runtime: invoking resolved commands, streaming their output, and
/// mapping exit codes through `fdl`.
/// Pre-flight build for cluster commands. Builds the target binary
/// locally (in Docker on the controller) for each remote host's
/// libtorch ABI before fan-out, delivering it via the shared
/// project-root mount so the remote can exec it directly without a
/// cargo / rustc toolchain.
/// `fdl schema` sub-command: discover every cache under the project,
/// report fresh / stale / orphan states, and clear or refresh on
/// demand. The [`Schema`] type itself lives in [`config`].
/// `--fdl-schema` binary contract and per-command cache mechanics.
/// Caches live at `<cmd_dir>/.fdl/schema-cache/<cmd>.json` with
/// mtime + binary hash metadata for staleness detection.
/// First-run and reconfiguration wizard (`fdl setup`).
/// Daily update check against crates.io for `flodl-cli` and
/// project-pinned `flodl` / `flodl-hf`. Opt out via
/// `FDL_NO_UPDATE_CHECK=1` or the global config file.
/// AI-skill bundles: packaging and installing the `/port` skill and
/// similar assistant integrations.
/// ANSI styling primitives and the `--ansi` / `--no-ansi` / `NO_COLOR`
/// resolution chain used by the help renderer and CLI output.
/// Miscellaneous helpers shared by the other modules.
/// Print a red-prefixed `error: <formatted>` line to stderr.
///
/// Takes standard `format!` arguments. Coloring follows the `--ansi` /
/// `--no-ansi` / `NO_COLOR` / `FORCE_COLOR` chain via
/// [`style::color_enabled`], so pipes stay plain automatically.
// ── Public API for binary authors ──────────────────────────────────────
/// Parse argv into `T`, intercepting `--fdl-schema` and `--help`.
pub use parse_or_schema;
/// Slice-based variant of [`parse_or_schema`] — parses from an explicit
/// `&[String]` rather than `std::env::args()`. Used by the `fdl` driver to
/// dispatch per-sub-command arg tails.
pub use parse_or_schema_from;
/// Trait implemented by `#[derive(FdlArgs)]` structs. Binary authors do
/// not typically implement this manually — the derive emits it.
pub use FdlArgsTrait;
/// Derive macro for `FdlArgs`. Generates argv parsing, `--fdl-schema`
/// emission, and `--help` rendering from a single struct definition.
pub use FdlArgs;
/// Schema types — mirror the JSON shape emitted by `--fdl-schema` and
/// consumed by the fdl driver.
pub use ;
/// Re-exported dependencies the derive macro needs to reference by path.
/// Users should not depend on these directly — they are only stable as
/// an implementation detail of the derive.
pub use serde_json;