Skip to content

feat: AI save and save_and_publish tools#166

Merged
mattbrailsford merged 5 commits into
devfrom
feature/cms-1740-ai-save-tools
May 14, 2026
Merged

feat: AI save and save_and_publish tools#166
mattbrailsford merged 5 commits into
devfrom
feature/cms-1740-ai-save-tools

Conversation

@mattbrailsford
Copy link
Copy Markdown
Contributor

Summary

Stacked on #160 (which itself stacks on #153). Adds two new LLM-visible tools for persisting AI-driven workspace changes:

  • save — calls the workspace's requestSubmit(); equivalent to clicking Save. Works on documents and media.
  • save_and_publish — calls the document publishing context's saveAndPublish(). Documents only.

The property-value-handler tools introduced in #160 stage changes on the workspace; until now the only way to persist them was a human clicking Save. These tools close that gap so the LLM can complete the staging → persistence flow on the user's behalf.

Design

Both tools route through the entity adapter contract, mirroring the existing applyValueChange shape:

  • UaiEntityAdapterApi gains optional save?(ctx) and publish?(ctx) methods returning a new UaiPersistResult { success, error? }.
  • UaiEntityAdapterContext gains saveSelectedEntity() / publishSelectedEntity() that delegate to the adapter and produce structured "not supported" errors when an adapter omits a method.

Per-adapter behavior:

Adapter save publish
Document requestSubmit() resolves UMB_DOCUMENT_PUBLISHING_WORKSPACE_CONTEXT as a sibling and calls saveAndPublish()
Media requestSubmit() (always live, so save IS publish) omitted — LLM gets "use save instead"
Block omitted omitted — LLM gets "save the parent document"

Two new tool scopes back the tools: entity-save and entity-publish. Both destructive. Split from the existing entity-write so an agent can be granted permission to mutate staged values without also being allowed to commit them, or to save drafts without publishing live.

Permissions migration

Agents currently using AllowedToolScopeIds: ["entity-write"] will not automatically pick these tools up. To enable them, grant the new scopes:

  • entity-save for save
  • entity-publish for publish (implies save semantics — publishing always saves first)

Agents using explicit AllowedToolIds need:

  • Uai.AgentFrontendTool.Save
  • Uai.AgentFrontendTool.SaveAndPublish

Test plan

  • Existing entity-write tools (set_value, add_item, etc.) continue to work
  • save from a document workspace persists staged AI-driven changes
  • save from a media workspace persists staged changes
  • save from a block workspace returns the structured "save the parent document" error
  • save_and_publish from a document workspace publishes the document
  • save_and_publish from a media workspace returns "use save instead"
  • save_and_publish on a multi-variant document surfaces the variant-picker modal (intentional — same UX as clicking the button)
  • An agent without entity-save scope cannot invoke save
  • An agent without entity-publish scope cannot invoke save_and_publish

🤖 Generated with Claude Code

mattbrailsford and others added 4 commits May 13, 2026 08:32
Adds optional `save?` and `publish?` methods to UaiEntityAdapterApi alongside a new
UaiPersistResult shape (mirroring UaiValueChangeResult). The entity adapter context exposes
delegating `saveSelectedEntity()` / `publishSelectedEntity()` methods that return structured
"not supported" errors when an entity type doesn't implement either operation — most
commonly when the user has a block workspace selected, since block changes save through the
parent document.

Document adapter implements both: save calls the workspace's `requestSubmit()`; publish
resolves the document publishing workspace context as a sibling (both register against the
same host) and calls `saveAndPublish()`. Media adapter implements save only — media has no
publish concept. Block adapter intentionally omits both so the missing-method path surfaces
a clear redirect to the parent document.

Two new built-in scopes back the new tools: EntitySaveScope (entity-save) and
EntityPublishScope (entity-publish). Both are destructive. Splitting them from
EntityWriteScope means an agent can be granted permission to stage value changes without
also being allowed to commit them or push them live.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two new LLM-visible tools in the entity-tool surface:

- `save` (scope entity-save) — calls UaiEntityAdapterContext.saveSelectedEntity(); the
  equivalent of the user clicking the workspace Save button. Works on documents and media.
- `save_and_publish` (scope entity-publish) — calls publishSelectedEntity(); document-only.

Both tools take no parameters since save/publish operate at the workspace level. Tool
descriptions explicitly direct the LLM toward the right tool for the entity type (no
publish on media, blocks save with their parent document) so failure modes surface a
useful error path rather than a generic rejection.

Agents currently using AllowedToolScopeIds=["entity-write"] won't pick these up; the new
scopes must be granted explicitly. Agents using AllowedToolIds need the tool IDs
Uai.AgentFrontendTool.Save and Uai.AgentFrontendTool.SaveAndPublish added.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The scope picker resolves per-scope labels and descriptions via
`uaiToolScope_${camelCase(scope.id)}Label` / `Description` keys, falling back to the raw
scope id when no key is registered. Adds entries for the new entity-save and entity-publish
scopes so they render as "Save Entity" / "Publish Entity" rather than the raw ids.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adapt the save and save_and_publish tools to the new manifest layout where
HITL approval lives on the frontend tool, not the renderer.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mattbrailsford mattbrailsford force-pushed the feature/cms-1740-ai-save-tools branch from a7f5807 to 6cf34e0 Compare May 13, 2026 07:35
@mattbrailsford mattbrailsford changed the base branch from feature/cms-1740-property-value-handlers to dev May 14, 2026 07:44
@mattbrailsford mattbrailsford merged commit baa6fb0 into dev May 14, 2026
11 of 23 checks passed
@mattbrailsford mattbrailsford deleted the feature/cms-1740-ai-save-tools branch May 14, 2026 07:58
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