[HN Gopher] Prelude - a tiny CLI tool building context prompts f...
___________________________________________________________________
Prelude - a tiny CLI tool building context prompts from your code
Author : aerugo_
Score : 43 points
Date : 2024-07-21 00:06 UTC (23 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| aerugo_ wrote:
| I was feeling bogged down by the repetitive copy-paste routine to
| build context prompts for debugging or generating code. This
| simple solution ended up saving me a lot of time, so I thought
| I'd share my workflow.
|
| With the large context windows of OpenAI and Anthropic models,
| you can keep entire code repositories in context. But copy-
| pasting the file-tree and code from lots of places is annoying.
| Prelude is a tiny CLI tool that creates a context prompt from
| files in your directory and its subdirectories, then copies it to
| your clipboard or saves it to a text file. Prelude creates a
| prompt containing the file tree of your specified directory,
| minus the files you ignored in .gitignore and .preludeignore,
| followed by the content of each file. It adds a bit of context
| prompting at the end, and that's it. Ready to copy-paste into a
| new chat with your favorite AI-chat. Nothing more, nothing less.
| Here's how it works:
|
| Install Prelude with Homebrew:
|
| brew tap aerugo/prelude brew install prelude
|
| Simply run prelude in your working directory. Need files from a
| specific subdirectory? Use prelude -p dir. Want to specify a
| filename to save the prompt? Use prelude -f prompt.txt. Lots of
| files you don't want in the prompt? Put them in a .preludeignore
| file in the root folder where you run Prelude
|
| Say that you know the names of the files you want to include, for
| example FooBar.py and BarFoo.md and they are somewhere in your
| file hierarchy.
|
| Just run
|
| prelude -M "foobar|barfoo"
|
| and you will get a prompt with only those files. It also works
| with * wildcards.
|
| Of course, it also works with the -P option, so you can also run
| something like
|
| prelude -P backend/src -M "*.py"
|
| To get all python files in the src directory of your backend.
|
| PS. I'm sure this already exists. Lots of people must have done
| this. But nevertheless, I couldn't find a simple CLI tool to do
| just this, so I wrote one for myself, and then thought to share
| it.
| snthpy wrote:
| Thank you for this. I was just thinking that I need something
| like it.
|
| Could you include an example of how you separate files? For
| example are you using YAML Front Matter or something like that?
| aerugo_ wrote:
| Just like this:
|
| --- File: ~/GitRepos/kanot/prelude ---
| paradite wrote:
| I personally think a GUI tool would provide better user
| experience since you can see the files, pick which ones to
| include as context, and check the prompt generated in real-time.
|
| So I built my own GUI version of this (plus a lot of other
| quality of life features): https://prompt.16x.engineer/
| visarga wrote:
| I made one too like this too, it would use .gitignore like files
| (.gptignore) to filter what goes into the prompt.
| aerugo_ wrote:
| Same here! Prelude respects .preludeignore, and also ignores
| annything in .gitignore.
| smcleod wrote:
| Sounds a bit like code2prompt -
| https://github.com/mufeedvh/code2prompt
| aerugo_ wrote:
| Oh yeah, I hadn't seen code2prompt - that's indeed really
| similar. Prelude is a lot simpler though, just around 200 lines
| of bash in a single file, with only a single dependency (a CLI
| tool called tree). code2prompt, in contrast, requires you to
| install Rust and use Cargo.
|
| Prelude is meant to really just do a single thing. I haven't
| felt the need for things like templates, but I will give
| code2prompt a spin if I need more fancy things.
| vnjxk wrote:
| If you have a repository, while still in it's early stages,
| TxtRepo.com is a good option (it can also do PRs)
| aerugo_ wrote:
| This is also neat, like simpler minimal version of Fume or GPT-
| Engineer. It seems really useful. Good job!
|
| Prelude is rather meant for when you are pair-programming with
| a chat model and find yourself pasting a lot of context to
| remind the model of the state of your code. I always have
| terminals open anyway, so having it as a CLI tool rather than
| needing to make requests to a server, makes sense for me.
| snthpy wrote:
| A similar thing I've been thinking about is extracting open
| github issues and using LLMs to triage them. Might look into
| that.
| samrolken wrote:
| I've been maintaining my own script that does something like
| this. A few things I've found to be useful: It can also pull in
| context from git history (prioritize based on which files have
| been most recently worked on, include recent git commit messages
| which can help the LLM know more about what's going on), and
| optionally it can go do multiple stages... for long files, first
| summarizing them, then including the summary in the final prompt.
| aerugo_ wrote:
| Interesting! Did you publish it? It's a great idea to
| prioritize based on git history.
|
| As for multiple stages, it means the tool itself is doing a few
| calls to the model. What do the code summaries look like? Just
| function and class doctrings? Getting the model to write
| summaries that are comprehensive enough to guide development
| but still more compact than the code itself seems like it may
| not be a trivial problem.
| aerugo_ wrote:
| I was asked in a PM how I use the prompts. Basically, whenever I
| need to write some new code for a project, I start by making a
| prompt out of the relevant parts of the repo, paste it into GPT
| or Claude, and follow up with something like (random made up
| example):
|
| ----
|
| I want to add a feature to my Content.js component. In the table
| that displays names of animals, I want to add an Edit button in a
| new column on each row. When clicked, it should bring up a modal
| that allows me to edit the name and emoji of the animal.
|
| Review my codebase to see how CRUD actions are implemented for
| other features. Make sure you follow the established code
| patterns in the project.
|
| Before starting to code, consider best practices for UX of a
| feature like this and make sure the implementation is user
| friendly and follows best practices.
|
| After reviewing the code, describe how you will implement the
| feature make a plan for how to implement. After that, write the
| complete code for the implementation.
| nevodavid wrote:
| This is pretty cool :)
| dsmurrell wrote:
| I made something like this too to use myself. It's called
| `describe dot` and builds a context by recursing over . and
| putting all the content into the clipboard. It respects the
| .gitignore files in each folder and I can add .dignore files to
| ignore more files. At the end it creates a text file folder
| structure followed by the contents of all the files. It also logs
| the files in size order so that you can trim down the total size
| by ignoring them. It's been useful for small projects but I
| imagine that a whitelist based approach might be more useful for
| larger ones.
| imaurer wrote:
| Have a bunch of Makerile commands (pbcopy-api, pbcopy-ui, pbcopy-
| curr) that use some mishmash of git ls-files, grep, xargs tail -n
| +1 piped into pbcopy.
|
| Kitchen sink command: pbcopy-all: git ls-files | xargs tail -n +1
| | pbcopy
|
| Works like a charm in Q2 2024.
|
| I'm sure this will be a very solved problem by 2025.
| voiper1 wrote:
| I know this is a bit heavier since it's a whole program:
|
| https://aider.chat/ generates a repo map, suggests related files,
| then makes your request and does the editing for you. (with
| intelligent diff for models that work well.)
|
| They have a leaderboard for models for editing and what mode they
| use: https://aider.chat/docs/leaderboards/
|
| EDIT: Oh, it looks like you're dumping the entire repo. Well,
| sure, I guess. Once it seems too big you can select just what you
| need. Also gui tools like the open source
| https://www.continue.dev/ lets you pick files, search codebase
| via RAG, add docs, etc...
| aerugo_ wrote:
| Yes, the whole point of this tool is just to make it extremely
| simply to make a prompt out of a part of your repo, with some
| pattern matching on filenames. It's just 200 lines of bash, so
| obviously nothing fancier than that.
|
| However, I just had a go at using Aider, and WOW - I have tried
| a bunch of these auto-commit tools before (GPT Engineer, Fume,
| etc) but I found them to be clunky and unintuitive. Aider has
| fixed a lot of these problems, and I absolutely love it. Can't
| believe I hadn't heard of it until now. Thanks! I see myself
| using this quite a bit, and using Prelude when I need to debug
| something where the Aider workflow gets stuck.
| kelvie wrote:
| To pile on, I was also going to make something similar for a very
| similar need (surprisingly hard to find prior art in this area
| that's good, probably due to _so_ many people doing this)
|
| But I will try this once I'm back from PTO!
| jamesponddotco wrote:
| Wrote something similar[1] using Go a while back, but I love that
| this one only uses shell tools. Extremely useful when working
| with LLMs for small to medium projects.
|
| For bigger ones on the other hand, I wish I could just get the
| exact context I need. Maybe something like only the files open in
| vim?
|
| [1]: https://git.sr.ht/~jamesponddotco/llmctx
| redeux wrote:
| Nice job! I wrote a bash script that does the exact same thing a
| couple weeks ago. I didn't even think to make it its own project.
___________________________________________________________________
(page generated 2024-07-21 23:14 UTC)