oficina / slides Public

Slides: the assistant is shown the deck's scenes and each asset's kind

The prompt offered scene ops and asked the model to reuse a scene's
code from DECK, but assistContext carried no scenes, and assets went as
"images" with only an id and alt, so a clip's video could not be told
from its poster.

DECK now has "scenes", bounded: each scene's id, name, states (id,
name, description), words (each cut at 2,000 runes), code ref and
data_bytes, with the data itself only when it is at most 4 KiB of
canonical JSON (maxAssistSceneData); the instructions say never to send
data for a scene shown without it. "assets" (was "images") carry a
kind: video, poster, still or image.

Test: TestTheModelIsToldTheDecksScenesAndWhatEachAssetIs reads the user
message the fake model received.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 923b9c6b46ca5caf1cd82a7ac18454c4a00e24a6 parent 6e51bed
3 files changed, +148 −7
  • AGENTS.md +4 −1
  • internal/slides/assist_prompt.go +77 −6
  • internal/slidestest/assist_test.go +67 −0
diff --git a/AGENTS.md b/AGENTS.md
index 5bbc9a9..50cde45 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -236,7 +236,10 @@ seeded on first sign-in — and comes back out as a PDF.
`fixtures/assist-panel.mjs`): an Assistant button in the editor's
header, present only with `SLIDES_AI=on`. **The model proposes, the
editor applies.** `POST /d/{sqid}/assist` sends the request and a
- compact view of the deck to TensorX (OpenAI-compatible, host pinned,
+ compact view of the deck (its slides, its assets each with a kind —
+ image, video, poster or still — and its scenes, bounded: ids, names,
+ states, words, code ref and data size, the data itself only up to
+ 4 KiB) to TensorX (OpenAI-compatible, host pinned,
memoria's provider posture), rebuilds what comes back op by op
(only the drive vocabulary less the asset ops, only each op's keys,
every new id minted here from the model's placeholders, the chosen
diff --git a/internal/slides/assist_prompt.go b/internal/slides/assist_prompt.go
index 24ed92a..ac092db 100644
--- a/internal/slides/assist_prompt.go
+++ b/internal/slides/assist_prompt.go
@@ -39,7 +39,7 @@ OPERATIONS. Each is an object with an "op" key. They are applied in order as one
- {"op":"set_block","slide":"<slide id>","id":"<block id>","props":{...},"region":"<region>","step":<number above 0> or null,"items":"each|together" or null} (props are merged into the block's)
- {"op":"set_text","slide":"<slide id>","id":"<block id>","markdown":"<text>"}
- {"op":"add_scene","id":"<new id>","name":"...","code":"<the code of a scene already in DECK>","states":[{"id":"...","name":"...","description":"<what a screen reader says>"}],"words":{"<key>":"<text>"},"data":<any JSON>} (a scene draws named states; slides show it with scene blocks)
-- {"op":"set_scene","id":"<scene id>","name":"...","states":[...],"words":{"<key>":"<text>" or null},"data":<any JSON>} (send only the keys you change; words merge, data is replaced whole)
+- {"op":"set_scene","id":"<scene id>","name":"...","states":[...],"words":{"<key>":"<text>" or null},"data":<any JSON>} (send only the keys you change; words merge, data is replaced whole; a scene in DECK with "data_bytes" and no "data" holds more data than you are shown: never send "data" for it)
- {"op":"remove_scene","id":"<scene id>"}
IDS. Existing slides and blocks are named by their "id" in DECK; use those exactly. For anything you create, invent a short placeholder id ("s1", "s2", "b1", "b2", ...), different for every new slide and block, and use it to refer to that slide or block later in the same answer. The editor replaces placeholders with real ids.
@@ -61,7 +61,8 @@ BLOCK TYPES and their props:
- code: {"language":"..."}; the markdown is the code itself, line for line, nothing interpreted
- divider, spacer: no text
- scene: {"scene":"<scene id>","from":"<state id>","to":"<state id>"}; shows from, then one state per press up to to (from must not come after to)
-- clip: {"asset":"<a video asset in DECK>","play":"press|loop|once"}
+- clip: {"asset":"<an asset in DECK of kind video>","play":"press|loop|once"}
+DECK's "scenes" are the deck's scenes, each with its states, words, code and the size of its data; its "assets" are its pictures and videos, each with a "kind": image, video, poster (a video's picture) or still (a scene state's picture).
Do not add image, table, columns or shape blocks: pictures cannot be added from here, and the others need a layout you cannot see.
TEXT is a small Markdown: **bold**, *italic*, ` + "`code`" + `, ==highlight==, [text](https://...), and "- " list items. Nothing else: no "#" headings, no tables, no HTML.
@@ -94,6 +95,14 @@ EXAMPLE, for "a two-slide deck about tea" in an empty deck:
// context, in runes; a slide is not an essay, and the cut is marked.
const maxAssistText = 2000
+// maxAssistSceneData bounds the scene data the model is shown, in bytes
+// of its canonical JSON (deck.SceneDataSize): 4 KiB. A scene's data at
+// most that is in the context whole; past it the context has only its
+// size, and the model is told not to send data for that scene. The data
+// is a scene's model, often a long list, and the deck's 160 KiB is for
+// its slides.
+const maxAssistSceneData = 4 << 10
+
// maxAssistContext bounds the whole deck view sent, in bytes. Past it
// the request is refused as too large rather than sent cut short — a
// model shown half a deck rewrites half a deck.
@@ -104,7 +113,8 @@ type assistContextDeck struct {
Theme string `json:"theme"`
Accent string `json:"accent,omitempty"`
Slides []assistSlide `json:"slides"`
- Assets []assistAssetRef `json:"images,omitempty"`
+ Assets []assistAssetRef `json:"assets,omitempty"`
+ Scenes []assistScene `json:"scenes,omitempty"`
}
type assistSlide struct {
@@ -128,9 +138,27 @@ type assistBlockView struct {
Text string `json:"markdown,omitempty"`
}
+// assistAssetRef is an asset as the model sees it. Kind tells a clip's
+// video ("video", what a clip block's asset names) from its poster
+// ("poster"), a scene's still ("still") and any other picture ("image").
type assistAssetRef struct {
- ID string `json:"id"`
- Alt string `json:"alt,omitempty"`
+ ID string `json:"id"`
+ Kind string `json:"kind"`
+ Alt string `json:"alt,omitempty"`
+}
+
+// assistScene is a scene as the model sees it, bounded: its states and
+// words in full (each word cut at maxAssistText), its code ref (which an
+// add_scene may reuse), the size of its data and the data itself only
+// when it is at most maxAssistSceneData.
+type assistScene struct {
+ ID string `json:"id"`
+ Name string `json:"name"`
+ Code string `json:"code"`
+ States []deck.SceneState `json:"states"`
+ Words map[string]string `json:"words,omitempty"`
+ DataBytes int `json:"data_bytes"`
+ Data *json.RawMessage `json:"data,omitempty"`
}
// assistContext is the deck as the model sees it. For one slide's
@@ -165,9 +193,31 @@ func assistContext(view *deck.Deck, scope assistScope) ([]byte, error) {
out.Slides = append(out.Slides, v)
}
for id, a := range view.Assets {
- out.Assets = append(out.Assets, assistAssetRef{ID: id, Alt: a.Alt})
+ out.Assets = append(out.Assets, assistAssetRef{ID: id, Kind: assistAssetKind(view, a), Alt: a.Alt})
}
sort.Slice(out.Assets, func(i, j int) bool { return out.Assets[i].ID < out.Assets[j].ID })
+ for id, sc := range view.Scenes {
+ v := assistScene{ID: id, Name: sc.Name, Code: sc.Code, States: sc.States, DataBytes: deck.SceneDataSize(sc)}
+ if v.States == nil {
+ v.States = []deck.SceneState{}
+ }
+ if len(sc.Words) > 0 {
+ v.Words = make(map[string]string, len(sc.Words))
+ for k, w := range sc.Words {
+ v.Words[k] = clipRunes(w, maxAssistText)
+ }
+ }
+ if v.DataBytes <= maxAssistSceneData {
+ raw, err := json.Marshal(sc.Data)
+ if err != nil {
+ return nil, err
+ }
+ msg := json.RawMessage(raw)
+ v.Data = &msg
+ }
+ out.Scenes = append(out.Scenes, v)
+ }
+ sort.Slice(out.Scenes, func(i, j int) bool { return out.Scenes[i].ID < out.Scenes[j].ID })
body, err := json.Marshal(out)
if err != nil {
return nil, err
@@ -178,6 +228,27 @@ func assistContext(view *deck.Deck, scope assistScope) ([]byte, error) {
return body, nil
}
+// assistAssetKind is what an asset is to the model: a clip's video, a
+// video's poster, a scene's still, or a picture.
+func assistAssetKind(view *deck.Deck, a deck.Asset) string {
+ if a.Video() {
+ return "video"
+ }
+ for _, v := range view.Assets {
+ if v.Video() && v.Poster == a.Ref {
+ return "poster"
+ }
+ }
+ for _, sc := range view.Scenes {
+ for _, st := range sc.Stills {
+ if st.Ref == a.Ref {
+ return "still"
+ }
+ }
+ }
+ return "image"
+}
+
// assistUserMessage is the user turn: the scope, the person's request
// and the deck, each fenced by its label.
func assistUserMessage(scope assistScope, prompt string, deckJSON []byte) string {
diff --git a/internal/slidestest/assist_test.go b/internal/slidestest/assist_test.go
index 624ed70..eaddf97 100644
--- a/internal/slidestest/assist_test.go
+++ b/internal/slidestest/assist_test.go
@@ -5,6 +5,7 @@ import (
"io"
"net/http"
"net/http/httptest"
+ "reflect"
"regexp"
"strings"
"sync"
@@ -296,3 +297,69 @@ func TestAssistRefusals(t *testing.T) {
t.Errorf("no same-origin evidence: %d, want 403", rec.Code)
}
}
+
+// TestTheModelIsToldTheDecksScenesAndWhatEachAssetIs (final review call
+// 4): the deck the model reads carries every scene, bounded (its id,
+// name, states, words, code ref and data size, and its data only when
+// small), and every asset with its kind, so a video is told from its
+// poster, a scene's still and a picture.
+func TestTheModelIsToldTheDecksScenesAndWhatEachAssetIs(t *testing.T) {
+ a, f := newAssistApp(t, `{"summary":"Nothing to do.","ops":[]}`)
+ cookies := signedIn(t, a, allowedAddress)
+ path := createDeck(t, a, cookies, "Scenes for the model")
+ token := mintAgent(t, a, cookies, "assist-scenes")
+ hex := func(c string) string { return strings.Repeat(c, 64) }
+ big := `{"s":"` + strings.Repeat("x", 5000) + `"}`
+ apiJSON(t, a, http.MethodPost, "/api/v1/decks/"+sqidOf(path)+"/ops", token, `{"ops":[
+ {"op":"register_asset","id":"pictureaaaaa","ref":"`+hex("1")+`","name":"a.png","width":1,"height":1,"alt":"A chart"},
+ {"op":"register_asset","id":"posteraaaaaa","ref":"`+hex("2")+`","name":"p.webp","width":1,"height":1,"alt":""},
+ {"op":"register_asset","id":"videoaaaaaaa","ref":"`+hex("3")+`","name":"v.webm","width":1,"height":1,"alt":"A demo","poster":"`+hex("2")+`","duration":1500},
+ {"op":"register_asset","id":"stillaaaaaaa","ref":"`+hex("4")+`","name":"a.png","width":1,"height":1,"alt":""},
+ {"op":"add_scene","id":"worldsceneaa","name":"World","code":"`+sceneCode+`","states":[{"id":"a","name":"Field","description":"An empty field"},{"id":"b","name":"Town"}],
+ "words":{"title":"Vienna"},"data":{"n":3}},
+ {"op":"set_scene","id":"worldsceneaa","stills":{"a":{"ref":"`+hex("4")+`","made":"`+hex("5")+`"}}},
+ {"op":"add_scene","id":"bigsceneaaaa","name":"Big","code":"`+sceneCode2+`","states":[{"id":"x"}],"data":`+big+`}]}`, http.StatusOK)
+
+ rec := postAssist(t, a, path, map[string]string{"prompt": "anything", "scope": "deck"}, cookies)
+ if rec.Code != http.StatusOK {
+ t.Fatalf("POST assist: %d %s", rec.Code, rec.Body)
+ }
+ user := f.messages(t, 1)[1]["content"].(string)
+ _, deckJSON, ok := strings.Cut(user, "\n\nDECK:\n")
+ if !ok {
+ t.Fatalf("no DECK in the user message:\n%s", user)
+ }
+ var got struct {
+ Assets []map[string]any
+ Scenes []map[string]any
+ }
+ if err := json.Unmarshal([]byte(deckJSON), &got); err != nil {
+ t.Fatalf("the DECK is not JSON: %v\n%s", err, deckJSON)
+ }
+ kinds := map[string]string{}
+ for _, as := range got.Assets {
+ kinds[as["id"].(string)], _ = as["kind"].(string)
+ }
+ if want := map[string]string{"pictureaaaaa": "image", "posteraaaaaa": "poster", "videoaaaaaaa": "video", "stillaaaaaaa": "still"}; !reflect.DeepEqual(kinds, want) {
+ t.Errorf("the assets' kinds are %v, want %v", kinds, want)
+ }
+ if len(got.Scenes) != 2 {
+ t.Fatalf("the model was told %d scenes, want 2:\n%s", len(got.Scenes), deckJSON)
+ }
+ big0, world := got.Scenes[0], got.Scenes[1]
+ if world["id"] != "worldsceneaa" || world["name"] != "World" || world["code"] != sceneCode || world["data_bytes"] != 7.0 {
+ t.Errorf("World is %v", world)
+ }
+ if raw, _ := json.Marshal(world["states"]); string(raw) != `[{"description":"An empty field","id":"a","name":"Field"},{"description":"","id":"b","name":"Town"}]` {
+ t.Errorf("World's states are %s", raw)
+ }
+ if raw, _ := json.Marshal(world["words"]); string(raw) != `{"title":"Vienna"}` {
+ t.Errorf("World's words are %s", raw)
+ }
+ if raw, _ := json.Marshal(world["data"]); string(raw) != `{"n":3}` {
+ t.Errorf("World's small data is %s, want it all", raw)
+ }
+ if _, has := big0["data"]; has || big0["id"] != "bigsceneaaaa" || big0["data_bytes"] != float64(len(big)) {
+ t.Errorf("Big's data, past the bound, should be its size alone: %v", big0)
+ }
+}