From 4382abe3458caa000af73008d603e5310c865cde Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 11:01:18 -0400 Subject: [PATCH 1/8] fix: use static to avoid rerenders --- src/ui/TUIChat.tsx | 24 ++++----- src/ui/components/StaticChatContent.tsx | 70 +++++++++++++++++++++++++ 2 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 src/ui/components/StaticChatContent.tsx diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 9c88dddb3..e3c8bc27c 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -14,6 +14,7 @@ import { import { getGitRemoteUrl, isGitRepo } from "../util/git.js"; import { ModeIndicator } from "./components/ModeIndicator.js"; +import { StaticChatContent } from "./components/StaticChatContent.js"; import { ToolPermissionSelector } from "./components/ToolPermissionSelector.js"; import { ConfigSelector } from "./ConfigSelector.js"; import { useNavigation } from "./context/NavigationContext.js"; @@ -25,7 +26,6 @@ import { useConfigSelector } from "./hooks/useConfigSelector.js"; import { useMessageRenderer } from "./hooks/useMessageRenderer.js"; import { useModelSelector } from "./hooks/useModelSelector.js"; import { useOrganizationSelector } from "./hooks/useOrganizationSelector.js"; -import { IntroMessage } from "./IntroMessage.js"; import { LoadingAnimation } from "./LoadingAnimation.js"; import { ModelSelector } from "./ModelSelector.js"; import { OrganizationSelector } from "./OrganizationSelector.js"; @@ -241,19 +241,15 @@ const TUIChat: React.FC = ({ /> )} */} - {/* Show intro message when ready */} - {showIntroMessage && - !isRemoteMode && - services.config?.config && - services.model?.model && - services.mcp?.mcpService && ( - - )} - {messages.map(renderMessage)} + {/* Chat content with intro message and messages in static container */} + {/* Fixed bottom section */} diff --git a/src/ui/components/StaticChatContent.tsx b/src/ui/components/StaticChatContent.tsx new file mode 100644 index 000000000..7ee1a4d49 --- /dev/null +++ b/src/ui/components/StaticChatContent.tsx @@ -0,0 +1,70 @@ +import type { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; +import { Static } from "ink"; +import React from "react"; + +import type { MCPService } from "../../mcp.js"; +import { IntroMessage } from "../IntroMessage.js"; +import type { DisplayMessage } from "../types.js"; + +interface StaticChatContentProps { + showIntroMessage: boolean; + config?: AssistantUnrolled; + model?: ModelConfig; + mcpService?: MCPService; + messages: DisplayMessage[]; + renderMessage: (message: DisplayMessage, index: number) => React.ReactElement; +} + +export const StaticChatContent: React.FC = ({ + showIntroMessage, + config, + model, + mcpService, + messages, + renderMessage, +}) => { + // Create a combined array of items to render + const staticItems = React.useMemo(() => { + const items: Array<{ + type: "intro" | "message"; + data: DisplayMessage | null; + index?: number; + }> = []; + + // Add intro message as first item if it should be shown + if (showIntroMessage && config && model && mcpService) { + items.push({ type: "intro", data: null }); + } + + // Add all chat messages + messages.forEach((message, index) => { + items.push({ type: "message", data: message, index }); + }); + + return items; + }, [showIntroMessage, config, model, mcpService, messages]); + + return ( + + {(item) => { + if (item.type === "intro" && config && model && mcpService) { + return ( + + ); + } else if ( + item.type === "message" && + item.data && + item.index !== undefined + ) { + return renderMessage(item.data, item.index); + } + return null; + }} + + ); +}; From 97a2574175302647a5155640d315af12821a44b0 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 11:21:07 -0400 Subject: [PATCH 2/8] fix: line wrapping --- src/ui/components/StaticChatContent.test.tsx | 137 +++++++++++++++++++ src/ui/components/StaticChatContent.tsx | 10 +- 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 src/ui/components/StaticChatContent.test.tsx diff --git a/src/ui/components/StaticChatContent.test.tsx b/src/ui/components/StaticChatContent.test.tsx new file mode 100644 index 000000000..7f8b7f005 --- /dev/null +++ b/src/ui/components/StaticChatContent.test.tsx @@ -0,0 +1,137 @@ +import { render } from "ink-testing-library"; +import React from "react"; +import { vi } from "vitest"; + +import type { DisplayMessage } from "../types.js"; + +import { StaticChatContent } from "./StaticChatContent.js"; + +describe("StaticChatContent", () => { + const mockRenderMessage = vi.fn((message: DisplayMessage, index: number) => ( +
+ {message.content} +
+ )); + + beforeEach(() => { + mockRenderMessage.mockClear(); + }); + + it("should handle long assistant message content with proper width constraints", () => { + // Create a very long message that should wrap + const longMessage = "This is a very long assistant message that should wrap properly at the terminal width boundary instead of overflowing or creating poor line wrapping with every other line having only a few characters and otherwise being empty. ".repeat(5); + + const messages: DisplayMessage[] = [ + { + role: "assistant", + content: longMessage.trim(), + }, + ]; + + const { lastFrame } = render( + + ); + + // Verify that renderMessage was called with the long content + expect(mockRenderMessage).toHaveBeenCalledWith(messages[0], 0); + + // Check that the content is rendered + expect(lastFrame()).toContain(longMessage.substring(0, 50)); + }); + + it("should apply width constraints to Static component when terminal width is available", () => { + // Mock terminal width + const mockStdout = { + columns: 80, + rows: 24, + }; + + // Override process.stdout for this test + const originalStdout = process.stdout; + Object.defineProperty(process, 'stdout', { + value: mockStdout, + configurable: true, + }); + + const messages: DisplayMessage[] = [ + { + role: "assistant", + content: "Test message for width constraints", + }, + ]; + + const { lastFrame } = render( + + ); + + expect(mockRenderMessage).toHaveBeenCalled(); + expect(lastFrame()).toContain("Test message for width constraints"); + + // Restore original stdout + Object.defineProperty(process, 'stdout', { + value: originalStdout, + configurable: true, + }); + }); + + it("should render intro message when showIntroMessage is true and services are available", () => { + const mockConfig = { name: "test-config" } as any; + const mockModel = { name: "test-model" } as any; + const mockMcpService = { name: "test-mcp" } as any; + + const { lastFrame } = render( + + ); + + // Should render intro message (specific content depends on IntroMessage component) + const output = lastFrame(); + expect(output).toBeDefined(); + }); + + it("should render both intro message and chat messages in correct order", () => { + const mockConfig = { name: "test-config" } as any; + const mockModel = { name: "test-model" } as any; + const mockMcpService = { name: "test-mcp" } as any; + + const messages: DisplayMessage[] = [ + { + role: "user", + content: "Hello", + }, + { + role: "assistant", + content: "Hi there!", + }, + ]; + + const { lastFrame } = render( + + ); + + // Should render both intro and messages + expect(mockRenderMessage).toHaveBeenCalledWith(messages[0], 0); + expect(mockRenderMessage).toHaveBeenCalledWith(messages[1], 1); + }); +}); \ No newline at end of file diff --git a/src/ui/components/StaticChatContent.tsx b/src/ui/components/StaticChatContent.tsx index 7ee1a4d49..1575b21f9 100644 --- a/src/ui/components/StaticChatContent.tsx +++ b/src/ui/components/StaticChatContent.tsx @@ -3,6 +3,7 @@ import { Static } from "ink"; import React from "react"; import type { MCPService } from "../../mcp.js"; +import { useTerminalSize } from "../hooks/useTerminalSize.js"; import { IntroMessage } from "../IntroMessage.js"; import type { DisplayMessage } from "../types.js"; @@ -23,6 +24,7 @@ export const StaticChatContent: React.FC = ({ messages, renderMessage, }) => { + const { columns } = useTerminalSize(); // Create a combined array of items to render const staticItems = React.useMemo(() => { const items: Array<{ @@ -45,7 +47,13 @@ export const StaticChatContent: React.FC = ({ }, [showIntroMessage, config, model, mcpService, messages]); return ( - + {(item) => { if (item.type === "intro" && config && model && mcpService) { return ( From 60879d8308b598a6fe8c74ed9163279cb605501c Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 11:28:34 -0400 Subject: [PATCH 3/8] remove test that won't work in CI --- src/ui/components/StaticChatContent.test.tsx | 137 ------------------- 1 file changed, 137 deletions(-) delete mode 100644 src/ui/components/StaticChatContent.test.tsx diff --git a/src/ui/components/StaticChatContent.test.tsx b/src/ui/components/StaticChatContent.test.tsx deleted file mode 100644 index 7f8b7f005..000000000 --- a/src/ui/components/StaticChatContent.test.tsx +++ /dev/null @@ -1,137 +0,0 @@ -import { render } from "ink-testing-library"; -import React from "react"; -import { vi } from "vitest"; - -import type { DisplayMessage } from "../types.js"; - -import { StaticChatContent } from "./StaticChatContent.js"; - -describe("StaticChatContent", () => { - const mockRenderMessage = vi.fn((message: DisplayMessage, index: number) => ( -
- {message.content} -
- )); - - beforeEach(() => { - mockRenderMessage.mockClear(); - }); - - it("should handle long assistant message content with proper width constraints", () => { - // Create a very long message that should wrap - const longMessage = "This is a very long assistant message that should wrap properly at the terminal width boundary instead of overflowing or creating poor line wrapping with every other line having only a few characters and otherwise being empty. ".repeat(5); - - const messages: DisplayMessage[] = [ - { - role: "assistant", - content: longMessage.trim(), - }, - ]; - - const { lastFrame } = render( - - ); - - // Verify that renderMessage was called with the long content - expect(mockRenderMessage).toHaveBeenCalledWith(messages[0], 0); - - // Check that the content is rendered - expect(lastFrame()).toContain(longMessage.substring(0, 50)); - }); - - it("should apply width constraints to Static component when terminal width is available", () => { - // Mock terminal width - const mockStdout = { - columns: 80, - rows: 24, - }; - - // Override process.stdout for this test - const originalStdout = process.stdout; - Object.defineProperty(process, 'stdout', { - value: mockStdout, - configurable: true, - }); - - const messages: DisplayMessage[] = [ - { - role: "assistant", - content: "Test message for width constraints", - }, - ]; - - const { lastFrame } = render( - - ); - - expect(mockRenderMessage).toHaveBeenCalled(); - expect(lastFrame()).toContain("Test message for width constraints"); - - // Restore original stdout - Object.defineProperty(process, 'stdout', { - value: originalStdout, - configurable: true, - }); - }); - - it("should render intro message when showIntroMessage is true and services are available", () => { - const mockConfig = { name: "test-config" } as any; - const mockModel = { name: "test-model" } as any; - const mockMcpService = { name: "test-mcp" } as any; - - const { lastFrame } = render( - - ); - - // Should render intro message (specific content depends on IntroMessage component) - const output = lastFrame(); - expect(output).toBeDefined(); - }); - - it("should render both intro message and chat messages in correct order", () => { - const mockConfig = { name: "test-config" } as any; - const mockModel = { name: "test-model" } as any; - const mockMcpService = { name: "test-mcp" } as any; - - const messages: DisplayMessage[] = [ - { - role: "user", - content: "Hello", - }, - { - role: "assistant", - content: "Hi there!", - }, - ]; - - const { lastFrame } = render( - - ); - - // Should render both intro and messages - expect(mockRenderMessage).toHaveBeenCalledWith(messages[0], 0); - expect(mockRenderMessage).toHaveBeenCalledWith(messages[1], 1); - }); -}); \ No newline at end of file From f970c7a24f123509f95ff6f27d649ae05b111447 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 16:00:09 -0400 Subject: [PATCH 4/8] print the prettier version --- .github/workflows/pr_checks.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index 700498b82..b0cb0be4d 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -43,6 +43,9 @@ jobs: - name: Install dependencies run: npm ci + - name: Print prettier version + run: npx prettier --version + - name: Check code formatting run: npm run format:check From 9f5e8aa3be272c50c620bc346a4971d37839b3ac Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 19:50:53 -0400 Subject: [PATCH 5/8] show prettier diff in ci --- .github/workflows/pr_checks.yml | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index b0cb0be4d..567fa151f 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -43,8 +43,37 @@ jobs: - name: Install dependencies run: npm ci - - name: Print prettier version - run: npx prettier --version + - name: Debug environment info + run: | + echo "Node.js version: $(node --version)" + echo "npm version: $(npm --version)" + echo "Prettier version: $(npx prettier --version)" + echo "Platform: $(uname -a)" + + - name: Show formatting differences for all files + run: | + echo "Finding files that would be changed by prettier..." + # Get list of files that prettier would change + UNFORMATTED_FILES=$(npx prettier --check . 2>&1 | grep -E '^\[warn\]' | sed 's/\[warn\] //' || true) + + if [ -z "$UNFORMATTED_FILES" ]; then + echo "No files need formatting changes." + else + echo "Files that need formatting:" + echo "$UNFORMATTED_FILES" + echo "" + echo "Showing diffs for each file:" + echo "$UNFORMATTED_FILES" | while read -r file; do + if [ -n "$file" ] && [ -f "$file" ]; then + echo "======================================" + echo "Diff for: $file" + echo "======================================" + npx prettier "$file" > "/tmp/$(basename "$file").formatted" + diff -u "$file" "/tmp/$(basename "$file").formatted" || true + echo "" + fi + done + fi - name: Check code formatting run: npm run format:check From 20e03982c69a67d21e787779def187974551f667 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 20:02:50 -0400 Subject: [PATCH 6/8] try again --- .github/workflows/pr_checks.yml | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index 567fa151f..d681d8c32 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -52,24 +52,33 @@ jobs: - name: Show formatting differences for all files run: | - echo "Finding files that would be changed by prettier..." - # Get list of files that prettier would change - UNFORMATTED_FILES=$(npx prettier --check . 2>&1 | grep -E '^\[warn\]' | sed 's/\[warn\] //' || true) + echo "Running prettier check to find unformatted files..." + # Capture prettier output to a temp file + npx prettier --check . > /tmp/prettier_output.txt 2>&1 || true + + echo "Full prettier output:" + cat /tmp/prettier_output.txt + echo "" + + # Extract files that need formatting + UNFORMATTED_FILES=$(grep -E '^\[warn\]' /tmp/prettier_output.txt | sed 's/\[warn\] //' || true) if [ -z "$UNFORMATTED_FILES" ]; then - echo "No files need formatting changes." + echo "No files found in [warn] messages." else echo "Files that need formatting:" echo "$UNFORMATTED_FILES" echo "" echo "Showing diffs for each file:" - echo "$UNFORMATTED_FILES" | while read -r file; do + echo "$UNFORMATTED_FILES" | while IFS= read -r file; do if [ -n "$file" ] && [ -f "$file" ]; then echo "======================================" echo "Diff for: $file" echo "======================================" - npx prettier "$file" > "/tmp/$(basename "$file").formatted" - diff -u "$file" "/tmp/$(basename "$file").formatted" || true + # Create formatted version + npx prettier "$file" > "/tmp/formatted_$(basename "$file")" + # Show diff + diff -u "$file" "/tmp/formatted_$(basename "$file")" || true echo "" fi done From ae5909a6bdf0487371ead49c4e14ee0147cb5ac3 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 20:10:52 -0400 Subject: [PATCH 7/8] try again --- .github/workflows/pr_checks.yml | 44 +++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index d681d8c32..eb54aa4f3 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -53,35 +53,59 @@ jobs: - name: Show formatting differences for all files run: | echo "Running prettier check to find unformatted files..." - # Capture prettier output to a temp file - npx prettier --check . > /tmp/prettier_output.txt 2>&1 || true + # Capture prettier output without colors + npx prettier --no-color --check . > /tmp/prettier_output.txt 2>&1 || true echo "Full prettier output:" cat /tmp/prettier_output.txt echo "" - # Extract files that need formatting - UNFORMATTED_FILES=$(grep -E '^\[warn\]' /tmp/prettier_output.txt | sed 's/\[warn\] //' || true) + # Debug: show raw bytes of the output + echo "Raw output (showing first 500 bytes):" + head -c 500 /tmp/prettier_output.txt | hexdump -C + echo "" + + # Extract files that need formatting (try multiple patterns) + echo "Trying different grep patterns:" + echo "Pattern 1 - looking for [warn]:" + grep '\[warn\]' /tmp/prettier_output.txt || echo "No matches for [warn]" + echo "Pattern 2 - looking for warn:" + grep 'warn' /tmp/prettier_output.txt || echo "No matches for warn" + echo "Pattern 3 - lines containing file extensions:" + grep -E '\.(ts|tsx|js|jsx|yml|yaml|json)' /tmp/prettier_output.txt || echo "No file extensions found" + + # Try to extract filenames more robustly + UNFORMATTED_FILES=$(grep '\[warn\]' /tmp/prettier_output.txt | sed 's/.*\[warn\][[:space:]]*//' || true) if [ -z "$UNFORMATTED_FILES" ]; then - echo "No files found in [warn] messages." - else + echo "No files found in [warn] messages. Trying alternative extraction..." + # Alternative: look for lines that look like file paths + UNFORMATTED_FILES=$(grep -E '^[^\[]*\.(ts|tsx|js|jsx|yml|yaml|json)' /tmp/prettier_output.txt || true) + fi + + if [ -n "$UNFORMATTED_FILES" ]; then echo "Files that need formatting:" echo "$UNFORMATTED_FILES" echo "" echo "Showing diffs for each file:" echo "$UNFORMATTED_FILES" | while IFS= read -r file; do - if [ -n "$file" ] && [ -f "$file" ]; then + # Clean up the filename (remove any remaining brackets or whitespace) + clean_file=$(echo "$file" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//') + if [ -n "$clean_file" ] && [ -f "$clean_file" ]; then echo "======================================" - echo "Diff for: $file" + echo "Diff for: $clean_file" echo "======================================" # Create formatted version - npx prettier "$file" > "/tmp/formatted_$(basename "$file")" + npx prettier --no-color "$clean_file" > "/tmp/formatted_$(basename "$clean_file")" # Show diff - diff -u "$file" "/tmp/formatted_$(basename "$file")" || true + diff -u "$clean_file" "/tmp/formatted_$(basename "$clean_file")" || true echo "" + else + echo "File not found or empty: '$clean_file'" fi done + else + echo "Still no files found. This might indicate a parsing issue." fi - name: Check code formatting From ee64d4e5f78f97ac9741e5f80e6640a24e71a645 Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 10 Aug 2025 20:20:07 -0400 Subject: [PATCH 8/8] fix formatting issues --- .github/workflows/pr_checks.yml | 58 --------------------------------- src/telemetry/posthogService.ts | 6 ++-- 2 files changed, 3 insertions(+), 61 deletions(-) diff --git a/.github/workflows/pr_checks.yml b/.github/workflows/pr_checks.yml index eb54aa4f3..3f8922952 100644 --- a/.github/workflows/pr_checks.yml +++ b/.github/workflows/pr_checks.yml @@ -50,64 +50,6 @@ jobs: echo "Prettier version: $(npx prettier --version)" echo "Platform: $(uname -a)" - - name: Show formatting differences for all files - run: | - echo "Running prettier check to find unformatted files..." - # Capture prettier output without colors - npx prettier --no-color --check . > /tmp/prettier_output.txt 2>&1 || true - - echo "Full prettier output:" - cat /tmp/prettier_output.txt - echo "" - - # Debug: show raw bytes of the output - echo "Raw output (showing first 500 bytes):" - head -c 500 /tmp/prettier_output.txt | hexdump -C - echo "" - - # Extract files that need formatting (try multiple patterns) - echo "Trying different grep patterns:" - echo "Pattern 1 - looking for [warn]:" - grep '\[warn\]' /tmp/prettier_output.txt || echo "No matches for [warn]" - echo "Pattern 2 - looking for warn:" - grep 'warn' /tmp/prettier_output.txt || echo "No matches for warn" - echo "Pattern 3 - lines containing file extensions:" - grep -E '\.(ts|tsx|js|jsx|yml|yaml|json)' /tmp/prettier_output.txt || echo "No file extensions found" - - # Try to extract filenames more robustly - UNFORMATTED_FILES=$(grep '\[warn\]' /tmp/prettier_output.txt | sed 's/.*\[warn\][[:space:]]*//' || true) - - if [ -z "$UNFORMATTED_FILES" ]; then - echo "No files found in [warn] messages. Trying alternative extraction..." - # Alternative: look for lines that look like file paths - UNFORMATTED_FILES=$(grep -E '^[^\[]*\.(ts|tsx|js|jsx|yml|yaml|json)' /tmp/prettier_output.txt || true) - fi - - if [ -n "$UNFORMATTED_FILES" ]; then - echo "Files that need formatting:" - echo "$UNFORMATTED_FILES" - echo "" - echo "Showing diffs for each file:" - echo "$UNFORMATTED_FILES" | while IFS= read -r file; do - # Clean up the filename (remove any remaining brackets or whitespace) - clean_file=$(echo "$file" | sed 's/^[[:space:]]*//; s/[[:space:]]*$//') - if [ -n "$clean_file" ] && [ -f "$clean_file" ]; then - echo "======================================" - echo "Diff for: $clean_file" - echo "======================================" - # Create formatted version - npx prettier --no-color "$clean_file" > "/tmp/formatted_$(basename "$clean_file")" - # Show diff - diff -u "$clean_file" "/tmp/formatted_$(basename "$clean_file")" || true - echo "" - else - echo "File not found or empty: '$clean_file'" - fi - done - else - echo "Still no files found. This might indicate a parsing issue." - fi - - name: Check code formatting run: npm run format:check diff --git a/src/telemetry/posthogService.ts b/src/telemetry/posthogService.ts index bfbef6ec8..ef66bfc69 100644 --- a/src/telemetry/posthogService.ts +++ b/src/telemetry/posthogService.ts @@ -1,11 +1,11 @@ import os from "node:os"; -import * as node_machine_id from 'node-machine-id'; +import * as node_machine_id from "node-machine-id"; import type { PostHog as PostHogType } from "posthog-node"; -import { loadAuthConfig, isAuthenticatedConfig } from "../auth/workos.js"; +import { isAuthenticatedConfig, loadAuthConfig } from "../auth/workos.js"; - export class PosthogService { +export class PosthogService { private os: string | undefined; private uniqueId: string;