Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experimental Cody CLI #3418

Merged
merged 1 commit into from
Apr 5, 2024
Merged

experimental Cody CLI #3418

merged 1 commit into from
Apr 5, 2024

Conversation

sqs
Copy link
Member

@sqs sqs commented Mar 15, 2024

The experimental Cody CLI spawns the agent and uses it to support CLI invocations like:

cody-agent experimental-cli chat -m 'what color is the sky?'

cody-agent experimental-cli chat --context-repo github.com/sourcegraph/{sourcegraph,cody} -m 'how is authentication handled in sourcegraph/cody?'

Unlike the previous CLI (which was removed), this CLI requires almost no changes to code outside the new cli/ directory, which is a nice win for the agent architecture and means that this experimental CLI does not necessitate bad code abstractions.

Depends on #3671 to publish cody-agent binaries and packages, so that it's easy to run the CLI without building it locally from source.

Test plan

n/a

@sqs sqs requested a review from a team March 15, 2024 06:09
@sqs
Copy link
Member Author

sqs commented Mar 15, 2024

I'm finding this useful for some stuff (see https://sourcegraph.slack.com/archives/C06PK6VJU6N/p1710487118552079). Anyone else? Fine to keep it on a branch if nobody else wants it yet.

@sqs sqs force-pushed the sqs/cli branch 3 times, most recently from 8ec9383 to 81fa95f Compare March 15, 2024 07:02
Copy link
Contributor

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this but what are your thoughts of bundling this directly inside the agent? So that the single agent binary (which already has two cli args, one for starting the jsonrpc server) is the CLI? So we'd move the command to a chat command here instead: https://github.com/sourcegraph/cody/blob/main/agent/src/cli/root.ts

This would also handily give us the CLI on every non-VS-Code-client installation (in case we need to do some debugging, any additional tooling is handy!)

@enriquegh
Copy link

➕ to @philipp-spiess's comment around debugging.
I could see this is as something SE uses as a troubleshooting tool as well. Where we want to remove all IDE logic from the equation and concentrate on the agent connection to the instance

@sqs
Copy link
Member Author

sqs commented Mar 16, 2024

@philipp-spiess:

I like this but what are your thoughts of bundling this directly inside the agent? So that the single agent binary (which already has two cli args, one for starting the jsonrpc server) is the CLI? So we'd move the command to a chat command here instead: main/agent/src/cli/root.ts

This would also handily give us the CLI on every non-VS-Code-client installation (in case we need to do some debugging, any additional tooling is handy!)

That's a great idea. I will do that.

Do you think that the CLI should still spawn an agent subprocess (basically like argv[0] jsonrpc since the agent and CLI are the same script now) so that it uses the agent in the same way that editor clients do? Or should the CLI just communicate with the agent within the same Node process? I'm leaning toward the former (spawn an agent subprocess) so that we don't introduce alternate code paths for in-process CLI vs. separate-process editor usage of the agent. cc @dominiccooney @steveyegge

Also, don't need to figure this out while it's still experimental, but for beta/GA for people who just want a Cody CLI, I think we'll want a single script/program that primarily identifies itself as the CLI, instead of telling people to download something called agent and whose --help says it's the agent. That probably means making cody the name (instead of cody-agent) and then the agent would be invoked by cody agent or cody jsonrpc or something.

@philipp-spiess
Copy link
Contributor

Do you think that the CLI should still spawn an agent subprocess (basically like argv[0] jsonrpc since the agent and CLI are the same script now) so that it uses the agent in the same way that editor clients do? Or should the CLI just communicate with the agent within the same Node process? I'm leaning toward the former (spawn an agent subprocess) so that we don't introduce alternate code paths for in-process CLI vs. separate-process editor usage of the agent.

Yeah I agree that it should probably go through the same jsonrpc protocol than our other clients to avoid yet-another way of invoking these methods.

@aramaraju
Copy link

Just checking in on the status of the PR, we can get some real-world testing once it's out :) Thank you

@sqs
Copy link
Member Author

sqs commented Apr 3, 2024

@aramaraju I'm waiting on #3671, then I'll update this PR. That will make it so people can run the CLI with a single command (without installing anything), like npx @sourcegraph/cody-agent chat .... I'm hopeful this will be possible tomorrow.

@sqs sqs force-pushed the sqs/cli branch 2 times, most recently from 632aa08 to a34f046 Compare April 3, 2024 08:57
@sqs sqs marked this pull request as ready for review April 3, 2024 09:02
@sqs sqs requested review from philipp-spiess and a team April 3, 2024 09:03
@sqs
Copy link
Member Author

sqs commented Apr 3, 2024

OK, @philipp-spiess or another @sourcegraph/cody-clients reviewer: I made this a subcommand of agent: cody-agent experimental-cli chat -m 'what color is the sky?'. The instructions in the README depend on #3671 to publish cody-agent, but you can run it locally now with either:

pnpm -C agent run build && node agent/dist/index.js experimental-cli chat -m 'what color is the sky?'

## or ##

pnpm -C agent run build-agent-binaries
agent/dist/agent-linux-x64 experimental-cli chat -m 'what color is the sky?'

(I am not intending to get this into the VS Code release announcement.)

@PriNova
Copy link
Contributor

PriNova commented Apr 3, 2024

How about putting the chat in a loop for chat continuation? Until user inputs '/quit' command to gracefully exit.

@PriNova
Copy link
Contributor

PriNova commented Apr 3, 2024

@sqs I'm not 100% sure about this, but to have context during chat, the enhanced context bool needs to be set to true.

EDIT: Overlooked it. It is already set to true

Comment on lines +33 to +35
Use the [Feedback on Cody CLI (experimental feature)](https://community.sourcegraph.com/t/feedback-on-cody-cli-experimental-feature/78) thread in the Sourcegraph community forum.

Issues and PRs appreciated!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@sqs
Copy link
Member Author

sqs commented Apr 3, 2024

How about putting the chat in a loop for chat continuation? Until user inputs '/quit' command to gracefully exit.

That's a great idea. I just want to get this basic thing out first. I suppose you could use it in a while true; do ...; done loop for now until I (or someone else) adds that, though!

The experimental Cody CLI spawns the agent and uses it to support CLI invocations like:

```
pnpm run cli experimental chat -m 'what color is the sky?'

pnpm run cli experimental chat --context-repo github.com/sourcegraph/{sourcegraph,cody} -m 'how is authentication handled in sourcegraph/cody?'
```

Unlike the previous CLI (which was removed), this CLI requires *no changes* to code outside the new `cli/` directory, which is a nice win for the agent architecture and means that this experimental CLI does not necessitate bad code abstractions.
@sqs sqs merged commit 94caab8 into main Apr 5, 2024
19 of 20 checks passed
@sqs sqs deleted the sqs/cli branch April 5, 2024 08:12
@kilyinov
Copy link

awesome stuff, NRI already started using this. I also experimented a bit with STDOUT redirection but couldn't get it work. I tried this:

cody-agent experimental-cli chat -m 'create plantuml for loadPetWithVisit method in src/main/java/org/springframework/samples/petclinic/owner/VisitController.java' --context-repo github.com/kilyinov/spring-petclinic 2>&1 > VisitController.puml

cody-agent experimental-cli chat -m 'create plantuml for loadPetWithVisit method in src/main/java/org/springframework/samples/petclinic/owner/VisitController.java' --context-repo github.com/kilyinov/spring-petclinic > VisitController.puml

The resulting file VisitController.puml was empty though. Being able to redirect output is very important for Cody scripting/automation use cases

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants