@serene-pub/sdk 0.6.0-pr-1
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.
- package/LICENSE +202 -0
- package/NOTICE +17 -0
- package/README.md +368 -0
- package/dist/actions.d.ts +572 -0
- package/dist/actions.js +829 -0
- package/dist/annexFields.d.ts +234 -0
- package/dist/annexFields.js +413 -0
- package/dist/announce.d.ts +464 -0
- package/dist/announce.js +426 -0
- package/dist/attributes.d.ts +670 -0
- package/dist/attributes.js +904 -0
- package/dist/bands.d.ts +125 -0
- package/dist/bands.js +256 -0
- package/dist/builder.d.ts +683 -0
- package/dist/builder.js +677 -0
- package/dist/candidates.d.ts +109 -0
- package/dist/candidates.js +118 -0
- package/dist/capabilities.d.ts +744 -0
- package/dist/capabilities.js +679 -0
- package/dist/channels.d.ts +106 -0
- package/dist/channels.js +129 -0
- package/dist/clauses.d.ts +40 -0
- package/dist/clauses.js +43 -0
- package/dist/component.d.ts +33 -0
- package/dist/component.js +27 -0
- package/dist/componentBuild.d.ts +48 -0
- package/dist/componentBuild.js +84 -0
- package/dist/componentClient.d.ts +100 -0
- package/dist/componentClient.js +13 -0
- package/dist/componentImports.d.ts +51 -0
- package/dist/componentImports.js +106 -0
- package/dist/componentModule.d.ts +8 -0
- package/dist/componentModule.js +270 -0
- package/dist/componentWire.d.ts +130 -0
- package/dist/componentWire.js +280 -0
- package/dist/config.d.ts +295 -0
- package/dist/config.js +231 -0
- package/dist/connections.d.ts +89 -0
- package/dist/connections.js +131 -0
- package/dist/declarations.d.ts +290 -0
- package/dist/declarations.js +794 -0
- package/dist/descriptors.d.ts +1774 -0
- package/dist/descriptors.js +1329 -0
- package/dist/dev.d.ts +136 -0
- package/dist/dev.js +161 -0
- package/dist/document.d.ts +202 -0
- package/dist/document.js +312 -0
- package/dist/engines.d.ts +117 -0
- package/dist/engines.js +203 -0
- package/dist/eventMapLaws.d.ts +63 -0
- package/dist/eventMapLaws.js +128 -0
- package/dist/events.d.ts +554 -0
- package/dist/events.js +633 -0
- package/dist/executor.d.ts +771 -0
- package/dist/executor.js +1829 -0
- package/dist/extension.d.ts +448 -0
- package/dist/extension.js +315 -0
- package/dist/facets.d.ts +53 -0
- package/dist/facets.js +60 -0
- package/dist/foldedSections.d.ts +74 -0
- package/dist/foldedSections.js +161 -0
- package/dist/genres.d.ts +507 -0
- package/dist/genres.js +633 -0
- package/dist/guardedConnection.d.ts +138 -0
- package/dist/guardedConnection.js +341 -0
- package/dist/handlebarsReach.d.ts +122 -0
- package/dist/handlebarsReach.js +222 -0
- package/dist/hash.d.ts +146 -0
- package/dist/hash.js +166 -0
- package/dist/hookGrants.d.ts +47 -0
- package/dist/hookGrants.js +68 -0
- package/dist/hooks.d.ts +290 -0
- package/dist/hooks.js +113 -0
- package/dist/hostElements.d.ts +447 -0
- package/dist/hostElements.js +702 -0
- package/dist/i18n.d.ts +94 -0
- package/dist/i18n.js +123 -0
- package/dist/identity.d.ts +93 -0
- package/dist/identity.js +135 -0
- package/dist/index.d.ts +85 -0
- package/dist/index.js +176 -0
- package/dist/layout.d.ts +194 -0
- package/dist/layout.js +40 -0
- package/dist/media.d.ts +202 -0
- package/dist/media.js +70 -0
- package/dist/messageBlocks.d.ts +487 -0
- package/dist/messageBlocks.js +683 -0
- package/dist/migration.d.ts +128 -0
- package/dist/migration.js +261 -0
- package/dist/names.d.ts +78 -0
- package/dist/names.js +136 -0
- package/dist/nodeInput.d.ts +399 -0
- package/dist/nodeInput.js +178 -0
- package/dist/participants.d.ts +291 -0
- package/dist/participants.js +252 -0
- package/dist/personGate.d.ts +62 -0
- package/dist/personGate.js +77 -0
- package/dist/pick.d.ts +84 -0
- package/dist/pick.js +103 -0
- package/dist/pluginHarness.d.ts +235 -0
- package/dist/pluginHarness.js +558 -0
- package/dist/pluginPermissions.d.ts +25 -0
- package/dist/pluginPermissions.js +97 -0
- package/dist/pluginRuleRef.d.ts +13 -0
- package/dist/pluginRuleRef.js +10 -0
- package/dist/predicates.d.ts +182 -0
- package/dist/predicates.js +249 -0
- package/dist/preview.d.ts +120 -0
- package/dist/preview.js +82 -0
- package/dist/promptBlocks.d.ts +130 -0
- package/dist/promptBlocks.js +197 -0
- package/dist/rankingDecisions.d.ts +60 -0
- package/dist/rankingDecisions.js +48 -0
- package/dist/receipt.d.ts +313 -0
- package/dist/receipt.js +60 -0
- package/dist/receiverRules.d.ts +24 -0
- package/dist/receiverRules.js +94 -0
- package/dist/refs.d.ts +117 -0
- package/dist/refs.js +137 -0
- package/dist/registry.d.ts +230 -0
- package/dist/registry.js +273 -0
- package/dist/review.d.ts +108 -0
- package/dist/review.js +97 -0
- package/dist/sampling.d.ts +152 -0
- package/dist/sampling.js +712 -0
- package/dist/scope.d.ts +65 -0
- package/dist/scope.js +128 -0
- package/dist/scripts.d.ts +243 -0
- package/dist/scripts.js +326 -0
- package/dist/sessionLayout.d.ts +339 -0
- package/dist/sessionLayout.js +503 -0
- package/dist/sessionSettings.d.ts +70 -0
- package/dist/sessionSettings.js +2 -0
- package/dist/settings.d.ts +501 -0
- package/dist/settings.js +604 -0
- package/dist/settingsSlot.d.ts +108 -0
- package/dist/settingsSlot.js +166 -0
- package/dist/shapes.d.ts +373 -0
- package/dist/shapes.js +408 -0
- package/dist/sheets.d.ts +165 -0
- package/dist/sheets.js +251 -0
- package/dist/statShapes.d.ts +96 -0
- package/dist/statShapes.js +112 -0
- package/dist/status.d.ts +103 -0
- package/dist/status.js +125 -0
- package/dist/storage.d.ts +145 -0
- package/dist/storage.js +33 -0
- package/dist/storyTime.d.ts +308 -0
- package/dist/storyTime.js +560 -0
- package/dist/surfaces.d.ts +501 -0
- package/dist/surfaces.js +292 -0
- package/dist/template.d.ts +312 -0
- package/dist/template.js +554 -0
- package/dist/templateCheck.d.ts +60 -0
- package/dist/templateCheck.js +516 -0
- package/dist/templateFit.d.ts +157 -0
- package/dist/templateFit.js +349 -0
- package/dist/templateIds.d.ts +138 -0
- package/dist/templateIds.js +144 -0
- package/dist/templateScopeAt.d.ts +131 -0
- package/dist/templateScopeAt.js +354 -0
- package/dist/testing.d.ts +177 -0
- package/dist/testing.js +383 -0
- package/dist/tokenizers.d.ts +113 -0
- package/dist/tokenizers.js +184 -0
- package/dist/turnLock.d.ts +96 -0
- package/dist/turnLock.js +79 -0
- package/dist/turnOrder.d.ts +143 -0
- package/dist/turnOrder.js +128 -0
- package/dist/validate.d.ts +74 -0
- package/dist/validate.js +1399 -0
- package/dist/values.d.ts +212 -0
- package/dist/values.js +390 -0
- package/dist/variables.d.ts +493 -0
- package/dist/variables.js +662 -0
- package/dist/verdicts.d.ts +275 -0
- package/dist/verdicts.js +348 -0
- package/dist/widgetDecls.d.ts +88 -0
- package/dist/widgetDecls.js +119 -0
- package/dist/widgets.d.ts +1527 -0
- package/dist/widgets.js +208 -0
- package/dist/wire.d.ts +126 -0
- package/dist/wire.js +140 -0
- package/dist/worldinfo.d.ts +150 -0
- package/dist/worldinfo.js +212 -0
- package/host-elements.d.ts +914 -0
- package/package.json +67 -0
package/dist/actions.js
ADDED
|
@@ -0,0 +1,829 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actions — what a person (or an AI-portrayed participant) can invoke, and
|
|
3
|
+
* where (plans/29 R-15 *venue* · *audience* · *quick* · *slash name*;
|
|
4
|
+
* 09-AMENDMENTS-B B9, F40 — was F38 before the 2026-09-17 renumbering; ruled
|
|
5
|
+
* 2026-09-15, built 2026-09-16 as U5c).
|
|
6
|
+
*
|
|
7
|
+
* A spec contributes actions through `contributes.actions[]`. Core's own message verbs — the floors and the
|
|
8
|
+
* built-ins of U5b — are described by the same shape in `CORE_ACTIONS`, so
|
|
9
|
+
* a client renders **one list** per venue and never hand-writes a verb button.
|
|
10
|
+
*
|
|
11
|
+
* ## The four declarations
|
|
12
|
+
*
|
|
13
|
+
* - **venue** — where the action appears, *per channel*: `{ kind, channel? }`.
|
|
14
|
+
* `VENUE_KINDS` is a closed set core owns; a plugin picks from it. An
|
|
15
|
+
* action may name several venues. A venue with no `channel` appears on
|
|
16
|
+
* every channel of the session.
|
|
17
|
+
* - **audience** — who may *see* and who may *act*, as participant
|
|
18
|
+
* references (`participants.ts`). Defaults per kind: a contributed action
|
|
19
|
+
* is seen by any `participant` and acted on by the `owner`
|
|
20
|
+
* (`DEFAULT_ACTION_AUDIENCE`); a core message verb is `item` — whoever the
|
|
21
|
+
* message belongs to, decided against the row at the venue.
|
|
22
|
+
* - **quick** — the one prominence flag. Every venue is a **primary set**
|
|
23
|
+
* (`quick: true`) plus an **overflow** that always lists every enabled
|
|
24
|
+
* action; composer actions are always reachable through `/`. Placement is
|
|
25
|
+
* presentation; availability is data (F40). A CSS pack may reposition the
|
|
26
|
+
* primary set, never remove an action.
|
|
27
|
+
* - **slash** — the stable ASCII id a composer action is called by. Core's
|
|
28
|
+
* specs claim bare names (`advance`, `narrate`); a plugin's are
|
|
29
|
+
* `<plugin>.<action>` (`acme.roll`), the plugin id being the spec's
|
|
30
|
+
* namespace — so a collision across owners is impossible by construction,
|
|
31
|
+
* and the palette autocompletes so nobody types the long form. Never
|
|
32
|
+
* localised (R-20): the palette shows the localised `label` beside it.
|
|
33
|
+
*
|
|
34
|
+
* - **enabled-when** (U5e, built 2026-09-17) — whether the action is offered
|
|
35
|
+
* *now*: a declared predicate over the session's **published values**, the
|
|
36
|
+
* junction clause's shape (`{ on: 'state.world.location', truthy: true,
|
|
37
|
+
* reason }`), never code. A list means all must hold. The genre supplies
|
|
38
|
+
* defaults per function (`GenreDecl.enabledWhen`); a session may override
|
|
39
|
+
* one function's; the action's own declaration sits between. The panel
|
|
40
|
+
* renders **why** a button is grey from the failing predicate's `reason`.
|
|
41
|
+
* The shape and its evaluator live in `predicates.ts`, shared with the
|
|
42
|
+
* junction clause.
|
|
43
|
+
*
|
|
44
|
+
* ## What this is not
|
|
45
|
+
*
|
|
46
|
+
* Not a *pipeline* — an action *starts* one (`function` is the key routing
|
|
47
|
+
* resolves, 19 §3). Not an *event* — those are core-owned occurrences. Not
|
|
48
|
+
* *availability* — the genre's `messageVerbs` and the preset's included set
|
|
49
|
+
* decide that; a declaration here says where and to whom an available action
|
|
50
|
+
* is offered.
|
|
51
|
+
*/
|
|
52
|
+
import { isParticipantRef, PARTICIPANT_ROLES } from './participants.js';
|
|
53
|
+
import { DEFAULT_CHANNEL, parseChannel } from './channels.js';
|
|
54
|
+
import { envoyFindings } from './genres.js';
|
|
55
|
+
import { enabledWhenFindings, i18nFindings, isEnabledWhenShaped, normalizeEnabledWhen, } from './predicates.js';
|
|
56
|
+
import { i18nText } from './i18n.js';
|
|
57
|
+
import { CORE_ACTION_SPEC_ID } from './identity.js';
|
|
58
|
+
import { assertSlotId } from './attributes.js';
|
|
59
|
+
/** The two sides of the effects line (R-15). `fiction` is the default. @experimental */
|
|
60
|
+
export const ACTION_EFFECTS = ['fiction', 'world'];
|
|
61
|
+
/**
|
|
62
|
+
* How much an action needs the text it **collects** (lair pass R3,
|
|
63
|
+
* 2026-09-28): `required` — the press does not fire without some;
|
|
64
|
+
* `optional` — an empty submit fires too, and `CollectedText.ifEmpty` says
|
|
65
|
+
* what that does. Was `COMPOSER_TEXT_MODES` (B10), when the text was read
|
|
66
|
+
* off the composer's draft.
|
|
67
|
+
* @experimental
|
|
68
|
+
*/
|
|
69
|
+
export const TEXT_NEEDS = ['required', 'optional'];
|
|
70
|
+
/** The keys `ActionDecl.collects` may carry, and each request's own keys. */
|
|
71
|
+
const COLLECTS_KEYS = ['text', 'recipients'];
|
|
72
|
+
const COLLECTED_TEXT_KEYS = ['need', 'label', 'placeholder', 'ifEmpty'];
|
|
73
|
+
const COLLECTED_RECIPIENTS_KEYS = ['label', 'min', 'max', 'overwrites'];
|
|
74
|
+
/**
|
|
75
|
+
* The venues a `world` action may appear in: never a form, the extra tab or a
|
|
76
|
+
* widget.
|
|
77
|
+
*
|
|
78
|
+
* ⚠ **`message` is on the owner's side since 2026-09-28** (lair re-plan R11,
|
|
79
|
+
* *File as a room*). The line exists so that a character can never be asked
|
|
80
|
+
* to answer an out-of-fiction question (29 R-15 *The line*), and a question
|
|
81
|
+
* put to someone lives in the **`form`** venue — split out of `message` the
|
|
82
|
+
* day the line was built (U5d review, S1). The `message` venue is a message's
|
|
83
|
+
* own ⋮ and quick row: a person's button, pressed by the person, on a row.
|
|
84
|
+
* With `act` held to `owner` / `admin` (`WORLD_ACTION_ACTORS`), no block
|
|
85
|
+
* naming it, and no fire made **as** a participant, a `world` action there
|
|
86
|
+
* is the owner acting on a row — the same act as the composer's button,
|
|
87
|
+
* with the row as its subject. `extra` and `widget` stay out: a widget can
|
|
88
|
+
* invoke without a person's press.
|
|
89
|
+
* @experimental
|
|
90
|
+
*/
|
|
91
|
+
export const WORLD_ACTION_VENUES = ['composer', 'message', 'session-settings', 'admin', 'review'];
|
|
92
|
+
/** The references a `world` action's `act` audience may name: the owner, an administrator. @experimental */
|
|
93
|
+
export const WORLD_ACTION_ACTORS = ['owner', 'admin'];
|
|
94
|
+
/** An action's side of the line: what it declared, else `fiction`. @experimental */
|
|
95
|
+
export const effectsOf = (action) => action.effects === 'world' ? 'world' : 'fiction';
|
|
96
|
+
/**
|
|
97
|
+
* The closed set of places an action may appear. Core owns it; a plugin picks.
|
|
98
|
+
*
|
|
99
|
+
* `form` (U5d review, S1) is the one venue nothing lists: an action carried
|
|
100
|
+
* by a **form** — a `choices` or `form` block in a message — and pressed
|
|
101
|
+
* only from that block (the Adventure genre's *Answer*). A `form`-venue
|
|
102
|
+
* action never appears in a message's overflow, the composer's More menu or
|
|
103
|
+
* any other listing (`LISTED_VENUE_KINDS`); the block's fire still resolves
|
|
104
|
+
* it. A `world` action may not take it (`WORLD_ACTION_VENUES`): an
|
|
105
|
+
* out-of-fiction effect is never a question a message carries.
|
|
106
|
+
*
|
|
107
|
+
* ⚠ **`form` stays fiction-only even after L1** (ruled 2026-09-17). A block
|
|
108
|
+
* addressed to the **owner** may name a `world` action — see
|
|
109
|
+
* `worldBlockFunctions` — but a *venue* is declared and an *addressee* is
|
|
110
|
+
* decided at run time, so this check cannot see one and would have to admit
|
|
111
|
+
* every `form`-venue world action to admit the owner's. The owner-addressed
|
|
112
|
+
* block therefore names a `composer`-venue world action instead: the venue
|
|
113
|
+
* says where the declaration may be OFFERED, the addressee says who may press
|
|
114
|
+
* this particular button, and the two answers stay separate.
|
|
115
|
+
* @experimental
|
|
116
|
+
*/
|
|
117
|
+
export const VENUE_KINDS = [
|
|
118
|
+
'composer',
|
|
119
|
+
'message',
|
|
120
|
+
'extra',
|
|
121
|
+
'widget',
|
|
122
|
+
'session-settings',
|
|
123
|
+
'pipelines',
|
|
124
|
+
'admin',
|
|
125
|
+
'review',
|
|
126
|
+
'form',
|
|
127
|
+
];
|
|
128
|
+
/** The venues a listing offers — every kind but `form`, which only a block reaches. @experimental */
|
|
129
|
+
export const LISTED_VENUE_KINDS = VENUE_KINDS.filter((k) => k !== 'form');
|
|
130
|
+
/** A contributed action's default audience: any member sees it, the owner acts. @internal */
|
|
131
|
+
export const DEFAULT_ACTION_AUDIENCE = Object.freeze({
|
|
132
|
+
see: ['participant'],
|
|
133
|
+
act: ['owner'],
|
|
134
|
+
});
|
|
135
|
+
/** A core message verb's audience: whoever the message belongs to (the item rule). @experimental */
|
|
136
|
+
export const ITEM_AUDIENCE = Object.freeze({
|
|
137
|
+
see: ['participant'],
|
|
138
|
+
act: ['item'],
|
|
139
|
+
});
|
|
140
|
+
/** A bare slash name — core's and its genres'. @experimental */
|
|
141
|
+
export const BARE_SLASH = /^[a-z][a-z0-9-]*$/;
|
|
142
|
+
/** A plugin's slash name is `<plugin>.<action>`; the plugin id is the spec's namespace. @experimental */
|
|
143
|
+
export const NAMESPACED_SLASH = /^([a-z0-9]+(?:[.-][a-z0-9]+)*)\.([a-z][a-z0-9-]*)$/;
|
|
144
|
+
/**
|
|
145
|
+
* Place actions into their venues for one channel — the placement rule every
|
|
146
|
+
* listing applies (F40; R-15 *quick*). `quick` → the primary set, else the
|
|
147
|
+
* overflow; a venue naming another channel's slug is skipped (a bare slug
|
|
148
|
+
* means every lane of it, 20 §7); a `form` venue is listed nowhere — the
|
|
149
|
+
* block alone reaches it (U5d review, S1).
|
|
150
|
+
*
|
|
151
|
+
* Availability is decided BEFORE this: the genre's verbs, the preset's
|
|
152
|
+
* included set and enabled-when say which actions a session offers, and the
|
|
153
|
+
* host's `listSessionActions` decorates each. Pass the offered set and every
|
|
154
|
+
* entry lands in each of its venues exactly once. Pure, so a host can build
|
|
155
|
+
* the conformance kit's `listActions` seam on it — the SDK's own host does
|
|
156
|
+
* — and the kit itself never calls it: C19 judges the listing the HOST
|
|
157
|
+
* returns, entry by entry, and a rule the kit applied for the host would be
|
|
158
|
+
* a rule it could not see the host break (U7 review, C1).
|
|
159
|
+
* @experimental
|
|
160
|
+
*/
|
|
161
|
+
export function placeActions(actions, channel = DEFAULT_CHANNEL) {
|
|
162
|
+
const listings = {};
|
|
163
|
+
for (const k of LISTED_VENUE_KINDS)
|
|
164
|
+
listings[k] = { primary: [], overflow: [] };
|
|
165
|
+
const slug = parseChannel(channel).slug;
|
|
166
|
+
for (const a of actions)
|
|
167
|
+
for (const v of a.venue) {
|
|
168
|
+
if (v.channel !== undefined && parseChannel(v.channel).slug !== slug)
|
|
169
|
+
continue;
|
|
170
|
+
const bucket = listings[v.kind];
|
|
171
|
+
if (!bucket)
|
|
172
|
+
continue;
|
|
173
|
+
(a.quick === true ? bucket.primary : bucket.overflow).push(a);
|
|
174
|
+
}
|
|
175
|
+
return listings;
|
|
176
|
+
}
|
|
177
|
+
/** The namespace of a spec id — `core:spec/narrate` → `core`, `acme:spec/roll` → `acme`. @experimental */
|
|
178
|
+
export function specNamespace(specId) {
|
|
179
|
+
const i = specId.indexOf(':');
|
|
180
|
+
return i === -1 ? '' : specId.slice(0, i);
|
|
181
|
+
}
|
|
182
|
+
/** Is this namespace core's — the one whose actions take bare slash names? @experimental */
|
|
183
|
+
export const isCoreNamespace = (ns) => ns === 'core';
|
|
184
|
+
/**
|
|
185
|
+
* The slash name an action is called by: the declared one, else derived from
|
|
186
|
+
* the key by the same rule a declared name must obey — `key` for core,
|
|
187
|
+
* `<plugin>.<key>` for a plugin. Always defined, so every composer action is
|
|
188
|
+
* reachable by `/` (F40) whether or not its author named one.
|
|
189
|
+
* @experimental
|
|
190
|
+
*/
|
|
191
|
+
export function slashNameOf(action, specId) {
|
|
192
|
+
if (action.slash)
|
|
193
|
+
return action.slash;
|
|
194
|
+
const ns = specNamespace(specId);
|
|
195
|
+
return isCoreNamespace(ns) || !ns ? action.key : `${ns}.${action.key}`;
|
|
196
|
+
}
|
|
197
|
+
const KEY = /^[a-z][a-z0-9-]*$/;
|
|
198
|
+
/** What a `world` action across the line is told to do instead — one fix for both halves of the declaration. */
|
|
199
|
+
const EFFECTS_LINE_FIX = `move the action to a venue on the owner's side of the line (${WORLD_ACTION_VENUES.join(', ')}) ` +
|
|
200
|
+
`and keep audience.act to ${WORLD_ACTION_ACTORS.join(' and/or ')} — or declare effects: 'fiction' ` +
|
|
201
|
+
`if its result stays inside the story`;
|
|
202
|
+
/**
|
|
203
|
+
* The effects line at a declaration (R-15 *The line*; F41): a `world` action
|
|
204
|
+
* is owner-only and never in a form, extra or widget venue. Judged one venue or one
|
|
205
|
+
* reference at a time, so the sentence names the venue or the reference
|
|
206
|
+
* that crossed.
|
|
207
|
+
*
|
|
208
|
+
* This is the declaration half of `effectsLineVerdict`'s judge
|
|
209
|
+
* (`messageBlocks.ts`), defined here because `actionFindingsByLaw` — the
|
|
210
|
+
* construction and `validate()` door — sits below that module in the
|
|
211
|
+
* import graph and must not import it. The verdict calls this for a
|
|
212
|
+
* `venue` or `actor` input; the door calls it directly and quotes it.
|
|
213
|
+
* @experimental
|
|
214
|
+
*/
|
|
215
|
+
export function worldActionCrossing(input) {
|
|
216
|
+
if (input.effects !== 'world')
|
|
217
|
+
return { ok: true };
|
|
218
|
+
if (input.kind === 'venue') {
|
|
219
|
+
const kind = input.venue;
|
|
220
|
+
if (typeof kind !== 'string' || WORLD_ACTION_VENUES.includes(kind))
|
|
221
|
+
return { ok: true };
|
|
222
|
+
return {
|
|
223
|
+
ok: false,
|
|
224
|
+
sentence: `${input.where}: a 'world' action may not appear in the '${kind}' venue — its result ` +
|
|
225
|
+
`reaches outside the fiction (cards, lore, settings, permissions), so it belongs ` +
|
|
226
|
+
`in ${WORLD_ACTION_VENUES.join(', ')} and never where a character could be asked ` +
|
|
227
|
+
`to answer it (the effects line, R-15)`,
|
|
228
|
+
fix: EFFECTS_LINE_FIX,
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
if (WORLD_ACTION_ACTORS.includes(String(input.ref)))
|
|
232
|
+
return { ok: true };
|
|
233
|
+
return {
|
|
234
|
+
ok: false,
|
|
235
|
+
sentence: `${input.where}: a 'world' action's audience.act names '${String(input.ref)}' — an ` +
|
|
236
|
+
`out-of-fiction effect is the owner's (or an administrator's) to invoke, ` +
|
|
237
|
+
`never a participant's or a character's (the effects line, R-15)`,
|
|
238
|
+
fix: EFFECTS_LINE_FIX,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Every fault in one `ActionDecl.collects` (lair pass R3), as sentences: an
|
|
243
|
+
* unknown key, a missing label, an `optional` text with no `ifEmpty`, a
|
|
244
|
+
* `min` below 1 or a `max` below `min`. `where` is the field's address
|
|
245
|
+
* (`contributes.actions[nudge].collects`).
|
|
246
|
+
* @experimental
|
|
247
|
+
*/
|
|
248
|
+
export function collectsFindings(raw, where) {
|
|
249
|
+
const out = [];
|
|
250
|
+
const unknownKeys = (o, known, at) => {
|
|
251
|
+
for (const k of Object.keys(o))
|
|
252
|
+
if (!known.includes(k))
|
|
253
|
+
out.push(`${at}: '${k}' is not something an action collects here — one of ${known.join(', ')}`);
|
|
254
|
+
};
|
|
255
|
+
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
256
|
+
return [`${where} is { text?, recipients? } — what the press asks for before it fires`];
|
|
257
|
+
const c = raw;
|
|
258
|
+
unknownKeys(c, COLLECTS_KEYS, where);
|
|
259
|
+
if (c.text !== undefined) {
|
|
260
|
+
const at = `${where}.text`;
|
|
261
|
+
const t = c.text;
|
|
262
|
+
if (!t || typeof t !== 'object' || Array.isArray(t))
|
|
263
|
+
out.push(`${at} is { need, label, placeholder?, ifEmpty? } — the text the modal asks for`);
|
|
264
|
+
else {
|
|
265
|
+
unknownKeys(t, COLLECTED_TEXT_KEYS, at);
|
|
266
|
+
if (!TEXT_NEEDS.includes(t.need))
|
|
267
|
+
out.push(`${at}.need is one of ${TEXT_NEEDS.join(', ')} — whether the press fires ` +
|
|
268
|
+
`without any text`);
|
|
269
|
+
out.push(...i18nFindings(t.label, `${at}.label`, { required: true }));
|
|
270
|
+
out.push(...i18nFindings(t.placeholder, `${at}.placeholder`));
|
|
271
|
+
if (t.need === 'optional' && t.ifEmpty === undefined)
|
|
272
|
+
out.push(`${at}.ifEmpty is required when need is 'optional' — one sentence saying what an ` +
|
|
273
|
+
`empty submit does ('The room decides.')`);
|
|
274
|
+
else
|
|
275
|
+
out.push(...i18nFindings(t.ifEmpty, `${at}.ifEmpty`));
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
if (c.recipients !== undefined) {
|
|
279
|
+
const at = `${where}.recipients`;
|
|
280
|
+
const r = c.recipients;
|
|
281
|
+
if (!r || typeof r !== 'object' || Array.isArray(r))
|
|
282
|
+
out.push(`${at} is { label, min?, max?, overwrites? } — the cast members the modal asks for`);
|
|
283
|
+
else {
|
|
284
|
+
unknownKeys(r, COLLECTED_RECIPIENTS_KEYS, at);
|
|
285
|
+
out.push(...i18nFindings(r.label, `${at}.label`, { required: true }));
|
|
286
|
+
const count = (v) => typeof v === 'number' && Number.isInteger(v);
|
|
287
|
+
if (r.min !== undefined && (!count(r.min) || r.min < 1))
|
|
288
|
+
out.push(`${at}.min is a whole number, 1 or more — the fewest who may be picked`);
|
|
289
|
+
if (r.max !== undefined) {
|
|
290
|
+
const min = count(r.min) ? r.min : 1;
|
|
291
|
+
if (!count(r.max) || r.max < min)
|
|
292
|
+
out.push(`${at}.max is a whole number no smaller than min (${min}) — the most who may be picked`);
|
|
293
|
+
}
|
|
294
|
+
if (r.overwrites !== undefined) {
|
|
295
|
+
try {
|
|
296
|
+
if (typeof r.overwrites !== 'string')
|
|
297
|
+
throw new Error('not a string');
|
|
298
|
+
assertSlotId(r.overwrites);
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
out.push(`${at}.overwrites is a slot id ('core:slot/whisper@1') — the per-cast slot the action ` +
|
|
302
|
+
`writes on each recipient`);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
if (c.text === undefined && c.recipients === undefined && !out.length)
|
|
308
|
+
out.push(`${where} collects nothing — declare text, recipients, or leave collects out`);
|
|
309
|
+
return out;
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Every fault in one action declaration, as sentences — the teaching-error
|
|
313
|
+
* pattern (15 §1.3). Empty when the declaration is sound.
|
|
314
|
+
*
|
|
315
|
+
* `specId` decides which slash grammar applies: a `core:` spec may not claim a
|
|
316
|
+
* dotted name and a plugin spec may not claim a bare one, or a name outside its
|
|
317
|
+
* own namespace. That rule is the whole collision guarantee.
|
|
318
|
+
* @experimental
|
|
319
|
+
*/
|
|
320
|
+
export function actionFindings(raw, specId, at = 'contributes.actions') {
|
|
321
|
+
return actionFindingsByLaw(raw, specId, at).map((f) => f.message);
|
|
322
|
+
}
|
|
323
|
+
/** `actionFindings`, each sentence with the law it comes from (`ActionFinding`). @experimental */
|
|
324
|
+
export function actionFindingsByLaw(raw, specId, at = 'contributes.actions') {
|
|
325
|
+
const out = [];
|
|
326
|
+
/** A fault in the declaration's shape (R-15). */
|
|
327
|
+
const shape = (...messages) => {
|
|
328
|
+
for (const message of messages)
|
|
329
|
+
out.push({ law: 'R-15', message });
|
|
330
|
+
};
|
|
331
|
+
/** A crossing of the effects line (F41) — the verdict's sentence and fix, quoted. */
|
|
332
|
+
const line = (heard) => {
|
|
333
|
+
if (!heard.ok)
|
|
334
|
+
out.push({ law: 'F41', message: i18nText(heard.sentence), fix: i18nText(heard.fix) });
|
|
335
|
+
};
|
|
336
|
+
if (!raw || typeof raw !== 'object')
|
|
337
|
+
return [{ law: 'R-15', message: `${at}: an action is an object — got ${typeof raw}` }];
|
|
338
|
+
const a = raw;
|
|
339
|
+
const where = `${at}[${typeof a.key === 'string' ? a.key : '?'}]`;
|
|
340
|
+
if (typeof a.key !== 'string' || !KEY.test(a.key))
|
|
341
|
+
shape(`${where}: 'key' is required — a lowercase kebab token (${KEY.source})`);
|
|
342
|
+
if (typeof a.genre !== 'string' || !a.genre)
|
|
343
|
+
shape(`${where}: 'genre' is required — the genre id this action is offered to (24 §3), ` +
|
|
344
|
+
`such as core:genre/chat`);
|
|
345
|
+
const venues = Array.isArray(a.venue) ? a.venue : a.venue === undefined ? [] : [a.venue];
|
|
346
|
+
if (!venues.length)
|
|
347
|
+
shape(`${where}: 'venue' is required — where the action appears (R-15)`);
|
|
348
|
+
for (const v of venues) {
|
|
349
|
+
if (!v || typeof v !== 'object') {
|
|
350
|
+
shape(`${where}: a venue is { kind, channel? } — got ${typeof v}`);
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
const kind = v.kind;
|
|
354
|
+
if (!VENUE_KINDS.includes(kind))
|
|
355
|
+
shape(`${where}: venue kind '${String(kind)}' is not one core offers — ` +
|
|
356
|
+
`one of ${VENUE_KINDS.join(', ')}`);
|
|
357
|
+
const channel = v.channel;
|
|
358
|
+
if (channel !== undefined && (typeof channel !== 'string' || !channel))
|
|
359
|
+
shape(`${where}: a venue's 'channel' is a channel slug`);
|
|
360
|
+
}
|
|
361
|
+
if (a.audience !== undefined) {
|
|
362
|
+
const aud = a.audience;
|
|
363
|
+
if (!aud || typeof aud !== 'object')
|
|
364
|
+
shape(`${where}: 'audience' is { see, act }`);
|
|
365
|
+
else
|
|
366
|
+
for (const half of ['see', 'act']) {
|
|
367
|
+
const refs = aud[half];
|
|
368
|
+
if (!Array.isArray(refs))
|
|
369
|
+
shape(`${where}: audience.${half} is a list of participant references`);
|
|
370
|
+
else
|
|
371
|
+
for (const r of refs)
|
|
372
|
+
if (!isParticipantRef(r))
|
|
373
|
+
shape(`${where}: audience.${half} names '${String(r)}', which is not a participant ` +
|
|
374
|
+
`reference — one of ${PARTICIPANT_ROLES.join(', ')}, or user:<id>, ` +
|
|
375
|
+
`character:<id>, envoy:<slug>`);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (a.quick !== undefined && typeof a.quick !== 'boolean')
|
|
379
|
+
shape(`${where}: 'quick' is a boolean — the one prominence flag`);
|
|
380
|
+
// What the press collects (lair pass R3): text and/or recipients, each
|
|
381
|
+
// labelled, in the collect modal. Any venue.
|
|
382
|
+
if (a.collects !== undefined)
|
|
383
|
+
shape(...collectsFindings(a.collects, `${where}.collects`));
|
|
384
|
+
// The effects line (R-15, F41): a `world` action is owner-only and never
|
|
385
|
+
// in a form, extra or widget venue (a row's ⋮ is the owner's, R11). Judged one declared venue and one `act` reference
|
|
386
|
+
// at a time by `worldActionCrossing` — the declaration half of
|
|
387
|
+
// `core:verdict/effects-line` — so the sentence names the venue or the
|
|
388
|
+
// reference that crossed it. An unknown `effects` value is the
|
|
389
|
+
// declaration's shape (R-15); a crossing is F41.
|
|
390
|
+
if (a.effects !== undefined && !ACTION_EFFECTS.includes(a.effects))
|
|
391
|
+
shape(`${where}: 'effects' is one of ${ACTION_EFFECTS.join(', ')} — what the result touches ` +
|
|
392
|
+
`(the effects line, R-15)`);
|
|
393
|
+
for (const v of venues)
|
|
394
|
+
line(worldActionCrossing({
|
|
395
|
+
kind: 'venue',
|
|
396
|
+
where,
|
|
397
|
+
effects: a.effects,
|
|
398
|
+
venue: v?.kind,
|
|
399
|
+
}));
|
|
400
|
+
const act = a.audience?.act;
|
|
401
|
+
if (Array.isArray(act))
|
|
402
|
+
for (const r of act)
|
|
403
|
+
line(worldActionCrossing({ kind: 'actor', where, effects: a.effects, ref: r }));
|
|
404
|
+
shape(...i18nFindings(a.label, `${where}.label`, { required: true }));
|
|
405
|
+
// The legend (2026-09-28): every action says what it does, so the
|
|
406
|
+
// session's legend and the control's tooltip always have a sentence.
|
|
407
|
+
if (a.description === undefined)
|
|
408
|
+
shape(`${where}: 'description' is required — one plain sentence saying what the action does, ` +
|
|
409
|
+
`shown in the session's action legend and as the control's tooltip ` +
|
|
410
|
+
`({ en: 'Roll the dice and post the result.' })`);
|
|
411
|
+
else
|
|
412
|
+
shape(...i18nFindings(a.description, `${where}.description`));
|
|
413
|
+
if (a.iconAlt !== undefined) {
|
|
414
|
+
shape(...i18nFindings(a.iconAlt, `${where}.iconAlt`));
|
|
415
|
+
if (a.icon === undefined)
|
|
416
|
+
shape(`${where}: 'iconAlt' needs an 'icon' — it is what the icon says when it stands alone; ` +
|
|
417
|
+
`drop it, or declare the icon`);
|
|
418
|
+
}
|
|
419
|
+
if (a.slash !== undefined) {
|
|
420
|
+
if (typeof a.slash !== 'string')
|
|
421
|
+
shape(`${where}: 'slash' is a string`);
|
|
422
|
+
else
|
|
423
|
+
shape(...slashFindings(a.slash, specId, where));
|
|
424
|
+
}
|
|
425
|
+
// The action's envoy (R-18): the same declaration a genre's carries, with
|
|
426
|
+
// one rule of its own — `on-action` only. Judged as an action's, so a
|
|
427
|
+
// `speaks: 'in-turn'` is a sentence here rather than a silent overwrite.
|
|
428
|
+
if (a.envoy !== undefined)
|
|
429
|
+
shape(...envoyFindings(a.envoy, `${where}.envoy`, 'action'));
|
|
430
|
+
// Enabled-when (R-15, U5e): the junction rule over published values —
|
|
431
|
+
// a path that is not a port reference, exactly one condition, a reason.
|
|
432
|
+
shape(...enabledWhenFindings(a.enabledWhen, `${where}.enabledWhen`));
|
|
433
|
+
// An `item.*` predicate is answered by the message a press is on: an
|
|
434
|
+
// action with no venue that has one would be judged against nothing.
|
|
435
|
+
const onMessage = venues.some((v) => {
|
|
436
|
+
const kind = v?.kind;
|
|
437
|
+
return kind === 'message' || kind === 'form';
|
|
438
|
+
});
|
|
439
|
+
if (!onMessage)
|
|
440
|
+
normalizeEnabledWhen(a.enabledWhen).forEach((p, i) => {
|
|
441
|
+
if (p.on === 'item' || p.on.startsWith('item.'))
|
|
442
|
+
shape(`${where}.enabledWhen[${i}]: reads '${p.on}', which only a press on a message can ` +
|
|
443
|
+
`answer — add a { kind: 'message' } venue, or read a session value ` +
|
|
444
|
+
`('state.world.…', 'session.generating') instead`);
|
|
445
|
+
});
|
|
446
|
+
// Present-when (W-GATE D3): the same grammar, and never `item.*` — a
|
|
447
|
+
// hidden action is hidden from a listing, which has no row to read.
|
|
448
|
+
shape(...enabledWhenFindings(a.presentWhen, `${where}.presentWhen`));
|
|
449
|
+
normalizeEnabledWhen(a.presentWhen).forEach((p, i) => {
|
|
450
|
+
if (p.on === 'item' || p.on.startsWith('item.'))
|
|
451
|
+
shape(`${where}.presentWhen[${i}]: reads '${p.on}' — whether an action is present is ` +
|
|
452
|
+
`decided for a listing, which has no message to read; read a session value ` +
|
|
453
|
+
`('state.world.…', 'session.openForm.action') instead, or grey it per row with ` +
|
|
454
|
+
`enabledWhen`);
|
|
455
|
+
});
|
|
456
|
+
return out;
|
|
457
|
+
}
|
|
458
|
+
/** The slash-name grammar, applied to one name for one spec. @experimental */
|
|
459
|
+
export function slashFindings(slash, specId, where = 'slash') {
|
|
460
|
+
const ns = specNamespace(specId);
|
|
461
|
+
if (isCoreNamespace(ns)) {
|
|
462
|
+
if (BARE_SLASH.test(slash))
|
|
463
|
+
return [];
|
|
464
|
+
return [
|
|
465
|
+
NAMESPACED_SLASH.test(slash)
|
|
466
|
+
? `${where}: a core spec may not claim the namespaced slash name '/${slash}' — ` +
|
|
467
|
+
`core's actions take bare names (/${slash.slice(slash.lastIndexOf('.') + 1)})`
|
|
468
|
+
: `${where}: '/${slash}' is not a slash name — lowercase, digits and hyphens, ` +
|
|
469
|
+
`starting with a letter`,
|
|
470
|
+
];
|
|
471
|
+
}
|
|
472
|
+
const m = NAMESPACED_SLASH.exec(slash);
|
|
473
|
+
if (!m)
|
|
474
|
+
return [
|
|
475
|
+
BARE_SLASH.test(slash)
|
|
476
|
+
? `${where}: a plugin spec may not claim the bare slash name '/${slash}' — ` +
|
|
477
|
+
`third-party actions are '/<plugin>.<action>' (/${ns}.${slash}), so a ` +
|
|
478
|
+
`collision with core's is impossible`
|
|
479
|
+
: `${where}: '/${slash}' is not a slash name — '<plugin>.<action>', lowercase, ` +
|
|
480
|
+
`digits and hyphens`,
|
|
481
|
+
];
|
|
482
|
+
if (m[1] !== ns)
|
|
483
|
+
return [
|
|
484
|
+
`${where}: '/${slash}' claims the namespace '${m[1]}' — a spec under '${ns}' ` +
|
|
485
|
+
`names its actions '/${ns}.<action>'`,
|
|
486
|
+
];
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* The document form of one declaration: `venue` as a list. Returns a copy.
|
|
491
|
+
* @experimental
|
|
492
|
+
*/
|
|
493
|
+
export function normalizeAction(raw) {
|
|
494
|
+
const a = { ...raw };
|
|
495
|
+
if (a.venue && !Array.isArray(a.venue))
|
|
496
|
+
a.venue = [a.venue];
|
|
497
|
+
else if (!Array.isArray(a.venue))
|
|
498
|
+
a.venue = [];
|
|
499
|
+
// An action's envoy is `on-action` by construction (R-21 (6)): the
|
|
500
|
+
// document form always says so, whether or not the author did.
|
|
501
|
+
if (a.envoy && typeof a.envoy === 'object')
|
|
502
|
+
a.envoy = { ...a.envoy, speaks: 'on-action' };
|
|
503
|
+
// Enabled-when in its list form (U5e), `reason` a locale map. Only when
|
|
504
|
+
// it is a predicate or a list of them: anything else is left as written
|
|
505
|
+
// for `actionFindings` to name.
|
|
506
|
+
if (a.enabledWhen !== undefined && a.enabledWhen !== null) {
|
|
507
|
+
const list = Array.isArray(a.enabledWhen) ? a.enabledWhen : [a.enabledWhen];
|
|
508
|
+
if (list.every(isEnabledWhenShaped))
|
|
509
|
+
a.enabledWhen = normalizeEnabledWhen(a.enabledWhen);
|
|
510
|
+
}
|
|
511
|
+
if (a.presentWhen !== undefined && a.presentWhen !== null) {
|
|
512
|
+
const list = Array.isArray(a.presentWhen) ? a.presentWhen : [a.presentWhen];
|
|
513
|
+
if (list.every(isEnabledWhenShaped))
|
|
514
|
+
a.presentWhen = normalizeEnabledWhen(a.presentWhen);
|
|
515
|
+
}
|
|
516
|
+
return a;
|
|
517
|
+
}
|
|
518
|
+
/**
|
|
519
|
+
* `contributes` after normalisation: every action in its document form.
|
|
520
|
+
* @experimental
|
|
521
|
+
*/
|
|
522
|
+
export function normalizeContributes(contributes) {
|
|
523
|
+
if (!contributes)
|
|
524
|
+
return contributes;
|
|
525
|
+
const { actions, ...rest } = contributes;
|
|
526
|
+
if (!actions?.length)
|
|
527
|
+
return rest;
|
|
528
|
+
return { ...rest, actions: actions.map(normalizeAction) };
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Every action a document contributes, normalised, with the spec id each
|
|
532
|
+
* came from. The one reader hosts use.
|
|
533
|
+
* @experimental
|
|
534
|
+
*/
|
|
535
|
+
export function actionsOf(doc) {
|
|
536
|
+
const c = doc.contributes;
|
|
537
|
+
const normalized = normalizeContributes(c);
|
|
538
|
+
return (normalized?.actions ?? []).map((a) => ({ ...a, specId: doc.id }));
|
|
539
|
+
}
|
|
540
|
+
// The identity grammar lives in `identity.ts` (a leaf, so `genres.ts` can
|
|
541
|
+
// hold a default's key to it without a cycle); re-exported here where every
|
|
542
|
+
// reader of it has always found it.
|
|
543
|
+
export { ACTION_IDENTITY, ACTION_IDENTITY_MAX_LENGTH, CORE_ACTION_SPEC_ID, actionIdentity, isActionIdentity, parseActionIdentity, } from './identity.js';
|
|
544
|
+
/**
|
|
545
|
+
* A slash collision: two actions offered to one genre under one name. One
|
|
546
|
+
* slash name means one action (plans/31 V2, ruled 2026-09-17): since the
|
|
547
|
+
* identity `<spec>#<key>` is the only routing key, two specs claiming one
|
|
548
|
+
* name are two actions a palette could not tell apart — a collision, not
|
|
549
|
+
* alternatives. (Until V2 two specs sharing a *function* under one name were
|
|
550
|
+
* alternatives a binding selected among; the function is gone, and so is the
|
|
551
|
+
* exemption.) A plugin's names are namespaced (`acme.roll`), so a plugin
|
|
552
|
+
* declaring the same `key` as a core verb is a different identity under a
|
|
553
|
+
* different name, and never shadows it.
|
|
554
|
+
*
|
|
555
|
+
* Core's verbs hold their names first (U5c review, S1): every genre the list
|
|
556
|
+
* touches is seeded with `CORE_ACTIONS` under `core`, so a core spec claiming
|
|
557
|
+
* `/retry` collides with the verb rather than shadowing it in the palette. (A
|
|
558
|
+
* plugin spec cannot claim a bare name at all — that is the grammar's job.)
|
|
559
|
+
*
|
|
560
|
+
* `slashCollisions` is the whole rule; `validate()` applies it inside one
|
|
561
|
+
* document, `announce.build()` inside one package, and the host across every
|
|
562
|
+
* published spec of an install (a boot-time refusal).
|
|
563
|
+
* @experimental
|
|
564
|
+
*/
|
|
565
|
+
export function slashCollisions(actions) {
|
|
566
|
+
const seen = new Map();
|
|
567
|
+
const out = [];
|
|
568
|
+
for (const genre of new Set(actions.map((a) => a.genre ?? '')))
|
|
569
|
+
for (const c of CORE_ACTIONS) {
|
|
570
|
+
const slash = slashNameOf(c, CORE_ACTION_SPEC_ID);
|
|
571
|
+
seen.set(`${genre}#${slash}`, {
|
|
572
|
+
identity: `${CORE_ACTION_SPEC_ID}#${c.key}`,
|
|
573
|
+
specId: CORE_ACTION_SPEC_ID,
|
|
574
|
+
key: c.key,
|
|
575
|
+
slash,
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
for (const a of actions) {
|
|
579
|
+
const slash = slashNameOf(a, a.specId);
|
|
580
|
+
const identity = `${a.specId}#${a.key}`;
|
|
581
|
+
const key = `${a.genre ?? ''}#${slash}`;
|
|
582
|
+
const prior = seen.get(key);
|
|
583
|
+
if (!prior) {
|
|
584
|
+
seen.set(key, { identity, specId: a.specId, key: a.key, slash });
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
// The same declaration met twice (a document listed on two roads) is
|
|
588
|
+
// one action, not two.
|
|
589
|
+
if (prior.identity === identity)
|
|
590
|
+
continue;
|
|
591
|
+
out.push(`'/${slash}' is claimed twice for genre '${a.genre ?? '(none)'}': by '${prior.specId}' ` +
|
|
592
|
+
`for '${prior.key}' and by '${a.specId}' for '${a.key}' — one slash name ` +
|
|
593
|
+
`means one action; rename one of them`);
|
|
594
|
+
}
|
|
595
|
+
return out;
|
|
596
|
+
}
|
|
597
|
+
/** Every finding on one document's contributed actions, sentences only. @internal */
|
|
598
|
+
export function actionDocumentFindings(doc) {
|
|
599
|
+
return actionDocumentFindingsByLaw(doc).map((f) => f.message);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* `actionDocumentFindings` with the law each sentence comes from — what
|
|
603
|
+
* `validate()` labels its findings by. A slash collision is R-15's.
|
|
604
|
+
* @experimental
|
|
605
|
+
*/
|
|
606
|
+
export function actionDocumentFindingsByLaw(doc) {
|
|
607
|
+
const c = doc.contributes;
|
|
608
|
+
if (!c)
|
|
609
|
+
return [];
|
|
610
|
+
const out = [];
|
|
611
|
+
for (const entry of c.actions ?? []) {
|
|
612
|
+
const a = normalizeAction(entry);
|
|
613
|
+
out.push(...actionFindingsByLaw(a, doc.id));
|
|
614
|
+
}
|
|
615
|
+
if (out.length)
|
|
616
|
+
return out;
|
|
617
|
+
return slashCollisions(actionsOf(doc)).map((message) => ({ law: 'R-15', message }));
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* The sentences beside a grey core verb, as locale maps — the `reason` of
|
|
621
|
+
* each verb's enabled-when below (U5e). One vocabulary: the host's chips,
|
|
622
|
+
* menus and palette read these through the verdict, and a refusal at the
|
|
623
|
+
* door says the same words. The two conditions that are NOT published
|
|
624
|
+
* values — an edit in progress, the audience — keep their sentences on the
|
|
625
|
+
* client (`messageVerbState.ts`).
|
|
626
|
+
* @internal
|
|
627
|
+
*/
|
|
628
|
+
export const CORE_VERB_REASONS = Object.freeze({
|
|
629
|
+
generating: { en: 'wait for the reply to finish' },
|
|
630
|
+
hidden: { en: 'unhide it first' },
|
|
631
|
+
notNewest: { en: 'only the newest reply can be regenerated' },
|
|
632
|
+
noSwipe: { en: 'nothing to swipe to' },
|
|
633
|
+
greeting: { en: 'a greeting is swiped, not regenerated' },
|
|
634
|
+
ownLine: { en: 'your own line is edited, not regenerated' },
|
|
635
|
+
nobodySeated: { en: 'nobody is seated to pick' },
|
|
636
|
+
});
|
|
637
|
+
/** Nothing in the session is generating — the busy rule every verb but stop shares. */
|
|
638
|
+
const NOT_GENERATING = {
|
|
639
|
+
on: 'session.generating',
|
|
640
|
+
equals: false,
|
|
641
|
+
reason: CORE_VERB_REASONS.generating,
|
|
642
|
+
};
|
|
643
|
+
/** The row is the newest on its channel — retry, extend and swipe act on the newest reply only. */
|
|
644
|
+
const NEWEST = { on: 'item.isNewest', truthy: true, reason: CORE_VERB_REASONS.notNewest };
|
|
645
|
+
/**
|
|
646
|
+
* The row is a reply — retry, extend and swipe write a reply over the row,
|
|
647
|
+
* so on the author's own line (`role: 'user'`) they would overwrite what the
|
|
648
|
+
* author wrote with the narrator's prose (F1, every persona-less genre). Keyed
|
|
649
|
+
* on the role, never on a persona: a persona-less author line has none.
|
|
650
|
+
*/
|
|
651
|
+
const REPLY = { on: 'item.role', equals: 'assistant', reason: CORE_VERB_REASONS.ownLine };
|
|
652
|
+
/** @internal */
|
|
653
|
+
export const CORE_ACTIONS = Object.freeze([
|
|
654
|
+
{
|
|
655
|
+
key: 'stop',
|
|
656
|
+
venue: [{ kind: 'message' }],
|
|
657
|
+
audience: { see: ['participant'], act: ['participant'] },
|
|
658
|
+
quick: true,
|
|
659
|
+
label: { en: 'Stop generating' },
|
|
660
|
+
description: { en: 'Stop the reply being written now; what it wrote so far is kept.' },
|
|
661
|
+
icon: 'square',
|
|
662
|
+
floor: true,
|
|
663
|
+
},
|
|
664
|
+
{
|
|
665
|
+
key: 'edit',
|
|
666
|
+
venue: [{ kind: 'message' }],
|
|
667
|
+
audience: ITEM_AUDIENCE,
|
|
668
|
+
quick: true,
|
|
669
|
+
label: { en: 'Edit' },
|
|
670
|
+
description: { en: 'Change the text of this message.' },
|
|
671
|
+
icon: 'pencil',
|
|
672
|
+
enabledWhen: [
|
|
673
|
+
{ on: 'item.hidden', equals: false, reason: CORE_VERB_REASONS.hidden },
|
|
674
|
+
NOT_GENERATING,
|
|
675
|
+
],
|
|
676
|
+
floor: true,
|
|
677
|
+
},
|
|
678
|
+
{
|
|
679
|
+
key: 'branch',
|
|
680
|
+
venue: [{ kind: 'message' }],
|
|
681
|
+
audience: { see: ['participant'], act: ['owner'] },
|
|
682
|
+
label: { en: 'Branch from here' },
|
|
683
|
+
description: { en: 'Start a copy of the session from this message, leaving this one as it is.' },
|
|
684
|
+
icon: 'git-branch',
|
|
685
|
+
enabledWhen: [NOT_GENERATING],
|
|
686
|
+
floor: true,
|
|
687
|
+
},
|
|
688
|
+
{
|
|
689
|
+
key: 'retry',
|
|
690
|
+
venue: [{ kind: 'message' }, { kind: 'extra' }],
|
|
691
|
+
audience: ITEM_AUDIENCE,
|
|
692
|
+
quick: true,
|
|
693
|
+
slash: 'retry',
|
|
694
|
+
label: { en: 'Regenerate' },
|
|
695
|
+
description: { en: 'Write the newest reply again, in place of the one there.' },
|
|
696
|
+
icon: 'refresh-cw',
|
|
697
|
+
enabledWhen: [
|
|
698
|
+
NEWEST,
|
|
699
|
+
REPLY,
|
|
700
|
+
{ on: 'item.greeting', equals: false, reason: CORE_VERB_REASONS.greeting },
|
|
701
|
+
{ on: 'item.hidden', equals: false, reason: CORE_VERB_REASONS.hidden },
|
|
702
|
+
NOT_GENERATING,
|
|
703
|
+
],
|
|
704
|
+
floor: false,
|
|
705
|
+
},
|
|
706
|
+
{
|
|
707
|
+
// The prefill extend: carry this reply on (ruling 2026-09-08; renamed
|
|
708
|
+
// from `continue` 2026-09-28). A message verb only — the composer's
|
|
709
|
+
// Continue is `advance` below.
|
|
710
|
+
key: 'extend',
|
|
711
|
+
venue: [{ kind: 'message' }],
|
|
712
|
+
audience: ITEM_AUDIENCE,
|
|
713
|
+
label: { en: 'Extend' },
|
|
714
|
+
description: { en: 'Carry on writing this reply from where it stopped.' },
|
|
715
|
+
icon: 'arrow-down',
|
|
716
|
+
enabledWhen: [NEWEST, REPLY, NOT_GENERATING],
|
|
717
|
+
floor: false,
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
// The composer's Continue (lair pass B7): fire the turn order's head.
|
|
721
|
+
// A turn control, not a message verb — no row, so no `item.*`
|
|
722
|
+
// predicate; who may fire which entry is the fire's own rule.
|
|
723
|
+
key: 'advance',
|
|
724
|
+
venue: [{ kind: 'extra' }],
|
|
725
|
+
audience: { see: ['participant'], act: ['participant'] },
|
|
726
|
+
slash: 'advance',
|
|
727
|
+
label: { en: 'Continue' },
|
|
728
|
+
description: { en: 'Let whoever is next in the turn order speak.' },
|
|
729
|
+
icon: 'message-square-more',
|
|
730
|
+
enabledWhen: [NOT_GENERATING],
|
|
731
|
+
floor: false,
|
|
732
|
+
},
|
|
733
|
+
{
|
|
734
|
+
// Pick who speaks (lair pass B8): fire a character the person names.
|
|
735
|
+
// A turn control — present where the genre's `turnControls.pick`
|
|
736
|
+
// says it applies; greyed here while busy or with nobody to pick.
|
|
737
|
+
key: 'pick',
|
|
738
|
+
venue: [{ kind: 'extra' }],
|
|
739
|
+
audience: { see: ['participant'], act: ['participant'] },
|
|
740
|
+
// Not `/pick`: too plain a word to take from every plugin's palette.
|
|
741
|
+
slash: 'pick-speaker',
|
|
742
|
+
label: { en: 'Pick who speaks' },
|
|
743
|
+
description: { en: 'Choose which character speaks next.' },
|
|
744
|
+
icon: 'message-square-plus',
|
|
745
|
+
enabledWhen: [
|
|
746
|
+
NOT_GENERATING,
|
|
747
|
+
{ on: 'state.who.active', truthy: true, reason: CORE_VERB_REASONS.nobodySeated },
|
|
748
|
+
],
|
|
749
|
+
floor: false,
|
|
750
|
+
},
|
|
751
|
+
{
|
|
752
|
+
// The genre's own voice narrates (lair pass B8, D3; R8): fire it with
|
|
753
|
+
// no new direction — Adventure's narrator, the Lair's Castellan (the
|
|
754
|
+
// host stamps the fire `via: 'narrate'`). Opt-in — only a `voice:
|
|
755
|
+
// 'narrator'` genre has one (`turnControls.narrate`). The owner's, as
|
|
756
|
+
// a pick out of order is.
|
|
757
|
+
key: 'narrate',
|
|
758
|
+
venue: [{ kind: 'extra' }],
|
|
759
|
+
audience: { see: ['participant'], act: ['owner'] },
|
|
760
|
+
// Not `/narrate`: Chat's narrate spec claims that name, and one
|
|
761
|
+
// slash name means one action (`slashCollisions`).
|
|
762
|
+
slash: 'narrator',
|
|
763
|
+
label: { en: 'Narrate' },
|
|
764
|
+
// Voice-neutral (lair pass R8, 2026-09-28): whose voice narrates is
|
|
765
|
+
// the genre's — Adventure's narrator, the Lair's Castellan.
|
|
766
|
+
description: { en: 'Describe what happens next, with no new direction.' },
|
|
767
|
+
icon: 'cloud-sun',
|
|
768
|
+
enabledWhen: [NOT_GENERATING],
|
|
769
|
+
floor: false,
|
|
770
|
+
},
|
|
771
|
+
{
|
|
772
|
+
// Regenerate the last turn, as a whole (lair pass R2, owner
|
|
773
|
+
// 2026-09-28): delete the newest turn's yield — every row its run
|
|
774
|
+
// created, on every channel, never a person's own line — and take
|
|
775
|
+
// the same turn again. Opt-in (`turnControls.retake`), for a genre
|
|
776
|
+
// whose turn writes more than one row; where it is offered, `retry`
|
|
777
|
+
// leaves the extra venue so one genre never shows two _Regenerate_
|
|
778
|
+
// chips. The owner's: it deletes what everybody at the table saw.
|
|
779
|
+
key: 'retake',
|
|
780
|
+
venue: [{ kind: 'extra' }],
|
|
781
|
+
audience: { see: ['participant'], act: ['owner'] },
|
|
782
|
+
slash: 'retake',
|
|
783
|
+
label: { en: 'Regenerate' },
|
|
784
|
+
description: {
|
|
785
|
+
en: "Delete the last turn's messages and take the same turn again. Your own lines stay.",
|
|
786
|
+
},
|
|
787
|
+
icon: 'refresh-cw',
|
|
788
|
+
enabledWhen: [NOT_GENERATING],
|
|
789
|
+
floor: false,
|
|
790
|
+
},
|
|
791
|
+
{
|
|
792
|
+
key: 'swipe',
|
|
793
|
+
venue: [{ kind: 'message' }],
|
|
794
|
+
audience: ITEM_AUDIENCE,
|
|
795
|
+
label: { en: 'Swipe' },
|
|
796
|
+
description: { en: 'Step between the other versions of this reply.' },
|
|
797
|
+
icon: 'chevrons-left-right',
|
|
798
|
+
enabledWhen: [
|
|
799
|
+
NEWEST,
|
|
800
|
+
REPLY,
|
|
801
|
+
{ on: 'item.hasSwipes', truthy: true, reason: CORE_VERB_REASONS.noSwipe },
|
|
802
|
+
NOT_GENERATING,
|
|
803
|
+
],
|
|
804
|
+
floor: false,
|
|
805
|
+
},
|
|
806
|
+
{
|
|
807
|
+
key: 'hide',
|
|
808
|
+
venue: [{ kind: 'message' }],
|
|
809
|
+
audience: ITEM_AUDIENCE,
|
|
810
|
+
label: { en: 'Hide' },
|
|
811
|
+
description: { en: 'Leave this message out of what the characters remember; it stays on the page.' },
|
|
812
|
+
icon: 'ghost',
|
|
813
|
+
enabledWhen: [NOT_GENERATING],
|
|
814
|
+
floor: false,
|
|
815
|
+
},
|
|
816
|
+
{
|
|
817
|
+
key: 'delete',
|
|
818
|
+
venue: [{ kind: 'message' }],
|
|
819
|
+
audience: ITEM_AUDIENCE,
|
|
820
|
+
label: { en: 'Delete' },
|
|
821
|
+
description: { en: 'Remove this message from the session.' },
|
|
822
|
+
icon: 'trash-2',
|
|
823
|
+
enabledWhen: [NOT_GENERATING],
|
|
824
|
+
floor: false,
|
|
825
|
+
},
|
|
826
|
+
]);
|
|
827
|
+
/** The core action a verb is, or undefined for a verb core does not describe. @internal */
|
|
828
|
+
export const coreAction = (key) => CORE_ACTIONS.find((a) => a.key === key);
|
|
829
|
+
//# sourceMappingURL=actions.js.map
|