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ยง
- CliVersion
Info - Snapshot of the installed-vs-latest claude CLI versions. Either
side can be
Noneindependently; the renderer falls back to a dim-placeholder for the missing side.
Enumsยง
- Probe
Outcome ๐ - Result of one npm-registry attempt. The type exists for the retry
decision:
Unreachablenever touched the server (retry direct),Unusablereached it but the response was no good (retry wonโt help).
Constantsยง
- NPM_
LATEST_ ๐URL - npm registry endpoint for the published
@anthropic-ai/claude-codepackage. The/latestdist-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!insidecrate::env::cli_version::fetch_info). 5 s is generous for a local--versioninvocation 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.
directadds.no_proxy()so the request bypasses any ambient proxy env and connects straight to the registry; both variants keepwith_extra_rootsso 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 bare2.1.116shapes the CLI / npm produce. - fetch_
info - Run both probes in parallel and return the merged snapshot.
Always succeeds - failures collapse to
Noneon the affected field with a WARN log; the workspace caller never has to handle aResult. - is_
strictly_ ๐newer truewhenlhsparses as a strictly-greater semver triple thanrhs. A parse failure on either side collapses tofalseso the update banner only fires when the comparison is unambiguous.- latest_
version_ ๐or_ warn - Normalise an npm
/latestresponse body to a version token, WARN +Nonewhen it carries none - the same silent-collapse shape as the installed probeโs miss. - parse_
latest_ ๐version - Pull the
MAJOR.MINOR.PATCHtoken from an npm/latestdist-tag response bodyโsversionfield. - parse_
semver_ ๐triple - Parse
MAJOR.MINOR.PATCH(ignoring any-pre.1/+buildsuffix after the patch number) into a(u32, u32, u32)tuple suitable for direct tuple comparison. - probe_
installed ๐ - Spawn
claude --versionon a blocking thread (the underlying helper usesstd::process::Command), bound the wait toPROBE_TIMEOUT, and normalise the output to a bareMAJOR.MINOR.PATCHtoken. WARN log +Noneon any failure. - probe_
installed_ ๐within probe_installedwith 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
/latestdist-tag and return the newest published@anthropic-ai/claude-codeversion asMAJOR.MINOR.PATCH. - reported_
version_ ๐or_ warn - Normalise a zero-exit
claude --versionstdout to a bare version token, WARN +Nonewhen it carries none - a silentNonehere is indistinguishable from a probe that never ran.