Skip to content

feat(core,api,client): writes as document state strategy actions — save and act, rooted in the operations registry (5a) - #40

Merged
jherr merged 1 commit into
mainfrom
cursor/write-actions-02f8
Nov 6, 2026
Merged

jherr merged 1 commit into
mainfrom
cursor/write-actions-02f8

Conversation

@jherr

@jherr jherr commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Implements cms-refactor-plan.md § Phase 5 (5a).

  • Writes become document state strategy actions.
  • save() stays as sugar and returns { doc, state, availableActions }.
  • createDoc, saveDoc and create_document are unified.
  • Plan item 6: an auto-approved save reports the change as live.

Merge chain: step 17 of 24. Base: main. Merge it right after #34. The branch is main 3b4a112, then one commit for each PR before this one in the merge order, then this PR's own commit 3dbbd75 (tree 0e2330b).

What

  • A write registry beside readVerbs. writeVerbs in @tanstack/cms-core declares save and act, with their schemas saveInput and actInput.

    • The save_document agent tool, the HTTP op descriptions and opSchemas all derive from it.
    • The api op set is typed satisfies Record<WriteVerbName, CmsOperation>.
    • act is agent: false, so it gets no agent tool.
  • save({ collection, id, doc, create?, publish?, expectedRevision?, expectedPendingVersion?, instruction? }) merges the doc patch onto the caller's own open change set, or onto the live document. It then picks the action:

    • An agent submits. publish is ignored.
    • A publisher edits. On a published document that's a draft, unless publish is set; with publish set, or on a document that isn't published, it's a commit.
    • Anyone else submits.

    The strategy then decides. create: true refuses an id that already exists or is already proposed, with CONFLICT.

  • act runs an offered action that carries no document: approve, reject, discard, schedule, or a custom step.

    • An action the strategy doesn't offer the caller fails with FORBIDDEN.
    • edit, submit, draft and import fail with BAD_REQUEST, because they go through save.
    • A stale expectedVersion fails with CONFLICT.
  • Both return { id, collection, doc, state, availableActions }.

    • state is { label, published, revision, changeSet: { id, version, source, publishAt } | null }.
    • doc is what the caller now sees, redacted. It's null after a rejected create.
    • documentWriteState(collection, id) reads state on its own.
  • get takes staged?: boolean (added in follow-up commits, see below). With staged: false, an edit or preview reader gets the committed row.

  • Every surface:

    • server: cmsAs(cms, ctx).save/act, saveAs, actAs;
    • HTTP/Start: the save op (content.write) and the act op;
    • client: client.save/client.act;
    • agents: save_document.
  • One write path. createDoc, saveDoc, create_document, update_document and actOnChange now run on runSave/runAct. They keep their bags, defaults and result shapes. They're deprecated, and Phase 6 removes them.

  • Docs: cms-core-server.md and cms-client.md (both with type-checked examples), the op tables, and a new upgrading step (step 27 on the merge chain).

Breaking changes (write-verbs-save-act.md: core, api and client minor)

  • Reserved names: save, act and save_document are now reserved operation names.
  • Deprecated but still working: saveDoc, createDoc, actOnChange, create_document, update_document.

Merging 3a: conflicts between 2c/3a and 4a–4d

Textual conflicts (11 files):

File Resolution
core/src/server/store/review.ts Kept 4b's strategy-routed bodies and took 2c's readDocumentAs with named system contexts. STAGE_BEFORE_READ is now defined here.
core/src/server/store/write.ts Kept 4b's bodies and took 2c's context reads. 2c's writer session now reaches afterChange/afterDelete through executeStrategyWrite and deleteDocument.
core/src/server/store/scheduling.ts Kept 4b's change-set schedule and took 2c's system-context reads.
api/src/ops.ts Kept 4b's own-source merge and strategy-decided approval, reading with 2c's OP_READ. 3a's get/list sit beside 4c's actOnChange.
docs/deployment/upgrading.md Kept both sides' upgrade steps (events, access contexts, get/list, this PR). They're numbered in merge order on the chain.
core store, plugins, readiness tests Kept 4a–4d's assertions. Reads now go through …As(systemContext('test')).
core characterization/workflow-suite.ts Kept 4b's relabelled rows. Reads take a system context.
api characterization/save-paths.test.ts Kept 4b's rows. runOp takes a context.
app/prm/tests/crm.test.ts Kept 4d's test. Reads take a context.

Semantic conflicts found after the textual merge:

  • Fail-closed reads. Some 4a–4d tests read through the deprecated plain functions, which 2c's fail-closed change now reads as public. Those tests now read with systemContext('test').
  • Hook sessions. afterChange gets the writer's session from executeStrategyWrite, so hooks see the same session on every write path.
  • app/prm/bakeoff. Kept 3a's regenerated files.

How verified

GitHub Actions is out of billing, so everything ran locally, on scratch merges into origin/main 3b4a112. The only merge conflict was scripts/codemods/index.ts, between 2c and #22, and both codemods were kept. The latest run was at 013cd74.

Check Result
pnpm install --frozen-lockfile pass
pnpm test:ci (174 tasks, cold cache) passes except the known @tanstack/cms-api:test:oxlint
test:dts / test:dialects pass
test:scripts 66/66
E2E blog / base 28/28 / 12/12
Characterization: core / libsql / postgres 37 / 83 / 120

Package suites: core 655, api 216, client 35, ui-react 85, app/prm 10. Core tsc, knip, test:docs and kiira (132/132) are clean.

New tests:

  • Core write-verbs.test.ts:
    • the registry;
    • a publisher's create, draft and publish;
    • CONFLICTs;
    • an author's submit and re-save merge;
    • agent saves stage;
    • auto-approve reports live;
    • a public visitor is refused;
    • actAs's cases;
    • a rejected create returns doc: null;
    • staged: false for a pending update, a pending create, an unpublished row, a live reader and the agent tool.
  • Api write-verbs.test.ts:
    • registry ops;
    • the HTTP save audit;
    • an author proposes and an editor approves;
    • anonymous 401;
    • reserved names;
    • HTTP get with staged: false.
  • Client: one test.

Assumptions (tasks 8–12 defaults)

  1. act is not an agent tool. Agents propose and people decide. Exposing it later is one registry flag.
  2. The act op is gated on content.read. Each action is then checked against what the strategy offers.
  3. Delete is out of scope for 5a.
  4. New ops attribute writes to the caller. The deprecated wrappers keep by: 'human'.
  5. An agent's save is always a submit.
  6. save merges a patch, with null to clear a field.
  7. A plain ?staged=false query string isn't parsed as a boolean, the same as populate today, so HTTP callers send it as JSON.

Divergence from plan

  1. No separate create verb. save takes create: true instead.
  2. Author and draft saves pass the writer's real context to the strategy.
  3. An author's re-save of their own staged create merges onto the proposal, instead of starting from scratch.
  4. actOnChange's error messages changed slightly. The codes are the same.
  5. The save/act op keys are written out by hand, typed against the registry with satisfies.
  6. staged: false is a per-verb option. terminology.md says the choice between live and working copy is made by the context's read mode, "not a boolean". A third read mode would reach list, populate, slug lookup and search. This option touches one verb, and only narrows what an edit or preview reader already sees.

Reading the committed row (follow-up, two fast-forward commits)

#39 (3d) leaves read-modify-write sites on readDocumentAs. In edit and system contexts, get overlays staged changes, but these writes need the stored row. save's patch merge can't replace these reads, for three reasons:

  • The writes depend on stored values.
  • save merges onto the caller's working copy, so a system write that publishes would also publish someone's open draft.
  • A live get misses unpublished rows.

So get({ staged: false }) is the canonical form. In Phase 6, readDocumentAs(ctx, c, id) becomes (await getAs(ctx, { collection: c, id, staged: false, populate: false }))?.doc ?? null, which is the shape #39's codemod already writes. Each #39 site maps to that form:

Site (#39) Phase 6 form
ecommerce addToCart and checkoutCart get({ staged: false }) in a system context; the write stays a full-row commit
membership completeLessonAndQuiz get({ staged: false }) in a system context
sendNewsletterIssue get({ staged: false }) in ctx.access, not a save patch, which would publish the caller's open draft
claimListing get({ staged: false }) in a system context; stageWrite stays
blog-voting votes, post tally, my-vote get({ staged: false }) with the VOTES system context
app/base committed(), submitReport, WordPress evacuation get({ staged: false }) with CHECKED
app/prm import_people and both scripts get({ staged: false }) in a system context
fleet readTenantPage get({ staged: false }) in ctx.access; this keeps today's result

No get form covers includeDeleted (trash reads).

A test merge of 3b (#35) over 013cd74 is clean in ops.ts and verbs.ts.

For DocForm (#33)

onSubmit(patch, { doc, baseline, meta }) can call:

cms.save({ collection, id, doc: patch, expectedRevision: state.revision, expectedPendingVersion: state.changeSet?.version ?? 0, publish: meta?.publish })

The result's doc becomes the next baseline, and state/availableActions drive the badge and buttons.

Merge chain (local verification, CI down)

This PR's commits are squashed into one commit on the linear merge chain. That commit holds this PR's own changes, resolved against every PR before it, with the integration rehearsal's fixes for this PR applied. No conflicts. The commit was replayed from this PR's merge of 3a (32d8e18). Its upgrading section is renumbered to step 27.

The step numbers in the upgrade guide used to collide across 3a, 3b, 3c(i), 3d and 5a. The chain renumbers them in merge order, so that clean-up is done.

The chain tip's tree is exactly the integration rehearsal plus #46 (c4e6d7c), and the tip passes the full local suite. I simulated merging every PR in order, with a merge commit or a fast-forward at each step, and every step is clean. A plain squash of the next PR would conflict, because the squash commit isn't an ancestor of the next branch. To squash instead, first rebase the branch's one commit onto the new main; that rebase is always clean.

Open in Web Open in Cursor 

@changeset-bot

changeset-bot Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a6879ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@tanstack/cms-core Minor
@tanstack/cms-api Minor
@tanstack/cms-client Minor
@tanstack/cms-cli Minor
@tanstack/cms-connect-atproto Patch
@tanstack/cms-migrate-wp Patch
@tanstack/cms-skills Patch
@tanstack/cms-media-s3 Minor
@tanstack/search-cms Patch
@tanstack/cms-store-libsql Minor
@tanstack/cms-store-postgres Patch
@tanstack/cms-ui-dom Patch
@tanstack/cms-ui-react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: TanStack/cms
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: dc7e4ab
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Free
  • Run ID: 341eee01-8235-4a5b-a05c-8a04f11679b6
Commits

Reviewing files that changed from the base of the PR and between dc7e4ab and a6879ed.

Files selected for processing: 28

  • .changeset/write-verbs-save-act.md
  • docs/agents/content-agent.md
  • docs/agents/review-queue.md
  • docs/api/cms-client.md
  • docs/api/cms-core-server.md
  • docs/api/cms-core.md
  • docs/api/routes-and-endpoints.md
  • docs/deployment/upgrading.md
  • docs/mcp/http-mcp-server.md
  • docs/mcp/operations-registry.md
  • docs/tutorials/mcp-and-webmcp.md
  • packages/api/src/ops.ts
  • packages/api/src/outputs.ts
  • packages/api/src/start.ts
  • packages/api/tests/write-verbs.test.ts
  • packages/client/src/client.ts
  • packages/client/tests/client.test.ts
  • packages/core/src/index.ts
  • packages/core/src/ops.ts
  • packages/core/src/server.ts
  • packages/core/src/server/cms-as.ts
  • packages/core/src/server/cms-ops.ts
  • packages/core/src/server/store.ts
  • packages/core/src/server/store/document-state.ts
  • packages/core/src/server/store/review.ts
  • packages/core/src/server/store/verbs.ts
  • packages/core/src/server/store/write-verbs.ts
  • packages/core/tests/write-verbs.test.ts

TanStack is on CodeRabbit Free, which includes PR summaries. Ask your admin to upgrade for code reviews.

  • Ask an admin to upgrade

Open in CodeRabbit

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

…ve and act, rooted in the operations registry (5a) (#40)

Chain step 17 of the linear merge chain onto main 3b4a112: this PR's own changes, resolved against the PRs before it in the merge order.

Co-authored-by: jherr <jherr@pobox.com>
@jherr
jherr force-pushed the cursor/write-actions-02f8 branch from 3dbbd75 to a6879ed Compare November 6, 2026 15:08
@jherr
jherr merged commit 1bd8f7e into main Nov 6, 2026
@jherr
jherr deleted the cursor/write-actions-02f8 branch November 8, 2026 01:55
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.

2 participants