/** * Release check for `@agentproto/cli` (and the daemon it carries) — shared * between the CLI (`agentproto daemon status` fold) and the VS Code extension * (the release status-bar indicator + update prompt). Both packages already * depend on `@agentproto/runtime`, so it's the natural home for the ONE copy * of the decision + IO, rather than a vscode-private module the CLI couldn't * reach. * * Two halves: * - the pure decision logic (`.`-version comparison, cache freshness, the * offline-safe `resolveReleaseCheck`) — no import beyond the standard * library, unit-testable without network/home/extension; * - the IO half (npm registry fetch + the `~/.agentproto/release-check.json` * versioned cache) — plain Node, no vscode import, runnable in tests. * * Contract (from .plans/release-update-indicator-PLAN.md, WP-A): * - The signal "a new release exists" is the npm registry for * `@agentproto/cli` (the CLI carries the daemon; `health.version` IS the * CLI version, so the daemon inherits it). * - Two comparison modes by `build.source` read on the daemon's /health: * - `tarball` / absent → compare `health.version` against npm latest. * - `workspace` → signal `workspace` distinctly: the real update for a * workspace install is a local REBUILD, not an npm reinstall. * - Offline-safe: never claim an update we didn't verify. When the npm fetch * failed and the cache is stale, the answer is `unknown` — never a false * "update dispo" off a stale number. */ /** Cache file version — bump when the on-disk shape changes. */ declare const RELEASE_CHECK_CACHE_VERSION = 1; /** Default npm poll TTL (ms). ~1 h, never below the 10 min floor. */ declare const RELEASE_CHECK_DEFAULT_TTL_MS: number; declare const RELEASE_CHECK_MIN_TTL_MS: number; /** Build provenance, from the daemon's health.build.source. */ type ReleaseBuildSource = "workspace" | "tarball" | null; /** * What the release indicator reports. `workspace` is deliberately distinct * from `current`: both mean "nothing to install via npm", but `workspace` * additionally tells the display to frame the update as a rebuild. */ type ReleaseState = "current" | "behind" | "unknown" | "workspace"; /** Persistent cache — the offline fallback. Versioned like the other * `~/.agentproto/*.json` stores (`{ version: N, ... }`). */ interface ReleaseCheckCache { /** Cache-file shape version. Must equal RELEASE_CHECK_CACHE_VERSION to be * trusted; a mismatch (older/newer on-disk shape) is treated as no cache. */ version: number; /** Latest `@agentproto/cli` observed on npm. Null while unknown. */ latest: string | null; /** Local CLI version at the time of the check that produced `latest`. */ localVersion: string | null; /** Epoch ms of the last successful npm fetch. */ checkedAtMs: number; } /** * Compare two dotted versions numerically. Returns a positive integer when * `a > b`, negative when `a < b`, 0 when equal or unparseable. Accepts * optional `v` prefix and trailing prerelease/build suffix. */ declare function compareVersions(a: string, b: string): number; /** * The WP-A decision. Returns: * - `unknown` — no usable `latestVersion` (network error / no cache → the * offline-safe answer; never a fabricated "behind"). * - `workspace` — the daemon is served from a workspace build: the real * update is a rebuild, so this is its own state, not a * plain `behind`. * - `behind` — `buildSource` is a published tarball and npm is ahead. * - `current` — tarball and npm is not ahead. */ declare function compareRelease(localVersion: string | null | undefined, latestVersion: string | null | undefined, buildSource: ReleaseBuildSource): ReleaseState; /** TTL, clamped to the 10 min floor. */ declare function releaseTtlMs(intervalMin: number | undefined): number; /** True when the cache is young enough to trust without a fresh fetch. */ declare function isCacheFresh(cache: ReleaseCheckCache | null, nowMs: number, ttlMs: number): boolean; interface ResolveCheckInput { localVersion: string | null; buildSource: ReleaseBuildSource; /** Npm result from a fresh fetch. Null when the network fetch failed or was * skipped because the cache was already fresh. */ latestFromNpm: string | null; cache: ReleaseCheckCache | null; nowMs: number; ttlMs: number; } interface ResolveCheckResult { state: ReleaseState; /** The `@agentproto/cli` latest we trust, if any (fresh npm or fresh cache). */ latest: string | null; /** Whether `latest` came from the cache rather than a live fetch. */ fromCache: boolean; /** Cached latest (may be stale) — informational only, never drives state. */ cachedLatest: string | null; } /** * Resolve the full check from its inputs. This is the pure, offline-safe * core: a fresh npm result wins; otherwise a fresh cache is trusted (this is * the "return the cache if the TTL hasn't expired" fallback); otherwise the * answer is `unknown` — a stale cache never fabricates a "behind". */ declare function resolveReleaseCheck(input: ResolveCheckInput): ResolveCheckResult; /** `~/.agentproto/release-check.json`. */ declare function releaseCheckCachePath(home?: string): string; interface FetchLatestCli { (opts?: { timeoutMs?: number; }): Promise; } /** Fetch the latest published `@agentproto/cli` version from the npm * registry. Returns null on any network error (so the caller can fall back to * the cache / report `unknown`), never throws. */ declare function fetchLatestCliVersion(opts?: { timeoutMs?: number; }): Promise; /** Read + parse the cache. Returns null when missing, malformed, or of a * version we don't understand. */ declare function readReleaseCache(path?: string): Promise; /** Atomically write the cache (tmp + rename), like the other versioned * `~/.agentproto` stores. */ declare function writeReleaseCache(next: ReleaseCheckCache, path?: string): Promise; interface ReleaseCheckView { /** Decided state. */ state: "current" | "behind" | "unknown" | "workspace"; /** Latest `@agentproto/cli` version to trust (fresh npm or fresh cache). */ latest: string | null; /** Whether this run used the cache instead of npm. */ fromCache: boolean; /** Local CLI version that was compared. */ localVersion: string | null; } interface RunReleaseCheckOptions { localVersion: string | null; buildSource: ReleaseBuildSource; /** Poll TTL (ms). Pass releaseTtlMs(config) typically. */ ttlMs: number; nowMs?: number; /** Injectable fetcher for tests; defaults to the real npm fetch. */ fetchLatest?: FetchLatestCli; cachePath?: string; } /** Run one release check: consult the cache, fetch npm only when stale, and * persist a successful live result. Offline-safe by construction. */ declare function runReleaseCheck(opts: RunReleaseCheckOptions): Promise; export { type FetchLatestCli, RELEASE_CHECK_CACHE_VERSION, RELEASE_CHECK_DEFAULT_TTL_MS, RELEASE_CHECK_MIN_TTL_MS, type ReleaseBuildSource, type ReleaseCheckCache, type ReleaseCheckView, type ReleaseState, type ResolveCheckInput, type ResolveCheckResult, type RunReleaseCheckOptions, compareRelease, compareVersions, fetchLatestCliVersion, isCacheFresh, readReleaseCache, releaseCheckCachePath, releaseTtlMs, resolveReleaseCheck, runReleaseCheck, writeReleaseCache };