@tagma/sdk 0.4.14 → 0.4.16

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 (67) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +569 -569
  3. package/dist/dag.d.ts.map +1 -1
  4. package/dist/dag.js +58 -69
  5. package/dist/dag.js.map +1 -1
  6. package/dist/engine.d.ts.map +1 -1
  7. package/dist/engine.js +63 -37
  8. package/dist/engine.js.map +1 -1
  9. package/dist/middlewares/static-context.d.ts.map +1 -1
  10. package/dist/middlewares/static-context.js +7 -3
  11. package/dist/middlewares/static-context.js.map +1 -1
  12. package/dist/prompt-doc.d.ts +36 -0
  13. package/dist/prompt-doc.d.ts.map +1 -0
  14. package/dist/prompt-doc.js +44 -0
  15. package/dist/prompt-doc.js.map +1 -0
  16. package/dist/registry.d.ts.map +1 -1
  17. package/dist/registry.js +11 -0
  18. package/dist/registry.js.map +1 -1
  19. package/dist/sdk.d.ts +3 -0
  20. package/dist/sdk.d.ts.map +1 -1
  21. package/dist/sdk.js +4 -0
  22. package/dist/sdk.js.map +1 -1
  23. package/dist/task-ref.d.ts +55 -0
  24. package/dist/task-ref.d.ts.map +1 -0
  25. package/dist/task-ref.js +101 -0
  26. package/dist/task-ref.js.map +1 -0
  27. package/dist/task-ref.test.d.ts +2 -0
  28. package/dist/task-ref.test.d.ts.map +1 -0
  29. package/dist/task-ref.test.js +364 -0
  30. package/dist/task-ref.test.js.map +1 -0
  31. package/dist/templates.d.ts +20 -0
  32. package/dist/templates.d.ts.map +1 -0
  33. package/dist/templates.js +93 -0
  34. package/dist/templates.js.map +1 -0
  35. package/dist/validate-raw.d.ts.map +1 -1
  36. package/dist/validate-raw.js +27 -53
  37. package/dist/validate-raw.js.map +1 -1
  38. package/package.json +2 -2
  39. package/scripts/preinstall.js +31 -31
  40. package/src/adapters/stdin-approval.ts +106 -106
  41. package/src/adapters/websocket-approval.ts +224 -224
  42. package/src/approval.ts +131 -131
  43. package/src/bootstrap.ts +37 -37
  44. package/src/completions/exit-code.ts +34 -34
  45. package/src/completions/file-exists.ts +66 -66
  46. package/src/completions/output-check.ts +86 -86
  47. package/src/config-ops.ts +307 -307
  48. package/src/dag.ts +61 -67
  49. package/src/drivers/claude-code.ts +250 -250
  50. package/src/engine.ts +1137 -1098
  51. package/src/hooks.ts +187 -187
  52. package/src/logger.ts +182 -182
  53. package/src/middlewares/static-context.ts +49 -45
  54. package/src/pipeline-runner.ts +156 -156
  55. package/src/prompt-doc.ts +49 -0
  56. package/src/registry.ts +255 -242
  57. package/src/runner.ts +395 -395
  58. package/src/schema.test.ts +101 -101
  59. package/src/schema.ts +338 -338
  60. package/src/sdk.ts +111 -92
  61. package/src/task-ref.test.ts +401 -0
  62. package/src/task-ref.ts +120 -0
  63. package/src/triggers/file.ts +164 -164
  64. package/src/triggers/manual.ts +86 -86
  65. package/src/types.ts +18 -18
  66. package/src/utils.ts +203 -203
  67. package/src/validate-raw.ts +412 -442
package/src/registry.ts CHANGED
@@ -1,242 +1,255 @@
1
- import { createRequire } from 'node:module';
2
- import { pathToFileURL } from 'node:url';
3
- import type {
4
- PluginCategory,
5
- DriverPlugin,
6
- TriggerPlugin,
7
- CompletionPlugin,
8
- MiddlewarePlugin,
9
- PluginManifest,
10
- } from './types';
11
-
12
- type PluginType = DriverPlugin | TriggerPlugin | CompletionPlugin | MiddlewarePlugin;
13
-
14
- const VALID_CATEGORIES: ReadonlySet<PluginCategory> = new Set([
15
- 'drivers',
16
- 'triggers',
17
- 'completions',
18
- 'middlewares',
19
- ]);
20
-
21
- const registries = {
22
- drivers: new Map<string, DriverPlugin>(),
23
- triggers: new Map<string, TriggerPlugin>(),
24
- completions: new Map<string, CompletionPlugin>(),
25
- middlewares: new Map<string, MiddlewarePlugin>(),
26
- };
27
-
28
- /**
29
- * Minimal contract enforcement so a malformed plugin fails fast at
30
- * registration time rather than crashing the engine mid-run.
31
- *
32
- * For drivers we materialize `capabilities` and assert each field is a
33
- * boolean — otherwise a plugin author can write
34
- * get capabilities() { throw new Error('boom') }
35
- * and pass the basic typeof check, then crash preflight when the engine
36
- * touches `driver.capabilities.sessionResume`. (R8)
37
- */
38
- function validateContract(category: PluginCategory, handler: unknown): void {
39
- if (!handler || typeof handler !== 'object') {
40
- throw new Error(`Plugin handler for category "${category}" must be an object`);
41
- }
42
- const h = handler as Record<string, unknown>;
43
- if (typeof h.name !== 'string' || h.name.length === 0) {
44
- throw new Error(`Plugin handler for category "${category}" must declare a non-empty "name"`);
45
- }
46
- switch (category) {
47
- case 'drivers': {
48
- if (typeof h.buildCommand !== 'function') {
49
- throw new Error(`drivers plugin "${h.name}" must export buildCommand()`);
50
- }
51
- // Materialize capabilities — this triggers any throwing getter NOW
52
- // instead of during preflight.
53
- let caps: unknown;
54
- try {
55
- caps = h.capabilities;
56
- } catch (err) {
57
- throw new Error(
58
- `drivers plugin "${h.name}" capabilities accessor threw: ` +
59
- (err instanceof Error ? err.message : String(err)),
60
- );
61
- }
62
- if (!caps || typeof caps !== 'object') {
63
- throw new Error(`drivers plugin "${h.name}" must declare capabilities object`);
64
- }
65
- const c = caps as Record<string, unknown>;
66
- for (const field of ['sessionResume', 'systemPrompt', 'outputFormat'] as const) {
67
- if (typeof c[field] !== 'boolean') {
68
- throw new Error(
69
- `drivers plugin "${h.name}".capabilities.${field} must be a boolean (got ${typeof c[field]})`,
70
- );
71
- }
72
- }
73
- // Optional methods, but if present must be functions.
74
- for (const opt of ['parseResult', 'resolveModel', 'resolveTools'] as const) {
75
- if (h[opt] !== undefined && typeof h[opt] !== 'function') {
76
- throw new Error(`drivers plugin "${h.name}".${opt} must be a function or undefined`);
77
- }
78
- }
79
- break;
80
- }
81
- case 'triggers':
82
- if (typeof h.watch !== 'function') {
83
- throw new Error(`triggers plugin "${h.name}" must export watch()`);
84
- }
85
- break;
86
- case 'completions':
87
- if (typeof h.check !== 'function') {
88
- throw new Error(`completions plugin "${h.name}" must export check()`);
89
- }
90
- break;
91
- case 'middlewares':
92
- if (typeof h.enhance !== 'function') {
93
- throw new Error(`middlewares plugin "${h.name}" must export enhance()`);
94
- }
95
- break;
96
- }
97
- }
98
-
99
- export type RegisterResult = 'registered' | 'replaced' | 'unchanged';
100
-
101
- /**
102
- * Register a plugin under (category, type). Returns:
103
- * - 'registered' on first registration
104
- * - 'replaced' when an existing entry was overwritten with a different handler
105
- * - 'unchanged' when the same handler instance was already present
106
- *
107
- * Throws if `category` is unknown, `type` is empty, or `handler` violates the
108
- * minimum interface contract for the category.
109
- */
110
- export function registerPlugin<T extends PluginType>(
111
- category: PluginCategory,
112
- type: string,
113
- handler: T,
114
- ): RegisterResult {
115
- if (!VALID_CATEGORIES.has(category)) {
116
- throw new Error(`Unknown plugin category "${category}"`);
117
- }
118
- if (typeof type !== 'string' || type.length === 0) {
119
- throw new Error(`Plugin type must be a non-empty string (category="${category}")`);
120
- }
121
- validateContract(category, handler);
122
- const registry = registries[category] as Map<string, T>;
123
- const existing = registry.get(type);
124
- if (existing === handler) return 'unchanged';
125
- const wasReplaced = existing !== undefined;
126
- registry.set(type, handler);
127
- return wasReplaced ? 'replaced' : 'registered';
128
- }
129
-
130
- /**
131
- * Remove a plugin from the in-process registry. Returns true if a plugin
132
- * was actually removed. Note: ESM module caching is not affected, so
133
- * re-importing the same file after unregister will yield the cached module —
134
- * callers wanting a fresh load must restart the host process.
135
- */
136
- export function unregisterPlugin(category: PluginCategory, type: string): boolean {
137
- if (!VALID_CATEGORIES.has(category)) return false;
138
- return registries[category].delete(type);
139
- }
140
-
141
- export function getHandler<T extends PluginType>(category: PluginCategory, type: string): T {
142
- const handler = registries[category].get(type);
143
- if (!handler) {
144
- throw new Error(
145
- `${category} type "${type}" not registered.\n` +
146
- `Install the plugin: bun add @tagma/${category.replace(/s$/, '')}-${type}`,
147
- );
148
- }
149
- return handler as T;
150
- }
151
-
152
- export function hasHandler(category: PluginCategory, type: string): boolean {
153
- return registries[category].has(type);
154
- }
155
-
156
- // Plugin name must be a scoped npm package or a tagma-prefixed package.
157
- // Reject absolute/relative paths and suspicious patterns to prevent
158
- // arbitrary code execution via crafted YAML configs.
159
- export const PLUGIN_NAME_RE = /^(@[a-z0-9-]+\/[a-z0-9._-]+|tagma-plugin-[a-z0-9._-]+)$/;
160
-
161
- export function isValidPluginName(name: unknown): name is string {
162
- return typeof name === 'string' && PLUGIN_NAME_RE.test(name);
163
- }
164
-
165
- /**
166
- * Parse and validate the `tagmaPlugin` field of a `package.json` blob.
167
- *
168
- * Returns the strongly-typed manifest if the field is present and
169
- * well-formed (`category` is one of the four known categories and `type`
170
- * is a non-empty string). Returns `null` if the field is absent — that
171
- * is the host's signal that the package is a library, not a plugin.
172
- *
173
- * Throws if the field is present but malformed: that's a packaging bug
174
- * the plugin author should hear about loudly, not a silent skip.
175
- *
176
- * Hosts use this during auto-discovery to decide whether to load a
177
- * package as a plugin without having to dynamically `import()` it.
178
- */
179
- export function readPluginManifest(pkgJson: unknown): PluginManifest | null {
180
- if (!pkgJson || typeof pkgJson !== 'object') return null;
181
- const raw = (pkgJson as Record<string, unknown>).tagmaPlugin;
182
- if (raw === undefined) return null;
183
- if (!raw || typeof raw !== 'object') {
184
- throw new Error('tagmaPlugin field must be an object with { category, type }');
185
- }
186
- const m = raw as Record<string, unknown>;
187
- const category = m.category;
188
- const type = m.type;
189
- if (typeof category !== 'string' || !VALID_CATEGORIES.has(category as PluginCategory)) {
190
- throw new Error(
191
- `tagmaPlugin.category must be one of ${[...VALID_CATEGORIES].join(', ')}, got ${JSON.stringify(category)}`,
192
- );
193
- }
194
- if (typeof type !== 'string' || type.length === 0) {
195
- throw new Error(`tagmaPlugin.type must be a non-empty string, got ${JSON.stringify(type)}`);
196
- }
197
- return { category: category as PluginCategory, type };
198
- }
199
-
200
- /**
201
- * Load and register a list of plugin packages.
202
- *
203
- * @param pluginNames - Validated npm package names to load.
204
- * @param resolveFrom - Optional absolute path to resolve plugins from (e.g. the
205
- * workspace's working directory). When omitted, the default ESM resolution
206
- * uses the SDK's own `node_modules`, which will fail for plugins installed
207
- * only in the user's workspace. CLI callers should pass `process.cwd()` or
208
- * the workspace root so that workspace-local plugins resolve correctly.
209
- */
210
- export async function loadPlugins(
211
- pluginNames: readonly string[],
212
- resolveFrom?: string,
213
- ): Promise<void> {
214
- for (const name of pluginNames) {
215
- if (!isValidPluginName(name)) {
216
- throw new Error(
217
- `Plugin "${name}" rejected: plugin names must be scoped npm packages ` +
218
- `(e.g. @tagma/trigger-xyz) or tagma-plugin-* packages. ` +
219
- `Relative/absolute paths are not allowed.`,
220
- );
221
- }
222
- let moduleUrl: string = name;
223
- if (resolveFrom) {
224
- // Resolve the package entry point relative to the caller's directory so
225
- // plugins installed in the workspace's node_modules are found even when
226
- // the SDK itself lives elsewhere (e.g. a global install or a monorepo
227
- // sibling package).
228
- const req = createRequire(resolveFrom.endsWith('/') ? resolveFrom : resolveFrom + '/');
229
- const resolved = req.resolve(name);
230
- moduleUrl = pathToFileURL(resolved).href;
231
- }
232
- const mod = await import(moduleUrl);
233
- if (!mod.pluginCategory || !mod.pluginType || !mod.default) {
234
- throw new Error(`Plugin "${name}" must export pluginCategory, pluginType, and default`);
235
- }
236
- registerPlugin(mod.pluginCategory, mod.pluginType, mod.default);
237
- }
238
- }
239
-
240
- export function listRegistered(category: PluginCategory): string[] {
241
- return [...registries[category].keys()];
242
- }
1
+ import { createRequire } from 'node:module';
2
+ import { pathToFileURL } from 'node:url';
3
+ import type {
4
+ PluginCategory,
5
+ DriverPlugin,
6
+ TriggerPlugin,
7
+ CompletionPlugin,
8
+ MiddlewarePlugin,
9
+ PluginManifest,
10
+ } from './types';
11
+
12
+ type PluginType = DriverPlugin | TriggerPlugin | CompletionPlugin | MiddlewarePlugin;
13
+
14
+ const VALID_CATEGORIES: ReadonlySet<PluginCategory> = new Set([
15
+ 'drivers',
16
+ 'triggers',
17
+ 'completions',
18
+ 'middlewares',
19
+ ]);
20
+
21
+ const registries = {
22
+ drivers: new Map<string, DriverPlugin>(),
23
+ triggers: new Map<string, TriggerPlugin>(),
24
+ completions: new Map<string, CompletionPlugin>(),
25
+ middlewares: new Map<string, MiddlewarePlugin>(),
26
+ };
27
+
28
+ /**
29
+ * Minimal contract enforcement so a malformed plugin fails fast at
30
+ * registration time rather than crashing the engine mid-run.
31
+ *
32
+ * For drivers we materialize `capabilities` and assert each field is a
33
+ * boolean — otherwise a plugin author can write
34
+ * get capabilities() { throw new Error('boom') }
35
+ * and pass the basic typeof check, then crash preflight when the engine
36
+ * touches `driver.capabilities.sessionResume`. (R8)
37
+ */
38
+ function validateContract(category: PluginCategory, handler: unknown): void {
39
+ if (!handler || typeof handler !== 'object') {
40
+ throw new Error(`Plugin handler for category "${category}" must be an object`);
41
+ }
42
+ const h = handler as Record<string, unknown>;
43
+ if (typeof h.name !== 'string' || h.name.length === 0) {
44
+ throw new Error(`Plugin handler for category "${category}" must declare a non-empty "name"`);
45
+ }
46
+ switch (category) {
47
+ case 'drivers': {
48
+ if (typeof h.buildCommand !== 'function') {
49
+ throw new Error(`drivers plugin "${h.name}" must export buildCommand()`);
50
+ }
51
+ // Materialize capabilities — this triggers any throwing getter NOW
52
+ // instead of during preflight.
53
+ let caps: unknown;
54
+ try {
55
+ caps = h.capabilities;
56
+ } catch (err) {
57
+ throw new Error(
58
+ `drivers plugin "${h.name}" capabilities accessor threw: ` +
59
+ (err instanceof Error ? err.message : String(err)),
60
+ );
61
+ }
62
+ if (!caps || typeof caps !== 'object') {
63
+ throw new Error(`drivers plugin "${h.name}" must declare capabilities object`);
64
+ }
65
+ const c = caps as Record<string, unknown>;
66
+ for (const field of ['sessionResume', 'systemPrompt', 'outputFormat'] as const) {
67
+ if (typeof c[field] !== 'boolean') {
68
+ throw new Error(
69
+ `drivers plugin "${h.name}".capabilities.${field} must be a boolean (got ${typeof c[field]})`,
70
+ );
71
+ }
72
+ }
73
+ // Optional methods, but if present must be functions.
74
+ for (const opt of ['parseResult', 'resolveModel', 'resolveTools'] as const) {
75
+ if (h[opt] !== undefined && typeof h[opt] !== 'function') {
76
+ throw new Error(`drivers plugin "${h.name}".${opt} must be a function or undefined`);
77
+ }
78
+ }
79
+ break;
80
+ }
81
+ case 'triggers':
82
+ if (typeof h.watch !== 'function') {
83
+ throw new Error(`triggers plugin "${h.name}" must export watch()`);
84
+ }
85
+ break;
86
+ case 'completions':
87
+ if (typeof h.check !== 'function') {
88
+ throw new Error(`completions plugin "${h.name}" must export check()`);
89
+ }
90
+ break;
91
+ case 'middlewares':
92
+ if (typeof h.enhance !== 'function') {
93
+ throw new Error(`middlewares plugin "${h.name}" must export enhance()`);
94
+ }
95
+ break;
96
+ }
97
+ }
98
+
99
+ export type RegisterResult = 'registered' | 'replaced' | 'unchanged';
100
+
101
+ /**
102
+ * Register a plugin under (category, type). Returns:
103
+ * - 'registered' on first registration
104
+ * - 'replaced' when an existing entry was overwritten with a different handler
105
+ * - 'unchanged' when the same handler instance was already present
106
+ *
107
+ * Throws if `category` is unknown, `type` is empty, or `handler` violates the
108
+ * minimum interface contract for the category.
109
+ */
110
+ export function registerPlugin<T extends PluginType>(
111
+ category: PluginCategory,
112
+ type: string,
113
+ handler: T,
114
+ ): RegisterResult {
115
+ if (!VALID_CATEGORIES.has(category)) {
116
+ throw new Error(`Unknown plugin category "${category}"`);
117
+ }
118
+ if (typeof type !== 'string' || type.length === 0) {
119
+ throw new Error(`Plugin type must be a non-empty string (category="${category}")`);
120
+ }
121
+ validateContract(category, handler);
122
+ const registry = registries[category] as Map<string, T>;
123
+ const existing = registry.get(type);
124
+ if (existing === handler) return 'unchanged';
125
+ const wasReplaced = existing !== undefined;
126
+ registry.set(type, handler);
127
+ if (wasReplaced) {
128
+ // D18: surface silent shadowing. Hot-reload flows legitimately replace
129
+ // handlers; installing two different plugin packages that both claim
130
+ // the same (category, type) does not — the second wins and breaks the
131
+ // first's consumers with no audit trail. A console.warn is cheap,
132
+ // respects existing callers that rely on 'replaced', and gives ops a
133
+ // grep-able signal when registrations collide unexpectedly.
134
+ // eslint-disable-next-line no-console
135
+ console.warn(
136
+ `[tagma-sdk] registerPlugin: replaced existing ${category}/${type} ` +
137
+ `check for duplicate plugin packages claiming the same type.`,
138
+ );
139
+ }
140
+ return wasReplaced ? 'replaced' : 'registered';
141
+ }
142
+
143
+ /**
144
+ * Remove a plugin from the in-process registry. Returns true if a plugin
145
+ * was actually removed. Note: ESM module caching is not affected, so
146
+ * re-importing the same file after unregister will yield the cached module —
147
+ * callers wanting a fresh load must restart the host process.
148
+ */
149
+ export function unregisterPlugin(category: PluginCategory, type: string): boolean {
150
+ if (!VALID_CATEGORIES.has(category)) return false;
151
+ return registries[category].delete(type);
152
+ }
153
+
154
+ export function getHandler<T extends PluginType>(category: PluginCategory, type: string): T {
155
+ const handler = registries[category].get(type);
156
+ if (!handler) {
157
+ throw new Error(
158
+ `${category} type "${type}" not registered.\n` +
159
+ `Install the plugin: bun add @tagma/${category.replace(/s$/, '')}-${type}`,
160
+ );
161
+ }
162
+ return handler as T;
163
+ }
164
+
165
+ export function hasHandler(category: PluginCategory, type: string): boolean {
166
+ return registries[category].has(type);
167
+ }
168
+
169
+ // Plugin name must be a scoped npm package or a tagma-prefixed package.
170
+ // Reject absolute/relative paths and suspicious patterns to prevent
171
+ // arbitrary code execution via crafted YAML configs.
172
+ export const PLUGIN_NAME_RE = /^(@[a-z0-9-]+\/[a-z0-9._-]+|tagma-plugin-[a-z0-9._-]+)$/;
173
+
174
+ export function isValidPluginName(name: unknown): name is string {
175
+ return typeof name === 'string' && PLUGIN_NAME_RE.test(name);
176
+ }
177
+
178
+ /**
179
+ * Parse and validate the `tagmaPlugin` field of a `package.json` blob.
180
+ *
181
+ * Returns the strongly-typed manifest if the field is present and
182
+ * well-formed (`category` is one of the four known categories and `type`
183
+ * is a non-empty string). Returns `null` if the field is absent that
184
+ * is the host's signal that the package is a library, not a plugin.
185
+ *
186
+ * Throws if the field is present but malformed: that's a packaging bug
187
+ * the plugin author should hear about loudly, not a silent skip.
188
+ *
189
+ * Hosts use this during auto-discovery to decide whether to load a
190
+ * package as a plugin without having to dynamically `import()` it.
191
+ */
192
+ export function readPluginManifest(pkgJson: unknown): PluginManifest | null {
193
+ if (!pkgJson || typeof pkgJson !== 'object') return null;
194
+ const raw = (pkgJson as Record<string, unknown>).tagmaPlugin;
195
+ if (raw === undefined) return null;
196
+ if (!raw || typeof raw !== 'object') {
197
+ throw new Error('tagmaPlugin field must be an object with { category, type }');
198
+ }
199
+ const m = raw as Record<string, unknown>;
200
+ const category = m.category;
201
+ const type = m.type;
202
+ if (typeof category !== 'string' || !VALID_CATEGORIES.has(category as PluginCategory)) {
203
+ throw new Error(
204
+ `tagmaPlugin.category must be one of ${[...VALID_CATEGORIES].join(', ')}, got ${JSON.stringify(category)}`,
205
+ );
206
+ }
207
+ if (typeof type !== 'string' || type.length === 0) {
208
+ throw new Error(`tagmaPlugin.type must be a non-empty string, got ${JSON.stringify(type)}`);
209
+ }
210
+ return { category: category as PluginCategory, type };
211
+ }
212
+
213
+ /**
214
+ * Load and register a list of plugin packages.
215
+ *
216
+ * @param pluginNames - Validated npm package names to load.
217
+ * @param resolveFrom - Optional absolute path to resolve plugins from (e.g. the
218
+ * workspace's working directory). When omitted, the default ESM resolution
219
+ * uses the SDK's own `node_modules`, which will fail for plugins installed
220
+ * only in the user's workspace. CLI callers should pass `process.cwd()` or
221
+ * the workspace root so that workspace-local plugins resolve correctly.
222
+ */
223
+ export async function loadPlugins(
224
+ pluginNames: readonly string[],
225
+ resolveFrom?: string,
226
+ ): Promise<void> {
227
+ for (const name of pluginNames) {
228
+ if (!isValidPluginName(name)) {
229
+ throw new Error(
230
+ `Plugin "${name}" rejected: plugin names must be scoped npm packages ` +
231
+ `(e.g. @tagma/trigger-xyz) or tagma-plugin-* packages. ` +
232
+ `Relative/absolute paths are not allowed.`,
233
+ );
234
+ }
235
+ let moduleUrl: string = name;
236
+ if (resolveFrom) {
237
+ // Resolve the package entry point relative to the caller's directory so
238
+ // plugins installed in the workspace's node_modules are found even when
239
+ // the SDK itself lives elsewhere (e.g. a global install or a monorepo
240
+ // sibling package).
241
+ const req = createRequire(resolveFrom.endsWith('/') ? resolveFrom : resolveFrom + '/');
242
+ const resolved = req.resolve(name);
243
+ moduleUrl = pathToFileURL(resolved).href;
244
+ }
245
+ const mod = await import(moduleUrl);
246
+ if (!mod.pluginCategory || !mod.pluginType || !mod.default) {
247
+ throw new Error(`Plugin "${name}" must export pluginCategory, pluginType, and default`);
248
+ }
249
+ registerPlugin(mod.pluginCategory, mod.pluginType, mod.default);
250
+ }
251
+ }
252
+
253
+ export function listRegistered(category: PluginCategory): string[] {
254
+ return [...registries[category].keys()];
255
+ }