feat: convert absolute paths to relative paths in tool display
This commit is contained in:
parent
daae97242f
commit
2c722c485e
4 changed files with 47 additions and 4 deletions
4
package-lock.json
generated
4
package-lock.json
generated
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@continuedev/cli",
|
"name": "@continuedev/cli",
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@continuedev/cli",
|
"name": "@continuedev/cli",
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@continuedev/openai-adapters": "^1.0.18",
|
"@continuedev/openai-adapters": "^1.0.18",
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import { ContinueClient } from "@continuedev/sdk";
|
import { ContinueClient } from "@continuedev/sdk";
|
||||||
import { Box, Text, useApp } from "ink";
|
import { Box, Text, useApp } from "ink";
|
||||||
import { ChatCompletionMessageParam } from "openai/resources.mjs";
|
import { ChatCompletionMessageParam } from "openai/resources.mjs";
|
||||||
|
import path from "path";
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import { handleSlashCommands } from "../slashCommands.js";
|
import { handleSlashCommands } from "../slashCommands.js";
|
||||||
import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js";
|
import { StreamCallbacks, streamChatResponse } from "../streamChatResponse.js";
|
||||||
|
|
@ -145,7 +146,18 @@ const TUIChat: React.FC<TUIChatProps> = ({
|
||||||
|
|
||||||
// Get the first parameter value for display
|
// Get the first parameter value for display
|
||||||
const firstValue = Object.values(args)[0];
|
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) => [
|
setMessages((prev) => [
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import { Box, Text } from "ink";
|
import { Box, Text } from "ink";
|
||||||
|
import path from "path";
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { getToolDisplayName } from "../tools.js";
|
import { getToolDisplayName } from "../tools.js";
|
||||||
|
|
||||||
|
|
@ -18,6 +19,16 @@ const ToolResultSummary: React.FC<ToolResultSummaryProps> = ({
|
||||||
const chars = content.length;
|
const chars = content.length;
|
||||||
const displayName = toolName ? getToolDisplayName(toolName) : "Tool";
|
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
|
// Handle specific tool output formatting
|
||||||
switch (toolName) {
|
switch (toolName) {
|
||||||
case "read_file":
|
case "read_file":
|
||||||
|
|
@ -25,7 +36,7 @@ const ToolResultSummary: React.FC<ToolResultSummaryProps> = ({
|
||||||
if (content.includes("→")) {
|
if (content.includes("→")) {
|
||||||
const pathMatch = content.match(/^(.+?):/);
|
const pathMatch = content.match(/^(.+?):/);
|
||||||
const filePath = pathMatch ? pathMatch[1] : "file";
|
const filePath = pathMatch ? pathMatch[1] : "file";
|
||||||
return `${displayName} ${filePath} (${lines} lines)`;
|
return `${displayName} ${formatPath(filePath)} (${lines} lines)`;
|
||||||
}
|
}
|
||||||
return `${displayName} tool output (${lines} lines)`;
|
return `${displayName} tool output (${lines} lines)`;
|
||||||
|
|
||||||
|
|
|
||||||
20
test-relative-path.js
Normal file
20
test-relative-path.js
Normal 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`));
|
||||||
Loading…
Add table
Reference in a new issue