@holoscript/std 6.0.3 → 7.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 (128) hide show
  1. package/README.md +8 -0
  2. package/dist/chunk-DGUM43GV.js +11 -0
  3. package/dist/chunk-DGUM43GV.js.map +1 -0
  4. package/dist/{chunk-PFX2JM4X.js → chunk-FAMOLKH3.js} +2 -1
  5. package/dist/{chunk-PFX2JM4X.js.map → chunk-FAMOLKH3.js.map} +1 -1
  6. package/dist/{chunk-7HVUYGPS.js → chunk-SOKH6FJ7.js} +37 -5
  7. package/dist/chunk-SOKH6FJ7.js.map +1 -0
  8. package/dist/{chunk-W2Q3LUCM.js → chunk-XJIFG7G3.js} +3 -3
  9. package/dist/chunk-XJIFG7G3.js.map +1 -0
  10. package/dist/collections.cjs +1 -0
  11. package/dist/collections.cjs.map +1 -1
  12. package/dist/collections.js +2 -1
  13. package/dist/fs/fs.d.ts +288 -0
  14. package/dist/fs/fs.d.ts.map +1 -0
  15. package/dist/fs/index.cjs +1049 -0
  16. package/dist/fs/index.cjs.map +1 -0
  17. package/dist/fs/index.d.ts +51 -0
  18. package/dist/fs/index.d.ts.map +1 -0
  19. package/dist/fs/index.js +918 -0
  20. package/dist/fs/index.js.map +1 -0
  21. package/dist/fs/path.d.ts +135 -0
  22. package/dist/fs/path.d.ts.map +1 -0
  23. package/dist/fs/sandbox.d.ts +49 -0
  24. package/dist/fs/sandbox.d.ts.map +1 -0
  25. package/dist/fs/watch.d.ts +133 -0
  26. package/dist/fs/watch.d.ts.map +1 -0
  27. package/dist/index.cjs +54 -7
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +19 -4
  30. package/dist/index.js.map +1 -1
  31. package/dist/math.cjs +21 -2
  32. package/dist/math.cjs.map +1 -1
  33. package/dist/math.js +2 -1
  34. package/dist/string.cjs +2 -2
  35. package/dist/string.cjs.map +1 -1
  36. package/dist/string.js +2 -1
  37. package/dist/time.js +1 -0
  38. package/dist/traits/EconomicPrimitives.js +1 -0
  39. package/dist/traits/EconomicTraits.js +1 -0
  40. package/dist/traits/VRRTraits.d.ts +2 -2
  41. package/dist/types.d.ts.map +1 -1
  42. package/package.json +24 -9
  43. package/CHANGELOG.md +0 -7
  44. package/dist/__tests__/EconomicPrimitives.test.d.ts +0 -2
  45. package/dist/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
  46. package/dist/__tests__/EconomicTraits.test.d.ts +0 -2
  47. package/dist/__tests__/EconomicTraits.test.d.ts.map +0 -1
  48. package/dist/__tests__/SimulationLabPrimitives.test.d.ts +0 -2
  49. package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +0 -1
  50. package/dist/__tests__/collections.test.d.ts +0 -2
  51. package/dist/__tests__/collections.test.d.ts.map +0 -1
  52. package/dist/__tests__/events.test.d.ts +0 -2
  53. package/dist/__tests__/events.test.d.ts.map +0 -1
  54. package/dist/__tests__/index.test.d.ts +0 -2
  55. package/dist/__tests__/index.test.d.ts.map +0 -1
  56. package/dist/__tests__/materials.test.d.ts +0 -2
  57. package/dist/__tests__/materials.test.d.ts.map +0 -1
  58. package/dist/__tests__/math.test.d.ts +0 -2
  59. package/dist/__tests__/math.test.d.ts.map +0 -1
  60. package/dist/__tests__/physics.test.d.ts +0 -2
  61. package/dist/__tests__/physics.test.d.ts.map +0 -1
  62. package/dist/__tests__/spatial.test.d.ts +0 -2
  63. package/dist/__tests__/spatial.test.d.ts.map +0 -1
  64. package/dist/__tests__/standard-library-fundamentals.test.d.ts +0 -2
  65. package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +0 -1
  66. package/dist/__tests__/string-and-time-utilities.test.d.ts +0 -2
  67. package/dist/__tests__/string-and-time-utilities.test.d.ts.map +0 -1
  68. package/dist/__tests__/string-decoupled.test.d.ts +0 -2
  69. package/dist/__tests__/string-decoupled.test.d.ts.map +0 -1
  70. package/dist/__tests__/string.test.d.ts +0 -2
  71. package/dist/__tests__/string.test.d.ts.map +0 -1
  72. package/dist/__tests__/time.test.d.ts +0 -2
  73. package/dist/__tests__/time.test.d.ts.map +0 -1
  74. package/dist/chunk-7HVUYGPS.js.map +0 -1
  75. package/dist/chunk-W2Q3LUCM.js.map +0 -1
  76. package/dist/string.basic.test.d.ts +0 -5
  77. package/dist/string.basic.test.d.ts.map +0 -1
  78. package/dist/string.test.d.ts +0 -5
  79. package/dist/string.test.d.ts.map +0 -1
  80. package/dist/traits/__tests__/ARTraits.test.d.ts +0 -2
  81. package/dist/traits/__tests__/ARTraits.test.d.ts.map +0 -1
  82. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +0 -2
  83. package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +0 -1
  84. package/dist/traits/__tests__/EconomicTraits.test.d.ts +0 -2
  85. package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +0 -1
  86. package/error-utf8.log +0 -6
  87. package/error.log +0 -0
  88. package/src/__tests__/EconomicPrimitives.test.ts +0 -690
  89. package/src/__tests__/EconomicTraits.test.ts +0 -425
  90. package/src/__tests__/SimulationLabPrimitives.test.ts +0 -415
  91. package/src/__tests__/collections.test.ts +0 -182
  92. package/src/__tests__/events.test.ts +0 -135
  93. package/src/__tests__/index.test.ts +0 -14
  94. package/src/__tests__/materials.test.ts +0 -84
  95. package/src/__tests__/math.test.ts +0 -246
  96. package/src/__tests__/physics.test.ts +0 -83
  97. package/src/__tests__/spatial.test.ts +0 -333
  98. package/src/__tests__/standard-library-fundamentals.test.ts +0 -1301
  99. package/src/__tests__/string-and-time-utilities.test.ts +0 -1070
  100. package/src/__tests__/string-decoupled.test.ts +0 -14
  101. package/src/__tests__/string.test.ts +0 -164
  102. package/src/__tests__/time.test.ts +0 -110
  103. package/src/collections.ts +0 -850
  104. package/src/events.ts +0 -88
  105. package/src/index.ts +0 -474
  106. package/src/materials.ts +0 -109
  107. package/src/math.ts +0 -674
  108. package/src/physics.ts +0 -141
  109. package/src/spatial.ts +0 -320
  110. package/src/string.basic.test.ts +0 -14
  111. package/src/string.test.ts +0 -335
  112. package/src/string.ts +0 -531
  113. package/src/time.ts +0 -621
  114. package/src/traits/ARTraits.ts +0 -103
  115. package/src/traits/EconomicPrimitives.ts +0 -755
  116. package/src/traits/EconomicTraits.ts +0 -552
  117. package/src/traits/IoTTraits.ts +0 -102
  118. package/src/traits/SimulationLabPrimitives.ts +0 -650
  119. package/src/traits/SimulationLabTraits.ts +0 -191
  120. package/src/traits/VRRTraits.ts +0 -326
  121. package/src/traits/__tests__/ARTraits.test.ts +0 -14
  122. package/src/traits/__tests__/EconomicPrimitives.test.ts +0 -14
  123. package/src/traits/__tests__/EconomicTraits.test.ts +0 -14
  124. package/src/types.ts +0 -411
  125. package/std_error.log +0 -5
  126. package/tsconfig.json +0 -18
  127. package/tsup.config.ts +0 -17
  128. package/vitest.config.ts +0 -10
@@ -1,552 +0,0 @@
1
- /**
2
- * @fileoverview Economic Trait Definitions for HoloScript
3
- * @module @holoscript/std/traits
4
- *
5
- * Defines five economic primitive traits that compose with existing VR traits
6
- * and leverage RBAC for economic permission enforcement:
7
- *
8
- * 1. @tradeable - Ownership, transfer, and trade settlement
9
- * 2. @depreciating - Time-based value decay (hard sink mechanic)
10
- * 3. @bonding_curved - Autonomous price discovery via bonding curves
11
- * 4. @taxable_wealth - Progressive wealth taxation with redistribution
12
- * 5. @pid_controlled - Dual-loop PID feedback for faucet/sink regulation
13
- *
14
- * These traits implement the research-proven mechanisms from:
15
- * - P.030.01 Dual-Loop PID Economy Controller
16
- * - P.030.02 Bonding Curve Marketplace
17
- * - P.030.03 Progressive Wealth Recycling
18
- * - W.031 Faucet-Sink Ratio as Master Variable
19
- * - W.032 Dual-Loop Feedback Control
20
- * - W.034 Wealth Tax > Income Tax for Gini Reduction
21
- * - W.035 Bonding Curves for Price Discovery
22
- *
23
- * RBAC Integration:
24
- * Each trait declares required permissions from the economy.* permission
25
- * category. The HoloScript compiler enforces these at compile time via
26
- * the existing AgentRBAC system.
27
- *
28
- * @version 1.0.0
29
- * @category economic
30
- */
31
-
32
- import type { TraitDefinition } from '../types.js';
33
-
34
- /**
35
- * Extended trait definition with economic-specific metadata.
36
- */
37
- export interface EconomicTraitDefinition extends TraitDefinition {
38
- /** RBAC permissions required to use this trait */
39
- requiredPermissions: string[];
40
- /** Economic layer this trait operates at (from 9-layer architecture) */
41
- economicLayer: number;
42
- /** Composability: which other economic traits this one works with */
43
- composesWith: string[];
44
- /** Compiler hints for code generation */
45
- compiler_hints?: {
46
- requires_runtime?: string[];
47
- thread_safety?: 'main_thread' | 'worker_thread' | 'any';
48
- performance_budget_ms?: number;
49
- };
50
- }
51
-
52
- // =============================================================================
53
- // TRAIT DEFINITIONS
54
- // =============================================================================
55
-
56
- /**
57
- * The five economic primitive traits.
58
- */
59
- export const EconomicTraits: Record<string, EconomicTraitDefinition> = {
60
- // ---------------------------------------------------------------------------
61
- // 1. TRADEABLE
62
- // ---------------------------------------------------------------------------
63
- tradeable: {
64
- name: '@tradeable',
65
- description:
66
- 'Makes a composition or node transferable between agents. Tracks ownership ' +
67
- 'history with transaction hashes for integrity verification (P.030.04). ' +
68
- 'Supports lock/unlock for escrow patterns and auction integration.',
69
- params: {
70
- initial_owner: {
71
- type: 'AgentID',
72
- required: true,
73
- description: 'The agent who initially owns this entity.',
74
- },
75
- transferable: {
76
- type: 'boolean',
77
- required: false,
78
- default: true,
79
- description: 'Whether transfers are currently allowed.',
80
- },
81
- min_price: {
82
- type: 'number',
83
- required: false,
84
- default: 0,
85
- description: 'Minimum trade price (prevents value manipulation).',
86
- },
87
- max_history: {
88
- type: 'number',
89
- required: false,
90
- default: 50,
91
- description: 'Maximum ownership history entries retained.',
92
- },
93
- requires_presence: {
94
- type: 'boolean',
95
- required: false,
96
- default: false,
97
- description: 'VR-specific: require spatial co-location for trade (anti-exploit, Layer 7).',
98
- },
99
- presence_radius: {
100
- type: 'number',
101
- required: false,
102
- default: 5.0,
103
- description: 'Maximum distance in meters for presence-based trades.',
104
- },
105
- },
106
- validator: (params) => {
107
- if (!params.initial_owner || typeof params.initial_owner !== 'string') return false;
108
- if (params.min_price !== undefined && params.min_price < 0) return false;
109
- return true;
110
- },
111
- requiredPermissions: ['economy.trade'],
112
- economicLayer: 0, // Layer 0: Integrity
113
- composesWith: ['@depreciating', '@bonding_curved', '@taxable_wealth'],
114
- compiler_hints: {
115
- requires_runtime: ['EconomicRuntime.executeTrade', 'EconomicRuntime.verifyOwnership'],
116
- thread_safety: 'any',
117
- },
118
- },
119
-
120
- // ---------------------------------------------------------------------------
121
- // 2. DEPRECIATING
122
- // ---------------------------------------------------------------------------
123
- depreciating: {
124
- name: '@depreciating',
125
- description:
126
- 'Applies time-based value decay to an entity (hard sink mechanic). ' +
127
- 'Uses exponential decay: condition(t) = condition(0) * e^(-rate * t). ' +
128
- 'When condition reaches destroy_threshold, the entity is consumed -- ' +
129
- 'removing currency/value from circulation permanently (W.031).',
130
- params: {
131
- decay_rate: {
132
- type: 'number',
133
- required: true,
134
- description: 'Per-second decay rate (0.0 - 1.0). E.g., 0.001 = 0.1% per second.',
135
- },
136
- initial_condition: {
137
- type: 'number',
138
- required: false,
139
- default: 1.0,
140
- description: 'Starting condition (1.0 = mint, 0.0 = destroyed).',
141
- },
142
- destroy_threshold: {
143
- type: 'number',
144
- required: false,
145
- default: 0.01,
146
- description: 'Condition level at which the entity is destroyed.',
147
- },
148
- repairable: {
149
- type: 'boolean',
150
- required: false,
151
- default: true,
152
- description: 'Whether the entity can be repaired to restore condition.',
153
- },
154
- repair_cost_multiplier: {
155
- type: 'number',
156
- required: false,
157
- default: 0.5,
158
- description: 'Repair cost as a fraction of base value per unit condition.',
159
- },
160
- emit_on_destroy: {
161
- type: 'string',
162
- required: false,
163
- default: 'on_entity_destroyed',
164
- description: 'Event emitted when condition reaches destroy threshold.',
165
- },
166
- },
167
- validator: (params) => {
168
- if (params.decay_rate === undefined || params.decay_rate < 0 || params.decay_rate > 1)
169
- return false;
170
- if (
171
- params.initial_condition !== undefined &&
172
- (params.initial_condition < 0 || params.initial_condition > 1)
173
- )
174
- return false;
175
- if (
176
- params.destroy_threshold !== undefined &&
177
- (params.destroy_threshold < 0 || params.destroy_threshold > 1)
178
- )
179
- return false;
180
- return true;
181
- },
182
- requiredPermissions: ['economy.burn'],
183
- economicLayer: 1, // Layer 1: Flow Control (sink side)
184
- composesWith: ['@tradeable', '@bonding_curved'],
185
- compiler_hints: {
186
- requires_runtime: ['EconomicRuntime.updateDepreciation', 'EconomicRuntime.destroyEntity'],
187
- thread_safety: 'worker_thread',
188
- performance_budget_ms: 0.1, // Must be fast -- called every tick
189
- },
190
- },
191
-
192
- // ---------------------------------------------------------------------------
193
- // 3. BONDING_CURVED
194
- // ---------------------------------------------------------------------------
195
- bonding_curved: {
196
- name: '@bonding_curved',
197
- description:
198
- 'Attaches a bonding curve to a marketplace or item category for autonomous ' +
199
- 'price discovery. Price is determined by P = f(supply) where f depends on ' +
200
- 'curve_type. Provides continuous liquidity via reserve pool without order ' +
201
- 'books (W.035, P.030.02). Supports spatial pricing for VR trade geography.',
202
- params: {
203
- curve_type: {
204
- type: 'string',
205
- required: false,
206
- default: 'exponential',
207
- description: 'Curve shape: linear | exponential | logarithmic | sigmoid.',
208
- validation: (val: any) => ['linear', 'exponential', 'logarithmic', 'sigmoid'].includes(val),
209
- },
210
- reserve_ratio: {
211
- type: 'number',
212
- required: true,
213
- description: 'Base price multiplier (R in the price formula).',
214
- },
215
- curve_steepness: {
216
- type: 'number',
217
- required: false,
218
- default: 2.0,
219
- description: 'Controls price sensitivity to supply changes (n in P = R * S^(1/n)).',
220
- },
221
- transaction_fee: {
222
- type: 'number',
223
- required: false,
224
- default: 0.02,
225
- description: 'Fee percentage per transaction (hard sink). Range: 0.0 - 0.5.',
226
- },
227
- initial_supply: {
228
- type: 'number',
229
- required: false,
230
- default: 0,
231
- description: 'Initial token/item supply on the curve.',
232
- },
233
- initial_reserve: {
234
- type: 'number',
235
- required: false,
236
- default: 0,
237
- description: 'Initial reserve pool balance backing the curve.',
238
- },
239
- sigmoid_k: {
240
- type: 'number',
241
- required: false,
242
- default: 100,
243
- description: 'Half-saturation constant for sigmoid curves.',
244
- },
245
- spatial_distance_factor: {
246
- type: 'number',
247
- required: false,
248
- default: 0.0,
249
- description:
250
- 'VR spatial pricing: price multiplier per unit distance from hub. ' +
251
- '0.0 = no spatial effect. Creates emergent trade routes (P.030.02 ENRICHED).',
252
- },
253
- },
254
- validator: (params) => {
255
- if (params.reserve_ratio === undefined || params.reserve_ratio <= 0) return false;
256
- if (params.curve_steepness !== undefined && params.curve_steepness <= 0) return false;
257
- if (
258
- params.transaction_fee !== undefined &&
259
- (params.transaction_fee < 0 || params.transaction_fee > 0.5)
260
- )
261
- return false;
262
- if (params.curve_type !== undefined) {
263
- if (!['linear', 'exponential', 'logarithmic', 'sigmoid'].includes(params.curve_type))
264
- return false;
265
- }
266
- return true;
267
- },
268
- requiredPermissions: ['economy.set_price', 'economy.trade'],
269
- economicLayer: 2, // Layer 2: Price Discovery
270
- composesWith: ['@tradeable', '@depreciating', '@pid_controlled'],
271
- compiler_hints: {
272
- requires_runtime: [
273
- 'EconomicRuntime.bondingCurveBuy',
274
- 'EconomicRuntime.bondingCurveSell',
275
- 'EconomicRuntime.getSpotPrice',
276
- ],
277
- thread_safety: 'any',
278
- performance_budget_ms: 1.0,
279
- },
280
- },
281
-
282
- // ---------------------------------------------------------------------------
283
- // 4. TAXABLE_WEALTH
284
- // ---------------------------------------------------------------------------
285
- taxable_wealth: {
286
- name: '@taxable_wealth',
287
- description:
288
- 'Applies progressive logarithmic wealth taxation with optional redistribution ' +
289
- 'to the lowest-wealth quintile (P.030.03, W.034). Tax = 0 below threshold, ' +
290
- 'then rate = min(max_rate, log(wealth/threshold) * base_rate). Collected taxes ' +
291
- 'are partially redistributed (UBI) and partially burned (hard sink).',
292
- params: {
293
- threshold: {
294
- type: 'number',
295
- required: true,
296
- description: 'Wealth level below which no tax is levied.',
297
- },
298
- base_rate: {
299
- type: 'number',
300
- required: false,
301
- default: 0.01,
302
- description: 'Base tax rate multiplied by log(wealth/threshold). Range: 0.0 - 0.1.',
303
- },
304
- max_effective_rate: {
305
- type: 'number',
306
- required: false,
307
- default: 0.05,
308
- description: 'Maximum effective tax rate cap (prevents punishing engagement).',
309
- },
310
- collection_interval: {
311
- type: 'string',
312
- required: false,
313
- default: 'daily',
314
- description: 'How often taxes are collected: hourly | daily | weekly.',
315
- validation: (val: any) => ['hourly', 'daily', 'weekly'].includes(val),
316
- },
317
- enable_redistribution: {
318
- type: 'boolean',
319
- required: false,
320
- default: true,
321
- description: 'Whether collected tax is redistributed to lowest-wealth players.',
322
- },
323
- redistribution_fraction: {
324
- type: 'number',
325
- required: false,
326
- default: 0.7,
327
- description:
328
- 'Fraction of tax redistributed (remainder burned as hard sink). Range: 0.0 - 1.0.',
329
- },
330
- emit_on_collection: {
331
- type: 'string',
332
- required: false,
333
- default: 'on_tax_collected',
334
- description: 'Event emitted when taxes are collected.',
335
- },
336
- public_ledger: {
337
- type: 'boolean',
338
- required: false,
339
- default: true,
340
- description:
341
- 'Whether tax collections and redistribution are visible in the ' +
342
- 'economy dashboard (Layer 6: Transparency, W.038).',
343
- },
344
- },
345
- validator: (params) => {
346
- if (params.threshold === undefined || params.threshold < 0) return false;
347
- if (params.base_rate !== undefined && (params.base_rate < 0 || params.base_rate > 0.1))
348
- return false;
349
- if (
350
- params.max_effective_rate !== undefined &&
351
- (params.max_effective_rate < 0 || params.max_effective_rate > 1.0)
352
- )
353
- return false;
354
- if (
355
- params.redistribution_fraction !== undefined &&
356
- (params.redistribution_fraction < 0 || params.redistribution_fraction > 1.0)
357
- )
358
- return false;
359
- return true;
360
- },
361
- requiredPermissions: ['economy.tax', 'economy.redistribute'],
362
- economicLayer: 4, // Layer 4: Redistribution
363
- composesWith: ['@tradeable', '@pid_controlled'],
364
- compiler_hints: {
365
- requires_runtime: [
366
- 'EconomicRuntime.collectTax',
367
- 'EconomicRuntime.redistribute',
368
- 'EconomicRuntime.getGiniCoefficient',
369
- ],
370
- thread_safety: 'worker_thread',
371
- performance_budget_ms: 5.0, // Runs on collection interval, not per-frame
372
- },
373
- },
374
-
375
- // ---------------------------------------------------------------------------
376
- // 5. PID_CONTROLLED
377
- // ---------------------------------------------------------------------------
378
- pid_controlled: {
379
- name: '@pid_controlled',
380
- description:
381
- 'Attaches a dual-loop PID feedback controller to regulate economic flow ' +
382
- '(P.030.01, W.032). Inner loop adjusts per-source faucet rates (fast). ' +
383
- 'Outer loop adjusts inner setpoint based on total money supply (slow). ' +
384
- 'Achieves <10% currency variance long-term while preserving gameplay variance.',
385
- params: {
386
- target_per_capita: {
387
- type: 'number',
388
- required: true,
389
- description: 'Target currency per active player (outer loop setpoint).',
390
- },
391
- inner_kp: {
392
- type: 'number',
393
- required: false,
394
- default: 0.5,
395
- description: 'Inner loop proportional gain.',
396
- },
397
- inner_ki: {
398
- type: 'number',
399
- required: false,
400
- default: 0.01,
401
- description: 'Inner loop integral gain.',
402
- },
403
- inner_kd: {
404
- type: 'number',
405
- required: false,
406
- default: 0.1,
407
- description: 'Inner loop derivative gain.',
408
- },
409
- outer_kp: {
410
- type: 'number',
411
- required: false,
412
- default: 0.3,
413
- description: 'Outer loop proportional gain.',
414
- },
415
- outer_ki: {
416
- type: 'number',
417
- required: false,
418
- default: 0.005,
419
- description: 'Outer loop integral gain.',
420
- },
421
- outer_kd: {
422
- type: 'number',
423
- required: false,
424
- default: 0.05,
425
- description: 'Outer loop derivative gain.',
426
- },
427
- update_interval: {
428
- type: 'number',
429
- required: false,
430
- default: 1.0,
431
- description: 'Controller update interval in seconds.',
432
- },
433
- faucet_min_multiplier: {
434
- type: 'number',
435
- required: false,
436
- default: 0.1,
437
- description: 'Minimum faucet rate multiplier (never fully stop rewards).',
438
- },
439
- faucet_max_multiplier: {
440
- type: 'number',
441
- required: false,
442
- default: 2.0,
443
- description: 'Maximum faucet rate multiplier.',
444
- },
445
- track_faucet_sink_ratio: {
446
- type: 'boolean',
447
- required: false,
448
- default: true,
449
- description: 'Whether to track and emit faucet/sink ratio metrics (W.031).',
450
- },
451
- emit_on_adjustment: {
452
- type: 'string',
453
- required: false,
454
- default: 'on_faucet_adjusted',
455
- description: 'Event emitted when faucet rate is adjusted.',
456
- },
457
- },
458
- validator: (params) => {
459
- if (params.target_per_capita === undefined || params.target_per_capita <= 0) return false;
460
- // PID gains can be any real number, but should be reasonable
461
- const gains = [
462
- params.inner_kp,
463
- params.inner_ki,
464
- params.inner_kd,
465
- params.outer_kp,
466
- params.outer_ki,
467
- params.outer_kd,
468
- ];
469
- for (const g of gains) {
470
- if (g !== undefined && (typeof g !== 'number' || isNaN(g))) return false;
471
- }
472
- if (params.update_interval !== undefined && params.update_interval <= 0) return false;
473
- return true;
474
- },
475
- requiredPermissions: ['economy.tune_pid', 'economy.mint', 'economy.burn'],
476
- economicLayer: 1, // Layer 1: Flow Control
477
- composesWith: ['@bonding_curved', '@taxable_wealth'],
478
- compiler_hints: {
479
- requires_runtime: [
480
- 'EconomicRuntime.updatePID',
481
- 'EconomicRuntime.getFaucetMultiplier',
482
- 'EconomicRuntime.getFaucetSinkMetrics',
483
- ],
484
- thread_safety: 'worker_thread',
485
- performance_budget_ms: 0.5,
486
- },
487
- },
488
- };
489
-
490
- // =============================================================================
491
- // TRAIT UTILITIES
492
- // =============================================================================
493
-
494
- /**
495
- * Get all trait names as an array.
496
- */
497
- export function getEconomicTraitNames(): string[] {
498
- return Object.keys(EconomicTraits).map((k) => EconomicTraits[k].name);
499
- }
500
-
501
- /**
502
- * Look up a trait definition by its @-prefixed name.
503
- */
504
- export function getEconomicTrait(name: string): EconomicTraitDefinition | undefined {
505
- const key = name.startsWith('@') ? name.slice(1) : name;
506
- return EconomicTraits[key];
507
- }
508
-
509
- /**
510
- * Validate that a set of composed traits are compatible.
511
- * Returns an error message if incompatible, or null if valid.
512
- */
513
- export function validateTraitComposition(traitNames: string[]): string | null {
514
- for (const name of traitNames) {
515
- const trait = getEconomicTrait(name);
516
- if (!trait) {
517
- return `Unknown economic trait: ${name}`;
518
- }
519
- }
520
-
521
- // Check that all traits compose with each other
522
- for (const name of traitNames) {
523
- const trait = getEconomicTrait(name)!;
524
- for (const other of traitNames) {
525
- if (other === name) continue;
526
- const otherPrefixed = other.startsWith('@') ? other : `@${other}`;
527
- if (!trait.composesWith.includes(otherPrefixed)) {
528
- return `Trait ${trait.name} does not compose with ${otherPrefixed}`;
529
- }
530
- }
531
- }
532
-
533
- return null;
534
- }
535
-
536
- /**
537
- * Get all RBAC permissions required by a set of economic traits.
538
- */
539
- export function getRequiredPermissions(traitNames: string[]): string[] {
540
- const permissions = new Set<string>();
541
- for (const name of traitNames) {
542
- const trait = getEconomicTrait(name);
543
- if (trait) {
544
- for (const perm of trait.requiredPermissions) {
545
- permissions.add(perm);
546
- }
547
- }
548
- }
549
- return Array.from(permissions).sort();
550
- }
551
-
552
- export default EconomicTraits;
@@ -1,102 +0,0 @@
1
- /**
2
- * @fileoverview IoT Traits (Internet of Things & Healthcare)
3
- * @module @holoscript/std/traits
4
- *
5
- * Defines the AST traits required for real-world physical sensor mapping
6
- * and hardware actuator integration inside the HoloScript engine.
7
- */
8
-
9
- import type { TraitDefinition } from '../types.js';
10
-
11
- /**
12
- * Standard IoT and Hardware traits included in HoloScript's base functionality
13
- */
14
- export const IoTTraits: TraitDefinition[] = [
15
- {
16
- name: '@sensor_stream',
17
- type: 'data_binding',
18
- description:
19
- 'Binds a virtual digital twin property directly to a real-world IoT sensor telemetry stream.',
20
- parameters: [
21
- {
22
- name: 'sensor_id',
23
- type: 'string',
24
- required: true,
25
- description: 'The unique hardware identifier (MAC address, IP, or cloud UUID).',
26
- },
27
- {
28
- name: 'telemetry_type',
29
- type: 'string',
30
- required: true,
31
- validation: (val: any) =>
32
- ['temperature', 'pressure', 'heart_rate', 'spo2', 'motion', 'custom'].includes(val),
33
- description: 'The standard type of data the sensor provides.',
34
- },
35
- {
36
- name: 'update_hz',
37
- type: 'number',
38
- required: false,
39
- defaultValue: 10,
40
- description: 'The target refresh rate in Hertz.',
41
- },
42
- ],
43
- validation: (node: any) => {
44
- return { valid: true };
45
- },
46
- },
47
- {
48
- name: '@actuator',
49
- type: 'behavior',
50
- description:
51
- 'Defines this HoloScript node as a control schema that can send physical actions back to real-world mechanisms.',
52
- parameters: [
53
- {
54
- name: 'device_id',
55
- type: 'string',
56
- required: true,
57
- description: 'The identifier of the physical actuator.',
58
- },
59
- {
60
- name: 'action_range',
61
- type: 'array',
62
- required: false,
63
- description:
64
- 'An array characterizing min/max values or discrete states to prevent hardware damage.',
65
- },
66
- ],
67
- validation: (node: any) => {
68
- // Must be bound to objects or scripts that can trigger state
69
- if (node.type !== 'Object' && node.type !== 'Script') {
70
- return { valid: false, message: '@actuator must be attached to an Object or Script node.' };
71
- }
72
- return { valid: true };
73
- },
74
- },
75
- {
76
- name: '@hardware_fault',
77
- type: 'event_hook',
78
- description:
79
- 'Registers an alert topology for when a linked physical sensor goes offline or returns anomalous readings.',
80
- parameters: [
81
- {
82
- name: 'anomaly_threshold',
83
- type: 'number',
84
- required: false,
85
- description: 'The variance (e.g. standard deviations) that triggers a fault state.',
86
- },
87
- {
88
- name: 'fallback_behavior',
89
- type: 'string',
90
- required: false,
91
- defaultValue: 'freeze',
92
- validation: (val: any) => ['freeze', 'interpolate', 'disconnect', 'alert'].includes(val),
93
- description: 'What the digital twin should do when physical telemetry fails.',
94
- },
95
- ],
96
- validation: (node: any) => {
97
- return { valid: true };
98
- },
99
- },
100
- ];
101
-
102
- export default IoTTraits;