Skip to content

Fix WP-CLI post content parsing before porcelain flags - #3264

Merged
youknowriad merged 1 commit into
trunkfrom
codex/fix-porcelain-post-drafts
Apr 28, 2026
Merged

Fix WP-CLI post content parsing before porcelain flags#3264
youknowriad merged 1 commit into
trunkfrom
codex/fix-porcelain-post-drafts

Conversation

@youknowriad

@youknowriad youknowriad commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

I noticed the studio code agent sometimes includes things like "--porcelain" in the actual content of the pages, this PR should fix it.

Summary

  • Split quoted --post_content values so later WP-CLI flags are not absorbed into the post body
  • Reject typographic dash options like –porcelain before dispatching the command
  • Add regression coverage for quoted content followed by flags and for invalid dash input

Testing

  • Added unit test coverage for the parser and wp_cli tool behavior
  • Lint and formatting passed
  • Typecheck passed
  • Targeted test file passed
@wpmobilebot

Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 176f3b0 vs trunk

app-size

Metric trunk 176f3b0 Diff Change
App Size (Mac) 1453.92 MB 1453.92 MB 0.01 MB ⚪ 0.0%

site-editor

Metric trunk 176f3b0 Diff Change
load 1861 ms 1532 ms 329 ms 🟢 -17.7%

site-startup

Metric trunk 176f3b0 Diff Change
siteCreation 8081 ms 8087 ms +6 ms ⚪ 0.0%
siteStartup 4944 ms 4949 ms +5 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

@youknowriad
youknowriad merged commit b8fe392 into trunk Apr 28, 2026
13 checks passed
@youknowriad
youknowriad deleted the codex/fix-porcelain-post-drafts branch April 28, 2026 09:58
youknowriad added a commit that referenced this pull request May 4, 2026
Brings in 53 commits since the last merge. Conflict resolution + ports:

- `apps/cli/ai/agent.ts`: kept the dual-runtime dispatch from this branch;
  absorbed trunk's drop of `maxTurns` (no longer destructured, no longer
  threaded to runtimes). Body contention with #3272's inline `query()`
  changes (mcpServers, remoteSession, STUDIO_REMOTE_SESSION env detection)
  was resolved by deferring those to the Anthropic runtime layer where the
  `query()` call now lives.
- `apps/cli/ai/runtimes/anthropic/index.ts`: ported #3272's improvements —
  `STUDIO_REMOTE_SESSION` env → `remoteSession` flag → systemPromptOptions
  (the Telegram bridge sets this when it spawns `studio code --json`).
  Dropped maxTurns from query() options to match trunk.
- `apps/cli/ai/runtimes/types.ts`, `apps/cli/ai/runtimes/openai/index.ts`,
  tests: dropped maxTurns from `AgentRuntimeConfig` and all callers.
- `apps/cli/ai/tools.ts` deleted on our side, modified on trunk: deleted
  in resolution. Trunk's #3272 additions were ported into our split-tools
  layout:
    - `apps/cli/ai/tools/screenshot-helpers.ts` (new): shared
      `captureScreenshotPng` + viewport constants.
    - `apps/cli/ai/tools/share-screenshot.ts` (new): the `share_screenshot`
      tool that emits a `media.share` event for the remote-session bridge.
    - `apps/cli/ai/tools/take-screenshot.ts`: refactored onto the shared
      helper; updated description to point at share_screenshot.
    - `apps/cli/ai/tools/index.ts`: registry includes shareScreenshotTool;
      `resolveStudioToolDefinitions` now uses an exclusion-set model so
      both preview-steering and (when not enabled) share_screenshot get
      filtered consistently. `createRemoteSiteTools` includes
      shareScreenshotTool when `isRemoteSessionEnabled()`.
- `apps/cli/ai/tools/utils.ts`: ported #3286's progress-update coalescing
  — `update: true` now overwrites the last progress message in
  `captureCommandOutput` instead of appending.
- `apps/cli/ai/tools/wp-cli.ts`: ported #3264's smarter `--post_content=`
  quote handling (flags after a quoted post_content are now parsed
  correctly) and the typographic-dash rejection that catches
  `‐porcelain` / `–color` etc. before they hit WP-CLI as silent garbage.
- `apps/ui/src/components/session-view/composer/index.tsx`: trunk
  converted Composer to `forwardRef` with a `ComposerHandle.appendDraft`
  imperative method (used by trunk's annotate-toolbar hand-off). Merged
  the forwardRef structure with our composer-owned cross-family swap
  state, dialog, and hooks. Kept trunk's Escape-to-interrupt keydown
  handler and the textareaRef.
- `apps/ui/src/components/session-view/index.tsx`: absorbed trunk's
  annotation handler (`handleAnnotationsDone`), the Annotation type
  import, and the SitePreview `onAnnotationsDone` prop. Dropped the
  unused-by-the-merged-body `useConnector` import.

Verified: typecheck has only the pre-existing #3320 (`@wp-playground` bump)
error in `apply-blueprint-form-values.ts` that's also present on plain
trunk; 1532 tests pass; lint clean; CLI builds.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
youknowriad added a commit that referenced this pull request May 4, 2026
Brings in 53 commits since the last merge. Conflict resolution + ports:

- `apps/cli/ai/agent.ts`: kept the dual-runtime dispatch from this branch;
  absorbed trunk's drop of `maxTurns` (no longer destructured, no longer
  threaded to runtimes). Body contention with #3272's inline `query()`
  changes (mcpServers, remoteSession, STUDIO_REMOTE_SESSION env detection)
  was resolved by deferring those to the Anthropic runtime layer where the
  `query()` call now lives.
- `apps/cli/ai/runtimes/anthropic/index.ts`: ported #3272's improvements —
  `STUDIO_REMOTE_SESSION` env → `remoteSession` flag → systemPromptOptions
  (the Telegram bridge sets this when it spawns `studio code --json`).
  Dropped maxTurns from query() options to match trunk.
- `apps/cli/ai/runtimes/types.ts`, `apps/cli/ai/runtimes/openai/index.ts`,
  tests: dropped maxTurns from `AgentRuntimeConfig` and all callers.
- `apps/cli/ai/tools.ts` deleted on our side, modified on trunk: deleted
  in resolution. Trunk's #3272 additions ported into our split-tools
  layout:
    - `apps/cli/ai/tools/screenshot-helpers.ts` (new): shared
      `captureScreenshotPng` + viewport constants.
    - `apps/cli/ai/tools/share-screenshot.ts` (new): the `share_screenshot`
      tool that emits a `media.share` event for the remote-session bridge.
    - `apps/cli/ai/tools/take-screenshot.ts`: refactored onto the shared
      helper; updated description to point at share_screenshot.
    - `apps/cli/ai/tools/index.ts`: registry includes shareScreenshotTool;
      `resolveStudioToolDefinitions` now uses an exclusion-set model so
      both preview-steering and (when not enabled) share_screenshot get
      filtered consistently. `createRemoteSiteTools` includes
      shareScreenshotTool when `isRemoteSessionEnabled()`.
- `apps/cli/ai/tools/utils.ts`: ported #3286's progress-update coalescing
  — `update: true` now overwrites the last progress message in
  `captureCommandOutput` instead of appending.
- `apps/cli/ai/tools/wp-cli.ts`: ported #3264's smarter `--post_content=`
  quote handling (flags after a quoted post_content are now parsed
  correctly) and the typographic-dash rejection that catches
  `‐porcelain` / `–color` etc. before they hit WP-CLI as silent garbage.
- `apps/ui/src/components/session-view/composer/index.tsx`: trunk
  converted Composer to `forwardRef` with a `ComposerHandle.appendDraft`
  imperative method (used by trunk's annotate-toolbar hand-off). Merged
  the forwardRef structure with our composer-owned cross-family swap
  state, dialog, and hooks. Kept trunk's Escape-to-interrupt keydown
  handler and the textareaRef.
- `apps/ui/src/components/session-view/index.tsx`: absorbed trunk's
  annotation handler (`handleAnnotationsDone`), the Annotation type
  import, and the SitePreview `onAnnotationsDone` prop. Dropped the
  unused-by-the-merged-body `useConnector` import.

Verified: typecheck has only the pre-existing #3320 (`@wp-playground` bump)
error in `apply-blueprint-form-values.ts` that's also present on plain
trunk; 1532 tests pass; lint clean; CLI builds.

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

2 participants