Skip to content

Fix hardcoded path in arxiv_to_md sub_agent.py#18

Open
ArtyT wants to merge 3 commits into
solatis:mainfrom
ArtyT:fix/hardcoded-path-arxiv-to-md
Open

Fix hardcoded path in arxiv_to_md sub_agent.py#18
ArtyT wants to merge 3 commits into
solatis:mainfrom
ArtyT:fix/hardcoded-path-arxiv-to-md

Conversation

@ArtyT

@ArtyT ArtyT commented Feb 5, 2026

Copy link
Copy Markdown

Summary

  • Replace hardcoded /Users/lmergen/.claude/skills/scripts path with dynamic __file__-based resolution using pathlib
  • Use string concatenation (not f-strings) to inject the path, avoiding brace collision with {result} template placeholder on line 103
  • Add package-level CLAUDE.md and README.md documenting path resolution architecture and template system design

Test plan

  • Module loads without error: python3 -c 'import skills.arxiv_to_md.sub_agent'
  • No hardcoded paths remain: grep -r '/Users/lmergen' skills/scripts/skills/arxiv_to_md/
  • SCRIPTS_DIR resolves to correct skills/scripts/ directory
  • End-to-end: run arxiv-to-md skill to convert a paper

Closes #16

🤖 Generated with Claude Code

…t.py

Replace hardcoded '/Users/lmergen/.claude/skills/scripts' with dynamic
__file__-based resolution using pathlib so the sub-agent works on any
machine. Uses string concatenation instead of f-strings to avoid brace
collision with {result} template placeholder.

Closes solatis#16

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Fix hardcoded path and document path resolution architecture

🐞 Bug fix 📝 Documentation

Grey Divider

Walkthroughs

Description
• Replace hardcoded author path with dynamic __file__-based resolution
• Use string concatenation to inject SCRIPTS_DIR into template, avoiding f-string brace collision
  with {result} placeholder
• Add comprehensive documentation explaining path resolution architecture and template system design
Diagram
flowchart LR
  A["Hardcoded Path<br/>/Users/lmergen/.claude/skills/scripts"] -->|Replace| B["Dynamic Resolution<br/>Path(__file__).resolve().parent.parent.parent"]
  B -->|Inject via| C["String Concatenation<br/>SCRIPTS_DIR variable"]
  C -->|Avoid| D["F-string Brace Collision<br/>with {result} placeholder"]
  E["Documentation<br/>CLAUDE.md + README.md"] -->|Explain| B
  E -->|Explain| D
Loading

Grey Divider

File Changes

1. skills/scripts/skills/arxiv_to_md/sub_agent.py 🐞 Bug fix +10/-2

Replace hardcoded path with dynamic resolution

• Import pathlib.Path and compute SCRIPTS_DIR dynamically at module load time using __file__
 resolution
• Replace hardcoded /Users/lmergen/.claude/skills/scripts path with SCRIPTS_DIR variable via
 string concatenation
• Add detailed comments explaining why string concatenation is used instead of f-strings to avoid
 brace collision with {result} template placeholder
• Document rejected alternatives (os.getcwd(), os.path.expanduser()) with rationale

skills/scripts/skills/arxiv_to_md/sub_agent.py


2. skills/scripts/skills/arxiv_to_md/CLAUDE.md 📝 Documentation +13/-0

Add module index and navigation guide

• Create new package-level index file documenting all files in the arxiv_to_md module
• Provide quick reference table mapping files to their contents and when to read them
• Link to README.md for deeper understanding of path resolution and template system

skills/scripts/skills/arxiv_to_md/CLAUDE.md


3. skills/scripts/skills/arxiv_to_md/README.md 📝 Documentation +30/-0

Document architecture and design decisions

• Document the path resolution problem and solution using Path(__file__).resolve()
• Explain why __file__-based resolution works universally across installations
• Detail rejected alternatives with specific rationale for each (os.getcwd() fragility,
 expanduser() incorrect repo location)
• Explain the template system design and f-string trap when {result} placeholder is present
• Justify string concatenation approach over f-strings and str.format() alternatives
• Document invariants about PHASES dict execution context and bash heredoc behavior

skills/scripts/skills/arxiv_to_md/README.md


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Feb 5, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider


Action required

✅ 1. Unescaped path injection 🐞 Bug ⛯ Reliability
Description
• Phase 2 constructs a Python source line by concatenating SCRIPTS_DIR inside single quotes, but
does not escape characters that are special in Python string literals. • If the absolute path
contains backslashes (common on Windows) it can produce invalid escape sequences (e.g., \U...) and
raise a SyntaxError before preprocessing runs; if the path contains a single quote, it will also
break the literal. • This fails the workflow at runtime in the Bash heredoc step, preventing
preprocess_tex() from being imported/executed.
Code

skills/scripts/skills/arxiv_to_md/sub_agent.py[107]

+            "sys.path.insert(0, '" + SCRIPTS_DIR + "')",
Evidence
SCRIPTS_DIR is computed as a filesystem path string at module load, then spliced verbatim into a
Python statement (as text) that will later be executed by python3 inside the bash heredoc. Because
the splice uses manual single-quote wrapping, any quotes/backslashes in the path can invalidate the
generated Python code.

skills/scripts/skills/arxiv_to_md/sub_agent.py[20-24]
skills/scripts/skills/arxiv_to_md/sub_agent.py[100-112]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Phase 2 generates Python code text that is later executed in a bash heredoc. The generated line `sys.path.insert(0, &amp;#x27;&amp;lt;SCRIPTS_DIR&amp;gt;&amp;#x27;)` is built via manual string concatenation without escaping. This can produce invalid Python when `SCRIPTS_DIR` contains backslashes (Windows paths) or single quotes.
### Issue Context
`SCRIPTS_DIR` is computed from `__file__` at module import time and then spliced into a template string that is executed by a different Python process (`python3 &amp;lt;&amp;lt; &amp;#x27;EOF&amp;#x27;`). Because this is *source code generation*, the inserted path must be a valid Python string literal.
### Fix
Change the injected action line to use `repr(SCRIPTS_DIR)` (or `json.dumps(SCRIPTS_DIR)`) so the resulting Python statement is syntactically valid across paths:
- Preferred: `&amp;quot;sys.path.insert(0, &amp;quot; + repr(SCRIPTS_DIR) + &amp;quot;)&amp;quot;`
### Fix Focus Areas
- skills/scripts/skills/arxiv_to_md/sub_agent.py[22-24]
- skills/scripts/skills/arxiv_to_md/sub_agent.py[100-108]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

ⓘ The new review experience is currently in Beta. Learn more

Grey Divider

Qodo Logo

ArtyT and others added 2 commits February 11, 2026 21:33
Addresses PR review: manual single-quote wrapping of SCRIPTS_DIR could
produce invalid Python if the path contains backslashes or quotes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Accept main's version of sub_agent.py which already includes the
MODULE_PATH fix from this PR in its refactored form.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
gcharang added a commit to playactai/claude-config that referenced this pull request Apr 16, 2026
PR solatis#21 (incoherence.py): add --thoughts CLI arg with context
propagation via <context> block and next-cmd placeholder, replace
substring "COMPLETE" check with exact WORKFLOW COMPLETE. sentinel,
and add SUB-AGENT TASK COMPLETE branch so terminal sub-agent steps
(7/11/19) return to parent instead of chaining forward.

PR solatis#18 (arxiv_to_md): replace hardcoded /Users/lmergen path in
sub_agent.py with SCRIPTS_DIR computed from __file__, injected via
repr() to survive backslashes and embedded quotes (Qodo review).
Add package-level CLAUDE.md and README.md documenting the path
resolution approach and the f-string vs {result} brace-collision
trap.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

hardcoded path to authors home directory in sub_agent.py in arxiv_to_md skill

1 participant