@holoscript/std 2.1.0 → 6.0.3

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 (159) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +21 -0
  3. package/README.md +197 -0
  4. package/dist/__tests__/EconomicPrimitives.test.d.ts +2 -0
  5. package/dist/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
  6. package/dist/__tests__/EconomicTraits.test.d.ts +2 -0
  7. package/dist/__tests__/EconomicTraits.test.d.ts.map +1 -0
  8. package/dist/__tests__/SimulationLabPrimitives.test.d.ts +2 -0
  9. package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +1 -0
  10. package/dist/__tests__/collections.test.d.ts +2 -0
  11. package/dist/__tests__/collections.test.d.ts.map +1 -0
  12. package/dist/__tests__/events.test.d.ts +2 -0
  13. package/dist/__tests__/events.test.d.ts.map +1 -0
  14. package/dist/__tests__/index.test.d.ts +2 -0
  15. package/dist/__tests__/index.test.d.ts.map +1 -0
  16. package/dist/__tests__/materials.test.d.ts +2 -0
  17. package/dist/__tests__/materials.test.d.ts.map +1 -0
  18. package/dist/__tests__/math.test.d.ts +2 -0
  19. package/dist/__tests__/math.test.d.ts.map +1 -0
  20. package/dist/__tests__/physics.test.d.ts +2 -0
  21. package/dist/__tests__/physics.test.d.ts.map +1 -0
  22. package/dist/__tests__/spatial.test.d.ts +2 -0
  23. package/dist/__tests__/spatial.test.d.ts.map +1 -0
  24. package/dist/__tests__/standard-library-fundamentals.test.d.ts +2 -0
  25. package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +1 -0
  26. package/dist/__tests__/string-and-time-utilities.test.d.ts +2 -0
  27. package/dist/__tests__/string-and-time-utilities.test.d.ts.map +1 -0
  28. package/dist/__tests__/string-decoupled.test.d.ts +2 -0
  29. package/dist/__tests__/string-decoupled.test.d.ts.map +1 -0
  30. package/dist/__tests__/string.test.d.ts +2 -0
  31. package/dist/__tests__/string.test.d.ts.map +1 -0
  32. package/dist/__tests__/time.test.d.ts +2 -0
  33. package/dist/__tests__/time.test.d.ts.map +1 -0
  34. package/dist/chunk-7HVUYGPS.js +679 -0
  35. package/dist/chunk-7HVUYGPS.js.map +1 -0
  36. package/dist/chunk-P4O3WNG2.js +287 -0
  37. package/dist/chunk-P4O3WNG2.js.map +1 -0
  38. package/dist/chunk-PFX2JM4X.js +683 -0
  39. package/dist/chunk-PFX2JM4X.js.map +1 -0
  40. package/dist/chunk-W2Q3LUCM.js +348 -0
  41. package/dist/chunk-W2Q3LUCM.js.map +1 -0
  42. package/dist/chunk-WS6W35YC.js +443 -0
  43. package/dist/chunk-WS6W35YC.js.map +1 -0
  44. package/dist/chunk-ZXVZAQCZ.js +470 -0
  45. package/dist/chunk-ZXVZAQCZ.js.map +1 -0
  46. package/dist/collections.cjs +715 -0
  47. package/dist/collections.cjs.map +1 -0
  48. package/dist/collections.d.ts.map +1 -1
  49. package/dist/collections.js +16 -719
  50. package/dist/collections.js.map +1 -1
  51. package/dist/events.d.ts +32 -0
  52. package/dist/events.d.ts.map +1 -0
  53. package/dist/index.cjs +4101 -0
  54. package/dist/index.cjs.map +1 -0
  55. package/dist/index.d.ts +21 -9
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +1270 -157
  58. package/dist/index.js.map +1 -1
  59. package/dist/materials.d.ts +50 -0
  60. package/dist/materials.d.ts.map +1 -0
  61. package/dist/math.cjs +591 -0
  62. package/dist/math.cjs.map +1 -0
  63. package/dist/math.d.ts.map +1 -1
  64. package/dist/math.js +51 -537
  65. package/dist/math.js.map +1 -1
  66. package/dist/physics.d.ts +59 -0
  67. package/dist/physics.d.ts.map +1 -0
  68. package/dist/spatial.d.ts +82 -0
  69. package/dist/spatial.d.ts.map +1 -0
  70. package/dist/string.basic.test.d.ts +5 -0
  71. package/dist/string.basic.test.d.ts.map +1 -0
  72. package/dist/string.cjs +422 -0
  73. package/dist/string.cjs.map +1 -0
  74. package/dist/string.d.ts +5 -1
  75. package/dist/string.d.ts.map +1 -1
  76. package/dist/string.js +106 -442
  77. package/dist/string.js.map +1 -1
  78. package/dist/string.test.d.ts +5 -0
  79. package/dist/string.test.d.ts.map +1 -0
  80. package/dist/time.cjs +512 -0
  81. package/dist/time.cjs.map +1 -0
  82. package/dist/time.d.ts.map +1 -1
  83. package/dist/time.js +41 -528
  84. package/dist/time.js.map +1 -1
  85. package/dist/traits/ARTraits.d.ts +14 -0
  86. package/dist/traits/ARTraits.d.ts.map +1 -0
  87. package/dist/traits/EconomicPrimitives.cjs +335 -0
  88. package/dist/traits/EconomicPrimitives.cjs.map +1 -0
  89. package/dist/traits/EconomicPrimitives.d.ts +345 -0
  90. package/dist/traits/EconomicPrimitives.d.ts.map +1 -0
  91. package/dist/traits/EconomicPrimitives.js +55 -0
  92. package/dist/traits/EconomicPrimitives.js.map +1 -0
  93. package/dist/traits/EconomicTraits.cjs +471 -0
  94. package/dist/traits/EconomicTraits.cjs.map +1 -0
  95. package/dist/traits/EconomicTraits.d.ts +71 -0
  96. package/dist/traits/EconomicTraits.d.ts.map +1 -0
  97. package/dist/traits/EconomicTraits.js +17 -0
  98. package/dist/traits/EconomicTraits.js.map +1 -0
  99. package/dist/traits/IoTTraits.d.ts +14 -0
  100. package/dist/traits/IoTTraits.d.ts.map +1 -0
  101. package/dist/traits/SimulationLabPrimitives.d.ts +187 -0
  102. package/dist/traits/SimulationLabPrimitives.d.ts.map +1 -0
  103. package/dist/traits/SimulationLabTraits.d.ts +42 -0
  104. package/dist/traits/SimulationLabTraits.d.ts.map +1 -0
  105. package/dist/traits/VRRTraits.d.ts +150 -0
  106. package/dist/traits/VRRTraits.d.ts.map +1 -0
  107. package/dist/traits/__tests__/ARTraits.test.d.ts +2 -0
  108. package/dist/traits/__tests__/ARTraits.test.d.ts.map +1 -0
  109. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +2 -0
  110. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
  111. package/dist/traits/__tests__/EconomicTraits.test.d.ts +2 -0
  112. package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +1 -0
  113. package/dist/types.d.ts +9 -0
  114. package/dist/types.d.ts.map +1 -1
  115. package/error-utf8.log +6 -0
  116. package/error.log +0 -0
  117. package/package.json +42 -19
  118. package/src/__tests__/EconomicPrimitives.test.ts +690 -0
  119. package/src/__tests__/EconomicTraits.test.ts +425 -0
  120. package/src/__tests__/SimulationLabPrimitives.test.ts +415 -0
  121. package/src/__tests__/collections.test.ts +182 -0
  122. package/src/__tests__/events.test.ts +135 -0
  123. package/src/__tests__/index.test.ts +14 -0
  124. package/src/__tests__/materials.test.ts +84 -0
  125. package/src/__tests__/math.test.ts +246 -0
  126. package/src/__tests__/physics.test.ts +83 -0
  127. package/src/__tests__/spatial.test.ts +333 -0
  128. package/src/__tests__/standard-library-fundamentals.test.ts +1301 -0
  129. package/src/__tests__/string-and-time-utilities.test.ts +1070 -0
  130. package/src/__tests__/string-decoupled.test.ts +14 -0
  131. package/src/__tests__/string.test.ts +164 -0
  132. package/src/__tests__/time.test.ts +110 -0
  133. package/src/collections.ts +8 -2
  134. package/src/events.ts +88 -0
  135. package/src/index.ts +161 -11
  136. package/src/materials.ts +109 -0
  137. package/src/math.ts +30 -14
  138. package/src/physics.ts +141 -0
  139. package/src/spatial.ts +320 -0
  140. package/src/string.basic.test.ts +14 -0
  141. package/src/string.test.ts +335 -0
  142. package/src/string.ts +45 -13
  143. package/src/time.ts +10 -11
  144. package/src/traits/ARTraits.ts +103 -0
  145. package/src/traits/EconomicPrimitives.ts +755 -0
  146. package/src/traits/EconomicTraits.ts +552 -0
  147. package/src/traits/IoTTraits.ts +102 -0
  148. package/src/traits/SimulationLabPrimitives.ts +650 -0
  149. package/src/traits/SimulationLabTraits.ts +191 -0
  150. package/src/traits/VRRTraits.ts +326 -0
  151. package/src/traits/__tests__/ARTraits.test.ts +14 -0
  152. package/src/traits/__tests__/EconomicPrimitives.test.ts +14 -0
  153. package/src/traits/__tests__/EconomicTraits.test.ts +14 -0
  154. package/src/types.ts +47 -12
  155. package/std_error.log +5 -0
  156. package/tsup.config.ts +17 -0
  157. package/vitest.config.ts +10 -0
  158. package/dist/types.js +0 -198
  159. package/dist/types.js.map +0 -1
@@ -0,0 +1,191 @@
1
+ /**
2
+ * @fileoverview SimulationLab Trait Definition for HoloScript
3
+ * @module @holoscript/std/traits
4
+ *
5
+ * Defines the @simulation_lab trait that enables hypothesis testing
6
+ * on any HoloScript composition. Attach this trait to run parameter sweeps,
7
+ * collect metrics across N epochs, and produce statistical results.
8
+ *
9
+ * Composes with all economic traits for economy stress testing.
10
+ *
11
+ * @version 1.0.0
12
+ * @category simulation
13
+ */
14
+
15
+ import type { TraitDefinition } from '../types.js';
16
+
17
+ /**
18
+ * Extended trait definition with simulation-specific metadata.
19
+ */
20
+ export interface SimulationTraitDefinition extends TraitDefinition {
21
+ /** Compiler hints for batch execution */
22
+ compiler_hints?: {
23
+ requires_runtime?: string[];
24
+ thread_safety?: 'main_thread' | 'worker_thread' | 'any';
25
+ performance_budget_ms?: number;
26
+ batch_mode?: boolean;
27
+ };
28
+ /** Which economic/VR traits this composes with */
29
+ composesWith: string[];
30
+ }
31
+
32
+ // =============================================================================
33
+ // TRAIT DEFINITION
34
+ // =============================================================================
35
+
36
+ /**
37
+ * The SimulationLab trait.
38
+ */
39
+ export const SimulationLabTraits: Record<string, SimulationTraitDefinition> = {
40
+ simulation_lab: {
41
+ name: '@simulation_lab',
42
+ description:
43
+ 'Attaches scientific hypothesis testing to any HoloScript composition. ' +
44
+ 'Enables parameter sweeps, multi-epoch execution, statistical analysis, ' +
45
+ 'and exportable results. The universe gets one sample — HoloScript gives ' +
46
+ 'you infinite. Results are marketplace-sellable as verified simulation data.',
47
+ params: {
48
+ hypothesis: {
49
+ type: 'string',
50
+ required: true,
51
+ description: 'Human-readable hypothesis description.',
52
+ },
53
+ null_hypothesis: {
54
+ type: 'string',
55
+ required: false,
56
+ default: '',
57
+ description: 'Formal null hypothesis (H0). Auto-generated if empty.',
58
+ },
59
+ alternative_hypothesis: {
60
+ type: 'string',
61
+ required: false,
62
+ default: '',
63
+ description: 'Formal alternative hypothesis (H1). Auto-generated if empty.',
64
+ },
65
+ direction: {
66
+ type: 'string',
67
+ required: false,
68
+ default: 'different',
69
+ description: 'Expected direction of effect: greater | less | different | equal.',
70
+ },
71
+ epochs: {
72
+ type: 'number',
73
+ required: false,
74
+ default: 1000,
75
+ description: 'Number of simulation runs per parameter combination. More = higher power.',
76
+ },
77
+ seed_start: {
78
+ type: 'number',
79
+ required: false,
80
+ default: 0,
81
+ description: 'Starting seed for reproducibility. Seeds increment per epoch.',
82
+ },
83
+ confidence_level: {
84
+ type: 'number',
85
+ required: false,
86
+ default: 0.95,
87
+ description: 'Confidence level for statistical tests (0.0 - 1.0). Default 0.95 = α=0.05.',
88
+ },
89
+ metrics: {
90
+ type: 'string[]',
91
+ required: true,
92
+ description:
93
+ 'List of metric names to collect each epoch. Must match emitted metric events.',
94
+ },
95
+ statistical_test: {
96
+ type: 'string',
97
+ required: false,
98
+ default: 'auto',
99
+ description:
100
+ 'Statistical test to use: t_test | mann_whitney_u | chi_squared | auto. ' +
101
+ 'Auto selects based on data distribution.',
102
+ },
103
+ export_training_data: {
104
+ type: 'boolean',
105
+ required: false,
106
+ default: false,
107
+ description: 'Whether to export results as training data for DataForge pipeline.',
108
+ },
109
+ marketplace_publishable: {
110
+ type: 'boolean',
111
+ required: false,
112
+ default: false,
113
+ description:
114
+ 'Whether to package results for marketplace listing as verified simulation data.',
115
+ },
116
+ max_duration_ms: {
117
+ type: 'number',
118
+ required: false,
119
+ default: 300000,
120
+ description:
121
+ 'Maximum wall-clock time for the entire experiment (5 min default). ' +
122
+ 'Prevents runaway simulations.',
123
+ },
124
+ worker_count: {
125
+ type: 'number',
126
+ required: false,
127
+ default: 4,
128
+ description: 'Number of parallel workers for epoch execution.',
129
+ },
130
+ },
131
+ validator: (params) => {
132
+ if (!params.hypothesis || typeof params.hypothesis !== 'string') return false;
133
+ if (!params.metrics || !Array.isArray(params.metrics) || params.metrics.length === 0)
134
+ return false;
135
+ if (params.epochs !== undefined && (params.epochs < 1 || params.epochs > 1000000))
136
+ return false;
137
+ if (
138
+ params.confidence_level !== undefined &&
139
+ (params.confidence_level <= 0 || params.confidence_level >= 1)
140
+ )
141
+ return false;
142
+ if (params.direction !== undefined) {
143
+ if (!['greater', 'less', 'different', 'equal'].includes(params.direction)) return false;
144
+ }
145
+ if (params.statistical_test !== undefined) {
146
+ if (!['t_test', 'mann_whitney_u', 'chi_squared', 'auto'].includes(params.statistical_test))
147
+ return false;
148
+ }
149
+ return true;
150
+ },
151
+ composesWith: [
152
+ '@tradeable',
153
+ '@depreciating',
154
+ '@bonding_curved',
155
+ '@taxable_wealth',
156
+ '@pid_controlled',
157
+ ],
158
+ compiler_hints: {
159
+ requires_runtime: [
160
+ 'SimulationRuntime.runExperiment',
161
+ 'SimulationRuntime.collectMetrics',
162
+ 'SimulationRuntime.runStatisticalTest',
163
+ 'SimulationRuntime.exportResults',
164
+ ],
165
+ thread_safety: 'worker_thread',
166
+ performance_budget_ms: 300000, // Experiment budget, not per-frame
167
+ batch_mode: true,
168
+ },
169
+ },
170
+ };
171
+
172
+ // =============================================================================
173
+ // TRAIT UTILITIES
174
+ // =============================================================================
175
+
176
+ /**
177
+ * Get all simulation trait names.
178
+ */
179
+ export function getSimulationTraitNames(): string[] {
180
+ return Object.keys(SimulationLabTraits).map((k) => SimulationLabTraits[k].name);
181
+ }
182
+
183
+ /**
184
+ * Look up a simulation trait definition by name.
185
+ */
186
+ export function getSimulationTrait(name: string): SimulationTraitDefinition | undefined {
187
+ const key = name.startsWith('@') ? name.slice(1) : name;
188
+ return SimulationLabTraits[key];
189
+ }
190
+
191
+ export default SimulationLabTraits;
@@ -0,0 +1,326 @@
1
+ /**
2
+ * @fileoverview VRR (Virtual Reality Reality) Trait Definitions
3
+ * @module @holoscript/std/traits
4
+ *
5
+ * TODO: HIGH - Define VRR Trait Library for 1:1 Digital Twins
6
+ *
7
+ * PURPOSE:
8
+ * Define standard HoloScript traits for VRR (Virtual Reality Reality) features:
9
+ * 1:1 real-world mirroring, geo-anchoring, real-time sync (weather, events,
10
+ * inventory), business quests, layer transitions, and x402 payments.
11
+ *
12
+ * VISION:
13
+ * Developers annotate HoloScript compositions with @vrr_twin, @weather_sync,
14
+ * @inventory_sync, and VRRCompiler auto-generates Three.js code with real-time
15
+ * API integration. Example: @weather_sync → auto-generates weather.gov API calls
16
+ * and scene fog/precipitation updates.
17
+ *
18
+ * REQUIREMENTS:
19
+ * 1. Core VRR Traits: @vrr_twin, @reality_mirror, @geo_anchor
20
+ * 2. Real-Time Sync Traits: @weather_sync, @event_sync, @inventory_sync, @traffic_sync
21
+ * 3. Business Traits: @quest_hub, @business_marker, @coupon_reward
22
+ * 4. Layer Transition Traits: @layer_shift, @ar_portal, @vr_portal
23
+ * 5. Payment Traits: @x402_paywall, @subscription, @revenue_share
24
+ * 6. Geo-Location Traits: @geo_coords, @geo_sync, @geo_fence
25
+ *
26
+ * EXAMPLE USAGE:
27
+ * ```holoscript
28
+ * composition "PhoenixDowntownVRR" {
29
+ * zone#phoenix_downtown @vrr_twin @reality_mirror @geo_sync("phoenix_az_center") {
30
+ * geo_coords: { lat: 33.4484, lng: -112.0740 }
31
+ * weather_sync: @weather_sync { provider: "weather.gov", refresh: 5_minutes }
32
+ * event_sync: @event_sync { provider: "eventbrite", refresh: 5_minutes }
33
+ *
34
+ * business#phoenix_brew @quest_hub @inventory_sync @x402_paywall {
35
+ * geo_coords: { lat: 33.4484, lng: -112.0740 }
36
+ * inventory_api: @inventory_sync { provider: "square_pos", refresh: 1_minute }
37
+ * paywall: @x402_paywall { price: 5_usdc, asset: "USDC", network: "base" }
38
+ *
39
+ * quest "LatteLegend" @quest_hub {
40
+ * steps: [
41
+ * @ar_scan { location: "storefront_window" },
42
+ * @vrr_find_item { item: "oat_milk", hint: "Check the fridge" },
43
+ * @vr_taste_menu { menu_item: "oat_milk_latte" }
44
+ * ]
45
+ * reward: @coupon_reward { value: "Buy1Get1Free", expiry: 30_days }
46
+ * }
47
+ * }
48
+ * }
49
+ * }
50
+ * ```
51
+ *
52
+ * TRAIT DEFINITIONS:
53
+ *
54
+ * 1. @vrr_twin - Marks composition as VRR digital twin (1:1 real-world mirror)
55
+ * - Example: @vrr_twin { mirror: "phoenix_downtown" }
56
+ * - Compiler: Generates geo-anchored Three.js scene
57
+ *
58
+ * 2. @reality_mirror - Enables real-world synchronization
59
+ * - Example: @reality_mirror { sync: ["weather", "events", "inventory"] }
60
+ * - Compiler: Generates API integration code
61
+ *
62
+ * 3. @geo_anchor - Geo-location anchoring (lat/lng)
63
+ * - Example: @geo_anchor { lat: 33.4484, lng: -112.0740 }
64
+ * - Compiler: Converts lat/lng to scene coordinates
65
+ *
66
+ * 4. @weather_sync - Real-time weather synchronization
67
+ * - Example: @weather_sync { provider: "weather.gov", refresh: 5_minutes }
68
+ * - Compiler: Generates weather API polling code
69
+ * - Runtime: Updates scene fog, precipitation, temperature
70
+ *
71
+ * 5. @event_sync - Real-time event synchronization
72
+ * - Example: @event_sync { provider: "eventbrite", refresh: 5_minutes }
73
+ * - Compiler: Generates event API polling code
74
+ * - Runtime: Spawns NPC crowds, triggers quests on festivals
75
+ *
76
+ * 6. @inventory_sync - Real-time inventory synchronization
77
+ * - Example: @inventory_sync { provider: "square_pos", refresh: 1_minute }
78
+ * - Compiler: Generates POS API integration code
79
+ * - Runtime: Enables/disables quests based on stock
80
+ *
81
+ * 7. @quest_hub - Marks business as quest starting point
82
+ * - Example: @quest_hub { quests: ["latte_legend", "espresso_challenge"] }
83
+ * - Compiler: Generates quest NPC, interaction prompts
84
+ *
85
+ * 8. @layer_shift - AR/VRR/VR layer transitions
86
+ * - Example: @layer_shift { from: "ar", to: "vrr", price: 5_usdc }
87
+ * - Compiler: Generates x402 payment + redirect logic
88
+ * - Runtime: Persists state across layers (IndexedDB → Supabase)
89
+ *
90
+ * 9. @x402_paywall - HTTP 402 payment requirement
91
+ * - Example: @x402_paywall { price: 5, asset: "USDC", network: "base" }
92
+ * - Compiler: Generates 402 response + payment verification
93
+ * - Runtime: Grants access after payment confirmed
94
+ *
95
+ * 10. @geo_sync - Geographic data synchronization
96
+ * - Example: @geo_sync { center: "phoenix_az_center", radius: 5000 } // 5km
97
+ * - Compiler: Fetches nearby POIs, traffic, events
98
+ *
99
+ * INTEGRATION POINTS:
100
+ * - VRRCompiler.ts (trait parsing, code generation)
101
+ * - VRRRuntime.ts (real-time sync implementation)
102
+ * - x402PaymentService.ts (payment verification)
103
+ * - BusinessQuestTools.ts (quest builder uses traits)
104
+ *
105
+ * RESEARCH REFERENCES:
106
+ * - HOLOLAND_INTEGRATION_TODOS.md (VRRTraits section)
107
+ * - VRRCompiler.ts (trait requirements)
108
+ * - uAA2++_Protocol/5.GROW P.029: "Machine Customers for VR Platforms"
109
+ *
110
+ * IMPLEMENTATION TASKS:
111
+ * [x] Define VRRTrait interface
112
+ * [ ] Implement @vrr_twin trait definition
113
+ * [ ] Implement @reality_mirror trait definition
114
+ * [ ] Implement @geo_anchor trait definition
115
+ * [ ] Implement @weather_sync trait definition
116
+ * [ ] Implement @event_sync trait definition
117
+ * [ ] Implement @inventory_sync trait definition
118
+ * [ ] Implement @quest_hub trait definition
119
+ * [ ] Implement @layer_shift trait definition
120
+ * [ ] Implement @x402_paywall trait definition
121
+ * [ ] Implement @geo_sync trait definition
122
+ * [ ] Add trait validation (ensure required params present)
123
+ * [ ] Add trait composition (combine multiple traits)
124
+ * [ ] Add tests (VRRTraits.test.ts)
125
+ * [ ] Add documentation (trait usage examples)
126
+ *
127
+ * ESTIMATED COMPLEXITY: 6/10 (medium - trait definitions, validation)
128
+ * ESTIMATED TIME: 1 week (includes testing, documentation)
129
+ * PRIORITY: HIGH (blocks VRRCompiler implementation)
130
+ *
131
+ * BLOCKED BY:
132
+ * - Nothing (can implement now)
133
+ *
134
+ * UNBLOCKS:
135
+ * - VRRCompiler.ts (trait parsing)
136
+ * - VRRRuntime.ts (trait-driven initialization)
137
+ * - BusinessQuestTools.ts (trait-based quest builder)
138
+ */
139
+
140
+ import type { TraitDefinition } from '../types.js';
141
+
142
+ export interface VRRTrait extends TraitDefinition {
143
+ name: string;
144
+ params: Record<string, any>;
145
+ validator?: (params: Record<string, any>) => boolean;
146
+ compiler_hints?: {
147
+ requires_runtime?: string[];
148
+ generates_api_calls?: string[];
149
+ };
150
+ }
151
+
152
+ export const VRRTraits: Record<string, VRRTrait> = {
153
+ vrr_twin: {
154
+ name: '@vrr_twin',
155
+ description: 'Marks composition as VRR digital twin (1:1 real-world mirror)',
156
+ params: {
157
+ mirror: { type: 'string', required: true, description: 'Real-world location to mirror' },
158
+ },
159
+ validator: (params) => !!params.mirror,
160
+ compiler_hints: {
161
+ generates_api_calls: ['geo_location'],
162
+ },
163
+ },
164
+
165
+ reality_mirror: {
166
+ name: '@reality_mirror',
167
+ description: 'Enables real-world synchronization (weather, events, inventory)',
168
+ params: {
169
+ sync: { type: 'array', required: true, description: 'List of sync types' },
170
+ },
171
+ validator: (params) => Array.isArray(params.sync) && params.sync.length > 0,
172
+ },
173
+
174
+ geo_anchor: {
175
+ name: '@geo_anchor',
176
+ description: 'Geo-location anchoring (lat/lng positioning)',
177
+ params: {
178
+ lat: { type: 'number', required: true, description: 'Latitude' },
179
+ lng: { type: 'number', required: true, description: 'Longitude' },
180
+ },
181
+ validator: (params) => {
182
+ return (
183
+ typeof params.lat === 'number' &&
184
+ typeof params.lng === 'number' &&
185
+ params.lat >= -90 &&
186
+ params.lat <= 90 &&
187
+ params.lng >= -180 &&
188
+ params.lng <= 180
189
+ );
190
+ },
191
+ },
192
+
193
+ weather_sync: {
194
+ name: '@weather_sync',
195
+ description: 'Real-time weather synchronization',
196
+ params: {
197
+ provider: { type: 'string', required: true, description: 'weather.gov | openweathermap' },
198
+ refresh: {
199
+ type: 'duration',
200
+ required: false,
201
+ default: '5_minutes',
202
+ description: 'Refresh interval',
203
+ },
204
+ },
205
+ validator: (params) => ['weather.gov', 'openweathermap'].includes(params.provider),
206
+ compiler_hints: {
207
+ requires_runtime: ['VRRRuntime.syncWeather'],
208
+ generates_api_calls: ['weather.gov', 'openweathermap'],
209
+ },
210
+ },
211
+
212
+ event_sync: {
213
+ name: '@event_sync',
214
+ description: 'Real-time event synchronization (festivals, concerts)',
215
+ params: {
216
+ provider: { type: 'string', required: true, description: 'eventbrite | ticketmaster' },
217
+ refresh: {
218
+ type: 'duration',
219
+ required: false,
220
+ default: '5_minutes',
221
+ description: 'Refresh interval',
222
+ },
223
+ },
224
+ validator: (params) => ['eventbrite', 'ticketmaster'].includes(params.provider),
225
+ compiler_hints: {
226
+ requires_runtime: ['VRRRuntime.syncEvents'],
227
+ generates_api_calls: ['eventbrite', 'ticketmaster'],
228
+ },
229
+ },
230
+
231
+ inventory_sync: {
232
+ name: '@inventory_sync',
233
+ description: 'Real-time inventory synchronization (Square POS, Shopify)',
234
+ params: {
235
+ provider: {
236
+ type: 'string',
237
+ required: true,
238
+ description: 'square_pos | shopify | woocommerce',
239
+ },
240
+ refresh: {
241
+ type: 'duration',
242
+ required: false,
243
+ default: '1_minute',
244
+ description: 'Refresh interval',
245
+ },
246
+ websocket: {
247
+ type: 'boolean',
248
+ required: false,
249
+ default: false,
250
+ description: 'Use WebSocket for real-time',
251
+ },
252
+ },
253
+ validator: (params) => ['square_pos', 'shopify', 'woocommerce'].includes(params.provider),
254
+ compiler_hints: {
255
+ requires_runtime: ['VRRRuntime.syncInventory'],
256
+ generates_api_calls: ['square_pos', 'shopify', 'woocommerce'],
257
+ },
258
+ },
259
+
260
+ quest_hub: {
261
+ name: '@quest_hub',
262
+ description: 'Marks business as quest starting point',
263
+ params: {
264
+ quests: { type: 'array', required: true, description: 'List of quest IDs' },
265
+ },
266
+ validator: (params) => Array.isArray(params.quests) && params.quests.length > 0,
267
+ },
268
+
269
+ layer_shift: {
270
+ name: '@layer_shift',
271
+ description: 'AR/VRR/VR layer transitions with state persistence',
272
+ params: {
273
+ from: { type: 'string', required: true, description: 'ar | vrr | vr' },
274
+ to: { type: 'string', required: true, description: 'ar | vrr | vr' },
275
+ price: { type: 'number', required: false, description: 'USDC price for transition' },
276
+ persist_state: {
277
+ type: 'boolean',
278
+ required: false,
279
+ default: true,
280
+ description: 'Persist state across layers',
281
+ },
282
+ },
283
+ validator: (params) => {
284
+ const validLayers = ['ar', 'vrr', 'vr'];
285
+ return validLayers.includes(params.from) && validLayers.includes(params.to);
286
+ },
287
+ compiler_hints: {
288
+ requires_runtime: ['VRRRuntime.persistState', 'ARRuntime.createARPortal'],
289
+ },
290
+ },
291
+
292
+ x402_paywall: {
293
+ name: '@x402_paywall',
294
+ description: 'HTTP 402 payment requirement for content access',
295
+ params: {
296
+ price: { type: 'number', required: true, description: 'Price in USDC' },
297
+ asset: { type: 'string', required: false, default: 'USDC', description: 'USDC | ETH | SOL' },
298
+ network: {
299
+ type: 'string',
300
+ required: false,
301
+ default: 'base',
302
+ description: 'base | ethereum | solana',
303
+ },
304
+ },
305
+ validator: (params) => {
306
+ return (
307
+ params.price > 0 &&
308
+ ['USDC', 'ETH', 'SOL'].includes(params.asset || 'USDC') &&
309
+ ['base', 'ethereum', 'solana'].includes(params.network || 'base')
310
+ );
311
+ },
312
+ compiler_hints: {
313
+ generates_api_calls: ['x402_payment_service'],
314
+ },
315
+ },
316
+
317
+ geo_sync: {
318
+ name: '@geo_sync',
319
+ description: 'Geographic data synchronization (POIs, traffic, events)',
320
+ params: {
321
+ center: { type: 'string', required: true, description: 'Center point identifier' },
322
+ radius: { type: 'number', required: false, default: 5000, description: 'Radius in meters' },
323
+ },
324
+ validator: (params) => !!params.center && (params.radius || 0) >= 0,
325
+ },
326
+ };
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from 'vitest';
2
+
3
+ // Auto-generated test for ARTraits
4
+ // Source: packages/std/src/traits/ARTraits.ts
5
+
6
+ describe('ARTraits', () => {
7
+ it('should be defined', () => {
8
+ // TODO: Import and test ARTraits
9
+ });
10
+
11
+ it('should have basic functionality', () => {
12
+ // TODO: Add meaningful tests for ARTraits
13
+ });
14
+ });
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from 'vitest';
2
+
3
+ // Auto-generated test for EconomicPrimitives
4
+ // Source: packages/std/src/traits/EconomicPrimitives.ts
5
+
6
+ describe('EconomicPrimitives', () => {
7
+ it('should be defined', () => {
8
+ // TODO: Import and test EconomicPrimitives
9
+ });
10
+
11
+ it('should have basic functionality', () => {
12
+ // TODO: Add meaningful tests for EconomicPrimitives
13
+ });
14
+ });
@@ -0,0 +1,14 @@
1
+ import { describe, it, expect } from 'vitest';
2
+
3
+ // Auto-generated test for EconomicTraits
4
+ // Source: packages/std/src/traits/EconomicTraits.ts
5
+
6
+ describe('EconomicTraits', () => {
7
+ it('should be defined', () => {
8
+ // TODO: Import and test EconomicTraits
9
+ });
10
+
11
+ it('should have basic functionality', () => {
12
+ // TODO: Add meaningful tests for EconomicTraits
13
+ });
14
+ });
package/src/types.ts CHANGED
@@ -346,20 +346,35 @@ export function parseColor(color: Color): ColorRGBA {
346
346
  const c = (1 - Math.abs(2 * l - 1)) * s;
347
347
  const x = c * (1 - Math.abs(((h / 60) % 2) - 1));
348
348
  const m = l - c / 2;
349
- let r = 0, g = 0, b = 0;
350
-
351
- if (h < 60) { r = c; g = x; }
352
- else if (h < 120) { r = x; g = c; }
353
- else if (h < 180) { g = c; b = x; }
354
- else if (h < 240) { g = x; b = c; }
355
- else if (h < 300) { r = x; b = c; }
356
- else { r = c; b = x; }
349
+ let r = 0,
350
+ g = 0,
351
+ b = 0;
352
+
353
+ if (h < 60) {
354
+ r = c;
355
+ g = x;
356
+ } else if (h < 120) {
357
+ r = x;
358
+ g = c;
359
+ } else if (h < 180) {
360
+ g = c;
361
+ b = x;
362
+ } else if (h < 240) {
363
+ g = x;
364
+ b = c;
365
+ } else if (h < 300) {
366
+ r = x;
367
+ b = c;
368
+ } else {
369
+ r = c;
370
+ b = x;
371
+ }
357
372
 
358
373
  return { r: r + m, g: g + m, b: b + m, a: 1 };
359
374
  }
360
375
 
361
376
  if ('a' in color) {
362
- return color as ColorRGBA;
377
+ return color;
363
378
  }
364
379
 
365
380
  return { ...color, a: 1 };
@@ -369,8 +384,28 @@ export function parseColor(color: Color): ColorRGBA {
369
384
  * Color to hex string
370
385
  */
371
386
  export function colorToHex(color: ColorRGB | ColorRGBA): string {
372
- const r = Math.round(color.r * 255).toString(16).padStart(2, '0');
373
- const g = Math.round(color.g * 255).toString(16).padStart(2, '0');
374
- const b = Math.round(color.b * 255).toString(16).padStart(2, '0');
387
+ const r = Math.round(color.r * 255)
388
+ .toString(16)
389
+ .padStart(2, '0');
390
+ const g = Math.round(color.g * 255)
391
+ .toString(16)
392
+ .padStart(2, '0');
393
+ const b = Math.round(color.b * 255)
394
+ .toString(16)
395
+ .padStart(2, '0');
375
396
  return `#${r}${g}${b}`;
376
397
  }
398
+
399
+ // =============================================================================
400
+ // TRAIT DEFINITIONS
401
+ // =============================================================================
402
+
403
+ export interface TraitDefinition {
404
+ name: string;
405
+ description?: string;
406
+ type?: string;
407
+ params?: Record<string, any>;
408
+ parameters?: Record<string, any>;
409
+ validator?: (params: Record<string, any>) => boolean;
410
+ validation?: any;
411
+ }
package/std_error.log ADDED
@@ -0,0 +1,5 @@
1
+ npm warn Unknown project config "shamefully-hoist". This will stop working in the next major version of npm.
2
+ npm warn Unknown project config "strict-peer-dependencies". This will stop working in the next major version of npm.
3
+ src/__tests__/SimulationLabPrimitives.test.ts(345,12): error TS18048: 'trait.params' is possibly 'undefined'.
4
+ src/__tests__/SimulationLabPrimitives.test.ts(346,12): error TS18048: 'trait.params' is possibly 'undefined'.
5
+ src/physics.ts(11,22): error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './spatial.js'?
package/tsup.config.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { defineConfig } from 'tsup';
2
+
3
+ export default defineConfig({
4
+ entry: [
5
+ 'src/index.ts',
6
+ 'src/math.ts',
7
+ 'src/collections.ts',
8
+ 'src/string.ts',
9
+ 'src/time.ts',
10
+ 'src/traits/EconomicPrimitives.ts',
11
+ 'src/traits/EconomicTraits.ts',
12
+ ],
13
+ format: ['esm', 'cjs'],
14
+ dts: false,
15
+ clean: true,
16
+ sourcemap: true,
17
+ });
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'vitest/config';
2
+
3
+ export default defineConfig({
4
+ test: {
5
+ globals: true,
6
+ environment: 'node',
7
+ include: ['src/**/*.test.ts'],
8
+ exclude: ['**/dist/**', '**/node_modules/**'],
9
+ },
10
+ });