diff --git a/packages/ai/src/steps/docs-agent/docs-agent-step.ts b/packages/ai/src/steps/docs-agent/docs-agent-step.ts index 8aa6ee0af..1dbbd913b 100644 --- a/packages/ai/src/steps/docs-agent/docs-agent-step.ts +++ b/packages/ai/src/steps/docs-agent/docs-agent-step.ts @@ -83,6 +83,18 @@ const docsAgentExecution = async ({ }); try { + // Get current working directory from sandbox + let cwdMessage = ''; + if (sandbox) { + try { + const pwdResult = await sandbox.process.executeCommand('pwd'); + const currentDir = pwdResult.result.trim(); + cwdMessage = `cwd: ${currentDir}`; + } catch (error) { + console.warn('[DocsAgent] Failed to get current working directory:', error); + } + } + // Get the docs agent instructions with the current date const instructions = getDocsInstructions(); const repositoryStructure = `\n${inputData.repositoryTree}\n`; @@ -110,6 +122,14 @@ const docsAgentExecution = async ({ } as CoreMessage, ]; + // Add cwd message if available (after todo list) + if (cwdMessage) { + messages.push({ + role: 'user', + content: cwdMessage, + } as CoreMessage); + } + // Execute the docs agent const result = await docsAgent.stream(messages, { instructions, diff --git a/packages/ai/src/tools/file-tools/grep-search-tool/grep-search-tool.ts b/packages/ai/src/tools/file-tools/grep-search-tool/grep-search-tool.ts index 1474088a9..7bf078b69 100644 --- a/packages/ai/src/tools/file-tools/grep-search-tool/grep-search-tool.ts +++ b/packages/ai/src/tools/file-tools/grep-search-tool/grep-search-tool.ts @@ -48,23 +48,28 @@ const rgSearchExecution = wrapTraced( // Execute all commands concurrently const resultPromises = commands.map(async (command) => { try { + // Use executeCommand like bash-tool does const result = await sandbox.process.executeCommand(command); - // Exit code 1 means no matches found, which is not an error for rg - if (result.exitCode === 0 || result.exitCode === 1) { + // The sandbox returns the full output in result.result + const output = (result.result || '').trim(); + + // For ripgrep, exit code 1 means no matches found, which is not an error + const isRgNoMatchesFound = result.exitCode === 1 && command.includes('rg '); + + if (result.exitCode === 0 || isRgNoMatchesFound) { return { success: true, command: command, - stdout: result.result || '', + stdout: output, stderr: '', }; } - return { success: false, command: command, stdout: '', - stderr: result.result || '', + stderr: output, error: `Command failed with exit code ${result.exitCode}`, }; } catch (error) { diff --git a/packages/ai/src/workflows/docs-agent/docs-agent-workflow.int.test.ts b/packages/ai/src/workflows/docs-agent/docs-agent-workflow.int.test.ts index ade570897..0437a2faa 100644 --- a/packages/ai/src/workflows/docs-agent/docs-agent-workflow.int.test.ts +++ b/packages/ai/src/workflows/docs-agent/docs-agent-workflow.int.test.ts @@ -94,7 +94,7 @@ describe('docs-agent-workflow', () => { }); const input = createTestWorkflowInput({ - message: TEST_MESSAGES.documentSpecific, // Use simpler test message + message: TEST_MESSAGES.documentAll, // Use simpler test message context, });