@zenithbuild/compiler 1.0.2

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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -0
  3. package/dist/build-analyzer.d.ts +44 -0
  4. package/dist/build-analyzer.js +87 -0
  5. package/dist/bundler.d.ts +31 -0
  6. package/dist/bundler.js +86 -0
  7. package/dist/core/components/index.d.ts +9 -0
  8. package/dist/core/components/index.js +13 -0
  9. package/dist/core/config/index.d.ts +11 -0
  10. package/dist/core/config/index.js +10 -0
  11. package/dist/core/config/loader.d.ts +17 -0
  12. package/dist/core/config/loader.js +60 -0
  13. package/dist/core/config/types.d.ts +98 -0
  14. package/dist/core/config/types.js +32 -0
  15. package/dist/core/index.d.ts +7 -0
  16. package/dist/core/index.js +6 -0
  17. package/dist/core/lifecycle/index.d.ts +16 -0
  18. package/dist/core/lifecycle/index.js +19 -0
  19. package/dist/core/lifecycle/zen-mount.d.ts +66 -0
  20. package/dist/core/lifecycle/zen-mount.js +151 -0
  21. package/dist/core/lifecycle/zen-unmount.d.ts +54 -0
  22. package/dist/core/lifecycle/zen-unmount.js +76 -0
  23. package/dist/core/plugins/bridge.d.ts +116 -0
  24. package/dist/core/plugins/bridge.js +121 -0
  25. package/dist/core/plugins/index.d.ts +6 -0
  26. package/dist/core/plugins/index.js +6 -0
  27. package/dist/core/plugins/registry.d.ts +67 -0
  28. package/dist/core/plugins/registry.js +113 -0
  29. package/dist/core/reactivity/index.d.ts +30 -0
  30. package/dist/core/reactivity/index.js +33 -0
  31. package/dist/core/reactivity/tracking.d.ts +74 -0
  32. package/dist/core/reactivity/tracking.js +136 -0
  33. package/dist/core/reactivity/zen-batch.d.ts +45 -0
  34. package/dist/core/reactivity/zen-batch.js +54 -0
  35. package/dist/core/reactivity/zen-effect.d.ts +48 -0
  36. package/dist/core/reactivity/zen-effect.js +98 -0
  37. package/dist/core/reactivity/zen-memo.d.ts +43 -0
  38. package/dist/core/reactivity/zen-memo.js +100 -0
  39. package/dist/core/reactivity/zen-ref.d.ts +44 -0
  40. package/dist/core/reactivity/zen-ref.js +34 -0
  41. package/dist/core/reactivity/zen-signal.d.ts +48 -0
  42. package/dist/core/reactivity/zen-signal.js +84 -0
  43. package/dist/core/reactivity/zen-state.d.ts +35 -0
  44. package/dist/core/reactivity/zen-state.js +147 -0
  45. package/dist/core/reactivity/zen-untrack.d.ts +38 -0
  46. package/dist/core/reactivity/zen-untrack.js +41 -0
  47. package/dist/css/index.d.ts +73 -0
  48. package/dist/css/index.js +246 -0
  49. package/dist/discovery/componentDiscovery.d.ts +42 -0
  50. package/dist/discovery/componentDiscovery.js +56 -0
  51. package/dist/discovery/layouts.d.ts +13 -0
  52. package/dist/discovery/layouts.js +41 -0
  53. package/dist/errors/compilerError.d.ts +31 -0
  54. package/dist/errors/compilerError.js +51 -0
  55. package/dist/finalize/finalizeOutput.d.ts +32 -0
  56. package/dist/finalize/finalizeOutput.js +62 -0
  57. package/dist/finalize/generateFinalBundle.d.ts +24 -0
  58. package/dist/finalize/generateFinalBundle.js +68 -0
  59. package/dist/index.d.ts +36 -0
  60. package/dist/index.js +51 -0
  61. package/dist/ir/types.d.ts +181 -0
  62. package/dist/ir/types.js +8 -0
  63. package/dist/output/types.d.ts +30 -0
  64. package/dist/output/types.js +6 -0
  65. package/dist/parse/detectMapExpressions.d.ts +45 -0
  66. package/dist/parse/detectMapExpressions.js +77 -0
  67. package/dist/parse/parseScript.d.ts +8 -0
  68. package/dist/parse/parseScript.js +36 -0
  69. package/dist/parse/parseTemplate.d.ts +11 -0
  70. package/dist/parse/parseTemplate.js +487 -0
  71. package/dist/parse/parseZenFile.d.ts +11 -0
  72. package/dist/parse/parseZenFile.js +50 -0
  73. package/dist/parse/scriptAnalysis.d.ts +25 -0
  74. package/dist/parse/scriptAnalysis.js +60 -0
  75. package/dist/parse/trackLoopContext.d.ts +20 -0
  76. package/dist/parse/trackLoopContext.js +62 -0
  77. package/dist/parseZenFile.d.ts +10 -0
  78. package/dist/parseZenFile.js +55 -0
  79. package/dist/runtime/analyzeAndEmit.d.ts +20 -0
  80. package/dist/runtime/analyzeAndEmit.js +70 -0
  81. package/dist/runtime/build.d.ts +6 -0
  82. package/dist/runtime/build.js +13 -0
  83. package/dist/runtime/bundle-generator.d.ts +27 -0
  84. package/dist/runtime/bundle-generator.js +1263 -0
  85. package/dist/runtime/client-runtime.d.ts +41 -0
  86. package/dist/runtime/client-runtime.js +397 -0
  87. package/dist/runtime/dataExposure.d.ts +52 -0
  88. package/dist/runtime/dataExposure.js +227 -0
  89. package/dist/runtime/generateDOM.d.ts +21 -0
  90. package/dist/runtime/generateDOM.js +194 -0
  91. package/dist/runtime/generateHydrationBundle.d.ts +15 -0
  92. package/dist/runtime/generateHydrationBundle.js +399 -0
  93. package/dist/runtime/hydration.d.ts +53 -0
  94. package/dist/runtime/hydration.js +271 -0
  95. package/dist/runtime/navigation.d.ts +58 -0
  96. package/dist/runtime/navigation.js +372 -0
  97. package/dist/runtime/serve.d.ts +13 -0
  98. package/dist/runtime/serve.js +76 -0
  99. package/dist/runtime/thinRuntime.d.ts +23 -0
  100. package/dist/runtime/thinRuntime.js +158 -0
  101. package/dist/runtime/transformIR.d.ts +19 -0
  102. package/dist/runtime/transformIR.js +285 -0
  103. package/dist/runtime/wrapExpression.d.ts +24 -0
  104. package/dist/runtime/wrapExpression.js +76 -0
  105. package/dist/runtime/wrapExpressionWithLoop.d.ts +17 -0
  106. package/dist/runtime/wrapExpressionWithLoop.js +75 -0
  107. package/dist/spa-build.d.ts +26 -0
  108. package/dist/spa-build.js +866 -0
  109. package/dist/ssg-build.d.ts +32 -0
  110. package/dist/ssg-build.js +408 -0
  111. package/dist/test/analyze-emit.test.d.ts +1 -0
  112. package/dist/test/analyze-emit.test.js +88 -0
  113. package/dist/test/bundler-contract.test.d.ts +1 -0
  114. package/dist/test/bundler-contract.test.js +137 -0
  115. package/dist/test/compiler-authority.test.d.ts +1 -0
  116. package/dist/test/compiler-authority.test.js +90 -0
  117. package/dist/test/component-instance-test.d.ts +1 -0
  118. package/dist/test/component-instance-test.js +115 -0
  119. package/dist/test/error-native-bridge.test.d.ts +1 -0
  120. package/dist/test/error-native-bridge.test.js +51 -0
  121. package/dist/test/error-serialization.test.d.ts +1 -0
  122. package/dist/test/error-serialization.test.js +38 -0
  123. package/dist/test/macro-inlining.test.d.ts +1 -0
  124. package/dist/test/macro-inlining.test.js +178 -0
  125. package/dist/test/validate-test.d.ts +6 -0
  126. package/dist/test/validate-test.js +95 -0
  127. package/dist/transform/classifyExpression.d.ts +46 -0
  128. package/dist/transform/classifyExpression.js +354 -0
  129. package/dist/transform/componentResolver.d.ts +15 -0
  130. package/dist/transform/componentResolver.js +30 -0
  131. package/dist/transform/expressionTransformer.d.ts +19 -0
  132. package/dist/transform/expressionTransformer.js +333 -0
  133. package/dist/transform/fragmentLowering.d.ts +25 -0
  134. package/dist/transform/fragmentLowering.js +468 -0
  135. package/dist/transform/layoutProcessor.d.ts +5 -0
  136. package/dist/transform/layoutProcessor.js +34 -0
  137. package/dist/transform/transformTemplate.d.ts +11 -0
  138. package/dist/transform/transformTemplate.js +33 -0
  139. package/dist/validate/invariants.d.ts +23 -0
  140. package/dist/validate/invariants.js +55 -0
  141. package/native/compiler-native/compiler-native.node +0 -0
  142. package/native/compiler-native/index.d.ts +113 -0
  143. package/native/compiler-native/index.js +19 -0
  144. package/native/compiler-native/package.json +19 -0
  145. package/package.json +49 -0
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Zenith OnMount - Post-Mount Lifecycle Hook
3
+ *
4
+ * Registers a callback to run after a component's DOM is inserted.
5
+ * This is an effect wrapper that defers execution until the mount phase.
6
+ *
7
+ * Features:
8
+ * - Runs after DOM is available
9
+ * - Only runs once per mount
10
+ * - Supports cleanup function return
11
+ * - Works with component lifecycle system
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * zenOnMount(() => {
16
+ * console.log('Component mounted!')
17
+ * const el = document.querySelector('.my-element')
18
+ *
19
+ * // Optional cleanup - runs on unmount
20
+ * return () => {
21
+ * console.log('Component will unmount')
22
+ * }
23
+ * })
24
+ * ```
25
+ *
26
+ * Note: This hook registers callbacks that will be executed by the
27
+ * component lifecycle system. If no mount scheduler is active,
28
+ * callbacks are queued for later execution.
29
+ */
30
+ /**
31
+ * Mount callback type - can optionally return a cleanup function
32
+ */
33
+ export type MountCallback = () => void | (() => void);
34
+ /**
35
+ * Register a callback to run after component mount
36
+ *
37
+ * @param callback - Function to run after mount (can return cleanup function)
38
+ * @returns Dispose function to cancel the mount callback
39
+ */
40
+ export declare function zenOnMount(callback: MountCallback): () => void;
41
+ /**
42
+ * Trigger mount phase - called by component lifecycle system
43
+ * Executes all pending mount callbacks
44
+ *
45
+ * @internal
46
+ */
47
+ export declare function triggerMount(): void;
48
+ /**
49
+ * Trigger unmount phase - called by component lifecycle system
50
+ * Runs cleanup functions for all active mount hooks
51
+ *
52
+ * @internal
53
+ */
54
+ export declare function triggerUnmount(): void;
55
+ /**
56
+ * Check if currently in mounted state
57
+ *
58
+ * @internal
59
+ */
60
+ export declare function getIsMounted(): boolean;
61
+ /**
62
+ * Reset mount state - for testing purposes
63
+ *
64
+ * @internal
65
+ */
66
+ export declare function resetMountState(): void;
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Zenith OnMount - Post-Mount Lifecycle Hook
3
+ *
4
+ * Registers a callback to run after a component's DOM is inserted.
5
+ * This is an effect wrapper that defers execution until the mount phase.
6
+ *
7
+ * Features:
8
+ * - Runs after DOM is available
9
+ * - Only runs once per mount
10
+ * - Supports cleanup function return
11
+ * - Works with component lifecycle system
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * zenOnMount(() => {
16
+ * console.log('Component mounted!')
17
+ * const el = document.querySelector('.my-element')
18
+ *
19
+ * // Optional cleanup - runs on unmount
20
+ * return () => {
21
+ * console.log('Component will unmount')
22
+ * }
23
+ * })
24
+ * ```
25
+ *
26
+ * Note: This hook registers callbacks that will be executed by the
27
+ * component lifecycle system. If no mount scheduler is active,
28
+ * callbacks are queued for later execution.
29
+ */
30
+ /**
31
+ * Queue of pending mount callbacks
32
+ * These are registered but not yet executed because mount hasn't occurred
33
+ */
34
+ const pendingMountCallbacks = [];
35
+ /**
36
+ * Currently active mount hooks (for cleanup on unmount)
37
+ */
38
+ const activeMountHooks = new Set();
39
+ /**
40
+ * Flag indicating whether we're in a mounted state
41
+ * This is controlled by the component lifecycle system
42
+ */
43
+ let isMounted = false;
44
+ /**
45
+ * Register a callback to run after component mount
46
+ *
47
+ * @param callback - Function to run after mount (can return cleanup function)
48
+ * @returns Dispose function to cancel the mount callback
49
+ */
50
+ export function zenOnMount(callback) {
51
+ const state = {
52
+ callback,
53
+ cleanup: null,
54
+ mounted: false
55
+ };
56
+ if (isMounted) {
57
+ // Already mounted - run immediately
58
+ executeMountCallback(state);
59
+ }
60
+ else {
61
+ // Queue for later execution
62
+ pendingMountCallbacks.push(state);
63
+ }
64
+ activeMountHooks.add(state);
65
+ // Return dispose function
66
+ return () => {
67
+ // Remove from pending if not yet executed
68
+ const pendingIndex = pendingMountCallbacks.indexOf(state);
69
+ if (pendingIndex !== -1) {
70
+ pendingMountCallbacks.splice(pendingIndex, 1);
71
+ }
72
+ // Run cleanup if already mounted
73
+ if (state.mounted && state.cleanup) {
74
+ state.cleanup();
75
+ state.cleanup = null;
76
+ }
77
+ activeMountHooks.delete(state);
78
+ };
79
+ }
80
+ /**
81
+ * Execute a mount callback
82
+ */
83
+ function executeMountCallback(state) {
84
+ if (state.mounted)
85
+ return;
86
+ state.mounted = true;
87
+ try {
88
+ const result = state.callback();
89
+ if (typeof result === 'function') {
90
+ state.cleanup = result;
91
+ }
92
+ }
93
+ catch (error) {
94
+ console.error('[Zenith] Error in onMount callback:', error);
95
+ }
96
+ }
97
+ /**
98
+ * Trigger mount phase - called by component lifecycle system
99
+ * Executes all pending mount callbacks
100
+ *
101
+ * @internal
102
+ */
103
+ export function triggerMount() {
104
+ isMounted = true;
105
+ // Execute all pending callbacks
106
+ const callbacks = [...pendingMountCallbacks];
107
+ pendingMountCallbacks.length = 0;
108
+ for (const state of callbacks) {
109
+ executeMountCallback(state);
110
+ }
111
+ }
112
+ /**
113
+ * Trigger unmount phase - called by component lifecycle system
114
+ * Runs cleanup functions for all active mount hooks
115
+ *
116
+ * @internal
117
+ */
118
+ export function triggerUnmount() {
119
+ isMounted = false;
120
+ // Run all cleanup functions
121
+ for (const state of activeMountHooks) {
122
+ if (state.cleanup) {
123
+ try {
124
+ state.cleanup();
125
+ }
126
+ catch (error) {
127
+ console.error('[Zenith] Error in onMount cleanup:', error);
128
+ }
129
+ state.cleanup = null;
130
+ }
131
+ state.mounted = false;
132
+ }
133
+ }
134
+ /**
135
+ * Check if currently in mounted state
136
+ *
137
+ * @internal
138
+ */
139
+ export function getIsMounted() {
140
+ return isMounted;
141
+ }
142
+ /**
143
+ * Reset mount state - for testing purposes
144
+ *
145
+ * @internal
146
+ */
147
+ export function resetMountState() {
148
+ isMounted = false;
149
+ pendingMountCallbacks.length = 0;
150
+ activeMountHooks.clear();
151
+ }
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Zenith OnUnmount - Pre-Unmount Lifecycle Hook
3
+ *
4
+ * Registers a cleanup callback to run before a component is disposed.
5
+ * Useful for cleaning up subscriptions, timers, event listeners, etc.
6
+ *
7
+ * Features:
8
+ * - Runs before component is removed from DOM
9
+ * - Can register multiple callbacks
10
+ * - Callbacks run in registration order
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * zenOnUnmount(() => {
15
+ * console.log('Cleaning up...')
16
+ * subscription.unsubscribe()
17
+ * clearInterval(timerId)
18
+ * })
19
+ * ```
20
+ *
21
+ * Note: This hook registers callbacks that will be executed by the
22
+ * component lifecycle system when the component is disposed.
23
+ */
24
+ /**
25
+ * Unmount callback type
26
+ */
27
+ export type UnmountCallback = () => void;
28
+ /**
29
+ * Register a callback to run before component unmount
30
+ *
31
+ * @param callback - Function to run before unmount
32
+ * @returns Dispose function to cancel the unmount callback
33
+ */
34
+ export declare function zenOnUnmount(callback: UnmountCallback): () => void;
35
+ /**
36
+ * Execute all unmount callbacks
37
+ * Called by the component lifecycle system before disposal
38
+ *
39
+ * @internal
40
+ */
41
+ export declare function executeUnmountCallbacks(): void;
42
+ /**
43
+ * Get count of registered unmount callbacks
44
+ * Useful for testing
45
+ *
46
+ * @internal
47
+ */
48
+ export declare function getUnmountCallbackCount(): number;
49
+ /**
50
+ * Reset unmount state - for testing purposes
51
+ *
52
+ * @internal
53
+ */
54
+ export declare function resetUnmountState(): void;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Zenith OnUnmount - Pre-Unmount Lifecycle Hook
3
+ *
4
+ * Registers a cleanup callback to run before a component is disposed.
5
+ * Useful for cleaning up subscriptions, timers, event listeners, etc.
6
+ *
7
+ * Features:
8
+ * - Runs before component is removed from DOM
9
+ * - Can register multiple callbacks
10
+ * - Callbacks run in registration order
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * zenOnUnmount(() => {
15
+ * console.log('Cleaning up...')
16
+ * subscription.unsubscribe()
17
+ * clearInterval(timerId)
18
+ * })
19
+ * ```
20
+ *
21
+ * Note: This hook registers callbacks that will be executed by the
22
+ * component lifecycle system when the component is disposed.
23
+ */
24
+ /**
25
+ * Queue of registered unmount callbacks
26
+ */
27
+ const unmountCallbacks = new Set();
28
+ /**
29
+ * Register a callback to run before component unmount
30
+ *
31
+ * @param callback - Function to run before unmount
32
+ * @returns Dispose function to cancel the unmount callback
33
+ */
34
+ export function zenOnUnmount(callback) {
35
+ unmountCallbacks.add(callback);
36
+ // Return dispose function
37
+ return () => {
38
+ unmountCallbacks.delete(callback);
39
+ };
40
+ }
41
+ /**
42
+ * Execute all unmount callbacks
43
+ * Called by the component lifecycle system before disposal
44
+ *
45
+ * @internal
46
+ */
47
+ export function executeUnmountCallbacks() {
48
+ // Execute in registration order
49
+ for (const callback of unmountCallbacks) {
50
+ try {
51
+ callback();
52
+ }
53
+ catch (error) {
54
+ console.error('[Zenith] Error in onUnmount callback:', error);
55
+ }
56
+ }
57
+ // Clear all callbacks after execution
58
+ unmountCallbacks.clear();
59
+ }
60
+ /**
61
+ * Get count of registered unmount callbacks
62
+ * Useful for testing
63
+ *
64
+ * @internal
65
+ */
66
+ export function getUnmountCallbackCount() {
67
+ return unmountCallbacks.size;
68
+ }
69
+ /**
70
+ * Reset unmount state - for testing purposes
71
+ *
72
+ * @internal
73
+ */
74
+ export function resetUnmountState() {
75
+ unmountCallbacks.clear();
76
+ }
@@ -0,0 +1,116 @@
1
+ /**
2
+ * Zenith CLI Bridge
3
+ *
4
+ * The ONLY interface between CLI and plugins.
5
+ *
6
+ * ═══════════════════════════════════════════════════════════════════════════════
7
+ * CLI BRIDGE RULES (CANONICAL)
8
+ * ═══════════════════════════════════════════════════════════════════════════════
9
+ *
10
+ * 1. No runtime emitters - plugins return data, CLI serializes blindly
11
+ * 2. No plugin typing - all data is unknown
12
+ * 3. No semantic helpers - CLI is blind to what data means
13
+ *
14
+ * The CLI dispatches hooks and collects returns. It never inspects payloads.
15
+ * ═══════════════════════════════════════════════════════════════════════════════
16
+ */
17
+ /**
18
+ * CLI Bridge API - passed to plugins during CLI registration
19
+ *
20
+ * Plugins use this to register namespaced hooks.
21
+ * CLI lifecycle hooks: 'cli:*'
22
+ * Plugin hooks: '<namespace>:*'
23
+ */
24
+ export interface CLIBridgeAPI {
25
+ /**
26
+ * Register a hook handler
27
+ *
28
+ * @param hook - Namespaced hook name (e.g., 'cli:runtime:collect', 'content:dev:watch')
29
+ * @param handler - Handler function that receives context and optionally returns data
30
+ */
31
+ on(hook: string, handler: (ctx: HookContext) => unknown | void | Promise<unknown | void>): void;
32
+ }
33
+ /**
34
+ * Context passed to hook handlers
35
+ *
36
+ * CLI provides this but never uses getPluginData itself.
37
+ * Only plugins call getPluginData with their own namespace.
38
+ */
39
+ export interface HookContext {
40
+ /** Absolute path to project root */
41
+ projectRoot: string;
42
+ /**
43
+ * Opaque data accessor
44
+ *
45
+ * CLI passes this function but NEVER calls it.
46
+ * Only plugins use it to access their own namespaced data.
47
+ */
48
+ getPluginData: (namespace: string) => unknown;
49
+ /** Additional context data (e.g., filename for file-change hooks) */
50
+ [key: string]: unknown;
51
+ }
52
+ /**
53
+ * Runtime payload returned by plugins
54
+ *
55
+ * CLI collects these and serializes without inspection.
56
+ * The envelope structure is: { [namespace]: payload }
57
+ */
58
+ export interface RuntimePayload {
59
+ /** Plugin namespace (e.g., 'content', 'router') */
60
+ namespace: string;
61
+ /** Opaque payload - CLI never inspects this */
62
+ payload: unknown;
63
+ }
64
+ type HookHandler = (ctx: HookContext) => unknown | void | Promise<unknown | void>;
65
+ /**
66
+ * Register a hook handler
67
+ *
68
+ * @internal Called by CLIBridgeAPI.on()
69
+ */
70
+ export declare function registerHook(hook: string, handler: HookHandler): void;
71
+ /**
72
+ * Clear all registered hooks
73
+ *
74
+ * @internal Used for testing and cleanup
75
+ */
76
+ export declare function clearHooks(): void;
77
+ /**
78
+ * Run all handlers for a hook (fire-and-forget)
79
+ *
80
+ * CLI calls this for lifecycle events.
81
+ * No return values are collected.
82
+ *
83
+ * @param hook - Hook name to dispatch
84
+ * @param ctx - Hook context
85
+ */
86
+ export declare function runPluginHooks(hook: string, ctx: HookContext): Promise<void>;
87
+ /**
88
+ * Collect return values from all handlers for a hook
89
+ *
90
+ * CLI calls this for 'cli:runtime:collect' to gather plugin payloads.
91
+ * Only RuntimePayload-shaped returns are collected.
92
+ *
93
+ * @param hook - Hook name to dispatch
94
+ * @param ctx - Hook context
95
+ * @returns Array of runtime payloads from plugins
96
+ */
97
+ export declare function collectHookReturns(hook: string, ctx: HookContext): Promise<RuntimePayload[]>;
98
+ /**
99
+ * Build runtime envelope from collected payloads
100
+ *
101
+ * CLI calls this to serialize plugin data for injection.
102
+ * CLI never inspects the envelope contents.
103
+ *
104
+ * @param payloads - Array of runtime payloads from collectHookReturns
105
+ * @returns Envelope object: { [namespace]: payload }
106
+ */
107
+ export declare function buildRuntimeEnvelope(payloads: RuntimePayload[]): Record<string, unknown>;
108
+ /**
109
+ * Create a CLI Bridge API for plugin registration
110
+ *
111
+ * CLI calls this once and passes to each plugin's registerCLI method.
112
+ *
113
+ * @returns CLIBridgeAPI instance
114
+ */
115
+ export declare function createBridgeAPI(): CLIBridgeAPI;
116
+ export {};
@@ -0,0 +1,121 @@
1
+ /**
2
+ * Zenith CLI Bridge
3
+ *
4
+ * The ONLY interface between CLI and plugins.
5
+ *
6
+ * ═══════════════════════════════════════════════════════════════════════════════
7
+ * CLI BRIDGE RULES (CANONICAL)
8
+ * ═══════════════════════════════════════════════════════════════════════════════
9
+ *
10
+ * 1. No runtime emitters - plugins return data, CLI serializes blindly
11
+ * 2. No plugin typing - all data is unknown
12
+ * 3. No semantic helpers - CLI is blind to what data means
13
+ *
14
+ * The CLI dispatches hooks and collects returns. It never inspects payloads.
15
+ * ═══════════════════════════════════════════════════════════════════════════════
16
+ */
17
+ const hookRegistry = new Map();
18
+ /**
19
+ * Register a hook handler
20
+ *
21
+ * @internal Called by CLIBridgeAPI.on()
22
+ */
23
+ export function registerHook(hook, handler) {
24
+ if (!hookRegistry.has(hook)) {
25
+ hookRegistry.set(hook, []);
26
+ }
27
+ hookRegistry.get(hook).push(handler);
28
+ }
29
+ /**
30
+ * Clear all registered hooks
31
+ *
32
+ * @internal Used for testing and cleanup
33
+ */
34
+ export function clearHooks() {
35
+ hookRegistry.clear();
36
+ }
37
+ // ============================================
38
+ // Hook Execution (CLI-facing)
39
+ // ============================================
40
+ /**
41
+ * Run all handlers for a hook (fire-and-forget)
42
+ *
43
+ * CLI calls this for lifecycle events.
44
+ * No return values are collected.
45
+ *
46
+ * @param hook - Hook name to dispatch
47
+ * @param ctx - Hook context
48
+ */
49
+ export async function runPluginHooks(hook, ctx) {
50
+ const handlers = hookRegistry.get(hook) || [];
51
+ for (const handler of handlers) {
52
+ try {
53
+ await handler(ctx);
54
+ }
55
+ catch (error) {
56
+ console.error(`[Zenith] Hook "${hook}" error:`, error);
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Collect return values from all handlers for a hook
62
+ *
63
+ * CLI calls this for 'cli:runtime:collect' to gather plugin payloads.
64
+ * Only RuntimePayload-shaped returns are collected.
65
+ *
66
+ * @param hook - Hook name to dispatch
67
+ * @param ctx - Hook context
68
+ * @returns Array of runtime payloads from plugins
69
+ */
70
+ export async function collectHookReturns(hook, ctx) {
71
+ const handlers = hookRegistry.get(hook) || [];
72
+ const results = [];
73
+ for (const handler of handlers) {
74
+ try {
75
+ const result = await handler(ctx);
76
+ // Only collect properly shaped payloads
77
+ if (result &&
78
+ typeof result === 'object' &&
79
+ 'namespace' in result &&
80
+ 'payload' in result &&
81
+ typeof result.namespace === 'string') {
82
+ results.push(result);
83
+ }
84
+ }
85
+ catch (error) {
86
+ console.error(`[Zenith] Hook "${hook}" collection error:`, error);
87
+ }
88
+ }
89
+ return results;
90
+ }
91
+ /**
92
+ * Build runtime envelope from collected payloads
93
+ *
94
+ * CLI calls this to serialize plugin data for injection.
95
+ * CLI never inspects the envelope contents.
96
+ *
97
+ * @param payloads - Array of runtime payloads from collectHookReturns
98
+ * @returns Envelope object: { [namespace]: payload }
99
+ */
100
+ export function buildRuntimeEnvelope(payloads) {
101
+ const envelope = {};
102
+ for (const { namespace, payload } of payloads) {
103
+ envelope[namespace] = payload;
104
+ }
105
+ return envelope;
106
+ }
107
+ // ============================================
108
+ // Bridge API Factory
109
+ // ============================================
110
+ /**
111
+ * Create a CLI Bridge API for plugin registration
112
+ *
113
+ * CLI calls this once and passes to each plugin's registerCLI method.
114
+ *
115
+ * @returns CLIBridgeAPI instance
116
+ */
117
+ export function createBridgeAPI() {
118
+ return {
119
+ on: registerHook
120
+ };
121
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Zenith Plugins
3
+ *
4
+ * Public exports for plugin system
5
+ */
6
+ export { PluginRegistry, createPluginContext } from './registry';
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Zenith Plugins
3
+ *
4
+ * Public exports for plugin system
5
+ */
6
+ export { PluginRegistry, createPluginContext } from './registry';
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Zenith Plugin Registry
3
+ *
4
+ * Manages plugin registration and initialization
5
+ *
6
+ * ═══════════════════════════════════════════════════════════════════════════════
7
+ * HOOK OWNERSHIP RULE (CANONICAL)
8
+ * ═══════════════════════════════════════════════════════════════════════════════
9
+ *
10
+ * The plugin registry is part of core infrastructure.
11
+ * It MUST remain plugin-agnostic:
12
+ * - No plugin-specific types
13
+ * - No plugin-specific logic
14
+ * - Generic data handling only
15
+ *
16
+ * Plugins own their data structures; core provides the storage mechanism.
17
+ * ═══════════════════════════════════════════════════════════════════════════════
18
+ */
19
+ import type { ZenithPlugin, PluginContext } from '../config/types';
20
+ /**
21
+ * Get all plugin data (for runtime access)
22
+ */
23
+ export declare function getPluginData(): Record<string, unknown[]>;
24
+ /**
25
+ * Get plugin data by namespace
26
+ */
27
+ export declare function getPluginDataByNamespace(namespace: string): unknown[];
28
+ /**
29
+ * Plugin registry for managing Zenith plugins
30
+ */
31
+ export declare class PluginRegistry {
32
+ private plugins;
33
+ /**
34
+ * Register a plugin
35
+ */
36
+ register(plugin: ZenithPlugin): void;
37
+ /**
38
+ * Get a plugin by name
39
+ */
40
+ get(name: string): ZenithPlugin | undefined;
41
+ /**
42
+ * Check if a plugin is registered
43
+ */
44
+ has(name: string): boolean;
45
+ /**
46
+ * Get all registered plugins
47
+ */
48
+ all(): ZenithPlugin[];
49
+ /**
50
+ * Initialize all plugins with the provided context
51
+ */
52
+ initAll(ctx: PluginContext): Promise<void>;
53
+ /**
54
+ * Clear all registered plugins
55
+ */
56
+ clear(): void;
57
+ }
58
+ /**
59
+ * Create a plugin context for initialization
60
+ *
61
+ * Uses a generic data setter that stores data by namespace.
62
+ * Plugins define their own data structures internally.
63
+ *
64
+ * @param projectRoot - Absolute path to the project root
65
+ * @returns A PluginContext for plugin initialization
66
+ */
67
+ export declare function createPluginContext(projectRoot: string): PluginContext;