Something went wrong. Try again.
fork of prime agent with changes i want but are not upstreamable probqbly (and some fixes)
Something went wrong. Try again.
2.1 kB · 90 lines
Shell
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091#!/usr/bin/env bash## Migrate sessions from ~/.pi/agent/*.jsonl to proper session directories.# Usage: ./migrate-sessions.sh [--dry-run]#
set -e
AGENT_DIR="${PI_AGENT_DIR:-$HOME/.pi/agent}"DRY_RUN=false
if [[ "$1" == "--dry-run" ]]; then DRY_RUN=true echo "Dry run mode - no files will be moved" echofi
# Find all .jsonl files directly in agent dir (not in subdirectories)shopt -s nullglobfiles=("$AGENT_DIR"/*.jsonl)shopt -u nullglob
if [[ ${#files[@]} -eq 0 ]]; then echo "No session files found in $AGENT_DIR" exit 0fi
echo "Found ${#files[@]} session file(s) to migrate"echo
migrated=0failed=0
for file in "${files[@]}"; do filename=$(basename "$file") # Read first line and extract cwd using jq if ! first_line=$(head -1 "$file" 2>/dev/null); then echo "SKIP: $filename - cannot read file" ((failed++)) continue fi # Parse JSON and extract cwd if ! cwd=$(echo "$first_line" | jq -r '.cwd // empty' 2>/dev/null); then echo "SKIP: $filename - invalid JSON" ((failed++)) continue fi if [[ -z "$cwd" ]]; then echo "SKIP: $filename - no cwd in session header" ((failed++)) continue fi # Encode cwd: remove leading slash, replace slashes with dashes, wrap with -- encoded=$(echo "$cwd" | sed 's|^/||' | sed 's|[/:\\]|-|g') encoded="--${encoded}--" target_dir="$AGENT_DIR/sessions/$encoded" target_file="$target_dir/$filename" if [[ -e "$target_file" ]]; then echo "SKIP: $filename - target already exists" ((failed++)) continue fi echo "MIGRATE: $filename" echo " cwd: $cwd" echo " to: $target_dir/" if [[ "$DRY_RUN" == false ]]; then mkdir -p "$target_dir" mv "$file" "$target_file" fi ((migrated++)) echodone
echo "---"echo "Migrated: $migrated"echo "Skipped: $failed"
if [[ "$DRY_RUN" == true && $migrated -gt 0 ]]; then echo echo "Run without --dry-run to perform the migration"fi