How clean capra-context-state.json

here is the solution based of another user post ., so I did a file and upload, that backup the file and then clean the json file, please can anybody get this and make it even better,

#!/bin/bash

echo "๐Ÿ”„ Creating backup..."
timestamp=$(date +%Y%m%d%H%M%S)
mkdir -p "/home/user/studio/context_backup/"
cp "/home/user/.idx/ai/capra-context-state.json" "/home/user/studio/context_backup/capra-context-state-$timestamp.json"
cp "/home/user/.idx/ai/capra-thread.json" "/home/user/studio/context_backup/capra-thread-$timestamp.json"
echo "โœ… Backup complete."

echo "๐Ÿงน Cleaning capra-context-state.json..."
jq '
  if .["app-prototyping-agent: edit-app-agent"] then
    .["app-prototyping-agent: edit-app-agent"] |= map(
      select(
        ((.content[]?.text? // "") | test("I see this error with the app, reported by NextJS")) | not
      )
    )
  else
    .
  end
' /home/user/.idx/ai/capra-context-state.json > /home/user/.idx/ai/temp-context.json

if [ -f /home/user/.idx/ai/temp-context.json ]; then
  mv /home/user/.idx/ai/temp-context.json /home/user/.idx/ai/capra-context-state.json
  echo "โœ… Cleaned and replaced capra-context-state.json"
else
  echo "โŒ Cleaning failed: temp-context.json not created"
fi

run this..


chmod +x scripts/backup-and-clean.sh
./scripts/backup-and-clean.sh
1 Like