@h-rig/core 0.0.6-alpha.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/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # Core Package
2
+
3
+ `@rig/core` holds pure task-graph and engine logic.
4
+
5
+ ## Expectations
6
+
7
+ - No app-shell assumptions.
8
+ - Keep selectors and reducers reusable by web, TUI, server, and tests.
9
+ - Push shared behavior here before duplicating it in UI packages.
@@ -0,0 +1,24 @@
1
+ // @bun
2
+ // packages/core/src/define-config.ts
3
+ import { Schema } from "effect";
4
+ import { RigConfig } from "@rig/contracts";
5
+ function defineConfig(cfg) {
6
+ const runtimeByName = new Map;
7
+ const plugins = cfg.plugins ?? [];
8
+ for (const plugin of plugins) {
9
+ if (plugin?.__runtime) {
10
+ runtimeByName.set(plugin.name, plugin.__runtime);
11
+ }
12
+ }
13
+ const decoded = Schema.decodeUnknownSync(RigConfig)(cfg);
14
+ const decodedPlugins = decoded.plugins.map((p) => {
15
+ const runtime = runtimeByName.get(p.name);
16
+ if (!runtime)
17
+ return p;
18
+ return { ...p, __runtime: runtime };
19
+ });
20
+ return { ...decoded, plugins: decodedPlugins };
21
+ }
22
+ export {
23
+ defineConfig
24
+ };
@@ -0,0 +1,50 @@
1
+ // @bun
2
+ // packages/core/src/define-plugin.ts
3
+ import { Schema } from "effect";
4
+ import { RigPlugin } from "@rig/contracts";
5
+ function definePlugin(meta, runtime) {
6
+ const validated = Schema.decodeUnknownSync(RigPlugin)(meta);
7
+ if (!runtime) {
8
+ return validated;
9
+ }
10
+ const declaredValidators = new Map((validated.contributes?.validators ?? []).map((v) => [v.id, v]));
11
+ const runtimeValidators = new Map((runtime.validators ?? []).map((v) => [v.id, v]));
12
+ for (const v of runtimeValidators.values()) {
13
+ const metadata = declaredValidators.get(v.id);
14
+ if (!metadata) {
15
+ throw new Error(`definePlugin(${validated.name}): executable validator "${v.id}" has no matching metadata entry in contributes.validators`);
16
+ }
17
+ if (metadata.category !== v.category) {
18
+ throw new Error(`definePlugin(${validated.name}): executable validator "${v.id}" category "${v.category}" does not match metadata category "${metadata.category}"`);
19
+ }
20
+ }
21
+ if (runtime.validators) {
22
+ for (const v of declaredValidators.values()) {
23
+ if (!runtimeValidators.has(v.id)) {
24
+ throw new Error(`definePlugin(${validated.name}): validator metadata "${v.id}" has no runtime implementation`);
25
+ }
26
+ }
27
+ }
28
+ const declaredSources = new Map((validated.contributes?.taskSources ?? []).map((s) => [s.id, s]));
29
+ const runtimeSources = new Map((runtime.taskSources ?? []).map((s) => [s.id, s]));
30
+ for (const s of runtimeSources.values()) {
31
+ const metadata = declaredSources.get(s.id);
32
+ if (!metadata) {
33
+ throw new Error(`definePlugin(${validated.name}): executable task source "${s.id}" has no matching metadata entry in contributes.taskSources`);
34
+ }
35
+ if (metadata.kind !== s.kind) {
36
+ throw new Error(`definePlugin(${validated.name}): executable task source "${s.id}" kind "${s.kind}" does not match metadata kind "${metadata.kind}"`);
37
+ }
38
+ }
39
+ if (runtime.taskSources) {
40
+ for (const s of declaredSources.values()) {
41
+ if (!runtimeSources.has(s.id)) {
42
+ throw new Error(`definePlugin(${validated.name}): task source metadata "${s.id}" has no runtime implementation`);
43
+ }
44
+ }
45
+ }
46
+ return { ...validated, __runtime: runtime };
47
+ }
48
+ export {
49
+ definePlugin
50
+ };