@almadar/std 3.13.0 → 3.13.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 (86) hide show
  1. package/behaviors/exports/atoms/std-agent-activity-log.orb +559 -0
  2. package/behaviors/exports/atoms/std-agent-chat-thread.orb +774 -0
  3. package/behaviors/exports/atoms/std-agent-classifier.orb +606 -137
  4. package/behaviors/exports/atoms/std-agent-completion.orb +646 -182
  5. package/behaviors/exports/atoms/std-agent-context-window.orb +1762 -258
  6. package/behaviors/exports/atoms/std-agent-conversation.orb +652 -369
  7. package/behaviors/exports/atoms/std-agent-memory.orb +574 -322
  8. package/behaviors/exports/atoms/std-agent-provider.orb +632 -136
  9. package/behaviors/exports/atoms/std-agent-search.orb +228 -198
  10. package/behaviors/exports/atoms/std-agent-session.orb +569 -559
  11. package/behaviors/exports/atoms/std-agent-step-progress.orb +850 -0
  12. package/behaviors/exports/atoms/std-agent-token-gauge.orb +1616 -0
  13. package/behaviors/exports/atoms/std-agent-tool-call.orb +983 -126
  14. package/behaviors/exports/molecules/std-agent-fix-loop.orb +1985 -21
  15. package/behaviors/exports/molecules/std-agent-learner.orb +1830 -23
  16. package/behaviors/exports/molecules/std-agent-planner.orb +1776 -19
  17. package/behaviors/exports/molecules/std-agent-rag.orb +1150 -15
  18. package/behaviors/exports/molecules/std-agent-tool-loop.orb +3643 -23
  19. package/behaviors/exports/organisms/std-agent-assistant.orb +5308 -1156
  20. package/behaviors/exports/organisms/std-agent-builder.orb +13525 -1326
  21. package/behaviors/exports/organisms/std-agent-pipeline.orb +10731 -1088
  22. package/behaviors/exports/organisms/std-agent-reviewer.orb +4187 -525
  23. package/behaviors/exports/organisms/std-agent-tutor.orb +3126 -322
  24. package/behaviors/exports/validation-report.json +1 -1426
  25. package/dist/behaviors/exports/atoms/std-agent-activity-log.orb +559 -0
  26. package/dist/behaviors/exports/atoms/std-agent-chat-thread.orb +774 -0
  27. package/dist/behaviors/exports/atoms/std-agent-classifier.orb +606 -137
  28. package/dist/behaviors/exports/atoms/std-agent-completion.orb +646 -182
  29. package/dist/behaviors/exports/atoms/std-agent-context-window.orb +1762 -258
  30. package/dist/behaviors/exports/atoms/std-agent-conversation.orb +652 -369
  31. package/dist/behaviors/exports/atoms/std-agent-memory.orb +574 -322
  32. package/dist/behaviors/exports/atoms/std-agent-provider.orb +632 -136
  33. package/dist/behaviors/exports/atoms/std-agent-search.orb +228 -198
  34. package/dist/behaviors/exports/atoms/std-agent-session.orb +569 -559
  35. package/dist/behaviors/exports/atoms/std-agent-step-progress.orb +850 -0
  36. package/dist/behaviors/exports/atoms/std-agent-token-gauge.orb +1616 -0
  37. package/dist/behaviors/exports/atoms/std-agent-tool-call.orb +983 -126
  38. package/dist/behaviors/exports/molecules/std-agent-fix-loop.orb +1985 -21
  39. package/dist/behaviors/exports/molecules/std-agent-learner.orb +1830 -23
  40. package/dist/behaviors/exports/molecules/std-agent-planner.orb +1776 -19
  41. package/dist/behaviors/exports/molecules/std-agent-rag.orb +1150 -15
  42. package/dist/behaviors/exports/molecules/std-agent-tool-loop.orb +3643 -23
  43. package/dist/behaviors/exports/organisms/std-agent-assistant.orb +5308 -1156
  44. package/dist/behaviors/exports/organisms/std-agent-builder.orb +13525 -1326
  45. package/dist/behaviors/exports/organisms/std-agent-pipeline.orb +10731 -1088
  46. package/dist/behaviors/exports/organisms/std-agent-reviewer.orb +4187 -525
  47. package/dist/behaviors/exports/organisms/std-agent-tutor.orb +3126 -322
  48. package/dist/behaviors/exports/validation-report.json +1 -1426
  49. package/dist/behaviors/exports-reader.js +4860 -4176
  50. package/dist/behaviors/exports-reader.js.map +1 -1
  51. package/dist/behaviors/functions/index.d.ts +259 -98
  52. package/dist/behaviors/functions/index.js +4845 -4177
  53. package/dist/behaviors/functions/index.js.map +1 -1
  54. package/dist/behaviors/index.d.ts +1 -1
  55. package/dist/behaviors/index.js +4863 -4179
  56. package/dist/behaviors/index.js.map +1 -1
  57. package/dist/behaviors/query.js +4862 -4178
  58. package/dist/behaviors/query.js.map +1 -1
  59. package/dist/exports/atoms/std-agent-activity-log.orb +559 -0
  60. package/dist/exports/atoms/std-agent-chat-thread.orb +774 -0
  61. package/dist/exports/atoms/std-agent-classifier.orb +606 -137
  62. package/dist/exports/atoms/std-agent-completion.orb +646 -182
  63. package/dist/exports/atoms/std-agent-context-window.orb +1762 -258
  64. package/dist/exports/atoms/std-agent-conversation.orb +652 -369
  65. package/dist/exports/atoms/std-agent-memory.orb +574 -322
  66. package/dist/exports/atoms/std-agent-provider.orb +632 -136
  67. package/dist/exports/atoms/std-agent-search.orb +228 -198
  68. package/dist/exports/atoms/std-agent-session.orb +569 -559
  69. package/dist/exports/atoms/std-agent-step-progress.orb +850 -0
  70. package/dist/exports/atoms/std-agent-token-gauge.orb +1616 -0
  71. package/dist/exports/atoms/std-agent-tool-call.orb +983 -126
  72. package/dist/exports/molecules/std-agent-fix-loop.orb +1985 -21
  73. package/dist/exports/molecules/std-agent-learner.orb +1830 -23
  74. package/dist/exports/molecules/std-agent-planner.orb +1776 -19
  75. package/dist/exports/molecules/std-agent-rag.orb +1150 -15
  76. package/dist/exports/molecules/std-agent-tool-loop.orb +3643 -23
  77. package/dist/exports/organisms/std-agent-assistant.orb +5308 -1156
  78. package/dist/exports/organisms/std-agent-builder.orb +13525 -1326
  79. package/dist/exports/organisms/std-agent-pipeline.orb +10731 -1088
  80. package/dist/exports/organisms/std-agent-reviewer.orb +4187 -525
  81. package/dist/exports/organisms/std-agent-tutor.orb +3126 -322
  82. package/dist/exports/validation-report.json +1 -1426
  83. package/dist/index.d.ts +1 -1
  84. package/dist/index.js +4864 -4180
  85. package/dist/index.js.map +1 -1
  86. package/package.json +1 -1
@@ -53,12 +53,37 @@
53
53
  "name": "lastCompactedAt",
54
54
  "type": "string",
55
55
  "default": ""
56
+ },
57
+ {
58
+ "name": "current",
59
+ "type": "number",
60
+ "default": 0
61
+ },
62
+ {
63
+ "name": "max",
64
+ "type": "number",
65
+ "default": 200000
66
+ },
67
+ {
68
+ "name": "threshold",
69
+ "type": "number",
70
+ "default": 0.85
71
+ },
72
+ {
73
+ "name": "message",
74
+ "type": "string",
75
+ "default": ""
76
+ },
77
+ {
78
+ "name": "notificationType",
79
+ "type": "string",
80
+ "default": "info"
56
81
  }
57
82
  ]
58
83
  },
59
84
  "traits": [
60
85
  {
61
- "name": "AgentContextWindowManager",
86
+ "name": "AgentContextWindowGauge",
62
87
  "linkedEntity": "AgentContextWindow",
63
88
  "category": "interaction",
64
89
  "stateMachine": {
@@ -68,10 +93,10 @@
68
93
  "isInitial": true
69
94
  },
70
95
  {
71
- "name": "approaching_limit"
96
+ "name": "warning"
72
97
  },
73
98
  {
74
- "name": "at_limit"
99
+ "name": "critical"
75
100
  }
76
101
  ],
77
102
  "events": [
@@ -80,12 +105,23 @@
80
105
  "name": "Initialize"
81
106
  },
82
107
  {
83
- "key": "UPDATE_TOKENS",
84
- "name": "Update Token Count"
108
+ "key": "UPDATE",
109
+ "name": "Update Token Count",
110
+ "payload": [
111
+ {
112
+ "name": "current",
113
+ "type": "number",
114
+ "required": true
115
+ }
116
+ ]
85
117
  },
86
118
  {
87
119
  "key": "COMPACT",
88
120
  "name": "Compact Context"
121
+ },
122
+ {
123
+ "key": "RESET",
124
+ "name": "Reset Gauge"
89
125
  }
90
126
  ],
91
127
  "transitions": [
@@ -98,12 +134,6 @@
98
134
  "fetch",
99
135
  "AgentContextWindow"
100
136
  ],
101
- [
102
- "agent/token-count"
103
- ],
104
- [
105
- "agent/context-usage"
106
- ],
107
137
  [
108
138
  "render-ui",
109
139
  "main",
@@ -120,52 +150,52 @@
120
150
  "children": [
121
151
  {
122
152
  "type": "icon",
123
- "name": "layers",
153
+ "name": "gauge",
124
154
  "size": "lg"
125
155
  },
126
156
  {
127
157
  "type": "typography",
128
- "content": "AgentContextWindow",
158
+ "content": "Token Usage",
129
159
  "variant": "h2"
160
+ },
161
+ {
162
+ "type": "badge",
163
+ "label": "Normal",
164
+ "variant": "default"
130
165
  }
131
166
  ]
132
167
  },
133
168
  {
134
169
  "type": "divider"
135
170
  },
171
+ {
172
+ "type": "progress-bar",
173
+ "value": "@entity.current",
174
+ "max": "@entity.max"
175
+ },
136
176
  {
137
177
  "type": "stack",
138
178
  "direction": "horizontal",
139
179
  "gap": "md",
140
180
  "children": [
141
181
  {
142
- "type": "badge",
143
- "label": "@entity.tokenCount",
144
- "variant": "default"
145
- },
146
- {
147
- "type": "typography",
148
- "variant": "caption",
149
- "content": "/"
182
+ "type": "stat-display",
183
+ "label": "Tokens Used",
184
+ "value": "@entity.current"
150
185
  },
151
186
  {
152
- "type": "badge",
153
- "label": "@entity.maxTokens",
154
- "variant": "default"
187
+ "type": "stat-display",
188
+ "label": "Max Tokens",
189
+ "value": "@entity.max"
155
190
  }
156
191
  ]
157
192
  },
158
- {
159
- "type": "progress-bar",
160
- "value": "@entity.usage",
161
- "max": 100
162
- },
163
193
  {
164
194
  "type": "button",
165
- "label": "Update Tokens",
166
- "event": "UPDATE_TOKENS",
167
- "variant": "secondary",
168
- "icon": "refresh-cw"
195
+ "label": "Reset",
196
+ "event": "RESET",
197
+ "variant": "ghost",
198
+ "icon": "rotate-ccw"
169
199
  }
170
200
  ]
171
201
  }
@@ -175,35 +205,21 @@
175
205
  {
176
206
  "from": "normal",
177
207
  "to": "normal",
178
- "event": "UPDATE_TOKENS",
208
+ "event": "UPDATE",
179
209
  "guard": [
180
210
  "<",
181
211
  [
182
212
  "/",
183
- "@entity.tokenCount",
184
- "@entity.maxTokens"
213
+ "@payload.current",
214
+ "@entity.max"
185
215
  ],
186
216
  0.85
187
217
  ],
188
218
  "effects": [
189
- [
190
- "agent/token-count"
191
- ],
192
- [
193
- "agent/context-usage"
194
- ],
195
219
  [
196
220
  "set",
197
- "@entity.usage",
198
- [
199
- "*",
200
- [
201
- "/",
202
- "@entity.tokenCount",
203
- "@entity.maxTokens"
204
- ],
205
- 100
206
- ]
221
+ "@entity.current",
222
+ "@payload.current"
207
223
  ],
208
224
  [
209
225
  "render-ui",
@@ -221,52 +237,52 @@
221
237
  "children": [
222
238
  {
223
239
  "type": "icon",
224
- "name": "layers",
240
+ "name": "gauge",
225
241
  "size": "lg"
226
242
  },
227
243
  {
228
244
  "type": "typography",
229
- "content": "AgentContextWindow",
245
+ "content": "Token Usage",
230
246
  "variant": "h2"
247
+ },
248
+ {
249
+ "type": "badge",
250
+ "label": "Normal",
251
+ "variant": "default"
231
252
  }
232
253
  ]
233
254
  },
234
255
  {
235
256
  "type": "divider"
236
257
  },
258
+ {
259
+ "type": "progress-bar",
260
+ "value": "@entity.current",
261
+ "max": "@entity.max"
262
+ },
237
263
  {
238
264
  "type": "stack",
239
265
  "direction": "horizontal",
240
266
  "gap": "md",
241
267
  "children": [
242
268
  {
243
- "type": "badge",
244
- "label": "@entity.tokenCount",
245
- "variant": "default"
246
- },
247
- {
248
- "type": "typography",
249
- "variant": "caption",
250
- "content": "/"
269
+ "type": "stat-display",
270
+ "label": "Tokens Used",
271
+ "value": "@entity.current"
251
272
  },
252
273
  {
253
- "type": "badge",
254
- "label": "@entity.maxTokens",
255
- "variant": "default"
274
+ "type": "stat-display",
275
+ "label": "Max Tokens",
276
+ "value": "@entity.max"
256
277
  }
257
278
  ]
258
279
  },
259
- {
260
- "type": "progress-bar",
261
- "value": "@entity.usage",
262
- "max": 100
263
- },
264
280
  {
265
281
  "type": "button",
266
- "label": "Update Tokens",
267
- "event": "UPDATE_TOKENS",
268
- "variant": "secondary",
269
- "icon": "refresh-cw"
282
+ "label": "Reset",
283
+ "event": "RESET",
284
+ "variant": "ghost",
285
+ "icon": "rotate-ccw"
270
286
  }
271
287
  ]
272
288
  }
@@ -275,16 +291,16 @@
275
291
  },
276
292
  {
277
293
  "from": "normal",
278
- "to": "approaching_limit",
279
- "event": "UPDATE_TOKENS",
294
+ "to": "warning",
295
+ "event": "UPDATE",
280
296
  "guard": [
281
297
  "and",
282
298
  [
283
299
  ">=",
284
300
  [
285
301
  "/",
286
- "@entity.tokenCount",
287
- "@entity.maxTokens"
302
+ "@payload.current",
303
+ "@entity.max"
288
304
  ],
289
305
  0.85
290
306
  ],
@@ -292,31 +308,17 @@
292
308
  "<",
293
309
  [
294
310
  "/",
295
- "@entity.tokenCount",
296
- "@entity.maxTokens"
311
+ "@payload.current",
312
+ "@entity.max"
297
313
  ],
298
- 1
314
+ 0.95
299
315
  ]
300
316
  ],
301
317
  "effects": [
302
- [
303
- "agent/token-count"
304
- ],
305
- [
306
- "agent/context-usage"
307
- ],
308
318
  [
309
319
  "set",
310
- "@entity.usage",
311
- [
312
- "*",
313
- [
314
- "/",
315
- "@entity.tokenCount",
316
- "@entity.maxTokens"
317
- ],
318
- 100
319
- ]
320
+ "@entity.current",
321
+ "@payload.current"
320
322
  ],
321
323
  [
322
324
  "render-ui",
@@ -339,8 +341,13 @@
339
341
  },
340
342
  {
341
343
  "type": "typography",
342
- "content": "AgentContextWindow (Warning)",
344
+ "content": "Token Usage",
343
345
  "variant": "h2"
346
+ },
347
+ {
348
+ "type": "badge",
349
+ "label": "Warning",
350
+ "variant": "warning"
344
351
  }
345
352
  ]
346
353
  },
@@ -350,12 +357,29 @@
350
357
  {
351
358
  "type": "alert",
352
359
  "variant": "warning",
353
- "message": "Context window approaching limit."
360
+ "message": "Token usage approaching limit. Consider compacting."
354
361
  },
355
362
  {
356
363
  "type": "progress-bar",
357
- "value": "@entity.usage",
358
- "max": 100
364
+ "value": "@entity.current",
365
+ "max": "@entity.max"
366
+ },
367
+ {
368
+ "type": "stack",
369
+ "direction": "horizontal",
370
+ "gap": "md",
371
+ "children": [
372
+ {
373
+ "type": "stat-display",
374
+ "label": "Tokens Used",
375
+ "value": "@entity.current"
376
+ },
377
+ {
378
+ "type": "stat-display",
379
+ "label": "Max Tokens",
380
+ "value": "@entity.max"
381
+ }
382
+ ]
359
383
  },
360
384
  {
361
385
  "type": "stack",
@@ -371,10 +395,10 @@
371
395
  },
372
396
  {
373
397
  "type": "button",
374
- "label": "Update",
375
- "event": "UPDATE_TOKENS",
376
- "variant": "secondary",
377
- "icon": "refresh-cw"
398
+ "label": "Reset",
399
+ "event": "RESET",
400
+ "variant": "ghost",
401
+ "icon": "rotate-ccw"
378
402
  }
379
403
  ]
380
404
  }
@@ -384,29 +408,23 @@
384
408
  ]
385
409
  },
386
410
  {
387
- "from": "approaching_limit",
388
- "to": "at_limit",
389
- "event": "UPDATE_TOKENS",
411
+ "from": "normal",
412
+ "to": "critical",
413
+ "event": "UPDATE",
390
414
  "guard": [
391
415
  ">=",
392
416
  [
393
417
  "/",
394
- "@entity.tokenCount",
395
- "@entity.maxTokens"
418
+ "@payload.current",
419
+ "@entity.max"
396
420
  ],
397
- 1
421
+ 0.95
398
422
  ],
399
423
  "effects": [
400
- [
401
- "agent/token-count"
402
- ],
403
- [
404
- "agent/context-usage"
405
- ],
406
424
  [
407
425
  "set",
408
- "@entity.usage",
409
- 100
426
+ "@entity.current",
427
+ "@payload.current"
410
428
  ],
411
429
  [
412
430
  "render-ui",
@@ -429,8 +447,13 @@
429
447
  },
430
448
  {
431
449
  "type": "typography",
432
- "content": "AgentContextWindow (At Limit)",
450
+ "content": "Token Usage",
433
451
  "variant": "h2"
452
+ },
453
+ {
454
+ "type": "badge",
455
+ "label": "Critical",
456
+ "variant": "destructive"
434
457
  }
435
458
  ]
436
459
  },
@@ -440,19 +463,50 @@
440
463
  {
441
464
  "type": "alert",
442
465
  "variant": "error",
443
- "message": "Context window at capacity. Compaction required."
466
+ "message": "Token usage critical. Compact immediately to avoid truncation."
444
467
  },
445
468
  {
446
469
  "type": "progress-bar",
447
- "value": 100,
448
- "max": 100
470
+ "value": "@entity.current",
471
+ "max": "@entity.max"
449
472
  },
450
473
  {
451
- "type": "button",
452
- "label": "Compact Now",
453
- "event": "COMPACT",
454
- "variant": "primary",
455
- "icon": "minimize-2"
474
+ "type": "stack",
475
+ "direction": "horizontal",
476
+ "gap": "md",
477
+ "children": [
478
+ {
479
+ "type": "stat-display",
480
+ "label": "Tokens Used",
481
+ "value": "@entity.current"
482
+ },
483
+ {
484
+ "type": "stat-display",
485
+ "label": "Max Tokens",
486
+ "value": "@entity.max"
487
+ }
488
+ ]
489
+ },
490
+ {
491
+ "type": "stack",
492
+ "direction": "horizontal",
493
+ "gap": "sm",
494
+ "children": [
495
+ {
496
+ "type": "button",
497
+ "label": "Compact Now",
498
+ "event": "COMPACT",
499
+ "variant": "primary",
500
+ "icon": "minimize-2"
501
+ },
502
+ {
503
+ "type": "button",
504
+ "label": "Reset",
505
+ "event": "RESET",
506
+ "variant": "ghost",
507
+ "icon": "rotate-ccw"
508
+ }
509
+ ]
456
510
  }
457
511
  ]
458
512
  }
@@ -460,36 +514,35 @@
460
514
  ]
461
515
  },
462
516
  {
463
- "from": "approaching_limit",
464
- "to": "normal",
465
- "event": "COMPACT",
466
- "effects": [
467
- [
468
- "agent/compact"
469
- ],
470
- [
471
- "agent/token-count"
472
- ],
517
+ "from": "warning",
518
+ "to": "warning",
519
+ "event": "UPDATE",
520
+ "guard": [
521
+ "and",
473
522
  [
474
- "agent/context-usage"
523
+ ">=",
524
+ [
525
+ "/",
526
+ "@payload.current",
527
+ "@entity.max"
528
+ ],
529
+ 0.85
475
530
  ],
476
531
  [
477
- "set",
478
- "@entity.lastCompactedAt",
479
- "@now"
480
- ],
532
+ "<",
533
+ [
534
+ "/",
535
+ "@payload.current",
536
+ "@entity.max"
537
+ ],
538
+ 0.95
539
+ ]
540
+ ],
541
+ "effects": [
481
542
  [
482
543
  "set",
483
- "@entity.usage",
484
- [
485
- "*",
486
- [
487
- "/",
488
- "@entity.tokenCount",
489
- "@entity.maxTokens"
490
- ],
491
- 100
492
- ]
544
+ "@entity.current",
545
+ "@payload.current"
493
546
  ],
494
547
  [
495
548
  "render-ui",
@@ -507,52 +560,71 @@
507
560
  "children": [
508
561
  {
509
562
  "type": "icon",
510
- "name": "layers",
563
+ "name": "alert-triangle",
511
564
  "size": "lg"
512
565
  },
513
566
  {
514
567
  "type": "typography",
515
- "content": "AgentContextWindow",
568
+ "content": "Token Usage",
516
569
  "variant": "h2"
570
+ },
571
+ {
572
+ "type": "badge",
573
+ "label": "Warning",
574
+ "variant": "warning"
517
575
  }
518
576
  ]
519
577
  },
520
578
  {
521
579
  "type": "divider"
522
580
  },
581
+ {
582
+ "type": "alert",
583
+ "variant": "warning",
584
+ "message": "Token usage approaching limit. Consider compacting."
585
+ },
586
+ {
587
+ "type": "progress-bar",
588
+ "value": "@entity.current",
589
+ "max": "@entity.max"
590
+ },
523
591
  {
524
592
  "type": "stack",
525
593
  "direction": "horizontal",
526
594
  "gap": "md",
527
595
  "children": [
528
596
  {
529
- "type": "badge",
530
- "label": "@entity.tokenCount",
531
- "variant": "default"
532
- },
533
- {
534
- "type": "typography",
535
- "variant": "caption",
536
- "content": "/"
597
+ "type": "stat-display",
598
+ "label": "Tokens Used",
599
+ "value": "@entity.current"
537
600
  },
538
601
  {
539
- "type": "badge",
540
- "label": "@entity.maxTokens",
541
- "variant": "default"
602
+ "type": "stat-display",
603
+ "label": "Max Tokens",
604
+ "value": "@entity.max"
542
605
  }
543
606
  ]
544
607
  },
545
608
  {
546
- "type": "progress-bar",
547
- "value": "@entity.usage",
548
- "max": 100
549
- },
550
- {
551
- "type": "button",
552
- "label": "Update Tokens",
553
- "event": "UPDATE_TOKENS",
554
- "variant": "secondary",
555
- "icon": "refresh-cw"
609
+ "type": "stack",
610
+ "direction": "horizontal",
611
+ "gap": "sm",
612
+ "children": [
613
+ {
614
+ "type": "button",
615
+ "label": "Compact",
616
+ "event": "COMPACT",
617
+ "variant": "primary",
618
+ "icon": "minimize-2"
619
+ },
620
+ {
621
+ "type": "button",
622
+ "label": "Reset",
623
+ "event": "RESET",
624
+ "variant": "ghost",
625
+ "icon": "rotate-ccw"
626
+ }
627
+ ]
556
628
  }
557
629
  ]
558
630
  }
@@ -560,36 +632,129 @@
560
632
  ]
561
633
  },
562
634
  {
563
- "from": "at_limit",
564
- "to": "normal",
565
- "event": "COMPACT",
566
- "effects": [
567
- [
568
- "agent/compact"
569
- ],
635
+ "from": "warning",
636
+ "to": "critical",
637
+ "event": "UPDATE",
638
+ "guard": [
639
+ ">=",
570
640
  [
571
- "agent/token-count"
641
+ "/",
642
+ "@payload.current",
643
+ "@entity.max"
572
644
  ],
645
+ 0.95
646
+ ],
647
+ "effects": [
573
648
  [
574
- "agent/context-usage"
649
+ "set",
650
+ "@entity.current",
651
+ "@payload.current"
575
652
  ],
576
653
  [
577
- "set",
578
- "@entity.lastCompactedAt",
579
- "@now"
654
+ "render-ui",
655
+ "main",
656
+ {
657
+ "type": "stack",
658
+ "direction": "vertical",
659
+ "gap": "lg",
660
+ "children": [
661
+ {
662
+ "type": "stack",
663
+ "direction": "horizontal",
664
+ "gap": "sm",
665
+ "align": "center",
666
+ "children": [
667
+ {
668
+ "type": "icon",
669
+ "name": "alert-octagon",
670
+ "size": "lg"
671
+ },
672
+ {
673
+ "type": "typography",
674
+ "content": "Token Usage",
675
+ "variant": "h2"
676
+ },
677
+ {
678
+ "type": "badge",
679
+ "label": "Critical",
680
+ "variant": "destructive"
681
+ }
682
+ ]
683
+ },
684
+ {
685
+ "type": "divider"
686
+ },
687
+ {
688
+ "type": "alert",
689
+ "variant": "error",
690
+ "message": "Token usage critical. Compact immediately to avoid truncation."
691
+ },
692
+ {
693
+ "type": "progress-bar",
694
+ "value": "@entity.current",
695
+ "max": "@entity.max"
696
+ },
697
+ {
698
+ "type": "stack",
699
+ "direction": "horizontal",
700
+ "gap": "md",
701
+ "children": [
702
+ {
703
+ "type": "stat-display",
704
+ "label": "Tokens Used",
705
+ "value": "@entity.current"
706
+ },
707
+ {
708
+ "type": "stat-display",
709
+ "label": "Max Tokens",
710
+ "value": "@entity.max"
711
+ }
712
+ ]
713
+ },
714
+ {
715
+ "type": "stack",
716
+ "direction": "horizontal",
717
+ "gap": "sm",
718
+ "children": [
719
+ {
720
+ "type": "button",
721
+ "label": "Compact Now",
722
+ "event": "COMPACT",
723
+ "variant": "primary",
724
+ "icon": "minimize-2"
725
+ },
726
+ {
727
+ "type": "button",
728
+ "label": "Reset",
729
+ "event": "RESET",
730
+ "variant": "ghost",
731
+ "icon": "rotate-ccw"
732
+ }
733
+ ]
734
+ }
735
+ ]
736
+ }
737
+ ]
738
+ ]
739
+ },
740
+ {
741
+ "from": "warning",
742
+ "to": "normal",
743
+ "event": "UPDATE",
744
+ "guard": [
745
+ "<",
746
+ [
747
+ "/",
748
+ "@payload.current",
749
+ "@entity.max"
580
750
  ],
751
+ 0.85
752
+ ],
753
+ "effects": [
581
754
  [
582
755
  "set",
583
- "@entity.usage",
584
- [
585
- "*",
586
- [
587
- "/",
588
- "@entity.tokenCount",
589
- "@entity.maxTokens"
590
- ],
591
- 100
592
- ]
756
+ "@entity.current",
757
+ "@payload.current"
593
758
  ],
594
759
  [
595
760
  "render-ui",
@@ -607,52 +772,158 @@
607
772
  "children": [
608
773
  {
609
774
  "type": "icon",
610
- "name": "layers",
775
+ "name": "gauge",
611
776
  "size": "lg"
612
777
  },
613
778
  {
614
779
  "type": "typography",
615
- "content": "AgentContextWindow",
780
+ "content": "Token Usage",
616
781
  "variant": "h2"
782
+ },
783
+ {
784
+ "type": "badge",
785
+ "label": "Normal",
786
+ "variant": "default"
617
787
  }
618
788
  ]
619
789
  },
620
790
  {
621
791
  "type": "divider"
622
792
  },
793
+ {
794
+ "type": "progress-bar",
795
+ "value": "@entity.current",
796
+ "max": "@entity.max"
797
+ },
623
798
  {
624
799
  "type": "stack",
625
800
  "direction": "horizontal",
626
801
  "gap": "md",
627
802
  "children": [
628
803
  {
629
- "type": "badge",
630
- "label": "@entity.tokenCount",
631
- "variant": "default"
804
+ "type": "stat-display",
805
+ "label": "Tokens Used",
806
+ "value": "@entity.current"
807
+ },
808
+ {
809
+ "type": "stat-display",
810
+ "label": "Max Tokens",
811
+ "value": "@entity.max"
812
+ }
813
+ ]
814
+ },
815
+ {
816
+ "type": "button",
817
+ "label": "Reset",
818
+ "event": "RESET",
819
+ "variant": "ghost",
820
+ "icon": "rotate-ccw"
821
+ }
822
+ ]
823
+ }
824
+ ]
825
+ ]
826
+ },
827
+ {
828
+ "from": "critical",
829
+ "to": "critical",
830
+ "event": "UPDATE",
831
+ "guard": [
832
+ ">=",
833
+ [
834
+ "/",
835
+ "@payload.current",
836
+ "@entity.max"
837
+ ],
838
+ 0.95
839
+ ],
840
+ "effects": [
841
+ [
842
+ "set",
843
+ "@entity.current",
844
+ "@payload.current"
845
+ ],
846
+ [
847
+ "render-ui",
848
+ "main",
849
+ {
850
+ "type": "stack",
851
+ "direction": "vertical",
852
+ "gap": "lg",
853
+ "children": [
854
+ {
855
+ "type": "stack",
856
+ "direction": "horizontal",
857
+ "gap": "sm",
858
+ "align": "center",
859
+ "children": [
860
+ {
861
+ "type": "icon",
862
+ "name": "alert-octagon",
863
+ "size": "lg"
632
864
  },
633
865
  {
634
866
  "type": "typography",
635
- "variant": "caption",
636
- "content": "/"
867
+ "content": "Token Usage",
868
+ "variant": "h2"
637
869
  },
638
870
  {
639
871
  "type": "badge",
640
- "label": "@entity.maxTokens",
641
- "variant": "default"
872
+ "label": "Critical",
873
+ "variant": "destructive"
642
874
  }
643
875
  ]
644
876
  },
877
+ {
878
+ "type": "divider"
879
+ },
880
+ {
881
+ "type": "alert",
882
+ "variant": "error",
883
+ "message": "Token usage critical. Compact immediately to avoid truncation."
884
+ },
645
885
  {
646
886
  "type": "progress-bar",
647
- "value": "@entity.usage",
648
- "max": 100
887
+ "value": "@entity.current",
888
+ "max": "@entity.max"
649
889
  },
650
890
  {
651
- "type": "button",
652
- "label": "Update Tokens",
653
- "event": "UPDATE_TOKENS",
654
- "variant": "secondary",
655
- "icon": "refresh-cw"
891
+ "type": "stack",
892
+ "direction": "horizontal",
893
+ "gap": "md",
894
+ "children": [
895
+ {
896
+ "type": "stat-display",
897
+ "label": "Tokens Used",
898
+ "value": "@entity.current"
899
+ },
900
+ {
901
+ "type": "stat-display",
902
+ "label": "Max Tokens",
903
+ "value": "@entity.max"
904
+ }
905
+ ]
906
+ },
907
+ {
908
+ "type": "stack",
909
+ "direction": "horizontal",
910
+ "gap": "sm",
911
+ "children": [
912
+ {
913
+ "type": "button",
914
+ "label": "Compact Now",
915
+ "event": "COMPACT",
916
+ "variant": "primary",
917
+ "icon": "minimize-2"
918
+ },
919
+ {
920
+ "type": "button",
921
+ "label": "Reset",
922
+ "event": "RESET",
923
+ "variant": "ghost",
924
+ "icon": "rotate-ccw"
925
+ }
926
+ ]
656
927
  }
657
928
  ]
658
929
  }
@@ -660,17 +931,17 @@
660
931
  ]
661
932
  },
662
933
  {
663
- "from": "approaching_limit",
664
- "to": "approaching_limit",
665
- "event": "UPDATE_TOKENS",
934
+ "from": "critical",
935
+ "to": "warning",
936
+ "event": "UPDATE",
666
937
  "guard": [
667
938
  "and",
668
939
  [
669
940
  ">=",
670
941
  [
671
942
  "/",
672
- "@entity.tokenCount",
673
- "@entity.maxTokens"
943
+ "@payload.current",
944
+ "@entity.max"
674
945
  ],
675
946
  0.85
676
947
  ],
@@ -678,31 +949,17 @@
678
949
  "<",
679
950
  [
680
951
  "/",
681
- "@entity.tokenCount",
682
- "@entity.maxTokens"
952
+ "@payload.current",
953
+ "@entity.max"
683
954
  ],
684
- 1
955
+ 0.95
685
956
  ]
686
957
  ],
687
958
  "effects": [
688
- [
689
- "agent/token-count"
690
- ],
691
- [
692
- "agent/context-usage"
693
- ],
694
959
  [
695
960
  "set",
696
- "@entity.usage",
697
- [
698
- "*",
699
- [
700
- "/",
701
- "@entity.tokenCount",
702
- "@entity.maxTokens"
703
- ],
704
- 100
705
- ]
961
+ "@entity.current",
962
+ "@payload.current"
706
963
  ],
707
964
  [
708
965
  "render-ui",
@@ -725,8 +982,13 @@
725
982
  },
726
983
  {
727
984
  "type": "typography",
728
- "content": "AgentContextWindow (Warning)",
985
+ "content": "Token Usage",
729
986
  "variant": "h2"
987
+ },
988
+ {
989
+ "type": "badge",
990
+ "label": "Warning",
991
+ "variant": "warning"
730
992
  }
731
993
  ]
732
994
  },
@@ -736,12 +998,29 @@
736
998
  {
737
999
  "type": "alert",
738
1000
  "variant": "warning",
739
- "message": "Context window approaching limit."
1001
+ "message": "Token usage approaching limit. Consider compacting."
740
1002
  },
741
1003
  {
742
1004
  "type": "progress-bar",
743
- "value": "@entity.usage",
744
- "max": 100
1005
+ "value": "@entity.current",
1006
+ "max": "@entity.max"
1007
+ },
1008
+ {
1009
+ "type": "stack",
1010
+ "direction": "horizontal",
1011
+ "gap": "md",
1012
+ "children": [
1013
+ {
1014
+ "type": "stat-display",
1015
+ "label": "Tokens Used",
1016
+ "value": "@entity.current"
1017
+ },
1018
+ {
1019
+ "type": "stat-display",
1020
+ "label": "Max Tokens",
1021
+ "value": "@entity.max"
1022
+ }
1023
+ ]
745
1024
  },
746
1025
  {
747
1026
  "type": "stack",
@@ -757,10 +1036,10 @@
757
1036
  },
758
1037
  {
759
1038
  "type": "button",
760
- "label": "Update",
761
- "event": "UPDATE_TOKENS",
762
- "variant": "secondary",
763
- "icon": "refresh-cw"
1039
+ "label": "Reset",
1040
+ "event": "RESET",
1041
+ "variant": "ghost",
1042
+ "icon": "rotate-ccw"
764
1043
  }
765
1044
  ]
766
1045
  }
@@ -768,23 +1047,1248 @@
768
1047
  }
769
1048
  ]
770
1049
  ]
771
- }
772
- ]
773
- }
774
- }
775
- ],
776
- "pages": [
777
- {
778
- "name": "AgentContextWindowPage",
779
- "path": "/agentcontextwindows",
780
- "traits": [
1050
+ },
1051
+ {
1052
+ "from": "critical",
1053
+ "to": "normal",
1054
+ "event": "UPDATE",
1055
+ "guard": [
1056
+ "<",
1057
+ [
1058
+ "/",
1059
+ "@payload.current",
1060
+ "@entity.max"
1061
+ ],
1062
+ 0.85
1063
+ ],
1064
+ "effects": [
1065
+ [
1066
+ "set",
1067
+ "@entity.current",
1068
+ "@payload.current"
1069
+ ],
1070
+ [
1071
+ "render-ui",
1072
+ "main",
1073
+ {
1074
+ "type": "stack",
1075
+ "direction": "vertical",
1076
+ "gap": "lg",
1077
+ "children": [
1078
+ {
1079
+ "type": "stack",
1080
+ "direction": "horizontal",
1081
+ "gap": "sm",
1082
+ "align": "center",
1083
+ "children": [
1084
+ {
1085
+ "type": "icon",
1086
+ "name": "gauge",
1087
+ "size": "lg"
1088
+ },
1089
+ {
1090
+ "type": "typography",
1091
+ "content": "Token Usage",
1092
+ "variant": "h2"
1093
+ },
1094
+ {
1095
+ "type": "badge",
1096
+ "label": "Normal",
1097
+ "variant": "default"
1098
+ }
1099
+ ]
1100
+ },
1101
+ {
1102
+ "type": "divider"
1103
+ },
1104
+ {
1105
+ "type": "progress-bar",
1106
+ "value": "@entity.current",
1107
+ "max": "@entity.max"
1108
+ },
1109
+ {
1110
+ "type": "stack",
1111
+ "direction": "horizontal",
1112
+ "gap": "md",
1113
+ "children": [
1114
+ {
1115
+ "type": "stat-display",
1116
+ "label": "Tokens Used",
1117
+ "value": "@entity.current"
1118
+ },
1119
+ {
1120
+ "type": "stat-display",
1121
+ "label": "Max Tokens",
1122
+ "value": "@entity.max"
1123
+ }
1124
+ ]
1125
+ },
1126
+ {
1127
+ "type": "button",
1128
+ "label": "Reset",
1129
+ "event": "RESET",
1130
+ "variant": "ghost",
1131
+ "icon": "rotate-ccw"
1132
+ }
1133
+ ]
1134
+ }
1135
+ ]
1136
+ ]
1137
+ },
1138
+ {
1139
+ "from": "normal",
1140
+ "to": "normal",
1141
+ "event": "COMPACT",
1142
+ "effects": [
1143
+ [
1144
+ "agent/compact"
1145
+ ],
1146
+ [
1147
+ "set",
1148
+ "@entity.lastCompactedAt",
1149
+ "@now"
1150
+ ],
1151
+ [
1152
+ "agent/token-count"
1153
+ ],
1154
+ [
1155
+ "render-ui",
1156
+ "main",
1157
+ {
1158
+ "type": "stack",
1159
+ "direction": "vertical",
1160
+ "gap": "lg",
1161
+ "children": [
1162
+ {
1163
+ "type": "stack",
1164
+ "direction": "horizontal",
1165
+ "gap": "sm",
1166
+ "align": "center",
1167
+ "children": [
1168
+ {
1169
+ "type": "icon",
1170
+ "name": "gauge",
1171
+ "size": "lg"
1172
+ },
1173
+ {
1174
+ "type": "typography",
1175
+ "content": "Token Usage",
1176
+ "variant": "h2"
1177
+ },
1178
+ {
1179
+ "type": "badge",
1180
+ "label": "Normal",
1181
+ "variant": "default"
1182
+ }
1183
+ ]
1184
+ },
1185
+ {
1186
+ "type": "divider"
1187
+ },
1188
+ {
1189
+ "type": "progress-bar",
1190
+ "value": "@entity.current",
1191
+ "max": "@entity.max"
1192
+ },
1193
+ {
1194
+ "type": "stack",
1195
+ "direction": "horizontal",
1196
+ "gap": "md",
1197
+ "children": [
1198
+ {
1199
+ "type": "stat-display",
1200
+ "label": "Tokens Used",
1201
+ "value": "@entity.current"
1202
+ },
1203
+ {
1204
+ "type": "stat-display",
1205
+ "label": "Max Tokens",
1206
+ "value": "@entity.max"
1207
+ }
1208
+ ]
1209
+ },
1210
+ {
1211
+ "type": "button",
1212
+ "label": "Reset",
1213
+ "event": "RESET",
1214
+ "variant": "ghost",
1215
+ "icon": "rotate-ccw"
1216
+ }
1217
+ ]
1218
+ }
1219
+ ]
1220
+ ]
1221
+ },
1222
+ {
1223
+ "from": "warning",
1224
+ "to": "normal",
1225
+ "event": "COMPACT",
1226
+ "effects": [
1227
+ [
1228
+ "agent/compact"
1229
+ ],
1230
+ [
1231
+ "set",
1232
+ "@entity.lastCompactedAt",
1233
+ "@now"
1234
+ ],
1235
+ [
1236
+ "agent/token-count"
1237
+ ],
1238
+ [
1239
+ "render-ui",
1240
+ "main",
1241
+ {
1242
+ "type": "stack",
1243
+ "direction": "vertical",
1244
+ "gap": "lg",
1245
+ "children": [
1246
+ {
1247
+ "type": "stack",
1248
+ "direction": "horizontal",
1249
+ "gap": "sm",
1250
+ "align": "center",
1251
+ "children": [
1252
+ {
1253
+ "type": "icon",
1254
+ "name": "gauge",
1255
+ "size": "lg"
1256
+ },
1257
+ {
1258
+ "type": "typography",
1259
+ "content": "Token Usage",
1260
+ "variant": "h2"
1261
+ },
1262
+ {
1263
+ "type": "badge",
1264
+ "label": "Normal",
1265
+ "variant": "default"
1266
+ }
1267
+ ]
1268
+ },
1269
+ {
1270
+ "type": "divider"
1271
+ },
1272
+ {
1273
+ "type": "progress-bar",
1274
+ "value": "@entity.current",
1275
+ "max": "@entity.max"
1276
+ },
1277
+ {
1278
+ "type": "stack",
1279
+ "direction": "horizontal",
1280
+ "gap": "md",
1281
+ "children": [
1282
+ {
1283
+ "type": "stat-display",
1284
+ "label": "Tokens Used",
1285
+ "value": "@entity.current"
1286
+ },
1287
+ {
1288
+ "type": "stat-display",
1289
+ "label": "Max Tokens",
1290
+ "value": "@entity.max"
1291
+ }
1292
+ ]
1293
+ },
1294
+ {
1295
+ "type": "button",
1296
+ "label": "Reset",
1297
+ "event": "RESET",
1298
+ "variant": "ghost",
1299
+ "icon": "rotate-ccw"
1300
+ }
1301
+ ]
1302
+ }
1303
+ ]
1304
+ ]
1305
+ },
1306
+ {
1307
+ "from": "critical",
1308
+ "to": "normal",
1309
+ "event": "COMPACT",
1310
+ "effects": [
1311
+ [
1312
+ "agent/compact"
1313
+ ],
1314
+ [
1315
+ "set",
1316
+ "@entity.lastCompactedAt",
1317
+ "@now"
1318
+ ],
1319
+ [
1320
+ "agent/token-count"
1321
+ ],
1322
+ [
1323
+ "render-ui",
1324
+ "main",
1325
+ {
1326
+ "type": "stack",
1327
+ "direction": "vertical",
1328
+ "gap": "lg",
1329
+ "children": [
1330
+ {
1331
+ "type": "stack",
1332
+ "direction": "horizontal",
1333
+ "gap": "sm",
1334
+ "align": "center",
1335
+ "children": [
1336
+ {
1337
+ "type": "icon",
1338
+ "name": "gauge",
1339
+ "size": "lg"
1340
+ },
1341
+ {
1342
+ "type": "typography",
1343
+ "content": "Token Usage",
1344
+ "variant": "h2"
1345
+ },
1346
+ {
1347
+ "type": "badge",
1348
+ "label": "Normal",
1349
+ "variant": "default"
1350
+ }
1351
+ ]
1352
+ },
1353
+ {
1354
+ "type": "divider"
1355
+ },
1356
+ {
1357
+ "type": "progress-bar",
1358
+ "value": "@entity.current",
1359
+ "max": "@entity.max"
1360
+ },
1361
+ {
1362
+ "type": "stack",
1363
+ "direction": "horizontal",
1364
+ "gap": "md",
1365
+ "children": [
1366
+ {
1367
+ "type": "stat-display",
1368
+ "label": "Tokens Used",
1369
+ "value": "@entity.current"
1370
+ },
1371
+ {
1372
+ "type": "stat-display",
1373
+ "label": "Max Tokens",
1374
+ "value": "@entity.max"
1375
+ }
1376
+ ]
1377
+ },
1378
+ {
1379
+ "type": "button",
1380
+ "label": "Reset",
1381
+ "event": "RESET",
1382
+ "variant": "ghost",
1383
+ "icon": "rotate-ccw"
1384
+ }
1385
+ ]
1386
+ }
1387
+ ]
1388
+ ]
1389
+ },
1390
+ {
1391
+ "from": "normal",
1392
+ "to": "normal",
1393
+ "event": "RESET",
1394
+ "effects": [
1395
+ [
1396
+ "set",
1397
+ "@entity.current",
1398
+ 0
1399
+ ],
1400
+ [
1401
+ "render-ui",
1402
+ "main",
1403
+ {
1404
+ "type": "stack",
1405
+ "direction": "vertical",
1406
+ "gap": "lg",
1407
+ "children": [
1408
+ {
1409
+ "type": "stack",
1410
+ "direction": "horizontal",
1411
+ "gap": "sm",
1412
+ "align": "center",
1413
+ "children": [
1414
+ {
1415
+ "type": "icon",
1416
+ "name": "gauge",
1417
+ "size": "lg"
1418
+ },
1419
+ {
1420
+ "type": "typography",
1421
+ "content": "Token Usage",
1422
+ "variant": "h2"
1423
+ },
1424
+ {
1425
+ "type": "badge",
1426
+ "label": "Normal",
1427
+ "variant": "default"
1428
+ }
1429
+ ]
1430
+ },
1431
+ {
1432
+ "type": "divider"
1433
+ },
1434
+ {
1435
+ "type": "progress-bar",
1436
+ "value": "@entity.current",
1437
+ "max": "@entity.max"
1438
+ },
1439
+ {
1440
+ "type": "stack",
1441
+ "direction": "horizontal",
1442
+ "gap": "md",
1443
+ "children": [
1444
+ {
1445
+ "type": "stat-display",
1446
+ "label": "Tokens Used",
1447
+ "value": "@entity.current"
1448
+ },
1449
+ {
1450
+ "type": "stat-display",
1451
+ "label": "Max Tokens",
1452
+ "value": "@entity.max"
1453
+ }
1454
+ ]
1455
+ },
1456
+ {
1457
+ "type": "button",
1458
+ "label": "Reset",
1459
+ "event": "RESET",
1460
+ "variant": "ghost",
1461
+ "icon": "rotate-ccw"
1462
+ }
1463
+ ]
1464
+ }
1465
+ ]
1466
+ ]
1467
+ },
1468
+ {
1469
+ "from": "warning",
1470
+ "to": "normal",
1471
+ "event": "RESET",
1472
+ "effects": [
1473
+ [
1474
+ "set",
1475
+ "@entity.current",
1476
+ 0
1477
+ ],
1478
+ [
1479
+ "render-ui",
1480
+ "main",
1481
+ {
1482
+ "type": "stack",
1483
+ "direction": "vertical",
1484
+ "gap": "lg",
1485
+ "children": [
1486
+ {
1487
+ "type": "stack",
1488
+ "direction": "horizontal",
1489
+ "gap": "sm",
1490
+ "align": "center",
1491
+ "children": [
1492
+ {
1493
+ "type": "icon",
1494
+ "name": "gauge",
1495
+ "size": "lg"
1496
+ },
1497
+ {
1498
+ "type": "typography",
1499
+ "content": "Token Usage",
1500
+ "variant": "h2"
1501
+ },
1502
+ {
1503
+ "type": "badge",
1504
+ "label": "Normal",
1505
+ "variant": "default"
1506
+ }
1507
+ ]
1508
+ },
1509
+ {
1510
+ "type": "divider"
1511
+ },
1512
+ {
1513
+ "type": "progress-bar",
1514
+ "value": "@entity.current",
1515
+ "max": "@entity.max"
1516
+ },
1517
+ {
1518
+ "type": "stack",
1519
+ "direction": "horizontal",
1520
+ "gap": "md",
1521
+ "children": [
1522
+ {
1523
+ "type": "stat-display",
1524
+ "label": "Tokens Used",
1525
+ "value": "@entity.current"
1526
+ },
1527
+ {
1528
+ "type": "stat-display",
1529
+ "label": "Max Tokens",
1530
+ "value": "@entity.max"
1531
+ }
1532
+ ]
1533
+ },
1534
+ {
1535
+ "type": "button",
1536
+ "label": "Reset",
1537
+ "event": "RESET",
1538
+ "variant": "ghost",
1539
+ "icon": "rotate-ccw"
1540
+ }
1541
+ ]
1542
+ }
1543
+ ]
1544
+ ]
1545
+ },
1546
+ {
1547
+ "from": "critical",
1548
+ "to": "normal",
1549
+ "event": "RESET",
1550
+ "effects": [
1551
+ [
1552
+ "set",
1553
+ "@entity.current",
1554
+ 0
1555
+ ],
1556
+ [
1557
+ "render-ui",
1558
+ "main",
1559
+ {
1560
+ "type": "stack",
1561
+ "direction": "vertical",
1562
+ "gap": "lg",
1563
+ "children": [
1564
+ {
1565
+ "type": "stack",
1566
+ "direction": "horizontal",
1567
+ "gap": "sm",
1568
+ "align": "center",
1569
+ "children": [
1570
+ {
1571
+ "type": "icon",
1572
+ "name": "gauge",
1573
+ "size": "lg"
1574
+ },
1575
+ {
1576
+ "type": "typography",
1577
+ "content": "Token Usage",
1578
+ "variant": "h2"
1579
+ },
1580
+ {
1581
+ "type": "badge",
1582
+ "label": "Normal",
1583
+ "variant": "default"
1584
+ }
1585
+ ]
1586
+ },
1587
+ {
1588
+ "type": "divider"
1589
+ },
1590
+ {
1591
+ "type": "progress-bar",
1592
+ "value": "@entity.current",
1593
+ "max": "@entity.max"
1594
+ },
1595
+ {
1596
+ "type": "stack",
1597
+ "direction": "horizontal",
1598
+ "gap": "md",
1599
+ "children": [
1600
+ {
1601
+ "type": "stat-display",
1602
+ "label": "Tokens Used",
1603
+ "value": "@entity.current"
1604
+ },
1605
+ {
1606
+ "type": "stat-display",
1607
+ "label": "Max Tokens",
1608
+ "value": "@entity.max"
1609
+ }
1610
+ ]
1611
+ },
1612
+ {
1613
+ "type": "button",
1614
+ "label": "Reset",
1615
+ "event": "RESET",
1616
+ "variant": "ghost",
1617
+ "icon": "rotate-ccw"
1618
+ }
1619
+ ]
1620
+ }
1621
+ ]
1622
+ ]
1623
+ }
1624
+ ]
1625
+ }
1626
+ },
1627
+ {
1628
+ "name": "AgentContextWindowNotification",
1629
+ "linkedEntity": "AgentContextWindow",
1630
+ "category": "interaction",
1631
+ "stateMachine": {
1632
+ "states": [
1633
+ {
1634
+ "name": "hidden",
1635
+ "isInitial": true
1636
+ },
1637
+ {
1638
+ "name": "visible"
1639
+ }
1640
+ ],
1641
+ "events": [
1642
+ {
1643
+ "key": "INIT",
1644
+ "name": "Initialize"
1645
+ },
1646
+ {
1647
+ "key": "SHOW",
1648
+ "name": "Show Notification",
1649
+ "payload": [
1650
+ {
1651
+ "name": "message",
1652
+ "type": "string",
1653
+ "required": true
1654
+ },
1655
+ {
1656
+ "name": "notificationType",
1657
+ "type": "string"
1658
+ }
1659
+ ]
1660
+ },
1661
+ {
1662
+ "key": "HIDE",
1663
+ "name": "Hide Notification"
1664
+ }
1665
+ ],
1666
+ "transitions": [
1667
+ {
1668
+ "from": "hidden",
1669
+ "to": "hidden",
1670
+ "event": "INIT",
1671
+ "effects": [
1672
+ [
1673
+ "fetch",
1674
+ "AgentContextWindow"
1675
+ ]
1676
+ ]
1677
+ },
1678
+ {
1679
+ "from": "hidden",
1680
+ "to": "visible",
1681
+ "event": "SHOW",
1682
+ "effects": [
1683
+ [
1684
+ "set",
1685
+ "@entity.message",
1686
+ "@payload.message"
1687
+ ],
1688
+ [
1689
+ "set",
1690
+ "@entity.notificationType",
1691
+ "@payload.notificationType"
1692
+ ],
1693
+ [
1694
+ "render-ui",
1695
+ "main",
1696
+ {
1697
+ "type": "stack",
1698
+ "direction": "vertical",
1699
+ "gap": "lg",
1700
+ "children": [
1701
+ {
1702
+ "type": "stack",
1703
+ "direction": "horizontal",
1704
+ "gap": "md",
1705
+ "justify": "space-between",
1706
+ "align": "center",
1707
+ "children": [
1708
+ {
1709
+ "type": "stack",
1710
+ "direction": "horizontal",
1711
+ "gap": "md",
1712
+ "align": "center",
1713
+ "children": [
1714
+ {
1715
+ "type": "icon",
1716
+ "name": "layers",
1717
+ "size": "lg"
1718
+ },
1719
+ {
1720
+ "type": "typography",
1721
+ "content": "Context Window Alert",
1722
+ "variant": "h2"
1723
+ }
1724
+ ]
1725
+ },
1726
+ {
1727
+ "type": "button",
1728
+ "label": "Dismiss",
1729
+ "event": "HIDE",
1730
+ "variant": "ghost",
1731
+ "icon": "x"
1732
+ }
1733
+ ]
1734
+ },
1735
+ {
1736
+ "type": "divider"
1737
+ },
1738
+ {
1739
+ "type": "alert",
1740
+ "variant": [
1741
+ "object/get",
1742
+ [
1743
+ "array/first",
1744
+ "@entity"
1745
+ ],
1746
+ "notificationType"
1747
+ ],
1748
+ "message": [
1749
+ "object/get",
1750
+ [
1751
+ "array/first",
1752
+ "@entity"
1753
+ ],
1754
+ "message"
1755
+ ]
1756
+ },
1757
+ {
1758
+ "type": "toast-slot",
1759
+ "position": "top-right"
1760
+ },
1761
+ {
1762
+ "type": "violation-alert",
1763
+ "severity": "warning",
1764
+ "message": [
1765
+ "object/get",
1766
+ [
1767
+ "array/first",
1768
+ "@entity"
1769
+ ],
1770
+ "message"
1771
+ ],
1772
+ "category": "compliance"
1773
+ }
1774
+ ]
1775
+ }
1776
+ ]
1777
+ ]
1778
+ },
1779
+ {
1780
+ "from": "visible",
1781
+ "to": "visible",
1782
+ "event": "SHOW",
1783
+ "effects": [
1784
+ [
1785
+ "set",
1786
+ "@entity.message",
1787
+ "@payload.message"
1788
+ ],
1789
+ [
1790
+ "set",
1791
+ "@entity.notificationType",
1792
+ "@payload.notificationType"
1793
+ ],
1794
+ [
1795
+ "render-ui",
1796
+ "main",
1797
+ {
1798
+ "type": "stack",
1799
+ "direction": "vertical",
1800
+ "gap": "lg",
1801
+ "children": [
1802
+ {
1803
+ "type": "stack",
1804
+ "direction": "horizontal",
1805
+ "gap": "md",
1806
+ "justify": "space-between",
1807
+ "align": "center",
1808
+ "children": [
1809
+ {
1810
+ "type": "stack",
1811
+ "direction": "horizontal",
1812
+ "gap": "md",
1813
+ "align": "center",
1814
+ "children": [
1815
+ {
1816
+ "type": "icon",
1817
+ "name": "layers",
1818
+ "size": "lg"
1819
+ },
1820
+ {
1821
+ "type": "typography",
1822
+ "content": "Context Window Alert",
1823
+ "variant": "h2"
1824
+ }
1825
+ ]
1826
+ },
1827
+ {
1828
+ "type": "button",
1829
+ "label": "Dismiss",
1830
+ "event": "HIDE",
1831
+ "variant": "ghost",
1832
+ "icon": "x"
1833
+ }
1834
+ ]
1835
+ },
1836
+ {
1837
+ "type": "divider"
1838
+ },
1839
+ {
1840
+ "type": "alert",
1841
+ "variant": [
1842
+ "object/get",
1843
+ [
1844
+ "array/first",
1845
+ "@entity"
1846
+ ],
1847
+ "notificationType"
1848
+ ],
1849
+ "message": [
1850
+ "object/get",
1851
+ [
1852
+ "array/first",
1853
+ "@entity"
1854
+ ],
1855
+ "message"
1856
+ ]
1857
+ },
1858
+ {
1859
+ "type": "toast-slot",
1860
+ "position": "top-right"
1861
+ },
1862
+ {
1863
+ "type": "violation-alert",
1864
+ "severity": "warning",
1865
+ "message": [
1866
+ "object/get",
1867
+ [
1868
+ "array/first",
1869
+ "@entity"
1870
+ ],
1871
+ "message"
1872
+ ],
1873
+ "category": "compliance"
1874
+ }
1875
+ ]
1876
+ }
1877
+ ]
1878
+ ]
1879
+ },
1880
+ {
1881
+ "from": "visible",
1882
+ "to": "hidden",
1883
+ "event": "HIDE",
1884
+ "effects": [
1885
+ [
1886
+ "set",
1887
+ "@entity.message",
1888
+ ""
1889
+ ]
1890
+ ]
1891
+ }
1892
+ ]
1893
+ }
1894
+ },
1895
+ {
1896
+ "name": "AgentContextWindowAgent",
1897
+ "linkedEntity": "AgentContextWindow",
1898
+ "category": "interaction",
1899
+ "emits": [
1900
+ {
1901
+ "event": "SHOW",
1902
+ "scope": "internal",
1903
+ "payload": [
1904
+ {
1905
+ "name": "tokenCount",
1906
+ "type": "number"
1907
+ },
1908
+ {
1909
+ "name": "usage",
1910
+ "type": "number"
1911
+ }
1912
+ ]
1913
+ },
1914
+ {
1915
+ "event": "UPDATE",
1916
+ "scope": "internal",
1917
+ "payload": [
1918
+ {
1919
+ "name": "current",
1920
+ "type": "number"
1921
+ },
1922
+ {
1923
+ "name": "max",
1924
+ "type": "number"
1925
+ }
1926
+ ]
1927
+ }
1928
+ ],
1929
+ "stateMachine": {
1930
+ "states": [
1931
+ {
1932
+ "name": "normal",
1933
+ "isInitial": true
1934
+ },
1935
+ {
1936
+ "name": "approaching_limit"
1937
+ },
1938
+ {
1939
+ "name": "at_limit"
1940
+ }
1941
+ ],
1942
+ "events": [
1943
+ {
1944
+ "key": "INIT",
1945
+ "name": "Initialize"
1946
+ },
1947
+ {
1948
+ "key": "UPDATE_TOKENS",
1949
+ "name": "Update Token Count"
1950
+ },
1951
+ {
1952
+ "key": "COMPACT",
1953
+ "name": "Compact Context"
1954
+ }
1955
+ ],
1956
+ "transitions": [
1957
+ {
1958
+ "from": "normal",
1959
+ "to": "normal",
1960
+ "event": "INIT",
1961
+ "effects": [
1962
+ [
1963
+ "fetch",
1964
+ "AgentContextWindow"
1965
+ ],
1966
+ [
1967
+ "agent/token-count"
1968
+ ],
1969
+ [
1970
+ "agent/context-usage"
1971
+ ],
1972
+ [
1973
+ "render-ui",
1974
+ "main",
1975
+ {
1976
+ "type": "empty-state",
1977
+ "icon": "layers",
1978
+ "title": "Context Window",
1979
+ "description": "Context Window is ready"
1980
+ }
1981
+ ]
1982
+ ]
1983
+ },
1984
+ {
1985
+ "from": "normal",
1986
+ "to": "normal",
1987
+ "event": "UPDATE_TOKENS",
1988
+ "guard": [
1989
+ "<",
1990
+ [
1991
+ "/",
1992
+ "@entity.tokenCount",
1993
+ "@entity.maxTokens"
1994
+ ],
1995
+ 0.85
1996
+ ],
1997
+ "effects": [
1998
+ [
1999
+ "agent/token-count"
2000
+ ],
2001
+ [
2002
+ "agent/context-usage"
2003
+ ],
2004
+ [
2005
+ "set",
2006
+ "@entity.usage",
2007
+ [
2008
+ "*",
2009
+ [
2010
+ "/",
2011
+ "@entity.tokenCount",
2012
+ "@entity.maxTokens"
2013
+ ],
2014
+ 100
2015
+ ]
2016
+ ],
2017
+ [
2018
+ "set",
2019
+ "@entity.current",
2020
+ "@entity.tokenCount"
2021
+ ],
2022
+ [
2023
+ "emit",
2024
+ "UPDATE"
2025
+ ]
2026
+ ]
2027
+ },
2028
+ {
2029
+ "from": "normal",
2030
+ "to": "approaching_limit",
2031
+ "event": "UPDATE_TOKENS",
2032
+ "guard": [
2033
+ "and",
2034
+ [
2035
+ ">=",
2036
+ [
2037
+ "/",
2038
+ "@entity.tokenCount",
2039
+ "@entity.maxTokens"
2040
+ ],
2041
+ 0.85
2042
+ ],
2043
+ [
2044
+ "<",
2045
+ [
2046
+ "/",
2047
+ "@entity.tokenCount",
2048
+ "@entity.maxTokens"
2049
+ ],
2050
+ 1
2051
+ ]
2052
+ ],
2053
+ "effects": [
2054
+ [
2055
+ "agent/token-count"
2056
+ ],
2057
+ [
2058
+ "agent/context-usage"
2059
+ ],
2060
+ [
2061
+ "set",
2062
+ "@entity.usage",
2063
+ [
2064
+ "*",
2065
+ [
2066
+ "/",
2067
+ "@entity.tokenCount",
2068
+ "@entity.maxTokens"
2069
+ ],
2070
+ 100
2071
+ ]
2072
+ ],
2073
+ [
2074
+ "set",
2075
+ "@entity.current",
2076
+ "@entity.tokenCount"
2077
+ ],
2078
+ [
2079
+ "emit",
2080
+ "UPDATE"
2081
+ ],
2082
+ [
2083
+ "emit",
2084
+ "SHOW"
2085
+ ]
2086
+ ]
2087
+ },
2088
+ {
2089
+ "from": "approaching_limit",
2090
+ "to": "at_limit",
2091
+ "event": "UPDATE_TOKENS",
2092
+ "guard": [
2093
+ ">=",
2094
+ [
2095
+ "/",
2096
+ "@entity.tokenCount",
2097
+ "@entity.maxTokens"
2098
+ ],
2099
+ 1
2100
+ ],
2101
+ "effects": [
2102
+ [
2103
+ "agent/token-count"
2104
+ ],
2105
+ [
2106
+ "agent/context-usage"
2107
+ ],
2108
+ [
2109
+ "set",
2110
+ "@entity.usage",
2111
+ 100
2112
+ ],
2113
+ [
2114
+ "set",
2115
+ "@entity.current",
2116
+ "@entity.tokenCount"
2117
+ ],
2118
+ [
2119
+ "emit",
2120
+ "UPDATE"
2121
+ ],
2122
+ [
2123
+ "emit",
2124
+ "SHOW"
2125
+ ]
2126
+ ]
2127
+ },
2128
+ {
2129
+ "from": "approaching_limit",
2130
+ "to": "normal",
2131
+ "event": "COMPACT",
2132
+ "effects": [
2133
+ [
2134
+ "agent/compact"
2135
+ ],
2136
+ [
2137
+ "agent/token-count"
2138
+ ],
2139
+ [
2140
+ "agent/context-usage"
2141
+ ],
2142
+ [
2143
+ "set",
2144
+ "@entity.lastCompactedAt",
2145
+ "@now"
2146
+ ],
2147
+ [
2148
+ "set",
2149
+ "@entity.usage",
2150
+ [
2151
+ "*",
2152
+ [
2153
+ "/",
2154
+ "@entity.tokenCount",
2155
+ "@entity.maxTokens"
2156
+ ],
2157
+ 100
2158
+ ]
2159
+ ],
2160
+ [
2161
+ "set",
2162
+ "@entity.current",
2163
+ "@entity.tokenCount"
2164
+ ],
2165
+ [
2166
+ "emit",
2167
+ "UPDATE"
2168
+ ]
2169
+ ]
2170
+ },
2171
+ {
2172
+ "from": "at_limit",
2173
+ "to": "normal",
2174
+ "event": "COMPACT",
2175
+ "effects": [
2176
+ [
2177
+ "agent/compact"
2178
+ ],
2179
+ [
2180
+ "agent/token-count"
2181
+ ],
2182
+ [
2183
+ "agent/context-usage"
2184
+ ],
2185
+ [
2186
+ "set",
2187
+ "@entity.lastCompactedAt",
2188
+ "@now"
2189
+ ],
2190
+ [
2191
+ "set",
2192
+ "@entity.usage",
2193
+ [
2194
+ "*",
2195
+ [
2196
+ "/",
2197
+ "@entity.tokenCount",
2198
+ "@entity.maxTokens"
2199
+ ],
2200
+ 100
2201
+ ]
2202
+ ],
2203
+ [
2204
+ "set",
2205
+ "@entity.current",
2206
+ "@entity.tokenCount"
2207
+ ],
2208
+ [
2209
+ "emit",
2210
+ "UPDATE"
2211
+ ]
2212
+ ]
2213
+ },
2214
+ {
2215
+ "from": "approaching_limit",
2216
+ "to": "approaching_limit",
2217
+ "event": "UPDATE_TOKENS",
2218
+ "guard": [
2219
+ "and",
2220
+ [
2221
+ ">=",
2222
+ [
2223
+ "/",
2224
+ "@entity.tokenCount",
2225
+ "@entity.maxTokens"
2226
+ ],
2227
+ 0.85
2228
+ ],
2229
+ [
2230
+ "<",
2231
+ [
2232
+ "/",
2233
+ "@entity.tokenCount",
2234
+ "@entity.maxTokens"
2235
+ ],
2236
+ 1
2237
+ ]
2238
+ ],
2239
+ "effects": [
2240
+ [
2241
+ "agent/token-count"
2242
+ ],
2243
+ [
2244
+ "agent/context-usage"
2245
+ ],
2246
+ [
2247
+ "set",
2248
+ "@entity.usage",
2249
+ [
2250
+ "*",
2251
+ [
2252
+ "/",
2253
+ "@entity.tokenCount",
2254
+ "@entity.maxTokens"
2255
+ ],
2256
+ 100
2257
+ ]
2258
+ ],
2259
+ [
2260
+ "set",
2261
+ "@entity.current",
2262
+ "@entity.tokenCount"
2263
+ ],
2264
+ [
2265
+ "emit",
2266
+ "UPDATE"
2267
+ ]
2268
+ ]
2269
+ }
2270
+ ]
2271
+ }
2272
+ }
2273
+ ],
2274
+ "pages": [
2275
+ {
2276
+ "name": "AgentContextWindowPage",
2277
+ "path": "/agentcontextwindows",
2278
+ "traits": [
2279
+ {
2280
+ "ref": "AgentContextWindowGauge"
2281
+ },
2282
+ {
2283
+ "ref": "AgentContextWindowNotification"
2284
+ },
781
2285
  {
782
- "ref": "AgentContextWindowManager"
2286
+ "ref": "AgentContextWindowAgent"
783
2287
  }
784
2288
  ]
785
2289
  }
786
2290
  ]
787
2291
  }
788
2292
  ],
789
- "description": "Context window management atom for agent token tracking. Monitors token usage and auto-compacts when approaching limits. States: normal -> approaching_limit -> at_limit with guards on thresholds."
2293
+ "description": "Context window management atom for agent token tracking. Composes UI atoms (stdAgentTokenGauge for visual display, stdNotification for threshold alerts) with an agent trait that handles agent/compact, agent/token-count, and agent/context-usage."
790
2294
  }