@serene-pub/contracts 0.6.0-pr-2 → 0.6.0-pr-5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1261 @@
1
+ /**
2
+ * Core's **outlet** node definitions — writes, attaches, emits: where a run leaves
3
+ * into the world.
4
+ *
5
+ * One file per node kind, with the helpers only that kind uses; `index.ts`
6
+ * re-exports them all.
7
+ */
8
+ import { S } from '@serene-pub/sdk';
9
+ import { describeOutletDefinition, pin } from '@serene-pub/sdk';
10
+ /**
11
+ * An author defaulting review ON for their own consumer — and unable to forbid it.
12
+ *
13
+ * Bound 2026-09-17: the host's commit for it existed and no
14
+ * binding reached it. `target` is the row the part lands on — the same port
15
+ * `update-message` takes, fed from an earlier write in the document (the reply's
16
+ * placeholder) or from the inlet's `messageId`. An update whose target is
17
+ * an earlier write is the same row, so placing this after `create-message` is
18
+ * one live row, not two. The host reads the id off `target`, or off the
19
+ * media reference's own `messageId` where a caller outside the graph set one.
20
+ * @experimental
21
+ */
22
+ export const attachImage = pin(describeOutletDefinition({
23
+ id: 'core:outlet/attach-image@1',
24
+ effects: 'write',
25
+ /** The image is a reference to an asset this run rendered; nothing to retype. */
26
+ review: { fields: [] },
27
+ timeoutMs: 5000,
28
+ reviewDefault: 'on',
29
+ causesEvent: 'core:event/message-updated@1',
30
+ ports: { in: { target: S.rowIds, image: S.image }, out: { main: S.writeResult } },
31
+ }));
32
+ /**
33
+ * The create pipeline's write: seed the collected greetings as
34
+ * the session's first messages — one assistant message per entry, the full
35
+ * list as its swipe history, redirected to the genre's declared greeting
36
+ * channel when that is not `main`.
37
+ * @experimental
38
+ */
39
+ export const seedGreetings = pin(describeOutletDefinition({
40
+ id: 'core:outlet/seed-greetings@1',
41
+ effects: 'write',
42
+ /** The greetings are the cards' own text and the channel the genre's: approve or refuse. */
43
+ review: { fields: [] },
44
+ timeoutMs: 5000,
45
+ causesEvent: 'core:event/message-created@1',
46
+ ports: {
47
+ in: {
48
+ greetings: S.json,
49
+ /**
50
+ * The channel the greetings land on — the genre's
51
+ * declared greeting channel, written by the create specs as a
52
+ * literal (`createChat.ts`, `adventure.ts`). Absent is `main`.
53
+ * Declared 2026-09-16: the host read it off the
54
+ * payload while no declaration supplied it.
55
+ */
56
+ channel: S.text,
57
+ },
58
+ out: { main: S.writeResult, messageIds: S.writeResult },
59
+ },
60
+ }));
61
+ /**
62
+ * Write a message — complete, or as the run's **placeholder**.
63
+ *
64
+ * A pipeline that wants a message creates it itself. The reply specs put this
65
+ * node straight after the inlet with `generating: true`: the row it inserts is
66
+ * empty and generating, it is the run's live row (`liveRow` — an oracle's
67
+ * stream lands in it, and Stop finalises it), and the spec's last node is an
68
+ * `update-message` that fills it. That create → update pair on one row inside
69
+ * one run is the run's **one live row**. Without `generating` (or a
70
+ * claimed `row`) the message is complete, and an ordinary write — a pipeline
71
+ * may write as many as it likes, just never a second on the live row's
72
+ * channel. `message-created` fires on the create, which is now genuinely the
73
+ * moment the row exists.
74
+ *
75
+ * `reviewDefault: 'off'` — review of a reply, when an admin enables it, lands
76
+ * on the *update* of the primary row and never on this create by default:
77
+ * a placeholder is a write, and an admin who gates this node gets
78
+ * a run that shows nothing until approved, which is honest and rarely wanted.
79
+ * Turning it on is still the admin's to do.
80
+ * @public
81
+ */
82
+ export const createMessage = pin(describeOutletDefinition({
83
+ id: 'core:outlet/create-message@1',
84
+ effects: 'write',
85
+ /** The text may be reviewed; who speaks, which row and which channel are the run's identity. */
86
+ review: { fields: ['text'] },
87
+ reviewDefault: 'off',
88
+ liveRow: true,
89
+ timeoutMs: 5000,
90
+ causesEvent: 'core:event/message-created@1',
91
+ slots: {
92
+ /**
93
+ * The write hook: one chain rewrites the final output, the
94
+ * other decides where a streamed reply stops. Stop is a verdict —
95
+ * min-reduction across every attached script, and the connection's
96
+ * own guards join the same union at dispatch, which is why
97
+ * order never needs ruling. `speakerName` and `castNames` are
98
+ * extras: readable, never writable, by construction.
99
+ */
100
+ scripts: {
101
+ kind: 'scripts',
102
+ accepts: ['core:script:text/transform@1', 'core:script:text/stop@1'],
103
+ port: 'text',
104
+ phase: 'before',
105
+ extras: ['speakerName', 'castNames'],
106
+ description: 'Scripts over the reply as it is saved — clean up the text, or stop a streaming reply early.',
107
+ },
108
+ },
109
+ ports: {
110
+ in: {
111
+ text: S.text,
112
+ /**
113
+ * Media to post WITH the message, as references.
114
+ *
115
+ * Posting an image as a NEW message is one write, not a create
116
+ * followed by an `attach-image`: the answer is the same one
117
+ * streaming got — one node with a settled output, not two nodes
118
+ * and a hope. The write that creates the message is the write
119
+ * that attaches its images.
120
+ */
121
+ media: S.mediaList,
122
+ /**
123
+ * Who is speaking, as a cast row — the inlet's `characterId`.
124
+ * Null or absent means nobody in particular: narration, or a
125
+ * message no character voices.
126
+ */
127
+ characterId: S.rowIds,
128
+ /**
129
+ * The participant voicing this message when they are **not** a
130
+ * cast row — the side-character fact `{ name, characterId, known }`
131
+ * off `side-character-turn@1`'s `sideCharacter` port. Stored
132
+ * beside the message under `metadata.sideCharacter` (was
133
+ * `metadata.speaker` until 2026-09-16 — that key is the
134
+ * participant reference now, on the row as on the inlet),
135
+ * where the run and the receipt read it from; it never writes a
136
+ * cast row and never enters the rotation.
137
+ *
138
+ * Was `speaker` until 2026-09-16 — the inlet's port of that
139
+ * name is a participant reference now.
140
+ */
141
+ sideCharacter: S.json,
142
+ /**
143
+ * Who is speaking, as a **participant reference**
144
+ * (2026-09-16) — `character:<id>` or `envoy:<slug>`, the
145
+ * inlet's `speaker`. Stored beside the message as
146
+ * `metadata.speaker`; it is the only identity an envoy's turn
147
+ * carries, since an envoy has no row for `characterId` to name.
148
+ * Optional: a spec that wires only `characterId` writes the row
149
+ * it always wrote.
150
+ */
151
+ speaker: S.participantRef,
152
+ /**
153
+ * Create the row as a **placeholder**: empty, generating, and the
154
+ * run's live row — filled by a later `update-message`, or
155
+ * finalised by core if the run stops first.
156
+ *
157
+ * A port, not a parameter, and the call site is what decides:
158
+ * the reply specs write `generating: true` as a literal into the
159
+ * node's config, in the same map as `text`, and `resolveInput`
160
+ * passes it through untouched — so the binding reads it exactly
161
+ * the way it reads a port (see `summarize-batch`'s `loreType`
162
+ * for the same reasoning at length). A `params` field would put
163
+ * a structural fact of the document in the panel as a knob.
164
+ */
165
+ generating: S.json,
166
+ /**
167
+ * The message is **narration** — not a character's turn. Shown
168
+ * under the narrator's name, never counted by the rotation. A
169
+ * literal, on the same terms as `generating`. The name is the
170
+ * session's narrator name, or the `speaker`'s where one was
171
+ * named; the host resolves it at the write, which is where the
172
+ * row is.
173
+ */
174
+ narration: S.json,
175
+ /**
176
+ * Instructions this message was asked for — a narrator's focus
177
+ * note. Stored beside the message and shown with it; never its
178
+ * text. Wired from the inlet's `text` on the narrate specs, which
179
+ * is what a narrator turn's triggering text is.
180
+ */
181
+ instructions: S.text,
182
+ /**
183
+ * The channel the row lands on. Absent is `main`, so a
184
+ * pipeline that has never heard of channels writes where it
185
+ * always did; a channel the session's genre never declared is
186
+ * refused at the write. Declared 2026-09-16 for
187
+ * the same reason `seed-greetings` declares its own.
188
+ */
189
+ channel: S.text,
190
+ /**
191
+ * An existing message row to take as the placeholder instead of
192
+ * inserting one — the inlet's `messageId` on a regenerate, swipe
193
+ * or extend. The row is reset to generating and becomes the
194
+ * run's live row; its text and swipe history stay as the verb
195
+ * left them. Absent on a fresh turn, which inserts.
196
+ */
197
+ row: S.rowIds,
198
+ /**
199
+ * Message **blocks** to post with the row
200
+ * (2026-09-17): a list of `MessageBlock` — text,
201
+ * tables, meters, and the two interactive kinds, `choices` and
202
+ * `form`, which are **forms** when they carry an `addressee`.
203
+ * The host validates the tree (`checkMessageBlocks`), refuses
204
+ * a block naming a function this spec declares no action for
205
+ * or one whose action is `world` (the effects line), stamps
206
+ * each form with the writing spec's action identity and an
207
+ * id, stores them as a `core:blocks` part, and — for a form
208
+ * whose addressee the run's pinned portrayals say the AI
209
+ * portrays — records `core:event/form-addressed@1` for the
210
+ * genre's answer pipeline once this run's receipt is saved.
211
+ * Absent on nearly every message.
212
+ */
213
+ blocks: S.json,
214
+ /**
215
+ * **Folded sections** to show collapsed beside the text — a
216
+ * narrator's Plan, a step's notes (`FoldedSectionV1[]`: each
217
+ * `{ kind, label, content }` or `{ kind, label, items }`; at
218
+ * most `MAX_FOLDED_SECTIONS`). Stored with the row as
219
+ * `core:section` parts above the body; never the text, and
220
+ * never read into the prompt transcript. A malformed section
221
+ * is refused by position. Absent on nearly every message.
222
+ */
223
+ sections: S.foldedSections,
224
+ /**
225
+ * 🚧 The **turn plan** this row carries (Lair character turns,
226
+ * owner ruling 2026-09-30): `{ plan, locationPassage? }`, where
227
+ * `plan` is a planner's document whose `speakers` (side-character
228
+ * facts — `{ name, intent }` or `{ characterId }`) name who takes
229
+ * a **character turn** next, in order, and `locationPassage` is
230
+ * prose that describes the room they are heading into. The host
231
+ * resolves each speaker to a seated cast member and stores the
232
+ * whole as `metadata.turnPlan` (`{ turns, plan, locationPassage? }`,
233
+ * `turns` the participant references in order). A turn-order
234
+ * strategy reads the **standing plan** off the history and
235
+ * prepares one entry per turn not yet taken (`via: 'plan'`); each
236
+ * character turn reads it back through `core:query/turn-plan@1`.
237
+ * Absent, or with no `plan`, the row plans nothing — which is
238
+ * every row but a planner's.
239
+ */
240
+ turnPlan: S.json,
241
+ },
242
+ out: { main: S.writeResult, messageId: S.writeResult },
243
+ },
244
+ }));
245
+ /**
246
+ * Update an existing message — finish a placeholder, or edit a settled row.
247
+ *
248
+ * `target` takes `row-ids@1`, and a `write-result@1` from earlier in the same
249
+ * run is assignable to it: the reply specs wire `$.placeholder.messageId`
250
+ * here, which is the create → update pair that makes the pipeline own its row.
251
+ * The other case is unchanged — the id comes from outside the run because the
252
+ * user clicked a message, so it is on the inlet.
253
+ *
254
+ * Which of the two this is, the row decides: a target still **generating** — a
255
+ * placeholder this run created — is finished (the text lands, the generating
256
+ * state ends, the reasoning trace and the swipe slot are written); a settled
257
+ * target is edited and marked so. That is the row's own state, not a flag a
258
+ * spec could get wrong.
259
+ *
260
+ * Where review lands on a reply: when an admin turns review on
261
+ * for a reply's message writes, it is THIS node that parks — the placeholder
262
+ * ships `reviewDefault: 'off'` and declares no default here either, so nothing
263
+ * gates by default and a reviewer who asks for one sees the content, not an
264
+ * empty row. The executor's own rule (`resolvePosition`) is "the setting, else
265
+ * the author's default, else off", and this node leaves the default unset.
266
+ * @experimental
267
+ */
268
+ export const updateMessage = pin(describeOutletDefinition({
269
+ id: 'core:outlet/update-message@1',
270
+ effects: 'write',
271
+ /** The text may be reviewed; the row may not, nor the reasoning trace. */
272
+ review: { fields: ['text'] },
273
+ timeoutMs: 5000,
274
+ causesEvent: 'core:event/message-updated@1',
275
+ slots: {
276
+ /** The same write hook as `create-message` — see it for the terms. */
277
+ scripts: {
278
+ kind: 'scripts',
279
+ accepts: ['core:script:text/transform@1', 'core:script:text/stop@1'],
280
+ port: 'text',
281
+ phase: 'before',
282
+ extras: ['speakerName', 'castNames'],
283
+ description: 'Scripts over the reply as it is saved — clean up the text, or stop a streaming reply early.',
284
+ },
285
+ },
286
+ ports: {
287
+ in: {
288
+ target: S.rowIds,
289
+ text: S.text,
290
+ /**
291
+ * The reasoning trace the oracle separated from its text, when
292
+ * the model produced one. Stored beside the message as the
293
+ * reasoning fold reads it; absent means none. Shown folded,
294
+ * and never re-sent to the model: the prompt transcript reads
295
+ * a row's text alone (decided 2026-09-27).
296
+ */
297
+ reasoning: S.text,
298
+ /**
299
+ * Blocks to append to the row — the same list, the same
300
+ * checks and the same stamping as `create-message`'s
301
+ * `blocks`; appended as a `core:blocks` part after the text
302
+ * lands, so a reply can end with a question put to the cast.
303
+ */
304
+ blocks: S.json,
305
+ /**
306
+ * **Folded sections** for the reply — the same list and the
307
+ * same checks as `create-message`'s `sections`. Finishing a
308
+ * reply, they are the shown alternative's sections, whole: a
309
+ * regenerate replaces what the slot held, and a finish with
310
+ * none clears it, while every other alternative keeps its own.
311
+ * Editing a settled row, they replace the shown alternative's
312
+ * only when given. Like `reasoning`, never re-sent to the model.
313
+ */
314
+ sections: S.foldedSections,
315
+ },
316
+ out: { main: S.writeResult, messageId: S.writeResult },
317
+ },
318
+ }));
319
+ // ── The built-in writes (R-15, ruled 2026-09-15, built 2026-09-16) ──────────
320
+ //
321
+ // *Anything that alters message state is a built-in*: core implements the
322
+ // write and it always emits an event carrying what changed and what was lost.
323
+ // Each of the five below is the write half of one message verb, run as its
324
+ // own one-node spec (`core:spec/builtin-*`) so it is receipted, gate-eligible
325
+ // (`reviewDefault: 'off'` — an admin may turn review on for a delete) and
326
+ // recorded in the session's changes for the next reply's inlet. The venue's
327
+ // handler makes the permission checks — that is the `item` audience rule,
328
+ // evaluated where the person is — and hands the request to the spec; the
329
+ // host's commit re-runs the same rule against the run's actor before it
330
+ // writes (U5b review C1), so a payload re-aimed between the two — at a review
331
+ // gate, by a spec that is not the built-in's own — is refused where the write
332
+ // happens. Each declares `review.fields`: what a reviewer may edit, and the
333
+ // row's identity is never among them.
334
+ //
335
+ // **Stop, branch and edit are floors**; delete, hide and swipe are built-ins a
336
+ // genre may switch off (`SessionShape.messageVerbs`). Stop has no outlet: it is
337
+ // the run-level guarantee (R-17) and emits `message-stopped` from the
338
+ // finalisation. Regenerate, extend and a swipe's fresh alternative are
339
+ // `update-message` with a `verb` — content the genre's pipeline produced,
340
+ // written by the outlet the reply already ends in.
341
+ /**
342
+ * Delete a message. Publishes `lost` — the content, role, speaker, channel
343
+ * and metadata the row held — beside the write result, so a listener (a
344
+ * plugin cleaning its rows, the next reply's inlet) knows what went.
345
+ * @experimental
346
+ */
347
+ export const deleteMessage = pin(describeOutletDefinition({
348
+ id: 'core:outlet/delete-message@1',
349
+ effects: 'write',
350
+ reviewDefault: 'off',
351
+ // Nothing to edit at the gate: approve the delete or refuse it. The
352
+ // row it is about was judged by the handler (the item rule) before
353
+ // the run began, and a reviewer retyping `target` would re-aim the
354
+ // write at a row nobody judged (U5b review C1).
355
+ review: { fields: [] },
356
+ timeoutMs: 5000,
357
+ causesEvent: 'core:event/message-deleted@1',
358
+ ports: {
359
+ in: { target: S.rowIds },
360
+ out: { main: S.writeResult, messageId: S.writeResult, lost: S.json },
361
+ },
362
+ }));
363
+ /**
364
+ * Write the session's turn order — the ONE
365
+ * write path for `sessions.metadata.turnOrder`, and the only outlet that
366
+ * writes `metadata` at all.
367
+ *
368
+ * Before writing it drops what cannot be fired, each with a receipt note:
369
+ * an entry whose `ref` is not among `candidates` (a script or a plugin
370
+ * strategy cannot seat somebody the pool did not admit), and an entry on a
371
+ * channel the session does not have. Then `writeTurnOrder`, which refuses
372
+ * an order answering an older event than the one already stored and says
373
+ * `stale` on the receipt rather than failing.
374
+ *
375
+ * `causesEvent` is how `turn-order-changed` reaches the auto-advance
376
+ * listener and the `sessions:turnOrder` push; the `cause` wired in here is
377
+ * the one that rides along, so the listener can tell a person's send from a
378
+ * migration's backfill.
379
+ * @experimental
380
+ */
381
+ export const setTurnOrder = pin(describeOutletDefinition({
382
+ id: 'core:outlet/set-turn-order@1',
383
+ i18n: { name: { en: 'Set turn order' } },
384
+ effects: 'write',
385
+ reviewDefault: 'off',
386
+ // Nothing a reviewer could usefully retype: the order is computed
387
+ // from the rows, and a hand-edited entry would name a participant
388
+ // nobody pooled. Approve the recompute or refuse it.
389
+ review: { fields: [] },
390
+ timeoutMs: 2000,
391
+ causesEvent: 'core:event/turn-order-changed@1',
392
+ ports: {
393
+ in: {
394
+ order: S.turnEntries,
395
+ candidates: S.turnCandidates,
396
+ /** The instant the answered event happened — the staleness key. */
397
+ basedOnAt: S.json,
398
+ /** The event id this order answers. */
399
+ event: S.text,
400
+ /** The inlet's cause, carried into `turn-order-changed`. */
401
+ cause: S.json,
402
+ },
403
+ out: {
404
+ main: S.writeResult,
405
+ /** The document as written, or the stored one when this was stale. */
406
+ turnOrder: S.turnOrder,
407
+ },
408
+ },
409
+ }));
410
+ /**
411
+ * Write one owner's document into the session's annex.
412
+ *
413
+ * Merged into what is there by default — a spec that keeps one key does not
414
+ * have to carry the rest — and written under
415
+ * `pg_advisory_xact_lock(hashtext('annex'), sessionId)` through `jsonb_set`,
416
+ * so two specs writing two owners' documents at once cannot lose each
417
+ * other's. Causes `core:event/annex-changed@1` (a later
418
+ * ruling, reversing the original "no causesEvent"): a package's state is the annex, and a
419
+ * genre that wants its turn order to answer that state binds the event in
420
+ * the open, where the event map draws it — not through a back door.
421
+ * @experimental
422
+ */
423
+ export const setSessionAnnex = pin(describeOutletDefinition({
424
+ id: 'core:outlet/set-session-annex@1',
425
+ i18n: { name: { en: 'Set session annex' } },
426
+ effects: 'write',
427
+ /**
428
+ * "My state changed" as an event any genre may listen for. The host
429
+ * emits it only when the merged value differs from the stored one. A
430
+ * package that wants its own named happening declares an event and
431
+ * records it with `record-event`.
432
+ */
433
+ causesEvent: 'core:event/annex-changed@1',
434
+ /**
435
+ * Who may see a value is the owner's **annex declaration**'s to say —
436
+ * each key's `annexField({ see })` — and the audience stored with a
437
+ * value is the declaration's. The step may write only keys its owner
438
+ * declares.
439
+ */
440
+ reviewDefault: 'off',
441
+ review: { fields: ['value'] },
442
+ timeoutMs: 2000,
443
+ slots: {
444
+ params: {
445
+ kind: 'parameters',
446
+ facet: 'behavior',
447
+ schema: {
448
+ owner: {
449
+ type: 'string',
450
+ default: '',
451
+ label: { en: 'Owner' },
452
+ description: {
453
+ en: "Whose document to write. Blank means this pipeline's own.",
454
+ },
455
+ },
456
+ merge: {
457
+ type: 'boolean',
458
+ default: true,
459
+ label: { en: 'Merge' },
460
+ description: {
461
+ en: 'Keep the keys already there and write over the ones given. Off replaces the whole document.',
462
+ },
463
+ },
464
+ sharedAnnex: {
465
+ type: 'boolean',
466
+ default: false,
467
+ label: { en: 'Write another owner' },
468
+ description: {
469
+ en: "Allow writing a document this pipeline does not own. Off refuses, with a note on the receipt.",
470
+ },
471
+ },
472
+ },
473
+ },
474
+ },
475
+ ports: {
476
+ in: { value: S.json },
477
+ out: { main: S.writeResult, annex: S.json },
478
+ },
479
+ }));
480
+ /**
481
+ * Set one **annex field** (2026-09-26): the write behind every
482
+ * `annexField()` a package declares — core's one pipeline for them all,
483
+ * `core:spec/set-annex-field`.
484
+ *
485
+ * `payload` is `{ field, value }`: `field` the field's action identity
486
+ * (`<owner>:annex#<key>`), which the host's door put there after judging the
487
+ * press — who pressed, the plugin switch, the shape. The host reads the
488
+ * declaration again here rather than trusting the payload: an undeclared
489
+ * key, a value its shape refuses, a secret, or a declared audience that is
490
+ * not one is refused, and the run halts on it. What is written goes through
491
+ * the same annex write as `set-session-annex` — the lock, one audience per
492
+ * key, `annex-changed`, every viewer's view re-sent — into
493
+ * `annex[<owner>][<key>]`, under the audience the declaration names.
494
+ * @experimental
495
+ */
496
+ export const setAnnexField = pin(describeOutletDefinition({
497
+ id: 'core:outlet/set-annex-field@1',
498
+ i18n: { name: { en: 'Set annex field' } },
499
+ effects: 'write',
500
+ causesEvent: 'core:event/annex-changed@1',
501
+ reviewDefault: 'off',
502
+ /** The payload was judged at the door and is judged again here — approve or refuse, never rewrite. */
503
+ review: { fields: [] },
504
+ timeoutMs: 2000,
505
+ ports: {
506
+ in: { payload: S.json },
507
+ out: { main: S.writeResult, annex: S.json },
508
+ },
509
+ }));
510
+ /**
511
+ * Record an event your package declared: something happened, and
512
+ * pipelines bound to it — plugin listeners, and widgets when the event is
513
+ * delivered to the session — hear it.
514
+ *
515
+ * `event` is the declaration value (`defineSessionEvent(…)`), written into
516
+ * the document as its id; it is never wired, so what a pipeline records is
517
+ * known before it runs. `payload` must carry the event's declared shape. The
518
+ * write is the `session_changes` row, and the event it causes is the one it
519
+ * names — so a recorded event is, like every event, the consequence of a
520
+ * write. It is never the live row; a run may record several.
521
+ *
522
+ * Who may record it is the declaring package's to say
523
+ * (`defineExtension({ events: [{ event, genre, recordedBy }] })`): the host
524
+ * refuses a recording from a pipeline outside that scope.
525
+ * @experimental
526
+ */
527
+ export const recordEvent = pin(describeOutletDefinition({
528
+ id: 'core:outlet/record-event@1',
529
+ i18n: { name: { en: 'Record event' } },
530
+ effects: 'write',
531
+ causesEventFrom: 'event',
532
+ reviewDefault: 'off',
533
+ review: { fields: ['payload'] },
534
+ timeoutMs: 2000,
535
+ ports: {
536
+ in: {
537
+ /** The declared event's id — a literal, never wired. */
538
+ event: S.text,
539
+ payload: S.json,
540
+ },
541
+ out: { main: S.writeResult },
542
+ },
543
+ }));
544
+ /**
545
+ * Hide a message from the prompt, or show it again — a **ghost**. The row
546
+ * stays; `hidden` says which way it went.
547
+ * @experimental
548
+ */
549
+ export const hideMessage = pin(describeOutletDefinition({
550
+ id: 'core:outlet/hide-message@1',
551
+ effects: 'write',
552
+ reviewDefault: 'off',
553
+ /** The direction may be reviewed; the row may not (see `delete-message`). */
554
+ review: { fields: ['hidden'] },
555
+ timeoutMs: 5000,
556
+ causesEvent: 'core:event/message-hidden@1',
557
+ ports: {
558
+ in: { target: S.rowIds, hidden: S.json },
559
+ out: { main: S.writeResult, messageId: S.writeResult, hidden: S.json },
560
+ },
561
+ }));
562
+ /**
563
+ * A person's rewrite of a **settled** row: the text replaces, the selected
564
+ * alternative follows it, the embedding is cleared for re-indexing, and the
565
+ * row is marked edited. Publishes `previous` — the content it replaced.
566
+ *
567
+ * Distinct from `update-message@1`, which finishes a *generating* row with
568
+ * what a pipeline produced. A floor: every genre has it.
569
+ * @experimental
570
+ */
571
+ export const editMessage = pin(describeOutletDefinition({
572
+ id: 'core:outlet/edit-message@1',
573
+ effects: 'write',
574
+ reviewDefault: 'off',
575
+ /** The text may be reviewed; the row may not (see `delete-message`). */
576
+ review: { fields: ['text'] },
577
+ timeoutMs: 5000,
578
+ causesEvent: 'core:event/message-edited@1',
579
+ ports: {
580
+ in: { target: S.rowIds, text: S.text },
581
+ out: { main: S.writeResult, messageId: S.writeResult, previous: S.json },
582
+ },
583
+ }));
584
+ /**
585
+ * Move between a message's alternatives, or record a new one. `index`
586
+ * selects an alternative the row already holds; `text` records a new one and
587
+ * selects it — the reply road then fills an empty one it opened this way.
588
+ * Publishes `swipeIndex`, the alternative now showing, and `previous` — the
589
+ * content and index that were.
590
+ * @experimental
591
+ */
592
+ export const swipeMessage = pin(describeOutletDefinition({
593
+ id: 'core:outlet/swipe-message@1',
594
+ effects: 'write',
595
+ reviewDefault: 'off',
596
+ /**
597
+ * A recorded alternative's text may be reviewed; neither the row nor
598
+ * the `index` — which alternative a navigation selects is as much the
599
+ * request's identity as the row is (see `delete-message`).
600
+ */
601
+ review: { fields: ['text'] },
602
+ timeoutMs: 5000,
603
+ causesEvent: 'core:event/message-swiped@1',
604
+ ports: {
605
+ in: { target: S.rowIds, index: S.json, text: S.text },
606
+ out: {
607
+ main: S.writeResult,
608
+ messageId: S.writeResult,
609
+ swipeIndex: S.json,
610
+ previous: S.json,
611
+ },
612
+ },
613
+ }));
614
+ /**
615
+ * Branch a session at a message: a new session with the same cast, guests
616
+ * and tags and a copy of the history up to and including `fromMessage`, each
617
+ * copy keeping its channel. Publishes the new `sessionId`. A floor.
618
+ * @experimental
619
+ */
620
+ export const branchSession = pin(describeOutletDefinition({
621
+ id: 'core:outlet/branch-session@1',
622
+ effects: 'write',
623
+ reviewDefault: 'off',
624
+ /** The title may be reviewed; the fork point may not (see `delete-message`). */
625
+ review: { fields: ['title'] },
626
+ timeoutMs: 30000,
627
+ causesEvent: 'core:event/session-branched@1',
628
+ ports: {
629
+ in: { fromMessage: S.rowIds, title: S.text },
630
+ out: { main: S.writeResult, sessionId: S.writeResult },
631
+ },
632
+ }));
633
+ // ── Backdrop (DESIGN-image-generation §6.4, ruling §9.4; 2026-10-12) ───────
634
+ /**
635
+ * 🚧 Set the session's **backdrop**: `sessions.backdropMediaId`, the picture
636
+ * the Backdrop widget shows behind or beside the Stage — session state, a
637
+ * role pointer like a card's avatar, never a message part.
638
+ *
639
+ * `media` is a media list (what `core:oracle/generate-image@1` publishes);
640
+ * the host takes the FIRST image in it, keyed or not, and refuses a file
641
+ * that belongs to neither this session nor the user the run acts as (the
642
+ * rule `create-message`'s media keeps). A list with no image in it writes
643
+ * nothing, causes no event and publishes a null `mediaId` — it never
644
+ * clears: a person clears a backdrop, a pipeline replaces it. Runs in the
645
+ * session scope the run was started in.
646
+ *
647
+ * Causes `core:event/backdrop-set@1` when the pointer moved. Publishes the
648
+ * write result on `main` and the file id now set on `mediaId` (null when
649
+ * nothing was written).
650
+ *
651
+ * ⚠ Not the app background (`user_settings.background_media_id`), not a
652
+ * message attachment, and not the retired *scene image* pins.
653
+ * @experimental
654
+ */
655
+ export const setBackdrop = pin(describeOutletDefinition({
656
+ id: 'core:outlet/set-backdrop@1',
657
+ i18n: { name: { en: 'Set backdrop' } },
658
+ effects: 'write',
659
+ causesEvent: 'core:event/backdrop-set@1',
660
+ reviewDefault: 'off',
661
+ /** A reference to a picture the run rendered; nothing to retype. */
662
+ review: { fields: [] },
663
+ timeoutMs: 5000,
664
+ ports: {
665
+ in: { media: S.mediaList },
666
+ out: { main: S.writeResult, mediaId: S.json },
667
+ },
668
+ }));
669
+ // ── Sprites (DESIGN-sprites §5, 2026-09-24; in-pipeline 2026-10-05) ─────────
670
+ /**
671
+ * Record a line's **shown sprite**. Writes it on the line's ACTIVE swipe
672
+ * (`metadata.swipes.spriteHistory[currentIdx]`, mirrored to
673
+ * `metadata.sprite`), so each swipe keeps its own face.
674
+ *
675
+ * Who chose it is `source`, written by the spec as a literal: `picker` after
676
+ * a reply, `person` in `core:spec/show-sprite` (a person's pick from the
677
+ * message menu). A picker never overwrites a person's pick. A picker's null
678
+ * pick writes nothing — the line keeps what it shows; a person's null clears
679
+ * the line's sprite.
680
+ * @experimental
681
+ */
682
+ export const showSprite = pin(describeOutletDefinition({
683
+ id: 'core:outlet/show-sprite@1',
684
+ effects: 'write',
685
+ reviewDefault: 'off',
686
+ review: { fields: [] },
687
+ timeoutMs: 5000,
688
+ causesEvent: 'core:event/sprite-shown@1',
689
+ ports: {
690
+ in: {
691
+ target: S.rowIds,
692
+ /** A `sprite-pick@1` — a picker's, or a person's; null for none. */
693
+ pick: S.spritePick,
694
+ /**
695
+ * Who chose the pick: `'picker'` or `'person'`.
696
+ *
697
+ * ## A port, not a parameter, and the call site is what decides
698
+ *
699
+ * A literal in the node's config, on `create-message`'s
700
+ * `generating` terms: the reply specs write `source: 'picker'`
701
+ * and `core:spec/show-sprite` writes `source: 'person'`. A
702
+ * `params` field would put a structural fact of the document
703
+ * in the panel as a knob. It was the host's to decide from the
704
+ * running spec's id until 2026-10-05; the document says it now.
705
+ *
706
+ * ⚠ Stated, not trusted: a host accepts `'person'` only from
707
+ * core's own `core:spec/show-sprite`, run for a person whose
708
+ * pick it checked against the item rule, as for an edit.
709
+ */
710
+ source: S.text,
711
+ },
712
+ out: {
713
+ main: S.writeResult,
714
+ messageId: S.writeResult,
715
+ /** What the line now shows, or null. */
716
+ sprite: S.json,
717
+ /**
718
+ * True when nothing was written — a picker meeting a person's
719
+ * pick, a picker's null pick, or the sprite the line already
720
+ * shows.
721
+ */
722
+ kept: S.json,
723
+ },
724
+ },
725
+ }));
726
+ /**
727
+ * 🚧 File pictures as a card's **sprites** — the end of the Sprite set fill.
728
+ *
729
+ * For every item of `media` that carries a series `key`: a `sprites` row in
730
+ * the set named `setName` (the card's default set when the name is blank or
731
+ * gone), under the sprite label that key was drawn for, with
732
+ * `source: 'generated'` and the picture as its file. The label comes from
733
+ * `series` (each item's `vars.label`); with no series the key is the label.
734
+ *
735
+ * - An **empty sprite** waiting under the label is filled first.
736
+ * - Otherwise the picture is added beside what is there — a **variant** —
737
+ * so a second picture under one key, or a run that redraws a label, never
738
+ * replaces a sprite.
739
+ * - An item with **no key** (surplus the host kept) is ignored.
740
+ * - A key in `series` that brought no picture is reported on `missing`.
741
+ *
742
+ * The picture becomes the card's file (provenance: `files.character_id`), so
743
+ * it carries the card's visibility and stays out of the card's gallery like
744
+ * every sprite. Refused unless the run's person owns the card or is an admin.
745
+ *
746
+ * Causes `core:event/sprites-attached@1` when at least one row was written.
747
+ * About a card, not a session: it writes no session row.
748
+ * @experimental
749
+ */
750
+ export const attachSprite = pin(describeOutletDefinition({
751
+ id: 'core:outlet/attach-sprite@1',
752
+ i18n: { name: { en: 'Attach as sprites' } },
753
+ effects: 'write',
754
+ causesEvent: 'core:event/sprites-attached@1',
755
+ reviewDefault: 'off',
756
+ /** References to pictures the run drew; nothing to retype. */
757
+ review: { fields: [] },
758
+ timeoutMs: 15000,
759
+ ports: {
760
+ in: {
761
+ media: S.mediaList,
762
+ characterId: S.rowIds,
763
+ setName: S.text,
764
+ /** The series the pictures were drawn for — the key → sprite label map. */
765
+ series: S.imageSeries,
766
+ },
767
+ out: {
768
+ main: S.writeResult,
769
+ /** `[{ label, spriteId }]`, one per row written, in media order. */
770
+ attached: S.json,
771
+ /** Sprite labels the series asked for that came back with no picture. */
772
+ missing: S.json,
773
+ },
774
+ },
775
+ }));
776
+ /**
777
+ * 🚧 **Offer** pictures to a card — put them in the card's **gallery** for a
778
+ * person to pick from (the end of Portrait).
779
+ *
780
+ * Each image in `media` becomes a picture of the card's gallery, after the
781
+ * pictures already there, in media order. Nothing is chosen for the person:
782
+ * the avatar and the likeness image are left as they are. *Use as avatar*
783
+ * and *Use as likeness image* on the gallery tile are the person's, later.
784
+ *
785
+ * - An item that is not an image is skipped.
786
+ * - A picture must be the run person's own file or already the card's — a
787
+ * media reference is an address anyone could type, and the gallery would
788
+ * re-publish whatever it names under the card's visibility.
789
+ * - A picture that is already one of the card's files stays where it is.
790
+ *
791
+ * `offered` is `[{ mediaId, key }]`, one per picture placed, with the series
792
+ * key it was drawn for (`null` for surplus the host kept unkeyed). Refused
793
+ * unless the run's person owns the card or is an admin.
794
+ *
795
+ * Causes `core:event/media-offered@1` when at least one picture was placed.
796
+ * About a card, not a session: it writes no session row.
797
+ * @experimental
798
+ */
799
+ export const offerMedia = pin(describeOutletDefinition({
800
+ id: 'core:outlet/offer-media@1',
801
+ i18n: { name: { en: 'Offer to the gallery' } },
802
+ effects: 'write',
803
+ causesEvent: 'core:event/media-offered@1',
804
+ reviewDefault: 'off',
805
+ /** References to pictures the run drew; nothing to retype. */
806
+ review: { fields: [] },
807
+ timeoutMs: 15000,
808
+ ports: {
809
+ in: {
810
+ media: S.mediaList,
811
+ characterId: S.rowIds,
812
+ },
813
+ out: {
814
+ main: S.writeResult,
815
+ /** `[{ mediaId, key }]`, one per picture placed, in media order. */
816
+ offered: S.json,
817
+ },
818
+ },
819
+ }));
820
+ // ── The story clock (DESIGN-story-time P3, 2026-09-28) ──────────────────────
821
+ /**
822
+ * Move a session's **story clock** — the session's own story now — by `by` of
823
+ * `unit`, through its lorebook's calendar (`advanceStoryTime`): carried by a
824
+ * declared calendar, and by the smallest-part rule in a free-form book.
825
+ * What "advance a minute per reply" places.
826
+ *
827
+ * Moves the session's clock only, never the book's or its line's present. A
828
+ * session with no clock of its own starts from its line's present. Refused
829
+ * with a sentence — the run halts, unless the spec says `onRefusal: 'skip'`
830
+ * — when the session has no lorebook, when there is no present to start
831
+ * from, and when the result does not land in the book's calendar; never
832
+ * clamped, never a silent no-op.
833
+ *
834
+ * `by` and `unit` in-ports, when wired, win over the parameters. To advance
835
+ * once per reply, place it in a spec bound to the reply's event, which runs
836
+ * after the reply is saved. (No ordering-only in-port: an unread port is a
837
+ * declared control no run consults — `declaredReads`.)
838
+ *
839
+ * 🚧 Every move it makes is written to the session's state ledger, anchored
840
+ * where the world's changes are (live scenes §15 G5, 2026-10-13): the person
841
+ * reads it under the message ("Time passes: 3 hours (… → …)"), and a delete,
842
+ * swipe or regenerate of that message takes it back as it takes values back.
843
+ * Why the clock moved is the spec's to say (`cause`), never inferred from
844
+ * the run's inlet.
845
+ * @experimental
846
+ */
847
+ export const advanceStoryClock = pin(describeOutletDefinition({
848
+ id: 'core:outlet/advance-story-clock@1',
849
+ i18n: { name: { en: 'Advance story clock' } },
850
+ effects: 'write',
851
+ reviewDefault: 'off',
852
+ review: { fields: [] },
853
+ timeoutMs: 2000,
854
+ causesEvent: 'core:event/session-updated@1',
855
+ slots: {
856
+ params: {
857
+ kind: 'parameters',
858
+ facet: 'behavior',
859
+ schema: {
860
+ by: {
861
+ type: 'integer',
862
+ default: 1,
863
+ label: { en: 'By' },
864
+ description: { en: 'How many units to move the clock. Negative goes back.' },
865
+ },
866
+ unit: {
867
+ type: 'enum',
868
+ of: ['minutes', 'hours', 'days', 'months', 'years'],
869
+ members: [
870
+ { key: 'minutes', label: { en: 'Minutes' } },
871
+ { key: 'hours', label: { en: 'Hours' } },
872
+ { key: 'days', label: { en: 'Days' } },
873
+ { key: 'months', label: { en: 'Months' } },
874
+ { key: 'years', label: { en: 'Years' } },
875
+ ],
876
+ default: 'hours',
877
+ label: { en: 'Unit' },
878
+ description: {
879
+ en: "What to count. In a free-form book only the part named moves: days never roll into a month.",
880
+ },
881
+ },
882
+ },
883
+ },
884
+ },
885
+ ports: {
886
+ in: {
887
+ /** A whole number; wins over the `by` parameter when wired. */
888
+ by: S.json,
889
+ /** One of the units; wins over the `unit` parameter when wired. */
890
+ unit: S.text,
891
+ /**
892
+ * 🚧 **Why the clock moves** (live scenes §15 G4, 2026-10-13),
893
+ * a literal: `'action'` — a person's press (*Time passes…*);
894
+ * `'keeper'` — the state-keeper's move under Trust the
895
+ * narrator; `'tick'` — a reply's fixed tick. An action's and
896
+ * the keeper's move are **time actions** the boundary watcher
897
+ * may begin a new scene at; a tick never is. Unwired reads as
898
+ * `'action'`.
899
+ *
900
+ * ## A port, not a parameter, and the call site is what decides
901
+ *
902
+ * As `show-sprite@1`'s `source`: a literal in the node's
903
+ * config, because why a step moves the clock is a structural
904
+ * fact of the document, not a knob for the panel. It was the
905
+ * host's to infer from the run's inlet until 2026-10-13, and a
906
+ * keeper's move on a reply turn was then never a time action.
907
+ * It also decides what a swipe or a regenerate takes back: a
908
+ * tick stands (the re-driven reply never ticks again), every
909
+ * other move goes with the reply.
910
+ */
911
+ cause: S.text,
912
+ /**
913
+ * 🚧 **What a refusal does** (live scenes §15 G7), a literal:
914
+ * `'halt'` (unwired) stops the run with the sentence;
915
+ * `'skip'` moves nothing, puts the sentence on `skipped` and
916
+ * on the session's state ledger, and lets the run finish — for
917
+ * a step that runs after other changes already landed, which
918
+ * a halt would leave looking like a failed turn. Every core
919
+ * spec's skips: Adventure's keeper steps and its *Time
920
+ * passes…*, Chat's reply tick, and Chat's and the Lair's *Time
921
+ * passes…* (live scenes §15 G12).
922
+ */
923
+ onRefusal: S.text,
924
+ },
925
+ out: {
926
+ main: S.writeResult,
927
+ /** The session's story clock as it now stands: `{ year, month?, day?, hour?, minute? }`. */
928
+ clock: S.json,
929
+ /**
930
+ * 🚧 Why the clock did not move, under `onRefusal: 'skip'` —
931
+ * the sentence the person reads; empty when it moved.
932
+ */
933
+ skipped: S.text,
934
+ /** It spelled through the book's calendar. */
935
+ label: S.text,
936
+ },
937
+ },
938
+ }));
939
+ // ── Forms (plans/29 R-15 *Forms* · *The line*; R-21 (5); 30 §U5d, 2026-09-17) ──
940
+ /**
941
+ * Commit an oracle's answer to a form **exactly as a click would**.
942
+ *
943
+ * The host checks the answer against the form's schema, then fires the
944
+ * block's action through the same server path a press takes
945
+ * (`fireAction`): the run owner is the acting user, the actor portrays the
946
+ * addressee, the block's addressee is the audience, and the action's spec
947
+ * runs as a child of this run. It records `form-answered` in the session's
948
+ * changes with the answer and `answeredBy: 'oracle'`, so the next reply's
949
+ * inlet sees it. Refused outside a document on `core:inlet/form-addressed@1`
950
+ * (`validate()` and the host), refused when the addressee is not the AI's,
951
+ * and refused for a `world` action (the effects line — belt to the
952
+ * validator's braces). `reviewDefault: 'off'`; an admin may gate it, and the
953
+ * reviewer edits the `answer` alone.
954
+ * @experimental
955
+ */
956
+ export const answerForm = pin(describeOutletDefinition({
957
+ id: 'core:outlet/answer-form@1',
958
+ i18n: { name: { en: 'Answer the form' } },
959
+ effects: 'write',
960
+ reviewDefault: 'off',
961
+ /** The answer may be corrected at the gate; which form, and who answers, may not. */
962
+ review: { fields: ['answer'] },
963
+ /**
964
+ * A write's timeout, not a run's (was 600000 until
965
+ * 2026-09-17): the commit checks the answer, asks the cycle caps and
966
+ * **collects** the fire — the action's run is dispatched by the host
967
+ * after this run's receipt is saved, outside any node timeout, as
968
+ * this run's child. A grandchild parked at review parks nothing here.
969
+ *
970
+ * Thirty seconds rather than a write's usual five (changed
971
+ * the same day): the commit does database work of its own — the
972
+ * block off the row, the session, the routing, a cap refusal's
973
+ * receipt — and under PGlite contention (a full test run, a busy
974
+ * install) five seconds turned a legible **halt** into a timeout
975
+ * `err` with no sentence. The ceiling is still a write's order of
976
+ * magnitude, never a model call's: nothing here waits on an oracle.
977
+ */
978
+ timeoutMs: 30000,
979
+ causesEvent: 'core:event/form-answered@1',
980
+ ports: {
981
+ in: {
982
+ /** The block, as the inlet published it. */
983
+ form: S.json,
984
+ /** The oracle's document — checked against `formAnswerSchema(form)`. */
985
+ answer: S.json,
986
+ messageId: S.rowIds,
987
+ blockId: S.text,
988
+ addressee: S.participantRef,
989
+ },
990
+ out: {
991
+ main: S.writeResult,
992
+ messageId: S.writeResult,
993
+ /** The answer as committed: `{ choice }` or the values. */
994
+ answer: S.json,
995
+ /** The identity of the action the answer fires — `<spec slug>#<key>`. */
996
+ firedAction: S.text,
997
+ /** The child run's id, chosen at the commit so this receipt can name it. */
998
+ firedRunId: S.text,
999
+ },
1000
+ },
1001
+ }));
1002
+ /** The audio twin of `attach-image` — same `target`, same commit, bound the same day. @experimental */
1003
+ export const attachAudio = pin(describeOutletDefinition({
1004
+ id: 'core:outlet/attach-audio@1',
1005
+ effects: 'write',
1006
+ /** A reference to rendered audio; nothing to retype. */
1007
+ review: { fields: [] },
1008
+ timeoutMs: 5000,
1009
+ causesEvent: 'core:event/message-updated@1',
1010
+ ports: { in: { target: S.rowIds, audio: S.audio }, out: { main: S.writeResult } },
1011
+ }));
1012
+ // ── Summarization ───────────────────────────────────────────────────────────
1013
+ /**
1014
+ * Write the finished entry. Gate-eligible, so it publishes a write result.
1015
+ *
1016
+ * ## Which kind of entry — the pipeline's decision, at last (2026-09-17)
1017
+ *
1018
+ * The host's commit case has said since the four summarize namespaces were
1019
+ * written that *which kind of entry comes from the pipeline that ran*. It did
1020
+ * not: it wrote world lore whatever ran, because nothing on this declaration
1021
+ * could say otherwise. `entryType` is that sentence made true — a declared
1022
+ * entry type id (`core:entry/world-lore`, `core:entry/history`,
1023
+ * `core:entry/location`), bare, the way `core:query/lorebook-entries@1` spells
1024
+ * them; the version is the row's own column.
1025
+ *
1026
+ * A **param** and not an in-port, because the kind of thing a pipeline writes
1027
+ * is a fact about the pipeline rather than about the turn — a summarizer
1028
+ * writes history every time it runs, a room-builder writes locations every
1029
+ * time — and a param is what a preset can set per session without the spec
1030
+ * being rewired. An unknown id is refused at the commit with a sentence
1031
+ * naming the declared types, never coerced to world lore: a typo that silently
1032
+ * files rooms as world lore is the defect this replaces.
1033
+ *
1034
+ * Default world lore, the agnostic shape, so every spec written before this
1035
+ * keeps doing exactly what it did.
1036
+ *
1037
+ * ## `links`, or a second write
1038
+ *
1039
+ * Linking a new entry takes one of two shapes, and both exist on purpose.
1040
+ * (A pipeline may write many times — only the live row is limited to one — so
1041
+ * `core:outlet/link-lore-entries@1` may also follow this outlet in the same
1042
+ * run, each its own transaction.)
1043
+ *
1044
+ * - `links` — the links land in the **same transaction** as the row, keyed
1045
+ * from the entry just written. A genre that builds a room with its exits
1046
+ * does it in one run and one commit, and a link naming an entry that does
1047
+ * not exist fails the row with it rather than writing half a room. This is
1048
+ * the shape a builder wants.
1049
+ * - `core:outlet/link-lore-entries@1` takes its `to` by **name**, so a later
1050
+ * run can link what an earlier one created without holding an id. This is
1051
+ * the shape a second turn wants.
1052
+ *
1053
+ * Each entry of `links` is a name or an entry id, or a `LoreLinkInput` —
1054
+ * `{ to, linkType?, reverseLinkType?, name?, description? }` — for one that
1055
+ * says more (2026-09-29). Absent on nearly every write, and an
1056
+ * empty list is the same as none. A link the list states twice, or one the
1057
+ * session already reads, is written once: see `linkLoreEntries` on idempotence.
1058
+ * @internal
1059
+ */
1060
+ export const createLoreEntry = pin(describeOutletDefinition({
1061
+ id: 'core:outlet/create-lore-entry@1',
1062
+ i18n: { name: { en: 'Save the lore entry' } },
1063
+ effects: 'write',
1064
+ /**
1065
+ * Both the name and the content may be edited before the entry lands
1066
+ *. `links` is deliberately not among them: the
1067
+ * gate's form edits values a reader can retype, and a list of
1068
+ * references is not one — a reviewer who disagrees with a room's exits
1069
+ * refuses the write.
1070
+ */
1071
+ review: { fields: ['name', 'content'] },
1072
+ timeoutMs: 10000,
1073
+ causesEvent: 'core:event/lore-entry-created@1',
1074
+ slots: {
1075
+ params: {
1076
+ kind: 'parameters',
1077
+ schema: {
1078
+ entryType: {
1079
+ type: 'string',
1080
+ default: 'core:entry/world-lore',
1081
+ quick: true,
1082
+ label: { en: 'Kind of entry' },
1083
+ description: 'Which kind of lorebook entry this pipeline writes — world lore, history, a location. Leave it as world lore for anything that is simply about the world.',
1084
+ },
1085
+ },
1086
+ },
1087
+ },
1088
+ ports: {
1089
+ in: {
1090
+ name: S.text,
1091
+ content: S.text,
1092
+ /**
1093
+ * Links to write from this entry in the same commit — see the
1094
+ * note above on the live row. Names, entry ids, or `LoreLinkInput`s.
1095
+ */
1096
+ links: S.json,
1097
+ },
1098
+ out: { main: S.writeResult, entryId: S.writeResult },
1099
+ },
1100
+ }));
1101
+ /**
1102
+ * Link two lore entries (2026-09-17).
1103
+ *
1104
+ * ## The gap it closes
1105
+ *
1106
+ * `create-lore-entry@1` takes a name and a body and nothing else, so a genre
1107
+ * whose world has *shape* — a room with exits, a street that runs past a shop
1108
+ * — had one place to put that shape: the prose. Lair shipped writing an
1109
+ * `Exits:` line into the content and parsing it back out, which is a link with
1110
+ * no foreign key, no cascade and no second reader. The rows have existed all
1111
+ * along (an entry-ended `narrative_relationships` row, the same edge the
1112
+ * lorebook's own graph draws); no pipeline could write one.
1113
+ *
1114
+ * ## Both ends, and the one scope
1115
+ *
1116
+ * `from` is an entry id — or, straight off `create-lore-entry@1`, its
1117
+ * `entryId` write result, which is assignable to `row-ids@1`. `to`
1118
+ * is an id **or a name**, resolved within the session's own lorebook, case
1119
+ * and surrounding space ignored. A name is the half that makes the law below
1120
+ * survivable, and it is also the half that can be wrong in two ways, so both
1121
+ * are refused with a sentence: a name nothing answers to, and a name **two**
1122
+ * entries answer to — the second never picks one, because picking would link
1123
+ * the wrong room silently and a duplicate name is the author's to resolve.
1124
+ *
1125
+ * One lorebook, both ends. An edge whose ends live in two books belongs to
1126
+ * neither and the row carries one `lorebook_id`, so a cross-book link is
1127
+ * refused rather than repaired — the same rule the socket handlers hold, held
1128
+ * again here because a pipeline does not come through them.
1129
+ *
1130
+ * ## After a create
1131
+ *
1132
+ * It may follow `core:outlet/create-lore-entry@1` in the same run (only the
1133
+ * live row is limited to one), linking by name what that write created — which is why
1134
+ * `to` takes one; a later run can do the same. Each write is its own
1135
+ * transaction, so a failed link leaves the entry behind. When the entry and
1136
+ * its links are one thought, `create-lore-entry`'s own `links` in-port writes
1137
+ * the edges in the row's transaction instead — the shape a room-builder wants.
1138
+ *
1139
+ * ## What the link says (2026-09-29)
1140
+ *
1141
+ * The row is a **relationship**, and it carries the relationship's whole
1142
+ * descriptor — the same four words the lorebook's own link form edits:
1143
+ *
1144
+ * - `linkType` — the relationship type, read from the `from` end ("leads
1145
+ * north to"). Free text in the row and free text here: the app's list is a
1146
+ * vocabulary of *suggestions*, and nothing reads a relationship type
1147
+ * semantically. The default is `leads to`.
1148
+ * - `reverseLinkType` — the wording read from the `to` end ("leads south
1149
+ * to"). **Empty is one way**, and one way is the default: direction is
1150
+ * something a spec says, never a guess the host makes from the forward
1151
+ * words. A symmetric wording repeats itself (`connects to` / `connects to`).
1152
+ * - `name` — the relationship's own name ("the rusted iron door", "the King's
1153
+ * Road"), empty for an unnamed way. ⚠ Something you can stand in is a place
1154
+ * of its own, not a named link.
1155
+ * - `description` — its description. (It was the port `label`; one column,
1156
+ * one word, no alias.)
1157
+ *
1158
+ * ## Idempotent
1159
+ *
1160
+ * One way is one row, **as the session reads** (the app's
1161
+ * `linksOnReadingThatWay`): a link the session already reads — on its own
1162
+ * line or one it inherits, undated or dated at or before its moment — with
1163
+ * the same name (case aside) that says **everything** this one would (the same
1164
+ * words read from the same end, both ways when both are asked, or its true
1165
+ * mirror drawn from the far end) is **the standing row**. The outlet returns
1166
+ * its id and writes nothing, so a re-run, a swipe or a second turn never stacks
1167
+ * a room's ways out; `fromEntryId` is the row's own `from`. The standing row is
1168
+ * never rewritten: a pipeline's repeat does not edit a link a person may have
1169
+ * drawn or worded. And because this run did not make the row, the host neither
1170
+ * records it as the run's (an undo of the run must not delete it) nor reports a
1171
+ * write (`written: false`, so no `core:event/lore-link-created@1`).
1172
+ *
1173
+ * Refused with a sentence instead: a link that says only PART of this one (a
1174
+ * one-way door where both ways is asked — a second row would say that part
1175
+ * twice), and one that says it all but no longer stands (resolved, broken,
1176
+ * secret) — nothing the session reads states it, and a pipeline does not
1177
+ * reopen or reveal it.
1178
+ * @internal
1179
+ */
1180
+ export const linkLoreEntries = pin(describeOutletDefinition({
1181
+ id: 'core:outlet/link-lore-entries@1',
1182
+ i18n: {
1183
+ name: { en: 'Link the lore entries' },
1184
+ description: {
1185
+ en: 'Draws a link between two entries of this session’s lorebook — a room’s way out, who keeps what, what stands near what.',
1186
+ },
1187
+ },
1188
+ effects: 'write',
1189
+ /**
1190
+ * The link itself is what a reviewer judges, so its words both ways,
1191
+ * its name and its description may be retyped. The
1192
+ * two ends may not: they are the run's own identity, and a reviewer
1193
+ * re-aiming them would link a pair nobody judged — the rule
1194
+ * `delete-message@1` states.
1195
+ */
1196
+ review: { fields: ['linkType', 'reverseLinkType', 'name', 'description'] },
1197
+ timeoutMs: 10000,
1198
+ causesEvent: 'core:event/lore-link-created@1',
1199
+ slots: {
1200
+ params: {
1201
+ kind: 'parameters',
1202
+ schema: {
1203
+ linkType: {
1204
+ type: 'string',
1205
+ default: 'leads to',
1206
+ quick: true,
1207
+ label: { en: 'Kind of link' },
1208
+ description: 'What the link says, read from the entry it starts at — “leads north to”, “connects to”, “is inside”, “keeper of”.',
1209
+ },
1210
+ reverseLinkType: {
1211
+ type: 'string',
1212
+ default: '',
1213
+ label: { en: 'From there it…' },
1214
+ description: 'What the link says read from the other end — “leads south to”, “holds”. Leave it empty for a way that only goes one way.',
1215
+ },
1216
+ },
1217
+ },
1218
+ },
1219
+ ports: {
1220
+ in: {
1221
+ /** The entry the link starts at — an id, or a write result. */
1222
+ from: S.rowIds,
1223
+ /**
1224
+ * The entry it ends at: an id, or a **name** resolved within
1225
+ * this session's lorebook. `json` because it is either — and
1226
+ * every shape is assignable into `json`, so an id port, a
1227
+ * write result and a text name all wire here.
1228
+ */
1229
+ to: S.json,
1230
+ /** The relationship's own name — "the rusted iron door". Optional. */
1231
+ name: S.text,
1232
+ /** Its description. Optional. */
1233
+ description: S.text,
1234
+ },
1235
+ out: { main: S.writeResult, linkId: S.writeResult },
1236
+ },
1237
+ }));
1238
+ // ── Graph build ─────────────────────────────────────────────────────────────
1239
+ /**
1240
+ * The proposal, held for review.
1241
+ *
1242
+ * `effects: 'write'` and therefore gate-eligible, which is the mechanism behind
1243
+ * the rule that a graph build **stops at the review screen** and never applies
1244
+ * itself. Under `async` review the proposal is exactly that — a proposal — and
1245
+ * `write-result@1` is the shape that refuses to be mistaken for row ids.
1246
+ * @internal
1247
+ */
1248
+ export const graphProposal = pin(describeOutletDefinition({
1249
+ id: 'core:outlet/graph-proposal@1',
1250
+ i18n: { name: { en: 'Propose graph changes' } },
1251
+ effects: 'write',
1252
+ /** The proposal is what the review screen exists to edit. */
1253
+ review: { fields: ['proposal'] },
1254
+ timeoutMs: 10000,
1255
+ causesEvent: 'core:event/graph-proposal-created@1',
1256
+ ports: {
1257
+ in: { proposal: S.json },
1258
+ out: { main: S.writeResult, proposalId: S.writeResult },
1259
+ },
1260
+ }));
1261
+ //# sourceMappingURL=outlets.js.map