From 2c722c485eea4c3c283fb643193a4b1ffe14bf7f Mon Sep 17 00:00:00 2001 From: Nate Date: Mon, 14 Jul 2025 00:25:35 -0700 Subject: [PATCH] feat: convert absolute paths to relative paths in tool display --- package-lock.json | 4 ++-- src/ui/TUIChat.tsx | 14 +++++++++++++- src/ui/ToolResultSummary.tsx | 13 ++++++++++++- test-relative-path.js | 20 ++++++++++++++++++++ 4 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 test-relative-path.js diff --git a/package-lock.json b/package-lock.json index 3ea880e57..93e9eafa3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@continuedev/cli", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@continuedev/cli", - "version": "1.0.1", + "version": "1.1.0", "license": "Apache-2.0", "dependencies": { "@continuedev/openai-adapters": "^1.0.18", diff --git a/src/ui/TUIChat.tsx b/src/ui/TUIChat.tsx index 25db23d85..2cf78a875 100644 --- a/src/ui/TUIChat.tsx +++ b/src/ui/TUIChat.tsx @@ -1,6 +1,7 @@ import { ContinueClient } from "@continuedev/sdk"; import { Box, Text, useApp } from "ink"; import { ChatCompletionMessageParam } from "openai/resources.mjs"; +import path from "path"; import React, { useEffect, useState } from "react"; import { handleSlashCommands } from "../slashCommands.js"; import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js"; @@ -145,7 +146,18 @@ const TUIChat: React.FC = ({ // Get the first parameter value for display const firstValue = Object.values(args)[0]; - return `${displayName}(${firstValue || ""})`; + + // Convert absolute paths to relative paths from workspace root + const formatPath = (value: any) => { + if (typeof value === "string" && path.isAbsolute(value)) { + const workspaceRoot = process.cwd(); + const relativePath = path.relative(workspaceRoot, value); + return relativePath || value; + } + return value; + }; + + return `${displayName}(${formatPath(firstValue) || ""})`; }; setMessages((prev) => [ diff --git a/src/ui/ToolResultSummary.tsx b/src/ui/ToolResultSummary.tsx index c360f9f0b..48fc5fd6a 100644 --- a/src/ui/ToolResultSummary.tsx +++ b/src/ui/ToolResultSummary.tsx @@ -1,4 +1,5 @@ import { Box, Text } from "ink"; +import path from "path"; import React from "react"; import { getToolDisplayName } from "../tools.js"; @@ -18,6 +19,16 @@ const ToolResultSummary: React.FC = ({ const chars = content.length; const displayName = toolName ? getToolDisplayName(toolName) : "Tool"; + // Convert absolute paths to relative paths from workspace root + const formatPath = (filePath: string) => { + if (path.isAbsolute(filePath)) { + const workspaceRoot = process.cwd(); + const relativePath = path.relative(workspaceRoot, filePath); + return relativePath || filePath; + } + return filePath; + }; + // Handle specific tool output formatting switch (toolName) { case "read_file": @@ -25,7 +36,7 @@ const ToolResultSummary: React.FC = ({ if (content.includes("→")) { const pathMatch = content.match(/^(.+?):/); const filePath = pathMatch ? pathMatch[1] : "file"; - return `${displayName} ${filePath} (${lines} lines)`; + return `${displayName} ${formatPath(filePath)} (${lines} lines)`; } return `${displayName} tool output (${lines} lines)`; diff --git a/test-relative-path.js b/test-relative-path.js new file mode 100644 index 000000000..89eb4975a --- /dev/null +++ b/test-relative-path.js @@ -0,0 +1,20 @@ +import path from "path"; + +// Test the relative path conversion logic +const formatPath = (value) => { + if (typeof value === "string" && path.isAbsolute(value)) { + const workspaceRoot = process.cwd(); + const relativePath = path.relative(workspaceRoot, value); + return relativePath || value; + } + return value; +}; + +// Test cases +console.log("Current working directory:", process.cwd()); +console.log("Test absolute path:", `/Users/nate/gh/continuedev/wt-no-abs/src/continueSDK.ts`); +console.log("Converted to relative:", formatPath(`/Users/nate/gh/continuedev/wt-no-abs/src/continueSDK.ts`)); +console.log("Test relative path:", `src/continueSDK.ts`); +console.log("Remains relative:", formatPath(`src/continueSDK.ts`)); +console.log("Test root file:", `/Users/nate/gh/continuedev/wt-no-abs/package.json`); +console.log("Converted to relative:", formatPath(`/Users/nate/gh/continuedev/wt-no-abs/package.json`)); \ No newline at end of file