Skip to content

Commit d1703fd

Browse files
committed
Separate logging concern
1 parent 685a465 commit d1703fd

1 file changed

Lines changed: 13 additions & 31 deletions

File tree

lib/zsh/functions/wiggum

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -63,38 +63,15 @@ ONLY WORK ON A SINGLE TASK.
6363

6464
This prompt is iteration number $iteration.
6565

66-
After you have completed the task, append an entry to wiggum_log.json with:
67-
68-
- a summary of what was done
69-
- a list of actions taken
70-
- a list of all commands run
71-
- errors or issues encountered
72-
- success or failure
73-
74-
If wiggum_log.json doesn't exist, create it. It should be a JSON file containing an array of objects:
66+
After you have completed the task, output a log entry as JSON on a single line prefixed with WIGGUM_LOG:
7567

7668
\`\`\`
77-
[
78-
{
79-
"iteration": 1,
80-
"success": true,
81-
"summary": "CSS added to style header",
82-
"steps_taken": [
83-
"decided to name CSS file foo.css",
84-
"created CSS file"
85-
],
86-
"commands_run": [
87-
"touch ./foo.css",
88-
],
89-
"issues_encountered": [],
90-
},
91-
...
92-
]
69+
WIGGUM_LOG:{"success":true,"summary":"CSS added to style header","steps_taken":["decided to name CSS file foo.css","created CSS file"],"commands_run":["touch ./foo.css"],"issues_encountered":[]}
9370
\`\`\`
9471

9572
ONLY WORK ON A SINGLE TASK.
9673

97-
If there is no further work to do, output exactly WIGGUM:OVER
74+
If there is no further work to do, output exactly WIGGUM:OVER instead of a log entry.
9875

9976
ONLY WORK ON A SINGLE TASK.
10077
EOF
@@ -109,14 +86,19 @@ EOF
10986
break
11087
fi
11188

112-
if [[ -f "wiggum_log.json" ]] && [[ $(jq '.[-1] | has("timestamp") | not' wiggum_log.json) == "true" ]]; then
89+
local log_json=$(echo "$output" | grep -oE 'WIGGUM_LOG:\{[^}]+\}' | head -1 | sed 's/WIGGUM_LOG://' | sed 's/\\"/"/g')
90+
if [[ -n "$log_json" ]]; then
11391
local ts=$(date -Iseconds)
114-
jq --arg ts "$ts" '.[-1].timestamp = $ts' wiggum_log.json > wiggum_log.json.tmp && mv wiggum_log.json.tmp wiggum_log.json
115-
fi
92+
local entry=$(echo "$log_json" | jq --arg ts "$ts" --argjson iter "$iteration" '. + {timestamp: $ts, iteration: $iter}')
93+
94+
if [[ -f "wiggum_log.json" ]]; then
95+
jq --argjson entry "$entry" '. += [$entry]' wiggum_log.json > wiggum_log.json.tmp && mv wiggum_log.json.tmp wiggum_log.json
96+
else
97+
echo "[$entry]" | jq '.' > wiggum_log.json
98+
fi
11699

117-
if [[ -f "wiggum_log.json" ]]; then
118100
echo -e "\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
119-
jq ".[] | select(.iteration == $iteration)" wiggum_log.json
101+
echo "$entry" | jq '.'
120102
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
121103
fi
122104

0 commit comments

Comments
 (0)