Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions packages/core/src/agents/codebase-investigator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { describe, it, expect } from 'vitest';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { CodebaseInvestigatorAgent } from './codebase-investigator.js';
import {
GLOB_TOOL_NAME,
Expand All @@ -17,9 +17,24 @@ import { makeFakeConfig } from '../test-utils/config.js';

describe('CodebaseInvestigatorAgent', () => {
const config = makeFakeConfig();
const agent = CodebaseInvestigatorAgent(config);

afterEach(() => {
vi.unstubAllGlobals();
});

const mockPlatform = (platform: string) => {
vi.stubGlobal(
'process',
Object.create(process, {
platform: {
get: () => platform,
},
}),
);
};

it('should have the correct agent definition', () => {
const agent = CodebaseInvestigatorAgent(config);
expect(agent.name).toBe('codebase_investigator');
expect(agent.displayName).toBe('Codebase Investigator Agent');
expect(agent.description).toBeDefined();
Expand All @@ -39,6 +54,7 @@ describe('CodebaseInvestigatorAgent', () => {
});

it('should process output to a formatted JSON string', () => {
const agent = CodebaseInvestigatorAgent(config);
const report = {
SummaryOfFindings: 'summary',
ExplorationTrace: ['trace'],
Expand All @@ -47,4 +63,18 @@ describe('CodebaseInvestigatorAgent', () => {
const processed = agent.processOutput?.(report);
expect(processed).toBe(JSON.stringify(report, null, 2));
});

it('should include Windows-specific list command in system prompt when on Windows', () => {
mockPlatform('win32');
const agent = CodebaseInvestigatorAgent(config);
expect(agent.promptConfig.systemPrompt).toContain(
'`dir /s` (CMD) or `Get-ChildItem -Recurse` (PowerShell)',
);
});

it('should include generic list command in system prompt when on non-Windows', () => {
mockPlatform('linux');
const agent = CodebaseInvestigatorAgent(config);
expect(agent.promptConfig.systemPrompt).toContain('`ls -R`');
});
});
7 changes: 6 additions & 1 deletion packages/core/src/agents/codebase-investigator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@ export const CodebaseInvestigatorAgent = (
? PREVIEW_GEMINI_FLASH_MODEL
: DEFAULT_GEMINI_MODEL;

const listCommand =
process.platform === 'win32'
? '`dir /s` (CMD) or `Get-ChildItem -Recurse` (PowerShell)'
: '`ls -R`';

return {
name: 'codebase_investigator',
kind: 'local',
Expand Down Expand Up @@ -164,7 +169,7 @@ When you are finished, you **MUST** call the \`complete_task\` tool. The \`repor
"ExplorationTrace": [
"Used \`grep\` to search for \`updateUser\` to locate the primary function.",
"Read the file \`src/controllers/userController.js\` to understand the function's logic.",
"Used \`ls -R\` to look for related files, such as services or database models.",
"Used ${listCommand} to look for related files, such as services or database models.",
"Read \`src/services/userService.js\` and \`src/models/User.js\` to understand the data flow and how state is managed."
],
"RelevantLocations": [
Expand Down
Loading
Loading