From 77efded76dd5bfb98c78923455a0969bd53aa506 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sun, 17 May 2026 13:24:28 +0200 Subject: [PATCH] u/cascade: add -json-output flag for structured synthesis output Schema: {summary, answer, worker_results[], errors[]} --- scripts/u/cascade | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/scripts/u/cascade b/scripts/u/cascade index 915b21c..47d9176 100755 --- a/scripts/u/cascade +++ b/scripts/u/cascade @@ -12,6 +12,8 @@ # -pm MODEL planner model (default: $OLLIE_CASCADE_PLAN_MODEL or claude-sonnet-4-20250514) # -wb BACKEND worker backend (default: $OLLIE_CASCADE_BACKEND or ollama) # -no-synthesize skip the final planner synthesis step; just print worker results +# -json-output request structured JSON from the synthesis step +# schema: {summary, answer, worker_results[], errors[]} set -euo pipefail OLLIE="${OLLIE:-$HOME/mnt/ollie}" @@ -25,6 +27,7 @@ WM="${OLLIE_CASCADE_MODEL:-qwen2.5-coder:14b}" die() { printf 'cascade: %s\n' "$*" >&2; exit 1; } synthesize=1 +json_output=0 while [ $# -gt 0 ]; do case $1 in @@ -33,6 +36,7 @@ while [ $# -gt 0 ]; do -wb) WB=$2; shift ;; -wm) WM=$2; shift ;; -no-synthesize) synthesize=0 ;; + -json-output) json_output=1 ;; --) shift; break ;; -*) die "unknown flag: $1" ;; *) break ;; @@ -111,13 +115,27 @@ if [ "$synthesize" -eq 0 ]; then printf '%s\n' "$results" [ "$failures" -gt 0 ] && exit 1 else - "$B" -backend "$PB" -model "$PM" \ - "Synthesize these worker results into a final, coherent answer to the original task. Note: workers marked [STATUS: failed] did not complete successfully — account for this in your synthesis. + synth_flags=(-backend "$PB" -model "$PM") + if [ "$json_output" -eq 1 ]; then + synth_flags+=(-json) + synth_prompt="Synthesize these worker results into a structured JSON response for the original task. Note: workers marked [STATUS: failed] did not complete successfully — include them in errors. + +Output schema: {\"summary\": \"\", \"answer\": \"\", \"worker_results\": [{\"id\": \"\", \"status\": \"done|failed\", \"output\": \"\"}], \"errors\": [\"\"]} ORIGINAL TASK: $task WORKER RESULTS: $results" + else + synth_prompt="Synthesize these worker results into a final, coherent answer to the original task. Note: workers marked [STATUS: failed] did not complete successfully — account for this in your synthesis. + +ORIGINAL TASK: +$task + +WORKER RESULTS: +$results" + fi + "$B" "${synth_flags[@]}" "$synth_prompt" [ "$failures" -gt 0 ] && exit 1 fi