Skip to content

Commit 9ae2a37

Browse files
committed
refactor: streamline context tools and standardize prompt handling
- Remove JSON/text format support across all tools, simplifying output to Markdown-only - Eliminate deprecated options (--include-deps, --format, --prompt) from context scripts - Add automatic prompt detection from prompts/ directory in all tools - Clean up verbose comments and redundant code in apply-md processor - Update git-context to use embedded prompt file for commit guidance - Improve consistency of file pattern handling and error reporting - Remove unused dependency tracking and file format conversion logic
1 parent 18c907c commit 9ae2a37

File tree

3 files changed

+107
-310
lines changed

3 files changed

+107
-310
lines changed

apply-md

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,31 +78,24 @@ extract_blocks() {
7878
local in_block=false
7979
local block_content=""
8080

81-
# Split markdown into lines
8281
echo "$MARKDOWN" | while IFS= read -r line; do
83-
# Check if line starts a code block with a file name
8482
if [[ "$line" =~ ^[[:space:]]*\`\`\`([a-zA-Z0-9\+\-]+)[[:space:]]+(.+) ]]; then
8583
current_file="${BASH_REMATCH[2]}"
8684
in_block=true
8785
block_content=""
8886
continue
8987
fi
9088

91-
# Check if line starts a code block without a file name (ignore these)
9289
if [[ "$line" =~ ^[[:space:]]*\`\`\`([a-zA-Z0-9\+\-]+)[[:space:]]*$ ]]; then
9390
in_block=false
9491
current_file=""
9592
continue
9693
fi
9794

98-
# Check if line ends a code block
9995
if [[ "$line" =~ ^[[:space:]]*\`\`\`[[:space:]]*$ ]]; then
10096
if [ -n "$current_file" ] && [ "$in_block" = true ]; then
101-
# Save block to a file
10297
echo "$current_file" >> "$FILES_FILE"
10398
echo "$block_content" > "$TEMP_DIR/$current_file"
104-
105-
# Format file path for output consistency
10699
current_file_formatted=$(echo "$current_file" | sed 's/^\.\///')
107100
if [ "$VERBOSE" = true ]; then
108101
echo "Found code block for file: $current_file_formatted"
@@ -113,7 +106,6 @@ extract_blocks() {
113106
continue
114107
fi
115108

116-
# Collect content if inside a block
117109
if [ "$in_block" = true ] && [ -n "$current_file" ]; then
118110
if [ -z "$block_content" ]; then
119111
block_content="$line"
@@ -130,32 +122,27 @@ apply_block() {
130122
local content_file="$TEMP_DIR/$file"
131123
local skipped=false
132124

133-
# Check if file should be ignored
134125
if [ -n "$IGNORE_FILES" ] && [[ "$file" == $IGNORE_FILES ]]; then
135126
if [ "$VERBOSE" = true ]; then
136127
echo "Skipping ignored file: $file"
137128
fi
138129
return
139130
fi
140131

141-
# Check if file should be included
142132
if [ -n "$ONLY_FILES" ] && [[ "$file" != $ONLY_FILES ]]; then
143133
if [ "$VERBOSE" = true ]; then
144134
echo "Skipping file not matching include pattern: $file"
145135
fi
146136
return
147137
fi
148138

149-
# Ensure the content file exists
150139
if [ ! -f "$content_file" ]; then
151140
echo "Error: Content file not found for $file"
152141
return
153142
fi
154143

155-
# Check if target file exists
156144
if [ ! -f "$file" ]; then
157145
if [ "$CREATE_MISSING" = true ]; then
158-
# Create the directory if it doesn't exist
159146
if [ "$DRY_RUN" = false ]; then
160147
mkdir -p "$(dirname "$file")"
161148
cat "$content_file" > "$file"
@@ -174,7 +161,6 @@ apply_block() {
174161
return
175162
fi
176163

177-
# Check if content is unchanged
178164
if [ "$SKIP_UNCHANGED" = true ]; then
179165
diff -q "$file" "$content_file" > /dev/null
180166
if [ $? -eq 0 ]; then
@@ -185,9 +171,7 @@ apply_block() {
185171
fi
186172
fi
187173

188-
# Apply changes if not skipped
189174
if [ "$skipped" = false ]; then
190-
# Check if changes are needed
191175
local changes=$(diff -u "$file" "$content_file")
192176
if [ -z "$changes" ]; then
193177
if [ "$VERBOSE" = true ]; then
@@ -196,7 +180,6 @@ apply_block() {
196180
return
197181
fi
198182

199-
# Show changes if verbose
200183
if [ "$VERBOSE" = true ]; then
201184
echo "Changes for $file:"
202185
echo "$changes"
@@ -205,7 +188,6 @@ apply_block() {
205188
echo "Modifying: $file"
206189
fi
207190

208-
# Ask for confirmation if needed
209191
if [ "$CONFIRM" = true ]; then
210192
read -p "Apply changes to $file? (y/n) " -n 1 -r
211193
echo
@@ -215,7 +197,6 @@ apply_block() {
215197
fi
216198
fi
217199

218-
# Create backup if needed
219200
if [ "$BACKUP" = true ]; then
220201
local backup_file="$BACKUP_DIR/$(basename "$file").$(date +%Y%m%d%H%M%S).bak"
221202
if [ "$DRY_RUN" = false ]; then
@@ -228,7 +209,6 @@ apply_block() {
228209
fi
229210
fi
230211

231-
# Apply changes
232212
if [ "$DRY_RUN" = false ]; then
233213
cat "$content_file" > "$file"
234214
echo "Updated file: $file"
@@ -244,23 +224,24 @@ if [ "$VERBOSE" = true ]; then
244224
if [ "$DRY_RUN" = true ]; then
245225
echo "Running in DRY RUN mode (no changes will be applied)"
246226
fi
227+
if [ -f "prompts/apply_prompt.txt" ]; then
228+
echo "Applying with prompt:"
229+
cat "prompts/apply_prompt.txt"
230+
echo ""
231+
fi
247232
fi
248233

249-
# Extract code blocks from markdown
250234
extract_blocks
251235

252-
# Check if any code blocks were found
253236
if [ ! -f "$FILES_FILE" ] || [ ! -s "$FILES_FILE" ]; then
254237
echo "No code blocks found in the markdown input."
255238
exit 0
256239
fi
257240

258-
# Process each code block
259241
while IFS= read -r file; do
260242
apply_block "$file"
261243
done < "$FILES_FILE"
262244

263-
# Show summary
264245
file_count=$(wc -l < "$FILES_FILE")
265246
if [ "$VERBOSE" = true ]; then
266247
echo ""

0 commit comments

Comments
 (0)