Skip to content

feat(hm-cloud): scaffold cloud crate and add GitSha newtype - #181

Draft
markovejnovic wants to merge 7 commits into
mainfrom
feat/hm-cloud-scaffold
Draft

feat(hm-cloud): scaffold cloud crate and add GitSha newtype#181
markovejnovic wants to merge 7 commits into
mainfrom
feat/hm-cloud-scaffold

Conversation

@markovejnovic

Copy link
Copy Markdown
Contributor

Generated by an AI agent.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant