Apply fixes for selected paper quality problems from a shears-check session. Use when the user invokes /shears-fix. Reads selections from .shears/results, backs up affected files, groups fixes by file, applies them via Edit, recompiles, and generates comparison artifacts.
You are the orchestrator for applying paper quality fixes that were identified by /shears-check and selected by the user in the web UI.
The user invoked this with: $ARGUMENTS
The plugin root is available via the ${CLAUDE_PLUGIN_ROOT} environment variable, automatically set by Claude Code when this skill runs.
$ARGUMENTS contains a timestamp, use it. Otherwise, find the latest session:ls -1d .shears/results/*/ 2>/dev/null | sort | tail -1
Set SESSION_DIR to that path.
Read ${SESSION_DIR}/selected.toml. If the file doesn't exist or is empty:
${SESSION_DIR}/ui_port)PDF_PATH=$(python3 -c "import json; d=json.load(open('${SESSION_DIR}/manifest.json')); print(d.get('pdf_path',''))")
nohup python3 ${CLAUDE_PLUGIN_ROOT}/scripts/shears_server.py "${SESSION_DIR}" --pdf "${PDF_PATH}" --plugin-root ${CLAUDE_PLUGIN_ROOT} > /dev/null 2>&1 &
/shears-fix again."Parse selected.toml to get the list of selected problem IDs.
For each selected problem ID:
.md file from ${SESSION_DIR}/check/.json file to get structured data"status": "resolved", skip it silently — it was already fixed in a previous runBuild a list of selected problems with their full details.
.tex file.line_start.[line_start, line_end] overlaps with fix B's range:
confidence scoreBACKUP_DIR=".shears/backups/$(date +%Y-%m-%d_%H-%M-%S)"
mkdir -p "${BACKUP_DIR}"
For each affected .tex file, copy it into the backup directory preserving the relative path:
mkdir -p "${BACKUP_DIR}/$(dirname <relative_path>)"
cp <file> "${BACKUP_DIR}/<relative_path>"
Also backup the current PDF:
cp <pdf_path> "${BACKUP_DIR}/"
Tell the user: "Backup created at ${BACKUP_DIR}"
Load all selected problem descriptions (the .md files) into your context. These contain the full fix details.
Apply fixes file by file. For each affected file:
line_start descending (bottom-to-top).Edit tool to apply the change:
original_text from the JSON as old_stringsuggested_fix from the JSON as new_stringoriginal_text is not found exactly, search nearby lines. If still not found, mark as skipped (see below) and warn.${SESSION_DIR}/check/<id>.json with the outcome:
"status": "resolved" and "resolved_at": "<ISO8601 UTC timestamp>""status": "skipped" and "skipped_reason": "<short reason>"Working bottom-to-top ensures earlier line numbers remain valid after each edit. The web UI polls /api/problems and will pick up the new status field within a couple of seconds — resolved problems get a green strikethrough in the list.
Recompile the paper:
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/compile_latex.py "${MAIN_TEX}"
If compilation fails:
Present the user with the comparison options:
latexdiff to be installed..tex files.Based on the user's choice:
python3 ${CLAUDE_PLUGIN_ROOT}/scripts/generate_diffs.py \
--backup-dir "${BACKUP_DIR}" \
--paper-root "${PAPER_ROOT}" \
--main-tex "${MAIN_TEX}" \
--mode <chosen_mode> \
--output-dir ".shears/diffs/"
Summarize:
${BACKUP_DIR}.shears/diffs/ (if generated)