mirror of
https://github.com/penpot/penpot.git
synced 2026-11-26 21:00:32 +00:00
📚 Separate plugin save and rollback guidance
Move shared save queue and rollback event contracts into a focused memory and link the MCP guidance to it. AI-assisted-by: gpt-6.1-terra
This commit is contained in:
parent
ea458b85ca
commit
b24ef3cbc5
@ -7,7 +7,7 @@ Start at `app.main.ui` for Rumext components, `app.main.data` for Potok events,
|
||||
- CLJS components, Design System, SCSS modules, accessibility and render cost: `mem:frontend/ui-conventions-and-style-system`.
|
||||
- JS/TS packages, shared React UI, Storybook and text editor boundaries: `mem:frontend/ui-packages-text-editor-workflow`.
|
||||
- PO files and locale conventions: `mem:frontend/translations`.
|
||||
- JS Plugin API bindings and proxies: `mem:frontend/plugin-api-to-cljs-binding`. External SaaS hooks and script load order: `mem:frontend/host-integration`.
|
||||
- JS Plugin API bindings and proxies: `mem:frontend/plugin-api-to-cljs-binding`; plugin save waits and rollback events: `mem:frontend/plugin-save-events`. External SaaS hooks and script load order: `mem:frontend/host-integration`.
|
||||
|
||||
## Workspace
|
||||
|
||||
|
||||
@ -34,10 +34,7 @@
|
||||
|
||||
## Events and history
|
||||
|
||||
- Plugin listeners are watches on the global store and callbacks are debounced about 10ms. Callback exceptions are caught and logged so plugin code does not crash the app.
|
||||
- Most plugin listeners watch the global store and debounce callbacks about 10ms. Callback exceptions are caught and logged so plugin code does not crash the app; rollback uses a separate stream subscription.
|
||||
- `selectionchange` callbacks receive arrays of shape id strings, while `filechange`, `pagechange`, and `shapechange` return proxies.
|
||||
- `contentsave` fires only when persistence status transitions to `:saved`; it calls the callback with no value.
|
||||
- `penpot.waitForSave(timeout?)` (`app.plugins.persist/wait-for-save`; runtime forwarder checks `content:read`) waits on the **shared** persistence queue, not only the plugin's own commits. Flow: ~100ms intake race (buffer/queue non-empty vs deadline, capped to the timeout) → empty resolves; pending emits `::dps/force-persist` and races `dps/wait-persisted-or-error` against `::dps/rollback-rejected` / `::dps/rolled-back` (rollback rejects even if status later reads `:saved`). Default 60s. `:error` status at intake rejects at once (`earlier-failure`): `save-retrying` while `dps/save-retrying?` (slow retry cycle, recovers by itself), otherwise the stored `[:error :code]` with reopen advice (a terminal failure stays until the file is reopened, so it fails every call). Rejections are `Error`s with `code`: `save-timeout`, `rolled-back`, `save-retrying`, or the failure code (`save-failed` unless the backend gave one).
|
||||
- Plugin timeouts validate through `u/valid-timeout?` (positive finite number ≤ `u/max-timeout`, signed 32-bit) and reject through `u/reject-not-valid`, which rejects an `Error` (never a bare string) so callers can read `.message`.
|
||||
- `contentrollback` is not a state watch: it subscribes to `st/stream` for `::dps/rolled-back` (kept in `subscriptions`, disposed by `remove-listener`), not debounced, delivered async so the reverted state is in place. Payload `{fileIds pageIds shapeIds}` from `pcm/rollback-targets` (page shapes only, from the reverted commits' redo changes). When the rollback falls back to reloading the file, `::dps/rolled-back` waits for the reloaded data, so the callback never reads the rejected data. The runtime's `validEvents` must list every event name, or `penpot.on` rejects it; a stale runtime build rejects new events. The MCP plugin forwards these rollbacks with the next task response and the server puts a warning first in that tool response (`RollbackNotices`). Unsent ones survive a tab or plugin reload in `penpot.localStorage` (key `rollbacks/<file-id>`, `LocalStorageRollbackStore`; the MCP manifest in `app.main.data.workspace.mcp` and `mcp/packages/plugin/public/manifest.json` grant `allow:localstorage`, which the runtime checks on access); the entry goes once a response carried them.
|
||||
- Plugin history `undoBlockBegin` creates a workspace undo transaction with a JS `Symbol`; `undoBlockFinish` commits that symbol. Missing finish eventually relies on the workspace transaction timeout.
|
||||
- Save waits, `contentsave` and rollback events: `mem:frontend/plugin-save-events`.
|
||||
- Plugin history `undoBlockBegin` creates a workspace undo transaction with a JS `Symbol`; `undoBlockFinish` commits that symbol. Missing finish eventually relies on the workspace transaction timeout.
|
||||
|
||||
8
.serena/memories/frontend/plugin-save-events.md
Normal file
8
.serena/memories/frontend/plugin-save-events.md
Normal file
@ -0,0 +1,8 @@
|
||||
# Plugin save and rollback events
|
||||
|
||||
- Start at `app.plugins.persist` for `penpot.waitForSave` and `app.plugins.events` for `contentsave` and `contentrollback`. The runtime forwarder requires `content:read` for `waitForSave`; new event names must also be added to runtime `validEvents`, and a stale runtime build can reject them.
|
||||
- `waitForSave(timeout?)` observes the shared persistence queue, not only the plugin's commits. Its default timeout is 60 seconds. It waits briefly for incoming commits, capped by the timeout; if work is pending it forces persistence and races settlement against rollback start or completion. A rollback must reject even if the status later becomes `:saved`. See `mem:frontend/workspace-state-persistence-subtleties`.
|
||||
- An earlier `:error` rejects even when no work is pending: a slow retry produces `save-retrying`, while a terminal failure keeps rejecting until the file is reopened. Other error codes include `save-timeout`, `rolled-back` and the stored failure code (default `save-failed`). Timeout validation accepts a positive finite number up to `u/max-timeout`; rejection must be an `Error`, not a string.
|
||||
- `contentsave` is a debounced state watch for transitions to `:saved` and passes no value. It does not prove the buffer is empty.
|
||||
- `contentrollback` subscribes to `::dps/rolled-back`, not the state watch. It is not debounced and is delivered asynchronously after reverted or reloaded data is in state. Its `{fileIds, pageIds, shapeIds}` payload comes from page-shape redo changes in reverted commits. Remove the stream subscription when the listener is removed.
|
||||
- MCP forwards rollback notices with task responses and retains unsent notices in per-file plugin local storage when available. Delivery is not an end-to-end acknowledgment; for its storage permissions, handoff and failure limits see `mem:mcp/save-and-rollback`.
|
||||
@ -1,7 +1,7 @@
|
||||
# MCP save results and rollback notices
|
||||
|
||||
- Start at `ExecuteCodeTaskHandler` in the plugin and `Tool`, `PluginBridge` and `RollbackNotices` in the server. For what `penpot.waitForSave` and `contentrollback` observe in the shared frontend queue, see `mem:frontend/plugin-api-to-cljs-binding`.
|
||||
- Start at `ExecuteCodeTaskHandler` in the plugin and `Tool`, `PluginBridge` and `RollbackNotices` in the server. For what `penpot.waitForSave` and `contentrollback` observe in the shared frontend queue, see `mem:frontend/plugin-save-events`.
|
||||
- `execute_code` waits for layout before the code if the layout API is available, then waits for save. Layout wait errors are logged; save failure, timeout or rollback during the wait fails the call. Keep the save wait outside the catch that only logs layout errors. Missing `waitForSave` is an API compatibility error, not permission to skip the check. Leave room in the tool timeout for both waits and the code itself.
|
||||
- Check workspace readiness at each wait because the code can navigate. Dashboard calls skip both waits so a prior workspace persistence error does not turn a successful management call into a failure. Without `penpotMgmt`, keep the waits enabled.
|
||||
- Rollback notices report events carried by a plugin task response, not proof that the current tool caused the reverted edit. `Task.sendResponse` attaches pending events and acknowledges them after handing the response to the UI for forwarding. The server prepends the notice to the tool response, including when the task failed.
|
||||
- `RollbackLog` writes through to per-file plugin local storage and falls back to memory if storage fails. When a late task response has no waiter, the server returns its events as `unclaimed-rollbacks` for a later response if the socket is still open; otherwise the notices can be lost. The handoff is not an end-to-end acknowledgment.
|
||||
- `RollbackLog` writes through to per-file plugin local storage and falls back to memory if storage fails. Both MCP manifests must grant `allow:localstorage`, which the runtime checks on access. When a late task response has no waiter, the server returns its events as `unclaimed-rollbacks` for a later response if the socket is still open; otherwise the notices can be lost. The handoff is not an end-to-end acknowledgment.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user