Skip to content

Instantly share code, notes, and snippets.

@brennop
Created August 5, 2026 21:37
Show Gist options
  • Select an option

  • Save brennop/b4372d0dff77a7e047de92d231e1d8a9 to your computer and use it in GitHub Desktop.

Select an option

Save brennop/b4372d0dff77a7e047de92d231e1d8a9 to your computer and use it in GitHub Desktop.
a coding harness in 18 lines of bash with but make it pretty
#!/bin/bash
j(){ jq -n --arg i "$I" --argjson t "$(<tools.json)" --arg s "$(<prompt.txt)" --arg p "${P}" \
'{model:"auto",input:$i,tools:$t,instructions:$s}+(if $p=="" then{}else{previous_response_id:$p}end)';}
while I=${I:-$(gum input)}; do
gum style --foreground 99 "${O:-$I}"
R=$(gum spin --show-output -- curl -s "$OPENAI_BASE_URL/responses" -H "Content-Type: application/json" -d "$(j)")
P=$(jq -r .id <<<"$R"); unset I O
while read -r X; do
case $(jq -r .type <<<"$X") in
message) jq -r .content[0].text <<<"$X" | gum format;;
function_call)
C=$(jq -r '.arguments|fromjson|.command' <<<"$X")
gum style --faint "\$ $C"
export D=$(jq -r .call_id <<<"$X") O=$(eval "$C" 2>&1)
I=$(jq -n '[{type:"function_call_output",call_id:$ENV.D,output:$ENV.O}]');;
esac
done < <(jq -c .output[] <<<"$R")
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment