@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
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Swastik Module Template
|
|
2
|
+
|
|
3
|
+
This template is the reference authoring layout for a module before upload to Swastik. It is **not**
|
|
4
|
+
loaded from the repository — promoted modules are discovered from the tier volumes under `MODULES_DIR`.
|
|
5
|
+
|
|
6
|
+
## Layout
|
|
7
|
+
|
|
8
|
+
```
|
|
9
|
+
<slug>/
|
|
10
|
+
manifest.json # name, version, tier, devId, commands, events, services, ...
|
|
11
|
+
src/index.ts # exports MODULE_SLUG, commands, onLoad/onReady/onUnload
|
|
12
|
+
src/commands/*.ts # defineCommand(...) from @quixotic_mnemonics/swastik
|
|
13
|
+
events/ jobs/ services/ repositories/ migrations/ locales/ assets/ ui/ tests/ config/
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Building a module in isolation (no main codebase)
|
|
17
|
+
|
|
18
|
+
A module's **only** dependency is the Swastik SDK. You never import the bot.
|
|
19
|
+
|
|
20
|
+
1. **Scaffold** — copy this `_template/` into a new package.
|
|
21
|
+
2. **Install the SDK** — the SDK is publishable; depend on the published version instead of the
|
|
22
|
+
workspace link:
|
|
23
|
+
```json
|
|
24
|
+
{ "dependencies": { "@quixotic_mnemonics/swastik": "^0.1.0" } }
|
|
25
|
+
```
|
|
26
|
+
(In the monorepo it is `"workspace:*"`; in an isolated environment install the published package.)
|
|
27
|
+
3. **Author** — write `manifest.json` (declare `devId`, `tier`, `commands`, …) and `src/index.ts`
|
|
28
|
+
using `defineCommand` / `defineEvent` from `@quixotic_mnemonics/swastik`.
|
|
29
|
+
4. **Typecheck** — `tsc -p tsconfig.json --noEmit` (this template's tsconfig).
|
|
30
|
+
5. **Bundle** — esbuild bundles `src/index.ts` → `index.js` (with the manifest, locales and assets).
|
|
31
|
+
6. **Push** — POST the bundle to a running Swastik:
|
|
32
|
+
`POST <swastik>/internal/deploy { moduleSlug, version, devId, manifest, indexSource }`.
|
|
33
|
+
|
|
34
|
+
The only contracts are the **SDK**, the **shared manifest schema**, and the **Swastik deploy API**.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { defineModule } from "@quixotic_mnemonics/swastik";
|
|
2
|
+
|
|
3
|
+
export default defineModule({
|
|
4
|
+
manifest: {
|
|
5
|
+
name: "template-module",
|
|
6
|
+
version: "0.1.0",
|
|
7
|
+
description: "Template module scaffold.",
|
|
8
|
+
tier: "standard",
|
|
9
|
+
required: false,
|
|
10
|
+
commands: [],
|
|
11
|
+
eventsCatalog: [],
|
|
12
|
+
},
|
|
13
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,110 @@
|
|
|
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
|
+
/** Every capability the framework knows. A module's tier decides which of these it may hold. */
|
|
17
|
+
export declare const moduleCapabilities: readonly ["logging", "config.read", "cache", "metrics", "i18n", "presentation.render", "permissions.resolve", "permissions.grants", "global.data.emit", "data.sql", "modules.registry", "commands.registry", "commands.router", "commands.ceiling", "commands.collisions", "events.bus", "events.router", "process.schedule", "process.queue", "process.workers", "personas", "admin.eval", "auth.oauth2", "analytics.mtp", "interactions.registry"];
|
|
18
|
+
export type ModuleCapability = (typeof moduleCapabilities)[number];
|
|
19
|
+
/**
|
|
20
|
+
* The capabilities every tier holds. These are presentation and plumbing: they let a module log, read
|
|
21
|
+
* its own config, cache its own values, measure itself, translate its own strings, render through the
|
|
22
|
+
* core renderer, ask the permission resolver, and share data on the global emit channel.
|
|
23
|
+
*/
|
|
24
|
+
export declare const baselineCapabilities: readonly ["logging", "config.read", "cache", "metrics", "i18n", "presentation.render", "permissions.resolve", "permissions.grants", "global.data.emit"];
|
|
25
|
+
/**
|
|
26
|
+
* The capabilities that reach the internal core base — SQL, the command registry and router, the
|
|
27
|
+
* scheduler and queue, the internal event bus and router, personas, the admin eval gate, OAuth2, the
|
|
28
|
+
* MTP token calculator and the interaction registry. Core and Admin hold all of them; Standard and
|
|
29
|
+
* Marketplace hold none.
|
|
30
|
+
*/
|
|
31
|
+
export declare const coreOnlyCapabilities: readonly ModuleCapability[];
|
|
32
|
+
/**
|
|
33
|
+
* The global data emit channel — the ONLY sanctioned way one module shares data with another.
|
|
34
|
+
*
|
|
35
|
+
* It carries data, never behaviour: a payload must be JSON, so no handle, function, class instance or
|
|
36
|
+
* database client can travel through it. The channel is topic-namespaced and every delivery is
|
|
37
|
+
* stamped with the emitting module, so a consumer knows the source and gets nothing else.
|
|
38
|
+
*
|
|
39
|
+
* A module can never subscribe to another module's internal events: the internal event bus is not a
|
|
40
|
+
* capability any non-core tier holds. Isolation is therefore structural, not a convention.
|
|
41
|
+
*/
|
|
42
|
+
export interface GlobalDataEmit {
|
|
43
|
+
/**
|
|
44
|
+
* Publish data on `topic`. The topic is namespaced and the delivery is stamped with this module.
|
|
45
|
+
*
|
|
46
|
+
* `key` marks the delivery PRIVATE: anyone may emit, but only a subscriber that presented the same
|
|
47
|
+
* key receives it. Omit it for a public topic.
|
|
48
|
+
*/
|
|
49
|
+
emit(topic: string, payload: JsonValue, key?: string): void;
|
|
50
|
+
/**
|
|
51
|
+
* Subscribe to a topic. Returns the unsubscribe function.
|
|
52
|
+
*
|
|
53
|
+
* `key` is the credential for a PRIVATE topic: a subscriber that presents a key receives only
|
|
54
|
+
* deliveries stamped with that same key, and a subscriber that presents none receives only public
|
|
55
|
+
* ones. A module cannot join a private topic it has not been given the key for.
|
|
56
|
+
*/
|
|
57
|
+
on(topic: string, handler: (delivery: GlobalDataDelivery) => void, key?: string): () => void;
|
|
58
|
+
/**
|
|
59
|
+
* Ask the CORE to act, and await its answer — the request/response half of the channel.
|
|
60
|
+
*
|
|
61
|
+
* The verbs are whatever the CORE registered (`GLOBAL_DATA_BUILTIN_VERBS` lists today's). A verb
|
|
62
|
+
* 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
|
|
63
|
+
* the emitting module's, so a caller can tell a real result from a module talking to itself.
|
|
64
|
+
*/
|
|
65
|
+
ask(verb: GlobalDataRequestVerb, payload: JsonValue, timeoutMs?: number): Promise<GlobalDataReply>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* What a module may ASK the core to do. Fixed on purpose: an open-ended verb would be an open-ended
|
|
69
|
+
* API surface, which is exactly what the module boundary exists to prevent.
|
|
70
|
+
*/
|
|
71
|
+
export type GlobalDataRequestVerb = string;
|
|
72
|
+
/**
|
|
73
|
+
* The verbs the framework wires TODAY. A convenience list for readers and tests — NOT the limit.
|
|
74
|
+
*
|
|
75
|
+
* A deployment registers whatever verbs it actually offers, and `ask()` accepts any verb the core has
|
|
76
|
+
* registered. A closed union would freeze the channel at whatever the first author thought of, which is
|
|
77
|
+
* precisely what a coordination surface must not do: the core decides what it answers, and a module
|
|
78
|
+
* cannot invent a capability by spelling its name.
|
|
79
|
+
*/
|
|
80
|
+
export declare const GLOBAL_DATA_BUILTIN_VERBS: readonly ["install", "disable", "enable", "persona-setup", "module-info", "queue-bccm", "commands", "health", "guild-profiles"];
|
|
81
|
+
export interface GlobalDataReply {
|
|
82
|
+
readonly verb: GlobalDataRequestVerb;
|
|
83
|
+
readonly ok: boolean;
|
|
84
|
+
/** The framework's answer for this verb, or the refusal reason when `ok` is false. */
|
|
85
|
+
readonly data?: JsonValue;
|
|
86
|
+
readonly error?: string;
|
|
87
|
+
}
|
|
88
|
+
export interface GlobalDataDelivery {
|
|
89
|
+
/** The module that emitted this delivery. Stamped by the framework; never supplied by a caller. */
|
|
90
|
+
readonly source: string;
|
|
91
|
+
readonly topic: string;
|
|
92
|
+
readonly payload: JsonValue;
|
|
93
|
+
}
|
|
94
|
+
export type JsonValue = string | number | boolean | null | JsonValue[] | {
|
|
95
|
+
[key: string]: JsonValue;
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* What a module receives in place of the raw container. It IS the container, narrowed: the guard
|
|
99
|
+
* intercepts `resolve`/`tryResolve`/`has`/`register` and refuses anything its tier does not hold.
|
|
100
|
+
*/
|
|
101
|
+
export interface ModuleRuntimeExtras {
|
|
102
|
+
readonly moduleId: string;
|
|
103
|
+
readonly tier: string;
|
|
104
|
+
/** The capabilities this module actually holds — the tier's set, narrowed to what it may use. */
|
|
105
|
+
readonly capabilities: readonly ModuleCapability[];
|
|
106
|
+
readonly globalData: GlobalDataEmit;
|
|
107
|
+
/** Does this module hold `capability`? (`has` itself stays the container's token query.) */
|
|
108
|
+
hasCapability(capability: ModuleCapability): boolean;
|
|
109
|
+
}
|
|
110
|
+
export type ModuleRuntime<Container = unknown> = Container & ModuleRuntimeExtras;
|
|
@@ -0,0 +1,107 @@
|
|
|
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
|
+
/** Every capability the framework knows. A module's tier decides which of these it may hold. */
|
|
17
|
+
export const moduleCapabilities = [
|
|
18
|
+
// --- baseline: every tier, because a module cannot present itself without these ---
|
|
19
|
+
'logging',
|
|
20
|
+
'config.read',
|
|
21
|
+
'cache',
|
|
22
|
+
'metrics',
|
|
23
|
+
'i18n',
|
|
24
|
+
'presentation.render',
|
|
25
|
+
'permissions.resolve',
|
|
26
|
+
'permissions.grants',
|
|
27
|
+
'global.data.emit',
|
|
28
|
+
// --- core/admin only: the internal core base ---
|
|
29
|
+
'data.sql',
|
|
30
|
+
'modules.registry',
|
|
31
|
+
'commands.registry',
|
|
32
|
+
'commands.router',
|
|
33
|
+
'commands.ceiling',
|
|
34
|
+
'commands.collisions',
|
|
35
|
+
'events.bus',
|
|
36
|
+
'events.router',
|
|
37
|
+
'process.schedule',
|
|
38
|
+
'process.queue',
|
|
39
|
+
// RESERVED — no token maps to this, so no tier can be granted it (2026-11-16). It is kept in the
|
|
40
|
+
// published type because a capability that was withdrawn from a public union is a breaking change
|
|
41
|
+
// for anyone who names it, and because the name records the intent: worker-thread execution for a
|
|
42
|
+
// module's own jobs. `TOKEN_CAPABILITIES` in apps/main/src/module-system/module-capabilities.ts is
|
|
43
|
+
// the map that decides what a module may reach, and it maps nothing to this — so declaring it here
|
|
44
|
+
// grants nothing and opens nothing. If it is ever implemented, add the token there first; this line
|
|
45
|
+
// is the record that the capability is a name and not a hole.
|
|
46
|
+
'process.workers',
|
|
47
|
+
'personas',
|
|
48
|
+
'admin.eval',
|
|
49
|
+
'auth.oauth2',
|
|
50
|
+
'analytics.mtp',
|
|
51
|
+
'interactions.registry',
|
|
52
|
+
];
|
|
53
|
+
/**
|
|
54
|
+
* The capabilities every tier holds. These are presentation and plumbing: they let a module log, read
|
|
55
|
+
* its own config, cache its own values, measure itself, translate its own strings, render through the
|
|
56
|
+
* core renderer, ask the permission resolver, and share data on the global emit channel.
|
|
57
|
+
*/
|
|
58
|
+
export const baselineCapabilities = [
|
|
59
|
+
'logging',
|
|
60
|
+
'config.read',
|
|
61
|
+
'cache',
|
|
62
|
+
'metrics',
|
|
63
|
+
'i18n',
|
|
64
|
+
'presentation.render',
|
|
65
|
+
'permissions.resolve',
|
|
66
|
+
/**
|
|
67
|
+
* UR-20261120-154 — reading and writing the guild's permit grants, through a surface that enforces the
|
|
68
|
+
* override boundary ON THE CORE SIDE.
|
|
69
|
+
*
|
|
70
|
+
* It is baseline, and that is a correction. UR-20261120-152 made it core-only, which the guard refuses for
|
|
71
|
+
* EVERY tier — `capabilitiesForTier` returns the baseline for all of them, deliberately, since a tier used to
|
|
72
|
+
* hand Core and Admin SQL and the command registry. So the permit module could never reach it and the module
|
|
73
|
+
* failed to load, taking production down.
|
|
74
|
+
*
|
|
75
|
+
* The danger was never "a module may call the surface". It was "a module may write `rbac_grants` directly and
|
|
76
|
+
* skip `grantBoundaryViolation`" — and a surface that cannot express those writes cannot make that mistake.
|
|
77
|
+
* This is the same shape as `permissions.resolve`, which every tier already holds.
|
|
78
|
+
*/
|
|
79
|
+
'permissions.grants',
|
|
80
|
+
'global.data.emit',
|
|
81
|
+
];
|
|
82
|
+
/**
|
|
83
|
+
* The capabilities that reach the internal core base — SQL, the command registry and router, the
|
|
84
|
+
* scheduler and queue, the internal event bus and router, personas, the admin eval gate, OAuth2, the
|
|
85
|
+
* MTP token calculator and the interaction registry. Core and Admin hold all of them; Standard and
|
|
86
|
+
* Marketplace hold none.
|
|
87
|
+
*/
|
|
88
|
+
export const coreOnlyCapabilities = moduleCapabilities.filter((capability) => !baselineCapabilities.includes(capability));
|
|
89
|
+
/**
|
|
90
|
+
* The verbs the framework wires TODAY. A convenience list for readers and tests — NOT the limit.
|
|
91
|
+
*
|
|
92
|
+
* A deployment registers whatever verbs it actually offers, and `ask()` accepts any verb the core has
|
|
93
|
+
* registered. A closed union would freeze the channel at whatever the first author thought of, which is
|
|
94
|
+
* precisely what a coordination surface must not do: the core decides what it answers, and a module
|
|
95
|
+
* cannot invent a capability by spelling its name.
|
|
96
|
+
*/
|
|
97
|
+
export const GLOBAL_DATA_BUILTIN_VERBS = [
|
|
98
|
+
'install',
|
|
99
|
+
'disable',
|
|
100
|
+
'enable',
|
|
101
|
+
'persona-setup',
|
|
102
|
+
'module-info',
|
|
103
|
+
'queue-bccm',
|
|
104
|
+
'commands',
|
|
105
|
+
'health',
|
|
106
|
+
'guild-profiles',
|
|
107
|
+
];
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { ComponentsV2Message } from './components-v2.js';
|
|
2
|
+
/**
|
|
3
|
+
* §1.7 / interface.md §10.5 — the schema-declared authoring model. A module declares a command
|
|
4
|
+
* schema with `defineCommand` and its handler returns page data; the Renderer derives the whole
|
|
5
|
+
* presentation from that data, so module code never constructs components, embeds or flags.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* §6.7 — a declared side effect. A module cannot reach the host process, so it cannot write to the
|
|
9
|
+
* queue, the database or anything else itself; it declares what should happen and the host
|
|
10
|
+
* performs it, which keeps the handler free of side effects during its own execution.
|
|
11
|
+
*/
|
|
12
|
+
export interface CommandEffect {
|
|
13
|
+
readonly kind: string;
|
|
14
|
+
readonly payload: Readonly<Record<string, unknown>>;
|
|
15
|
+
}
|
|
16
|
+
export interface CommandPageData {
|
|
17
|
+
readonly page: string;
|
|
18
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
19
|
+
readonly effects?: readonly CommandEffect[];
|
|
20
|
+
/**
|
|
21
|
+
* UR-20261120-157 — the module's OWN message, when the answer is interactive rather than a page.
|
|
22
|
+
*
|
|
23
|
+
* A command could only ever return page data, so a module that had built a full Components V2 surface —
|
|
24
|
+
* as it already may from a component handler — could not deliver it from its own command. That is why the
|
|
25
|
+
* permit console was unreachable: `/permit` returned `{ page: 'permit' }` and the core rendered a page that
|
|
26
|
+
* carried none of the console's controls.
|
|
27
|
+
*
|
|
28
|
+
* Present, it IS the answer and the page is not rendered. Absent, nothing changes.
|
|
29
|
+
*/
|
|
30
|
+
readonly message?: ComponentsV2Message;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* §11 (system-map) — WHO a dispatch is running as, and WHERE.
|
|
34
|
+
*
|
|
35
|
+
* The framework hosts the main bot and any number of personas in ONE process. Before this, a module
|
|
36
|
+
* could not tell which of them was running its command: `CommandContext` carried config and page data
|
|
37
|
+
* and nothing about identity, so a handler had no way to know whose signal it was answering, which
|
|
38
|
+
* application it should speak as, or which guild it was bound to. Every module-facing decision that
|
|
39
|
+
* depended on that had to be made by the core on the module's behalf — which is how the core came to
|
|
40
|
+
* hold facts the modules own.
|
|
41
|
+
*
|
|
42
|
+
* This is the module-facing half of the framework's identity: one object, built once at dispatch from
|
|
43
|
+
* the interaction Discord hands us, and never re-derived.
|
|
44
|
+
*/
|
|
45
|
+
export interface ExecutionIdentity {
|
|
46
|
+
/** `'main'` for the main bot, or the persona's id. The profile running this command. */
|
|
47
|
+
readonly profileId: string;
|
|
48
|
+
/** Which of the two this is. A persona is single-guild and can refuse; the main bot serves all. */
|
|
49
|
+
readonly kind: 'main' | 'persona';
|
|
50
|
+
/** The Discord application this identity speaks as — the one that owns its emoji and commands. */
|
|
51
|
+
readonly applicationId: string;
|
|
52
|
+
/** The identity's display name: the bot's username, or the persona's registered name. */
|
|
53
|
+
readonly profileName: string;
|
|
54
|
+
/** The guild the signal came from. `null` in a direct message. */
|
|
55
|
+
readonly guildId: string | null;
|
|
56
|
+
/**
|
|
57
|
+
* The ONE guild this identity serves. Absent for the main bot, which serves every guild it is
|
|
58
|
+
* installed in; present for a persona, which refuses everywhere else.
|
|
59
|
+
*/
|
|
60
|
+
readonly boundGuildId?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* §11 / §13.2 — the module's OWN standing in the guild this dispatch is running in.
|
|
64
|
+
*
|
|
65
|
+
* "Where is this module installed, where is it running, and whose is it." A standard or marketplace
|
|
66
|
+
* module belongs to ONE profile per guild, first come; core belongs to nobody and runs for everyone.
|
|
67
|
+
*/
|
|
68
|
+
export interface ModuleStanding {
|
|
69
|
+
/** The module this command belongs to. */
|
|
70
|
+
readonly moduleId: string;
|
|
71
|
+
/** The module's tier, as its own manifest declares it. */
|
|
72
|
+
readonly tier: 'admin' | 'core' | 'standard' | 'marketplace';
|
|
73
|
+
/** Whether the module is enabled in this guild. Core is always enabled. */
|
|
74
|
+
readonly enabled: boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Which profile HOLDS this module here: `'main'`, a persona id, or `'shared'` for core, which no
|
|
77
|
+
* profile owns and every profile runs.
|
|
78
|
+
*/
|
|
79
|
+
readonly owner: string;
|
|
80
|
+
/** Whether the identity running this dispatch is the one that holds it. */
|
|
81
|
+
readonly ownedByCaller: boolean;
|
|
82
|
+
}
|
|
83
|
+
export interface CommandContext {
|
|
84
|
+
readonly config: Readonly<Record<string, unknown>>;
|
|
85
|
+
/**
|
|
86
|
+
* §11 — who is running this command and where. Always present: a handler that needs to know whose
|
|
87
|
+
* signal it is answering can ask, instead of the core having to decide for it.
|
|
88
|
+
*/
|
|
89
|
+
readonly identity: ExecutionIdentity;
|
|
90
|
+
/**
|
|
91
|
+
* §11 / §13.2 — this module's own standing in that guild: its tier, whether it is enabled, which
|
|
92
|
+
* profile holds it, and whether that is the caller.
|
|
93
|
+
*/
|
|
94
|
+
readonly module: ModuleStanding;
|
|
95
|
+
/**
|
|
96
|
+
* Host-supplied data for the command's declared page. The framework gathers it at dispatch —
|
|
97
|
+
* live metrics, the module registry, queue state, persona bindings — so a module can present
|
|
98
|
+
* runtime state without reaching into the host process itself, which it cannot do. Empty when
|
|
99
|
+
* the host supplies nothing for the module.
|
|
100
|
+
*/
|
|
101
|
+
readonly data: Readonly<Record<string, unknown>>;
|
|
102
|
+
}
|
|
103
|
+
export type CommandHandler = (interaction: unknown, context: CommandContext) => Promise<CommandPageData> | CommandPageData;
|
|
104
|
+
/** Layer 6 vocabulary, canonical short form (blueprint §21). */
|
|
105
|
+
export type CommandRbacRequirement = 'RESTRICTED' | 'MEMBER' | 'HELPER' | 'MOD' | 'ADMIN' | 'OWNER';
|
|
106
|
+
export interface CommandPermissionsDeclaration {
|
|
107
|
+
readonly discord?: readonly string[];
|
|
108
|
+
readonly rbac?: CommandRbacRequirement;
|
|
109
|
+
readonly nsfw?: boolean;
|
|
110
|
+
}
|
|
111
|
+
/** A slash-command option (Discord `ApplicationCommandOptionType` number in `type`). */
|
|
112
|
+
export interface CommandOptionDeclaration {
|
|
113
|
+
readonly name: string;
|
|
114
|
+
readonly description: string;
|
|
115
|
+
readonly type: number;
|
|
116
|
+
readonly required?: boolean;
|
|
117
|
+
readonly autocomplete?: boolean;
|
|
118
|
+
}
|
|
119
|
+
export interface CommandDeclaration {
|
|
120
|
+
readonly name: string;
|
|
121
|
+
readonly description: string;
|
|
122
|
+
readonly pages: readonly string[];
|
|
123
|
+
readonly execute: CommandHandler;
|
|
124
|
+
readonly guildOnly?: boolean;
|
|
125
|
+
readonly options?: readonly CommandOptionDeclaration[];
|
|
126
|
+
readonly permissions?: CommandPermissionsDeclaration;
|
|
127
|
+
/** UR-A-03 / finding #3 — the middleware metadata the framework reads. */
|
|
128
|
+
readonly requiresDefer?: boolean;
|
|
129
|
+
readonly ephemeral?: boolean;
|
|
130
|
+
readonly cooldownMs?: number;
|
|
131
|
+
}
|
|
132
|
+
export declare function defineCommand(declaration: CommandDeclaration): CommandDeclaration;
|
|
133
|
+
/**
|
|
134
|
+
* UR-20261031-131 (OI-19) — the profile a command registry serves, and the registry surface both the
|
|
135
|
+
* framework and a module rely on.
|
|
136
|
+
*
|
|
137
|
+
* A module hosts commands: it builds a registry for a profile, filters it, and hands it to the framework
|
|
138
|
+
* to deploy. Both sides must agree on what a registry IS, and until now they could not, because the type
|
|
139
|
+
* lived in the core. Two routes were tried and both fail: a module MIRRORING the type is not assignable
|
|
140
|
+
* where the core expects its full one, and a module IMPORTING it loses the self-contained declaration the
|
|
141
|
+
* core needs to resolve through the @modules mapping. So it lives here, where both sides import from.
|
|
142
|
+
*/
|
|
143
|
+
export interface CommandProfile {
|
|
144
|
+
readonly kind: 'main' | 'persona';
|
|
145
|
+
readonly id: string;
|
|
146
|
+
readonly applicationId: string;
|
|
147
|
+
}
|
|
148
|
+
export interface CommandDefinitionLike {
|
|
149
|
+
readonly data: unknown;
|
|
150
|
+
readonly moduleId: string;
|
|
151
|
+
}
|
|
152
|
+
export interface CommandRegistryLike {
|
|
153
|
+
all(): readonly CommandDefinitionLike[];
|
|
154
|
+
getModuleTier(moduleId: string): string | undefined;
|
|
155
|
+
register(def: CommandDefinitionLike): void;
|
|
156
|
+
registerModule(moduleId: string, tier: string): void;
|
|
157
|
+
}
|
package/dist/commands.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function defineCommand(declaration) {
|
|
2
|
+
if (declaration.name.trim().length === 0) {
|
|
3
|
+
throw new Error('command name is required');
|
|
4
|
+
}
|
|
5
|
+
if (declaration.pages.length === 0) {
|
|
6
|
+
throw new Error(`command "${declaration.name}" must declare at least one page`);
|
|
7
|
+
}
|
|
8
|
+
return declaration;
|
|
9
|
+
}
|