From e933c56f7c8a09dd41afbdab9720ebd8833cfd04 Mon Sep 17 00:00:00 2001 From: Nate Date: Wed, 23 Jul 2025 09:53:49 -0700 Subject: [PATCH] cn serve intro message and move version t rght --- src/asciiArt.ts | 4 +++- src/commands/chat.ts | 32 ++++++++++++++++++++++---------- src/commands/serve.ts | 13 +++++++++++++ src/ui/TUIChat.tsx | 20 ++++++++++++++++++++ 4 files changed, 58 insertions(+), 11 deletions(-) diff --git a/src/asciiArt.ts b/src/asciiArt.ts index 305cf75c5..b5b853c59 100644 --- a/src/asciiArt.ts +++ b/src/asciiArt.ts @@ -1,4 +1,5 @@ import chalk from "chalk"; +import { getVersion } from "./version.js"; const b = chalk.bold.magenta; const d = chalk.dim; @@ -8,7 +9,8 @@ export const CONTINUE_ASCII_ART = ` ${b("/ ___/")}${d(" __ \\")}${b("/ |/ /")}${d("_ __/ _/ |/ / / / / __/")} ${b("/ /__")}${d("/ /_/ ")}${b("/ /")}${d(" / / _/ // / /_/ / _/ ")} ${b("\\___/")}${d("\\____")}${b("/_/|_/")}${d(" /_/ /___/_/|_/\\____/___/")} -`; + + ${d("v" + getVersion())}`; // export const CONTINUE_ASCII_ART = ` // _________ _ _____________ ____ ______ // / ___/ __ \\/ |/ /_ __/ _/ |/ / / / / __/ diff --git a/src/commands/chat.ts b/src/commands/chat.ts index 6a076b940..9a02ac2e8 100644 --- a/src/commands/chat.ts +++ b/src/commands/chat.ts @@ -2,8 +2,10 @@ import chalk from "chalk"; import { ChatCompletionMessageParam } from "openai/resources.mjs"; import * as readlineSync from "readline-sync"; import { CONTINUE_ASCII_ART } from "../asciiArt.js"; +import { loadAuthConfig } from "../auth/workos.js"; import { configureLogger } from "../logger.js"; import * as logging from "../logging.js"; +import { initializeWithOnboarding } from "../onboarding.js"; import { initializeServices } from "../services/index.js"; import { serviceContainer } from "../services/ServiceContainer.js"; import { ModelServiceState, SERVICE_NAMES } from "../services/types.js"; @@ -15,7 +17,6 @@ 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 { getVersion } from "../version.js"; export interface ChatOptions { headless?: boolean; @@ -152,18 +153,29 @@ export async function chat(prompt?: string, options: ChatOptions = {}) { // Start active time tracking telemetryService.startActiveTime(); - // If not in headless mode, start the TUI chat (default) + // If not in headless mode, check for onboarding first if (!options.headless) { - // Show ASCII art and version for TUI mode - console.log(chalk.white(CONTINUE_ASCII_ART)); - console.info( - chalk.gray( - `${" ".repeat( - CONTINUE_ASCII_ART.trimEnd().split("\n").pop()!.length - )}v${getVersion()}\n` - ) + // Load auth config to check for onboarding + const authConfig = loadAuthConfig(); + + // Run onboarding check - this will handle first-time setup + const onboardingResult = await initializeWithOnboarding( + authConfig, + options.config, + options.rule ); + // If onboarding was completed (user just went through setup), exit gracefully + if (onboardingResult.wasOnboarded) { + console.log( + chalk.green("✓ Setup complete! Run 'cn' again to start chatting.") + ); + return; + } + + // Show ASCII art and version for TUI mode + console.log(CONTINUE_ASCII_ART); + // Start TUI immediately - it will handle service loading await startTUIChat(prompt, options.resume, options.config, options.rule); return; diff --git a/src/commands/serve.ts b/src/commands/serve.ts index 31e13bcf8..55d322e62 100644 --- a/src/commands/serve.ts +++ b/src/commands/serve.ts @@ -6,6 +6,7 @@ import path from "path"; import { promisify } from "util"; import { ensureOrganization, + getAssistantSlug, getOrganizationId, loadAuthConfig, } from "../auth/workos.js"; @@ -71,6 +72,18 @@ export async function serve(prompt?: string, options: ServeOptions = {}) { } } + // Log configuration information + const organizationId = getOrganizationId(finalAuthConfig || authConfig) || 'personal'; + const assistantName = config.name; + const assistantSlug = getAssistantSlug(finalAuthConfig || authConfig); + const modelProvider = model.provider; + const modelName = model.model; + + console.log(chalk.blue(`\nConfiguration:`)); + console.log(chalk.dim(` Organization: ${organizationId}`)); + console.log(chalk.dim(` Assistant: ${assistantName}${assistantSlug ? ` (${assistantSlug})` : ''}`)); + console.log(chalk.dim(` Model: ${modelProvider}/${modelName}`)); + // Initialize chat history let chatHistory: ChatCompletionMessageParam[] = []; const systemMessage = await constructSystemMessage("", options.rule); diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 61d64bbfd..0f5af68f5 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -1,5 +1,6 @@ import { Box, Text } from "ink"; import React, { useEffect, useState } from "react"; +import { introMessage } from "../intro.js"; import { useServices } from "../hooks/useService.js"; import { ApiClientServiceState, @@ -76,6 +77,25 @@ const TUIChat: React.FC = ({ }); }, []); + // Display intro message when services are ready (only in non-remote mode) + useEffect(() => { + if ( + !isRemoteMode && + allServicesReady && + services.config?.config && + services.model?.model && + services.mcp?.mcpService + ) { + introMessage( + services.config.config, + services.model.model, + services.mcp.mcpService + ).catch((error) => { + console.error("Failed to display intro message:", error); + }); + } + }, [isRemoteMode, allServicesReady, services.config?.config, services.model?.model, services.mcp?.mcpService]); + // Custom login prompt handler for TUI const handleLoginPrompt = (promptText: string): Promise => { return new Promise((resolve) => {