refactor: simplify and harden code since v2.1.0 release#377
Merged
Conversation
Simplification (from /simplify review): - Extract strip_code_fences() utility, replacing 6 duplicate instances across complete_command.py and pr_template.py - Deduplicate temp directory cleanup in open_command.py by delegating to canonical cleanup_temp_directory() from temp_directory.py - Deduplicate PR template AI prompt (built once, passed to API fallback) - Pass pre-loaded config to _fill_template_fallback to avoid re-reading - Cache package_file_name property in ReleaseManager, replacing 2 inline expressions that each re-read pyproject.toml - Extract _clone_repo_to_temp() shared core from clone_to_temp_directory and prompt_and_clone_to_temp, eliminating ~30 duplicate lines - Fix duplicate git ls-remote call in open_command.py (wasted network round-trip) Code review fixes (from /code-review): - Fix _cleanup_temp_directory in complete_command.py not handling nested daf-session-* directories (orphaned temp dirs in /tmp/) - Fix unbound 'prompt' variable in pr_template.py FileNotFoundError handler by moving context/prompt building outside the try block - Sanitize issue_key in investigate_command.py session name generation to prevent path separators in names (e.g., owner/repo#123) - Use lambda in re.sub for session.goal to prevent regex backreference interpretation of user-provided text - Tighten JIRA placeholder regex from \w+ to \d+ to avoid matching natural English words like ISSUE-HANDLING - Add Path.resolve() to temp directory cleanup symlink comparison for macOS compatibility (/tmp -> /private/tmp) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Jira Issue:
Description
Simplification and hardening of code changes since the v2.1.0 release, based on automated
/simplifyand/code-reviewanalysis.Simplification (7 items):
strip_code_fences()utility, replacing 6 duplicate instances acrosscomplete_command.pyandpr_template.pyopen_command.pyby delegating to canonicalcleanup_temp_directory()fromtemp_directory.py_fill_template_fallbackpackage_file_nameproperty inReleaseManager, replacing 2 inline expressions that re-readpyproject.toml_clone_repo_to_temp()shared core fromclone_to_temp_directoryandprompt_and_clone_to_tempgit ls-remotecall inopen_command.py(wasted network round-trip)Code review fixes (6 items):
_cleanup_temp_directoryincomplete_command.pynot handling nesteddaf-session-*directories (orphaned temp dirs)promptvariable inpr_template.pyFileNotFoundErrorhandlerissue_keyininvestigate_command.pysession name to prevent path separatorsre.subforsession.goalto prevent regex backreference interpretation\w+to\d+to avoid matching words likeISSUE-HANDLINGPath.resolve()to temp directory cleanup for macOS symlink compatibilityAssisted-by: Claude
Testing
Steps to test
python -m pytest tests/ -x -qtest_workspace.pyis unrelated)daf investigate #123ordaf investigate owner/repo#123and verify session name is sanitizeddaf completeon a ticket_creation session and verify temp directory cleanup removes the parentdaf-session-*directoryScenarios tested
Deployment considerations
🤖 Generated with Claude Code