Skip to main content

Module cli_version

Module cli_version 

Source
Expand description

Detect the installed claude CLI version and (when reachable) the latest published version on npm.

The local probe shells out via forge_sdk::transport::process::query_cli_version and normalises the result to a bare MAJOR.MINOR.PATCH token - claude --version prints lines like 2.1.116 (anthropic) or claude 2.1.116 depending on the build channel, so callers want the version token alone for display.

CliVersionInfo is the cross-crate shape returned by the workspace mediator; both installed and latest are Option because either probe can fail independently (claude not on PATH, no network, npm rate-limited). The renderer treats None as a - placeholder so the panelโ€™s row count stays constant.

Re-exportsยง

use std::time::Duration; ๐Ÿ”’

Structsยง

CliVersionInfo
Snapshot of the installed-vs-latest claude CLI versions. Either side can be None independently; the renderer falls back to a dim - placeholder for the missing side.

Enumsยง

ProbeOutcome ๐Ÿ”’
Result of one npm-registry attempt. The type exists for the retry decision: Unreachable never touched the server (retry direct), Unusable reached it but the response was no good (retry wonโ€™t help).

Constantsยง

NPM_LATEST_URL ๐Ÿ”’
npm registry endpoint for the published @anthropic-ai/claude-code package. The /latest dist-tag returns the same JSON shape as the full package document but trimmed to the current latest version, which is all we need.
PROBE_TIMEOUT ๐Ÿ”’
Per-probe timeout (each of the two probes runs in parallel via tokio::join! inside crate::env::cli_version::fetch_info). 5 s is generous for a local --version invocation and still well below the user-visible โ€œapp feels stuckโ€ threshold for the startup latency hit.

Functionsยง

attempt_latest ๐Ÿ”’
Run one GET against the npm registry with the given client, classifying the result so the caller can decide whether a direct retry is worthwhile.
build_probe_client ๐Ÿ”’
Build the reqwest client for a single npm probe. direct adds .no_proxy() so the request bypasses any ambient proxy env and connects straight to the registry; both variants keep with_extra_roots so a corporate / mitmproxy CA still validates.
extract_semver_token ๐Ÿ”’
Extract the first whitespace-separated token that starts with a digit - handles 2.1.116 (anthropic), claude 2.1.116, and bare 2.1.116 shapes the CLI / npm produce.
fetch_info
Run both probes in parallel and return the merged snapshot. Always succeeds - failures collapse to None on the affected field with a WARN log; the workspace caller never has to handle a Result.
is_strictly_newer ๐Ÿ”’
true when lhs parses as a strictly-greater semver triple than rhs. A parse failure on either side collapses to false so the update banner only fires when the comparison is unambiguous.
latest_version_or_warn ๐Ÿ”’
Normalise an npm /latest response body to a version token, WARN + None when it carries none - the same silent-collapse shape as the installed probeโ€™s miss.
parse_latest_version ๐Ÿ”’
Pull the MAJOR.MINOR.PATCH token from an npm /latest dist-tag response bodyโ€™s version field.
parse_semver_triple ๐Ÿ”’
Parse MAJOR.MINOR.PATCH (ignoring any -pre.1 / +build suffix after the patch number) into a (u32, u32, u32) tuple suitable for direct tuple comparison.
probe_installed ๐Ÿ”’
Spawn claude --version on a blocking thread (the underlying helper uses std::process::Command), bound the wait to PROBE_TIMEOUT, and normalise the output to a bare MAJOR.MINOR.PATCH token. WARN log + None on any failure.
probe_installed_within ๐Ÿ”’
probe_installed with the wait as a parameter, so a test driving a real child can widen the budget rather than race machine load.
probe_latest ๐Ÿ”’
GET npmโ€™s /latest dist-tag and return the newest published @anthropic-ai/claude-code version as MAJOR.MINOR.PATCH.
reported_version_or_warn ๐Ÿ”’
Normalise a zero-exit claude --version stdout to a bare version token, WARN + None when it carries none - a silent None here is indistinguishable from a probe that never ran.