Do not use this yet; it is in development.
- Code autocompletions should be usable now.
- Telemetry probably isn’t working; API has changed and it needs to be re-implemented for the new protocol.
It uses a distributed copy of the Cody agent as compressed javascript, but you can override this by specifying the location of the agent binary, e.g.:
(setq cody--agent-binary
"/path/to/eg/cody/agent/dist/agent-macos-arm64/agent-macos-arm64")
Fetches your access token via auth-source and hardcodes the instance and codebase. You can currently bypass this by setting your access token directly:
(setq cody--access-token "sgp_etc")
To try it out, evaluate the buffer and `M-x cody-login’.
Note: For now, if you are using the extension and want ripgrep support, you will want to add this to your `~/.bashrc` or equivalent:
export MOCK_RG_PATH="/opt/homebrew/bin/rg" # path to your rg binary
You can create a Sourcegraph access token at https://sourcegraph.com/users/yourname/settings/tokens.
;; Tell `use-package' where to find your clone of `cody.el'.
(add-to-list 'load-path (expand-file-name "~/my/path/to/emacs-cody"))
(use-package cody
:straight nil
:commands (cody-login cody-restart cody-chat cody-mode)
;; Some common key bindings.
:bind (("C-M-n" . cody-completion-cycle-next-key-dispatch)
("C-M-p" . cody-completion-cycle-prev-key-dispatch)
("M-TAB" . cody-completion-accept-key-dispatch)
("C-M-g" . cody-quit-key-dispatch))
:init
(setq cody--sourcegraph-host "sourcegraph.com") ; for clarity; this is the default.
(setq cody--access-token "sgp_asdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdfasdf")
(setopt cody-workspace-root "/your/path/to/some/project/dir") ; optional
(setenv "MOCK_RG_PATH" "/opt/homebrew/bin/rg") ; ripgrep
:config
(defalias 'cody-start 'cody-login))
`M-x cody` will start Cody and prompt you with available commands `M-x cody-chat` will pop you immediately into the Q&A command
Chat is just a stub for now.
`M-x cody-login` to start and initialize the agent without doing a command `M-x cody-force-unload` to tear everything down
(load-file "cody.el")
(cody--request 'recipes/list)
(cody--request 'recipes/execute
:id "code-question"
:humanChatInput "Does cody work in emacs?")
You can view the output by switching to the *cody output*
and
*cody events*
buffer. You can also see debugging messages in the
*cody log*
buffer.
You can shut down the connection with *M-x cody-shutdown*
, or shut
it down and remove all traces with *M-x cody-force-unload*
.
Alternatively run list-processes
and select the buffer. You can also
shut down cody by hitting d
on the cody process.
Start by binding *cody-agent-command*
to a list like this one,
which points to the path of the agent that you have cloned.
(setq cody-agent-command
(list "node"
"/Users/stevey/src/sg/cody/agent/dist/index.js"
""))
This will allow you to rebuild and reattach in a tight dev loop.
Restart Cody, e.g. with *M-x cody-restart*
, and then verify that
Cody is running the version of the agent in *cody-agent-command*
.
$ ps aux | grep node
yourself 31174Ss 4:08PM ~/.asdf/installs/nodejs/20.4.0/bin/node \
~/src/sg/cody/agent/dist/index.js
To have it listen for the debugger to attach, you can either run
the script *./bin/debug-cody*
, or send the sigusr1 to the pid of
the node process yourself like so:
$ kill -USR1 31174
Either way, your Agent should now be listening for a debugger.
Now you can attach with *chrome://inspect*
or with VSCode’s debugger.
VSCode is recommended, as it seems to connect more reliably - use the
built-in configuration =*Debug: Attach to Node Process=*.
You should also *(setq jsonrpc-default-request-timeout 500)*
to ensure
that the jsonrpc calls don’t time out while you’re paused at breakpoints.
N.B. Everything stops when the debugger is stopped at a breakpoint, as Emacs concurrency is cooperative.