Skip to content

Let the AI Workspace propose a workflow for a person to approve - #196

Draft
whyisjake wants to merge 1 commit into
mainfrom
feat/ai-workspace-propose-sequence
Draft

whyisjake wants to merge 1 commit into
mainfrom
feat/ai-workspace-propose-sequence

Conversation

@whyisjake

@whyisjake whyisjake commented Nov 14, 2026 •

Copy link
Copy Markdown

Intent

Lets the WordPress AI plugin's AI Workspace design an editorial workflow that a person approves before it exists. The AI Workspace never offers the model a tool that writes, so create-sequence can't be reached from it. A write there goes through a proposal kind instead: the model calls the kind's propose ability, the person sees the stored values on an approval card, and the kind writes them once they approve. This adds that kind for sequences.

It pairs with WordPress/ai#1004 (AI Workspace, landing in WordPress AI 1.6.0). It needs no change in the AI plugin: a create kind with no card of its own renders as the AI plugin's generic create card.

Spec changes

  • M5 (A team sets up a workflow by describing it): one sentence added. In the AI Workspace the agent can only propose the sequence, and approving creates it as a draft.
  • REST and Abilities: new row for vip-workflows/propose-sequence (manage_options, re-checked at approval; not in REST or MCP).
  • Sequences and stages → Footguns: two new entries.
    • A sequence created as a draft is briefly active. This is existing behavior in create_item(), which this feature relies on.
    • The proposal kind follows an interface the AI plugin marks internal.
  • Sequences and stages → Code: the new includes/ai-workspace/ files.

What was done

A workflow proposal kind (includes/ai-workspace/class-sequence-proposal.php)

  • SequenceProposal implements the AI plugin's Proposal_Kind interface directly, without extending its internal Proposal_Writer base.
  • It proposes one sequence per proposal (max_items 1), only creates (is_update false), and takes no edits on the card (accepts_edits false).
  • When proposed: normalize_item() requires a name, stages and at least one registered post type. It runs the stages through validate-sequence, the same dry run of the write gate the sequence editor and create-sequence use, so the card never shows a sequence that can't be saved. Stages and post types are stored as JSON, because the AI plugin stores a kind's fields as strings.
  • On the card: present_item() gives the name, post_type: workflow, status: draft, the description, and the stages in order (Pitch → Draft → Edit → Legal review → Ready to publish). The button then reads "Create 1 draft".
  • On approval: write() re-checks manage_options, then creates the sequence through create-sequence with status: draft. It reports every outcome count, calls $on_item for each item, and links to admin.php?page=vip-workflows-sequences#/edit/{id}.

A propose ability (includes/ai-workspace/class-propose-sequence.php)

  • vip-workflows/propose-sequence stores the proposal and writes nothing.
  • readonly: false, show_in_rest: false, mcp.public: false, the same as the AI plugin's own propose abilities.
  • It refuses to run outside an AI Workspace turn.
  • Its stage schema is taken from create-sequence's input schema, so the two can't drift.

A module that is idle without the AI plugin (includes/ai-workspace/class-ai-workspace.php)

  • AIWorkspace adds the kind on wpai_workspace_proposal_kinds and registers the ability on wp_abilities_api_init at priority 11, after create-sequence.
  • Both check interface_exists( Proposal_Kind ) first, so without the AI plugin nothing loads.
  • Registered in Plugin::init_components().

Tests

  • tests/phpunit/Integration/AIWorkspaceSequenceProposalTest.php has 9 tests against the real write path: kind metadata, field stripping, refusal of an invalid graph and of missing fields, the card fields, a draft created with every count reported, a deselected item, and capability revoked between proposing and approving.
  • tests/phpunit/stubs/ai-workspace.php copies the AI plugin's Proposal_Kind signatures for the test environment, which doesn't load the AI plugin.
  • CopyStandardTest exempts the three strings written for the model, matching how ability strings under abilities/ are already exempt.

How to test

  1. cd vip-workflows && composer test: the unit suite passes.
  2. npm run test:php:integration: the integration suite passes. Ran locally: 627 tests OK, including the 9 new ones.
  3. Manual, with the AI plugin's feat/ai-workspace branch active and the AI Workspace experiment on:
    • Ask the AI Workspace: "Design an editorial workflow for our legal-reviewed explainer posts."
    • The card offers "Create 1 draft", with the stages under Preview.
    • Approve it, then follow Open. The sequence editor shows the new sequence, saved as a draft.

Verified locally against WordPress/ai at 58323606, driven by a script rather than a live model:

  • The propose ability is refused outside a turn.
  • Inside a turn it stores a proposal, and the card shows the five stages.
  • Executing the proposal returns 200 with created: 1, and the row is stored with status=draft.
  • Re-executing the same proposal writes nothing new.

Follow-ups

  • Duplicate detection. The AI plugin finds an already-written item through post meta (_wpai_workspace_proposal_item), and sequences aren't posts. Protection against writing twice therefore relies on the AI plugin claiming the proposal and marking it executed, and duplicate is always 0. If the stored proposal expired and the same proposal ran again, it would create a second draft.
  • Audit log. Approvals of this kind write no rows to the AI plugin's audit log. Its logger is internal, so log_operation() names the operation but nothing records it.
  • Non-atomic draft creation. create_item() inserts the sequence as active and then sets draft in a second write. Making that one write would close the footgun above.

AI assistance: Yes. Tool(s): Claude Code (Claude Opus 5.5). Used for: implementing the proposal kind, the ability and the module, writing the integration tests and the SPEC.md changes, and running the local verification described above.

@whyisjake to confirm: [review attestation — replace with your own sentence once you have reviewed the change]

🤖 Generated with Claude Code

Open WordPress Playground Preview

The WordPress AI plugin's AI Workspace never offers the model a tool that
writes, so create-sequence is not reachable from it. A write there goes
through a proposal kind instead: the model calls the kind's propose ability,
the person sees the stored values on a card, and the kind writes them on
approval.

Adds a `workflow` proposal kind and its `vip-workflows/propose-sequence`
ability. Proposed stages pass validate-sequence when they are stored, and
approval creates the sequence through create-sequence as a draft, with
manage_options re-checked at approval. Both are registered only while the AI
plugin's Proposal_Kind interface exists.

Co-Authored-By: Claude Opus 5.5 <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.

1 participant