Repository navigation
Studio Code: Refuse a file path given as wp_cli --post_content instead of rewriting the command - #5327
Conversation
…d of rewriting the command Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
📊 Performance Test ResultsComparing 84210ae vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
|
This is how I originally had my PR written, but I decided to route the intent to reduce friction. Are you sure it's a problem? |
|
Your rewrite isn’t wrong, and it saves a retry when the file exists in the site folder. I went with the refusal mainly for simplicity (I think going for the simplest solution compounds long term in a project). It also covers the cases the rewrite misses (missing file, file outside the site, path with a space), where the path still gets saved as the content. One retry seems a fair price for that, wdyt. |
|
I'm in full agreement about simpler = better. But sometimes we can compensate for the fact that LLMs are non-deterministic by allowing them to make mistakes and simply doing what they intended to do. I'm cool with either approach for this one |
Related issues
post update 5 --post_content=<site>/tmp/header-new.htmlsaved the path as the header's content, and the agent reported success.post create/updatecommands so it can check that file's block markup.How AI was used in this PR
Claude Code reviewed #5305 together with the other
--post_contentPRs (#5310, #5312, #5241), suggested this simpler fix, wrote the change and tests, and ran the checks below. I reviewed the diff.Proposed Changes
#5305 handled this mistake by quietly rewriting the command so WP-CLI reads the file. This PR refuses the command instead, the same way
wp_clialready handles$(cat file), typographic dashes and JSON that doesn't parse. When--post_contentis just a file path, nothing is saved and the agent is told to pass the path as a positional argument (post update <id> <file>), which the tool description already recommends.Why a refusal is better:
Content that only mentions a path (
See tmp/header.html,<p>tmp/header.html</p>), block markup and JSON are saved as before.Testing Instructions
npx vitest run apps/cli/lib/tests/wp-cli-post-content.test.ts apps/cli/ai: 332 pass. New cases: an absolute path, a relative path followed by--porcelain, a.jsonpath (all refused); a bare word, text and markup that mention a path, and block markup (all saved as written).npm run typecheckpasses.template-part-db-overridecase only hits this when the agent happens to make the mistake, so one run wouldn't show the difference.Pre-merge Checklist
🤖 Generated with Claude Code