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: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "openresearch-cli"
version = "0.1.62"
version = "0.1.63"
edition = "2021"
description = "OpenResearch CLI (orx) — Rust port"
repository = "https://github.com/alphaXiv/openresearch-cli"
Expand Down
190 changes: 15 additions & 175 deletions src/commands/create_experiment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@
//! (`orx create-project` or the web), not here — so there is no `--repo` flag.
//! The baseline is materialized on whatever repo the project is already bound to.

use crate::client::{
create_baseline_experiment, create_child_experiment, CreateBaselineExperimentBody,
CreateChildBody, Experiment,
};
use crate::error::{anyhow, require_credentials, Result};
use crate::local::resolve::{resolve_project, ProjectRef};
use crate::error::Result;
use crate::plane::{resolve_project, CreateExperimentSpec};
use crate::store::Store;

const USAGE: &str = "Usage: orx create-experiment <projectId> --title \"<title>\" [--parent <experimentId>] [--description \"<text>\"] [--run-command \"<cmd>\"]";
Expand All @@ -33,177 +29,21 @@ pub async fn run(mut args: crate::CreateExperimentArgs) -> Result<()> {
}
};

// Local project (orx up): create the row + branch locally, no api.
// Local project (orx up): create the row + branch locally, no api — the
// plane resolver decides which side owns the id.
let store = Store::open()?;
match resolve_project(&store, &args.project_id)? {
ProjectRef::Local(project) => {
run_local(
&store,
&project,
title,
args.parent,
args.baseline,
args.description,
args.run_command,
)?;
// Key event, fired only on success. Coarse props only — no ids/names.
crate::telemetry::capture_experiment_started("create", true, None);
Ok(())
}
ProjectRef::Server(_) => run_server(args, title).await,
}
}

/// Server-mode create via the api.
async fn run_server(args: crate::CreateExperimentArgs, title: String) -> Result<()> {
// The server child-create API carries no run command field — refuse rather
// than silently drop it. (The baseline create below does accept one.)
if args.run_command.is_some() && args.parent.is_some() {
return Err(anyhow!(
"--run-command is supported for local projects and server baselines \
only. For server child experiments, set it after creation with \
`orx exp cmd <expId> --set '<cmd>'`."
));
}

let creds = require_credentials().await;
let description = args.description;

let experiment: Experiment;
let kind: String;
if let Some(parent) = args.parent {
let envelope = create_child_experiment(
&creds,
&args.project_id,
&CreateChildBody {
title,
description,
parent_experiment_id: parent,
},
)
.await?;
experiment = envelope.experiment;
kind = "child".to_string();
} else {
// Baseline on the project's already-bound GitHub repo. The server
// branches `orx/<slug>` off the branch picked at project creation
// (the repo's default unless one was chosen).
let envelope = create_baseline_experiment(
&creds,
&args.project_id,
&CreateBaselineExperimentBody {
title: Some(title),
description,
run_command: args.run_command,
},
)
let plane = resolve_project(store, &args.project_id)?;
let is_local = plane.is_local();
plane
.create_experiment(CreateExperimentSpec {
title,
parent: args.parent,
baseline: args.baseline,
description: args.description,
run_command: args.run_command,
})
.await?;
experiment = envelope.experiment;
kind = "baseline".to_string();
}

println!("\u{2713} Created {} experiment", kind);
println!(" id: {}", experiment.id);
println!(" title: {}", experiment.title);
println!(" slug: {}", experiment.slug);
println!(" branch: {}", experiment.branch_name);
println!();
println!("To edit it, check out the branch in your local clone of the project's repo:");
println!(
" git fetch origin && git checkout {}",
experiment.branch_name
);
println!(" # …edit, then…");
println!(
" git commit -am \"<msg>\" && git push -u origin {}",
experiment.branch_name
);
// Key event, fired only on success. Coarse props only — no ids/names.
crate::telemetry::capture_experiment_started("create", false, None);
Ok(())
}

/// Local-mode create: every node gets a branch `orx/<slug>` pushed to origin
/// so jobs can clone it — children fork off the parent's tip, baselines off
/// the project's base branch (which itself is never an experiment node). No
/// parent = child of the project's oldest root when one exists; on an empty
/// project (or with `--baseline`) the new row becomes a baseline root.
/// Projects may hold multiple baselines.
fn run_local(
store: &Store,
project: &crate::local::model::LocalProject,
title: String,
parent: Option<String>,
baseline: bool,
description: Option<String>,
run_command: Option<String>,
) -> Result<()> {
let mut defaulted_to_root = false;
let parent_exp = match &parent {
Some(parent_id) => Some(store.get_local_experiment(parent_id)?.ok_or_else(|| {
anyhow!(
"Parent experiment {} not found in the local store. \
See the dashboard, or omit --parent to branch off the project root.",
parent_id
)
})?),
None if baseline => None,
None => {
let root = crate::local::experiments::project_root(store, &project.id)?;
defaulted_to_root = root.is_some();
root
}
};
let kind = if parent_exp.is_some() {
"child"
} else {
"baseline"
};

let experiment = crate::local::experiments::create_experiment(
store,
project,
parent_exp.as_ref(),
None,
Some(title),
description,
run_command,
)?;

println!("\u{2713} Created local {} experiment", kind);
if defaulted_to_root {
let root = parent_exp.as_ref().unwrap();
println!(" parent: {} (project root, defaulted)", root.id);
}
if let Some(warning) = parent_exp
.as_ref()
.and_then(|p| crate::local::experiments::legacy_root_warning(project, p))
{
eprintln!(" {warning}");
}
println!(" id: {}", experiment.id);
println!(" title: {}", experiment.display_name());
println!(" slug: {}", experiment.slug);
println!(" branch: {}", experiment.branch_name);
if experiment.run_command.is_empty() {
println!(
" command: — (none inherited — set one with `orx project edit {} --run-command '<cmd>'`)",
project.id
);
} else {
println!(" command: {}", experiment.run_command);
}
println!();
println!("To edit it, check out the branch in the project's local clone:");
println!(" cd {}", project.repo_path);
println!(
" git fetch origin && git checkout {}",
experiment.branch_name
);
println!(" # …edit, then…");
println!(
" git commit -am \"<msg>\" && git push -u origin {}",
experiment.branch_name
);
crate::telemetry::capture_experiment_started("create", is_local, None);
Ok(())
}
Loading
Loading