Repository navigation
Expand file tree
/
Copy pathmain.rs
More file actions
1662 lines (1518 loc) · 59.4 KB
/
Copy pathmain.rs
File metadata and controls
1662 lines (1518 loc) · 59.4 KB
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//! OpenResearch CLI (`orx`) — Rust port entry point.
//!
//! A clap-derive command tree mirroring the USAGE
//! block, dispatched from an async `tokio::main`. Each subcommand routes to one
//! module fn in `commands::<name>`. The six fs verbs (read/write/str-replace/
//! ls/grep/rm) all route into `commands::fs`.
//!
//! Error handling: command fns return `anyhow::Result<()>`. `main` prints the
//! error's `Display` to stderr and exits 1 — matching the TS
//! `main().catch(err => { console.error(err.message); process.exit(1) })`.
mod alphaxiv;
mod browser;
mod editors;
// DTOs faithfully mirror every API wire field; not all are read by the CLI yet.
#[allow(dead_code)]
mod client;
mod commands;
mod compute;
mod config;
mod engine;
mod error;
mod folder_picker;
mod invocation;
mod jobs;
// Local mode (`orx up`): builds out across stages; not all of it is wired yet.
#[allow(dead_code)]
mod local;
mod net;
mod output;
mod paths;
mod plane;
mod process;
mod remote;
mod store;
mod telemetry;
mod updates;
mod workspace_state;
use clap::{Args, Parser, Subcommand, ValueEnum};
#[derive(Parser, Debug)]
#[command(
name = "orx",
about = "OpenResearch CLI",
version,
disable_help_subcommand = true
)]
struct Cli {
// Optional so a bare `orx` prints USAGE to stdout and exits 0 (like the TS
// `if (!command) { console.log(USAGE); return; }`) instead of clap's exit-2.
#[command(subcommand)]
command: Option<Command>,
/// Disable anonymous usage analytics for this run. To disable it
/// persistently, run `orx telemetry off`.
#[arg(long, global = true)]
no_telemetry: bool,
}
#[derive(Subcommand, Debug)]
// NOTE: `local::harness::plan_gate` keeps a hand-maintained allowlist of the
// read-only verbs here (what Claude plan mode may run without approval). When
// you add a *read-only* subcommand, add it there too, or it stays gated in plan
// mode. `readonly_verbs_are_real_commands` catches renames but not additions.
enum Command {
/// Log in via the browser and store a token.
Login(LoginArgs),
/// Remove the stored token.
Logout,
/// Read your alphaXiv library.
Alphaxiv(AlphaXivArgs),
/// List projects registered in the local orx store.
Projects(ProjectsArgs),
/// List organizations available for OpenResearch compute.
Orgs(OrgsArgs),
/// Operate on one local project.
Project(ProjectArgs),
/// List a project's runs.
Runs(RunsArgs),
/// Show a run's compact log summary (path, size, and preview) by default.
Logs(LogsArgs),
/// Print the command that opens a run's TensorBoard logs.
Tensorboard(TensorboardArgs),
/// Summarize the metrics runs logged to Trackio: local, a Hugging Face Space, or a server.
Metrics(MetricsArgs),
/// Add an experiment node to a local `orx up` project.
#[command(name = "create-experiment")]
CreateExperiment(CreateExperimentArgs),
/// Configure compute backends, test connections, and browse offers.
Compute(ComputeArgs),
/// Spin up standalone compute in an organization (no experiment).
Instance(InstanceArgs),
/// Register this computer's SSH key so the boxes you provision accept it.
#[command(name = "ssh-key")]
SshKey(SshKeyArgs),
/// Operate on one local experiment node.
Exp(ExpArgs),
/// Print CLI usage for agents, or fetch a skill doc.
Skill(SkillArgs),
/// Add reusable skills to the local OpenResearch library.
Skills(LibraryArgs),
/// Add reusable LaTeX templates to the local OpenResearch library.
Templates(LibraryArgs),
/// Install the OpenResearch skill into local coding agents (Claude Code, Codex, OpenCode, Cursor, Antigravity).
#[command(name = "install-skills")]
InstallSkills(InstallSkillsArgs),
/// Call one paper-retrieval primitive; the caller owns the search loop.
Discover(DiscoverArgs),
/// Fetch a paper: alphaXiv report/full-text, or OpenAlex/bioRxiv/PubMed metadata.
/// The source is auto-detected from the id (override with `--source`).
Paper(PaperArgs),
/// Show the CLI version; `--check` compares it to the latest release.
Version(VersionArgs),
/// Update orx to the latest release (installer-script installs only).
Update(UpdateArgs),
/// Link the macOS app's `orx` onto your PATH (macOS app installs only).
InstallCli(InstallCliArgs),
/// Permanently delete the local database, CLI executable, or both.
Delete(DeleteArgs),
/// Loopback HTTP/SSE daemon over the local run store (jobs sibling of
/// `opencode serve`); the api tunnels to it on agent boxes.
Serve(ServeArgs),
/// Supervise one local run: tail backend logs, persist status, and honor
/// local cancel intent. Spawned detached by `exp run`.
Supervise(SuperviseArgs),
#[command(hide = true)]
RentalSupervise { config: std::path::PathBuf },
/// Start the local autoresearch dashboard on 127.0.0.1: embedded UI,
/// JSON/SSE API over the local store, and the opencode agent proxy.
Up(UpArgs),
/// Turn anonymous usage analytics on or off, or show current status.
Telemetry(TelemetryArgs),
/// Report a bug, feature request, or frustration with OpenResearch itself
/// to its maintainers. Filed by the agent; see the `orx-feedback` skill.
Feedback(FeedbackArgs),
/// Internal: the Claude plan-mode `PreToolUse` hook body. Reads the hook
/// payload on stdin and prints an allow decision for read-only `orx`
/// inspection; not a user command.
#[command(name = "plan-gate", hide = true)]
PlanGate,
#[command(name = "invocation-gate", hide = true)]
InvocationGate,
/// Internal: orx's stdio MCP server, which every agent harness spawns:
/// Claude's permission bridge and the orchestration tools, relayed to the
/// running `orx up`. `mcp-gate`, its old name, stays for configs an older
/// `orx up` still writes. Not a user command.
#[command(name = "mcp", alias = "mcp-gate", hide = true)]
Mcp,
#[command(name = "alphaxiv-mcp", hide = true)]
AlphaxivMcp,
#[command(name = "antigravity-gate", hide = true)]
AntigravityGate,
/// Internal: detached worker for optional local-project publication.
#[command(name = "publish-branch", hide = true)]
PublishBranch(PublishBranchArgs),
/// Internal: manage a persistent SSH remote host.
#[command(name = "remote-host", hide = true)]
RemoteHost(RemoteHostArgs),
}
#[derive(Args, Debug)]
struct PublishBranchArgs {
repo_path: std::path::PathBuf,
branch: String,
owner: String,
repo: String,
}
#[derive(Args, Debug)]
pub struct LoginArgs {
/// Override the API base URL (or set OPENRESEARCH_API_URL).
#[arg(long = "api-url")]
pub api_url: Option<String>,
/// The app's sign-in: skips the agent-skills offer.
#[arg(long, hide = true)]
pub non_interactive: bool,
/// Connect alphaXiv to an existing OpenResearch sign-in.
#[arg(long)]
pub alphaxiv: bool,
}
#[derive(Args, Debug)]
pub struct AlphaXivArgs {
#[command(subcommand)]
command: AlphaXivCommand,
}
#[derive(Subcommand, Debug)]
enum AlphaXivCommand {
/// List folders and papers.
Library {
#[arg(long)]
json: bool,
},
}
#[derive(Args, Debug)]
pub struct ProjectsArgs {
/// Emit local project records as JSON.
#[arg(long)]
pub json: bool,
}
#[derive(Args, Debug)]
pub struct OrgsArgs {
/// Emit organization records as JSON.
#[arg(long)]
pub json: bool,
}
#[derive(Args, Debug)]
pub struct ProjectArgs {
#[command(subcommand)]
pub command: ProjectCommand,
}
#[derive(Subcommand, Debug)]
pub enum ProjectCommand {
/// Show a local project's details and experiment tree.
View {
project_id: String,
/// Include archived experiments in the listing.
#[arg(long)]
all: bool,
},
/// Edit a local project's name or run command.
Edit {
project_id: String,
/// Rename the project.
#[arg(long)]
name: Option<String>,
/// Set the project's default run command.
/// New experiments inherit it; pass '' to clear.
#[arg(long = "run-command")]
run_command: Option<String>,
},
/// Save a project as a .orx file a collaborator can open in OpenResearch,
/// or publish it as an openresearch.sh link with --publish.
/// Every chat is included unless narrowed with --chat or left out with --no-chats.
Share {
project_id: String,
/// File to write (default: ./<project>.orx).
#[arg(long, conflicts_with = "publish")]
out: Option<String>,
/// Upload the file to openresearch.sh and print a link anyone can open
/// (needs `orx login`). Publishing again updates the same link.
#[arg(long)]
publish: bool,
/// Include only this chat's transcript (repeatable).
#[arg(long = "chat")]
chats: Vec<String>,
/// Leave every chat out.
#[arg(long, conflicts_with = "chats")]
no_chats: bool,
/// Leave run logs out.
#[arg(long)]
no_logs: bool,
/// Leave the artifacts folder out.
#[arg(long)]
no_artifacts: bool,
},
/// Delete a project's published openresearch.sh link and its file.
Unpublish { project_id: String },
/// Open a shared .orx file, or an openresearch.sh/p/... link, as a new project.
Import {
file: String,
/// Folder to create the project in (default: ./<file or project name>).
#[arg(long)]
path: Option<String>,
},
}
#[derive(Args, Debug)]
pub struct RunsArgs {
pub project_id: String,
/// Filter to one experiment.
#[arg(long)]
pub experiment: Option<String>,
}
#[derive(Args, Debug)]
pub struct LogsArgs {
pub run_id: String,
#[arg(short, long, hide = true)]
pub follow: bool,
}
#[derive(Args, Debug)]
pub struct TensorboardArgs {
pub run_id: String,
}
#[derive(Args, Debug)]
pub struct MetricsArgs {
/// One or more run ids; several print one after another for comparison.
#[arg(required = true)]
pub run_ids: Vec<String>,
/// Only metrics whose name contains this text (case-insensitive). Repeatable.
#[arg(long = "metric")]
pub metrics: Vec<String>,
/// Sampled points per metric, first and last included.
#[arg(long, default_value_t = 20)]
pub points: usize,
/// Print JSON instead of the text summary.
#[arg(long)]
pub json: bool,
}
#[derive(Args, Debug)]
pub struct CreateExperimentArgs {
/// Local project id from `orx projects`.
pub project_id: String,
/// Experiment title (required).
#[arg(long)]
pub title: Option<String>,
/// Experiment description.
#[arg(long)]
pub description: Option<String>,
/// Parent experiment id -> create a child. Omit on an empty project to
/// create the baseline (root); once a root exists, attach under it.
#[arg(long)]
pub parent: Option<String>,
/// Create a new baseline (root) even when the project already has one.
/// Conflicts with --parent. Projects may hold multiple baselines.
#[arg(long, conflicts_with = "parent")]
pub baseline: bool,
/// Run command for the node. Omit to inherit from the parent/project default.
#[arg(long = "run-command")]
pub run_command: Option<String>,
}
#[derive(Args, Debug)]
pub struct ComputeArgs {
#[command(subcommand)]
pub command: Option<commands::compute::ComputeCommand>,
/// Machine-readable output.
#[arg(long, global = true)]
pub json: bool,
#[command(flatten)]
pub catalog: commands::compute::CatalogArgs,
}
#[derive(Args, Debug)]
pub struct SshKeyArgs {
#[command(subcommand)]
pub command: SshKeyCommand,
}
#[derive(Subcommand, Debug)]
pub enum SshKeyCommand {
/// Register a public key on your account. Every box in your orgs — including
/// ones already running — starts accepting it.
Add(SshKeyAddArgs),
/// List registered keys, marking the ones usable from this computer.
List,
}
#[derive(Args, Debug)]
pub struct SshKeyAddArgs {
/// Public key path. Without a path, reuse ~/.ssh/id_ed25519.pub or create a key pair.
pub path: Option<String>,
}
#[derive(Args, Debug)]
pub struct InstanceArgs {
#[command(subcommand)]
pub command: InstanceCommand,
}
#[derive(Subcommand, Debug)]
pub enum InstanceCommand {
/// Provision a standalone instance in an org (GPU with `--gpu`, or CPU with
/// `--cpu`). Not tied to an experiment — like the dashboard's "Spin up".
Create(InstanceCreateArgs),
/// List an org's instances (status, SSH endpoint, price) — including any
/// `--backend openresearch` box a failed teardown left behind.
List(InstanceListArgs),
/// Terminate an instance (destroys the provider machine). The manual
/// cleanup path when a run's automatic teardown failed.
Delete(InstanceDeleteArgs),
}
#[derive(Args, Debug)]
pub struct InstanceCreateArgs {
/// Organization id (from `orx orgs`).
pub org_id: String,
/// Provision a GPU instance with this GPU id, e.g. `H100_SXM` — the exact id
/// from `orx compute`, not a family name like `H100`.
#[arg(long)]
pub gpu: Option<String>,
/// GPUs per instance (with `--gpu`; default 1).
#[arg(long)]
pub count: Option<i64>,
/// Disk in GB (with `--gpu`; default 100).
#[arg(long)]
pub disk: Option<i64>,
/// Provider to provision from (with `--gpu`), e.g. runpod, vast, lambda.
/// Omit to pick the cheapest matching offer across providers (like the
/// dashboard). See `orx compute` for providers; validated server-side.
#[arg(long)]
pub provider: Option<String>,
/// Provision a CPU-only instance with this flavor: cpu5c (compute), cpu5g
/// (general), or cpu5m (memory-optimized). Mutually exclusive with `--gpu`.
#[arg(long)]
pub cpu: Option<String>,
/// vCPUs for a CPU instance (with `--cpu`): 2, 8, or 32 (default 8).
#[arg(long)]
pub vcpus: Option<i64>,
}
#[derive(Args, Debug)]
pub struct InstanceListArgs {
/// Organization id (from `orx orgs`).
pub org_id: String,
}
#[derive(Args, Debug)]
pub struct InstanceDeleteArgs {
/// The instance (sandbox) id to terminate.
pub sandbox_id: String,
}
#[derive(Args, Debug)]
pub struct ExpArgs {
#[command(subcommand)]
pub command: ExpCommand,
}
#[derive(Subcommand, Debug)]
pub enum ExpCommand {
/// Hide ancestors, the selected experiment, or descendants.
/// A later no-parent create starts a new baseline if all roots are archived.
#[command(group(clap::ArgGroup::new("archive_scope").required(true)))]
Archive {
exp_id: String,
/// Archive ancestors, excluding the selected experiment.
#[arg(long, group = "archive_scope")]
ancestors: bool,
/// Archive only the selected experiment.
#[arg(long, group = "archive_scope")]
only: bool,
/// Archive descendants, excluding the selected experiment.
#[arg(long, group = "archive_scope")]
descendants: bool,
},
/// Restore archived experiments using the same scopes.
#[command(group(clap::ArgGroup::new("unarchive_scope").required(true)))]
Unarchive {
exp_id: String,
/// Restore ancestors, excluding the selected experiment.
#[arg(long, group = "unarchive_scope")]
ancestors: bool,
/// Restore only the selected experiment.
#[arg(long, group = "unarchive_scope")]
only: bool,
/// Restore descendants, excluding the selected experiment.
#[arg(long, group = "unarchive_scope")]
descendants: bool,
},
/// Permanently delete an experiment with no child experiments or active runs, its runs, and
/// its orx/ branch (refused while any worktree has it checked out).
Delete { exp_id: String },
/// Re-parent an experiment and its subtree. Only the tree changes; git branches stay put.
#[command(group(clap::ArgGroup::new("move_target").required(true)))]
Move {
exp_id: String,
/// New parent experiment in the same project.
#[arg(long, group = "move_target")]
parent: Option<String>,
/// Make the experiment a new root (baseline).
#[arg(long, group = "move_target")]
baseline: bool,
},
/// Show the experiment's status, run command, and latest run.
Status {
exp_id: String,
/// Query live Slurm accounting in addition to locally stored status.
#[arg(long)]
scheduler: bool,
},
/// View the experiment's description/notes, or overwrite it with `--set` / `--stdin`.
Desc {
exp_id: String,
/// Overwrite the description with this value.
#[arg(long)]
set: Option<String>,
/// Overwrite the description with the whole of stdin (for long markdown docs).
#[arg(long)]
stdin: bool,
},
/// Launch a locally initialized experiment through the run engine.
Run(Box<ExpRunArgs>),
/// Cancel in-flight runs in an experiment, or one run with --run.
Cancel {
#[arg(required_unless_present = "run")]
exp_id: Option<String>,
/// Cancel only this run. With an experiment id, the run must belong to it.
#[arg(long)]
run: Option<String>,
},
/// Abandon a run whose outcome cannot be recovered; keep its cancel pending.
Abandon { run: String },
/// Send this chat the result of the experiment's latest run when it finishes.
Wake { exp_id: String },
/// Wait for a run to finish: one experiment (`<expId>`) or the next completion in a project (`--project`).
Wait {
/// Experiment to watch until its latest run reaches a terminal state.
/// Omit and pass `--project` to watch a whole project.
exp_id: Option<String>,
/// Watch every run in this project and return on the FIRST one to
/// complete (reach done/failed/cancelled) — a "slot freed" signal. Call
/// it in a loop, re-listing `orx runs` on each return to catch all
/// finished runs. Returns immediately ("drained: no runs in flight") if
/// none are in flight. Mutually exclusive with `<expId>`.
#[arg(long)]
project: Option<String>,
/// Give up and exit non-zero after this many seconds (default 1800).
#[arg(long)]
timeout: Option<u64>,
/// Seconds between retries while the local database is busy (default 5).
#[arg(long, hide = true)]
interval: Option<u64>,
},
}
#[derive(Args, Debug, serde::Serialize, serde::Deserialize)]
pub struct ExpRunArgs {
pub exp_id: String,
/// Disk in GB for a `--backend openresearch` instance (default 100).
#[arg(long)]
pub disk: Option<i64>,
/// Provider for a `--backend openresearch` GPU flavor. When omitted, the
/// cheapest qualified offer is selected.
#[arg(long)]
pub provider: Option<String>,
/// orx-supervised executor: `hf` (Hugging Face Jobs,
/// billed to your HF account), `modal` (a Modal Sandbox on your own Modal
/// account, billed per second), `k8s` (a Job on your own Kubernetes
/// cluster), `ssh` (a detached process on one of your own boxes), `slurm`
/// (a batch job on your Slurm cluster, submitted via its login node),
/// `ray` (a job on your Ray cluster, via the Ray Jobs API), `vercel` (a
/// CPU-only Vercel Sandbox microVM on your own Vercel project), `openresearch`
/// (an ephemeral OpenResearch GPU/CPU box billed to your org; needs
/// `orx login`), `tinker` (a local controller using remote Tinker model
/// compute), or `local` (a detached process on this machine). k8s,
/// ssh, slurm, ray, openresearch, tinker, and local are local
/// experiments only. The run engine in the OpenResearch server submits
/// the job and records its status and logs locally. Omitted on a local experiment: launches on
/// the configured default compute target, if set.
#[arg(long)]
pub backend: Option<String>,
/// Hardware flavor. With `--backend hf`: t4-small, a10g-small, a100-large,
/// h200, … With `--backend modal`: a Modal GPU (t4, l4, a10g, a100,
/// a100-80gb, l40s, h100, h200, or e.g. h100:2) or cpu/cpu-large. With
/// `--backend slurm`: a GPU request as a GRES spec (h100:2 → --gres=gpu:h100:2;
/// plain `gpu` → one GPU; omit for CPU-only). With `--backend ray`: optional
/// entrypoint resources (`cpu:2`, `gpu:1`, `gpu:1,mem:8GiB`; omit to reserve
/// nothing). With `--backend vercel`: optional vCPUs (cpu = 2, cpu-<n> or
/// <n>: 1 or an even number up to 32; 2 GB memory each; plans cap this at
/// 4 on Hobby, 8 on Pro, and 32 on Enterprise). With `--backend openresearch`: a GPU id from `orx compute`
/// (h100_sxm, or h100_sxm:2 for two) or a CPU flavor (cpu5c/cpu5g/cpu5m, or
/// cpu5c:32 for the vCPU tier). Not used by k8s (see --manifest) or ssh
/// (see --host).
#[arg(long)]
pub flavor: Option<String>,
/// The org to bill the box to (with `--backend openresearch`). Omit when
/// you belong to exactly one org.
#[arg(long)]
pub org: Option<String>,
/// The ~/.ssh/config host alias (SSH defaults to its saved default host), or the
/// cluster login node (with `--backend slurm`; defaults to the slurm
/// settings' host).
#[arg(long)]
pub host: Option<String>,
/// Existing running Docker container on the SSH host (name or ID).
#[arg(long, conflicts_with = "no_container")]
pub container: Option<String>,
/// Run directly on the SSH host, overriding its saved container.
#[arg(long)]
pub no_container: bool,
/// Repo-relative path to the k8s manifest on the experiment branch (with
/// `--backend k8s`; default .orx/k8s.yaml). The manifest declares the run's
/// resources — image, GPUs, topology — and orx injects the run script, env
/// Secret, labels, and a default timeout. See `orx skill` for the contract.
#[arg(long)]
pub manifest: Option<String>,
/// Docker image for the job (with `--backend hf/modal`). Defaults to
/// python:3.12 on CPU flavors, a CUDA pytorch image otherwise. With
/// `--backend vercel`, a Vercel Container Registry image (default
/// vercel/sandbox/python:3.14). With
/// `--backend k8s`, set the image in the manifest instead.
#[arg(long)]
pub image: Option<String>,
/// Job timeout (with `--backend hf/modal/vercel/k8s/slurm/openresearch`): 90s,
/// 30m, 4h, 1d. Default 4h (HF's own default is only 30 minutes; Vercel
/// defaults to 40m on Hobby so a 45-minute session still includes 5 minutes
/// to read logs and the exit status, and caps a session at 24h otherwise). With
/// `--backend k8s` it becomes activeDeadlineSeconds unless the manifest
/// sets its own. With `--backend slurm` it becomes `#SBATCH --time=` and
/// has no 4h default — unset falls back to the slurm settings, then the
/// cluster's own limit. With `--backend openresearch` it bounds the run's
/// wall clock on the box (the box itself is deleted when the run ends).
/// Not supported with `--backend ray` (Ray Jobs have no time limit).
#[arg(long)]
pub timeout: Option<String>,
/// Cores for the job (with `--backend slurm`): `#SBATCH --cpus-per-task=`.
/// Omitted falls back to the slurm settings, then the partition default —
/// which on many clusters is a single core, whatever the GPU request.
#[arg(long)]
pub cpus: Option<u32>,
/// Host memory for the job (with `--backend slurm`): `#SBATCH --mem=`, in
/// Slurm's own syntax (64G, 4000M, or a bare number for megabytes).
/// Omitted falls back to the slurm settings, then the partition default,
/// which is usually `DefMemPerCPU` × the core count — so raising `--cpus`
/// raises memory with it.
#[arg(long)]
pub mem: Option<String>,
/// Slurm partition for this run; overrides the saved default. Accepts comma-separated names.
#[arg(long)]
pub partition: Option<String>,
/// Launch even when another run is already in flight for this experiment.
#[arg(long)]
pub force: bool,
/// Internal attribution forwarded through the local orx up API.
#[arg(skip)]
pub chat_session_id: Option<String>,
#[arg(long, hide = true)]
pub invocation_context: Option<String>,
/// The native agent CLI whose shell ran `orx exp run`, read once in that process.
#[arg(skip)]
pub agent_origin: Option<String>,
/// Handled by `orx up` for a caller: launch evidence comes only from the request.
#[arg(skip)]
pub forwarded: bool,
#[arg(skip)]
pub telemetry_suppressed: bool,
/// The caller's compute settings, which must be the server's.
#[arg(skip)]
#[serde(default)]
pub caller_config_dir: Option<std::path::PathBuf>,
}
/// Markers the native agent CLIs export to their shells; nested agents are `unknown`.
/// Antigravity exports none.
pub(crate) fn agent_origin() -> Option<String> {
let found: Vec<_> = [
("CLAUDECODE", "claude-code"),
("CODEX_THREAD_ID", "codex"),
("OPENCODE", "opencode"),
("CURSOR_AGENT", "cursor"),
]
.into_iter()
.filter(|(key, _)| std::env::var(key).is_ok_and(|value| !value.is_empty()))
.map(|(_, harness)| harness.to_string())
.collect();
match found.len() {
0 => None,
1 => found.into_iter().next(),
_ => Some("unknown".into()),
}
}
impl ExpRunArgs {
pub(crate) fn invocation_identity(
&self,
) -> crate::error::Result<Option<crate::store::InvocationIdentity>> {
let context = self
.invocation_context
.clone()
.or_else(|| (!self.forwarded).then(|| std::env::var("ORX_INVOCATION_CONTEXT").ok())?);
let identity: Option<crate::store::InvocationIdentity> = match context {
Some(json) => Some(serde_json::from_str(&json)?),
// Codex exports only its thread id to shells; that thread's running turn invoked us.
None if !self.forwarded && self.launching_chat_session().is_some() => {
std::env::var("CODEX_THREAD_ID")
.ok()
.and_then(|thread| crate::local::harness::codex::running_turn_identity(&thread))
}
None => None,
};
if let Some(identity) = &identity {
identity.validate()?;
}
Ok(identity)
}
pub fn launching_chat_session(&self) -> Option<String> {
self.chat_session_id.clone().or_else(|| {
(!self.forwarded)
.then(crate::local::chat::launching_chat_session)
.flatten()
})
}
}
#[derive(Args, Debug)]
pub struct ServeArgs {
/// Port to bind on 127.0.0.1 (default 4790 — what the api proxies to).
#[arg(long)]
pub port: Option<u16>,
}
#[derive(Args, Debug)]
pub struct SuperviseArgs {
/// The run to supervise (must exist in the local store).
pub run_id: String,
}
#[derive(Args, Debug)]
pub struct UpArgs {
/// Port to listen on. With `--remote`, the local presentation port.
#[arg(long, default_value_t = 4791)]
pub port: u16,
/// Address to listen on: `127.0.0.1`, or `0.0.0.0` to also serve devices on
/// your private network. The dashboard has no login, so anyone who can
/// reach it controls your agents and terminals; only do this on a network
/// you trust. Public peers, public addresses and hostnames stay refused.
#[arg(
long,
default_value = "127.0.0.1",
value_name = "ADDR",
conflicts_with_all = ["remote", "remote_host"]
)]
pub host: std::net::IpAddr,
/// Run `orx up` on a remote box over SSH and forward it here. The value is
/// an `~/.ssh/config` host alias, or `user@host` (append `:PORT` for a
/// non-standard SSH port, e.g. `root@1.2.3.4:38455`). Only user@host + port
/// are reconstructed; a custom key or jump host must come from `~/.ssh/config`.
/// Starts an authenticated server there, tunnels it through a hidden local
/// port, and opens a dedicated local presentation gateway in your browser.
#[arg(long, value_name = "HOST")]
pub remote: Option<String>,
/// Don't open the dashboard in the browser on startup.
#[arg(long)]
pub no_browser: bool,
/// Keep the engine running without opening a window.
#[arg(long, hide = true)]
pub headless: bool,
/// Don't spawn the opencode agent on startup (for tests).
#[arg(long)]
pub no_agent: bool,
/// opencode model override, e.g. `anthropic/claude-sonnet-4-5`.
#[arg(long)]
pub model: Option<String>,
/// Internal persistent dashboard/agent-host mode.
#[arg(long, hide = true)]
pub remote_host: bool,
/// Serving the desktop app's window, which only restarts when asked.
#[arg(skip)]
pub desktop_app: bool,
}
#[derive(Args, Clone, Debug)]
pub struct RemoteHostArgs {
#[command(subcommand)]
pub command: RemoteHostCommand,
}
#[derive(Clone, Subcommand, Debug)]
pub enum RemoteHostCommand {
Ensure {
#[arg(long)]
expected_instance: Option<String>,
},
Status,
Attach {
#[arg(long)]
expected_instance: String,
},
Stop,
}
#[derive(Args, Debug)]
pub struct SkillArgs {
pub path: Option<String>,
}
#[derive(Args, Debug)]
pub struct LibraryArgs {
#[command(subcommand)]
pub command: LibraryCommand,
}
#[derive(Subcommand, Debug)]
pub enum LibraryCommand {
/// Save a file or ZIP across projects; replaces an existing entry of the same name.
Add { path: std::path::PathBuf },
}
#[derive(Args, Debug)]
pub struct InstallSkillsArgs {
/// Which agent(s) to install into: `claude`, `codex`, `opencode`, `cursor`,
/// `antigravity`, or `all`. Defaults to every agent already set up on this machine.
#[arg(long)]
pub agent: Option<String>,
/// Also install the full set of modular `orx` skills (~8 always-listed
/// skills) into the agent's global skills dir, not just the thin shim.
/// Intended for dedicated/orx-only environments. In a general-purpose setup
/// the always-on skills add noise, so the default is the shim alone.
#[arg(long)]
pub full: bool,
}
#[derive(Args, Debug)]
pub struct TelemetryArgs {
#[command(subcommand)]
pub command: TelemetryCommand,
}
#[derive(Subcommand, Debug)]
pub enum TelemetryCommand {
/// Show whether analytics is on, why, and the anonymous install id.
Status,
/// Enable anonymous usage analytics.
On,
/// Disable anonymous usage analytics on this machine.
Off,
}
#[derive(Args, Debug)]
pub struct FeedbackArgs {
#[arg(long, value_enum)]
pub kind: FeedbackKind,
/// One line, at most 200 characters.
#[arg(long)]
pub summary: String,
/// For bugs, include as much detail as possible: non-sensitive input,
/// command and flags, error, expected and actual behavior, environment,
/// and workaround; at most 4000 characters. Omit sensitive information.
#[arg(long)]
pub details: String,
/// The user's own words, rephrased to strip sensitive details; at most 1000
/// characters.
#[arg(long)]
pub quote: Option<String>,
}
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq, serde::Serialize)]
#[value(rename_all = "snake_case")]
#[serde(rename_all = "snake_case")]
pub enum FeedbackKind {
Bug,
FeatureRequest,
Frustration,
}
/// Which corpus a literature command searches or reads from.
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
#[value(rename_all = "lower")]
pub enum LitSource {
/// alphaXiv (arXiv corpus: CS, math, physics, stats — the default).
Alphaxiv,
/// OpenAlex (general scholarly graph across all disciplines).
Openalex,
/// bioRxiv biology preprints (searched via OpenAlex, fetched via bioRxiv).
Biorxiv,
/// PubMed biomedical literature (NCBI E-utilities).
Pubmed,
}
impl LitSource {
/// Lowercase wire name used to enforce against the Settings disable-set.
/// Matches the `--source` flag values (clap `rename_all = "lower"`) and the
/// `LitHit.source` JSON labels.
pub fn as_str(&self) -> &'static str {
match self {
LitSource::Alphaxiv => "alphaxiv",
LitSource::Openalex => "openalex",
LitSource::Biorxiv => "biorxiv",
LitSource::Pubmed => "pubmed",
}
}
/// Human-facing name for error/UI text.
pub fn display_name(&self) -> &'static str {
match self {
LitSource::Alphaxiv => "alphaXiv",
LitSource::Openalex => "OpenAlex",
LitSource::Biorxiv => "bioRxiv",
LitSource::Pubmed => "PubMed",
}
}
}
#[derive(Args, Debug)]
pub struct DiscoverArgs {
#[command(subcommand)]
pub command: DiscoverCommand,
}
#[derive(Subcommand, Debug)]
pub enum DiscoverCommand {
/// alphaXiv full-text BM25 retrieval with match snippets.
Keyword(DiscoverySearchArgs),
/// alphaXiv semantic title/abstract retrieval with similarity/popularity reranking.
Embedding(DiscoverySearchArgs),
/// OpenAlex scholarly-graph search across disciplines. Set OPENALEX_API_KEY (free:
/// help.openalex.org/api/authentication) for a daily budget of its own.
Openalex(DiscoverySearchArgs),
/// bioRxiv preprint search through OpenAlex's bioRxiv source index.
Biorxiv(DiscoverySearchArgs),
/// PubMed biomedical literature search through NCBI E-utilities.
Pubmed(DiscoverySearchArgs),
}
#[derive(Args, Debug)]
pub struct DiscoverySearchArgs {
/// Exact keyword query or semantic description, depending on the strategy.
pub query: String,
/// Include papers first published on or after this date (YYYY-MM-DD).
#[arg(long = "published-after")]
pub published_after: Option<String>,
/// Include papers first published on or before this date (YYYY-MM-DD). Older
/// or narrow embedding windows can return a thin candidate set.
#[arg(long = "published-before")]
pub published_before: Option<String>,
/// Ranking policy after topical relevance is accounted for.
#[arg(long, value_enum, default_value = "default")]
pub prioritize: DiscoveryPriority,
/// Maximum results to emit (default 15). alphaXiv uses its fixed server-side candidate pool.
#[arg(long, default_value_t = 15, value_parser = clap::value_parser!(u32).range(1..=200))]
pub limit: u32,
}
#[derive(ValueEnum, Clone, Copy, Debug, PartialEq, Eq)]
#[value(rename_all = "lower")]
pub enum DiscoveryPriority {
Historical,
Default,
Recency,
Popular,
}
impl DiscoveryPriority {
pub fn as_str(self) -> &'static str {
match self {
Self::Historical => "historical",
Self::Default => "default",
Self::Recency => "recency",
Self::Popular => "popular",
}
}
}
#[derive(Args, Debug)]
pub struct VersionArgs {
/// Print the desktop build identity.