vault backup: 2025-06-06 09:49:16
This commit is contained in:
10 files changed
+98
No files matched your search
@@ -723,4 +723,14 @@ In your task file you can import these functions from the taskfile library.
|
||||
# Import commands
|
||||
|
||||
[ -f ~/taskfile.build/bin/update-submodule ] && source ~/taskfile.build/bin/update-submodule
|
||||
```
|
||||
|
||||
### update-with-llm
|
||||
|
||||
```bash
|
||||
printf "$COLUMN" "update-with-llm" "[glob][prompt]" "Feed files matching glob with prompt to LLM and apply file changes."
|
||||
|
||||
# Import commands
|
||||
|
||||
[ -f ~/taskfile.build/bin/update-with-llm ] && source ~/taskfile.build/bin/update-with-llm
|
||||
```
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function commit-with-llm() {
|
||||
|
||||
mkdir -p tmp
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function copy-env() {
|
||||
if test -z "$1"; then echo "\$1 is empty."; exit; fi
|
||||
if test -z "$2"; then echo "\$2 is empty."; exit; fi
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function edit-env() {
|
||||
if test -z "$1"; then echo "\$1 is empty."; exit; fi
|
||||
TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function list-env() {
|
||||
TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"}
|
||||
ls -a1 "$TASK_CONFIG_DIR"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function load-env() {
|
||||
TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"}
|
||||
ENV_FILEPATH="$TASK_CONFIG_DIR/.env.$1"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function show-env() {
|
||||
if test -z "$1"; then echo "\$1 is empty."; exit; fi
|
||||
TASK_CONFIG_DIR=${TASK_CONFIG_DIR:="$HOME/.config/taskfile.build"}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#!/bin/bash
|
||||
|
||||
function update-submodule() {
|
||||
echo "Update git submodules."
|
||||
git submodule update --init --recursive --checkout --depth=1
|
||||
|
||||
@@ -0,0 +1,79 @@
|
||||
#!/bin/bash
|
||||
|
||||
function update-with-llm() {
|
||||
if [ $# -lt 2 ]; then
|
||||
echo "Usage: update-with-llm [glob] [prompt]"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get the last argument as the task description
|
||||
TASK_DESCRIPTION="${@: -1}"
|
||||
|
||||
# All preceding arguments are file paths
|
||||
FILES=("${@:1:$#-1}")
|
||||
|
||||
echo -e "Load these files into prompt:\n\n${FILES[*]}\n"
|
||||
echo -e "Task: $TASK_DESCRIPTION\n"
|
||||
|
||||
FILE_CONTENTS=""
|
||||
for FILE in "${FILES[@]}"; do
|
||||
FILE_CONTENTS+="<<<$FILE>>>
|
||||
$(cat "$FILE")
|
||||
|
||||
"
|
||||
done
|
||||
|
||||
# Define prompt content
|
||||
PROMPT_FILE="tmp/llm_update"
|
||||
echo -e "\nWrite prompt to $PROMPT_FILE."
|
||||
cat << EOF > "$PROMPT_FILE"
|
||||
Look at the code files below and do the following:
|
||||
|
||||
$TASK_DESCRIPTION
|
||||
|
||||
Output all files that you need to change in full again, including your changes.
|
||||
In the same format as I provide the files below. Under no circumstances output any other text,
|
||||
no additional infos, no code formatting chars. Only the code in the given format.
|
||||
|
||||
Here are the files:
|
||||
|
||||
$FILE_CONTENTS
|
||||
EOF
|
||||
|
||||
# Run the llm command
|
||||
echo -e "Send prompt and wait for the response of the $LLM_MODEL LLM."
|
||||
RESULT=$(cat "$PROMPT_FILE" | llm -m "$LLM_MODEL")
|
||||
|
||||
# Check if result is empty
|
||||
if [ -z "$RESULT" ]; then
|
||||
echo "No response from the model. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Save the result to a file
|
||||
RESULT_FILE="tmp/llm_update_result"
|
||||
echo "$RESULT" > "$RESULT_FILE"
|
||||
echo -e "Saved response to $RESULT_FILE.\n"
|
||||
|
||||
# Show a preview of result file
|
||||
less "$RESULT_FILE"
|
||||
|
||||
# Ask for confirmation before updating files
|
||||
read -p "Do you want to apply these updates to the files? (y/n): " CONFIRM
|
||||
if [[ ! "$CONFIRM" =~ ^[Yy]$ ]]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Parse the response from the file and update the files directly
|
||||
echo -e "Parsing the response and updating files...\n"
|
||||
CURRENT_FILE=""
|
||||
while IFS= read -r LINE; do
|
||||
if [[ $LINE =~ ^"<<<"(.*)">>>" ]]; then
|
||||
CURRENT_FILE="${BASH_REMATCH[1]}"
|
||||
echo "Update file $CURRENT_FILE."
|
||||
> "$CURRENT_FILE"
|
||||
elif [[ -n $CURRENT_FILE ]]; then
|
||||
echo "$LINE" >> "$CURRENT_FILE"
|
||||
fi
|
||||
done < "$RESULT_FILE"
|
||||
}
|
||||
Reference in new issue
Block a user