@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.
Files changed (66) hide show
  1. package/_template/README.md +34 -0
  2. package/_template/assets/.gitkeep +1 -0
  3. package/_template/commands/.gitkeep +1 -0
  4. package/_template/config/.gitkeep +1 -0
  5. package/_template/events/.gitkeep +1 -0
  6. package/_template/jobs/.gitkeep +1 -0
  7. package/_template/locales/.gitkeep +1 -0
  8. package/_template/manifest.ts +13 -0
  9. package/_template/migrations/.gitkeep +1 -0
  10. package/_template/repositories/.gitkeep +1 -0
  11. package/_template/services/.gitkeep +1 -0
  12. package/_template/tests/.gitkeep +1 -0
  13. package/_template/ui/.gitkeep +1 -0
  14. package/dist/capabilities.d.ts +110 -0
  15. package/dist/capabilities.js +107 -0
  16. package/dist/commands.d.ts +157 -0
  17. package/dist/commands.js +9 -0
  18. package/dist/components-v2.d.ts +252 -0
  19. package/dist/components-v2.js +263 -0
  20. package/dist/components.d.ts +142 -0
  21. package/dist/components.js +11 -0
  22. package/dist/context.d.ts +59 -0
  23. package/dist/context.js +29 -0
  24. package/dist/entrypoints/admin.d.ts +26 -0
  25. package/dist/entrypoints/admin.js +2 -0
  26. package/dist/entrypoints/core.d.ts +31 -0
  27. package/dist/entrypoints/core.js +2 -0
  28. package/dist/entrypoints/marketplace.d.ts +30 -0
  29. package/dist/entrypoints/marketplace.js +2 -0
  30. package/dist/entrypoints/standard.d.ts +36 -0
  31. package/dist/entrypoints/standard.js +2 -0
  32. package/dist/events.d.ts +15 -0
  33. package/dist/events.js +19 -0
  34. package/dist/index.d.ts +27 -0
  35. package/dist/index.js +21 -0
  36. package/dist/manifest-schema.d.ts +261 -0
  37. package/dist/manifest-schema.js +297 -0
  38. package/dist/manifest.d.ts +47 -0
  39. package/dist/manifest.js +6 -0
  40. package/dist/pages.d.ts +274 -0
  41. package/dist/pages.js +3 -0
  42. package/dist/paging.d.ts +32 -0
  43. package/dist/paging.js +59 -0
  44. package/dist/permits.d.ts +222 -0
  45. package/dist/permits.js +16 -0
  46. package/dist/validate.d.ts +21 -0
  47. package/dist/validate.js +33 -0
  48. package/package.json +78 -4
  49. package/src/capabilities.ts +196 -0
  50. package/src/commands.ts +181 -0
  51. package/src/components-v2.ts +533 -0
  52. package/src/components.ts +162 -0
  53. package/src/context.ts +83 -0
  54. package/src/entrypoints/admin.ts +36 -0
  55. package/src/entrypoints/core.ts +41 -0
  56. package/src/entrypoints/marketplace.ts +38 -0
  57. package/src/entrypoints/standard.ts +44 -0
  58. package/src/events.ts +34 -0
  59. package/src/index.ts +159 -0
  60. package/src/manifest-schema.ts +340 -0
  61. package/src/manifest.ts +68 -0
  62. package/src/pages.ts +282 -0
  63. package/src/paging.ts +72 -0
  64. package/src/permits.ts +250 -0
  65. package/src/validate.ts +42 -0
  66. package/README.md +0 -3
@@ -0,0 +1,162 @@
1
+ import type { ComponentsV2Message, ModalPayload } from './components-v2.js';
2
+
3
+ /**
4
+ * UR-20261116-132 \u2014 the COMPONENT surface: a module owns the control AND the answer to it.
5
+ *
6
+ * The gap this closes. `UR-20261031-120` gave modules the Components V2 vocabulary so that a
7
+ * module-specific card \u2014 the persona OAuth redirect guide \u2014 could leave the core. It moved the
8
+ * vocabulary and stopped there, because the card was not the whole problem: the CONTROL that opens it
9
+ * (`dumby:persona-setup:<invoker>:<applicationId>`) is built by the persona module's blocks, while the
10
+ * handler for that prefix was registered by core in `interactions/core-frame.handlers.ts`. So core still
11
+ * carried a persona-shaped branch \u2014 the prefix string and the callback that built the card \u2014 which is
12
+ * what `SPEC-01-FOUNDATIONS-0001` \u00a71.2's consequence check forbids: "an admin command implemented as
13
+ * inline framework code instead of a module".
14
+ *
15
+ * The contract now has a fifth entry point. A module declares the prefixes it owns in its manifest and
16
+ * exports the handlers; the loader registers them with the interaction registry, exactly as it already
17
+ * registers `pages`. Core stops knowing any module's customId.
18
+ *
19
+ * WHAT THE HOST DOES, AND WHY THAT IS NOT A LEAK. The module returns a MESSAGE; the host performs the
20
+ * acknowledgement and the `editReply`. Acknowledgement is a property of the interaction, not of the
21
+ * module's intent \u2014 Discord requires it within three seconds and the mode (update, ephemeral, none)
22
+ * decides whether the page is replaced, a private card is opened, or nothing is sent. A module that had
23
+ * to acknowledge would need the raw interaction object, which is a core type; a module that returns a
24
+ * message and declares its `ack` does not.
25
+ */
26
+ export interface ComponentInvocation {
27
+ /** The full customId, as Discord sent it. */
28
+ readonly customId: string;
29
+ /** The segments AFTER the declared prefix \u2014 `dumby:persona-setup:u1:999` gives `['u1', '999']`. */
30
+ readonly params: readonly string[];
31
+ /** The invoker, when the customId carries one. */
32
+ readonly invokerId?: string;
33
+ /** The profile whose control this was, when the interaction reports one. */
34
+ readonly applicationId?: string;
35
+ /** The guild the interaction happened in. */
36
+ readonly guildId?: string;
37
+ /**
38
+ * UR-20261120-153 — the chosen values, when the control was a SELECT MENU.
39
+ *
40
+ * `params` come from the customId, which a select does not change: its choice arrives in `values`. Without
41
+ * this a module could render a menu and never learn what was picked, which is why the permit console could
42
+ * not have been built on selects alone.
43
+ */
44
+ readonly values?: readonly string[];
45
+ /**
46
+ * UR-20261123-190 (P3b) — the fields a MODAL SUBMISSION carried, keyed by the input's `custom_id`.
47
+ *
48
+ * A modal answers through `fields.getTextInputValue(name)`, which is not `values`: `values` is a select
49
+ * menu's choice and arrives with the component interaction, while these arrive only on submit. Without them
50
+ * a module could open a text input and never learn what was typed — which is why the framework's one modal
51
+ * (`/browse`'s Discover) had to be special-cased in core, by name, field and module.
52
+ */
53
+ readonly fields?: Readonly<Record<string, string>>;
54
+ }
55
+
56
+ /**
57
+ * How the host should acknowledge before the module's answer is sent.
58
+ *
59
+ * - `update` (default) \u2014 the component's own message is edited in place; the page stays where it is.
60
+ * - `ephemeral` \u2014 a PRIVATE message. Used for anything that shows an operator a credential, a URL or a
61
+ * refusal: the interaction's response is private, so the answer is too.
62
+ * - `none` \u2014 nothing is acknowledged here; the module's answer opens a modal or is sent by other means.
63
+ */
64
+ export type ComponentAck = 'update' | 'ephemeral' | 'none';
65
+
66
+ /** The rank vocabulary a control uses — the same names a command's `permissions.rbac` accepts. */
67
+ export type ComponentRbacRequirement =
68
+ 'RESTRICTED' | 'MEMBER' | 'HELPER' | 'MOD' | 'ADMIN' | 'OWNER';
69
+
70
+ export interface ComponentHandlerDefinition {
71
+ /**
72
+ * The customId prefix this handler owns, e.g. `dumby:persona-setup:`.
73
+ *
74
+ * It MUST also be declared in the manifest's `components`, and the loader refuses a handler whose
75
+ * prefix is not declared \u2014 the manifest is the complete table of contents, and a control a module
76
+ * answers but does not declare is exactly the kind of hidden surface the contract exists to prevent.
77
+ */
78
+ readonly customIdPrefix: string;
79
+ /** Defaults to `update`. */
80
+ readonly ack?: ComponentAck;
81
+ /**
82
+ * UR-20261119-147 — the rank a member must hold to USE this control.
83
+ *
84
+ * A command's requirement gates the command; this gates one action inside it. `/browse` may be open to
85
+ * everyone while its install control is not — which is the distinction the backend did not have: every
86
+ * control was open because `ComponentHandlerDefinition` carried no requirement at all.
87
+ *
88
+ * The same rank names a command uses, so an author has one vocabulary:
89
+ * `RESTRICTED | MEMBER | HELPER | MOD | ADMIN | OWNER`. Absent means the control inherits the command's
90
+ * posture, which is today's behaviour and therefore no regression.
91
+ */
92
+ readonly permissions?: { readonly rbac?: ComponentRbacRequirement };
93
+ /**
94
+ * The reason shown when a member who fails `permissions` sees this control.
95
+ *
96
+ * Rendered by the card itself, so the member is told what the control needs instead of discovering it by
97
+ * clicking. Optional: absent, the card decides, and the control is refused at dispatch with the standard
98
+ * one-line denial.
99
+ */
100
+ readonly deniedReason?: string;
101
+ /**
102
+ * Build the answer.
103
+ *
104
+ * Returning `undefined` means "acknowledged, nothing to say" \u2014 a legitimate outcome for an `update`
105
+ * that changes nothing. The host sends nothing in that case.
106
+ */
107
+ readonly build: (
108
+ invocation: ComponentInvocation,
109
+ ) =>
110
+ | Promise<ModalPayload | BlockPayload | NoticePayload | undefined>
111
+ | ComponentsV2Message
112
+ | ModalPayload
113
+ | BlockPayload
114
+ | undefined;
115
+ }
116
+
117
+ /**
118
+ * UR-20261124-203 — A HANDLER MAY ANSWER WITH BLOCKS INSTEAD OF A MESSAGE.
119
+ *
120
+ * A message returned from here goes straight to `editReply`, so the framework's chrome — banner, accent, title
121
+ * row, footer — is never applied, and a re-render comes out as a bare notice while the first render, which went
122
+ * through the page path, is framed. That is the inconsistency reported on /permit on 2026-11-24.
123
+ *
124
+ * A `BlockPayload` is routed through `renderer.render()` by the adapter, exactly as a page's blocks are, so the
125
+ * chrome is applied on every render and the first and the thousandth look the same. The module declares blocks;
126
+ * the framework frames them.
127
+ *
128
+ * Structurally typed rather than importing the renderer's `RenderBlock`, because a module may not reach into
129
+ * `apps/main` — the adapter validates the shape before it renders.
130
+ */
131
+ /**
132
+ * UR-20261126-241 — A NOTICE IS ITS OWN SIGNAL, NOT A BLOCK.
133
+ *
134
+ * The owner's rule: enforcement follows the FINAL STATE of the signal. A private ephemeral answer and a public
135
+ * page are two grammars with their own templates — standard (banner, band, accent, footer) and notice (compact,
136
+ * none of them). A module states WHICH; the renderer decides HOW.
137
+ *
138
+ * Returning blocks for a notice was wrong for exactly that reason: it went through `render()` and came back
139
+ * wearing the standard grammar on an ephemeral message.
140
+ */
141
+ export interface NoticePayload {
142
+ /** The one line the member is told. The renderer supplies the rest of the notice grammar. */
143
+ readonly notice: string;
144
+ }
145
+
146
+ export interface BlockPayload {
147
+ readonly blocks: readonly Readonly<Record<string, unknown>>[];
148
+ }
149
+
150
+ /** A module's declared component surface, as exported from its entry point. */
151
+ export type ComponentHandlers = readonly ComponentHandlerDefinition[];
152
+
153
+ /**
154
+ * Read the segments after a prefix. Exported so a module can test its own `parse` without the host.
155
+ */
156
+ export function componentParams(customId: string, prefix: string): readonly string[] {
157
+ if (!customId.startsWith(prefix)) return [];
158
+ return customId
159
+ .slice(prefix.length)
160
+ .split(':')
161
+ .filter((part) => part !== '');
162
+ }
package/src/context.ts ADDED
@@ -0,0 +1,83 @@
1
+ import type { ExecutionIdentity, ModuleStanding } from './commands.js';
2
+
3
+ /**
4
+ * UR-20261012-070 — the module EXECUTION CONTEXT, for entry points that are not a command.
5
+ *
6
+ * UR-20261012-067 gave a command an `identity` and a `module` standing, because a command has an
7
+ * interaction to carry them. A module's other entry points do not: a gateway event handler receives
8
+ * Discord's own arguments, a job processor receives its payload, and a cron task receives nothing at
9
+ * all. So the same question — *which profile is running this, and where* — had no answer on three of
10
+ * the four paths, and the answer is exactly what a module needs to behave correctly when the main bot
11
+ * and a persona both run it in different guilds.
12
+ *
13
+ * Passing a context as a parameter was rejected for the event path: a handler already receives a
14
+ * variable argument list, so an appended context is invisible to a rest parameter and a prepended one
15
+ * silently breaks every existing handler. The context is therefore carried out-of-band — but the SDK
16
+ * stays environment-neutral (no Node builtins, no `@types/node`), so the CARRIER is installed by the
17
+ * host and the SDK only declares the shape. See `ModuleContextStore`.
18
+ *
19
+ * ```ts
20
+ * const context = currentModuleContext();
21
+ * if (context?.standing.ownedByCaller) {
22
+ * // this profile holds the module in this guild
23
+ * }
24
+ * ```
25
+ */
26
+ export type ModuleEntryPoint = 'command' | 'event' | 'job' | 'task';
27
+
28
+ export interface ModuleExecutionContext {
29
+ /** The module this work belongs to. */
30
+ readonly moduleId: string;
31
+ /** Which of the four paths is running it. */
32
+ readonly source: ModuleEntryPoint;
33
+ /** Who is running it and where — the same shape a command receives. */
34
+ readonly identity: ExecutionIdentity;
35
+ /** This module's own standing in that guild — the same shape a command receives. */
36
+ readonly standing: ModuleStanding;
37
+ }
38
+
39
+ /**
40
+ * The carrier. The host installs an implementation (the app uses `AsyncLocalStorage`, so the context
41
+ * propagates through awaits and callbacks); the SDK never depends on one, which is what keeps this
42
+ * package free of Node builtins.
43
+ */
44
+ export interface ModuleContextStore {
45
+ get(): ModuleExecutionContext | undefined;
46
+ run<T>(context: ModuleExecutionContext, fn: () => T): T;
47
+ }
48
+
49
+ let store: ModuleContextStore | undefined;
50
+
51
+ /** Install the carrier. Called once by the host at boot. */
52
+ export function installModuleContextStore(next: ModuleContextStore): void {
53
+ store = next;
54
+ }
55
+
56
+ /**
57
+ * Run `fn` with the module context attached. The HOST calls this, once per entry point; a module
58
+ * never calls it. With no store installed this is a plain call, so the framework behaves exactly as
59
+ * it did before.
60
+ */
61
+ export function runWithModuleContext<T>(context: ModuleExecutionContext, fn: () => T): T {
62
+ return store === undefined ? fn() : store.run(context, fn);
63
+ }
64
+
65
+ /** The context of the work currently running, or `undefined` outside a module entry point. */
66
+ export function currentModuleContext(): ModuleExecutionContext | undefined {
67
+ return store?.get();
68
+ }
69
+
70
+ /**
71
+ * The context, or a throw naming the reason. For a module whose logic is meaningless without knowing
72
+ * whose signal it is answering — better a loud failure than a silent guess at the wrong guild.
73
+ */
74
+ export function requireModuleContext(): ModuleExecutionContext {
75
+ const context = store?.get();
76
+ if (context === undefined) {
77
+ throw new Error(
78
+ 'No module execution context is active. This work is not running inside a module entry point, ' +
79
+ 'so the framework cannot say which profile is running it or where.',
80
+ );
81
+ }
82
+ return context;
83
+ }
@@ -0,0 +1,36 @@
1
+ /**
2
+ * DEPRECATED — nothing imports this file, and the tier distinction it was built to express is not the
3
+ * one the framework now enforces (recorded 2026-11-16).
4
+ *
5
+ * The four tier entrypoints were byte-identical apart from their doc comments: they re-exported the
6
+ * same surface, so a module's tier differed in name only. The framework has since moved the tier
7
+ * decision off the import path entirely — `capabilitiesForTier` returns the same baseline for every
8
+ * tier, and what a module may actually reach is decided by the guarded container at load time, not by
9
+ * which entrypoint it imported. `moduleTiers` (the list) is live and used; these files are not.
10
+ *
11
+ * It is kept, not deleted, because the four subpaths are declared in `package.json` and withdrawing a
12
+ * published subpath is a breaking change for a consumer that names one — and the package has not yet
13
+ * been published, so the removal can be taken deliberately with a version bump rather than by
14
+ * accident. Nothing should start importing this file: take behaviour from the SDK root and reach the
15
+ * container through the capabilities the loader grants.
16
+ */
17
+ /**
18
+ * The ADMIN tier entrypoint — identical in surface to `core.ts`, and deliberately so.
19
+ *
20
+ * POLICY (operator directive, 2026-10-27): the admin tier is the operator's own tier. It holds the
21
+ * same capabilities as core, plus the tier rules the manifest schema enforces (`devGuildOnly: true`).
22
+ * It is not a wider surface than core: no tier reaches further than the internal core base.
23
+ */
24
+ export type { ModuleCommandManifest, ModuleManifest, SwastikModule } from '../manifest.js';
25
+ export { defineModule } from '../manifest.js';
26
+ export {
27
+ baselineCapabilities,
28
+ coreOnlyCapabilities,
29
+ moduleCapabilities,
30
+ type GlobalDataDelivery,
31
+ type GlobalDataEmit,
32
+ type JsonValue,
33
+ type ModuleCapability,
34
+ type ModuleRuntime,
35
+ type ModuleRuntimeExtras,
36
+ } from '../capabilities.js';
@@ -0,0 +1,41 @@
1
+ /**
2
+ * DEPRECATED — nothing imports this file, and the tier distinction it was built to express is not the
3
+ * one the framework now enforces (recorded 2026-11-16).
4
+ *
5
+ * The four tier entrypoints were byte-identical apart from their doc comments: they re-exported the
6
+ * same surface, so a module's tier differed in name only. The framework has since moved the tier
7
+ * decision off the import path entirely — `capabilitiesForTier` returns the same baseline for every
8
+ * tier, and what a module may actually reach is decided by the guarded container at load time, not by
9
+ * which entrypoint it imported. `moduleTiers` (the list) is live and used; these files are not.
10
+ *
11
+ * It is kept, not deleted, because the four subpaths are declared in `package.json` and withdrawing a
12
+ * published subpath is a breaking change for a consumer that names one — and the package has not yet
13
+ * been published, so the removal can be taken deliberately with a version bump rather than by
14
+ * accident. Nothing should start importing this file: take behaviour from the SDK root and reach the
15
+ * container through the capabilities the loader grants.
16
+ */
17
+ /**
18
+ * The CORE tier entrypoint — for a module that owns part of the internal core base.
19
+ *
20
+ * POLICY (operator directive, 2026-10-27): core and admin modules are specialised and optimised for
21
+ * the framework. They may reach the database, the command registry and router, the scheduler, the
22
+ * queue, the internal event bus and router, personas, the admin eval gate, OAuth2, the MTP token
23
+ * calculator and the interaction registry — because administering those surfaces IS their job.
24
+ *
25
+ * A standard or marketplace module must not import this file. The static half of that rule is
26
+ * enforced by `packages/modules/eslint.config.mjs`; the runtime half by the guarded container the
27
+ * loader hands every module, which refuses a capability its tier does not hold.
28
+ */
29
+ export type { ModuleCommandManifest, ModuleManifest, SwastikModule } from '../manifest.js';
30
+ export { defineModule } from '../manifest.js';
31
+ export {
32
+ baselineCapabilities,
33
+ coreOnlyCapabilities,
34
+ moduleCapabilities,
35
+ type GlobalDataDelivery,
36
+ type GlobalDataEmit,
37
+ type JsonValue,
38
+ type ModuleCapability,
39
+ type ModuleRuntime,
40
+ type ModuleRuntimeExtras,
41
+ } from '../capabilities.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * DEPRECATED — nothing imports this file, and the tier distinction it was built to express is not the
3
+ * one the framework now enforces (recorded 2026-11-16).
4
+ *
5
+ * The four tier entrypoints were byte-identical apart from their doc comments: they re-exported the
6
+ * same surface, so a module's tier differed in name only. The framework has since moved the tier
7
+ * decision off the import path entirely — `capabilitiesForTier` returns the same baseline for every
8
+ * tier, and what a module may actually reach is decided by the guarded container at load time, not by
9
+ * which entrypoint it imported. `moduleTiers` (the list) is live and used; these files are not.
10
+ *
11
+ * It is kept, not deleted, because the four subpaths are declared in `package.json` and withdrawing a
12
+ * published subpath is a breaking change for a consumer that names one — and the package has not yet
13
+ * been published, so the removal can be taken deliberately with a version bump rather than by
14
+ * accident. Nothing should start importing this file: take behaviour from the SDK root and reach the
15
+ * container through the capabilities the loader grants.
16
+ */
17
+ /**
18
+ * The MARKETPLACE tier entrypoint — for a third-party module.
19
+ *
20
+ * POLICY (operator directive, 2026-10-27): a marketplace module is a guest in the framework. Its
21
+ * surface is the BASELINE only, exactly as a standard module's, and the internal core base is not
22
+ * part of it. It cannot reach the database, the command registry, the scheduler, the queue, the
23
+ * internal event bus or another module's code — and the framework refuses those at runtime rather
24
+ * than trusting the module not to ask.
25
+ *
26
+ * Sharing with another module happens on the global data emit channel and nowhere else.
27
+ */
28
+ export type { ModuleCommandManifest, ModuleManifest, SwastikModule } from '../manifest.js';
29
+ export { defineModule } from '../manifest.js';
30
+ export {
31
+ baselineCapabilities,
32
+ type GlobalDataDelivery,
33
+ type GlobalDataEmit,
34
+ type JsonValue,
35
+ type ModuleCapability,
36
+ type ModuleRuntime,
37
+ type ModuleRuntimeExtras,
38
+ } from '../capabilities.js';
@@ -0,0 +1,44 @@
1
+ /**
2
+ * DEPRECATED — nothing imports this file, and the tier distinction it was built to express is not the
3
+ * one the framework now enforces (recorded 2026-11-16).
4
+ *
5
+ * The four tier entrypoints were byte-identical apart from their doc comments: they re-exported the
6
+ * same surface, so a module's tier differed in name only. The framework has since moved the tier
7
+ * decision off the import path entirely — `capabilitiesForTier` returns the same baseline for every
8
+ * tier, and what a module may actually reach is decided by the guarded container at load time, not by
9
+ * which entrypoint it imported. `moduleTiers` (the list) is live and used; these files are not.
10
+ *
11
+ * It is kept, not deleted, because the four subpaths are declared in `package.json` and withdrawing a
12
+ * published subpath is a breaking change for a consumer that names one — and the package has not yet
13
+ * been published, so the removal can be taken deliberately with a version bump rather than by
14
+ * accident. Nothing should start importing this file: take behaviour from the SDK root and reach the
15
+ * container through the capabilities the loader grants.
16
+ */
17
+ /**
18
+ * The STANDARD tier entrypoint — for a first-party feature module.
19
+ *
20
+ * POLICY (operator directive, 2026-10-27): a standard module is a feature, not part of the framework.
21
+ * Its surface is the BASELINE only: it logs, reads its own config, caches its own values, measures
22
+ * itself, translates its own strings, renders through the core renderer, asks the permission
23
+ * resolver, and shares data on the global emit channel.
24
+ *
25
+ * It does NOT hold `data.sql`, `commands.registry`, `commands.router`, `events.bus`, `events.router`,
26
+ * `process.schedule`, `process.queue`, `modules.registry`, `personas`, `admin.eval`, `auth.oauth2`,
27
+ * `analytics.mtp` or `interactions.registry`. Those are listed in `coreOnlyCapabilities` and are
28
+ * refused at runtime by the guarded container, so reaching for one fails during the module's own load
29
+ * rather than quietly succeeding.
30
+ *
31
+ * Sharing with another module happens on the global data emit channel and nowhere else: no imports,
32
+ * no direct calls, no subscribing to another module's internal events.
33
+ */
34
+ export type { ModuleCommandManifest, ModuleManifest, SwastikModule } from '../manifest.js';
35
+ export { defineModule } from '../manifest.js';
36
+ export {
37
+ baselineCapabilities,
38
+ type GlobalDataDelivery,
39
+ type GlobalDataEmit,
40
+ type JsonValue,
41
+ type ModuleCapability,
42
+ type ModuleRuntime,
43
+ type ModuleRuntimeExtras,
44
+ } from '../capabilities.js';
package/src/events.ts ADDED
@@ -0,0 +1,34 @@
1
+ import type { z } from 'zod';
2
+ import { eventCatalogEntrySchema } from './manifest-schema.js';
3
+
4
+ /**
5
+ * §18 — the events-catalog declaration helpers. A module declares every event it emits (with a
6
+ * payload schema) in its manifest `eventsCatalog`; the emit/subscribe surface is checked against
7
+ * that catalog, so a module cannot emit an undeclared event.
8
+ */
9
+ export type EventCatalogEntry = z.infer<typeof eventCatalogEntrySchema>;
10
+
11
+ export function defineEvent(
12
+ name: string,
13
+ description: string,
14
+ payload: Record<string, unknown>,
15
+ ): EventCatalogEntry {
16
+ return eventCatalogEntrySchema.parse({ name, description, payload });
17
+ }
18
+
19
+ export class EventCatalogError extends Error {
20
+ constructor(readonly missing: readonly string[]) {
21
+ super(`eventsCatalog is missing entries for emitted events: ${missing.join(', ')}`);
22
+ this.name = 'EventCatalogError';
23
+ }
24
+ }
25
+
26
+ /** Every emitted event name must name a catalog entry (enforced at Stage 11 / module review). */
27
+ export function assertCatalogCoversEvents(
28
+ emittedEventNames: readonly string[],
29
+ catalog: readonly EventCatalogEntry[],
30
+ ): void {
31
+ const declared = new Set(catalog.map((entry) => entry.name));
32
+ const missing = emittedEventNames.filter((name) => !declared.has(name));
33
+ if (missing.length > 0) throw new EventCatalogError(missing);
34
+ }
package/src/index.ts ADDED
@@ -0,0 +1,159 @@
1
+ export type {
2
+ ModuleCommandManifest,
3
+ ModuleLifecycle,
4
+ ModuleManifest,
5
+ ModuleTier,
6
+ SwastikModule,
7
+ } from './manifest.js';
8
+ export { defineModule, isRequiredTier, moduleTiers, moduleManifestSchema } from './manifest.js';
9
+ export { validateManifest } from './validate.js';
10
+ export type {
11
+ CommandContext,
12
+ ExecutionIdentity,
13
+ ModuleStanding,
14
+ CommandDeclaration,
15
+ CommandHandler,
16
+ CommandPageData,
17
+ CommandPermissionsDeclaration,
18
+ CommandRbacRequirement,
19
+ } from './commands.js';
20
+ export { defineCommand } from './commands.js';
21
+ // UR-20261031-131 (OI-19) — the command-registry vocabulary, shared so neither side mirrors the other.
22
+ export type { CommandProfile, CommandDefinitionLike, CommandRegistryLike } from './commands.js';
23
+ export {
24
+ assertCatalogCoversEvents,
25
+ defineEvent,
26
+ EventCatalogError,
27
+ type EventCatalogEntry,
28
+ } from './events.js';
29
+ export type { ModuleEntryPoint, ModuleExecutionContext, ModuleContextStore } from './context.js';
30
+ export {
31
+ currentModuleContext,
32
+ installModuleContextStore,
33
+ requireModuleContext,
34
+ runWithModuleContext,
35
+ } from './context.js';
36
+ export {
37
+ baselineCapabilities,
38
+ GLOBAL_DATA_BUILTIN_VERBS,
39
+ coreOnlyCapabilities,
40
+ moduleCapabilities,
41
+ type GlobalDataDelivery,
42
+ type GlobalDataEmit,
43
+ type GlobalDataReply,
44
+ type GlobalDataRequestVerb,
45
+ type JsonValue,
46
+ type ModuleCapability,
47
+ type ModuleRuntime,
48
+ type ModuleRuntimeExtras,
49
+ } from './capabilities.js';
50
+ export {
51
+ componentParams,
52
+ type ComponentAck,
53
+ type ComponentHandlerDefinition,
54
+ type ComponentRbacRequirement,
55
+ type ComponentHandlers,
56
+ type ComponentInvocation,
57
+ } from './components.js';
58
+ export {
59
+ definePage,
60
+ type ActingProfileFacts,
61
+ type GuildCounts,
62
+ type HostProcessFacts,
63
+ type PendingQueueEntry,
64
+ type PersonaBinding,
65
+ type PersonaRecord,
66
+ type ModulePage,
67
+ type ModulePageContext,
68
+ type ModulePageReadModel,
69
+ type ModuleSummary,
70
+ type SubsystemState,
71
+ } from './pages.js';
72
+
73
+ export { modulePageNavigation, romanNumeral, type PageSlide } from './paging.js';
74
+
75
+ /**
76
+ * UR-20261031-120 — the Components V2 primitive vocabulary.
77
+ *
78
+ * A module returns DATA and BLOCKS, and the framework renders them. That left one surface unable to
79
+ * leave the core: a module-specific card that builds a message directly (`persona-setup`) could not
80
+ * move into its module without importing the core, and the import gate refuses exactly that.
81
+ *
82
+ * The operator's decision: the SDK owns the vocabulary, and rendering stays in the core as a library
83
+ * modules call. So the primitives live here, a module imports them from `@quixotic_mnemonics/swastik`, and the
84
+ * core imports the same file — one definition, no duplication, no core dependency for a module.
85
+ */
86
+ export {
87
+ textDisplay,
88
+ mediaGallery,
89
+ separator,
90
+ container,
91
+ stringSelect,
92
+ userSelect,
93
+ roleSelect,
94
+ mentionableSelect,
95
+ channelSelect,
96
+ button,
97
+ linkButton,
98
+ actionRow,
99
+ thumbnail,
100
+ section,
101
+ textInputModal,
102
+ multiInputModal,
103
+ buildComponentsV2,
104
+ createBannerMediaGallery,
105
+ getDefaultBannerUrl,
106
+ createTitleBlock,
107
+ createMarketplaceTitleBlock,
108
+ createSectionHeader,
109
+ createKeyValueDisplay,
110
+ IS_COMPONENTS_V2,
111
+ EPHEMERAL,
112
+ ComponentType,
113
+ DEFAULT_ACCENT_COLOR,
114
+ DEFAULT_PERSONA_ACCENT,
115
+ type ComponentTypeValue,
116
+ type ComponentBase,
117
+ type TextDisplayComponent,
118
+ type MediaGalleryComponent,
119
+ type SeparatorComponent,
120
+ type ContainerComponent,
121
+ type StringSelectComponent,
122
+ type EntitySelectComponent,
123
+ type ButtonComponent,
124
+ type ActionRowComponent,
125
+ type ThumbnailComponent,
126
+ type SectionComponent,
127
+ type Component,
128
+ type ComponentsV2Message,
129
+ type ModalTextInput,
130
+ type ModalPayload,
131
+ } from './components-v2.js';
132
+
133
+ // UR-20261124-203 — a handler may answer with blocks so the adapter can frame them.
134
+ export type { BlockPayload, NoticePayload } from './components.js';
135
+
136
+ // UR-20261123-190 — the permit surface's shape, shared so core and module compile against ONE declaration.
137
+ export type {
138
+ PermitSurface,
139
+ PixelSummary,
140
+ PixelTarget,
141
+ PixelTargetInput,
142
+ PixelTargetKind,
143
+ PixelEffect,
144
+ PixelQuota,
145
+ PixelState,
146
+ PixelErrorCode,
147
+ PixelResult,
148
+ GrantableCommand,
149
+ // UR-20261124-194 — PMT-DD-002 v2.0, the contract the eight views call.
150
+ PermitV2Surface,
151
+ PermitKind,
152
+ PermitRule,
153
+ PermitQuotaV2,
154
+ PermitCommandRef,
155
+ PermitMemberRef,
156
+ PermitSummary,
157
+ PermitNoticeCode,
158
+ PermitResult,
159
+ } from './permits.js';