Skip to content

Commit bc3ed61

Browse files
authored
feat(core): refine shell tool description display logic (#24903)
1 parent 9c4e17b commit bc3ed61

File tree

2 files changed

+47
-29
lines changed

2 files changed

+47
-29
lines changed

packages/core/src/tools/shell.test.ts

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -768,6 +768,46 @@ describe('ShellTool', () => {
768768
const shellTool = new ShellTool(mockConfig, createMockMessageBus());
769769
expect(shellTool.description).not.toContain('Efficiency Guidelines:');
770770
});
771+
772+
it('should return the command if description is not provided', () => {
773+
const invocation = shellTool.build({
774+
command: 'echo "hello"',
775+
});
776+
expect(invocation.getDescription()).toBe('echo "hello"');
777+
});
778+
779+
it('should return the command if it is short (<= 150 chars), even if description is provided', () => {
780+
const invocation = shellTool.build({
781+
command: 'echo "hello"',
782+
description: 'Prints a friendly greeting.',
783+
});
784+
expect(invocation.getDescription()).toBe('echo "hello"');
785+
});
786+
787+
it('should return the description if the command is long (> 150 chars)', () => {
788+
const longCommand = 'echo "hello" && '.repeat(15) + 'echo "world"'; // Length > 150
789+
const invocation = shellTool.build({
790+
command: longCommand,
791+
description: 'Prints multiple greetings.',
792+
});
793+
expect(invocation.getDescription()).toBe('Prints multiple greetings.');
794+
});
795+
796+
it('should return the raw command if description is an empty string', () => {
797+
const invocation = shellTool.build({
798+
command: 'echo hello',
799+
description: '',
800+
});
801+
expect(invocation.getDescription()).toBe('echo hello');
802+
});
803+
804+
it('should return the raw command if description is just whitespace', () => {
805+
const invocation = shellTool.build({
806+
command: 'echo hello',
807+
description: ' ',
808+
});
809+
expect(invocation.getDescription()).toBe('echo hello');
810+
});
771811
});
772812

773813
describe('getDisplayTitle and getExplanation', () => {
@@ -803,32 +843,6 @@ describe('ShellTool', () => {
803843
});
804844
});
805845

806-
describe('invocation getDescription', () => {
807-
it('should return the description if it is present and not empty whitespace', () => {
808-
const invocation = shellTool.build({
809-
command: 'echo hello',
810-
description: 'prints hello',
811-
});
812-
expect(invocation.getDescription()).toBe('prints hello');
813-
});
814-
815-
it('should return the raw command if description is an empty string', () => {
816-
const invocation = shellTool.build({
817-
command: 'echo hello',
818-
description: '',
819-
});
820-
expect(invocation.getDescription()).toBe('echo hello');
821-
});
822-
823-
it('should return the raw command if description is just whitespace', () => {
824-
const invocation = shellTool.build({
825-
command: 'echo hello',
826-
description: ' ',
827-
});
828-
expect(invocation.getDescription()).toBe('echo hello');
829-
});
830-
});
831-
832846
describe('llmContent output format', () => {
833847
const mockAbortSignal = new AbortController().signal;
834848

packages/core/src/tools/shell.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export const OUTPUT_UPDATE_INTERVAL_MS = 1000;
6363

6464
// Delay so user does not see the output of the process before the process is moved to the background.
6565
const BACKGROUND_DELAY_MS = 200;
66+
const SHOW_NL_DESCRIPTION_THRESHOLD = 150;
6667

6768
export interface ShellToolParams {
6869
command: string;
@@ -136,9 +137,12 @@ export class ShellToolInvocation extends BaseToolInvocation<
136137
}
137138

138139
getDescription(): string {
139-
return this.params.description?.trim()
140-
? this.params.description
141-
: this.params.command;
140+
const descStr = this.params.description?.trim();
141+
const commandStr = this.params.command;
142+
return Array.from(commandStr).length <= SHOW_NL_DESCRIPTION_THRESHOLD ||
143+
!descStr
144+
? commandStr
145+
: descStr;
142146
}
143147

144148
private simplifyPaths(paths: Set<string>): string[] {

0 commit comments

Comments
 (0)