@vib3code/sdk 2.0.1

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 (258) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/DOCS/BLUEPRINT_EXECUTION_PLAN_2026-01-07.md +34 -0
  3. package/DOCS/CI_TESTING.md +38 -0
  4. package/DOCS/CLI_ONBOARDING.md +75 -0
  5. package/DOCS/CONTROL_REFERENCE.md +64 -0
  6. package/DOCS/DEV_TRACK_ANALYSIS.md +77 -0
  7. package/DOCS/DEV_TRACK_PLAN_2026-01-07.md +42 -0
  8. package/DOCS/DEV_TRACK_SESSION_2026-01-31.md +220 -0
  9. package/DOCS/ENV_SETUP.md +189 -0
  10. package/DOCS/EXPORT_FORMATS.md +417 -0
  11. package/DOCS/GPU_DISPOSAL_GUIDE.md +21 -0
  12. package/DOCS/LICENSING_TIERS.md +275 -0
  13. package/DOCS/MASTER_PLAN_2026-01-31.md +570 -0
  14. package/DOCS/OBS_SETUP_GUIDE.md +98 -0
  15. package/DOCS/PROJECT_SETUP.md +66 -0
  16. package/DOCS/RENDERER_LIFECYCLE.md +40 -0
  17. package/DOCS/REPO_MANIFEST.md +121 -0
  18. package/DOCS/SESSION_014_PLAN.md +195 -0
  19. package/DOCS/SESSION_LOG_2026-01-07.md +56 -0
  20. package/DOCS/STRATEGIC_BLUEPRINT_2026-01-07.md +72 -0
  21. package/DOCS/SYSTEM_AUDIT_2026-01-30.md +738 -0
  22. package/DOCS/SYSTEM_INVENTORY.md +520 -0
  23. package/DOCS/TELEMETRY_EXPORTS.md +34 -0
  24. package/DOCS/WEBGPU_STATUS.md +38 -0
  25. package/DOCS/XR_BENCHMARKS.md +608 -0
  26. package/LICENSE +21 -0
  27. package/README.md +426 -0
  28. package/docs/.nojekyll +0 -0
  29. package/docs/01-dissolution_of_euclidean_hegemony.html +346 -0
  30. package/docs/02-hyperspatial_ego_death.html +346 -0
  31. package/docs/03-post_cartesian_sublime.html +346 -0
  32. package/docs/04-crystalline_void_meditation.html +346 -0
  33. package/docs/05-quantum_decoherence_ballet.html +346 -0
  34. package/docs/06-dissolution_of_euclidean_hegemony.html +346 -0
  35. package/docs/07-hyperspatial_ego_death.html +346 -0
  36. package/docs/08-post_cartesian_sublime.html +346 -0
  37. package/docs/09-crystalline_void_meditation.html +346 -0
  38. package/docs/10-quantum_decoherence_ballet.html +346 -0
  39. package/docs/11-dissolution_of_euclidean_hegemony.html +346 -0
  40. package/docs/12-hyperspatial_ego_death.html +346 -0
  41. package/docs/13-post_cartesian_sublime.html +346 -0
  42. package/docs/index.html +794 -0
  43. package/docs/test-hub.html +441 -0
  44. package/docs/url-state.js +102 -0
  45. package/docs/vib3-exports/01-quantum-quantum-tetrahedron-lattice.html +489 -0
  46. package/docs/vib3-exports/02-quantum-quantum-hypersphere-matrix.html +489 -0
  47. package/docs/vib3-exports/03-quantum-quantum-hypertetra-fractal.html +489 -0
  48. package/docs/vib3-exports/04-faceted-faceted-crystal-structure.html +407 -0
  49. package/docs/vib3-exports/05-faceted-faceted-klein-bottle.html +407 -0
  50. package/docs/vib3-exports/06-faceted-faceted-hypertetra-torus.html +407 -0
  51. package/docs/vib3-exports/07-holographic-holographic-wave-field.html +457 -0
  52. package/docs/vib3-exports/08-holographic-holographic-hypersphere-sphere.html +457 -0
  53. package/docs/vib3-exports/09-holographic-holographic-hypertetra-crystal.html +457 -0
  54. package/docs/vib3-exports/index.html +238 -0
  55. package/docs/webgpu-live.html +702 -0
  56. package/package.json +367 -0
  57. package/src/advanced/AIPresetGenerator.js +777 -0
  58. package/src/advanced/MIDIController.js +703 -0
  59. package/src/advanced/OffscreenWorker.js +1051 -0
  60. package/src/advanced/WebGPUCompute.js +1051 -0
  61. package/src/advanced/WebXRRenderer.js +680 -0
  62. package/src/agent/cli/AgentCLI.js +615 -0
  63. package/src/agent/cli/index.js +14 -0
  64. package/src/agent/index.js +73 -0
  65. package/src/agent/mcp/MCPServer.js +950 -0
  66. package/src/agent/mcp/index.js +9 -0
  67. package/src/agent/mcp/tools.js +548 -0
  68. package/src/agent/telemetry/EventStream.js +669 -0
  69. package/src/agent/telemetry/Instrumentation.js +618 -0
  70. package/src/agent/telemetry/TelemetryExporters.js +427 -0
  71. package/src/agent/telemetry/TelemetryService.js +464 -0
  72. package/src/agent/telemetry/index.js +52 -0
  73. package/src/benchmarks/BenchmarkRunner.js +381 -0
  74. package/src/benchmarks/MetricsCollector.js +299 -0
  75. package/src/benchmarks/index.js +9 -0
  76. package/src/benchmarks/scenes.js +259 -0
  77. package/src/cli/index.js +675 -0
  78. package/src/config/ApiConfig.js +88 -0
  79. package/src/core/CanvasManager.js +217 -0
  80. package/src/core/ErrorReporter.js +117 -0
  81. package/src/core/ParameterMapper.js +333 -0
  82. package/src/core/Parameters.js +396 -0
  83. package/src/core/RendererContracts.js +200 -0
  84. package/src/core/UnifiedResourceManager.js +370 -0
  85. package/src/core/VIB3Engine.js +636 -0
  86. package/src/core/renderers/FacetedRendererAdapter.js +32 -0
  87. package/src/core/renderers/HolographicRendererAdapter.js +29 -0
  88. package/src/core/renderers/QuantumRendererAdapter.js +29 -0
  89. package/src/core/renderers/RendererLifecycleManager.js +63 -0
  90. package/src/creative/ColorPresetsSystem.js +980 -0
  91. package/src/creative/ParameterTimeline.js +1061 -0
  92. package/src/creative/PostProcessingPipeline.js +1113 -0
  93. package/src/creative/TransitionAnimator.js +683 -0
  94. package/src/export/CSSExporter.js +226 -0
  95. package/src/export/CardGeneratorBase.js +279 -0
  96. package/src/export/ExportManager.js +580 -0
  97. package/src/export/FacetedCardGenerator.js +279 -0
  98. package/src/export/HolographicCardGenerator.js +543 -0
  99. package/src/export/LottieExporter.js +552 -0
  100. package/src/export/QuantumCardGenerator.js +315 -0
  101. package/src/export/SVGExporter.js +519 -0
  102. package/src/export/ShaderExporter.js +903 -0
  103. package/src/export/TradingCardGenerator.js +3055 -0
  104. package/src/export/TradingCardManager.js +181 -0
  105. package/src/export/VIB3PackageExporter.js +559 -0
  106. package/src/export/index.js +14 -0
  107. package/src/export/systems/TradingCardSystemFaceted.js +494 -0
  108. package/src/export/systems/TradingCardSystemHolographic.js +452 -0
  109. package/src/export/systems/TradingCardSystemQuantum.js +411 -0
  110. package/src/faceted/FacetedSystem.js +963 -0
  111. package/src/features/CollectionManager.js +433 -0
  112. package/src/gallery/CollectionManager.js +240 -0
  113. package/src/gallery/GallerySystem.js +485 -0
  114. package/src/geometry/GeometryFactory.js +314 -0
  115. package/src/geometry/GeometryLibrary.js +72 -0
  116. package/src/geometry/buffers/BufferBuilder.js +338 -0
  117. package/src/geometry/buffers/index.js +18 -0
  118. package/src/geometry/generators/Crystal.js +420 -0
  119. package/src/geometry/generators/Fractal.js +298 -0
  120. package/src/geometry/generators/KleinBottle.js +197 -0
  121. package/src/geometry/generators/Sphere.js +192 -0
  122. package/src/geometry/generators/Tesseract.js +160 -0
  123. package/src/geometry/generators/Tetrahedron.js +225 -0
  124. package/src/geometry/generators/Torus.js +304 -0
  125. package/src/geometry/generators/Wave.js +341 -0
  126. package/src/geometry/index.js +142 -0
  127. package/src/geometry/warp/HypersphereCore.js +211 -0
  128. package/src/geometry/warp/HypertetraCore.js +386 -0
  129. package/src/geometry/warp/index.js +57 -0
  130. package/src/holograms/HolographicVisualizer.js +1073 -0
  131. package/src/holograms/RealHolographicSystem.js +966 -0
  132. package/src/holograms/variantRegistry.js +69 -0
  133. package/src/integrations/FigmaPlugin.js +854 -0
  134. package/src/integrations/OBSMode.js +754 -0
  135. package/src/integrations/ThreeJsPackage.js +660 -0
  136. package/src/integrations/TouchDesignerExport.js +552 -0
  137. package/src/integrations/frameworks/Vib3React.js +591 -0
  138. package/src/integrations/frameworks/Vib3Svelte.js +654 -0
  139. package/src/integrations/frameworks/Vib3Vue.js +628 -0
  140. package/src/llm/LLMParameterInterface.js +240 -0
  141. package/src/llm/LLMParameterUI.js +577 -0
  142. package/src/math/Mat4x4.js +708 -0
  143. package/src/math/Projection.js +341 -0
  144. package/src/math/Rotor4D.js +637 -0
  145. package/src/math/Vec4.js +476 -0
  146. package/src/math/constants.js +164 -0
  147. package/src/math/index.js +68 -0
  148. package/src/math/projections.js +54 -0
  149. package/src/math/rotations.js +196 -0
  150. package/src/quantum/QuantumEngine.js +906 -0
  151. package/src/quantum/QuantumVisualizer.js +1103 -0
  152. package/src/reactivity/ReactivityConfig.js +499 -0
  153. package/src/reactivity/ReactivityManager.js +586 -0
  154. package/src/reactivity/SpatialInputSystem.js +1783 -0
  155. package/src/reactivity/index.js +93 -0
  156. package/src/render/CommandBuffer.js +465 -0
  157. package/src/render/MultiCanvasBridge.js +340 -0
  158. package/src/render/RenderCommand.js +514 -0
  159. package/src/render/RenderResourceRegistry.js +523 -0
  160. package/src/render/RenderState.js +552 -0
  161. package/src/render/RenderTarget.js +512 -0
  162. package/src/render/ShaderLoader.js +253 -0
  163. package/src/render/ShaderProgram.js +599 -0
  164. package/src/render/UnifiedRenderBridge.js +496 -0
  165. package/src/render/backends/WebGLBackend.js +1108 -0
  166. package/src/render/backends/WebGPUBackend.js +1409 -0
  167. package/src/render/commands/CommandBufferExecutor.js +607 -0
  168. package/src/render/commands/RenderCommandBuffer.js +661 -0
  169. package/src/render/commands/index.js +17 -0
  170. package/src/render/index.js +367 -0
  171. package/src/scene/Disposable.js +498 -0
  172. package/src/scene/MemoryPool.js +618 -0
  173. package/src/scene/Node4D.js +697 -0
  174. package/src/scene/ResourceManager.js +599 -0
  175. package/src/scene/Scene4D.js +540 -0
  176. package/src/scene/index.js +98 -0
  177. package/src/schemas/error.schema.json +84 -0
  178. package/src/schemas/extension.schema.json +88 -0
  179. package/src/schemas/index.js +214 -0
  180. package/src/schemas/parameters.schema.json +142 -0
  181. package/src/schemas/tool-pack.schema.json +44 -0
  182. package/src/schemas/tool-response.schema.json +127 -0
  183. package/src/shaders/common/fullscreen.vert.glsl +5 -0
  184. package/src/shaders/common/fullscreen.vert.wgsl +17 -0
  185. package/src/shaders/common/geometry24.glsl +65 -0
  186. package/src/shaders/common/geometry24.wgsl +54 -0
  187. package/src/shaders/common/rotation4d.glsl +85 -0
  188. package/src/shaders/common/rotation4d.wgsl +86 -0
  189. package/src/shaders/common/uniforms.glsl +44 -0
  190. package/src/shaders/common/uniforms.wgsl +48 -0
  191. package/src/shaders/faceted/faceted.frag.glsl +129 -0
  192. package/src/shaders/faceted/faceted.frag.wgsl +164 -0
  193. package/src/shaders/holographic/holographic.frag.glsl +406 -0
  194. package/src/shaders/holographic/holographic.frag.wgsl +185 -0
  195. package/src/shaders/quantum/quantum.frag.glsl +513 -0
  196. package/src/shaders/quantum/quantum.frag.wgsl +361 -0
  197. package/src/testing/ParallelTestFramework.js +519 -0
  198. package/src/testing/__snapshots__/exportFormats.test.js.snap +24 -0
  199. package/src/testing/exportFormats.test.js +8 -0
  200. package/src/testing/projections.test.js +14 -0
  201. package/src/testing/rotations.test.js +37 -0
  202. package/src/ui/InteractivityMenu.js +516 -0
  203. package/src/ui/StatusManager.js +96 -0
  204. package/src/ui/adaptive/renderers/webgpu/BufferLayout.ts +252 -0
  205. package/src/ui/adaptive/renderers/webgpu/PolytopeInstanceBuffer.ts +144 -0
  206. package/src/ui/adaptive/renderers/webgpu/TripleBufferedUniform.ts +170 -0
  207. package/src/ui/adaptive/renderers/webgpu/WebGPURenderer.ts +735 -0
  208. package/src/ui/adaptive/renderers/webgpu/index.ts +112 -0
  209. package/src/variations/VariationManager.js +431 -0
  210. package/src/viewer/AudioReactivity.js +505 -0
  211. package/src/viewer/CardBending.js +481 -0
  212. package/src/viewer/GalleryUI.js +832 -0
  213. package/src/viewer/ReactivityManager.js +590 -0
  214. package/src/viewer/TradingCardExporter.js +600 -0
  215. package/src/viewer/ViewerPortal.js +374 -0
  216. package/src/viewer/index.js +12 -0
  217. package/src/wasm/WasmLoader.js +296 -0
  218. package/src/wasm/index.js +132 -0
  219. package/tools/agentic/mcpTools.js +88 -0
  220. package/tools/cli/agent-cli.js +92 -0
  221. package/tools/export/formats.js +24 -0
  222. package/tools/math/rotation-baseline.mjs +64 -0
  223. package/tools/shader-sync-verify.js +937 -0
  224. package/tools/telemetry/manifestPipeline.js +141 -0
  225. package/tools/telemetry/telemetryEvents.js +35 -0
  226. package/types/adaptive-sdk.d.ts +185 -0
  227. package/types/advanced/AIPresetGenerator.d.ts +81 -0
  228. package/types/advanced/MIDIController.d.ts +100 -0
  229. package/types/advanced/OffscreenWorker.d.ts +82 -0
  230. package/types/advanced/WebGPUCompute.d.ts +52 -0
  231. package/types/advanced/WebXRRenderer.d.ts +77 -0
  232. package/types/advanced/index.d.ts +46 -0
  233. package/types/core/ErrorReporter.d.ts +50 -0
  234. package/types/core/VIB3Engine.d.ts +204 -0
  235. package/types/creative/ColorPresetsSystem.d.ts +91 -0
  236. package/types/creative/ParameterTimeline.d.ts +74 -0
  237. package/types/creative/PostProcessingPipeline.d.ts +109 -0
  238. package/types/creative/TransitionAnimator.d.ts +71 -0
  239. package/types/creative/index.d.ts +35 -0
  240. package/types/integrations/FigmaPlugin.d.ts +46 -0
  241. package/types/integrations/OBSMode.d.ts +74 -0
  242. package/types/integrations/ThreeJsPackage.d.ts +62 -0
  243. package/types/integrations/TouchDesignerExport.d.ts +36 -0
  244. package/types/integrations/Vib3React.d.ts +74 -0
  245. package/types/integrations/Vib3Svelte.d.ts +63 -0
  246. package/types/integrations/Vib3Vue.d.ts +55 -0
  247. package/types/integrations/index.d.ts +52 -0
  248. package/types/reactivity/SpatialInputSystem.d.ts +173 -0
  249. package/types/reactivity/index.d.ts +394 -0
  250. package/types/render/CommandBuffer.d.ts +169 -0
  251. package/types/render/RenderCommand.d.ts +312 -0
  252. package/types/render/RenderState.d.ts +279 -0
  253. package/types/render/RenderTarget.d.ts +254 -0
  254. package/types/render/ShaderProgram.d.ts +277 -0
  255. package/types/render/UnifiedRenderBridge.d.ts +143 -0
  256. package/types/render/WebGLBackend.d.ts +168 -0
  257. package/types/render/WebGPUBackend.d.ts +186 -0
  258. package/types/render/index.d.ts +141 -0
@@ -0,0 +1,615 @@
1
+ /**
2
+ * AgentCLI.js - Command Line Interface for Agentic Integration
3
+ *
4
+ * Provides streaming and batch modes for agent control of VIB3+ engine.
5
+ * Supports JSONL input/output for easy integration with LLM agents.
6
+ */
7
+
8
+ import { EventEmitter } from 'events';
9
+ import { createInterface } from 'readline';
10
+ import { telemetry, EventType } from '../telemetry/TelemetryService.js';
11
+ import {
12
+ PrometheusExporter,
13
+ JSONExporter,
14
+ NDJSONExporter,
15
+ ConsoleExporter
16
+ } from '../telemetry/TelemetryExporters.js';
17
+ import { EventStreamServer, connectTelemetryToStream } from '../telemetry/EventStream.js';
18
+
19
+ /**
20
+ * CLI Command types
21
+ */
22
+ export const CommandType = {
23
+ // Engine commands
24
+ SET_PARAMETER: 'set_parameter',
25
+ GET_PARAMETER: 'get_parameter',
26
+ SET_GEOMETRY: 'set_geometry',
27
+ SET_SYSTEM: 'set_system',
28
+
29
+ // Rotation commands
30
+ ROTATE: 'rotate',
31
+ RESET_ROTATION: 'reset_rotation',
32
+
33
+ // Batch operations
34
+ BATCH: 'batch',
35
+ BATCH_ROTATE: 'batch_rotate',
36
+
37
+ // Telemetry
38
+ GET_METRICS: 'get_metrics',
39
+ GET_SPANS: 'get_spans',
40
+ FLUSH_TELEMETRY: 'flush_telemetry',
41
+
42
+ // Control
43
+ PING: 'ping',
44
+ STATUS: 'status',
45
+ HELP: 'help',
46
+ QUIT: 'quit'
47
+ };
48
+
49
+ /**
50
+ * Response status codes
51
+ */
52
+ export const ResponseStatus = {
53
+ OK: 'ok',
54
+ ERROR: 'error',
55
+ PARTIAL: 'partial'
56
+ };
57
+
58
+ /**
59
+ * Agent CLI for VIB3+ Engine
60
+ */
61
+ export class AgentCLI extends EventEmitter {
62
+ constructor(engine, options = {}) {
63
+ super();
64
+
65
+ /** @type {object} VIB3+ Engine instance */
66
+ this.engine = engine;
67
+
68
+ /** @type {object} Options */
69
+ this.options = {
70
+ inputStream: options.inputStream || process.stdin,
71
+ outputStream: options.outputStream || process.stdout,
72
+ errorStream: options.errorStream || process.stderr,
73
+ format: options.format || 'jsonl', // jsonl, json, text
74
+ pretty: options.pretty || false,
75
+ enableTelemetry: options.enableTelemetry !== false,
76
+ ...options
77
+ };
78
+
79
+ /** @type {readline.Interface|null} */
80
+ this._readline = null;
81
+
82
+ /** @type {boolean} */
83
+ this._running = false;
84
+
85
+ /** @type {number} Command counter */
86
+ this._commandCount = 0;
87
+
88
+ /** @type {Map<string, Function>} Command handlers */
89
+ this._handlers = new Map();
90
+
91
+ /** @type {EventStreamServer|null} */
92
+ this._streamServer = null;
93
+
94
+ this._registerDefaultHandlers();
95
+ }
96
+
97
+ /**
98
+ * Start CLI in streaming mode
99
+ */
100
+ start() {
101
+ if (this._running) return;
102
+ this._running = true;
103
+
104
+ this._readline = createInterface({
105
+ input: this.options.inputStream,
106
+ output: this.options.outputStream,
107
+ terminal: false
108
+ });
109
+
110
+ this._readline.on('line', (line) => {
111
+ this._processLine(line);
112
+ });
113
+
114
+ this._readline.on('close', () => {
115
+ this._running = false;
116
+ this.emit('close');
117
+ });
118
+
119
+ // Send ready signal
120
+ this._respond({
121
+ type: 'ready',
122
+ version: '1.7.0',
123
+ commands: Object.values(CommandType)
124
+ });
125
+
126
+ if (this.options.enableTelemetry) {
127
+ telemetry.recordEvent(EventType.TOOL_INVOCATION, {
128
+ tool: 'AgentCLI',
129
+ action: 'start'
130
+ });
131
+ }
132
+
133
+ this.emit('start');
134
+ }
135
+
136
+ /**
137
+ * Stop CLI
138
+ */
139
+ stop() {
140
+ if (this._readline) {
141
+ this._readline.close();
142
+ this._readline = null;
143
+ }
144
+ this._running = false;
145
+ this.emit('stop');
146
+ }
147
+
148
+ /**
149
+ * Process input line
150
+ * @private
151
+ */
152
+ async _processLine(line) {
153
+ const trimmed = line.trim();
154
+ if (!trimmed) return;
155
+
156
+ let command;
157
+
158
+ try {
159
+ // Parse as JSON
160
+ command = JSON.parse(trimmed);
161
+ } catch {
162
+ // Try as simple text command
163
+ command = this._parseTextCommand(trimmed);
164
+ }
165
+
166
+ if (!command) {
167
+ this._respond({
168
+ status: ResponseStatus.ERROR,
169
+ error: 'Invalid command format'
170
+ });
171
+ return;
172
+ }
173
+
174
+ // Process command
175
+ await this._executeCommand(command);
176
+ }
177
+
178
+ /**
179
+ * Parse simple text command
180
+ * @private
181
+ */
182
+ _parseTextCommand(text) {
183
+ const parts = text.split(/\s+/);
184
+ const cmd = parts[0]?.toLowerCase();
185
+
186
+ switch (cmd) {
187
+ case 'ping':
188
+ return { type: CommandType.PING };
189
+ case 'status':
190
+ return { type: CommandType.STATUS };
191
+ case 'help':
192
+ return { type: CommandType.HELP };
193
+ case 'quit':
194
+ case 'exit':
195
+ return { type: CommandType.QUIT };
196
+ case 'metrics':
197
+ return { type: CommandType.GET_METRICS };
198
+ case 'set':
199
+ return {
200
+ type: CommandType.SET_PARAMETER,
201
+ param: parts[1],
202
+ value: parseFloat(parts[2]) || parts[2]
203
+ };
204
+ case 'get':
205
+ return {
206
+ type: CommandType.GET_PARAMETER,
207
+ param: parts[1]
208
+ };
209
+ case 'rotate':
210
+ return {
211
+ type: CommandType.ROTATE,
212
+ plane: parts[1],
213
+ angle: parseFloat(parts[2])
214
+ };
215
+ case 'geometry':
216
+ return {
217
+ type: CommandType.SET_GEOMETRY,
218
+ index: parseInt(parts[1], 10)
219
+ };
220
+ case 'system':
221
+ return {
222
+ type: CommandType.SET_SYSTEM,
223
+ system: parts[1]
224
+ };
225
+ default:
226
+ return null;
227
+ }
228
+ }
229
+
230
+ /**
231
+ * Execute a command
232
+ * @private
233
+ */
234
+ async _executeCommand(command) {
235
+ this._commandCount++;
236
+ const startTime = performance.now();
237
+
238
+ const commandId = command.id || `cmd_${this._commandCount}`;
239
+
240
+ try {
241
+ const handler = this._handlers.get(command.type);
242
+
243
+ if (!handler) {
244
+ this._respond({
245
+ id: commandId,
246
+ status: ResponseStatus.ERROR,
247
+ error: `Unknown command type: ${command.type}`
248
+ });
249
+ return;
250
+ }
251
+
252
+ const result = await handler(command);
253
+
254
+ const duration = performance.now() - startTime;
255
+
256
+ this._respond({
257
+ id: commandId,
258
+ status: ResponseStatus.OK,
259
+ result,
260
+ durationMs: duration
261
+ });
262
+
263
+ if (this.options.enableTelemetry) {
264
+ telemetry.recordEvent(EventType.TOOL_INVOCATION, {
265
+ tool: 'AgentCLI',
266
+ command: command.type,
267
+ durationMs: duration
268
+ });
269
+ }
270
+
271
+ } catch (error) {
272
+ const duration = performance.now() - startTime;
273
+
274
+ this._respond({
275
+ id: commandId,
276
+ status: ResponseStatus.ERROR,
277
+ error: error.message,
278
+ durationMs: duration
279
+ });
280
+
281
+ if (this.options.enableTelemetry) {
282
+ telemetry.recordEvent(EventType.TOOL_ERROR, {
283
+ tool: 'AgentCLI',
284
+ command: command.type,
285
+ error: error.message
286
+ });
287
+ }
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Send response to output
293
+ * @private
294
+ */
295
+ _respond(data) {
296
+ let output;
297
+
298
+ switch (this.options.format) {
299
+ case 'json':
300
+ output = this.options.pretty
301
+ ? JSON.stringify(data, null, 2)
302
+ : JSON.stringify(data);
303
+ break;
304
+
305
+ case 'text':
306
+ output = this._formatAsText(data);
307
+ break;
308
+
309
+ case 'jsonl':
310
+ default:
311
+ output = JSON.stringify(data);
312
+ break;
313
+ }
314
+
315
+ this.options.outputStream.write(output + '\n');
316
+ this.emit('response', data);
317
+ }
318
+
319
+ /**
320
+ * Format response as text
321
+ * @private
322
+ */
323
+ _formatAsText(data) {
324
+ if (data.status === ResponseStatus.ERROR) {
325
+ return `ERROR: ${data.error}`;
326
+ }
327
+
328
+ if (data.type === 'ready') {
329
+ return `VIB3+ CLI v${data.version} ready`;
330
+ }
331
+
332
+ if (data.result !== undefined) {
333
+ if (typeof data.result === 'object') {
334
+ return JSON.stringify(data.result);
335
+ }
336
+ return String(data.result);
337
+ }
338
+
339
+ return 'OK';
340
+ }
341
+
342
+ /**
343
+ * Register default command handlers
344
+ * @private
345
+ */
346
+ _registerDefaultHandlers() {
347
+ // Ping
348
+ this._handlers.set(CommandType.PING, () => ({
349
+ pong: true,
350
+ timestamp: new Date().toISOString()
351
+ }));
352
+
353
+ // Status
354
+ this._handlers.set(CommandType.STATUS, () => ({
355
+ running: this._running,
356
+ commandsProcessed: this._commandCount,
357
+ engine: this.engine ? {
358
+ system: this.engine.currentSystem || 'unknown',
359
+ geometry: this.engine.currentGeometry || 0
360
+ } : null
361
+ }));
362
+
363
+ // Help
364
+ this._handlers.set(CommandType.HELP, () => ({
365
+ commands: Object.entries(CommandType).map(([name, type]) => ({
366
+ name,
367
+ type
368
+ })),
369
+ formats: ['jsonl', 'json', 'text']
370
+ }));
371
+
372
+ // Quit
373
+ this._handlers.set(CommandType.QUIT, () => {
374
+ setTimeout(() => this.stop(), 100);
375
+ return { goodbye: true };
376
+ });
377
+
378
+ // Set parameter
379
+ this._handlers.set(CommandType.SET_PARAMETER, (cmd) => {
380
+ if (!this.engine) throw new Error('No engine connected');
381
+ if (!cmd.param) throw new Error('Missing param');
382
+
383
+ this.engine.setParameter?.(cmd.param, cmd.value);
384
+ return { param: cmd.param, value: cmd.value };
385
+ });
386
+
387
+ // Get parameter
388
+ this._handlers.set(CommandType.GET_PARAMETER, (cmd) => {
389
+ if (!this.engine) throw new Error('No engine connected');
390
+ if (!cmd.param) throw new Error('Missing param');
391
+
392
+ const value = this.engine.getParameter?.(cmd.param);
393
+ return { param: cmd.param, value };
394
+ });
395
+
396
+ // Set geometry
397
+ this._handlers.set(CommandType.SET_GEOMETRY, (cmd) => {
398
+ if (!this.engine) throw new Error('No engine connected');
399
+
400
+ const index = cmd.index ?? cmd.geometry;
401
+ if (index === undefined) throw new Error('Missing geometry index');
402
+
403
+ this.engine.setGeometry?.(index);
404
+ return { geometry: index };
405
+ });
406
+
407
+ // Set system
408
+ this._handlers.set(CommandType.SET_SYSTEM, (cmd) => {
409
+ if (!this.engine) throw new Error('No engine connected');
410
+ if (!cmd.system) throw new Error('Missing system');
411
+
412
+ this.engine.setSystem?.(cmd.system);
413
+ return { system: cmd.system };
414
+ });
415
+
416
+ // Rotate
417
+ this._handlers.set(CommandType.ROTATE, (cmd) => {
418
+ if (!this.engine) throw new Error('No engine connected');
419
+
420
+ const plane = cmd.plane?.toUpperCase() || 'XW';
421
+ const angle = cmd.angle ?? 0;
422
+
423
+ this.engine.rotate?.(plane, angle);
424
+ return { plane, angle };
425
+ });
426
+
427
+ // Reset rotation
428
+ this._handlers.set(CommandType.RESET_ROTATION, () => {
429
+ if (!this.engine) throw new Error('No engine connected');
430
+
431
+ this.engine.resetRotation?.();
432
+ return { reset: true };
433
+ });
434
+
435
+ // Batch
436
+ this._handlers.set(CommandType.BATCH, async (cmd) => {
437
+ if (!cmd.commands || !Array.isArray(cmd.commands)) {
438
+ throw new Error('Missing commands array');
439
+ }
440
+
441
+ const results = [];
442
+ let errors = 0;
443
+
444
+ for (const subCmd of cmd.commands) {
445
+ try {
446
+ const handler = this._handlers.get(subCmd.type);
447
+ if (handler) {
448
+ const result = await handler(subCmd);
449
+ results.push({ status: 'ok', result });
450
+ } else {
451
+ results.push({ status: 'error', error: 'Unknown command' });
452
+ errors++;
453
+ }
454
+ } catch (err) {
455
+ results.push({ status: 'error', error: err.message });
456
+ errors++;
457
+ }
458
+ }
459
+
460
+ return {
461
+ total: cmd.commands.length,
462
+ succeeded: cmd.commands.length - errors,
463
+ failed: errors,
464
+ results
465
+ };
466
+ });
467
+
468
+ // Batch rotate
469
+ this._handlers.set(CommandType.BATCH_ROTATE, (cmd) => {
470
+ if (!this.engine) throw new Error('No engine connected');
471
+
472
+ const rotations = cmd.rotations || {};
473
+
474
+ for (const [plane, angle] of Object.entries(rotations)) {
475
+ this.engine.rotate?.(plane.toUpperCase(), angle);
476
+ }
477
+
478
+ return { rotations };
479
+ });
480
+
481
+ // Get metrics
482
+ this._handlers.set(CommandType.GET_METRICS, (cmd) => {
483
+ const metrics = telemetry.getMetrics();
484
+
485
+ if (cmd.format === 'prometheus') {
486
+ const exporter = new PrometheusExporter();
487
+ return { format: 'prometheus', data: exporter.export(metrics) };
488
+ }
489
+
490
+ return metrics;
491
+ });
492
+
493
+ // Get spans
494
+ this._handlers.set(CommandType.GET_SPANS, () => {
495
+ const spans = telemetry.getSpans?.() || [];
496
+ return { count: spans.length, spans };
497
+ });
498
+
499
+ // Flush telemetry
500
+ this._handlers.set(CommandType.FLUSH_TELEMETRY, () => {
501
+ const payload = telemetry.flush();
502
+ return payload;
503
+ });
504
+ }
505
+
506
+ /**
507
+ * Register custom command handler
508
+ * @param {string} type - Command type
509
+ * @param {Function} handler - Handler function
510
+ */
511
+ registerHandler(type, handler) {
512
+ this._handlers.set(type, handler);
513
+ }
514
+
515
+ /**
516
+ * Execute single command (for programmatic use)
517
+ * @param {object} command
518
+ * @returns {Promise<object>}
519
+ */
520
+ async execute(command) {
521
+ const handler = this._handlers.get(command.type);
522
+ if (!handler) {
523
+ throw new Error(`Unknown command: ${command.type}`);
524
+ }
525
+ return handler(command);
526
+ }
527
+ }
528
+
529
+ /**
530
+ * Batch command executor
531
+ */
532
+ export class BatchExecutor {
533
+ constructor(cli) {
534
+ this.cli = cli;
535
+ this.queue = [];
536
+ this.results = [];
537
+ }
538
+
539
+ /**
540
+ * Add command to batch
541
+ */
542
+ add(command) {
543
+ this.queue.push(command);
544
+ return this;
545
+ }
546
+
547
+ /**
548
+ * Execute all queued commands
549
+ */
550
+ async execute() {
551
+ this.results = [];
552
+
553
+ for (const cmd of this.queue) {
554
+ try {
555
+ const result = await this.cli.execute(cmd);
556
+ this.results.push({ status: 'ok', command: cmd.type, result });
557
+ } catch (err) {
558
+ this.results.push({ status: 'error', command: cmd.type, error: err.message });
559
+ }
560
+ }
561
+
562
+ this.queue = [];
563
+ return this.results;
564
+ }
565
+
566
+ /**
567
+ * Execute commands in parallel
568
+ */
569
+ async executeParallel() {
570
+ const promises = this.queue.map(async (cmd) => {
571
+ try {
572
+ const result = await this.cli.execute(cmd);
573
+ return { status: 'ok', command: cmd.type, result };
574
+ } catch (err) {
575
+ return { status: 'error', command: cmd.type, error: err.message };
576
+ }
577
+ });
578
+
579
+ this.results = await Promise.all(promises);
580
+ this.queue = [];
581
+ return this.results;
582
+ }
583
+ }
584
+
585
+ /**
586
+ * Create CLI with SSE streaming
587
+ */
588
+ export function createStreamingCLI(engine, httpServer, options = {}) {
589
+ const cli = new AgentCLI(engine, options);
590
+ const streamServer = new EventStreamServer(options.streamOptions);
591
+
592
+ // Connect telemetry to stream
593
+ connectTelemetryToStream(telemetry, streamServer);
594
+
595
+ // Add stream endpoint to HTTP server
596
+ if (httpServer) {
597
+ httpServer.on('request', (req, res) => {
598
+ if (req.url?.startsWith('/events')) {
599
+ streamServer.handleConnection(req, res);
600
+ }
601
+ });
602
+ }
603
+
604
+ cli._streamServer = streamServer;
605
+
606
+ return { cli, streamServer };
607
+ }
608
+
609
+ export default {
610
+ AgentCLI,
611
+ BatchExecutor,
612
+ CommandType,
613
+ ResponseStatus,
614
+ createStreamingCLI
615
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * VIB3+ Agent CLI Module
3
+ */
4
+
5
+ export {
6
+ AgentCLI,
7
+ BatchExecutor,
8
+ CommandType,
9
+ ResponseStatus,
10
+ createStreamingCLI
11
+ } from './AgentCLI.js';
12
+
13
+ import AgentCLI from './AgentCLI.js';
14
+ export default AgentCLI;
@@ -0,0 +1,73 @@
1
+ /**
2
+ * VIB3+ Agent Module
3
+ * Agentic integration layer with MCP server, telemetry, and CLI
4
+ */
5
+
6
+ // Telemetry - Core
7
+ export {
8
+ TelemetryService,
9
+ TelemetrySpan,
10
+ EventType,
11
+ SpanStatus,
12
+ withTelemetry,
13
+ withTelemetrySync,
14
+ telemetry
15
+ } from './telemetry/index.js';
16
+
17
+ // Telemetry - Exporters
18
+ export {
19
+ PrometheusExporter,
20
+ JSONExporter,
21
+ NDJSONExporter,
22
+ ConsoleExporter,
23
+ createExporter
24
+ } from './telemetry/index.js';
25
+
26
+ // Telemetry - Event Streaming
27
+ export {
28
+ StreamEventType,
29
+ EventStreamServer,
30
+ EventStreamClient,
31
+ SSEConnection,
32
+ createSSEHandler,
33
+ connectTelemetryToStream
34
+ } from './telemetry/index.js';
35
+
36
+ // Telemetry - Instrumentation
37
+ export {
38
+ configureTelemetry,
39
+ getTelemetry,
40
+ trace,
41
+ traceFunction,
42
+ traceAsyncIterable,
43
+ instrumentClass,
44
+ traceObject,
45
+ withTiming,
46
+ meter,
47
+ traceBatch,
48
+ TraceContext
49
+ } from './telemetry/index.js';
50
+
51
+ // MCP
52
+ export {
53
+ MCPServer,
54
+ mcpServer,
55
+ toolDefinitions,
56
+ getToolList,
57
+ getToolNames,
58
+ getTool,
59
+ validateToolInput
60
+ } from './mcp/index.js';
61
+
62
+ // CLI
63
+ export {
64
+ AgentCLI,
65
+ BatchExecutor,
66
+ CommandType,
67
+ ResponseStatus,
68
+ createStreamingCLI
69
+ } from './cli/index.js';
70
+
71
+ // Default exports
72
+ export { telemetry } from './telemetry/index.js';
73
+ export { mcpServer } from './mcp/index.js';