OpenWriterControle/plugins/claude-code/scripts/cleanup-tmp.sh
Darren Hinde f84f32b7b3
fix: overhaul Claude Code plugin for correctness and spec compliance (#225)
- Fix critical bugs: coder-agent name (CoderAgent→coder-agent), manifest
  path in session-start.sh, /oac:setup ghost command replaced with /install-context
- Fix hooks.json: add timeout/async, add description, restore matcher
- Fix session-start.sh: dual-format output (Claude Code + Cursor/OpenCode),
  remove invalid JSON escapes for $ and backtick
- Fix agent spec compliance: disallowedTools on read-only agents, WebFetch
  on external-scout, haiku model on context-scout, example blocks on 3 agents
- Fix skill descriptions: triggering conditions only (no workflow summaries)
  per superpowers empirical testing — prevents Claude shortcutting skill content
- Add Red Flags + Rationalization tables to 4 discipline skills
- Add install-context skill + command replacing oac-setup/oac-plan/oac-add-context
- Add cleanup-tmp.sh (was missing, broke /oac:cleanup)
- Add TypeScript installer (install-context.ts/js) with profile-based download
- Update plugin.json: keywords, homepage for marketplace discoverability
- Update README: correct skill count, fix structure diagram, remove stale refs
- Remove obsolete files: FIRST-TIME-SETUP.md, INSTALL.md, QUICK-START.md,
  download-context.sh, verify-context.sh, load-config.sh, context-manager skill,
  oac-setup/oac-plan/oac-add-context commands
2026-02-19 20:16:17 +00:00

58 lines
2.2 KiB
Bash
Executable file

#!/usr/bin/env bash
# cleanup-tmp.sh - Clean up old temporary files from .tmp directory
set -euo pipefail
# Defaults
SESSION_DAYS=7
TASK_DAYS=30
EXTERNAL_DAYS=7
FORCE=false
# Parse arguments
for arg in "$@"; do
case "$arg" in
--force) FORCE=true ;;
--session-days=*) SESSION_DAYS="${arg#*=}" ;;
--task-days=*) TASK_DAYS="${arg#*=}" ;;
--external-days=*) EXTERNAL_DAYS="${arg#*=}" ;;
esac
done
# Find old files
SESSION_FILES=$(find .tmp/sessions -maxdepth 1 -mindepth 1 -type d -mtime +${SESSION_DAYS} 2>/dev/null || true)
TASK_FILES=$(find .tmp/tasks -maxdepth 1 -mindepth 1 -type d -mtime +${TASK_DAYS} 2>/dev/null | while read d; do
# Only include completed tasks (skip active ones)
if [ -f "$d/task.json" ] && grep -q '"status": "completed"' "$d/task.json" 2>/dev/null; then
echo "$d"
fi
done || true)
EXTERNAL_FILES=$(find .tmp/external-context -maxdepth 1 -mindepth 1 -type d -mtime +${EXTERNAL_DAYS} 2>/dev/null || true)
SESSION_COUNT=$(echo "$SESSION_FILES" | grep -c . 2>/dev/null || echo 0)
TASK_COUNT=$(echo "$TASK_FILES" | grep -c . 2>/dev/null || echo 0)
EXTERNAL_COUNT=$(echo "$EXTERNAL_FILES" | grep -c . 2>/dev/null || echo 0)
TOTAL=$((SESSION_COUNT + TASK_COUNT + EXTERNAL_COUNT))
if [ "$TOTAL" -eq 0 ]; then
echo '{"status":"success","deleted":{"sessions":0,"tasks":0,"external":0},"freed_space":"0 B","summary":"No old temporary files found."}'
exit 0
fi
# Show what will be deleted
if [ "$FORCE" = false ]; then
echo "Files to be deleted:"
[ -n "$SESSION_FILES" ] && echo "$SESSION_FILES" | sed 's/^/ [session] /'
[ -n "$TASK_FILES" ] && echo "$TASK_FILES" | sed 's/^/ [task] /'
[ -n "$EXTERNAL_FILES" ] && echo "$EXTERNAL_FILES" | sed 's/^/ [external] /'
echo ""
read -r -p "Delete $TOTAL items? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || { echo "Cancelled."; exit 0; }
fi
# Delete
[ -n "$SESSION_FILES" ] && echo "$SESSION_FILES" | xargs rm -rf
[ -n "$TASK_FILES" ] && echo "$TASK_FILES" | xargs rm -rf
[ -n "$EXTERNAL_FILES" ] && echo "$EXTERNAL_FILES" | xargs rm -rf
echo "{\"status\":\"success\",\"deleted\":{\"sessions\":${SESSION_COUNT},\"tasks\":${TASK_COUNT},\"external\":${EXTERNAL_COUNT}},\"summary\":\"Cleaned up ${TOTAL} old temporary items.\"}"