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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
//! Centralized path definitions for the CLI
//!
//! All hardcoded paths should be defined here to ensure consistency across the codebase.
#![allow(dead_code)]
/// Project configuration file
pub const PROJECT_CONFIG: &str = "mecha10.json";
/// Project directories
pub mod project {
/// Node source code directory
pub const NODES_DIR: &str = "nodes";
/// Framework node (`@mecha10` scope) schema directory, under the project's `nodes/`
/// directory. This is where a framework node's `<name>.schema.json` lives.
pub const NODES_MECHA10_DIR: &str = "nodes/@mecha10";
/// The framework node's schema *directory* (no `<name>.schema.json` suffix) under
/// `nodes/@mecha10/<node_name>`.
pub fn framework_node_schema_dir(node_name: &str) -> String {
format!("{}/{}", NODES_MECHA10_DIR, node_name)
}
/// Driver source code directory
pub const DRIVERS_DIR: &str = "drivers";
/// Types directory
pub const TYPES_DIR: &str = "types";
/// Behavior trees directory - nested under `configs/` (LAB-2072) so `mecha10 config
/// push`/`pull`/`list` genuinely sync it like any other config, instead of living as a
/// sibling top-level directory `collect_configs_from_dir` never walked.
pub const BEHAVIORS_DIR: &str = "configs/behaviors";
/// Models directory (ONNX models, etc.)
pub const MODELS_DIR: &str = "models";
/// Model catalog subdirectory, bind-mounted into the `ollama` Compose service as
/// `/root/.ollama/models` (see `docker-compose.yml.template`).
pub const MODELS_CATALOG_DIR: &str = "models/catalog";
/// Logs directory
pub const LOGS_DIR: &str = "logs";
/// Simulation directory - nested under `configs/` (moved from a top-level `simulation/`
/// sibling) so `mecha10 config push`/`pull` syncs it like any other config, the same reason
/// `BEHAVIORS_DIR` moved under `configs/` in LAB-2072.
pub const SIMULATION_DIR: &str = "configs/simulation";
/// Simulation models directory
pub const SIMULATION_MODELS_DIR: &str = "configs/simulation/models";
/// Simulation environments directory
pub const SIMULATION_ENVIRONMENTS_DIR: &str = "configs/simulation/environments";
/// Simulation billboard-image assets directory (`type: "image"` `environment.json`/
/// `task.json` objects' `source` fields point here) - flat, no per-environment nesting.
pub const SIMULATION_IMAGES_DIR: &str = "configs/simulation/images";
/// RL task-curriculum configs directory, scaffolded from the templates package's bundled
/// catalog at `mecha10 init` time. `mecha10-rl`'s `AssetResolver` resolves task configs
/// (e.g. `task1`) from here for training (`mecha10 train`).
pub const RL_TASKS_DIR: &str = "configs/rl/tasks";
/// Simulation output directory (generated robot/scene files)
pub const SIMULATION_OUTPUT_DIR: &str = "configs/simulation/output";
/// Cargo build target directory
pub const TARGET_DIR: &str = "target";
/// Source directory
pub const SRC_DIR: &str = "src";
/// Local (gitignored) project-scoped state directory - mirrors the `~/.mecha10`
/// user-home convention (`user::MECHA10_DIR`) but scoped to this project checkout.
pub const STATE_DIR: &str = ".mecha10";
/// Cache file for `mecha10 dev`'s project-level Python dependency preflight gate.
pub const DEV_PREFLIGHT_CACHE_FILE: &str = ".mecha10/dev-preflight-cache.json";
}
/// Configuration paths within project
pub mod config {
use super::project;
/// Base configs directory
pub const DIR: &str = "configs";
/// Node configs base directory
pub const NODES_DIR: &str = "configs/nodes";
/// Framework node configs (@mecha10 scope)
pub const NODES_MECHA10_DIR: &str = "configs/nodes/@mecha10";
/// Framework-tier (`@mecha10`) `config.json` path for `name` under `category_dir`.
fn framework_config(category_dir: &str, name: &str) -> String {
format!("{category_dir}/@mecha10/{name}/config.json")
}
/// Project-tier (plain name) `config.json` path for `name` under `category_dir`.
fn project_config(category_dir: &str, name: &str) -> String {
format!("{category_dir}/{name}/config.json")
}
/// The 2-tier `config.json` lookup candidates for `name` under `category_dir`, in canonical
/// resolution order: framework (`@mecha10`) -> project (plain name).
fn config_candidates(category_dir: &str, name: &str) -> [String; 2] {
[framework_config(category_dir, name), project_config(category_dir, name)]
}
/// Get config path for a framework node
pub fn framework_node(node_name: &str) -> String {
framework_config(NODES_DIR, node_name)
}
/// Get config path for a project node (plain name)
pub fn project_node(node_name: &str) -> String {
project_config(NODES_DIR, node_name)
}
/// Get the framework node's config *directory* (no `config.json` suffix) - the `@mecha10`
/// counterpart to [`framework_node`], for callers that need the directory itself (e.g. to
/// copy a whole config template tree into it) rather than the `config.json` file path.
pub fn framework_node_dir(node_name: &str) -> String {
format!("{}/{}", NODES_MECHA10_DIR, node_name)
}
/// The 2-tier `config.json` lookup candidates for a node, in canonical resolution order:
/// framework (`@mecha10`) -> project (plain name).
pub fn node_config_candidates(node_name: &str) -> [String; 2] {
config_candidates(NODES_DIR, node_name)
}
/// Get config path for a framework-default behavior (bundled into the project at scaffold
/// time under `configs/behaviors/@mecha10/<name>/config.json`).
pub fn framework_behavior(behavior_name: &str) -> String {
framework_config(project::BEHAVIORS_DIR, behavior_name)
}
/// The framework behavior's directory (no `config.json` suffix) - the `@mecha10`
/// counterpart to [`framework_behavior`].
pub fn framework_behavior_dir(behavior_name: &str) -> String {
format!("{}/@mecha10/{}", project::BEHAVIORS_DIR, behavior_name)
}
/// Get config path for a project behavior (plain name:
/// `configs/behaviors/<name>/config.json`).
pub fn project_behavior(behavior_name: &str) -> String {
project_config(project::BEHAVIORS_DIR, behavior_name)
}
/// The 2-tier `config.json` lookup candidates for a behavior, in override-precedence order
/// (highest first): project (plain name) -> framework (`@mecha10`).
pub fn behavior_config_candidates(behavior_name: &str) -> [String; 2] {
[project_behavior(behavior_name), framework_behavior(behavior_name)]
}
}
/// Docker-related paths within project
pub mod docker {
/// Docker directory
pub const DIR: &str = "docker";
/// Main docker-compose file
pub const COMPOSE_FILE: &str = "docker/docker-compose.yml";
/// Remote nodes docker-compose file
pub const COMPOSE_REMOTE_FILE: &str = "docker/docker-compose.remote.yml";
/// Remote nodes Dockerfile
pub const DOCKERFILE_REMOTE: &str = "docker/Dockerfile.remote";
/// Remote container entrypoint script (execs mecha10-launcher)
pub const ENTRYPOINT_REMOTE: &str = "docker/entrypoint.sh";
/// rl target docker-compose file - runs a trained RL policy in production
pub const COMPOSE_RL_FILE: &str = "docker/docker-compose.rl.yml";
/// rl target Dockerfile
pub const DOCKERFILE_RL: &str = "docker/Dockerfile.rl";
/// rl target container entrypoint script (execs mecha10-launcher --target rl) - a distinct
/// filename from `ENTRYPOINT_REMOTE` since both `docker/entrypoint.sh` and this file coexist
/// in the same project (remote and rl are independent, both-scaffolded targets).
pub const ENTRYPOINT_RL: &str = "docker/entrypoint-rl.sh";
}
/// Environment files
pub mod env {
/// Environment example file
pub const EXAMPLE: &str = ".env.example";
/// Environment file
pub const FILE: &str = ".env";
}
/// Meta files (README, gitignore, etc.)
pub mod meta {
/// README file
pub const README: &str = "README.md";
/// Git ignore file
pub const GITIGNORE: &str = ".gitignore";
/// Package.json for Node.js tooling
pub const PACKAGE_JSON: &str = "package.json";
/// Python requirements
pub const REQUIREMENTS_TXT: &str = "requirements.txt";
/// Pinned Python version for `mecha10 setup` to target (see
/// `find_python_executable` in `packages/cli/src/handlers/setup.rs`).
pub const PYTHON_VERSION: &str = ".python-version";
}
/// Rust project files
pub mod rust {
/// Cargo workspace manifest
pub const CARGO_TOML: &str = "Cargo.toml";
/// Cargo lock file
pub const CARGO_LOCK: &str = "Cargo.lock";
/// Main entry point
pub const MAIN_RS: &str = "src/main.rs";
/// Library entry point
pub const LIB_RS: &str = "src/lib.rs";
/// Build script
pub const BUILD_RS: &str = "build.rs";
/// Rustfmt config
pub const RUSTFMT_TOML: &str = "rustfmt.toml";
}
/// Model files within a model directory
pub mod model {
/// ONNX model file
pub const ONNX_FILE: &str = "model.onnx";
/// Labels file
pub const LABELS_FILE: &str = "labels.txt";
/// Model config file
pub const CONFIG_FILE: &str = "config.json";
}
/// User-level paths in home directory
pub mod user {
use std::path::PathBuf;
/// Base mecha10 directory in user home.
///
/// Re-exports `mecha10_core::fs_utils::MECHA10_DIR`, shared with `launcher-service`.
pub const MECHA10_DIR: &str = mecha10_core::fs_utils::MECHA10_DIR;
/// Credentials file, relative to the user home directory.
///
/// Documentation-only - `credentials_file()` below is the actual source of truth.
pub const CREDENTIALS_FILE: &str = ".mecha10/credentials.json";
/// Templates cache directory
pub const TEMPLATES_DIR: &str = ".mecha10/templates";
/// Binary installation directory
pub const BIN_DIR: &str = ".mecha10/bin";
/// Get the base mecha10 directory path
pub fn mecha10_dir() -> PathBuf {
dirs::home_dir().unwrap_or_else(|| PathBuf::from(".")).join(MECHA10_DIR)
}
/// Get the credentials file path.
///
/// Delegates to `mecha10-auth`'s `credentials::default_credentials_path()`.
pub fn credentials_file() -> PathBuf {
mecha10_auth::default_credentials_path()
}
/// Get the templates cache directory
pub fn templates_dir() -> PathBuf {
mecha10_dir().join("templates")
}
/// Get the binary directory
pub fn bin_dir() -> PathBuf {
mecha10_dir().join("bin")
}
/// Get path to a binary in the mecha10 bin directory
pub fn bin(name: &str) -> PathBuf {
bin_dir().join(name)
}
/// Get path to a binary in cargo bin directory
pub fn cargo_bin(name: &str) -> PathBuf {
home_bin_dir(".cargo", name)
}
/// Get path to a binary in local bin directory
pub fn local_bin(name: &str) -> PathBuf {
home_bin_dir(".local", name)
}
/// Get path to a binary in a `bin` subdirectory of the given home-relative directory
/// (e.g. `~/.cargo/bin/{name}`, `~/.local/bin/{name}`).
fn home_bin_dir(home_subdir: &str, name: &str) -> PathBuf {
mecha10_core::fs_utils::home_subpath(&[home_subdir, "bin", name])
}
}
/// Paths used inside Docker containers
pub mod container {
/// Project mount point in container
pub const PROJECT_ROOT: &str = "/project";
/// Framework mount point in container
pub const FRAMEWORK_ROOT: &str = "/mecha10";
/// App directory (for mecha10-remote)
pub const APP_ROOT: &str = "/app";
/// Config file in mecha10-remote container
pub const REMOTE_CONFIG: &str = "/app/mecha10.json";
/// Get project-relative path inside container
pub fn project_path(relative: &str) -> String {
format!("{}/{}", PROJECT_ROOT, relative)
}
/// Get framework-relative path inside container
pub fn framework_path(relative: &str) -> String {
format!("{}/{}", FRAMEWORK_ROOT, relative)
}
}
/// Paths within the mecha10 framework source
pub mod framework {
/// Packages directory
pub const PACKAGES_DIR: &str = "packages";
/// Nodes package directory
pub const NODES_DIR: &str = "packages/nodes";
/// Drivers package directory
pub const DRIVERS_DIR: &str = "packages/drivers";
/// Marker directory used to detect the mecha10 framework root
pub const ROOT_MARKER_DIR: &str = "packages/core";
/// Release binary
pub const RELEASE_BINARY: &str = "target/release/mecha10";
/// Debug binary
pub const DEBUG_BINARY: &str = "target/debug/mecha10";
/// Get node config path within framework
pub fn node_config(node_name: &str) -> String {
format!("packages/nodes/{}/configs/config.json", node_name)
}
}
/// External service URLs
pub mod urls {
/// Default base URL for the public `mecha10-api` service. All framework/runtime artifact
/// downloads are proxied through its `/api/downloads/*` routes.
pub const MECHA10_API_URL: &str = "https://mecha.industries/api";
/// Build the `mecha10-api` base URL (e.g. `https://mecha.industries/api`).
///
/// Override at runtime with the `MECHA10_API_URL` env var.
pub fn mecha10_api_base_url() -> String {
std::env::var("MECHA10_API_URL")
.unwrap_or_else(|_| MECHA10_API_URL.to_string())
.trim_end_matches('/')
.to_string()
}
/// Join `path` onto [`mecha10_api_base_url`]. `path` must not start with a leading
/// `/api` of its own, or the request doubles up to `.../api/api/...` and 404s.
pub fn mecha10_api_path(path: &str) -> String {
format!("{}/{}", mecha10_api_base_url(), path.trim_start_matches('/'))
}
/// Default authentication URL
pub const AUTH_URL: &str = "https://mecha.industries/api/auth";
}
/// Build a target output path
pub fn target_path(profile: &str, binary: &str) -> String {
format!("target/{}/{}", profile, binary)
}
/// Build a target output path with optional target triple
pub fn target_path_with_triple(target: Option<&str>, profile: &str) -> String {
match target {
Some(t) => format!("target/{}/{}", t, profile),
None => format!("target/{}", profile),
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn credentials_file_matches_mecha10_auth_source_of_truth() {
assert_eq!(user::credentials_file(), mecha10_auth::default_credentials_path());
}
/// `cargo_bin`/`local_bin` share a `home_bin_dir` helper that only differs on which
/// home-relative directory it joins.
#[test]
fn cargo_bin_and_local_bin_join_name_under_their_own_home_subdir() {
let home = dirs::home_dir().expect("home dir must resolve in test environment");
assert_eq!(
user::cargo_bin("mecha10"),
home.join(".cargo").join("bin").join("mecha10")
);
assert_eq!(
user::local_bin("mecha10"),
home.join(".local").join("bin").join("mecha10")
);
}
#[test]
fn simulation_project_dirs_share_the_simulation_root() {
assert_eq!(project::SIMULATION_MODELS_DIR, "configs/simulation/models");
assert_eq!(project::SIMULATION_ENVIRONMENTS_DIR, "configs/simulation/environments");
for dir in [project::SIMULATION_MODELS_DIR, project::SIMULATION_ENVIRONMENTS_DIR] {
assert!(dir.starts_with(&format!("{}/", project::SIMULATION_DIR)));
}
}
/// Task-curriculum configs live under `configs/rl/`, NOT `SIMULATION_DIR` - they're a
/// project's RL configuration, not a physics/rendering asset.
#[test]
fn rl_tasks_dir_lives_under_configs_rl_not_simulation() {
assert_eq!(project::RL_TASKS_DIR, "configs/rl/tasks");
assert!(!project::RL_TASKS_DIR.starts_with(&format!("{}/", project::SIMULATION_DIR)));
}
#[test]
fn test_config_paths() {
assert_eq!(
config::framework_node("object-detector"),
"configs/nodes/@mecha10/object-detector/config.json"
);
assert_eq!(config::project_node("camera"), "configs/nodes/camera/config.json");
}
#[test]
fn test_framework_node_dir() {
assert_eq!(config::framework_node_dir("speaker"), "configs/nodes/@mecha10/speaker");
}
#[test]
fn test_framework_node_schema_dir_lives_under_nodes_not_configs_nodes() {
assert_eq!(project::framework_node_schema_dir("speaker"), "nodes/@mecha10/speaker");
assert_ne!(
project::framework_node_schema_dir("speaker"),
config::framework_node_dir("speaker"),
"schema dir (wave 10) must not collide with the config.json dir"
);
}
#[test]
fn test_node_config_candidates_order() {
assert_eq!(
config::node_config_candidates("teleop"),
[
"configs/nodes/@mecha10/teleop/config.json".to_string(),
"configs/nodes/teleop/config.json".to_string(),
]
);
}
#[test]
fn test_behavior_config_paths() {
assert_eq!(
config::framework_behavior("idle_wander"),
"configs/behaviors/@mecha10/idle_wander/config.json"
);
assert_eq!(
config::project_behavior("idle_wander"),
"configs/behaviors/idle_wander/config.json"
);
}
#[test]
fn test_framework_behavior_dir() {
assert_eq!(
config::framework_behavior_dir("idle-wander"),
"configs/behaviors/@mecha10/idle-wander"
);
assert_eq!(
config::framework_behavior("idle-wander"),
format!("{}/config.json", config::framework_behavior_dir("idle-wander"))
);
}
#[test]
fn test_behavior_config_candidates_order() {
assert_eq!(
config::behavior_config_candidates("idle_wander"),
[
"configs/behaviors/idle_wander/config.json".to_string(),
"configs/behaviors/@mecha10/idle_wander/config.json".to_string(),
]
);
}
#[test]
fn test_target_path() {
assert_eq!(target_path("release", "my-node"), "target/release/my-node");
assert_eq!(
target_path_with_triple(Some("aarch64-unknown-linux-gnu"), "release"),
"target/aarch64-unknown-linux-gnu/release"
);
assert_eq!(target_path_with_triple(None, "debug"), "target/debug");
}
#[test]
fn test_container_paths() {
assert_eq!(
container::project_path("configs/test.json"),
"/project/configs/test.json"
);
assert_eq!(container::framework_path("packages/core"), "/mecha10/packages/core");
}
#[test]
fn test_mecha10_api_base_url_default() {
let _guard = ENV_MUTEX.lock().unwrap();
std::env::remove_var("MECHA10_API_URL");
assert_eq!(urls::mecha10_api_base_url(), "https://mecha.industries/api");
}
#[test]
fn test_mecha10_api_base_url_env_override() {
let _guard = ENV_MUTEX.lock().unwrap();
std::env::set_var("MECHA10_API_URL", "http://localhost:4000/api/");
assert_eq!(urls::mecha10_api_base_url(), "http://localhost:4000/api");
std::env::remove_var("MECHA10_API_URL");
}
#[test]
fn test_mecha10_api_path_does_not_double_the_api_segment() {
let _guard = ENV_MUTEX.lock().unwrap();
std::env::remove_var("MECHA10_API_URL");
assert_eq!(
urls::mecha10_api_path("/models/catalog"),
"https://mecha.industries/api/models/catalog"
);
}
#[test]
fn test_mecha10_api_path_works_without_a_leading_slash() {
let _guard = ENV_MUTEX.lock().unwrap();
std::env::remove_var("MECHA10_API_URL");
assert_eq!(
urls::mecha10_api_path("downloads/model/deepghs/yolos/yolov8n/model.onnx"),
"https://mecha.industries/api/downloads/model/deepghs/yolos/yolov8n/model.onnx"
);
}
/// Serializes tests that mutate process-wide env vars, since `cargo test` runs
/// tests in this module concurrently by default.
static ENV_MUTEX: std::sync::Mutex<()> = std::sync::Mutex::new(());
}