Dashboard › cli › Distillation
9e560e90-094a-4e0a-ae90-8d585c93f403["lore_tm_v1_vJROr1vn4AojHp3VIsm5Y0X1o2DCj-v_DB1n6VdVlRA","lore_tm_v1_WZtLtdbbO6MaEDhyDbcZLU06iiIXhkKAPIIrgAkQq3k","lore_tm_v1_IUx47zU6JxiJt3DgFM-sl9ed363UuCXECNU9xvtZ07A","lore_tm_v1_bxsqh5iKx8rFCNvJn2RwbZXTtnXtiVDQ2pIyRnDc7l8","lore_tm_v1_YM9zVxYLOsOLvw9tNTYFVsXffM_MhFZXp4i9t9xpIUg"]
.craft.yml, .git, .github/, .gitignore, .lore.md, .nojekyll, .npmrc, .opencode/, .plans/, .ruff_cache/, AGENTS.md, apps/, CHANGELOG.md, codemods/, coverage/, dist-bin/, dist/, docs/, LICENSE.md, node_modules/, package.json, packages/, pnpm-lock.yaml, pnpm-workspace.yaml, README.md, and test-results.junit.xml.packages/cli/src/lib/upgrade.ts lines 375β400 define fetchLatestFromGitHub(signal?): it requests ${GITHUB_RELEASES_URL}/latest through fetchWithUpgradeError() with getGitHubHeaders() and the optional AbortSignal, throws UpgradeError("network_error", ...) for a non-OK response or missing tag_name, and strips the leading v using VERSION_PREFIX_REGEX.fetchLatestFromNpm() in packages/cli/src/lib/upgrade.ts requests ${NPM_REGISTRY_URL}/latest with Accept: application/json, returns data.version, and throws UpgradeError("network_error", ...) for a non-OK response or missing version.fetchLatestNightlyVersion(signal?) checks the signal before each network operation, obtains a token using getAnonymousToken(), fetches the rolling nightly manifest with fetchNightlyManifest(token), and returns getNightlyVersion(manifest); an already-aborted signal causes AbortError.fetchLatestVersion(method, channel = "stable") selects GHCR through fetchLatestNightlyVersion() for the "nightly" channel, GitHub through fetchLatestFromGitHub() for stable "curl" or "brew" installations, and npm through fetchLatestFromNpm() for other stable installation methods.nightlyVersionExists(version) checks GHCR tag nightly-${version} via fetchManifest(); HTTP 404 and HTTP 403 map to false, while other errors propagate. versionExists(method, version) delegates nightly versions to that helper, checks ${GITHUB_RELEASES_URL}/tags/${version} with HEAD for "curl"/"brew", and checks ${NPM_REGISTRY_URL}/${version} with HEAD for package-manager installations.DownloadResult in packages/cli/src/lib/upgrade.ts contains tempBinaryPath: string, lockPath: string, and optional patchBytes?: number; the caller must retain the lock until the child exits.streamDecompressToFile(body, destPath, setMessage?) pipes the response through new DecompressionStream("gzip"), writes with createWriteStream(destPath), and reports indeterminate decompressed-byte progress through makeByteProgress("Downloading", null, setMessage).streamDecompressToFile() therefore calls writer.end() after stream processing even when streaming failed, invokes progress.done() in finally, preserves the original streaming error over any later writer.end() failure, and logs the secondary close failure with log.debug.ENOSPC while the write buffer is full may βnever emit 'drain'.β The backpressure path must therefore race one-time "drain" and "error" listeners, resolving on either and removing the unused listener to avoid hanging and MaxListenersExceededWarning.streamDecompressToFile() installs an early persistent writer "error" listener to capture errors in writeError; without it, failed writes such as ENOSPC or EIO could crash Node with ERR_UNHANDLED_ERROR.getNightlyGzFilename() returns ${getPlatformBinaryName()}.gz. downloadNightlyToPath(destPath, version?, setMessage?) gets an anonymous GHCR token, fetches nightly-${version} when pinned or the rolling :nightly manifest otherwise, locates the layer by that gzip filename, downloads its blob by digest, throws UpgradeError("execution_failed", "GHCR blob response had no body") when needed, and streams decompression to destPath.downloadStableToPath(version, destPath, setMessage?) first attempts ${getBinaryDownloadUrl(version)}.gz and streams gzip decompression; any compressed-path failure falls back to the raw GitHub Release binary. The comments quantify compressed versus raw size as approximately 37 MB versus 99 MB and describe gzip as approximately 60% smaller.UpgradeError("execution_failed", \Failed to download binary: HTTP ${response.status}`); it fully consumes response.arrayBuffer()and writesnew Uint8Array(body)withwriteFile()` rather than streaming directly.packages/cli/src/lib/upgrade.ts are VERIFY_MAX_ATTEMPTS = 6 and VERIFY_BASE_DELAY_MS = 100; six probes with five exponentially increasing sleeps provide approximately 3.1 seconds total wall-clock budget. probeBinaryFile(path) returns the file size only for a present, regular, non-empty file and otherwise returns null.