-
Notifications
You must be signed in to change notification settings - Fork 135
Expand file tree
/
Copy pathcoding.format.sh
More file actions
executable file
·64 lines (50 loc) · 1.47 KB
/
coding.format.sh
File metadata and controls
executable file
·64 lines (50 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
set -e
rm -f changes.patch formatted.py || true
# Read the coding rules and the file content
RULES=$(cat .claude/skills/coding.rules.md)
FILE_CONTENT=$(cat linters2/normalize_import.py)
PROMPT_INSTRUCTIONS=$(cat prompt.md)
# Build the system prompt
SYSTEM_PROMPT="You are a Python code formatter. $PROMPT_INSTRUCTIONS"
# Build the user prompt with the file content and rules
USER_PROMPT="Format this Python file according to these coding rules:
$RULES
File to format:
\`\`\`python
$FILE_CONTENT
\`\`\`
Output ONLY the formatted Python code in a code block, no explanations."
# Call llm and save the cost info
echo "Calling llm to format code..." >&2
llm "$USER_PROMPT" \
-s "$SYSTEM_PROMPT" \
-m openrouter/openai/gpt-oss-120b \
-o provider '{"sort": "throughput"}' \
-x \
--usage \
> formatted.py \
2> cost.txt
# Create a diff/patch
if [[ 1 == 0 ]]; then
echo "=== Generating diff ==="
diff -u linters2/normalize_import.py formatted.py > changes.patch || true
# Show the diff
if [ -s changes.patch ]; then
echo "Changes found:"
head -50 changes.patch
echo ""
echo "To apply changes, run: git apply changes.patch"
else
echo "No changes detected - file is already well-formatted"
fi
fi;
cp formatted.py linters2/normalize_import.py
# Show cost information
echo ""
echo "=== Cost information ==="
if command -v jq &> /dev/null; then
cat cost.txt | sed 's/^[^{]*//' | jq '.cost' 2>/dev/null || cat cost.txt
else
cat cost.txt
fi