feat: convert absolute paths to relative paths in tool display

This commit is contained in:
Nate 2025-07-14 00:25:35 -07:00
parent daae97242f
commit 2c722c485e
4 changed files with 47 additions and 4 deletions

4
package-lock.json generated
View file

@ -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",

View file

@ -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<TUIChatProps> = ({
// 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) => [

View file

@ -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<ToolResultSummaryProps> = ({
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<ToolResultSummaryProps> = ({
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)`;

20
test-relative-path.js Normal file
View file

@ -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`));