diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index fd4fabe18..0fe221a81 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -1,7 +1,7 @@ import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; import { BaseLlmApi } from "@continuedev/openai-adapters"; import { Box, Text } from "ink"; -import React, { useState, useEffect } from "react"; +import React, { useEffect, useState } from "react"; import { loadAuthConfig } from "../auth/workos.js"; import { initialize } from "../config.js"; import { introMessage } from "../intro.js"; @@ -15,6 +15,7 @@ import { useOrganizationSelector } from "./hooks/useOrganizationSelector.js"; import LoadingAnimation from "./LoadingAnimation.js"; import OrganizationSelector from "./OrganizationSelector.js"; import Timer from "./Timer.js"; +import UpdateNotification from "./UpdateNotification.js"; import UserInput from "./UserInput.js"; interface TUIChatProps { @@ -239,7 +240,15 @@ const TUIChat: React.FC = ({ onFileAttached={handleFileAttached} disabled={showOrgSelector || showConfigSelector || !!loginPrompt} /> - + + + + ● Continue CLI diff --git a/src/ui/UpdateNotification.tsx b/src/ui/UpdateNotification.tsx new file mode 100644 index 000000000..dcf5cb438 --- /dev/null +++ b/src/ui/UpdateNotification.tsx @@ -0,0 +1,40 @@ +import { Text } from "ink"; +import React, { useEffect, useState } from "react"; +import { compareVersions, getLatestVersion, getVersion } from "../version.js"; + +const UpdateNotification: React.FC = () => { + const [updateAvailable, setUpdateAvailable] = useState(false); + const [latestVersion, setLatestVersion] = useState(""); + const [currentVersion] = useState(getVersion()); + + useEffect(() => { + const checkForUpdate = async () => { + try { + const latest = await getLatestVersion(); + if (latest) { + setLatestVersion(latest); + const comparison = compareVersions(currentVersion, latest); + setUpdateAvailable(comparison === "older"); + } + } catch (error) { + // Silently fail - we don't want to interrupt the user experience + console.debug("Failed to check for updates:", error); + } + }; + + // Check for updates but don't block + checkForUpdate(); + }, [currentVersion]); + + if (!updateAvailable) { + return null; + } + + return ( + + Update available: v{latestVersion} (npm i -g @continuedev/cli) + + ); +}; + +export default UpdateNotification; diff --git a/src/version.ts b/src/version.ts index 8d2b4b98b..99001961b 100644 --- a/src/version.ts +++ b/src/version.ts @@ -14,3 +14,46 @@ export function getVersion(): string { return "unknown"; } } + +export async function getLatestVersion(): Promise { + try { + const response = await fetch( + "https://registry.npmjs.org/@continuedev/cli/latest" + ); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); + return data.version; + } catch (error) { + console.warn("Warning: Could not fetch latest version from npm registry"); + return null; + } +} + +export function compareVersions( + current: string, + latest: string +): "newer" | "same" | "older" { + if (current === "unknown" || latest === "unknown") { + return "same"; + } + + // Simple semantic version comparison + const parseVersion = (version: string) => { + const parts = version.replace(/^v/, "").split(".").map(part => parseInt(part, 10)); + return { major: parts[0] || 0, minor: parts[1] || 0, patch: parts[2] || 0 }; + }; + + const currentParts = parseVersion(current); + const latestParts = parseVersion(latest); + + if (currentParts.major > latestParts.major) return "newer"; + if (currentParts.major < latestParts.major) return "older"; + if (currentParts.minor > latestParts.minor) return "newer"; + if (currentParts.minor < latestParts.minor) return "older"; + if (currentParts.patch > latestParts.patch) return "newer"; + if (currentParts.patch < latestParts.patch) return "older"; + + return "same"; +}