@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/dist/paging.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
* 1 -> I, 4 -> IIII. Non-finite or non-positive values are printed as they are.
|
|
10
|
+
*
|
|
11
|
+
* ADDITIVE ONLY, and deliberately so: there is no subtractive pair, so 4 is `IIII` and not `IV`, 9 is
|
|
12
|
+
* `VIIII` and not `IX`, 40 is `XXXX` and not `XL`. The rationale lived only in the host's re-export
|
|
13
|
+
* (`apps/main/src/rendering/page-data.ts`), which said the form is used "throughout (IIII rather than
|
|
14
|
+
* IV) on purpose: it is unambiguous to read at a glance" — a slide dial is scanned, not read. It is
|
|
15
|
+
* recorded here, at the implementation, because this comment used to say "4 -> IV" and the function
|
|
16
|
+
* has never done that; a reader who trusted it would have "fixed" a deliberate choice.
|
|
17
|
+
*/
|
|
18
|
+
export function romanNumeral(value) {
|
|
19
|
+
if (!Number.isFinite(value) || value < 1)
|
|
20
|
+
return String(value);
|
|
21
|
+
const table = [
|
|
22
|
+
[1000, 'M'],
|
|
23
|
+
[500, 'D'],
|
|
24
|
+
[100, 'C'],
|
|
25
|
+
[50, 'L'],
|
|
26
|
+
[10, 'X'],
|
|
27
|
+
[5, 'V'],
|
|
28
|
+
[1, 'I'],
|
|
29
|
+
];
|
|
30
|
+
let remaining = Math.floor(value);
|
|
31
|
+
let out = '';
|
|
32
|
+
for (const [size, glyph] of table) {
|
|
33
|
+
while (remaining >= size) {
|
|
34
|
+
out += glyph;
|
|
35
|
+
remaining -= size;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return out;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The DIAL's entries for a surface that pages MODULES directly: one option per slide, naming the
|
|
42
|
+
* range it holds. An option per module would offer targets that do not exist.
|
|
43
|
+
*
|
|
44
|
+
* Page 0 is Home; the slides cover 1..pageTotal-1, numbered from I — numbering the first listing page
|
|
45
|
+
* as a slide made Home and "Slide I" the same destination with the same modules on it.
|
|
46
|
+
*/
|
|
47
|
+
export function modulePageNavigation(pageTotal, total, pageSize) {
|
|
48
|
+
return Array.from({ length: Math.max(0, pageTotal - 1) }, (_, offset) => {
|
|
49
|
+
const index = offset + 1;
|
|
50
|
+
const first = index * pageSize + 1;
|
|
51
|
+
const last = Math.min((index + 1) * pageSize, total);
|
|
52
|
+
return {
|
|
53
|
+
id: `page-${index + 1}`,
|
|
54
|
+
name: `Slide ${romanNumeral(offset + 1)}`,
|
|
55
|
+
description: first === last ? `Module ${first}` : `Modules ${first}–${last}`,
|
|
56
|
+
page: index,
|
|
57
|
+
};
|
|
58
|
+
});
|
|
59
|
+
}
|
|
@@ -0,0 +1,222 @@
|
|
|
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
|
+
/** What a Pixel points at. `user` sits above the other three: most specific wins. */
|
|
17
|
+
export type PixelTargetKind = 'user' | 'role' | 'group' | 'set';
|
|
18
|
+
/**
|
|
19
|
+
* What a Pixel does to its target. Two values, not three.
|
|
20
|
+
*
|
|
21
|
+
* `whitelist` is NOT here on purpose: it restricts a COMMAND to only whitelisted targets, which is a different
|
|
22
|
+
* axis from "what does this Pixel do to this target". Mixing them is what made the tri-state toggle wrong.
|
|
23
|
+
*/
|
|
24
|
+
export type PixelEffect = 'allow' | 'deny';
|
|
25
|
+
/** A rolling-window ceiling for the target: `count` uses per `windowSeconds`. */
|
|
26
|
+
export interface PixelQuota {
|
|
27
|
+
readonly count: number;
|
|
28
|
+
readonly windowSeconds: number;
|
|
29
|
+
}
|
|
30
|
+
export interface PixelTarget {
|
|
31
|
+
readonly kind: PixelTargetKind;
|
|
32
|
+
/** A Discord id, or a group/set id from the RBAC tables. */
|
|
33
|
+
readonly refId: string;
|
|
34
|
+
/** What the operator saw when they picked it, so a page can render without a second lookup. */
|
|
35
|
+
readonly label?: string;
|
|
36
|
+
}
|
|
37
|
+
export type PixelState = 'draft' | 'armed' | 'live';
|
|
38
|
+
/** Everything a page needs to draw one Pixel. No row, no table, no guild internals. */
|
|
39
|
+
export interface PixelSummary {
|
|
40
|
+
readonly id: string;
|
|
41
|
+
readonly name: string;
|
|
42
|
+
readonly state: PixelState;
|
|
43
|
+
readonly enabled: boolean;
|
|
44
|
+
/** `moduleId.commandName` — absent until the command is chosen. */
|
|
45
|
+
readonly key?: string;
|
|
46
|
+
readonly moduleName?: string;
|
|
47
|
+
readonly target?: PixelTarget;
|
|
48
|
+
readonly effect?: PixelEffect;
|
|
49
|
+
readonly quota?: PixelQuota;
|
|
50
|
+
/** Prerequisite names still unmet, in the order the panel should show them. Empty when armed or live. */
|
|
51
|
+
readonly missing: readonly string[];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* A closed set. Every refusal is one of these plus a sentence the member reads — a bare `false` is the defect
|
|
55
|
+
* this corpus keeps finding.
|
|
56
|
+
*/
|
|
57
|
+
export type PixelErrorCode = 'name-taken' | 'name-invalid' | 'not-found' | 'not-a-module-command' | 'core-command-refused' | 'prerequisite-unmet' | 'unknown-target' | 'quota-invalid' | 'forbidden';
|
|
58
|
+
export type PixelResult = {
|
|
59
|
+
readonly ok: true;
|
|
60
|
+
readonly pixel: PixelSummary;
|
|
61
|
+
} | {
|
|
62
|
+
readonly ok: false;
|
|
63
|
+
readonly code: PixelErrorCode;
|
|
64
|
+
readonly reason: string;
|
|
65
|
+
};
|
|
66
|
+
/** A command a grant may apply to. Core commands never appear here (§21.6). */
|
|
67
|
+
export interface GrantableCommand {
|
|
68
|
+
readonly moduleId: string;
|
|
69
|
+
readonly moduleName: string;
|
|
70
|
+
readonly commandName: string;
|
|
71
|
+
}
|
|
72
|
+
export interface PixelTargetInput {
|
|
73
|
+
readonly kind: PixelTargetKind;
|
|
74
|
+
readonly refId: string;
|
|
75
|
+
readonly label?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The surface the core offers and the permit module captures at `onLoad`.
|
|
79
|
+
*
|
|
80
|
+
* Every write is a SET, not a toggle: pressing twice yields one state, so a double click or a retried
|
|
81
|
+
* interaction cannot produce a second row.
|
|
82
|
+
*/
|
|
83
|
+
/**
|
|
84
|
+
* UR-20261124-194 — PMT-DD-002 v2.0, the surface the eight views call.
|
|
85
|
+
*
|
|
86
|
+
* This is the SAME capability the v1 methods ride (`core.Permits`), extended rather than duplicated. The v1
|
|
87
|
+
* methods stay because `pixel.service.ts` and its tests compile against them; the module stops using them, which
|
|
88
|
+
* is what removes the second description of this contract that DOC-089 recorded.
|
|
89
|
+
*
|
|
90
|
+
* THE INTERFACE SAYS "PERMIT". The model says Pixel — that is what the object is called in code and in the
|
|
91
|
+
* corpus — but a member reads "Permits", never the jargon. The split is deliberate and is stated in the
|
|
92
|
+
* specification; the two words never meet in one string a member sees.
|
|
93
|
+
*/
|
|
94
|
+
export type PermitKind = 'user' | 'role' | 'group' | 'set';
|
|
95
|
+
export type PermitRule = 'allow' | 'block';
|
|
96
|
+
/** §10.1 — a limit always arrives with its window; slowmode is independent of both and 0 means off. */
|
|
97
|
+
export interface PermitQuotaV2 {
|
|
98
|
+
readonly limitCount: number;
|
|
99
|
+
readonly windowSeconds: number;
|
|
100
|
+
readonly slowmodeSeconds: number;
|
|
101
|
+
}
|
|
102
|
+
/** One governed command. `commandName === '*'` is the wildcard that covers every Standard command. */
|
|
103
|
+
export interface PermitCommandRef {
|
|
104
|
+
readonly moduleId: string;
|
|
105
|
+
readonly commandName: string;
|
|
106
|
+
}
|
|
107
|
+
/** A group's roles, or a set's members (§10.1 PIXELMEMBER). */
|
|
108
|
+
export interface PermitMemberRef {
|
|
109
|
+
readonly memberType: 'role' | 'user';
|
|
110
|
+
readonly memberId: string;
|
|
111
|
+
}
|
|
112
|
+
/** Everything a view draws. No row, no table, no guild internals cross this seam. */
|
|
113
|
+
export interface PermitSummary {
|
|
114
|
+
readonly id: string;
|
|
115
|
+
readonly kind: PermitKind;
|
|
116
|
+
readonly targetId: string | null;
|
|
117
|
+
readonly name: string;
|
|
118
|
+
readonly rule: PermitRule;
|
|
119
|
+
readonly quota: PermitQuotaV2 | null;
|
|
120
|
+
readonly commands: readonly PermitCommandRef[];
|
|
121
|
+
readonly members: readonly PermitMemberRef[];
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The notice codes of Appendix C. A refusal is always a code plus a sentence the member reads — a bare `false`
|
|
125
|
+
* is the defect this corpus keeps finding, and a refusal that says only "failed" is indistinguishable from a bug.
|
|
126
|
+
*/
|
|
127
|
+
export type PermitNoticeCode = 'P01' | 'P02' | 'P03' | 'P04' | 'P05' | 'P06' | 'P07' | 'P08' | 'P09' | 'P10';
|
|
128
|
+
export type PermitResult = {
|
|
129
|
+
readonly ok: true;
|
|
130
|
+
readonly permit: PermitSummary;
|
|
131
|
+
} | {
|
|
132
|
+
readonly ok: false;
|
|
133
|
+
readonly code: PermitNoticeCode;
|
|
134
|
+
readonly message: string;
|
|
135
|
+
};
|
|
136
|
+
export interface PermitV2Surface {
|
|
137
|
+
/** Every permit in the guild, oldest first. */
|
|
138
|
+
permits(guildId: string): Promise<readonly PermitSummary[]>;
|
|
139
|
+
createPermit(input: {
|
|
140
|
+
guildId: string;
|
|
141
|
+
kind: PermitKind;
|
|
142
|
+
/** UR-20261125-231 — a permit is created NAMED and UNAIMED; the target is set from the panel. */
|
|
143
|
+
targetId: string | null;
|
|
144
|
+
name: string;
|
|
145
|
+
actorId: string;
|
|
146
|
+
}): Promise<PermitResult>;
|
|
147
|
+
renamePermit(input: {
|
|
148
|
+
guildId: string;
|
|
149
|
+
permitId: string;
|
|
150
|
+
name: string;
|
|
151
|
+
actorId: string;
|
|
152
|
+
}): Promise<PermitResult>;
|
|
153
|
+
/**
|
|
154
|
+
* UR-20261125-206 — assign or clear the target. A permit is created with a NAME and no target, so the member
|
|
155
|
+
* can name it first and aim it second; until it is aimed it governs nothing, which the panel states.
|
|
156
|
+
*/
|
|
157
|
+
setPermitTarget(input: {
|
|
158
|
+
readonly guildId: string;
|
|
159
|
+
readonly permitId: string;
|
|
160
|
+
readonly targetId: string | null;
|
|
161
|
+
readonly actorId: string;
|
|
162
|
+
}): Promise<PermitResult>;
|
|
163
|
+
setPermitRule(input: {
|
|
164
|
+
guildId: string;
|
|
165
|
+
permitId: string;
|
|
166
|
+
rule: PermitRule;
|
|
167
|
+
actorId: string;
|
|
168
|
+
}): Promise<PermitResult>;
|
|
169
|
+
setPermitQuota(input: {
|
|
170
|
+
guildId: string;
|
|
171
|
+
permitId: string;
|
|
172
|
+
quota: PermitQuotaV2 | null;
|
|
173
|
+
actorId: string;
|
|
174
|
+
}): Promise<PermitResult>;
|
|
175
|
+
addPermitCommands(input: {
|
|
176
|
+
guildId: string;
|
|
177
|
+
permitId: string;
|
|
178
|
+
commands: readonly PermitCommandRef[];
|
|
179
|
+
actorId: string;
|
|
180
|
+
}): Promise<PermitResult>;
|
|
181
|
+
removePermitCommands(input: {
|
|
182
|
+
guildId: string;
|
|
183
|
+
permitId: string;
|
|
184
|
+
commands: readonly PermitCommandRef[];
|
|
185
|
+
actorId: string;
|
|
186
|
+
}): Promise<PermitResult>;
|
|
187
|
+
addPermitMembers(input: {
|
|
188
|
+
guildId: string;
|
|
189
|
+
permitId: string;
|
|
190
|
+
members: readonly PermitMemberRef[];
|
|
191
|
+
actorId: string;
|
|
192
|
+
}): Promise<PermitResult>;
|
|
193
|
+
removePermitMembers(input: {
|
|
194
|
+
guildId: string;
|
|
195
|
+
permitId: string;
|
|
196
|
+
members: readonly PermitMemberRef[];
|
|
197
|
+
actorId: string;
|
|
198
|
+
}): Promise<PermitResult>;
|
|
199
|
+
deletePermit(input: {
|
|
200
|
+
guildId: string;
|
|
201
|
+
permitId: string;
|
|
202
|
+
actorId: string;
|
|
203
|
+
}): Promise<PermitResult>;
|
|
204
|
+
/** D4 — the ceiling this deployment enforces, so the interface can say what the limit is rather than guess. */
|
|
205
|
+
permitLimit(): number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* The capability the permit module captures at `onLoad`.
|
|
209
|
+
*
|
|
210
|
+
* UR-20261124-194 — THE v1 WRITE MEMBERS ARE GONE. `apply`, `remove`, `list`, `decision` and the nine Pixel
|
|
211
|
+
* mutators were the console the module no longer has, and `pixel.service`/`pixel.repository` are deleted with
|
|
212
|
+
* them. `rbac_grants` stays READABLE: `rbac.ts` still resolves a pre-Pixel grant row, so nothing that was
|
|
213
|
+
* applying has stopped applying. What is gone is the second writer, which is where a second precedence rule
|
|
214
|
+
* would have grown. (Owner decision, 2026-11-24.)
|
|
215
|
+
*/
|
|
216
|
+
export interface PermitSurface extends PermitV2Surface {
|
|
217
|
+
/**
|
|
218
|
+
* The commands a permit may govern. The CORE names them: a module that named its own could offer a command it
|
|
219
|
+
* does not own. Core commands are excluded — a permit never reaches one (§21.6, Division 8 §8.4).
|
|
220
|
+
*/
|
|
221
|
+
grantable(): readonly GrantableCommand[];
|
|
222
|
+
}
|
package/dist/permits.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export {};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ModuleManifest } from './manifest-schema.js';
|
|
2
|
+
export interface ManifestValidationResult {
|
|
3
|
+
readonly valid: boolean;
|
|
4
|
+
/** One message per issue, each naming the offending path. Empty when `valid` is true. */
|
|
5
|
+
readonly errors: readonly string[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* The Swastik upload validator. It imports the *same* schema the bot's Stage 11 validator uses
|
|
9
|
+
* (`./manifest-schema.ts`, re-exported by `apps/main/src/module-system/manifest.schema.ts`), so an
|
|
10
|
+
* upload that passes here cannot fail at Stage 11 for a schema reason — and vice versa
|
|
11
|
+
* (ACC-MOD-0011-2, "no drift").
|
|
12
|
+
*/
|
|
13
|
+
export declare function validateManifest(input: unknown): ManifestValidationResult;
|
|
14
|
+
/** Throws on an invalid manifest, naming every issue — the upload path's fail-closed entry point. */
|
|
15
|
+
export declare function assertValidManifest(input: unknown): ModuleManifest;
|
|
16
|
+
/**
|
|
17
|
+
* The bot's Stage 11 validator entry point. Same schema, same result as `assertValidManifest` —
|
|
18
|
+
* kept under this name because `swastik-loader.ts`, `promotion.ts` and `entry/swastik.ts` all call
|
|
19
|
+
* it, and a rename would be drift of a different kind.
|
|
20
|
+
*/
|
|
21
|
+
export declare const parseManifest: typeof assertValidManifest;
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { moduleManifestSchema } from './manifest-schema.js';
|
|
2
|
+
/**
|
|
3
|
+
* The Swastik upload validator. It imports the *same* schema the bot's Stage 11 validator uses
|
|
4
|
+
* (`./manifest-schema.ts`, re-exported by `apps/main/src/module-system/manifest.schema.ts`), so an
|
|
5
|
+
* upload that passes here cannot fail at Stage 11 for a schema reason — and vice versa
|
|
6
|
+
* (ACC-MOD-0011-2, "no drift").
|
|
7
|
+
*/
|
|
8
|
+
export function validateManifest(input) {
|
|
9
|
+
const parsed = moduleManifestSchema.safeParse(input);
|
|
10
|
+
if (parsed.success)
|
|
11
|
+
return { valid: true, errors: [] };
|
|
12
|
+
return {
|
|
13
|
+
valid: false,
|
|
14
|
+
errors: parsed.error.issues.map((issue) => {
|
|
15
|
+
const path = issue.path.join('.');
|
|
16
|
+
return path.length > 0 ? `${path}: ${issue.message}` : issue.message;
|
|
17
|
+
}),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
/** Throws on an invalid manifest, naming every issue — the upload path's fail-closed entry point. */
|
|
21
|
+
export function assertValidManifest(input) {
|
|
22
|
+
const result = validateManifest(input);
|
|
23
|
+
if (!result.valid) {
|
|
24
|
+
throw new Error(`invalid module manifest:\n ${result.errors.join('\n ')}`);
|
|
25
|
+
}
|
|
26
|
+
return moduleManifestSchema.parse(input);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The bot's Stage 11 validator entry point. Same schema, same result as `assertValidManifest` —
|
|
30
|
+
* kept under this name because `swastik-loader.ts`, `promotion.ts` and `entry/swastik.ts` all call
|
|
31
|
+
* it, and a rename would be drift of a different kind.
|
|
32
|
+
*/
|
|
33
|
+
export const parseManifest = assertValidManifest;
|
package/package.json
CHANGED
|
@@ -1,6 +1,80 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quixotic_mnemonics/swastik",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"description": "
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Dumby Swastik module authoring surface \u2014 the SDK a module imports. Publishable so a module can be built in an isolated environment with no main codebase.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"workspace": "./src/index.ts",
|
|
10
|
+
"types": "./src/index.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./manifest": {
|
|
14
|
+
"workspace": "./src/manifest.ts",
|
|
15
|
+
"types": "./src/manifest.ts",
|
|
16
|
+
"default": "./dist/manifest.js"
|
|
17
|
+
},
|
|
18
|
+
"./entrypoints/core": {
|
|
19
|
+
"workspace": "./src/entrypoints/core.ts",
|
|
20
|
+
"types": "./src/entrypoints/core.ts",
|
|
21
|
+
"default": "./dist/entrypoints/core.js"
|
|
22
|
+
},
|
|
23
|
+
"./entrypoints/admin": {
|
|
24
|
+
"workspace": "./src/entrypoints/admin.ts",
|
|
25
|
+
"types": "./src/entrypoints/admin.ts",
|
|
26
|
+
"default": "./dist/entrypoints/admin.js"
|
|
27
|
+
},
|
|
28
|
+
"./entrypoints/standard": {
|
|
29
|
+
"workspace": "./src/entrypoints/standard.ts",
|
|
30
|
+
"types": "./src/entrypoints/standard.ts",
|
|
31
|
+
"default": "./dist/entrypoints/standard.js"
|
|
32
|
+
},
|
|
33
|
+
"./entrypoints/marketplace": {
|
|
34
|
+
"workspace": "./src/entrypoints/marketplace.ts",
|
|
35
|
+
"types": "./src/entrypoints/marketplace.ts",
|
|
36
|
+
"default": "./dist/entrypoints/marketplace.js"
|
|
37
|
+
},
|
|
38
|
+
"./validate": {
|
|
39
|
+
"workspace": "./src/validate.ts",
|
|
40
|
+
"types": "./src/validate.ts",
|
|
41
|
+
"default": "./dist/validate.js"
|
|
42
|
+
},
|
|
43
|
+
"./events": {
|
|
44
|
+
"workspace": "./src/events.ts",
|
|
45
|
+
"types": "./src/events.ts",
|
|
46
|
+
"default": "./dist/events.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"files": [
|
|
50
|
+
"src",
|
|
51
|
+
"dist",
|
|
52
|
+
"_template"
|
|
53
|
+
],
|
|
54
|
+
"scripts": {
|
|
55
|
+
"build": "tsc -p tsconfig.json",
|
|
56
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
57
|
+
"prepublishOnly": "pnpm build"
|
|
58
|
+
},
|
|
59
|
+
"dependencies": {
|
|
60
|
+
"zod": "^4.6.7"
|
|
61
|
+
},
|
|
62
|
+
"publishConfig": {
|
|
63
|
+
"access": "public"
|
|
64
|
+
},
|
|
65
|
+
"keywords": [
|
|
66
|
+
"dumby",
|
|
67
|
+
"swastik",
|
|
68
|
+
"module",
|
|
69
|
+
"sdk"
|
|
70
|
+
],
|
|
71
|
+
"license": "MIT",
|
|
72
|
+
"engines": {
|
|
73
|
+
"node": ">=22"
|
|
74
|
+
},
|
|
75
|
+
"repository": {
|
|
76
|
+
"type": "git",
|
|
77
|
+
"url": "git+https://github.com/master-ronix/Dumby-Suite.git",
|
|
78
|
+
"directory": "packages/swastik"
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The module capability surface — what a module is allowed to reach inside the core base.
|
|
3
|
+
*
|
|
4
|
+
* POLICY (operator directive, 2026-10-27): a module owner or developer must never be handed the
|
|
5
|
+
* internal core base. Core and Admin modules are specialised and optimised for the framework and may
|
|
6
|
+
* reach it; Standard and Marketplace modules may not — not the database, not the command registry,
|
|
7
|
+
* not the scheduler, not the internal event bus.
|
|
8
|
+
*
|
|
9
|
+
* This file is the ONE list. `apps/main/src/module-system/module-capabilities.ts` enforces it at
|
|
10
|
+
* load time by handing every module a guarded container, and `packages/modules/eslint.config.mjs`
|
|
11
|
+
* enforces the static half by refusing cross-module and core-internal imports.
|
|
12
|
+
*
|
|
13
|
+
* Naming: a capability is a verb-shaped permission, never a token name, so the surface stays stable
|
|
14
|
+
* when a token is renamed.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Every capability the framework knows. A module's tier decides which of these it may hold. */
|
|
18
|
+
export const moduleCapabilities = [
|
|
19
|
+
// --- baseline: every tier, because a module cannot present itself without these ---
|
|
20
|
+
'logging',
|
|
21
|
+
'config.read',
|
|
22
|
+
'cache',
|
|
23
|
+
'metrics',
|
|
24
|
+
'i18n',
|
|
25
|
+
'presentation.render',
|
|
26
|
+
'permissions.resolve',
|
|
27
|
+
'permissions.grants',
|
|
28
|
+
'global.data.emit',
|
|
29
|
+
|
|
30
|
+
// --- core/admin only: the internal core base ---
|
|
31
|
+
'data.sql',
|
|
32
|
+
'modules.registry',
|
|
33
|
+
'commands.registry',
|
|
34
|
+
'commands.router',
|
|
35
|
+
'commands.ceiling',
|
|
36
|
+
'commands.collisions',
|
|
37
|
+
'events.bus',
|
|
38
|
+
'events.router',
|
|
39
|
+
'process.schedule',
|
|
40
|
+
'process.queue',
|
|
41
|
+
// RESERVED — no token maps to this, so no tier can be granted it (2026-11-16). It is kept in the
|
|
42
|
+
// published type because a capability that was withdrawn from a public union is a breaking change
|
|
43
|
+
// for anyone who names it, and because the name records the intent: worker-thread execution for a
|
|
44
|
+
// module's own jobs. `TOKEN_CAPABILITIES` in apps/main/src/module-system/module-capabilities.ts is
|
|
45
|
+
// the map that decides what a module may reach, and it maps nothing to this — so declaring it here
|
|
46
|
+
// grants nothing and opens nothing. If it is ever implemented, add the token there first; this line
|
|
47
|
+
// is the record that the capability is a name and not a hole.
|
|
48
|
+
'process.workers',
|
|
49
|
+
'personas',
|
|
50
|
+
'admin.eval',
|
|
51
|
+
'auth.oauth2',
|
|
52
|
+
'analytics.mtp',
|
|
53
|
+
'interactions.registry',
|
|
54
|
+
] as const;
|
|
55
|
+
|
|
56
|
+
export type ModuleCapability = (typeof moduleCapabilities)[number];
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* The capabilities every tier holds. These are presentation and plumbing: they let a module log, read
|
|
60
|
+
* its own config, cache its own values, measure itself, translate its own strings, render through the
|
|
61
|
+
* core renderer, ask the permission resolver, and share data on the global emit channel.
|
|
62
|
+
*/
|
|
63
|
+
export const baselineCapabilities = [
|
|
64
|
+
'logging',
|
|
65
|
+
'config.read',
|
|
66
|
+
'cache',
|
|
67
|
+
'metrics',
|
|
68
|
+
'i18n',
|
|
69
|
+
'presentation.render',
|
|
70
|
+
'permissions.resolve',
|
|
71
|
+
/**
|
|
72
|
+
* UR-20261120-154 — reading and writing the guild's permit grants, through a surface that enforces the
|
|
73
|
+
* override boundary ON THE CORE SIDE.
|
|
74
|
+
*
|
|
75
|
+
* It is baseline, and that is a correction. UR-20261120-152 made it core-only, which the guard refuses for
|
|
76
|
+
* EVERY tier — `capabilitiesForTier` returns the baseline for all of them, deliberately, since a tier used to
|
|
77
|
+
* hand Core and Admin SQL and the command registry. So the permit module could never reach it and the module
|
|
78
|
+
* failed to load, taking production down.
|
|
79
|
+
*
|
|
80
|
+
* The danger was never "a module may call the surface". It was "a module may write `rbac_grants` directly and
|
|
81
|
+
* skip `grantBoundaryViolation`" — and a surface that cannot express those writes cannot make that mistake.
|
|
82
|
+
* This is the same shape as `permissions.resolve`, which every tier already holds.
|
|
83
|
+
*/
|
|
84
|
+
'permissions.grants',
|
|
85
|
+
'global.data.emit',
|
|
86
|
+
] as const satisfies readonly ModuleCapability[];
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* The capabilities that reach the internal core base — SQL, the command registry and router, the
|
|
90
|
+
* scheduler and queue, the internal event bus and router, personas, the admin eval gate, OAuth2, the
|
|
91
|
+
* MTP token calculator and the interaction registry. Core and Admin hold all of them; Standard and
|
|
92
|
+
* Marketplace hold none.
|
|
93
|
+
*/
|
|
94
|
+
export const coreOnlyCapabilities = moduleCapabilities.filter(
|
|
95
|
+
(capability) => !(baselineCapabilities as readonly string[]).includes(capability),
|
|
96
|
+
) as readonly ModuleCapability[];
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* The global data emit channel — the ONLY sanctioned way one module shares data with another.
|
|
100
|
+
*
|
|
101
|
+
* It carries data, never behaviour: a payload must be JSON, so no handle, function, class instance or
|
|
102
|
+
* database client can travel through it. The channel is topic-namespaced and every delivery is
|
|
103
|
+
* stamped with the emitting module, so a consumer knows the source and gets nothing else.
|
|
104
|
+
*
|
|
105
|
+
* A module can never subscribe to another module's internal events: the internal event bus is not a
|
|
106
|
+
* capability any non-core tier holds. Isolation is therefore structural, not a convention.
|
|
107
|
+
*/
|
|
108
|
+
export interface GlobalDataEmit {
|
|
109
|
+
/**
|
|
110
|
+
* Publish data on `topic`. The topic is namespaced and the delivery is stamped with this module.
|
|
111
|
+
*
|
|
112
|
+
* `key` marks the delivery PRIVATE: anyone may emit, but only a subscriber that presented the same
|
|
113
|
+
* key receives it. Omit it for a public topic.
|
|
114
|
+
*/
|
|
115
|
+
emit(topic: string, payload: JsonValue, key?: string): void;
|
|
116
|
+
/**
|
|
117
|
+
* Subscribe to a topic. Returns the unsubscribe function.
|
|
118
|
+
*
|
|
119
|
+
* `key` is the credential for a PRIVATE topic: a subscriber that presents a key receives only
|
|
120
|
+
* deliveries stamped with that same key, and a subscriber that presents none receives only public
|
|
121
|
+
* ones. A module cannot join a private topic it has not been given the key for.
|
|
122
|
+
*/
|
|
123
|
+
on(topic: string, handler: (delivery: GlobalDataDelivery) => void, key?: string): () => void;
|
|
124
|
+
/**
|
|
125
|
+
* Ask the CORE to act, and await its answer — the request/response half of the channel.
|
|
126
|
+
*
|
|
127
|
+
* The verbs are whatever the CORE registered (`GLOBAL_DATA_BUILTIN_VERBS` lists today's). A verb
|
|
128
|
+
* nobody registered is refused by the responder, so the channel stays a contract, not a back door. The reply is the framework's answer to that verb, not
|
|
129
|
+
* the emitting module's, so a caller can tell a real result from a module talking to itself.
|
|
130
|
+
*/
|
|
131
|
+
ask(
|
|
132
|
+
verb: GlobalDataRequestVerb,
|
|
133
|
+
payload: JsonValue,
|
|
134
|
+
timeoutMs?: number,
|
|
135
|
+
): Promise<GlobalDataReply>;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* What a module may ASK the core to do. Fixed on purpose: an open-ended verb would be an open-ended
|
|
140
|
+
* API surface, which is exactly what the module boundary exists to prevent.
|
|
141
|
+
*/
|
|
142
|
+
export type GlobalDataRequestVerb = string;
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The verbs the framework wires TODAY. A convenience list for readers and tests — NOT the limit.
|
|
146
|
+
*
|
|
147
|
+
* A deployment registers whatever verbs it actually offers, and `ask()` accepts any verb the core has
|
|
148
|
+
* registered. A closed union would freeze the channel at whatever the first author thought of, which is
|
|
149
|
+
* precisely what a coordination surface must not do: the core decides what it answers, and a module
|
|
150
|
+
* cannot invent a capability by spelling its name.
|
|
151
|
+
*/
|
|
152
|
+
export const GLOBAL_DATA_BUILTIN_VERBS = [
|
|
153
|
+
'install',
|
|
154
|
+
'disable',
|
|
155
|
+
'enable',
|
|
156
|
+
'persona-setup',
|
|
157
|
+
'module-info',
|
|
158
|
+
'queue-bccm',
|
|
159
|
+
'commands',
|
|
160
|
+
'health',
|
|
161
|
+
'guild-profiles',
|
|
162
|
+
] as const;
|
|
163
|
+
|
|
164
|
+
export interface GlobalDataReply {
|
|
165
|
+
readonly verb: GlobalDataRequestVerb;
|
|
166
|
+
readonly ok: boolean;
|
|
167
|
+
/** The framework's answer for this verb, or the refusal reason when `ok` is false. */
|
|
168
|
+
readonly data?: JsonValue;
|
|
169
|
+
readonly error?: string;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface GlobalDataDelivery {
|
|
173
|
+
/** The module that emitted this delivery. Stamped by the framework; never supplied by a caller. */
|
|
174
|
+
readonly source: string;
|
|
175
|
+
readonly topic: string;
|
|
176
|
+
readonly payload: JsonValue;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export type JsonValue =
|
|
180
|
+
string | number | boolean | null | JsonValue[] | { [key: string]: JsonValue };
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* What a module receives in place of the raw container. It IS the container, narrowed: the guard
|
|
184
|
+
* intercepts `resolve`/`tryResolve`/`has`/`register` and refuses anything its tier does not hold.
|
|
185
|
+
*/
|
|
186
|
+
export interface ModuleRuntimeExtras {
|
|
187
|
+
readonly moduleId: string;
|
|
188
|
+
readonly tier: string;
|
|
189
|
+
/** The capabilities this module actually holds — the tier's set, narrowed to what it may use. */
|
|
190
|
+
readonly capabilities: readonly ModuleCapability[];
|
|
191
|
+
readonly globalData: GlobalDataEmit;
|
|
192
|
+
/** Does this module hold `capability`? (`has` itself stays the container's token query.) */
|
|
193
|
+
hasCapability(capability: ModuleCapability): boolean;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
export type ModuleRuntime<Container = unknown> = Container & ModuleRuntimeExtras;
|