Repository navigation
Conversation
…vents An observe: true hook config registers content:beforeSave with only content:read; the pipeline hands it a shallow-cloned event and discards its return value so it cannot mutate the draft. ContentHookEvent gains an optional id, set on updates where the payload data carries no id. The plugin-cli probe and dev pipeline forward the new flag.
The manifest declared only content:read, so core skipped content:beforeSave (requires content:write) and media:afterUpload (requires media:read) at registration — update audit entries lost their before/after diffs and media uploads were never audited. Add media:read, register beforeSave as an observe hook keyed by the new event id, and cover the manifest/code coupling and the diff flow with tests wired into test:unit.
Observers now get a structuredClone of the content so nested mutation cannot leak into the save, and their errors are recorded but never abort the pipeline — a content:read observer can no longer alter or veto a save through any path. Reject observe on unsupported hooks and observe+exclusive at definePlugin, adaptSandboxEntry, and plugin-cli build time. Pass resolvedItem?.id (never a raw slug) as the beforeSave event id and forward it through PluginManager. audit-log caches the prior field data (matching the shape of changes.after), bounds its before-state cache, and its test stubs the real ContentItem shape.
🦋 Changeset detectedLatest commit: dca6498 The changes in this PR will be included in the next version bump. This PR includes changesets to release 18 packages
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 |
Scope checkThis PR changes 667 lines across 26 files. Large PRs are harder to review and more likely to be closed without review. If this scope is intentional, no action needed. A maintainer will review it. If not, please consider splitting this into smaller PRs. See CONTRIBUTING.md for contribution guidelines. |
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ✅ Deployment successful! View logs |
docs | c85c1cf | Aug 31 2026, 08:48 AM |
@emdash-cms/admin
@emdash-cms/auth
@emdash-cms/auth-atproto
@emdash-cms/blocks
@emdash-cms/cloudflare
@emdash-cms/contentful-to-portable-text
emdash
create-emdash
@emdash-cms/gutenberg-to-portable-text
@emdash-cms/plugin-cli
@emdash-cms/plugin-types
@emdash-cms/registry-client
@emdash-cms/registry-lexicons
@emdash-cms/registry-moderation
@emdash-cms/registry-verification
@emdash-cms/sandbox-workerd
@emdash-cms/x402
@emdash-cms/plugin-ai-moderation
@emdash-cms/plugin-atproto
@emdash-cms/plugin-audit-log
@emdash-cms/plugin-color
@emdash-cms/plugin-embeds
@emdash-cms/plugin-field-kit
@emdash-cms/plugin-forms
@emdash-cms/plugin-webhook-notifier
commit: |
Overlapping PRsThis PR modifies files that are also changed by other open PRs:
This may cause merge conflicts or duplicated work. A maintainer will coordinate. |
What does this PR do?
Fixes the audit-log plugin's hooks being skipped at registration on every scaffolded-site boot:
The manifest declared only
content:read, butHOOK_REQUIRED_CAPABILITYrequirescontent:writeforcontent:beforeSaveandmedia:readformedia:afterUpload. Update audit entries lost their before/after diffs and media uploads were never audited.Resolution of the design fork (over-grant
content:writevs. teach core about read-only observation): the capability system's own design leans hard toward legible least-privilege (hooks.email-events:registerexists precisely so "reads email events" is visible separately from "can send email"), andcontent:writehands a plugin the fullctx.contentwrite API. Granting write access to an audit plugin whose manifest is documented as a read-only trust contract seemed wrong, so core gets the distinction:observe: trueoncontent:beforeSaveregisters the hook withcontent:read. It's enforced, not honor-system: the handler gets astructuredCloneof the content (nested mutation can't leak), its return value is discarded, and its errors are logged without aborting the pipeline — an observer cannot alter or veto a save through any path.observeon any other hook, or combined withexclusive, is rejected atdefinePlugin,adaptSandboxEntry, andplugin-clibuild time.ContentHookEventgains an optionalid, set on updates. This turned out to be a second, hidden blocker: the update payload'scontentcarries only field data (idis a reserved field slug), so the audit plugin's before-state cache could never be keyed — diffs were broken even with the hook registered. The id passed isresolvedItem?.id, never a raw slug.media:read, registersbeforeSaveas an observer keyed byevent.id, caches the prior field data sochanges.beforematches the shape ofchanges.after, and bounds the before-state cache (the consuming after-hook never fires for failed saves).Verified live on the blog template: no
[hooks]warnings on boot, and an authenticated post update produces an audit entry with bothbeforeandafter.An adversarial review pass (see disclosure) ran before pushing; its three blocking findings (shallow clone was mutable through nested references, an observer could veto saves via the default
errorPolicy: "abort", and the before/after shapes mismatched) are fixed in the last commit, along with most minors.Notes / consciously not done:
runSandboxedBeforeSave) applies hook results without any capability gating and ignoresobserve— pre-existing for that tier, unchanged here. Worth its own issue.emdashpeer floor stays at>=0.15.0: on older cores the plugin degrades to exactly today's behavior (skip + warning), which seemed better than a hard install failure; the changeset spells it out.ctx.content.getreads the published record, sochanges.beforeis the last published state rather than the previous draft — existing accessor semantics, noted here for reviewers.Closes # — no issue; direct maintainer instruction.
Type of change
Checklist
pnpm typecheckpassespnpm lintpassespnpm testpasses (or targeted tests for my change) — fullemdashsuite plus new targeted tests; audit-log's new test package is wired intotest:unitpnpm formathas been run (scoped to touched files to avoid unrelated repo drift)adaptSandboxEntry+HookPipeline(fails with exactly the two projector warnings on the old code); a before/after diff-flow test against the real handlersemdashminor +@emdash-cms/plugin-clipatch, and@emdash-cms/plugin-audit-logpatchobserveoption is the fix mechanism)AI-generated code disclosure
Screenshots / test output
Live blog-template check (dev server, authenticated update via API):