@almadar/ui 2.46.1 → 2.47.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.
@@ -866,6 +866,67 @@ function useDeepAgentGeneration() {
866
866
  submitInterruptDecisions
867
867
  };
868
868
  }
869
+
870
+ // lib/logger.ts
871
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
872
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
873
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
874
+ function getViteEnv(key) {
875
+ try {
876
+ const meta = import.meta;
877
+ return meta?.env?.[key];
878
+ } catch {
879
+ return void 0;
880
+ }
881
+ }
882
+ function envGet(key, viteKey) {
883
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
884
+ }
885
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
886
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
887
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
888
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
889
+ function matchesNamespace(namespace) {
890
+ if (DEBUG_FILTER.length === 0) return true;
891
+ return DEBUG_FILTER.some((pattern) => {
892
+ if (pattern === "*" || pattern === "almadar:*") return true;
893
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
894
+ return namespace === pattern;
895
+ });
896
+ }
897
+ function createLogger(namespace) {
898
+ const nsAllowed = matchesNamespace(namespace);
899
+ const log2 = (level, message, data, correlationId) => {
900
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
901
+ if (level === "DEBUG" && !nsAllowed) return;
902
+ const prefix = `[${namespace}]`;
903
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
904
+ switch (level) {
905
+ case "DEBUG":
906
+ console.debug(prefix, message, logData ?? "");
907
+ break;
908
+ case "INFO":
909
+ console.info(prefix, message, logData ?? "");
910
+ break;
911
+ case "WARN":
912
+ console.warn(prefix, message, logData ?? "");
913
+ break;
914
+ case "ERROR":
915
+ console.error(prefix, message, logData ?? "");
916
+ break;
917
+ }
918
+ };
919
+ return {
920
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
921
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
922
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
923
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
924
+ };
925
+ }
926
+
927
+ // hooks/useEventBus.ts
928
+ var log = createLogger("almadar:eventbus");
929
+ var subLog = createLogger("almadar:eventbus:subscribe");
869
930
  function getGlobalEventBus() {
870
931
  if (typeof window !== "undefined") {
871
932
  return window.__kflowEventBus ?? null;
@@ -882,6 +943,7 @@ var fallbackEventBus = {
882
943
  timestamp: Date.now()
883
944
  };
884
945
  const handlers = fallbackListeners.get(type);
946
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
885
947
  if (handlers) {
886
948
  handlers.forEach((handler) => {
887
949
  try {
@@ -904,6 +966,7 @@ var fallbackEventBus = {
904
966
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
905
967
  }
906
968
  fallbackListeners.get(type).add(listener);
969
+ subLog.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
907
970
  return () => {
908
971
  const handlers = fallbackListeners.get(type);
909
972
  if (handlers) {
@@ -927,6 +990,7 @@ var fallbackEventBus = {
927
990
  },
928
991
  onAny: (listener) => {
929
992
  fallbackAnyListeners.add(listener);
993
+ subLog.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
930
994
  return () => {
931
995
  fallbackAnyListeners.delete(listener);
932
996
  };
@@ -1106,31 +1170,7 @@ function useUISlotManager() {
1106
1170
  var SelectionContext = createContext(null);
1107
1171
 
1108
1172
  // hooks/useUIEvents.ts
1109
- var UI_EVENT_MAP = {
1110
- // Form/CRUD events
1111
- "UI:SAVE": "SAVE",
1112
- "UI:CANCEL": "CANCEL",
1113
- "UI:CLOSE": "CLOSE",
1114
- "UI:VIEW": "VIEW",
1115
- "UI:EDIT": "EDIT",
1116
- "UI:DELETE": "DELETE",
1117
- "UI:CREATE": "CREATE",
1118
- "UI:SELECT": "SELECT",
1119
- "UI:DESELECT": "DESELECT",
1120
- "UI:SUBMIT": "SAVE",
1121
- "UI:UPDATE_STATUS": "UPDATE_STATUS",
1122
- "UI:SEARCH": "SEARCH",
1123
- "UI:CLEAR_SEARCH": "CLEAR_SEARCH",
1124
- "UI:ADD": "CREATE",
1125
- // Game events (for closed circuit with GameMenu, GamePauseOverlay, GameOverScreen)
1126
- "UI:PAUSE": "PAUSE",
1127
- "UI:RESUME": "RESUME",
1128
- "UI:RESTART": "RESTART",
1129
- "UI:GAME_OVER": "GAME_OVER",
1130
- "UI:START": "START",
1131
- "UI:QUIT": "QUIT",
1132
- "UI:INIT": "INIT"
1133
- };
1173
+ var UI_PREFIX = "UI:";
1134
1174
  function useUIEvents(dispatch, validEvents, eventBusInstance) {
1135
1175
  const defaultEventBus = useEventBus();
1136
1176
  const eventBus = eventBusInstance ?? defaultEventBus;
@@ -1142,15 +1182,18 @@ function useUIEvents(dispatch, validEvents, eventBusInstance) {
1142
1182
  );
1143
1183
  useEffect(() => {
1144
1184
  const unsubscribes = [];
1145
- Object.entries(UI_EVENT_MAP).forEach(([uiEvent, smEvent]) => {
1146
- const handler = (event) => {
1147
- if (!stableValidEvents || stableValidEvents.includes(smEvent)) {
1185
+ if (stableValidEvents) {
1186
+ for (const smEvent of stableValidEvents) {
1187
+ const prefixedHandler = (event) => {
1148
1188
  dispatch(smEvent, event.payload);
1149
- }
1150
- };
1151
- const unsubscribe = eventBus.on(uiEvent, handler);
1152
- unsubscribes.push(unsubscribe);
1153
- });
1189
+ };
1190
+ unsubscribes.push(eventBus.on(`${UI_PREFIX}${smEvent}`, prefixedHandler));
1191
+ const directHandler = (event) => {
1192
+ dispatch(smEvent, event.payload);
1193
+ };
1194
+ unsubscribes.push(eventBus.on(smEvent, directHandler));
1195
+ }
1196
+ }
1154
1197
  const genericHandler = (event) => {
1155
1198
  const eventName = event.payload?.event;
1156
1199
  if (eventName) {
@@ -1160,30 +1203,11 @@ function useUIEvents(dispatch, validEvents, eventBusInstance) {
1160
1203
  }
1161
1204
  }
1162
1205
  };
1163
- const genericUnsubscribe = eventBus.on("UI:DISPATCH", genericHandler);
1164
- unsubscribes.push(genericUnsubscribe);
1165
- if (stableValidEvents) {
1166
- stableValidEvents.forEach((smEvent) => {
1167
- const uiPrefixedEvent = `UI:${smEvent}`;
1168
- const alreadyMapped = Object.keys(UI_EVENT_MAP).includes(uiPrefixedEvent);
1169
- if (!alreadyMapped) {
1170
- const directHandler = (event) => {
1171
- dispatch(smEvent, event.payload);
1172
- };
1173
- const unsubscribePrefixed = eventBus.on(
1174
- uiPrefixedEvent,
1175
- directHandler
1176
- );
1177
- unsubscribes.push(unsubscribePrefixed);
1178
- const unsubscribeDirect = eventBus.on(smEvent, directHandler);
1179
- unsubscribes.push(unsubscribeDirect);
1180
- }
1181
- });
1182
- }
1206
+ unsubscribes.push(eventBus.on(`${UI_PREFIX}DISPATCH`, genericHandler));
1183
1207
  return () => {
1184
- unsubscribes.forEach((unsub) => {
1208
+ for (const unsub of unsubscribes) {
1185
1209
  if (typeof unsub === "function") unsub();
1186
- });
1210
+ }
1187
1211
  };
1188
1212
  }, [eventBus, dispatch, stableValidEvents]);
1189
1213
  }
@@ -1605,21 +1629,21 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1605
1629
  update: options?.events?.update || ENTITY_EVENTS.UPDATE,
1606
1630
  delete: options?.events?.delete || ENTITY_EVENTS.DELETE
1607
1631
  };
1608
- const log = (message, data) => {
1632
+ const log2 = (message, data) => {
1609
1633
  if (options?.debug) {
1610
1634
  console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
1611
1635
  }
1612
1636
  };
1613
1637
  const createMutation = useMutation({
1614
1638
  mutationFn: async (data) => {
1615
- log("Creating entity", data);
1639
+ log2("Creating entity", data);
1616
1640
  return sendOrbitalEvent(orbitalName, {
1617
1641
  event: events.create,
1618
1642
  payload: { data, entityType: entityName }
1619
1643
  });
1620
1644
  },
1621
1645
  onSuccess: (response) => {
1622
- log("Create succeeded", response);
1646
+ log2("Create succeeded", response);
1623
1647
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1624
1648
  },
1625
1649
  onError: (error) => {
@@ -1631,7 +1655,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1631
1655
  id,
1632
1656
  data
1633
1657
  }) => {
1634
- log(`Updating entity ${id}`, data);
1658
+ log2(`Updating entity ${id}`, data);
1635
1659
  return sendOrbitalEvent(orbitalName, {
1636
1660
  event: events.update,
1637
1661
  entityId: id,
@@ -1639,7 +1663,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1639
1663
  });
1640
1664
  },
1641
1665
  onSuccess: (response, variables) => {
1642
- log("Update succeeded", response);
1666
+ log2("Update succeeded", response);
1643
1667
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1644
1668
  queryClient.invalidateQueries({
1645
1669
  queryKey: entityDataKeys.detail(entityName, variables.id)
@@ -1651,7 +1675,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1651
1675
  });
1652
1676
  const deleteMutation = useMutation({
1653
1677
  mutationFn: async (id) => {
1654
- log(`Deleting entity ${id}`);
1678
+ log2(`Deleting entity ${id}`);
1655
1679
  return sendOrbitalEvent(orbitalName, {
1656
1680
  event: events.delete,
1657
1681
  entityId: id,
@@ -1659,7 +1683,7 @@ function useOrbitalMutations(entityName, orbitalName, options) {
1659
1683
  });
1660
1684
  },
1661
1685
  onSuccess: (response, id) => {
1662
- log("Delete succeeded", response);
1686
+ log2("Delete succeeded", response);
1663
1687
  queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1664
1688
  queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
1665
1689
  },
@@ -3,6 +3,7 @@
3
3
  var clsx = require('clsx');
4
4
  var tailwindMerge = require('tailwind-merge');
5
5
 
6
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
6
7
  function cn(...inputs) {
7
8
  return tailwindMerge.twMerge(clsx.clsx(inputs));
8
9
  }
@@ -427,7 +428,69 @@ function clearTraits() {
427
428
  notifyListeners4();
428
429
  }
429
430
 
431
+ // lib/logger.ts
432
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
433
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
434
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
435
+ function getViteEnv(key) {
436
+ try {
437
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
438
+ return meta?.env?.[key];
439
+ } catch {
440
+ return void 0;
441
+ }
442
+ }
443
+ function envGet(key, viteKey) {
444
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
445
+ }
446
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
447
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
448
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
449
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
450
+ function matchesNamespace(namespace) {
451
+ if (DEBUG_FILTER.length === 0) return true;
452
+ return DEBUG_FILTER.some((pattern) => {
453
+ if (pattern === "*" || pattern === "almadar:*") return true;
454
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
455
+ return namespace === pattern;
456
+ });
457
+ }
458
+ function createLogger(namespace) {
459
+ const nsAllowed = matchesNamespace(namespace);
460
+ const log2 = (level, message, data, correlationId) => {
461
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
462
+ if (level === "DEBUG" && !nsAllowed) return;
463
+ const prefix = `[${namespace}]`;
464
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
465
+ switch (level) {
466
+ case "DEBUG":
467
+ console.debug(prefix, message, logData ?? "");
468
+ break;
469
+ case "INFO":
470
+ console.info(prefix, message, logData ?? "");
471
+ break;
472
+ case "WARN":
473
+ console.warn(prefix, message, logData ?? "");
474
+ break;
475
+ case "ERROR":
476
+ console.error(prefix, message, logData ?? "");
477
+ break;
478
+ }
479
+ };
480
+ return {
481
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
482
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
483
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
484
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
485
+ };
486
+ }
487
+ var _cidCounter = 0;
488
+ function generateCorrelationId() {
489
+ return `evt-${Date.now()}-${++_cidCounter}`;
490
+ }
491
+
430
492
  // lib/verificationRegistry.ts
493
+ var log = createLogger("almadar:bridge");
431
494
  var MAX_TRANSITIONS = 500;
432
495
  function getState() {
433
496
  if (typeof window !== "undefined") {
@@ -471,6 +534,7 @@ function recordTransition(trace) {
471
534
  ...trace,
472
535
  id: `t-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
473
536
  };
537
+ log.info("transition:recorded", { trait: trace.traitName, from: trace.from, to: trace.to, event: trace.event, effectCount: trace.effects.length });
474
538
  getState().transitions.push(entry);
475
539
  if (getState().transitions.length > MAX_TRANSITIONS) {
476
540
  getState().transitions.shift();
@@ -620,10 +684,12 @@ function waitForTransition(event, timeoutMs = 1e4) {
620
684
  }
621
685
  function bindEventBus(eventBus) {
622
686
  if (typeof window === "undefined") return;
687
+ log.info("bindEventBus", { hasOnAny: !!eventBus.onAny });
623
688
  exposeOnWindow();
624
689
  if (window.__orbitalVerification) {
625
690
  window.__orbitalVerification.sendEvent = (event, payload) => {
626
691
  const prefixed = event.startsWith("UI:") ? event : `UI:${event}`;
692
+ log.debug("sendEvent", { event: prefixed, payloadKeys: payload ? Object.keys(payload) : [] });
627
693
  eventBus.emit(prefixed, payload);
628
694
  };
629
695
  const eventLog = [];
@@ -1461,6 +1527,7 @@ exports.clearTicks = clearTicks;
1461
1527
  exports.clearTraits = clearTraits;
1462
1528
  exports.clearVerification = clearVerification;
1463
1529
  exports.cn = cn;
1530
+ exports.createLogger = createLogger;
1464
1531
  exports.debug = debug;
1465
1532
  exports.debugCollision = debugCollision;
1466
1533
  exports.debugError = debugError;
@@ -1477,6 +1544,7 @@ exports.extractOutputsFromTransitions = extractOutputsFromTransitions;
1477
1544
  exports.extractStateMachine = extractStateMachine;
1478
1545
  exports.formatGuard = formatGuard;
1479
1546
  exports.formatNestedFieldLabel = formatNestedFieldLabel;
1547
+ exports.generateCorrelationId = generateCorrelationId;
1480
1548
  exports.getAllChecks = getAllChecks;
1481
1549
  exports.getAllTicks = getAllTicks;
1482
1550
  exports.getAllTraits = getAllTraits;
@@ -16,3 +16,4 @@ export * from './verificationRegistry';
16
16
  export * from './getNestedValue';
17
17
  export * from './visualizer';
18
18
  export * from './parseContentSegments';
19
+ export * from './logger';
package/dist/lib/index.js CHANGED
@@ -425,7 +425,69 @@ function clearTraits() {
425
425
  notifyListeners4();
426
426
  }
427
427
 
428
+ // lib/logger.ts
429
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
430
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
431
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
432
+ function getViteEnv(key) {
433
+ try {
434
+ const meta = import.meta;
435
+ return meta?.env?.[key];
436
+ } catch {
437
+ return void 0;
438
+ }
439
+ }
440
+ function envGet(key, viteKey) {
441
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
442
+ }
443
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
444
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
445
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
446
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
447
+ function matchesNamespace(namespace) {
448
+ if (DEBUG_FILTER.length === 0) return true;
449
+ return DEBUG_FILTER.some((pattern) => {
450
+ if (pattern === "*" || pattern === "almadar:*") return true;
451
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
452
+ return namespace === pattern;
453
+ });
454
+ }
455
+ function createLogger(namespace) {
456
+ const nsAllowed = matchesNamespace(namespace);
457
+ const log2 = (level, message, data, correlationId) => {
458
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
459
+ if (level === "DEBUG" && !nsAllowed) return;
460
+ const prefix = `[${namespace}]`;
461
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
462
+ switch (level) {
463
+ case "DEBUG":
464
+ console.debug(prefix, message, logData ?? "");
465
+ break;
466
+ case "INFO":
467
+ console.info(prefix, message, logData ?? "");
468
+ break;
469
+ case "WARN":
470
+ console.warn(prefix, message, logData ?? "");
471
+ break;
472
+ case "ERROR":
473
+ console.error(prefix, message, logData ?? "");
474
+ break;
475
+ }
476
+ };
477
+ return {
478
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
479
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
480
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
481
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
482
+ };
483
+ }
484
+ var _cidCounter = 0;
485
+ function generateCorrelationId() {
486
+ return `evt-${Date.now()}-${++_cidCounter}`;
487
+ }
488
+
428
489
  // lib/verificationRegistry.ts
490
+ var log = createLogger("almadar:bridge");
429
491
  var MAX_TRANSITIONS = 500;
430
492
  function getState() {
431
493
  if (typeof window !== "undefined") {
@@ -469,6 +531,7 @@ function recordTransition(trace) {
469
531
  ...trace,
470
532
  id: `t-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`
471
533
  };
534
+ log.info("transition:recorded", { trait: trace.traitName, from: trace.from, to: trace.to, event: trace.event, effectCount: trace.effects.length });
472
535
  getState().transitions.push(entry);
473
536
  if (getState().transitions.length > MAX_TRANSITIONS) {
474
537
  getState().transitions.shift();
@@ -618,10 +681,12 @@ function waitForTransition(event, timeoutMs = 1e4) {
618
681
  }
619
682
  function bindEventBus(eventBus) {
620
683
  if (typeof window === "undefined") return;
684
+ log.info("bindEventBus", { hasOnAny: !!eventBus.onAny });
621
685
  exposeOnWindow();
622
686
  if (window.__orbitalVerification) {
623
687
  window.__orbitalVerification.sendEvent = (event, payload) => {
624
688
  const prefixed = event.startsWith("UI:") ? event : `UI:${event}`;
689
+ log.debug("sendEvent", { event: prefixed, payloadKeys: payload ? Object.keys(payload) : [] });
625
690
  eventBus.emit(prefixed, payload);
626
691
  };
627
692
  const eventLog = [];
@@ -1446,4 +1511,4 @@ function parseContentSegments(content) {
1446
1511
  return segments;
1447
1512
  }
1448
1513
 
1449
- export { ApiError, DEFAULT_CONFIG, apiClient, bindCanvasCapture, bindEventBus, bindTraitStateGetter, clearDebugEvents, clearEntityProvider, clearGuardHistory, clearTicks, clearTraits, clearVerification, cn, debug, debugCollision, debugError, debugGameState, debugGroup, debugGroupEnd, debugInput, debugPhysics, debugTable, debugTime, debugTimeEnd, debugWarn, extractOutputsFromTransitions, extractStateMachine, formatGuard, formatNestedFieldLabel, getAllChecks, getAllTicks, getAllTraits, getBridgeHealth, getDebugEvents, getEffectSummary, getEntitiesByType, getEntityById, getEntitySnapshot, getEventsBySource, getEventsByType, getGuardEvaluationsForTrait, getGuardHistory, getNestedValue, getRecentEvents, getRecentGuardEvaluations, getSnapshot, getSummary, getTick, getTrait, getTransitions, getTransitionsForTrait, initDebugShortcut, isDebugEnabled, logDebugEvent, logEffectExecuted, logError, logEventFired, logInfo, logStateChange, logWarning, onDebugToggle, parseContentSegments, parseMarkdownWithCodeBlocks, recordGuardEvaluation, recordServerResponse, recordTransition, registerCheck, registerTick, registerTrait, renderStateMachineToDomData, renderStateMachineToSvg, setDebugEnabled, setEntityProvider, setTickActive, subscribeToDebugEvents, subscribeToGuardChanges, subscribeToTickChanges, subscribeToTraitChanges, subscribeToVerification, toggleDebug, unregisterTick, unregisterTrait, updateAssetStatus, updateBridgeHealth, updateCheck, updateGuardResult, updateTickExecution, updateTraitState, waitForTransition };
1514
+ export { ApiError, DEFAULT_CONFIG, apiClient, bindCanvasCapture, bindEventBus, bindTraitStateGetter, clearDebugEvents, clearEntityProvider, clearGuardHistory, clearTicks, clearTraits, clearVerification, cn, createLogger, debug, debugCollision, debugError, debugGameState, debugGroup, debugGroupEnd, debugInput, debugPhysics, debugTable, debugTime, debugTimeEnd, debugWarn, extractOutputsFromTransitions, extractStateMachine, formatGuard, formatNestedFieldLabel, generateCorrelationId, getAllChecks, getAllTicks, getAllTraits, getBridgeHealth, getDebugEvents, getEffectSummary, getEntitiesByType, getEntityById, getEntitySnapshot, getEventsBySource, getEventsByType, getGuardEvaluationsForTrait, getGuardHistory, getNestedValue, getRecentEvents, getRecentGuardEvaluations, getSnapshot, getSummary, getTick, getTrait, getTransitions, getTransitionsForTrait, initDebugShortcut, isDebugEnabled, logDebugEvent, logEffectExecuted, logError, logEventFired, logInfo, logStateChange, logWarning, onDebugToggle, parseContentSegments, parseMarkdownWithCodeBlocks, recordGuardEvaluation, recordServerResponse, recordTransition, registerCheck, registerTick, registerTrait, renderStateMachineToDomData, renderStateMachineToSvg, setDebugEnabled, setEntityProvider, setTickActive, subscribeToDebugEvents, subscribeToGuardChanges, subscribeToTickChanges, subscribeToTraitChanges, subscribeToVerification, toggleDebug, unregisterTick, unregisterTrait, updateAssetStatus, updateBridgeHealth, updateCheck, updateGuardResult, updateTickExecution, updateTraitState, waitForTransition };
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Almadar Structured Logger
3
+ *
4
+ * Namespace-based logging with level gating and correlation IDs.
5
+ * Pure TypeScript, zero React dependencies. Works in Node.js, Vite, and browser.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ export interface Logger {
10
+ debug: (msg: string, data?: Record<string, unknown>, cid?: string) => void;
11
+ info: (msg: string, data?: Record<string, unknown>, cid?: string) => void;
12
+ warn: (msg: string, data?: Record<string, unknown>, cid?: string) => void;
13
+ error: (msg: string, data?: Record<string, unknown>, cid?: string) => void;
14
+ }
15
+ export declare function createLogger(namespace: string): Logger;
16
+ export declare function generateCorrelationId(): string;
@@ -4,6 +4,7 @@ var React5 = require('react');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var LucideIcons = require('lucide-react');
6
6
 
7
+ var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
7
8
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
8
9
 
9
10
  function _interopNamespace(e) {
@@ -2506,9 +2507,70 @@ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
2506
2507
  function cn(...inputs) {
2507
2508
  return twMerge(clsx(inputs));
2508
2509
  }
2510
+
2511
+ // lib/logger.ts
2512
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
2513
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
2514
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
2515
+ function getViteEnv(key) {
2516
+ try {
2517
+ const meta = ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)) });
2518
+ return meta?.env?.[key];
2519
+ } catch {
2520
+ return void 0;
2521
+ }
2522
+ }
2523
+ function envGet(key, viteKey) {
2524
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
2525
+ }
2526
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
2527
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
2528
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
2529
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
2530
+ function matchesNamespace(namespace) {
2531
+ if (DEBUG_FILTER.length === 0) return true;
2532
+ return DEBUG_FILTER.some((pattern) => {
2533
+ if (pattern === "*" || pattern === "almadar:*") return true;
2534
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
2535
+ return namespace === pattern;
2536
+ });
2537
+ }
2538
+ function createLogger(namespace) {
2539
+ const nsAllowed = matchesNamespace(namespace);
2540
+ const log2 = (level, message, data, correlationId) => {
2541
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
2542
+ if (level === "DEBUG" && !nsAllowed) return;
2543
+ const prefix = `[${namespace}]`;
2544
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
2545
+ switch (level) {
2546
+ case "DEBUG":
2547
+ console.debug(prefix, message, logData ?? "");
2548
+ break;
2549
+ case "INFO":
2550
+ console.info(prefix, message, logData ?? "");
2551
+ break;
2552
+ case "WARN":
2553
+ console.warn(prefix, message, logData ?? "");
2554
+ break;
2555
+ case "ERROR":
2556
+ console.error(prefix, message, logData ?? "");
2557
+ break;
2558
+ }
2559
+ };
2560
+ return {
2561
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
2562
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
2563
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
2564
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
2565
+ };
2566
+ }
2567
+ createLogger("almadar:eventbus");
2568
+ createLogger("almadar:eventbus:subscribe");
2509
2569
  var EventBusContext = React5.createContext(null);
2510
2570
 
2511
2571
  // hooks/useEventBus.ts
2572
+ var log = createLogger("almadar:eventbus");
2573
+ var subLog2 = createLogger("almadar:eventbus:subscribe");
2512
2574
  function getGlobalEventBus() {
2513
2575
  if (typeof window !== "undefined") {
2514
2576
  return window.__kflowEventBus ?? null;
@@ -2525,6 +2587,7 @@ var fallbackEventBus = {
2525
2587
  timestamp: Date.now()
2526
2588
  };
2527
2589
  const handlers = fallbackListeners.get(type);
2590
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
2528
2591
  if (handlers) {
2529
2592
  handlers.forEach((handler) => {
2530
2593
  try {
@@ -2547,6 +2610,7 @@ var fallbackEventBus = {
2547
2610
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
2548
2611
  }
2549
2612
  fallbackListeners.get(type).add(listener);
2613
+ subLog2.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
2550
2614
  return () => {
2551
2615
  const handlers = fallbackListeners.get(type);
2552
2616
  if (handlers) {
@@ -2570,6 +2634,7 @@ var fallbackEventBus = {
2570
2634
  },
2571
2635
  onAny: (listener) => {
2572
2636
  fallbackAnyListeners.add(listener);
2637
+ subLog2.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
2573
2638
  return () => {
2574
2639
  fallbackAnyListeners.delete(listener);
2575
2640
  };
@@ -2482,9 +2482,70 @@ var twMerge = /* @__PURE__ */ createTailwindMerge(getDefaultConfig);
2482
2482
  function cn(...inputs) {
2483
2483
  return twMerge(clsx(inputs));
2484
2484
  }
2485
+
2486
+ // lib/logger.ts
2487
+ var LEVEL_PRIORITY = { DEBUG: 0, INFO: 1, WARN: 2, ERROR: 3 };
2488
+ var ENV = typeof process !== "undefined" && process.env ? process.env : {};
2489
+ var VITE_ENV = typeof globalThis !== "undefined" && globalThis.__vite_env__ ? globalThis.__vite_env__ : {};
2490
+ function getViteEnv(key) {
2491
+ try {
2492
+ const meta = import.meta;
2493
+ return meta?.env?.[key];
2494
+ } catch {
2495
+ return void 0;
2496
+ }
2497
+ }
2498
+ function envGet(key, viteKey) {
2499
+ return ENV[key] ?? (viteKey ? getViteEnv(viteKey) : void 0) ?? VITE_ENV[viteKey ?? key];
2500
+ }
2501
+ var NODE_ENV = envGet("NODE_ENV", "VITE_NODE_ENV") ?? "development";
2502
+ var CONFIGURED_LEVEL = (envGet("LOG_LEVEL", "VITE_LOG_LEVEL") ?? (NODE_ENV === "production" ? "info" : "debug")).toUpperCase();
2503
+ var MIN_PRIORITY = LEVEL_PRIORITY[CONFIGURED_LEVEL] ?? 0;
2504
+ var DEBUG_FILTER = (envGet("ALMADAR_DEBUG", "VITE_ALMADAR_DEBUG") ?? "").split(",").map((s) => s.trim()).filter(Boolean);
2505
+ function matchesNamespace(namespace) {
2506
+ if (DEBUG_FILTER.length === 0) return true;
2507
+ return DEBUG_FILTER.some((pattern) => {
2508
+ if (pattern === "*" || pattern === "almadar:*") return true;
2509
+ if (pattern.endsWith(":*")) return namespace.startsWith(pattern.slice(0, -1));
2510
+ return namespace === pattern;
2511
+ });
2512
+ }
2513
+ function createLogger(namespace) {
2514
+ const nsAllowed = matchesNamespace(namespace);
2515
+ const log2 = (level, message, data, correlationId) => {
2516
+ if (LEVEL_PRIORITY[level] < MIN_PRIORITY) return;
2517
+ if (level === "DEBUG" && !nsAllowed) return;
2518
+ const prefix = `[${namespace}]`;
2519
+ const logData = correlationId ? { ...data, cid: correlationId } : data;
2520
+ switch (level) {
2521
+ case "DEBUG":
2522
+ console.debug(prefix, message, logData ?? "");
2523
+ break;
2524
+ case "INFO":
2525
+ console.info(prefix, message, logData ?? "");
2526
+ break;
2527
+ case "WARN":
2528
+ console.warn(prefix, message, logData ?? "");
2529
+ break;
2530
+ case "ERROR":
2531
+ console.error(prefix, message, logData ?? "");
2532
+ break;
2533
+ }
2534
+ };
2535
+ return {
2536
+ debug: (msg, data, cid) => log2("DEBUG", msg, data, cid),
2537
+ info: (msg, data, cid) => log2("INFO", msg, data, cid),
2538
+ warn: (msg, data, cid) => log2("WARN", msg, data, cid),
2539
+ error: (msg, data, cid) => log2("ERROR", msg, data, cid)
2540
+ };
2541
+ }
2542
+ createLogger("almadar:eventbus");
2543
+ createLogger("almadar:eventbus:subscribe");
2485
2544
  var EventBusContext = createContext(null);
2486
2545
 
2487
2546
  // hooks/useEventBus.ts
2547
+ var log = createLogger("almadar:eventbus");
2548
+ var subLog2 = createLogger("almadar:eventbus:subscribe");
2488
2549
  function getGlobalEventBus() {
2489
2550
  if (typeof window !== "undefined") {
2490
2551
  return window.__kflowEventBus ?? null;
@@ -2501,6 +2562,7 @@ var fallbackEventBus = {
2501
2562
  timestamp: Date.now()
2502
2563
  };
2503
2564
  const handlers = fallbackListeners.get(type);
2565
+ log.debug("emit", { type, payloadKeys: payload ? Object.keys(payload).length : 0, listenerCount: (handlers?.size ?? 0) + fallbackAnyListeners.size });
2504
2566
  if (handlers) {
2505
2567
  handlers.forEach((handler) => {
2506
2568
  try {
@@ -2523,6 +2585,7 @@ var fallbackEventBus = {
2523
2585
  fallbackListeners.set(type, /* @__PURE__ */ new Set());
2524
2586
  }
2525
2587
  fallbackListeners.get(type).add(listener);
2588
+ subLog2.debug("subscribe", { type, totalListeners: fallbackListeners.get(type).size });
2526
2589
  return () => {
2527
2590
  const handlers = fallbackListeners.get(type);
2528
2591
  if (handlers) {
@@ -2546,6 +2609,7 @@ var fallbackEventBus = {
2546
2609
  },
2547
2610
  onAny: (listener) => {
2548
2611
  fallbackAnyListeners.add(listener);
2612
+ subLog2.debug("subscribe:any", { totalAnyListeners: fallbackAnyListeners.size });
2549
2613
  return () => {
2550
2614
  fallbackAnyListeners.delete(listener);
2551
2615
  };