feat(hm-cloud): scaffold cloud crate and add GitSha newtype - #181
Merged
Conversation
Introduce a validated git object-id type (40/64 hex, lowercase, null-oid sentinel) with transparent-string serde, and thread it through every place a commit id is produced or carried: - git::head_commit() -> Option<GitSha>, parsed from rev-parse. - exec::SourceMeta.commit: GitSha, converted to String only at the harmont-cloud SDK boundary. - hm run derives the commit as GitSha::zero() when git has none. - cloud run's --commit parses to GitSha at clap time, rejecting a malformed id before submission.
New crate that will own the whole cloud domain (executor + verbs). This
first step lands the clap command tree only, no runtime:
- CloudCommand { Auth{login,logout,whoami}, Org, Pipeline, Build, Job,
Billing } with every arg documented.
- Pipeline-identifying args are Option<String> so an omitted --pipeline
falls back to config.default_pipeline.
- No submit verb: submission stays with hm run --cloud.
Represent a commit id as its 20 raw bytes ([u8; 20], Copy) instead of a heap String, with hex only at the edges: decode via the hex crate on parse, encode on Display/serde. Drops the speculative SHA-256 width — git and Harmont's repos are SHA-1; promote to an enum if one ever appears.
The binary now consumes hm_cloud::cli::CloudCommand instead of a duplicate enum tree, so hm-cloud's cli.rs is the single definition. Adopting it applies the shape the scaffold settled on: - login/logout/whoami move under `hm cloud auth`. - `hm cloud run` is dropped; submission stays with `hm run --cloud`. - --pipeline is optional everywhere, resolving to the project's default_pipeline (via ProjectCtx) with a clear error when neither is set. Dispatch and the verbs adapt to the new enums; verbs/run.rs is deleted.
Capture the process's runtime environment once at startup — stdin/stdout/ stderr TTY state, CI, SSH, and display presence — behind AppCtx::term(). is_interactive() and has_gui() give the CLI honest signals for prompting and for choosing browser vs. terminal fallbacks (an SSH session is interactive but has no local browser). Consolidates the scattered TTY detection: hm-render's color_enabled now takes the stderr-tty bit from Term, and the run/cloud render paths read Term instead of calling std::io::IsTerminal ad hoc.
A cryptographically random, URL-safe nonce stored as its raw 32 bytes: OS CSPRNG generation, constant-time comparison, redacted Debug, and zeroize-on-drop. Only constructor is random(), so a weak nonce can't be built by accident; base_64() renders it for URLs.
AuthProvider drives the login flow, picking the path from Term: a GUI gets the browser-loopback flow (BrowserAuth binds the listener, opens the page, ClaimPoller claims the token by nonce); otherwise the paste flow (PasteTokenAuth). Each step carries a typed error, the dialoguer prompt runs on spawn_blocking, and URLs are built with url::Url — for which BackendDomain now exposes app() as a Url. hm cloud auth login loses --paste (detection replaces it) and hm's login.rs drops its ~160-line loopback/nonce/poll implementation for a thin adapter over AuthProvider that reads the user back.
Rework AuthProvider to hold {app_ctx, config} and build its own clients
(anonymous for login, authenticated for whoami and the post-login
readback) rather than taking an injected one — so it can own the whole
`hm cloud auth` surface. logout and whoami move onto it; hm's login.rs/
logout.rs/whoami.rs become thin adapters, and the old settings::client-
based whoami is dropped.
Review fixes to the login flow:
- Gate the browser flow on !is_ci() so a CI runner with a display fails
fast instead of hanging on the loopback.
- Poll for the token directly while the spawned listener serves the
redirect concurrently, instead of waiting out the redirect timeout
first (BrowserAuth becomes a side-effecting open()).
Also fold NO_COLOR detection into Term (wants_color(), flag applied by
callers), drop the now-unused hm-render::color_enabled, inline the
trailing-slash trim in BackendDomain, and expose app() as a Url.
…llows
The harmont-cloud client string-concatenates its base (format!("{base}{path}")),
so BackendDomain must hand back a trailing-slash-trimmed String. Note to switch
to Url once the client accepts a URL base.
Snapshot the process environment once at startup behind EnvVarProvider (get/is_set/is_present/parse, redacted Debug since env can hold secrets), exposed as AppCtx::env(). Term::detect now reads SSH/DISPLAY/NO_COLOR from it instead of hitting std::env inline. Also drop the dead env threading through the cloud dispatch: verbs all ignored the BTreeMap (the run verb that used it moved to hm run --cloud), so remove the _env params, the dispatch env argument, and the std::env::vars() collect.
EnvVarProvider now owns the environment-derived facts (is_ci, is_ssh, has_display, no_color) as typed accessors; is_ci::cached() moves here. Term drops its ci/ssh/display/no_color fields and holds a borrowed &EnvVarProvider instead, so those facts live in one place and Term is back under the bool count that needed struct_excessive_bools. AppCtx no longer stores a Term (it would be self-referential); term() builds Term<'_> on demand against the captured env.
Store the probed terminal state (TerminalState) and the EnvVarProvider as plain sibling fields on AppCtx. TerminalState::term(&self, env) binds the two into a Copy Term<'_> view; AppCtx::term() returns it. Terminal state is probed once at init (not per call), and there is no self-reference, so no ouroboros.
markovejnovic
marked this pull request as ready for review
July 29, 2026 07:28
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.