@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,675 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * VIB3+ CLI
4
+ * Agent-friendly command-line interface with JSON output mode
5
+ */
6
+
7
+ import { performance } from 'node:perf_hooks';
8
+ import { mcpServer, toolDefinitions } from '../agent/index.js';
9
+ import { schemaRegistry } from '../schemas/index.js';
10
+
11
+ /**
12
+ * CLI Configuration
13
+ */
14
+ const CLI_VERSION = '1.0.0';
15
+ const CLI_NAME = 'vib3';
16
+
17
+ /**
18
+ * Exit codes following standard conventions
19
+ */
20
+ const ExitCode = {
21
+ SUCCESS: 0,
22
+ ERROR: 1,
23
+ INVALID_ARGS: 2,
24
+ NOT_FOUND: 3,
25
+ VALIDATION_ERROR: 4
26
+ };
27
+
28
+ /**
29
+ * Parse command line arguments
30
+ */
31
+ function parseArgs(args) {
32
+ const parsed = {
33
+ command: null,
34
+ subcommand: null,
35
+ options: {},
36
+ positional: [],
37
+ flags: {
38
+ json: false,
39
+ help: false,
40
+ version: false,
41
+ noInteractive: false,
42
+ verbose: false
43
+ }
44
+ };
45
+
46
+ let i = 0;
47
+ while (i < args.length) {
48
+ const arg = args[i];
49
+
50
+ if (arg === '--json' || arg === '-j') {
51
+ parsed.flags.json = true;
52
+ } else if (arg === '--help' || arg === '-h') {
53
+ parsed.flags.help = true;
54
+ } else if (arg === '--version' || arg === '-v') {
55
+ parsed.flags.version = true;
56
+ } else if (arg === '--no-interactive') {
57
+ parsed.flags.noInteractive = true;
58
+ } else if (arg === '--verbose') {
59
+ parsed.flags.verbose = true;
60
+ } else if (arg.startsWith('--')) {
61
+ // Parse --key=value or --key value
62
+ const [key, ...valueParts] = arg.slice(2).split('=');
63
+ if (valueParts.length > 0) {
64
+ parsed.options[key] = valueParts.join('=');
65
+ } else if (i + 1 < args.length && !args[i + 1].startsWith('-')) {
66
+ parsed.options[key] = args[++i];
67
+ } else {
68
+ parsed.options[key] = true;
69
+ }
70
+ } else if (arg.startsWith('-')) {
71
+ // Short options
72
+ const key = arg.slice(1);
73
+ if (i + 1 < args.length && !args[i + 1].startsWith('-')) {
74
+ parsed.options[key] = args[++i];
75
+ } else {
76
+ parsed.options[key] = true;
77
+ }
78
+ } else if (!parsed.command) {
79
+ parsed.command = arg;
80
+ } else if (!parsed.subcommand) {
81
+ parsed.subcommand = arg;
82
+ } else {
83
+ parsed.positional.push(arg);
84
+ }
85
+
86
+ i++;
87
+ }
88
+
89
+ return parsed;
90
+ }
91
+
92
+ /**
93
+ * Output formatter
94
+ */
95
+ function output(data, isJson) {
96
+ if (isJson) {
97
+ console.log(JSON.stringify(data, null, 2));
98
+ } else {
99
+ if (typeof data === 'string') {
100
+ console.log(data);
101
+ } else if (data.error) {
102
+ console.error(`Error [${data.error.code}]: ${data.error.message}`);
103
+ if (data.error.suggestion) {
104
+ console.error(`Suggestion: ${data.error.suggestion}`);
105
+ }
106
+ } else {
107
+ console.log(formatHumanReadable(data));
108
+ }
109
+ }
110
+ }
111
+
112
+ function wrapResponse(operation, data = {}, success = true, durationMs = null) {
113
+ return {
114
+ success,
115
+ operation,
116
+ timestamp: new Date().toISOString(),
117
+ duration_ms: durationMs ?? undefined,
118
+ ...data
119
+ };
120
+ }
121
+
122
+ function validateResponseEnvelope(response) {
123
+ const validation = schemaRegistry.validate('toolResponse', response);
124
+ if (!validation.valid) {
125
+ return { ...response, validation_errors: validation.errors };
126
+ }
127
+ return response;
128
+ }
129
+
130
+ /**
131
+ * Format data for human-readable output
132
+ */
133
+ function formatHumanReadable(data) {
134
+ const lines = [];
135
+
136
+ if (data.success !== undefined) {
137
+ lines.push(`Status: ${data.success ? 'SUCCESS' : 'FAILED'}`);
138
+ }
139
+ if (data.operation) {
140
+ lines.push(`Operation: ${data.operation}`);
141
+ }
142
+ if (data.scene_id) {
143
+ lines.push(`Scene ID: ${data.scene_id}`);
144
+ }
145
+ if (data.system) {
146
+ lines.push(`System: ${data.system}`);
147
+ }
148
+ if (data.geometry) {
149
+ lines.push(`Geometry: ${data.geometry.base_type} (${data.geometry.core_type}) [index: ${data.geometry.index}]`);
150
+ }
151
+ if (data.rotation_state) {
152
+ const r = data.rotation_state;
153
+ lines.push(`Rotation: XY=${r.XY?.toFixed(2)}, XZ=${r.XZ?.toFixed(2)}, YZ=${r.YZ?.toFixed(2)}, XW=${r.XW?.toFixed(2)}, YW=${r.YW?.toFixed(2)}, ZW=${r.ZW?.toFixed(2)}`);
154
+ }
155
+ if (data.suggested_next_actions?.length) {
156
+ lines.push(`Next actions: ${data.suggested_next_actions.join(', ')}`);
157
+ }
158
+ if (data.duration_ms !== undefined) {
159
+ lines.push(`Duration: ${data.duration_ms.toFixed(2)}ms`);
160
+ }
161
+
162
+ return lines.join('\n');
163
+ }
164
+
165
+ /**
166
+ * Show help
167
+ */
168
+ function showHelp(isJson) {
169
+ const help = {
170
+ name: CLI_NAME,
171
+ version: CLI_VERSION,
172
+ description: 'VIB3+ 4D Visualization Engine CLI',
173
+ usage: `${CLI_NAME} <command> [options]`,
174
+ commands: {
175
+ create: 'Create a new 4D visualization',
176
+ state: 'Get current engine state',
177
+ set: 'Set parameters (rotation, visual)',
178
+ geometry: 'Change or list geometries',
179
+ system: 'Switch visualization system',
180
+ randomize: 'Randomize all parameters',
181
+ reset: 'Reset to default parameters',
182
+ tools: 'List available MCP tools',
183
+ validate: 'Validate manifests, packs, and configs'
184
+ },
185
+ options: {
186
+ '--json, -j': 'Output in JSON format (agent-friendly)',
187
+ '--help, -h': 'Show this help message',
188
+ '--version, -v': 'Show version',
189
+ '--no-interactive': 'Disable interactive prompts',
190
+ '--verbose': 'Verbose output'
191
+ },
192
+ examples: [
193
+ `${CLI_NAME} create --system quantum --geometry 8 --json`,
194
+ `${CLI_NAME} set rotation --XW 1.5 --YW 0.5`,
195
+ `${CLI_NAME} set visual --hue 200 --chaos 0.3`,
196
+ `${CLI_NAME} geometry list --core-type hypersphere`,
197
+ `${CLI_NAME} state --json`,
198
+ `${CLI_NAME} tools --json`,
199
+ `${CLI_NAME} validate pack scene.vib3 --json`,
200
+ `${CLI_NAME} validate manifest extension.json`
201
+ ]
202
+ };
203
+
204
+ output(help, isJson);
205
+ }
206
+
207
+ /**
208
+ * Show version
209
+ */
210
+ function showVersion(isJson) {
211
+ const version = {
212
+ name: CLI_NAME,
213
+ version: CLI_VERSION,
214
+ node: process.version,
215
+ platform: process.platform
216
+ };
217
+
218
+ if (isJson) {
219
+ output(version, true);
220
+ } else {
221
+ console.log(`${CLI_NAME} v${CLI_VERSION}`);
222
+ }
223
+ }
224
+
225
+ /**
226
+ * Handle 'create' command
227
+ */
228
+ async function handleCreate(parsed) {
229
+ const args = {
230
+ system: parsed.options.system || 'quantum',
231
+ geometry_index: parseInt(parsed.options.geometry || '0'),
232
+ projection: parsed.options.projection || 'perspective'
233
+ };
234
+
235
+ return await mcpServer.handleToolCall('create_4d_visualization', args);
236
+ }
237
+
238
+ /**
239
+ * Handle 'state' command
240
+ */
241
+ async function handleState(parsed) {
242
+ return await mcpServer.handleToolCall('get_state', {});
243
+ }
244
+
245
+ /**
246
+ * Handle 'set' command
247
+ */
248
+ async function handleSet(parsed, startTime) {
249
+ const subcommand = parsed.subcommand;
250
+
251
+ if (subcommand === 'rotation') {
252
+ const args = {};
253
+ if (parsed.options.XY) args.XY = parseFloat(parsed.options.XY);
254
+ if (parsed.options.XZ) args.XZ = parseFloat(parsed.options.XZ);
255
+ if (parsed.options.YZ) args.YZ = parseFloat(parsed.options.YZ);
256
+ if (parsed.options.XW) args.XW = parseFloat(parsed.options.XW);
257
+ if (parsed.options.YW) args.YW = parseFloat(parsed.options.YW);
258
+ if (parsed.options.ZW) args.ZW = parseFloat(parsed.options.ZW);
259
+ return await mcpServer.handleToolCall('set_rotation', args);
260
+ }
261
+
262
+ if (subcommand === 'visual') {
263
+ const args = {};
264
+ if (parsed.options.hue) args.hue = parseInt(parsed.options.hue);
265
+ if (parsed.options.saturation) args.saturation = parseFloat(parsed.options.saturation);
266
+ if (parsed.options.intensity) args.intensity = parseFloat(parsed.options.intensity);
267
+ if (parsed.options.speed) args.speed = parseFloat(parsed.options.speed);
268
+ if (parsed.options.chaos) args.chaos = parseFloat(parsed.options.chaos);
269
+ if (parsed.options.morphFactor) args.morphFactor = parseFloat(parsed.options.morphFactor);
270
+ if (parsed.options.gridDensity) args.gridDensity = parseFloat(parsed.options.gridDensity);
271
+ if (parsed.options.dimension) args.dimension = parseFloat(parsed.options.dimension);
272
+ return await mcpServer.handleToolCall('set_visual_parameters', args);
273
+ }
274
+
275
+ return wrapResponse('set_parameters', {
276
+ error: {
277
+ type: 'ValidationError',
278
+ code: 'INVALID_SUBCOMMAND',
279
+ message: `Unknown set subcommand: ${subcommand}`,
280
+ valid_options: ['rotation', 'visual'],
281
+ suggestion: 'Use "set rotation" or "set visual"'
282
+ }
283
+ }, false, performance.now() - startTime);
284
+ }
285
+
286
+ /**
287
+ * Handle 'geometry' command
288
+ */
289
+ async function handleGeometry(parsed, startTime) {
290
+ const subcommand = parsed.subcommand || 'list';
291
+
292
+ if (subcommand === 'list') {
293
+ const args = {
294
+ core_type: parsed.options['core-type'] || parsed.options.coreType || 'all'
295
+ };
296
+ return await mcpServer.handleToolCall('search_geometries', args);
297
+ }
298
+
299
+ if (subcommand === 'set' || !isNaN(parseInt(subcommand))) {
300
+ const index = parseInt(parsed.subcommand) || parseInt(parsed.options.index || '0');
301
+ return await mcpServer.handleToolCall('change_geometry', { geometry_index: index });
302
+ }
303
+
304
+ return wrapResponse('change_geometry', {
305
+ error: {
306
+ type: 'ValidationError',
307
+ code: 'INVALID_SUBCOMMAND',
308
+ message: `Unknown geometry subcommand: ${subcommand}`,
309
+ valid_options: ['list', 'set', '<index>'],
310
+ suggestion: 'Use "geometry list" or "geometry <index>"'
311
+ }
312
+ }, false, performance.now() - startTime);
313
+ }
314
+
315
+ /**
316
+ * Handle 'system' command
317
+ */
318
+ async function handleSystem(parsed, startTime) {
319
+ const system = parsed.subcommand || parsed.options.system;
320
+
321
+ if (!system) {
322
+ return wrapResponse('switch_system', {
323
+ error: {
324
+ type: 'ValidationError',
325
+ code: 'MISSING_SYSTEM',
326
+ message: 'System name required',
327
+ valid_options: ['quantum', 'faceted', 'holographic'],
328
+ suggestion: 'Use "system quantum", "system faceted", or "system holographic"'
329
+ }
330
+ }, false, performance.now() - startTime);
331
+ }
332
+
333
+ return await mcpServer.handleToolCall('switch_system', { system });
334
+ }
335
+
336
+ /**
337
+ * Handle 'randomize' command
338
+ */
339
+ async function handleRandomize(parsed) {
340
+ const args = {
341
+ preserve_system: parsed.options['preserve-system'] === 'true',
342
+ preserve_geometry: parsed.options['preserve-geometry'] === 'true'
343
+ };
344
+ return await mcpServer.handleToolCall('randomize_parameters', args);
345
+ }
346
+
347
+ /**
348
+ * Handle 'reset' command
349
+ */
350
+ async function handleReset(parsed) {
351
+ return await mcpServer.handleToolCall('reset_parameters', {});
352
+ }
353
+
354
+ /**
355
+ * Handle 'tools' command
356
+ */
357
+ async function handleTools(parsed, startTime) {
358
+ const includeSchemas = parsed.options.schemas === 'true' || parsed.options.full === 'true';
359
+ const tools = mcpServer.listTools(includeSchemas);
360
+
361
+ return wrapResponse('list_tools', {
362
+ count: tools.length,
363
+ tools
364
+ }, true, performance.now() - startTime);
365
+ }
366
+
367
+ /**
368
+ * Handle 'validate' command - validates manifests, packs, and configs
369
+ */
370
+ async function handleValidate(parsed, startTime) {
371
+ const subcommand = parsed.subcommand || 'pack';
372
+ const filePath = parsed.options.file || parsed.options.f || parsed.positional[0];
373
+
374
+ if (!filePath && subcommand !== 'schema') {
375
+ return wrapResponse('validate', {
376
+ error: {
377
+ type: 'ValidationError',
378
+ code: 'MISSING_FILE',
379
+ message: 'File path required for validation',
380
+ suggestion: 'Use --file <path> or provide file as positional argument'
381
+ }
382
+ }, false, performance.now() - startTime);
383
+ }
384
+
385
+ try {
386
+ switch (subcommand) {
387
+ case 'pack': {
388
+ // Validate a .vib3 scene pack file
389
+ const fs = await import('fs/promises');
390
+ const content = await fs.readFile(filePath, 'utf-8');
391
+ const pack = JSON.parse(content);
392
+
393
+ const validation = schemaRegistry.validate('parameters', pack.parameters || pack);
394
+ return wrapResponse('validate_pack', {
395
+ file: filePath,
396
+ valid: validation.valid,
397
+ errors: validation.errors || [],
398
+ schema: 'parameters'
399
+ }, validation.valid, performance.now() - startTime);
400
+ }
401
+
402
+ case 'manifest': {
403
+ // Validate extension/tool manifest
404
+ const fs = await import('fs/promises');
405
+ const content = await fs.readFile(filePath, 'utf-8');
406
+ const manifest = JSON.parse(content);
407
+
408
+ // Basic manifest structure validation
409
+ const required = ['name', 'version', 'type'];
410
+ const missing = required.filter(f => !manifest[f]);
411
+ const valid = missing.length === 0;
412
+
413
+ return wrapResponse('validate_manifest', {
414
+ file: filePath,
415
+ valid,
416
+ errors: missing.length > 0 ? [{ message: `Missing required fields: ${missing.join(', ')}` }] : [],
417
+ manifest_type: manifest.type || 'unknown',
418
+ name: manifest.name,
419
+ version: manifest.version
420
+ }, valid, performance.now() - startTime);
421
+ }
422
+
423
+ case 'response': {
424
+ // Validate a tool response envelope
425
+ const fs = await import('fs/promises');
426
+ const content = await fs.readFile(filePath, 'utf-8');
427
+ const response = JSON.parse(content);
428
+
429
+ const validation = schemaRegistry.validate('toolResponse', response);
430
+ return wrapResponse('validate_response', {
431
+ file: filePath,
432
+ valid: validation.valid,
433
+ errors: validation.errors || [],
434
+ schema: 'toolResponse'
435
+ }, validation.valid, performance.now() - startTime);
436
+ }
437
+
438
+ case 'schema': {
439
+ // List available schemas
440
+ const schemas = ['parameters', 'toolResponse', 'error'];
441
+ return wrapResponse('list_schemas', {
442
+ schemas,
443
+ count: schemas.length
444
+ }, true, performance.now() - startTime);
445
+ }
446
+
447
+ default:
448
+ return wrapResponse('validate', {
449
+ error: {
450
+ type: 'ValidationError',
451
+ code: 'INVALID_SUBCOMMAND',
452
+ message: `Unknown validate subcommand: ${subcommand}`,
453
+ valid_options: ['pack', 'manifest', 'response', 'schema'],
454
+ suggestion: 'Use "validate pack <file>", "validate manifest <file>", or "validate schema"'
455
+ }
456
+ }, false, performance.now() - startTime);
457
+ }
458
+ } catch (error) {
459
+ if (error.code === 'ENOENT') {
460
+ return wrapResponse('validate', {
461
+ error: {
462
+ type: 'NotFoundError',
463
+ code: 'FILE_NOT_FOUND',
464
+ message: `File not found: ${filePath}`,
465
+ suggestion: 'Check the file path and try again'
466
+ }
467
+ }, false, performance.now() - startTime);
468
+ }
469
+
470
+ if (error instanceof SyntaxError) {
471
+ return wrapResponse('validate', {
472
+ error: {
473
+ type: 'ValidationError',
474
+ code: 'INVALID_JSON',
475
+ message: `Invalid JSON in file: ${error.message}`,
476
+ suggestion: 'Ensure the file contains valid JSON'
477
+ }
478
+ }, false, performance.now() - startTime);
479
+ }
480
+
481
+ throw error;
482
+ }
483
+ }
484
+
485
+ /**
486
+ * Main entry point
487
+ */
488
+ async function main() {
489
+ const args = process.argv.slice(2);
490
+ const parsed = parseArgs(args);
491
+
492
+ // Handle global flags
493
+ if (parsed.flags.version) {
494
+ showVersion(parsed.flags.json);
495
+ process.exit(ExitCode.SUCCESS);
496
+ }
497
+
498
+ if (parsed.flags.help || !parsed.command) {
499
+ showHelp(parsed.flags.json);
500
+ process.exit(parsed.command ? ExitCode.SUCCESS : ExitCode.INVALID_ARGS);
501
+ }
502
+
503
+ // Route to command handler
504
+ let result;
505
+
506
+ const startTime = performance.now();
507
+
508
+ try {
509
+ switch (parsed.command) {
510
+ case 'create':
511
+ result = await handleCreate(parsed);
512
+ break;
513
+ case 'state':
514
+ result = await handleState(parsed);
515
+ break;
516
+ case 'set':
517
+ result = await handleSet(parsed, startTime);
518
+ break;
519
+ case 'geometry':
520
+ result = await handleGeometry(parsed, startTime);
521
+ break;
522
+ case 'system':
523
+ result = await handleSystem(parsed, startTime);
524
+ break;
525
+ case 'randomize':
526
+ result = await handleRandomize(parsed);
527
+ break;
528
+ case 'reset':
529
+ result = await handleReset(parsed);
530
+ break;
531
+ case 'tools':
532
+ result = await handleTools(parsed, startTime);
533
+ break;
534
+ case 'validate':
535
+ result = await handleValidate(parsed, startTime);
536
+ break;
537
+ case 'init':
538
+ result = await handleInit(parsed, startTime);
539
+ break;
540
+ default:
541
+ result = wrapResponse('get_state', {
542
+ error: {
543
+ type: 'NotFoundError',
544
+ code: 'UNKNOWN_COMMAND',
545
+ message: `Unknown command: ${parsed.command}`,
546
+ valid_options: ['create', 'state', 'set', 'geometry', 'system', 'randomize', 'reset', 'tools', 'init'],
547
+ suggestion: 'Run "vib3 --help" for available commands'
548
+ }
549
+ }, false, performance.now() - startTime);
550
+ }
551
+ } catch (error) {
552
+ result = wrapResponse(parsed.command || 'get_state', {
553
+ error: {
554
+ type: 'SystemError',
555
+ code: 'EXECUTION_ERROR',
556
+ message: error.message,
557
+ suggestion: 'Check your command syntax and try again'
558
+ }
559
+ }, false, performance.now() - startTime);
560
+ }
561
+
562
+ const finalResult = parsed.flags.verbose ? validateResponseEnvelope(result) : result;
563
+ output(finalResult, parsed.flags.json);
564
+
565
+ // Exit with appropriate code
566
+ if (finalResult.error || finalResult.success === false) {
567
+ const code = {
568
+ 'ValidationError': ExitCode.VALIDATION_ERROR,
569
+ 'NotFoundError': ExitCode.NOT_FOUND,
570
+ 'SystemError': ExitCode.ERROR
571
+ }[finalResult.error?.type] || ExitCode.ERROR;
572
+
573
+ process.exit(code);
574
+ }
575
+
576
+ process.exit(ExitCode.SUCCESS);
577
+ }
578
+
579
+ /**
580
+ * Handle init command — scaffold a new VIB3+ project
581
+ */
582
+ async function handleInit(parsed, startTime) {
583
+ const { writeFileSync, mkdirSync, existsSync } = await import('node:fs');
584
+ const { join } = await import('node:path');
585
+
586
+ const projectName = parsed.positional[0] || 'my-vib3-app';
587
+ const projectDir = join(process.cwd(), projectName);
588
+
589
+ if (existsSync(projectDir)) {
590
+ return wrapResponse('init', {
591
+ error: {
592
+ type: 'ValidationError',
593
+ code: 'DIR_EXISTS',
594
+ message: `Directory "${projectName}" already exists`,
595
+ suggestion: 'Choose a different name or delete the existing directory'
596
+ }
597
+ }, false, performance.now() - startTime);
598
+ }
599
+
600
+ mkdirSync(projectDir, { recursive: true });
601
+
602
+ // package.json
603
+ writeFileSync(join(projectDir, 'package.json'), JSON.stringify({
604
+ name: projectName,
605
+ version: '0.1.0',
606
+ type: 'module',
607
+ scripts: {
608
+ dev: 'npx vite --open',
609
+ build: 'npx vite build'
610
+ },
611
+ dependencies: {
612
+ '@vib3code/sdk': '^2.0.0'
613
+ },
614
+ devDependencies: {
615
+ vite: '^5.3.0'
616
+ }
617
+ }, null, 2) + '\n');
618
+
619
+ // index.html
620
+ writeFileSync(join(projectDir, 'index.html'), `<!DOCTYPE html>
621
+ <html lang="en">
622
+ <head>
623
+ <meta charset="utf-8">
624
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
625
+ <title>${projectName}</title>
626
+ <style>
627
+ body { margin: 0; background: #07070f; overflow: hidden; }
628
+ #controls { position: fixed; top: 12px; left: 12px; z-index: 10; font: 13px monospace; color: #0fc; }
629
+ select, input[type="range"] { margin-left: 6px; }
630
+ </style>
631
+ </head>
632
+ <body>
633
+ <div id="controls">
634
+ <label>System: <select id="sys"><option>quantum</option><option>faceted</option><option>holographic</option></select></label>
635
+ <label>Geometry: <input type="range" id="geo" min="0" max="23" value="0"></label>
636
+ <label>Hue: <input type="range" id="hue" min="0" max="360" value="200"></label>
637
+ </div>
638
+ <script type="module" src="main.js"></script>
639
+ </body>
640
+ </html>
641
+ `);
642
+
643
+ // main.js
644
+ writeFileSync(join(projectDir, 'main.js'), `import { VIB3Engine } from '@vib3code/sdk/core';
645
+
646
+ const engine = new VIB3Engine();
647
+ await engine.initialize();
648
+ await engine.switchSystem('quantum');
649
+
650
+ document.getElementById('sys').addEventListener('change', (e) => engine.switchSystem(e.target.value));
651
+ document.getElementById('geo').addEventListener('input', (e) => engine.setParameter('geometry', +e.target.value));
652
+ document.getElementById('hue').addEventListener('input', (e) => engine.setParameter('hue', +e.target.value));
653
+ `);
654
+
655
+ console.log(`\\n Created ${projectName}/`);
656
+ console.log(' ├── package.json');
657
+ console.log(' ├── index.html');
658
+ console.log(' └── main.js');
659
+ console.log(`\\n Next steps:`);
660
+ console.log(` cd ${projectName}`);
661
+ console.log(' npm install');
662
+ console.log(' npm run dev\\n');
663
+
664
+ return wrapResponse('init', {
665
+ project: projectName,
666
+ files: ['package.json', 'index.html', 'main.js'],
667
+ next_steps: [`cd ${projectName}`, 'npm install', 'npm run dev']
668
+ }, true, performance.now() - startTime);
669
+ }
670
+
671
+ // Run CLI
672
+ main().catch(error => {
673
+ console.error('Fatal error:', error.message);
674
+ process.exit(ExitCode.ERROR);
675
+ });