From 1ef79618201912988cddb8ba3d6d3e24c5d52c24 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 25 Jul 2025 16:00:58 +0700 Subject: [PATCH 1/4] feat: show cwd/repo in bottom left --- src/ui/TUIChat.tsx | 37 +++++++++++++++++++++++++--- src/ui/UpdateNotification.tsx | 33 +++++++++++++++---------- src/ui/hooks/useTerminalSize.ts | 43 +++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+), 17 deletions(-) create mode 100644 src/ui/hooks/useTerminalSize.ts diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 619b0e09d..40862cd23 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -1,5 +1,5 @@ -import { Box, Text } from "ink"; -import React, { useEffect, useState } from "react"; +import { Box, Text, useApp, useStdout } from "ink"; +import React, { useEffect, useMemo, useState } from "react"; import { useServices } from "../hooks/useService.js"; import { ApiClientServiceState, @@ -22,6 +22,8 @@ import OrganizationSelector from "./OrganizationSelector.js"; import Timer from "./Timer.js"; import UpdateNotification from "./UpdateNotification.js"; import UserInput from "./UserInput.js"; +import { getGitRemoteUrl, getRepoUrl, isGitRepo } from "../util/git.js"; +import useTerminalSize from "./hooks/useTerminalSize.js"; interface TUIChatProps { // Remote mode props @@ -42,7 +44,29 @@ const TUIChat: React.FC = ({ additionalRules, }) => { // Check if we're in remote mode - const isRemoteMode = !!remoteUrl; + const isRemoteMode = useMemo(() => { + return !!remoteUrl; + }, [remoteUrl]); + + const repoURlText = useMemo(() => { + let url = remoteUrl ?? ""; + if (!url) { + const isGit = isGitRepo(); + if (isGit) { + const gitUrl = getGitRemoteUrl(); + if (gitUrl) { + url = gitUrl; + } + } + } + if (!url) { + url = process.cwd(); + } + + url = url.replace(/\.git$/, ""); + url = url.replace(/^(https|http):\/\/.*?\//, ""); + return url; + }, [remoteUrl]); // Get all services reactively - only in normal mode const { @@ -320,6 +344,11 @@ const TUIChat: React.FC = ({ justifyContent="space-between" alignItems="center" > + + + {repoURlText} + + {!isRemoteMode && services.model?.model && ( = ({ /> )} - + diff --git a/src/ui/UpdateNotification.tsx b/src/ui/UpdateNotification.tsx index 8612b1f14..ffd5669fb 100644 --- a/src/ui/UpdateNotification.tsx +++ b/src/ui/UpdateNotification.tsx @@ -1,24 +1,28 @@ -import { Text } from "ink"; -import React, { useEffect, useState } from "react"; +import { Text, useStdout } from "ink"; +import React, { useEffect, useMemo, useState } from "react"; import { compareVersions, getLatestVersion, getVersion } from "../version.js"; +import useTerminalSize from "./hooks/useTerminalSize.js"; interface UpdateNotificationProps { isRemoteMode?: boolean; } -const UpdateNotification: React.FC = ({ isRemoteMode = false }) => { +const UpdateNotification: React.FC = ({ + isRemoteMode = false, +}) => { const [updateAvailable, setUpdateAvailable] = useState(false); const [latestVersion, setLatestVersion] = useState(""); const [currentVersion] = useState(getVersion()); + const { columns } = useTerminalSize(); useEffect(() => { // Skip update check in test environment - if (process.env.NODE_ENV === 'test') { + if (process.env.NODE_ENV === "test") { return; } - + const abortController = new AbortController(); - + const checkForUpdate = async () => { try { const latest = await getLatestVersion(abortController.signal); @@ -29,7 +33,7 @@ const UpdateNotification: React.FC = ({ isRemoteMode = } } catch (error) { // Silently fail - we don't want to interrupt the user experience - if (error instanceof Error && error.name !== 'AbortError') { + if (error instanceof Error && error.name !== "AbortError") { console.debug("Failed to check for updates:", error); } } @@ -37,13 +41,20 @@ const UpdateNotification: React.FC = ({ isRemoteMode = // Check for updates but don't block checkForUpdate(); - + // Cleanup function to abort the request when component unmounts return () => { abortController.abort(); }; }, [currentVersion]); + const text = useMemo(() => { + if (columns < 75) { + return `v${latestVersion} available`; + } + return `Update available: v${latestVersion} (npm i -g @continuedev/cli)`; + }, [columns, latestVersion]); + if (!updateAvailable) { if (isRemoteMode) { return ◉ Remote Mode; @@ -51,11 +62,7 @@ const UpdateNotification: React.FC = ({ isRemoteMode = return ● Continue CLI; } - return ( - - Update available: v{latestVersion} (npm i -g @continuedev/cli) - - ); + return {text}; }; export default UpdateNotification; diff --git a/src/ui/hooks/useTerminalSize.ts b/src/ui/hooks/useTerminalSize.ts new file mode 100644 index 000000000..b2271f4a6 --- /dev/null +++ b/src/ui/hooks/useTerminalSize.ts @@ -0,0 +1,43 @@ +import { useEffect, useState } from "react"; +import { useStdout } from "ink"; + +const useTerminalSize = (debounce = 100) => { + const { stdout } = useStdout(); + const [dimensions, setDimensions] = useState({ + columns: stdout.columns || 80, + rows: stdout.rows || 24, + }); + const [isResizing, setIsResizing] = useState(false); + + useEffect(() => { + let debounceTimer: NodeJS.Timeout | null = null; + + const handleResize = () => { + setIsResizing(true); + + if (debounceTimer) { + clearTimeout(debounceTimer); + } + + debounceTimer = setTimeout(() => { + setDimensions({ + columns: stdout.columns, + rows: stdout.rows, + }); + setIsResizing(false); + }, debounce); + }; + + stdout.on("resize", handleResize); + return () => { + stdout.removeListener("resize", handleResize); + if (debounceTimer) { + clearTimeout(debounceTimer); + } + }; + }, [stdout]); + + return { ...dimensions, isResizing }; +}; + +export default useTerminalSize; From 6eb3a4a11d6f74a3ca81cde1e6e007568c702110 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 25 Jul 2025 16:07:12 +0700 Subject: [PATCH 2/4] fix: useTerminalSize tweaks --- src/ui/hooks/useTerminalSize.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ui/hooks/useTerminalSize.ts b/src/ui/hooks/useTerminalSize.ts index b2271f4a6..41bcbcfd3 100644 --- a/src/ui/hooks/useTerminalSize.ts +++ b/src/ui/hooks/useTerminalSize.ts @@ -1,11 +1,14 @@ import { useEffect, useState } from "react"; import { useStdout } from "ink"; +const DEFAULT_ROWS = 24; +const DEFAULT_COLS = 80; + const useTerminalSize = (debounce = 100) => { const { stdout } = useStdout(); const [dimensions, setDimensions] = useState({ - columns: stdout.columns || 80, - rows: stdout.rows || 24, + columns: stdout.columns || DEFAULT_COLS, + rows: stdout.rows || DEFAULT_ROWS, }); const [isResizing, setIsResizing] = useState(false); @@ -21,8 +24,8 @@ const useTerminalSize = (debounce = 100) => { debounceTimer = setTimeout(() => { setDimensions({ - columns: stdout.columns, - rows: stdout.rows, + columns: stdout.columns || DEFAULT_COLS, + rows: stdout.rows || DEFAULT_ROWS, }); setIsResizing(false); }, debounce); @@ -35,7 +38,7 @@ const useTerminalSize = (debounce = 100) => { clearTimeout(debounceTimer); } }; - }, [stdout]); + }, [stdout, debounce]); return { ...dimensions, isResizing }; }; From 9e39d8483ca1232fb337d2cb50a5aa64cc6b6bc3 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Fri, 25 Jul 2025 16:49:40 +0700 Subject: [PATCH 3/4] feat: posthog telemetry: chat, sessionStart, and slash commands --- package-lock.json | 14 ++++++- package.json | 1 + src/commands/chat.ts | 2 + src/slashCommands.ts | 28 ++++++++++++- src/telemetry/posthogService.ts | 69 +++++++++++++++++++++++++++++++++ src/ui/hooks/useChat.ts | 14 +++++++ 6 files changed, 124 insertions(+), 4 deletions(-) create mode 100644 src/telemetry/posthogService.ts diff --git a/package-lock.json b/package-lock.json index 39059bba9..65348ad4a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@continuedev/cli", - "version": "1.4.2", + "version": "0.0.0-dev", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/cli", - "version": "1.4.2", + "version": "0.0.0-dev", "license": "Apache-2.0", "dependencies": { "@continuedev/config-yaml": "^1.0.96", @@ -38,6 +38,7 @@ "minimatch": "^10.0.3", "node-fetch": "^3.3.2", "open": "^10.1.0", + "posthog-node": "^5.6.0", "react": "^19.1.0", "readline-sync": "^1.4.10", "turndown": "^7.2.0", @@ -14123,6 +14124,15 @@ "node": ">=4" } }, + "node_modules/posthog-node": { + "version": "5.6.0", + "resolved": "https://registry.npmjs.org/posthog-node/-/posthog-node-5.6.0.tgz", + "integrity": "sha512-MVXxKmqAYp2cPBrN1YMhnhYsJYIu6yc6wumbHz1dbo67wZBf2WtMm67Uh+4VCrp07049qierWlxQqz1W5zGDeg==", + "license": "MIT", + "engines": { + "node": ">=20" + } + }, "node_modules/pretty-format": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", diff --git a/package.json b/package.json index c94b0338b..1c29f9e77 100644 --- a/package.json +++ b/package.json @@ -60,6 +60,7 @@ "minimatch": "^10.0.3", "node-fetch": "^3.3.2", "open": "^10.1.0", + "posthog-node": "^5.6.0", "react": "^19.1.0", "readline-sync": "^1.4.10", "turndown": "^7.2.0", diff --git a/src/commands/chat.ts b/src/commands/chat.ts index b10e4a1f4..bfa759d57 100644 --- a/src/commands/chat.ts +++ b/src/commands/chat.ts @@ -17,6 +17,7 @@ import { startTUIChat } from "../ui/index.js"; import { safeStdout } from "../util/consoleOverride.js"; import { formatError } from "../util/formatError.js"; import logger from "../util/logger.js"; +import { posthogService } from "../telemetry/posthogService.js"; export interface ChatOptions { headless?: boolean; @@ -149,6 +150,7 @@ export async function chat(prompt?: string, options: ChatOptions = {}) { try { // Record session start telemetryService.recordSessionStart(); + posthogService.capture("sessionStart", {}); // Start active time tracking telemetryService.startActiveTime(); diff --git a/src/slashCommands.ts b/src/slashCommands.ts index 1cee4bda6..9777e438b 100644 --- a/src/slashCommands.ts +++ b/src/slashCommands.ts @@ -7,6 +7,7 @@ import { } from "./auth/workos.js"; import { getAllSlashCommands } from "./commands/commands.js"; import { reloadService, SERVICE_NAMES, services } from "./services/index.js"; +import { posthogService } from "./telemetry/posthogService.js"; export async function handleSlashCommands( input: string, @@ -29,14 +30,29 @@ export async function handleSlashCommands( "Available commands:", ...allCommands.map((cmd) => `/${cmd.name} - ${cmd.description}`), ].join("\n"); + posthogService.capture("useSlashCommand", { + name: "help", + }); return { output: helpMessage }; case "clear": + posthogService.capture("useSlashCommand", { + name: "clear", + }); return { clear: true, output: "Chat history cleared" }; case "exit": + posthogService.capture("useSlashCommand", { + name: "exit", + }); return { exit: true, output: "Goodbye!" }; case "config": + posthogService.capture("useSlashCommand", { + name: "config", + }); return { openConfigSelector: true }; case "login": + posthogService.capture("useSlashCommand", { + name: "login", + }); try { const newAuthState = await services.auth.login(); @@ -66,6 +82,9 @@ export async function handleSlashCommands( } case "logout": + posthogService.capture("useSlashCommand", { + name: "logout", + }); try { await services.auth.logout(); @@ -82,6 +101,9 @@ export async function handleSlashCommands( } case "whoami": + posthogService.capture("useSlashCommand", { + name: "whoami", + }); if (isAuthenticated()) { const config = loadAuthConfig(); if (config && isAuthenticatedConfig(config)) { @@ -103,6 +125,9 @@ export async function handleSlashCommands( } case "org": + posthogService.capture("useSlashCommand", { + name: "org", + }); // Organization switching command if (args.length === 0) { return { @@ -156,7 +181,6 @@ export async function handleSlashCommands( }; } } - default: const assistantPrompt = assistant.prompts?.find( (prompt) => prompt?.name === command @@ -169,4 +193,4 @@ export async function handleSlashCommands( } } return null; -} \ No newline at end of file +} diff --git a/src/telemetry/posthogService.ts b/src/telemetry/posthogService.ts new file mode 100644 index 000000000..8ea9484f7 --- /dev/null +++ b/src/telemetry/posthogService.ts @@ -0,0 +1,69 @@ +import os from "node:os"; + +import type { PostHog as PostHogType } from "posthog-node"; + +export class PosthogService { + private os: string | undefined; + private uniqueId: string; + + constructor() { + this.os = os.platform(); + this.uniqueId = "NOT_UNIQUE"; + } + + get isEnabled() { + return process.env.CONTINUE_CLI_ENABLE_TELEMETRY !== "0"; + } + + private _client: PostHogType | undefined; + private async getClient() { + if (this.isEnabled) { + if (!this._client) { + const { PostHog } = await import("posthog-node"); + this._client = new PostHog( + "phc_JS6XFROuNbhJtVCEdTSYk6gl5ArRrTNMpCcguAXlSPs", + { + host: "https://app.posthog.com", + } + ); + } + } else { + this._client = undefined; + } + return this._client; + } + + async capture(event: string, properties: { [key: string]: any }) { + const client = await this.getClient(); + if (!client) { + return; + } + + try { + const augmentedProperties = { + ...properties, + os: this.os, + extensionVersion: "", // TODO cn version + ideName: "cn", + ideType: "cli", + }; + const payload = { + distinctId: this.uniqueId, + event, + properties: augmentedProperties, + sendFeatureFlags: true, + }; + + client?.capture(payload); + } catch (e) { + console.error(`Failed to capture event: ${e}`); + } + } + + async shutdown() { + const client = await this.getClient(); + client?.shutdown(); + } +} + +export const posthogService = new PosthogService(); diff --git a/src/ui/hooks/useChat.ts b/src/ui/hooks/useChat.ts index a9ad58371..c94776863 100644 --- a/src/ui/hooks/useChat.ts +++ b/src/ui/hooks/useChat.ts @@ -17,6 +17,7 @@ import { formatError } from "../../util/formatError.js"; import logger from "../../util/logger.js"; import { DisplayMessage } from "../types.js"; +import { posthogService } from "../../telemetry/posthogService.js"; interface UseChatProps { assistant?: AssistantUnrolled; @@ -257,18 +258,27 @@ export function useChat({ const handleUserMessage = async (message: string) => { // Special handling for /org command in TUI if (message.trim() === "/org") { + posthogService.capture("useSlashCommand", { + name: "org", + }); onShowOrgSelector(); return; } // Special handling for /config command in TUI if (message.trim() === "/config") { + posthogService.capture("useSlashCommand", { + name: "config", + }); onShowConfigSelector(); return; } // Handle /exit command in remote mode if (isRemoteMode && remoteUrl && message.trim() === "/exit") { + posthogService.capture("useSlashCommand", { + name: "exit", + }); try { // Send POST request to /exit endpoint const response = await fetch(`${remoteUrl}/exit`, { @@ -379,6 +389,10 @@ export function useChat({ // Track user prompt telemetryService.logUserPrompt(message.length, message); + posthogService.capture("chat", { + model: model?.name, + provider: model?.provider, + }); // Add user message to history and display let messageContent = message; From af01e0e431417e3615e1ef8656be587c19916f0b Mon Sep 17 00:00:00 2001 From: Nate Sesti <33237525+sestinj@users.noreply.github.com> Date: Sat, 26 Jul 2025 19:42:47 -0700 Subject: [PATCH 4/4] Update src/commands/chat.ts Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- src/commands/chat.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/chat.ts b/src/commands/chat.ts index bfa759d57..6c2101521 100644 --- a/src/commands/chat.ts +++ b/src/commands/chat.ts @@ -150,7 +150,7 @@ export async function chat(prompt?: string, options: ChatOptions = {}) { try { // Record session start telemetryService.recordSessionStart(); - posthogService.capture("sessionStart", {}); + await posthogService.capture("sessionStart", {}); // Start active time tracking telemetryService.startActiveTime();