@bitcobblers/wod-wiki-lang 0.1.5 → 0.1.8

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.
package/dist/index.cjs CHANGED
@@ -5620,6 +5620,11 @@ function createBrowserRuntimeNow() {
5620
5620
  nowMs: () => getRuntimeNowMs()
5621
5621
  };
5622
5622
  }
5623
+
5624
+ // src/runtime/contracts/ICastSubscription.ts
5625
+ function isCastSubscription(s) {
5626
+ return "sendAnalyticsSummary" in s && typeof s.sendAnalyticsSummary === "function";
5627
+ }
5623
5628
  var CompletionTimestampBehavior = class {
5624
5629
  completionTime;
5625
5630
  wasComplete = false;
@@ -11598,6 +11603,514 @@ var PlaySoundAction = class {
11598
11603
  return runtime.eventBus.dispatch(event, runtime);
11599
11604
  }
11600
11605
  };
11606
+
11607
+ // src/runtime/utils/MemoryUtils.ts
11608
+ function searchStackMemory(runtime, criteria) {
11609
+ const results = [];
11610
+ if (!runtime.stack || !runtime.stack.blocks) {
11611
+ return results;
11612
+ }
11613
+ for (const block of runtime.stack.blocks) {
11614
+ if (!block.context || !block.context.references) {
11615
+ continue;
11616
+ }
11617
+ const matches = block.context.references.filter((ref) => {
11618
+ if (criteria.id !== void 0 && criteria.id !== null && ref.id !== criteria.id) return false;
11619
+ if (criteria.ownerId !== void 0 && criteria.ownerId !== null && ref.ownerId !== criteria.ownerId) return false;
11620
+ if (criteria.type !== void 0 && criteria.type !== null && ref.type !== criteria.type) return false;
11621
+ if (criteria.visibility !== void 0 && criteria.visibility !== null && ref.visibility !== criteria.visibility) return false;
11622
+ return true;
11623
+ });
11624
+ results.push(...matches);
11625
+ }
11626
+ return results;
11627
+ }
11628
+
11629
+ // src/runtime/adapters/RuntimeAdapter.ts
11630
+ var RuntimeAdapter = class {
11631
+ /**
11632
+ * Creates immutable snapshot of runtime state for UI rendering
11633
+ */
11634
+ createSnapshot(runtime) {
11635
+ const stackBlocks = this.extractStackBlocks(runtime);
11636
+ const memoryEntries = this.extractMemoryEntries(runtime);
11637
+ const activeIndex = stackBlocks.findIndex((block) => block.isActive);
11638
+ const groupedByOwner = this.groupMemoryEntries(memoryEntries, "owner");
11639
+ const groupedByType = this.groupMemoryEntries(memoryEntries, "type");
11640
+ const status = this.determineExecutionStatus(stackBlocks);
11641
+ return {
11642
+ stack: {
11643
+ blocks: stackBlocks,
11644
+ activeIndex: activeIndex >= 0 ? activeIndex : 0,
11645
+ depth: stackBlocks.length,
11646
+ rootBlockKey: stackBlocks.length > 0 ? stackBlocks[0].key : void 0
11647
+ },
11648
+ memory: {
11649
+ entries: memoryEntries,
11650
+ groupedByOwner,
11651
+ groupedByType,
11652
+ totalEntries: memoryEntries.length
11653
+ },
11654
+ status,
11655
+ metadata: {
11656
+ stepCount: 0,
11657
+ // TODO: Track actual step count
11658
+ elapsedTime: 0,
11659
+ // TODO: Track actual elapsed time
11660
+ lastEvent: void 0,
11661
+ lastEventTime: void 0
11662
+ },
11663
+ timestamp: Date.now()
11664
+ };
11665
+ }
11666
+ /**
11667
+ * Extracts RuntimeStackBlocks from runtime stack
11668
+ */
11669
+ extractStackBlocks(runtime) {
11670
+ const blocks = runtime.stack.blocks;
11671
+ return blocks.map((block, index) => {
11672
+ const blockType = this.mapBlockType(block);
11673
+ const isActive = index === blocks.length - 1;
11674
+ const status = this.determineBlockStatus(isActive);
11675
+ const metrics = this.extractBlockFragments(runtime, block);
11676
+ const displayLocs = block.getMemoryByTag("metric:display");
11677
+ const metricGroups = displayLocs.length > 1 ? displayLocs.map((loc) => wodWikiCore.MetricContainer.from([...loc.metrics])) : void 0;
11678
+ return {
11679
+ key: block.key.toString(),
11680
+ blockType,
11681
+ parentKey: this.findParentKey(blocks, index),
11682
+ children: this.findChildrenKeys(blocks, block.key.toString()),
11683
+ depth: index,
11684
+ label: block.label || this.generateBlockLabel(blockType),
11685
+ color: this.getBlockColor(blockType),
11686
+ icon: this.getBlockIcon(blockType),
11687
+ isActive,
11688
+ isComplete: status === "complete",
11689
+ status,
11690
+ metric: {},
11691
+ // TODO: Extract actual metrics
11692
+ metrics,
11693
+ metricGroups,
11694
+ sourceIds: block.sourceIds,
11695
+ lineNumber: block.sourceIds.length > 0 ? block.sourceIds[0] : void 0,
11696
+ metadata: {
11697
+ mountTime: void 0,
11698
+ executionTime: void 0,
11699
+ iterationCount: void 0
11700
+ }
11701
+ };
11702
+ });
11703
+ }
11704
+ /**
11705
+ * Extracts metrics from block's source statements for unified visualization
11706
+ */
11707
+ extractBlockFragments(_runtime, block) {
11708
+ if (!block.sourceIds || block.sourceIds.length === 0) {
11709
+ return void 0;
11710
+ }
11711
+ return void 0;
11712
+ }
11713
+ /**
11714
+ * Extracts MemoryEntries from runtime memory
11715
+ */
11716
+ extractMemoryEntries(runtime) {
11717
+ const entries = [];
11718
+ const ownerLineMap = /* @__PURE__ */ new Map();
11719
+ const ownerLabelMap = /* @__PURE__ */ new Map();
11720
+ runtime.stack.blocks.forEach((block) => {
11721
+ const key = block.key.toString();
11722
+ if (block.sourceIds && block.sourceIds.length > 0) {
11723
+ ownerLineMap.set(key, block.sourceIds[0]);
11724
+ }
11725
+ ownerLabelMap.set(key, block.label);
11726
+ });
11727
+ for (const block of runtime.stack.blocks) {
11728
+ const blockKey = block.key.toString();
11729
+ const locations = block.getAllMemory();
11730
+ for (const loc of locations) {
11731
+ const tag = loc.tag;
11732
+ const value = loc.metrics.length > 0 ? loc.metrics[0].value : void 0;
11733
+ const memoryType = this.mapMemoryType(tag);
11734
+ const entryId = `${blockKey}-${tag}`;
11735
+ entries.push({
11736
+ id: entryId,
11737
+ ownerId: blockKey,
11738
+ ownerLabel: ownerLabelMap.get(blockKey) ?? blockKey,
11739
+ type: memoryType,
11740
+ value,
11741
+ valueFormatted: this.formatValue(value),
11742
+ label: this.generateMemoryLabelFromType(tag, memoryType),
11743
+ groupLabel: this.generateGroupLabel(memoryType),
11744
+ icon: this.getMemoryIcon(memoryType),
11745
+ lineNumber: ownerLineMap.get(blockKey),
11746
+ isValid: value !== void 0,
11747
+ isHighlighted: false,
11748
+ metadata: {
11749
+ createdAt: void 0,
11750
+ lastModified: void 0,
11751
+ accessCount: void 0
11752
+ },
11753
+ references: [],
11754
+ referencedBy: []
11755
+ });
11756
+ }
11757
+ }
11758
+ const references = searchStackMemory(runtime, {});
11759
+ for (const ref of references) {
11760
+ const existingId = `${ref.ownerId}-${ref.type}`;
11761
+ if (entries.some((e) => e.id === existingId)) {
11762
+ continue;
11763
+ }
11764
+ const value = ref.value();
11765
+ const memoryType = this.mapMemoryType(ref.type);
11766
+ entries.push({
11767
+ id: ref.id,
11768
+ ownerId: ref.ownerId,
11769
+ ownerLabel: ownerLabelMap.get(ref.ownerId) ?? this.generateOwnerLabel(ref.ownerId),
11770
+ type: memoryType,
11771
+ value,
11772
+ valueFormatted: this.formatValue(value),
11773
+ label: this.generateMemoryLabel(ref, memoryType),
11774
+ groupLabel: this.generateGroupLabel(memoryType),
11775
+ icon: this.getMemoryIcon(memoryType),
11776
+ lineNumber: ownerLineMap.get(ref.ownerId),
11777
+ isValid: value !== void 0,
11778
+ isHighlighted: false,
11779
+ metadata: {
11780
+ createdAt: void 0,
11781
+ lastModified: void 0,
11782
+ accessCount: void 0
11783
+ },
11784
+ references: [],
11785
+ referencedBy: []
11786
+ });
11787
+ }
11788
+ return entries;
11789
+ }
11790
+ /**
11791
+ * Generates a label for a memory entry from its type
11792
+ */
11793
+ generateMemoryLabelFromType(rawType, _displayType) {
11794
+ const typeStr = rawType.toString();
11795
+ return typeStr.charAt(0).toUpperCase() + typeStr.slice(1).replace(/-/g, " ");
11796
+ }
11797
+ /**
11798
+ * Groups memory entries by specified grouping strategy
11799
+ */
11800
+ groupMemoryEntries(entries, groupBy) {
11801
+ const groups = /* @__PURE__ */ new Map();
11802
+ if (groupBy === "none") {
11803
+ groups.set("All Entries", entries);
11804
+ return groups;
11805
+ }
11806
+ for (const entry of entries) {
11807
+ let groupKey;
11808
+ switch (groupBy) {
11809
+ case "owner":
11810
+ groupKey = entry.ownerLabel || entry.ownerId;
11811
+ break;
11812
+ case "type":
11813
+ groupKey = entry.type;
11814
+ break;
11815
+ default:
11816
+ groupKey = "Unknown";
11817
+ }
11818
+ if (!groups.has(groupKey)) {
11819
+ groups.set(groupKey, []);
11820
+ }
11821
+ groups.get(groupKey).push(entry);
11822
+ }
11823
+ return groups;
11824
+ }
11825
+ // Helper methods
11826
+ determineExecutionStatus(stackBlocks) {
11827
+ if (stackBlocks.length === 0) {
11828
+ return "idle";
11829
+ }
11830
+ const hasActiveBlock = stackBlocks.some((block) => block.isActive);
11831
+ if (hasActiveBlock) {
11832
+ return "executing";
11833
+ }
11834
+ return "idle";
11835
+ }
11836
+ mapBlockType(block) {
11837
+ const blockType = block.blockType?.toLowerCase();
11838
+ switch (blockType) {
11839
+ case "workout":
11840
+ return "workout";
11841
+ case "group":
11842
+ return "group";
11843
+ case "timer":
11844
+ return "timer";
11845
+ case "rounds":
11846
+ return "rounds";
11847
+ case "effort":
11848
+ return "effort";
11849
+ case "exercise":
11850
+ return "exercise";
11851
+ default:
11852
+ return "custom";
11853
+ }
11854
+ }
11855
+ determineBlockStatus(isActive) {
11856
+ if (isActive) {
11857
+ return "active";
11858
+ }
11859
+ return "pending";
11860
+ }
11861
+ findParentKey(blocks, currentIndex) {
11862
+ if (currentIndex === 0) return void 0;
11863
+ return blocks[currentIndex - 1].key.toString();
11864
+ }
11865
+ findChildrenKeys(_blocks, _parentKey) {
11866
+ return [];
11867
+ }
11868
+ generateBlockLabel(blockType) {
11869
+ return `${blockType.charAt(0).toUpperCase() + blockType.slice(1)} Block`;
11870
+ }
11871
+ getBlockColor(blockType) {
11872
+ const colors = {
11873
+ workout: "#3B82F6",
11874
+ // blue
11875
+ group: "#10B981",
11876
+ // green
11877
+ timer: "#F59E0B",
11878
+ // yellow
11879
+ rounds: "#8B5CF6",
11880
+ // purple
11881
+ effort: "#EF4444",
11882
+ // red
11883
+ exercise: "#06B6D4",
11884
+ // cyan
11885
+ custom: "#6B7280"
11886
+ // gray
11887
+ };
11888
+ return colors[blockType];
11889
+ }
11890
+ getBlockIcon(blockType) {
11891
+ const icons = {
11892
+ workout: "\u{1F3CB}\uFE0F",
11893
+ timer: "\u23F1\uFE0F",
11894
+ rounds: "\u{1F504}",
11895
+ exercise: "\u{1F4AA}"
11896
+ };
11897
+ return icons[blockType];
11898
+ }
11899
+ mapMemoryType(type) {
11900
+ if (!type) return "unknown";
11901
+ const lowerType = type.toLowerCase();
11902
+ if (lowerType.includes("metric")) return "metric";
11903
+ if (lowerType.includes("timer")) return "timer-state";
11904
+ if (lowerType.includes("loop")) return "loop-state";
11905
+ if (lowerType.includes("group")) return "group-state";
11906
+ if (lowerType.includes("handler")) return "handler";
11907
+ if (lowerType.includes("span")) return "span";
11908
+ return "unknown";
11909
+ }
11910
+ generateOwnerLabel(ownerId) {
11911
+ return ownerId;
11912
+ }
11913
+ formatValue(value) {
11914
+ if (value === void 0 || value === null) {
11915
+ return "undefined";
11916
+ }
11917
+ if (typeof value === "string") {
11918
+ return `"${value}"`;
11919
+ }
11920
+ if (typeof value === "number" || typeof value === "boolean") {
11921
+ return value.toString();
11922
+ }
11923
+ if (Array.isArray(value)) {
11924
+ return `Array(${value.length})`;
11925
+ }
11926
+ if (typeof value === "object") {
11927
+ return `{${Object.keys(value).length} properties}`;
11928
+ }
11929
+ return typeof value;
11930
+ }
11931
+ generateMemoryLabel(ref, memoryType) {
11932
+ return `${memoryType}: ${ref.id}`;
11933
+ }
11934
+ generateGroupLabel(memoryType) {
11935
+ return memoryType;
11936
+ }
11937
+ getMemoryIcon(memoryType) {
11938
+ const icons = {
11939
+ metric: "\u{1F4CA}",
11940
+ "timer-state": "\u23F1\uFE0F",
11941
+ "loop-state": "\u{1F504}",
11942
+ "group-state": "\u{1F4C1}",
11943
+ handler: "\u2699\uFE0F",
11944
+ span: "\u{1F4CF}",
11945
+ unknown: "\u2753"
11946
+ };
11947
+ return icons[memoryType];
11948
+ }
11949
+ };
11950
+
11951
+ // src/runtime/subscriptions/LocalRuntimeSubscription.ts
11952
+ var LocalRuntimeSubscription = class {
11953
+ id;
11954
+ onStackSnapshotCallback;
11955
+ onOutputCallback;
11956
+ constructor(options) {
11957
+ this.id = options?.id ?? "local";
11958
+ this.onStackSnapshotCallback = options?.onStackSnapshot;
11959
+ this.onOutputCallback = options?.onOutput;
11960
+ }
11961
+ onStackSnapshot(snapshot) {
11962
+ this.onStackSnapshotCallback?.(snapshot);
11963
+ }
11964
+ onOutput(output) {
11965
+ this.onOutputCallback?.(output);
11966
+ }
11967
+ dispose() {
11968
+ this.onStackSnapshotCallback = void 0;
11969
+ this.onOutputCallback = void 0;
11970
+ }
11971
+ };
11972
+
11973
+ // src/runtime/subscriptions/LocalEventProvider.ts
11974
+ var LocalEventProvider = class _LocalEventProvider {
11975
+ constructor(runtime) {
11976
+ this.runtime = runtime;
11977
+ }
11978
+ runtime;
11979
+ static subscriptionCounter = 0;
11980
+ unsubscribes = [];
11981
+ disposed = false;
11982
+ dispatch(event) {
11983
+ if (this.disposed) return;
11984
+ this.runtime.handle(event);
11985
+ }
11986
+ onEvent(handler) {
11987
+ if (this.disposed) return () => {
11988
+ };
11989
+ const ownerId = `local-event-provider-${_LocalEventProvider.subscriptionCounter++}`;
11990
+ const unsubscribeFromBus = this.runtime.eventBus.on("*", (event) => {
11991
+ handler(event);
11992
+ }, ownerId);
11993
+ const unsubscribe = () => {
11994
+ unsubscribeFromBus();
11995
+ this.unsubscribes = this.unsubscribes.filter((candidate) => candidate !== unsubscribe);
11996
+ };
11997
+ this.unsubscribes.push(unsubscribe);
11998
+ return unsubscribe;
11999
+ }
12000
+ dispose() {
12001
+ if (this.disposed) return;
12002
+ this.disposed = true;
12003
+ const unsubscribes = [...this.unsubscribes];
12004
+ this.unsubscribes = [];
12005
+ for (const unsubscribe of unsubscribes) {
12006
+ unsubscribe();
12007
+ }
12008
+ }
12009
+ };
12010
+
12011
+ // src/runtime/subscriptions/SubscriptionManager.ts
12012
+ var SubscriptionManager = class {
12013
+ constructor(runtime) {
12014
+ this.runtime = runtime;
12015
+ this.stackUnsub = this.runtime.subscribeToStack((snapshot) => {
12016
+ for (const sub of this.subscriptions.values()) {
12017
+ try {
12018
+ sub.onStackSnapshot(snapshot);
12019
+ } catch (err) {
12020
+ console.error(`[SubscriptionManager] Error in subscription '${sub.id}' onStackSnapshot:`, err);
12021
+ }
12022
+ }
12023
+ });
12024
+ this.outputUnsub = this.runtime.subscribeToOutput((output) => {
12025
+ for (const sub of this.subscriptions.values()) {
12026
+ try {
12027
+ sub.onOutput(output);
12028
+ } catch (err) {
12029
+ console.error(`[SubscriptionManager] Error in subscription '${sub.id}' onOutput:`, err);
12030
+ }
12031
+ }
12032
+ });
12033
+ }
12034
+ runtime;
12035
+ subscriptions = /* @__PURE__ */ new Map();
12036
+ stackUnsub = null;
12037
+ outputUnsub = null;
12038
+ disposed = false;
12039
+ /**
12040
+ * Register a subscription. If a subscription with the same ID already exists,
12041
+ * the old one is disposed and replaced.
12042
+ *
12043
+ * New subscriptions immediately receive the current stack state and any
12044
+ * existing output statements to catch them up.
12045
+ */
12046
+ add(subscription) {
12047
+ if (this.disposed) {
12048
+ console.warn("[SubscriptionManager] Cannot add subscription after dispose");
12049
+ return;
12050
+ }
12051
+ const existing = this.subscriptions.get(subscription.id);
12052
+ if (existing) {
12053
+ existing.dispose();
12054
+ }
12055
+ this.subscriptions.set(subscription.id, subscription);
12056
+ try {
12057
+ subscription.onStackSnapshot({
12058
+ type: "initial",
12059
+ blocks: [...this.runtime.stack.blocks],
12060
+ depth: this.runtime.stack.count,
12061
+ clockTime: this.runtime.clock.currentDate
12062
+ });
12063
+ const currentOutputs = this.runtime.getOutputStatements();
12064
+ for (const output of currentOutputs) {
12065
+ subscription.onOutput(output);
12066
+ }
12067
+ } catch (err) {
12068
+ console.error(`[SubscriptionManager] Error catching up subscription '${subscription.id}':`, err);
12069
+ }
12070
+ }
12071
+ /**
12072
+ * Remove and dispose a subscription by ID.
12073
+ * Returns true if the subscription was found and removed.
12074
+ */
12075
+ remove(id) {
12076
+ const sub = this.subscriptions.get(id);
12077
+ if (!sub) return false;
12078
+ sub.dispose();
12079
+ this.subscriptions.delete(id);
12080
+ return true;
12081
+ }
12082
+ /**
12083
+ * Check if a subscription with the given ID is registered.
12084
+ */
12085
+ has(id) {
12086
+ return this.subscriptions.has(id);
12087
+ }
12088
+ /**
12089
+ * Get the number of active subscriptions.
12090
+ */
12091
+ get count() {
12092
+ return this.subscriptions.size;
12093
+ }
12094
+ /**
12095
+ * Dispose all subscriptions and unsubscribe from the runtime.
12096
+ */
12097
+ dispose() {
12098
+ if (this.disposed) return;
12099
+ this.disposed = true;
12100
+ this.stackUnsub?.();
12101
+ this.stackUnsub = null;
12102
+ this.outputUnsub?.();
12103
+ this.outputUnsub = null;
12104
+ for (const sub of this.subscriptions.values()) {
12105
+ try {
12106
+ sub.dispose();
12107
+ } catch (err) {
12108
+ console.error(`[SubscriptionManager] Error disposing subscription '${sub.id}':`, err);
12109
+ }
12110
+ }
12111
+ this.subscriptions.clear();
12112
+ }
12113
+ };
11601
12114
  function formatMetricLabel(key) {
11602
12115
  return key.charAt(0).toUpperCase() + key.slice(1).replace(/_/g, " ");
11603
12116
  }
@@ -12766,13 +13279,13 @@ function toStoredOutputStatement(output) {
12766
13279
  }
12767
13280
 
12768
13281
  // src/version.ts
12769
- var VERSION = "0.1.5";
12770
- var GIT_SHA = "8c595e1";
12771
- var BUILD_TIME = "2026-08-18T18:07:40.647Z";
13282
+ var VERSION = "0.1.8";
13283
+ var GIT_SHA = "52af1e3";
13284
+ var BUILD_TIME = "2026-08-18T18:19:06.086Z";
12772
13285
  var SEMVER = {
12773
- version: "0.1.5",
12774
- gitSha: "8c595e1",
12775
- buildTime: "2026-08-18T18:07:40.647Z"
13286
+ version: "0.1.8",
13287
+ gitSha: "52af1e3",
13288
+ buildTime: "2026-08-18T18:19:06.086Z"
12776
13289
  };
12777
13290
 
12778
13291
  exports.AbortSessionAction = AbortSessionAction;
@@ -12818,6 +13331,8 @@ exports.HabitsDialect = HabitsDialect;
12818
13331
  exports.INTENSITY_TIERS = INTENSITY_TIERS;
12819
13332
  exports.InMemoryEffortRegistry = InMemoryEffortRegistry;
12820
13333
  exports.JitCompiler = JitCompiler;
13334
+ exports.LocalEventProvider = LocalEventProvider;
13335
+ exports.LocalRuntimeSubscription = LocalRuntimeSubscription;
12821
13336
  exports.LookupRegistry = LookupRegistry;
12822
13337
  exports.MdTimerRuntime = MdTimerRuntime;
12823
13338
  exports.MemoryLocation = MemoryLocation;
@@ -12835,6 +13350,7 @@ exports.PushRestBlockAction = PushRestBlockAction;
12835
13350
  exports.RegisterEventHandlerAction = RegisterEventHandlerAction;
12836
13351
  exports.Registry = Registry;
12837
13352
  exports.RestBlock = RestBlock;
13353
+ exports.RuntimeAdapter = RuntimeAdapter;
12838
13354
  exports.RuntimeBlock = RuntimeBlock;
12839
13355
  exports.RuntimeBuilder = RuntimeBuilder;
12840
13356
  exports.RuntimeClock = RuntimeClock;
@@ -12852,6 +13368,7 @@ exports.SnapshotClock = SnapshotClock;
12852
13368
  exports.StandardAnalyticsProfile = StandardAnalyticsProfile;
12853
13369
  exports.StartSessionAction = StartSessionAction;
12854
13370
  exports.StartWorkoutAction = StartWorkoutAction;
13371
+ exports.SubscriptionManager = SubscriptionManager;
12855
13372
  exports.ThrowError = ThrowError;
12856
13373
  exports.ThrowErrorAction = ThrowErrorAction;
12857
13374
  exports.TimeSpan = TimeSpan;
@@ -12923,6 +13440,7 @@ exports.getRuntimeNowMs = getRuntimeNowMs;
12923
13440
  exports.hasHint = hasHint;
12924
13441
  exports.hintMetric = hintMetric;
12925
13442
  exports.hintsToContainer = hintsToContainer;
13443
+ exports.isCastSubscription = isCastSubscription;
12926
13444
  exports.isEffortDiscipline = isEffortDiscipline;
12927
13445
  exports.isFragmentTag = isFragmentTag;
12928
13446
  exports.isTimeLikeMetric = isTimeLikeMetric;