oficina / slides Public

Clone
git clone https://amadan.net/oficina/slides

Plain git — no account needed to clone.

Download

Download this file

1# Delegated semantic deck editing
2
3Status: specification and final source independently approved by a separate
4GPT-6 Astra agent, 2026-11-01, with the machine contract clarification below.
5Validation is recorded below.
6Author: GPT-6 Astra, 2026-11-01. Paul authorized everyday editing APIs through
7the suite's existing API, CLI and MCP connection. This extends the approved
82026-10-25 agent-access design. Its identity, namespace, privacy, roster and
9response-emission rules remain binding, and existing v1 contracts are unchanged.
10
11## Contract
12
13Add `slides_update_deck`, scope `slides:write`, readOnly false, idempotent true.
14HTTP, CLI and MCP use the same team-independent descriptor. All five fields
15below are required; unknown top-level fields are refused.
16
17```json
18{
19 "team": "team-id",
20 "sqid": "k7m2xq9dwb",
21 "expected_revision": "12",
22 "client_id": "1dc98332-7165-43c5-8f98-9546f10146a8",
23 "ops": [
24 {"op":"set_notes","id":"abcdefghijkl","markdown":"Discuss the revised estimate."},
25 {"op":"add_slide","layout":"flow","template":"title-body"}
26 ]
27}
28```
29
30Sqid retains the exact existing ten-character alphabet and revision retains
31the canonical nonnegative decimal string of `Deck.Seq`, at most MaxInt64.
32Signs, leading zeros, fractions and overflow are invalid. A new edit must
33leave room for one sequence increment. The UUID is nonzero canonical
34lowercase hyphenated form. Team is 1–128 characters and must equal the
35configured instance team. Accept 1–100 ordered semantic operations, at most
361 MiB for the whole request. Reject malformed Unicode and duplicate JSON
37object keys before decoding op fragments; retain raw numbers and the semantic
38distinction between absent keys and null.
39
40Allowed operation names are `set_meta`, `add_slide`, `remove_slide`,
41`move_slide`, `duplicate_slide`, `set_slide`, `set_notes`, `add_block`,
42`remove_block`, `move_block`, `set_block`, `set_text` and `set_phone`.
43Their fields, references, markdown, rich text, fractional coordinates and
44ordering are the existing canonical operation vocabulary in `docs/api.md`
45and `core/src/ops.rs`, with no second Go operation interpreter. The exported
46descriptor exposes concrete argument fields and types for every supported op,
47using per-operation `oneOf` or an equivalent machine schema, so API, CLI and
48MCP callers can discover the contract without external documentation. The core
49validates operation-specific types, fields and cross-operation references.
50The envelope limit and op count are enforced before calling the engine.
51Asset registration/removal, upload, export, presentation, sharing and deck
52deletion are outside this slice. Existing registered images can still be
53referenced by ordinary block operations under their current validation.
54
55Missing slide/block IDs are minted through existing `mintOpIDs`, including
56duplicate-slide block identities. Caller-supplied IDs retain native semantics.
57The caller can provide its own IDs when later operations in the same batch
58need to refer to newly added objects. No raw Yjs updates or whole-deck JSON
59replacement are accepted.
60
61Success is a small acknowledgement:
62
63```json
64{"sqid":"k7m2xq9dwb","revision":"13","url":"https://slides.example/d/k7m2xq9dwb","ids":{"1":"mnopqrstuvwx"}}
65```
66
67All four fields are required. `ids` is the existing native operation-index
68map for server-minted slide/block IDs; duplicate-slide child block identities
69are discoverable by reading the resulting deck, as on the existing drive API.
70`revision` is the immutable sequence committed by this mutation. A completed
71retry returns the same revision and IDs even after later browser edits. It
72does not return a stale deck body; `slides_get_deck` gives current content and
73revision. Existing create responses keep their current-revision semantics.
74Bound the encoded result before commit to the existing 1 MiB result maximum.
75
76`conflict` means stale expected revision for a new mutation or a reused client
77UUID with a different target, expected revision or ordered operation payload.
78Current access is checked before disclosing conflict. A stale request never
79automatically rebases against a newer deck. The caller reads again and chooses
80a fresh UUID for its revised intent. Core refusal is `invalid`; storage,
81deadline or engine execution failures are unavailable, not partial success.
82Missing/inaccessible decks and other authority failures use existing codes.
83
84## Native authority and response boundary
85
86Only creation requires creator membership; do not treat every slides:write
87operation as create. Document editing follows the app's existing deck write
88authority: a person who can reach a deck through the native owner/team/grant
89seam may edit its document, as `apiOps` does. No new viewer/editor distinction
90is invented. Existing independent deck grants survive NotMember or Unknown;
91owner/team-rung reach requires Member from the single captured Access.
92
93At writer reservation and before commit, including completed retries,
94reverify the original delegation verifier and unchanged principal fields,
95resolve the keyed Home link on the transaction through `ResolveOn`, compare
96stable local person ID and address, and recheck live deck reach on that same
97transaction. The team write guard wraps the entire mutation/receipt decision.
98No outer-pool lookup, HomeOnly fallback, automatic provisioning or roster
99network request runs under the writer. A missing or expired required lease
100fails closed; an independent current grant is checked on the transaction.
101
102Remember the exact deck for existing before-header and per-chunk identity,
103delegation, live deck and roster checks. Preserve the standing-lease socket
104deadline clamp. Loss of authority during emission aborts it; a committed but
105unacknowledged edit is recovered through its stable retry UUID.
106
107## One canonical edit transaction
108
109Use the existing semantic engine, op ID minting, `metaRowUpdates`,
110`applyOpsOn`, core shape check and canonical projection parser. Do not call
111the legacy `applyAgentOps` retry loop: it intentionally retries a busy deck
112at its new sequence, which violates this operation's explicit precondition.
113
114Reserve the SQLite writer using the existing immutable namespace marker.
115Recheck local authority, read any existing receipt, then read the current
116deck row and compare its sequence to expected_revision. Open a fresh owned
117core handle whose snapshot and ordered log reads use the caller's transaction
118at that exact sequence; factor a transaction-aware `openDeck` seam if needed.
119Never call the outer-pool reader while holding the writer. All handles are
120closed/discarded after either commit or rollback.
121
122For a new request, mint missing IDs on a copy of its op fragments, preserving
123the original request for fingerprinting. Apply the batch once through the
124canonical engine; require both `Handle.Check` of shared-type structure and
125`deck.Parse` of `Handle.JSON` before commit. The app's transaction encloses
126the update-log insert, optimistic sequence bump, any deck-row metadata,
127actor attribution, receipt and final authority check. If the existing helper
128performs inserts before shape checking, these stay inside the uncommitted
129transaction and any failed check rolls all of them back. The resulting deck
130must also fit the existing 1 MiB canonical get result bound, so this editing
131surface cannot successfully create a deck its read operation cannot return.
132
133Preserve fractional z/box values by retaining raw op JSON and the canonical
134JSON projection; never round-trip through the simplified typed Deck struct
135as the source of persisted content. All order changes go through the engine's
136identity-preserving order keys. Both required checks remain independent gates.
137Only after commit publish the new sequence and attempt a native snapshot.
138Replays publish nothing and create no extra log entry or actor attribution.
139
140## Durable retry and attribution
141
142Add a separate additive edit-receipt table. Its unique HMAC coordinate binds
143operation name, both authority issuers, team, subject, delegated client and
144client UUID. The payload HMAC binds sqid, expected revision and ordered
145operation content before server-generated IDs. Object key order and harmless
146JSON whitespace do not change the fingerprint: canonicalize recursively with
147exact JSON numbers, without float64 conversion; number spelling may remain
148significant and is documented as requiring an exact semantic retry payload.
149Absent and null remain different. No plaintext markdown or op payload is
150persisted in the receipt or logged.
151
152Persist the target deck ID, applied sequence and a sealed acknowledgement
153containing the stable returned ID map under a receipt-specific purpose. Use
154the existing sealed connection attribution and connection actor on the update
155row. The immutable namespace marker's no-adoption checks include new edit
156receipts as well as creation receipts and attribution. Marker, receipt,
157attribution and content share one transaction and key/issuer/team continuity.
158
159A matching completed receipt is returned only after current resource and
160writer authority checks, before checking expected_revision against the now
161current deck. This is why a retry after later changes is safe. Changed payload
162conflicts. Concurrent identical submissions commit one batch and return one
163stable acknowledgement. A failed write leaves no receipt or generated IDs
164claiming a committed result. Recreated app and reopened database must replay
165the same applied revision and IDs without rerunning the semantic engine.
166
167## Review and validation gates
168
169Independent highest-capability spec approval precedes implementation and
170independent source/evidence review follows. Required gates:
171
172- Real Home grant/gateway/MCP create-read-edit-read, including text, notes,
173 slide/block reorder, add/duplicate/remove, metadata and fractional canvas
174 coordinates. Compare native `openDeck`, the canonical JSON read operation
175 and browser-rendered HTML from the same state.
176- Two concurrent edits from one sequence: one commit, one conflict; exact
177 duplicate retry after a later native edit and after app restart preserves
178 that later edit and returns original generated IDs and applied sequence.
179- Invalid later op, malformed rich text, missing reference and columns-cycle
180 rejection leave no partial updates. Independently exercise shape and
181 projection gates, not merely core input parsing.
182- SQL failures at update insert, metadata update, attribution and receipt
183 persistence roll back sequence, log, metadata and acknowledgement. A
184 fresh open reads the old deck; no seq publication or snapshot precedes
185 commit. Completed retries do not apply another op batch.
186- Initial/final revocation, unlink, binding corruption, live deck/grant loss
187 and roster lease expiry, including direct-domain completed-retry tests
188 independent of emission. Independent granted access under Unknown and
189 NotMember remains supported; create still requires current membership.
190- Exact JSON numbers, null/absence, strict Unicode/duplicate keys, revision
191 limits, unknown operation names and 100-op/1 MiB bounds. Verify sealed
192 acknowledgement/attribution and no plaintext content in receipt storage.
193- Add the delegated path to the enumerated team-write lapse test. Effective
194 runtime-failing mutants separately skip revision comparison, completed
195 receipt payload checking, final writer guard, live transactional reach,
196 one canonical shape gate and receipt atomicity.
197- Restore all mutants; run focused race tests and the full pinned
198 `.amadan/ci.d/10-gate` (canonical wasm rebuild/cmp, Rust/JS, Go and migrations)
199 on the final tree. A fast `make ci` alone does not replace this gate.
200
201This additive operation carries no canary, main-merge or deployment approval.
202
203## Independent review record
204
205On 2026-11-01 a separate GPT-6 Astra agent approved this specification before
206implementation, then independently reviewed the final source and selected
207adversarial mutations. Final source approval covers this bounded editing
208operation and its native transaction/authority integration. It does not approve
209main merge, canary behavior or deployment.
210
211Eight selected mutants failed at runtime: missing revision check, ignored
212completed receipt, missing final writer check, new IDs returned on replay,
213omitted shared-type shape check, omitted projection parsing, float64 receipt
214fingerprints, and ignored receipt persistence failure. Every original was
215restored. The exported operation contract contains concrete schemas for all
216thirteen allowed semantic operations; the canonical engine remains authoritative.
217
218Final restored-tree canonical gate passed on 2026-11-01:
219`TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 ./.amadan/ci.d/10-gate`. This includes
220Rust formatting/clippy/tests, canonical WASM rebuild and byte comparison,
221JavaScript tests/vectors/bundle checks, and Go vet/formatting/tests/migrations
222and credits. The short temporary directory avoids the macOS Unix-socket path
223limit in the existing shutdown test; no application behavior or test was
224changed for that environment constraint.
225
226The final focused race check also passed (313.173s):
227`GOMAXPROCS=2 TMPDIR=/tmp GOTOOLCHAIN=go1.26.5 go test -race
228./internal/slides -run
229'TestAgentDeckEdit|TestAgentGatewayToRealSlides|TestAgentTeamSlidesMembership'
230-count=1 -timeout 1200s`. It covers the editing boundary, native semantic
231parity, real HTTPS CLI/MCP edit/read/retry, and retained roster behavior.
232