Steer agent to use Jetpack Forms instead of raw HTML forms - #3351
Conversation
Introduces a generic plugin-recommendations architecture so the agent knows which plugins to reach for instead of hand-rolling HTML. Adding a new rule requires only one object in the PLUGIN_RECOMMENDATIONS array — the system prompt and block content policy both pick it up automatically. First two rules: - Jetpack Forms: agent installs Jetpack and uses jetpack/contact-form + jetpack/field-* blocks instead of raw <form> HTML. The block content policy now flags <form> HTML with a targeted error pointing to Jetpack. - WooCommerce: agent installs WooCommerce and uses woocommerce/* blocks for any shop, product listing, cart, or checkout request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Update the form-markup test to assert the Jetpack-specific error message instead of expecting an empty array (the old allowed-exception behavior) - Replace non-existent woocommerce/product-grid with woocommerce/product-collection in the recommendation blocks list and guidance text Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Current Jetpack releases create core/button for form submission rather than the legacy jetpack/button block. Update both the blocks list and the example markup in the Jetpack Forms recommendation to match. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The previous example used self-closing field blocks, but real Jetpack forms use composite field blocks where each field wraps jetpack/label + jetpack/input children. Updates the recommendation to reflect this: - Replace the simplified self-closing example with the actual markup Jetpack inserts when clicking "contact form" in the block editor - Add jetpack/label and jetpack/input to the blocks list - Explain the inner-block structure in the field-type description Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Scope this PR to Jetpack Forms only. WooCommerce can land as a follow-up once the plugin recommendation architecture is reviewed and merged. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
📊 Performance Test ResultsComparing f78e842 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) |
|
Pushed ProblemTested this branch end-to-end against a fresh local site by running the agent with "add a contact form". The agent followed the guidance perfectly — installed Jetpack, generated the prescribed Root cause: in Jetpack 15.7, The failure is silent: Reproduction (before the fix)$ wp plugin install jetpack --activate
$ wp jetpack module list | grep contact-form
contact-form Inactive
$ wp eval 'echo count(array_filter(array_keys(\WP_Block_Type_Registry::get_instance()->get_all_registered()), fn($n) => str_starts_with($n, "jetpack/")));'
0
# After adding a jetpack/contact-form block to a page:
$ curl -s http://localhost:8889/ | grep -c '<form'
0
$ curl -s http://localhost:8889/ | grep -c '<input'
0I confirmed empirically that only the Fix in this commitUpdates the Jetpack Forms guidance to instruct the agent to activate the module after installing the plugin: Re-ran the agent end-to-end with the new build — it followed the new instruction, and the rendered form now has 1 DisclosureFix and this comment were drafted by Claude after I confirmed the reproduction and fix manually. |
|
Ok this is working well :) |
Related issues
How AI was used in this PR
This PR was generated with Claude Code. The architecture and guidance text were written by AI and reviewed for correctness.
Proposed Changes
Introduces a
plugin-recommendations.tsregistry so the agent knows which plugins to reach for rather than hand-rolling raw HTML. Each entry in the registry declares the plugin, its blocks, guidance text for the system prompt, and optional HTML patterns to flag in the block content policy. Adding new rules in the future (e.g. WooCommerce) requires only one object in the array — no other files change.This PR ships one rule: Jetpack Forms.
When the agent is asked for any form (contact, feedback, newsletter, survey), it now:
jetpack/contact-formandjetpack/field-*blocks using the exact composite markup Jetpack generates in the editor<form>element in acore/htmlblockFiles changed:
apps/cli/ai/plugin-recommendations.ts(new) — the recommendation registryapps/cli/ai/block-content-policy.ts—<form>HTML no longer silently passes; the policy loop iteratesPLUGIN_RECOMMENDATIONSso any rule withhtmlPatternsis enforced automaticallyapps/cli/ai/system-prompt.ts— local content guidelines now append allguidancestrings from the registryTesting Instructions
jetpack/contact-formblock markup, not a<form>element<!-- wp:html -->…<form>…</form>…<!-- /wp:html -->block in content and runvalidate_blocks→ the policy should return the Jetpack-specific error message (not the generic "use core blocks" message)Pre-merge Checklist