From 8ba7242861778cf8ee6cabeca8c44955ba33b37e Mon Sep 17 00:00:00 2001 From: shokollm <270575765+shokollm@users.noreply.github.com> Date: Tue, 7 Apr 2026 00:35:38 +0000 Subject: [PATCH] fix: add JSON validation in write_index to prevent malformed index.json The index.json was getting corrupted (ending with 'issues: }' instead of 'issues: {}'). Added validation that checks if the JSON is valid before moving the temp file. If invalid, the write is aborted with an error message showing the problematic values. --- skills/kugetsu/scripts/kugetsu | 7 +++++++ skills/kugetsu/scripts/kugetsu-index.sh | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/skills/kugetsu/scripts/kugetsu b/skills/kugetsu/scripts/kugetsu index 3e847d0..d293a3c 100755 --- a/skills/kugetsu/scripts/kugetsu +++ b/skills/kugetsu/scripts/kugetsu @@ -481,6 +481,13 @@ write_index() { local issues_json="$3" local temp_file="$INDEX_FILE.tmp.$$" printf '{"base": %s, "pm_agent": %s, "issues": %s}\n' "$base" "$pm_agent" "$issues_json" > "$temp_file" + + if ! python3 -c "import json; json.load(open('$temp_file'))" 2>/dev/null; then + echo "Error: write_index would create malformed JSON, aborting. base=$base, pm_agent=$pm_agent, issues_json=$issues_json" >&2 + rm -f "$temp_file" + return 1 + fi + mv "$temp_file" "$INDEX_FILE" } diff --git a/skills/kugetsu/scripts/kugetsu-index.sh b/skills/kugetsu/scripts/kugetsu-index.sh index 8eec8c2..f1e6695 100755 --- a/skills/kugetsu/scripts/kugetsu-index.sh +++ b/skills/kugetsu/scripts/kugetsu-index.sh @@ -15,6 +15,13 @@ write_index() { local issues_json="$3" local temp_file="$INDEX_FILE.tmp.$$" printf '{"base": %s, "pm_agent": %s, "issues": %s}\n' "$base" "$pm_agent" "$issues_json" > "$temp_file" + + if ! python3 -c "import json; json.load(open('$temp_file'))" 2>/dev/null; then + echo "Error: write_index would create malformed JSON, aborting. base=$base, pm_agent=$pm_agent, issues_json=$issues_json" >&2 + rm -f "$temp_file" + return 1 + fi + mv "$temp_file" "$INDEX_FILE" }