@quixotic_mnemonics/swastik 0.0.0-stage → 0.1.0
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/_template/README.md +34 -0
- package/_template/assets/.gitkeep +1 -0
- package/_template/commands/.gitkeep +1 -0
- package/_template/config/.gitkeep +1 -0
- package/_template/events/.gitkeep +1 -0
- package/_template/jobs/.gitkeep +1 -0
- package/_template/locales/.gitkeep +1 -0
- package/_template/manifest.ts +13 -0
- package/_template/migrations/.gitkeep +1 -0
- package/_template/repositories/.gitkeep +1 -0
- package/_template/services/.gitkeep +1 -0
- package/_template/tests/.gitkeep +1 -0
- package/_template/ui/.gitkeep +1 -0
- package/dist/capabilities.d.ts +110 -0
- package/dist/capabilities.js +107 -0
- package/dist/commands.d.ts +157 -0
- package/dist/commands.js +9 -0
- package/dist/components-v2.d.ts +252 -0
- package/dist/components-v2.js +263 -0
- package/dist/components.d.ts +142 -0
- package/dist/components.js +11 -0
- package/dist/context.d.ts +59 -0
- package/dist/context.js +29 -0
- package/dist/entrypoints/admin.d.ts +26 -0
- package/dist/entrypoints/admin.js +2 -0
- package/dist/entrypoints/core.d.ts +31 -0
- package/dist/entrypoints/core.js +2 -0
- package/dist/entrypoints/marketplace.d.ts +30 -0
- package/dist/entrypoints/marketplace.js +2 -0
- package/dist/entrypoints/standard.d.ts +36 -0
- package/dist/entrypoints/standard.js +2 -0
- package/dist/events.d.ts +15 -0
- package/dist/events.js +19 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +21 -0
- package/dist/manifest-schema.d.ts +261 -0
- package/dist/manifest-schema.js +297 -0
- package/dist/manifest.d.ts +47 -0
- package/dist/manifest.js +6 -0
- package/dist/pages.d.ts +274 -0
- package/dist/pages.js +3 -0
- package/dist/paging.d.ts +32 -0
- package/dist/paging.js +59 -0
- package/dist/permits.d.ts +222 -0
- package/dist/permits.js +16 -0
- package/dist/validate.d.ts +21 -0
- package/dist/validate.js +33 -0
- package/package.json +78 -4
- package/src/capabilities.ts +196 -0
- package/src/commands.ts +181 -0
- package/src/components-v2.ts +533 -0
- package/src/components.ts +162 -0
- package/src/context.ts +83 -0
- package/src/entrypoints/admin.ts +36 -0
- package/src/entrypoints/core.ts +41 -0
- package/src/entrypoints/marketplace.ts +38 -0
- package/src/entrypoints/standard.ts +44 -0
- package/src/events.ts +34 -0
- package/src/index.ts +159 -0
- package/src/manifest-schema.ts +340 -0
- package/src/manifest.ts +68 -0
- package/src/pages.ts +282 -0
- package/src/paging.ts +72 -0
- package/src/permits.ts +250 -0
- package/src/validate.ts +42 -0
- package/README.md +0 -3
package/src/pages.ts
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UR-20261027-106 — a module OWNS its page.
|
|
3
|
+
*
|
|
4
|
+
* The doctrine says a module is a self-contained vertical slice owning commands, events, services,
|
|
5
|
+
* data and config. The tree did the opposite: every module declared a command that returned
|
|
6
|
+
* `{ page, data }` and the host built the page in `apps/main/src/rendering/page-data.ts`. That file is
|
|
7
|
+
* a core-base file serving seven modules, which makes "core module" a manifest label rather than a
|
|
8
|
+
* code boundary.
|
|
9
|
+
*
|
|
10
|
+
* This is the contract that lets a module build its own page without importing the core base:
|
|
11
|
+
*
|
|
12
|
+
* - the module declares the page and owns its composition (labels, sections, ordering);
|
|
13
|
+
* - the framework supplies the DATA through typed capability calls (operator decision, 2026-10-27):
|
|
14
|
+
* the module calls `read.installState(guildId)` and owns the page; the framework owns the query.
|
|
15
|
+
* A raw SQL handle was rejected — under the doctrine a module owns its own tables, and a
|
|
16
|
+
* framework read-model is the honest shape for a read that spans what the framework records.
|
|
17
|
+
*
|
|
18
|
+
* A page declared here wins over the host's built-in page of the same id, so a module can take over
|
|
19
|
+
* its own surface without the host changing.
|
|
20
|
+
*/
|
|
21
|
+
export interface ModulePageContext {
|
|
22
|
+
/** The guild the page is being rendered for; null in a DM. */
|
|
23
|
+
readonly guildId: string | null;
|
|
24
|
+
/** The Discord application answering — the main profile's, or a persona's. */
|
|
25
|
+
readonly applicationId: string;
|
|
26
|
+
/** `'main'`, or the persona's id. */
|
|
27
|
+
readonly profileId: string;
|
|
28
|
+
/** 1-based page index within the module's own pager. */
|
|
29
|
+
readonly page: number;
|
|
30
|
+
/** The member who invoked the surface — a module binding its own control ids needs it. */
|
|
31
|
+
readonly invokerId: string;
|
|
32
|
+
/** The member's search text, when the surface has one — /browse's Discover query. */
|
|
33
|
+
readonly query?: string;
|
|
34
|
+
/**
|
|
35
|
+
* UR-20261029-113 — resolve an emoji NAME to the reference the rendering application owns, or
|
|
36
|
+
* `undefined` when that application has not uploaded it (the caller falls back to its own glyph).
|
|
37
|
+
*
|
|
38
|
+
* A module composes its own blocks, so it needs the marks it puts in them. Without this it would
|
|
39
|
+
* have to import the framework's emoji table — which is how a module's schema ended up living in the
|
|
40
|
+
* host in the first place. The module names the emoji; the framework owns the id.
|
|
41
|
+
*/
|
|
42
|
+
readonly emoji: (name: string) => string | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* UR-20261029-116 — whether the member who invoked the command administers this guild.
|
|
45
|
+
*
|
|
46
|
+
* A page that offers a control only an admin may use must know this, and the module cannot ask
|
|
47
|
+
* Discord. Without it the /persona setup control had to be assembled by the router, which is how
|
|
48
|
+
* that page's whole schema ended up in the framework.
|
|
49
|
+
*/
|
|
50
|
+
readonly isAdmin: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* The same emoji as PARTS, for a component that needs the object rather than the inline ref — a
|
|
53
|
+
* button's icon is `{ id, name }`, not `<:name:id>`. Both shapes are honest needs, so both are here
|
|
54
|
+
* rather than one being reconstructed from the other by string surgery in every module.
|
|
55
|
+
*/
|
|
56
|
+
readonly emojiParts: (name: string) => { readonly id: string; readonly name: string } | undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** A module as the read-model reports it — manifest facts only, no database row. */
|
|
60
|
+
export interface ModuleSummary {
|
|
61
|
+
readonly slug: string;
|
|
62
|
+
readonly tier: string;
|
|
63
|
+
readonly description: string;
|
|
64
|
+
readonly displayName?: string;
|
|
65
|
+
readonly iconName?: string;
|
|
66
|
+
readonly accent?: string;
|
|
67
|
+
readonly commands: readonly {
|
|
68
|
+
readonly name: string;
|
|
69
|
+
readonly description: string;
|
|
70
|
+
}[]; /** The developer who published it — what the Discover search matches on. */
|
|
71
|
+
readonly devId?: string;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The typed read-model the framework provides. It carries no handle and no table name: a module asks
|
|
76
|
+
* for the fact it needs, and the framework decides how to answer it. Every method is scoped to the
|
|
77
|
+
* guild and profile the page is being rendered for, so a module cannot read another guild's state by
|
|
78
|
+
* passing a different id.
|
|
79
|
+
*/
|
|
80
|
+
export interface ModulePageReadModel {
|
|
81
|
+
/** Every module the framework knows, in load order. */
|
|
82
|
+
list(): Promise<readonly ModuleSummary[]>;
|
|
83
|
+
/** Is this module enabled in the page's guild? Core and admin always are. */
|
|
84
|
+
installState(slug: string): Promise<boolean>;
|
|
85
|
+
/** When this module was installed in the page's guild, as epoch ms; `undefined` when it has no row. */
|
|
86
|
+
installedAt(slug: string): Promise<number | undefined>;
|
|
87
|
+
/** Does the page's profile hold this module in this guild? */
|
|
88
|
+
ownedByCaller(slug: string): Promise<boolean>;
|
|
89
|
+
/** The command names this guild actually resolves to, keyed by the declared name. */
|
|
90
|
+
commandNames(): Promise<ReadonlyMap<string, string>>;
|
|
91
|
+
/** The per-guild status of a declared command name. */
|
|
92
|
+
commandStatus(name: string): Promise<'enabled' | 'disabled'>;
|
|
93
|
+
/** The emoji name a module page uses as its command marker. */
|
|
94
|
+
markerIcon(): Promise<string>;
|
|
95
|
+
/**
|
|
96
|
+
* The rendered reference for a declared `ui.icon`, as the application serving this page owns it —
|
|
97
|
+
* `<:name:id>` — or the declared name itself when the application has not uploaded that emoji.
|
|
98
|
+
*
|
|
99
|
+
* A module names the icon; the framework resolves it. The emoji registry, the upload lifecycle and
|
|
100
|
+
* the per-application ownership of an emoji all stay behind this call, which is why a page can
|
|
101
|
+
* render an icon without touching the core base.
|
|
102
|
+
*/
|
|
103
|
+
moduleIcon(iconName: string | undefined): Promise<string>;
|
|
104
|
+
/** Reachability of the two shared subsystems, as the framework measured them for this render. */
|
|
105
|
+
probe(): Promise<{ readonly database: SubsystemState; readonly redis: SubsystemState }>;
|
|
106
|
+
/** The PROFILE this page reports for — her runtime, not the host's. */
|
|
107
|
+
actingProfile(): Promise<ActingProfileFacts>;
|
|
108
|
+
/** The modules this profile HOLDS in the page's guild — the ownership read, not what is loaded. */
|
|
109
|
+
heldModules(): Promise<readonly string[]>;
|
|
110
|
+
/**
|
|
111
|
+
* The configured shard count. A narrow read on purpose: a general `setting(key)` would hand a module
|
|
112
|
+
* the whole configuration surface, which is the boundary this contract exists to hold.
|
|
113
|
+
*/
|
|
114
|
+
shardCount(): Promise<number>;
|
|
115
|
+
/**
|
|
116
|
+
* The guild and member counts this profile sees, and WHICH source answered. The Discord API is the
|
|
117
|
+
* authority on membership; the cache is a snapshot taken at login and can lag, which is how a bot in
|
|
118
|
+
* three guilds once reported four. A page must be able to say which it used.
|
|
119
|
+
*/
|
|
120
|
+
guilds(): Promise<GuildCounts>;
|
|
121
|
+
/**
|
|
122
|
+
* The host process's own numbers. A module CANNOT read these itself: its tsconfig carries no Node
|
|
123
|
+
* types, because a module is environment-neutral — it declares surfaces, it does not touch the host
|
|
124
|
+
* runtime. So the framework reports them, and the page labels them as SHARED rather than the
|
|
125
|
+
* profile's.
|
|
126
|
+
*/
|
|
127
|
+
hostProcess(): Promise<HostProcessFacts>;
|
|
128
|
+
/**
|
|
129
|
+
* The pending command-queue actions for the page's guild, oldest first. The queue is core
|
|
130
|
+
* infrastructure; a module asks what is pending, not how the table is shaped.
|
|
131
|
+
*/
|
|
132
|
+
pendingQueue(): Promise<readonly PendingQueueEntry[]>;
|
|
133
|
+
/**
|
|
134
|
+
* WHO holds a module in this page's guild — `'main'`, a persona's id, or `undefined` when nobody
|
|
135
|
+
* does. `undefined` is NOT the main bot: the ownership read answers `'main'` explicitly when the
|
|
136
|
+
* resident bot holds it, and a page that conflated the two would name the bot as the holder of a
|
|
137
|
+
* module it never claimed.
|
|
138
|
+
*/
|
|
139
|
+
holder(slug: string): Promise<string | undefined>;
|
|
140
|
+
/**
|
|
141
|
+
* Is this module enabled by DEFAULT for the acting profile? Not the same as the guild's state: a
|
|
142
|
+
* standard module is enabled by default only for the profile that got there first, so this answer
|
|
143
|
+
* depends on ownership. Core and Admin are shared and always on; marketplace never defaults on.
|
|
144
|
+
*/
|
|
145
|
+
enabledByDefault(slug: string): Promise<boolean>;
|
|
146
|
+
/**
|
|
147
|
+
* How to NAME a profile on a surface: "Dumby Profile" for the internal one, or the persona's own
|
|
148
|
+
* registered name. A page must never invent a holder, and never show a raw id to a member.
|
|
149
|
+
*/
|
|
150
|
+
profileLabel(profileId: string): Promise<string>;
|
|
151
|
+
/**
|
|
152
|
+
* The GUILD's own stored state for a module — the `guild_module_states` row — and `undefined` when
|
|
153
|
+
* there is no row. Lossless on purpose: `undefined` ("never touched here") and `false` ("the guild
|
|
154
|
+
* disabled it") are different facts, and a catalogue that conflated them would label a module
|
|
155
|
+
* disabled-by-choice as merely unavailable.
|
|
156
|
+
*/
|
|
157
|
+
guildState(slug: string): Promise<boolean | undefined>;
|
|
158
|
+
/** The tier's default for the GUILD, when it has no row: core and admin on, marketplace off. */
|
|
159
|
+
tierDefault(slug: string): Promise<boolean>;
|
|
160
|
+
/**
|
|
161
|
+
* The guild's persona bindings: which module is bound to which persona here. A module bound to a
|
|
162
|
+
* persona is owned by that persona in this guild; every other module belongs to the resident bot.
|
|
163
|
+
*/
|
|
164
|
+
personaBindings(): Promise<readonly PersonaBinding[]>;
|
|
165
|
+
/**
|
|
166
|
+
* The personas this guild knows — registered here, or named by a binding. `boundGuildId` is exactly
|
|
167
|
+
* "the personas this guild registered", which is not the same set as "personas bound to a module".
|
|
168
|
+
*/
|
|
169
|
+
registeredPersonas(): Promise<readonly PersonaRecord[]>;
|
|
170
|
+
/**
|
|
171
|
+
* The identity this PROCESS runs as: a persona's id when it is a dedicated persona process, `'main'`
|
|
172
|
+
* otherwise. Not "the persona registered for this guild" — that was the bug that opened /persona on
|
|
173
|
+
* a persona's profile when the main bot ran it.
|
|
174
|
+
*/
|
|
175
|
+
residentProfileId(): Promise<string>;
|
|
176
|
+
/** The resident bot's own identity: its name, its application id, and whether it is connected. */
|
|
177
|
+
botIdentity(): Promise<{
|
|
178
|
+
readonly name: string;
|
|
179
|
+
readonly applicationId: string;
|
|
180
|
+
readonly online: boolean;
|
|
181
|
+
}>;
|
|
182
|
+
/**
|
|
183
|
+
* Is this application present in the page's guild? A persona is ACTIVE only when its bot has been
|
|
184
|
+
* invited and is there; presence that cannot be resolved is reported as absent, never assumed.
|
|
185
|
+
*/
|
|
186
|
+
isMember(applicationId: string): Promise<boolean>;
|
|
187
|
+
/** The invite URL for a persona's application, or `''` when there is no guild or no builder. */
|
|
188
|
+
inviteUrl(applicationId: string, withOAuth: boolean): Promise<string>;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export type SubsystemState = 'connected' | 'unavailable';
|
|
192
|
+
|
|
193
|
+
export interface PersonaBinding {
|
|
194
|
+
readonly moduleSlug: string;
|
|
195
|
+
readonly personaId: string;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
export interface PersonaRecord {
|
|
199
|
+
readonly id: string;
|
|
200
|
+
readonly name: string;
|
|
201
|
+
readonly discordApplicationId: string;
|
|
202
|
+
readonly boundGuildId: string;
|
|
203
|
+
readonly dmBehavior: string;
|
|
204
|
+
readonly shardAllocation: number;
|
|
205
|
+
readonly status: string;
|
|
206
|
+
readonly hasOAuth: boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Whether this persona's OAuth leg has EVER completed. Discord exposes no API to read an
|
|
209
|
+
* application's registered redirect URIs, so a successful exchange is the only honest proof the
|
|
210
|
+
* redirect URL is configured. The fact, not a presentation of it.
|
|
211
|
+
*/
|
|
212
|
+
readonly oauthVerified: boolean;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export interface PendingQueueEntry {
|
|
216
|
+
/** The command this action will apply to. */
|
|
217
|
+
readonly commandKey: string;
|
|
218
|
+
/** `'rename'` when the payload carries no action — the queue's own default. */
|
|
219
|
+
readonly action: string;
|
|
220
|
+
readonly newName?: string;
|
|
221
|
+
readonly alias?: string;
|
|
222
|
+
readonly disable?: boolean;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export interface HostProcessFacts {
|
|
226
|
+
/** Seconds the process has been up. */
|
|
227
|
+
readonly uptimeSeconds: number;
|
|
228
|
+
/** e.g. `v20.20.2`. */
|
|
229
|
+
readonly nodeVersion: string;
|
|
230
|
+
readonly memory: {
|
|
231
|
+
readonly rss: number;
|
|
232
|
+
readonly heapUsed: number;
|
|
233
|
+
readonly heapTotal: number;
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export interface GuildCounts {
|
|
238
|
+
/** Guilds this profile is in. */
|
|
239
|
+
readonly total: number;
|
|
240
|
+
/** Members across them; `undefined` when the cache has not filled — not zero. */
|
|
241
|
+
readonly members?: number;
|
|
242
|
+
/** `'live'` when the API answered, `'cache'` when the snapshot did. */
|
|
243
|
+
readonly source: 'live' | 'cache';
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
export interface ActingProfileFacts {
|
|
247
|
+
/** `'main'`, or the persona's id. */
|
|
248
|
+
readonly profileId: string;
|
|
249
|
+
/** When this profile's runtime started, epoch ms; absent for the internal profile, the host. */
|
|
250
|
+
readonly startedAt?: number;
|
|
251
|
+
/** Is this profile's gateway connected? */
|
|
252
|
+
readonly gatewayReady: boolean;
|
|
253
|
+
/** Gateway latency in ms, when the client reports one. */
|
|
254
|
+
readonly gatewayPingMs?: number;
|
|
255
|
+
/** The module slugs this profile's runtime has LOADED — a different fact from what it holds. */
|
|
256
|
+
readonly loadedModules: readonly string[];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* UR-20261029-113 — what a page hands back.
|
|
261
|
+
*
|
|
262
|
+
* `data` is the shape the framework's own consumers read; `blocks` is the module's OWN renderer
|
|
263
|
+
* schema for its content. A module that returns blocks owns its surface end to end: the framework
|
|
264
|
+
* renders what it is given and contributes only its chrome — the navigation, the footer, the dial —
|
|
265
|
+
* which is what keeps the zone grammar enforceable. A module that returns data alone is shaped by the
|
|
266
|
+
* framework as before, so no existing page had to change.
|
|
267
|
+
*/
|
|
268
|
+
export interface ModulePageResult {
|
|
269
|
+
readonly data: unknown;
|
|
270
|
+
readonly blocks?: readonly Record<string, unknown>[];
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
export interface ModulePage {
|
|
274
|
+
/** The page id the command returns. */
|
|
275
|
+
readonly id: string;
|
|
276
|
+
/** Build the page: its data, and optionally its own content blocks. */
|
|
277
|
+
render(context: ModulePageContext, read: ModulePageReadModel): Promise<unknown>;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
export function definePage(page: ModulePage): ModulePage {
|
|
281
|
+
return page;
|
|
282
|
+
}
|
package/src/paging.ts
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Paging helpers a module page needs to build its own slides.
|
|
3
|
+
*
|
|
4
|
+
* These lived in `apps/main/src/rendering/page-data.ts`, which a module cannot import — so they are
|
|
5
|
+
* here, in the package a module already depends on, and the host re-exports them from where it used
|
|
6
|
+
* to declare them. One implementation, two callers.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 1 -> I, 4 -> IIII. Non-finite or non-positive values are printed as they are.
|
|
11
|
+
*
|
|
12
|
+
* ADDITIVE ONLY, and deliberately so: there is no subtractive pair, so 4 is `IIII` and not `IV`, 9 is
|
|
13
|
+
* `VIIII` and not `IX`, 40 is `XXXX` and not `XL`. The rationale lived only in the host's re-export
|
|
14
|
+
* (`apps/main/src/rendering/page-data.ts`), which said the form is used "throughout (IIII rather than
|
|
15
|
+
* IV) on purpose: it is unambiguous to read at a glance" — a slide dial is scanned, not read. It is
|
|
16
|
+
* recorded here, at the implementation, because this comment used to say "4 -> IV" and the function
|
|
17
|
+
* has never done that; a reader who trusted it would have "fixed" a deliberate choice.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export function romanNumeral(value: number): string {
|
|
21
|
+
if (!Number.isFinite(value) || value < 1) return String(value);
|
|
22
|
+
const table: Array<[number, string]> = [
|
|
23
|
+
[1000, 'M'],
|
|
24
|
+
[500, 'D'],
|
|
25
|
+
[100, 'C'],
|
|
26
|
+
[50, 'L'],
|
|
27
|
+
[10, 'X'],
|
|
28
|
+
[5, 'V'],
|
|
29
|
+
[1, 'I'],
|
|
30
|
+
];
|
|
31
|
+
let remaining = Math.floor(value);
|
|
32
|
+
let out = '';
|
|
33
|
+
for (const [size, glyph] of table) {
|
|
34
|
+
while (remaining >= size) {
|
|
35
|
+
out += glyph;
|
|
36
|
+
remaining -= size;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface PageSlide {
|
|
43
|
+
readonly id: string;
|
|
44
|
+
readonly name: string;
|
|
45
|
+
readonly description: string;
|
|
46
|
+
readonly page: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* The DIAL's entries for a surface that pages MODULES directly: one option per slide, naming the
|
|
51
|
+
* range it holds. An option per module would offer targets that do not exist.
|
|
52
|
+
*
|
|
53
|
+
* Page 0 is Home; the slides cover 1..pageTotal-1, numbered from I — numbering the first listing page
|
|
54
|
+
* as a slide made Home and "Slide I" the same destination with the same modules on it.
|
|
55
|
+
*/
|
|
56
|
+
export function modulePageNavigation(
|
|
57
|
+
pageTotal: number,
|
|
58
|
+
total: number,
|
|
59
|
+
pageSize: number,
|
|
60
|
+
): readonly PageSlide[] {
|
|
61
|
+
return Array.from({ length: Math.max(0, pageTotal - 1) }, (_, offset) => {
|
|
62
|
+
const index = offset + 1;
|
|
63
|
+
const first = index * pageSize + 1;
|
|
64
|
+
const last = Math.min((index + 1) * pageSize, total);
|
|
65
|
+
return {
|
|
66
|
+
id: `page-${index + 1}`,
|
|
67
|
+
name: `Slide ${romanNumeral(offset + 1)}`,
|
|
68
|
+
description: first === last ? `Module ${first}` : `Modules ${first}–${last}`,
|
|
69
|
+
page: index,
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
package/src/permits.ts
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* UR-20261123-190 — the permit surface, as a CONTRACT.
|
|
3
|
+
*
|
|
4
|
+
* The permit module used to hand-write this shape in `packages/modules/permit/src/surface.ts`, which made two
|
|
5
|
+
* descriptions of one thing: the core's surface and the module's copy, kept in step by discipline. The
|
|
6
|
+
* three-layer rule says the SHAPE belongs in the SDK — both sides need it, neither owns it — so it lives here
|
|
7
|
+
* and the module imports it like any other type.
|
|
8
|
+
*
|
|
9
|
+
* A module never sees a grant row, a table or a connection through this interface. It names a Pixel, a target,
|
|
10
|
+
* an effect and a quota; the core decides what that means, and whether it is allowed.
|
|
11
|
+
*
|
|
12
|
+
* UR-20261123-190 §5 — the state machine. `draft` has a name and nothing else; `armed` has a command, a target
|
|
13
|
+
* and an effect, and is one press from doing anything; `live` is armed AND enabled. `missing` names what an
|
|
14
|
+
* armed Pixel still lacks, so a disabled button can say WHY instead of just being grey.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** What a Pixel points at. `user` sits above the other three: most specific wins. */
|
|
18
|
+
export type PixelTargetKind = 'user' | 'role' | 'group' | 'set';
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* What a Pixel does to its target. Two values, not three.
|
|
22
|
+
*
|
|
23
|
+
* `whitelist` is NOT here on purpose: it restricts a COMMAND to only whitelisted targets, which is a different
|
|
24
|
+
* axis from "what does this Pixel do to this target". Mixing them is what made the tri-state toggle wrong.
|
|
25
|
+
*/
|
|
26
|
+
export type PixelEffect = 'allow' | 'deny';
|
|
27
|
+
|
|
28
|
+
/** A rolling-window ceiling for the target: `count` uses per `windowSeconds`. */
|
|
29
|
+
export interface PixelQuota {
|
|
30
|
+
readonly count: number;
|
|
31
|
+
readonly windowSeconds: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PixelTarget {
|
|
35
|
+
readonly kind: PixelTargetKind;
|
|
36
|
+
/** A Discord id, or a group/set id from the RBAC tables. */
|
|
37
|
+
readonly refId: string;
|
|
38
|
+
/** What the operator saw when they picked it, so a page can render without a second lookup. */
|
|
39
|
+
readonly label?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type PixelState = 'draft' | 'armed' | 'live';
|
|
43
|
+
|
|
44
|
+
/** Everything a page needs to draw one Pixel. No row, no table, no guild internals. */
|
|
45
|
+
export interface PixelSummary {
|
|
46
|
+
readonly id: string;
|
|
47
|
+
readonly name: string;
|
|
48
|
+
readonly state: PixelState;
|
|
49
|
+
readonly enabled: boolean;
|
|
50
|
+
/** `moduleId.commandName` — absent until the command is chosen. */
|
|
51
|
+
readonly key?: string;
|
|
52
|
+
readonly moduleName?: string;
|
|
53
|
+
readonly target?: PixelTarget;
|
|
54
|
+
readonly effect?: PixelEffect;
|
|
55
|
+
readonly quota?: PixelQuota;
|
|
56
|
+
/** Prerequisite names still unmet, in the order the panel should show them. Empty when armed or live. */
|
|
57
|
+
readonly missing: readonly string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* A closed set. Every refusal is one of these plus a sentence the member reads — a bare `false` is the defect
|
|
62
|
+
* this corpus keeps finding.
|
|
63
|
+
*/
|
|
64
|
+
export type PixelErrorCode =
|
|
65
|
+
| 'name-taken'
|
|
66
|
+
| 'name-invalid'
|
|
67
|
+
| 'not-found'
|
|
68
|
+
| 'not-a-module-command'
|
|
69
|
+
| 'core-command-refused'
|
|
70
|
+
| 'prerequisite-unmet'
|
|
71
|
+
| 'unknown-target'
|
|
72
|
+
| 'quota-invalid'
|
|
73
|
+
| 'forbidden';
|
|
74
|
+
|
|
75
|
+
export type PixelResult =
|
|
76
|
+
| { readonly ok: true; readonly pixel: PixelSummary }
|
|
77
|
+
| { readonly ok: false; readonly code: PixelErrorCode; readonly reason: string };
|
|
78
|
+
|
|
79
|
+
/** A command a grant may apply to. Core commands never appear here (§21.6). */
|
|
80
|
+
export interface GrantableCommand {
|
|
81
|
+
readonly moduleId: string;
|
|
82
|
+
readonly moduleName: string;
|
|
83
|
+
readonly commandName: string;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export interface PixelTargetInput {
|
|
87
|
+
readonly kind: PixelTargetKind;
|
|
88
|
+
readonly refId: string;
|
|
89
|
+
readonly label?: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The surface the core offers and the permit module captures at `onLoad`.
|
|
94
|
+
*
|
|
95
|
+
* Every write is a SET, not a toggle: pressing twice yields one state, so a double click or a retried
|
|
96
|
+
* interaction cannot produce a second row.
|
|
97
|
+
*/
|
|
98
|
+
/**
|
|
99
|
+
* UR-20261124-194 — PMT-DD-002 v2.0, the surface the eight views call.
|
|
100
|
+
*
|
|
101
|
+
* This is the SAME capability the v1 methods ride (`core.Permits`), extended rather than duplicated. The v1
|
|
102
|
+
* methods stay because `pixel.service.ts` and its tests compile against them; the module stops using them, which
|
|
103
|
+
* is what removes the second description of this contract that DOC-089 recorded.
|
|
104
|
+
*
|
|
105
|
+
* THE INTERFACE SAYS "PERMIT". The model says Pixel — that is what the object is called in code and in the
|
|
106
|
+
* corpus — but a member reads "Permits", never the jargon. The split is deliberate and is stated in the
|
|
107
|
+
* specification; the two words never meet in one string a member sees.
|
|
108
|
+
*/
|
|
109
|
+
export type PermitKind = 'user' | 'role' | 'group' | 'set';
|
|
110
|
+
export type PermitRule = 'allow' | 'block';
|
|
111
|
+
|
|
112
|
+
/** §10.1 — a limit always arrives with its window; slowmode is independent of both and 0 means off. */
|
|
113
|
+
export interface PermitQuotaV2 {
|
|
114
|
+
readonly limitCount: number;
|
|
115
|
+
readonly windowSeconds: number;
|
|
116
|
+
readonly slowmodeSeconds: number;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** One governed command. `commandName === '*'` is the wildcard that covers every Standard command. */
|
|
120
|
+
export interface PermitCommandRef {
|
|
121
|
+
readonly moduleId: string;
|
|
122
|
+
readonly commandName: string;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** A group's roles, or a set's members (§10.1 PIXELMEMBER). */
|
|
126
|
+
export interface PermitMemberRef {
|
|
127
|
+
readonly memberType: 'role' | 'user';
|
|
128
|
+
readonly memberId: string;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Everything a view draws. No row, no table, no guild internals cross this seam. */
|
|
132
|
+
export interface PermitSummary {
|
|
133
|
+
readonly id: string;
|
|
134
|
+
readonly kind: PermitKind;
|
|
135
|
+
readonly targetId: string | null;
|
|
136
|
+
readonly name: string;
|
|
137
|
+
readonly rule: PermitRule;
|
|
138
|
+
readonly quota: PermitQuotaV2 | null;
|
|
139
|
+
readonly commands: readonly PermitCommandRef[];
|
|
140
|
+
readonly members: readonly PermitMemberRef[];
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* The notice codes of Appendix C. A refusal is always a code plus a sentence the member reads — a bare `false`
|
|
145
|
+
* is the defect this corpus keeps finding, and a refusal that says only "failed" is indistinguishable from a bug.
|
|
146
|
+
*/
|
|
147
|
+
export type PermitNoticeCode =
|
|
148
|
+
| 'P01'
|
|
149
|
+
| 'P02'
|
|
150
|
+
| 'P03'
|
|
151
|
+
| 'P04'
|
|
152
|
+
| 'P05'
|
|
153
|
+
| 'P06'
|
|
154
|
+
| 'P07'
|
|
155
|
+
| 'P08'
|
|
156
|
+
| 'P09'
|
|
157
|
+
| 'P10';
|
|
158
|
+
|
|
159
|
+
export type PermitResult =
|
|
160
|
+
| { readonly ok: true; readonly permit: PermitSummary }
|
|
161
|
+
| { readonly ok: false; readonly code: PermitNoticeCode; readonly message: string };
|
|
162
|
+
|
|
163
|
+
export interface PermitV2Surface {
|
|
164
|
+
/** Every permit in the guild, oldest first. */
|
|
165
|
+
permits(guildId: string): Promise<readonly PermitSummary[]>;
|
|
166
|
+
createPermit(input: {
|
|
167
|
+
guildId: string;
|
|
168
|
+
kind: PermitKind;
|
|
169
|
+
/** UR-20261125-231 — a permit is created NAMED and UNAIMED; the target is set from the panel. */
|
|
170
|
+
targetId: string | null;
|
|
171
|
+
name: string;
|
|
172
|
+
actorId: string;
|
|
173
|
+
}): Promise<PermitResult>;
|
|
174
|
+
renamePermit(input: {
|
|
175
|
+
guildId: string;
|
|
176
|
+
permitId: string;
|
|
177
|
+
name: string;
|
|
178
|
+
actorId: string;
|
|
179
|
+
}): Promise<PermitResult>;
|
|
180
|
+
/**
|
|
181
|
+
* UR-20261125-206 — assign or clear the target. A permit is created with a NAME and no target, so the member
|
|
182
|
+
* can name it first and aim it second; until it is aimed it governs nothing, which the panel states.
|
|
183
|
+
*/
|
|
184
|
+
setPermitTarget(input: {
|
|
185
|
+
readonly guildId: string;
|
|
186
|
+
readonly permitId: string;
|
|
187
|
+
readonly targetId: string | null;
|
|
188
|
+
readonly actorId: string;
|
|
189
|
+
}): Promise<PermitResult>;
|
|
190
|
+
setPermitRule(input: {
|
|
191
|
+
guildId: string;
|
|
192
|
+
permitId: string;
|
|
193
|
+
rule: PermitRule;
|
|
194
|
+
actorId: string;
|
|
195
|
+
}): Promise<PermitResult>;
|
|
196
|
+
setPermitQuota(input: {
|
|
197
|
+
guildId: string;
|
|
198
|
+
permitId: string;
|
|
199
|
+
quota: PermitQuotaV2 | null;
|
|
200
|
+
actorId: string;
|
|
201
|
+
}): Promise<PermitResult>;
|
|
202
|
+
addPermitCommands(input: {
|
|
203
|
+
guildId: string;
|
|
204
|
+
permitId: string;
|
|
205
|
+
commands: readonly PermitCommandRef[];
|
|
206
|
+
actorId: string;
|
|
207
|
+
}): Promise<PermitResult>;
|
|
208
|
+
removePermitCommands(input: {
|
|
209
|
+
guildId: string;
|
|
210
|
+
permitId: string;
|
|
211
|
+
commands: readonly PermitCommandRef[];
|
|
212
|
+
actorId: string;
|
|
213
|
+
}): Promise<PermitResult>;
|
|
214
|
+
addPermitMembers(input: {
|
|
215
|
+
guildId: string;
|
|
216
|
+
permitId: string;
|
|
217
|
+
members: readonly PermitMemberRef[];
|
|
218
|
+
actorId: string;
|
|
219
|
+
}): Promise<PermitResult>;
|
|
220
|
+
removePermitMembers(input: {
|
|
221
|
+
guildId: string;
|
|
222
|
+
permitId: string;
|
|
223
|
+
members: readonly PermitMemberRef[];
|
|
224
|
+
actorId: string;
|
|
225
|
+
}): Promise<PermitResult>;
|
|
226
|
+
deletePermit(input: {
|
|
227
|
+
guildId: string;
|
|
228
|
+
permitId: string;
|
|
229
|
+
actorId: string;
|
|
230
|
+
}): Promise<PermitResult>;
|
|
231
|
+
/** D4 — the ceiling this deployment enforces, so the interface can say what the limit is rather than guess. */
|
|
232
|
+
permitLimit(): number;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* The capability the permit module captures at `onLoad`.
|
|
237
|
+
*
|
|
238
|
+
* UR-20261124-194 — THE v1 WRITE MEMBERS ARE GONE. `apply`, `remove`, `list`, `decision` and the nine Pixel
|
|
239
|
+
* mutators were the console the module no longer has, and `pixel.service`/`pixel.repository` are deleted with
|
|
240
|
+
* them. `rbac_grants` stays READABLE: `rbac.ts` still resolves a pre-Pixel grant row, so nothing that was
|
|
241
|
+
* applying has stopped applying. What is gone is the second writer, which is where a second precedence rule
|
|
242
|
+
* would have grown. (Owner decision, 2026-11-24.)
|
|
243
|
+
*/
|
|
244
|
+
export interface PermitSurface extends PermitV2Surface {
|
|
245
|
+
/**
|
|
246
|
+
* The commands a permit may govern. The CORE names them: a module that named its own could offer a command it
|
|
247
|
+
* does not own. Core commands are excluded — a permit never reaches one (§21.6, Division 8 §8.4).
|
|
248
|
+
*/
|
|
249
|
+
grantable(): readonly GrantableCommand[];
|
|
250
|
+
}
|
package/src/validate.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { moduleManifestSchema } from './manifest-schema.js';
|
|
2
|
+
import type { ModuleManifest } from './manifest-schema.js';
|
|
3
|
+
|
|
4
|
+
export interface ManifestValidationResult {
|
|
5
|
+
readonly valid: boolean;
|
|
6
|
+
/** One message per issue, each naming the offending path. Empty when `valid` is true. */
|
|
7
|
+
readonly errors: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The Swastik upload validator. It imports the *same* schema the bot's Stage 11 validator uses
|
|
12
|
+
* (`./manifest-schema.ts`, re-exported by `apps/main/src/module-system/manifest.schema.ts`), so an
|
|
13
|
+
* upload that passes here cannot fail at Stage 11 for a schema reason — and vice versa
|
|
14
|
+
* (ACC-MOD-0011-2, "no drift").
|
|
15
|
+
*/
|
|
16
|
+
export function validateManifest(input: unknown): ManifestValidationResult {
|
|
17
|
+
const parsed = moduleManifestSchema.safeParse(input);
|
|
18
|
+
if (parsed.success) return { valid: true, errors: [] };
|
|
19
|
+
return {
|
|
20
|
+
valid: false,
|
|
21
|
+
errors: parsed.error.issues.map((issue) => {
|
|
22
|
+
const path = issue.path.join('.');
|
|
23
|
+
return path.length > 0 ? `${path}: ${issue.message}` : issue.message;
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Throws on an invalid manifest, naming every issue — the upload path's fail-closed entry point. */
|
|
29
|
+
export function assertValidManifest(input: unknown): ModuleManifest {
|
|
30
|
+
const result = validateManifest(input);
|
|
31
|
+
if (!result.valid) {
|
|
32
|
+
throw new Error(`invalid module manifest:\n ${result.errors.join('\n ')}`);
|
|
33
|
+
}
|
|
34
|
+
return moduleManifestSchema.parse(input);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The bot's Stage 11 validator entry point. Same schema, same result as `assertValidManifest` —
|
|
39
|
+
* kept under this name because `swastik-loader.ts`, `promotion.ts` and `entry/swastik.ts` all call
|
|
40
|
+
* it, and a rename would be drift of a different kind.
|
|
41
|
+
*/
|
|
42
|
+
export const parseManifest = assertValidManifest;
|
package/README.md
DELETED