Create custom prompt programmatically?

It’s awesome that custom prompts now can contain any @ syntax, but it’s quite cumbersome to create an maintain such prompts by hand. Is there any way to do it programmatically?

I have medium-ish set of files I want to include in the prompt and which these files are can change sometimes. Just doing the initial selection is quite annoying.

Ideally I would want to be able to generate the prompts as xml/json/whatever

Use at your own risk…

But you can try to copy existing prompt with file links and then inspect the clipboard contents (using tools like Clipboard Inspector or locally), for example, for me it outputs:

{"namespace":"BaseEditor","nodes":[{"contextItem":{"type":"file","uri":"file:///home/[[...]]/js/jquery.js","source":"user","isIgnored":false,"size":20689,"isTooLarge":false},"isFromInitialContext":false,"type":"contextItemMention","text":"jquery.js","version":1},{"detail":0,"format":0,"mode":"normal","style":"","text":" Test","type":"text","version":1}]}

so I believe that it’s possible to programmatically generate and fill clipboard with your defined file prompt and then you could paste that in Cody’s chat window and Cody should identify the files mentioned correctly.

Thanks! I figured this out as well by inspecting the clipboard content using xclip

xclip -selection clipboard -o -t TARGETS
xclip -selection clipboard -out -t text/html
xclip -selection clipboard -out -t chromium/x-web-custom-data

I’m not able to make the chromium/x-web-custom-data format work, but this could because the output include some weird jibberish in the beginning.

The text/html format works though. Writing some tooling around this now.

Hm, the code in cody/lib/prompt-editor/README.md at b00f9b6d7588c78957bff0e451faa95a70ef490f · sourcegraph/cody · GitHub might be useful.

UPDATE: seems like they might be in the process of switching from Lexical to a ProseMirror based editor - which likely would change the clip-board format.

UPDATE: Using the “Copy” button in the web prompt manager give yet another format. A plain text format where @references are encoded as cody://serialized.v1?data=$BASE64DATA_ Where $BASE64DATA is a url encoded json structure. (this format does not handle escaping, so it’s not possible to save a prompt mentioning a such a string without having cody interpret it as a reference. Ie. if you write in such a text string manually and save, cody will still interpret it as a reference.

UPDATE: vscode does not understand the cody://serialized.v1? format (which is not really a problem)

UPDATE: some helper code