sourcegraph / cody

AI that knows your entire codebase
https://cody.dev
Apache License 2.0
2.24k stars 213 forks source link

CLI: print to stdout instead of stderr #4652

Closed olafurpg closed 1 week ago

olafurpg commented 1 week ago

Fixes CODY-2502

Previously, the experimental cli printed all output to stderr making it cumbersome to pipe the output into other cli tools. The reason for this was that we change console.log to become console.error when the agent cli starts up. The motivation for this behavior is that the Cody codebase has a lot of console.log statements that are used for debugging purposes, and we don't have any linting rules to prevent these statements from getting added. This PR changes the behavior so that cli uses process.stdout explicitly to ensure the cli output goes to stdout. This gives us fine-grained control over what the cli outputs.

Implementation detail: I considered fixing this issue by removing the console.log remapping to console.error when we run the cli. I'm not 100% opposed to this approach because I don't like writing process.stdout.write(... + '\n'). However, I chose not to go this route because I think it's important for cli tools to be intentional about what goes to stdout since it's effectively the contract/API of the cli.

Test plan

  1. The agent is implemented as a JSON-RPC server that interacts with Cody via stdout/stdin. This is mentioned in the /agent/README.md file. [...]
    
    <!-- Required. See https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles. -->