@turing-machine-js/machine 7.0.0-alpha.5 → 7.0.0-alpha.6

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.mjs CHANGED
@@ -11,13 +11,13 @@ function id(object) {
11
11
  id[idKey] = 0;
12
12
  id[idWeakMapKey] = new WeakMap();
13
13
 
14
- var __classPrivateFieldSet$8 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
14
+ var __classPrivateFieldSet$9 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
15
15
  if (kind === "m") throw new TypeError("Private method is not writable");
16
16
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
17
17
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
18
18
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
19
19
  };
20
- var __classPrivateFieldGet$8 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
20
+ var __classPrivateFieldGet$9 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
21
21
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
22
22
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
23
23
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -37,36 +37,36 @@ class Alphabet {
37
37
  if (!isSymbolsValid) {
38
38
  throw new Error('symbols contains invalid symbol');
39
39
  }
40
- __classPrivateFieldSet$8(this, _Alphabet_symbols, Array.from(uniqueSymbols), "f");
40
+ __classPrivateFieldSet$9(this, _Alphabet_symbols, Array.from(uniqueSymbols), "f");
41
41
  }
42
42
  get symbols() {
43
- return Array.from(__classPrivateFieldGet$8(this, _Alphabet_symbols, "f"));
43
+ return Array.from(__classPrivateFieldGet$9(this, _Alphabet_symbols, "f"));
44
44
  }
45
45
  get blankSymbol() {
46
- return __classPrivateFieldGet$8(this, _Alphabet_symbols, "f")[0];
46
+ return __classPrivateFieldGet$9(this, _Alphabet_symbols, "f")[0];
47
47
  }
48
48
  has(symbol) {
49
- return __classPrivateFieldGet$8(this, _Alphabet_symbols, "f").indexOf(symbol) >= 0;
49
+ return __classPrivateFieldGet$9(this, _Alphabet_symbols, "f").indexOf(symbol) >= 0;
50
50
  }
51
51
  get(index) {
52
- if (index < 0 || index >= __classPrivateFieldGet$8(this, _Alphabet_symbols, "f").length) {
52
+ if (index < 0 || index >= __classPrivateFieldGet$9(this, _Alphabet_symbols, "f").length) {
53
53
  throw new Error('Invalid index');
54
54
  }
55
- return __classPrivateFieldGet$8(this, _Alphabet_symbols, "f")[index];
55
+ return __classPrivateFieldGet$9(this, _Alphabet_symbols, "f")[index];
56
56
  }
57
57
  index(symbol) {
58
- return __classPrivateFieldGet$8(this, _Alphabet_symbols, "f").indexOf(symbol);
58
+ return __classPrivateFieldGet$9(this, _Alphabet_symbols, "f").indexOf(symbol);
59
59
  }
60
60
  }
61
61
  _Alphabet_symbols = new WeakMap();
62
62
 
63
- var __classPrivateFieldSet$7 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
63
+ var __classPrivateFieldSet$8 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
64
64
  if (kind === "m") throw new TypeError("Private method is not writable");
65
65
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
66
66
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
67
67
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
68
68
  };
69
- var __classPrivateFieldGet$7 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
69
+ var __classPrivateFieldGet$8 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
70
70
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
71
71
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
72
72
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -89,30 +89,30 @@ class TapeCommand {
89
89
  if (!isValidMovement) {
90
90
  throw new Error('invalid movement');
91
91
  }
92
- __classPrivateFieldSet$7(this, _TapeCommand_movement, movement, "f");
92
+ __classPrivateFieldSet$8(this, _TapeCommand_movement, movement, "f");
93
93
  const isValidSymbol = ((typeof symbol === 'string' && symbol.length === 1)
94
94
  || [symbolCommands.keep, symbolCommands.erase].includes(symbol));
95
95
  if (!isValidSymbol) {
96
96
  throw new Error('invalid symbol');
97
97
  }
98
- __classPrivateFieldSet$7(this, _TapeCommand_symbol, symbol, "f");
98
+ __classPrivateFieldSet$8(this, _TapeCommand_symbol, symbol, "f");
99
99
  }
100
100
  get symbol() {
101
- return __classPrivateFieldGet$7(this, _TapeCommand_symbol, "f");
101
+ return __classPrivateFieldGet$8(this, _TapeCommand_symbol, "f");
102
102
  }
103
103
  get movement() {
104
- return __classPrivateFieldGet$7(this, _TapeCommand_movement, "f");
104
+ return __classPrivateFieldGet$8(this, _TapeCommand_movement, "f");
105
105
  }
106
106
  }
107
107
  _TapeCommand_movement = new WeakMap(), _TapeCommand_symbol = new WeakMap();
108
108
 
109
- var __classPrivateFieldSet$6 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
109
+ var __classPrivateFieldSet$7 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
110
110
  if (kind === "m") throw new TypeError("Private method is not writable");
111
111
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
112
112
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
113
113
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
114
114
  };
115
- var __classPrivateFieldGet$6 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
115
+ var __classPrivateFieldGet$7 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
116
116
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
117
117
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
118
118
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -125,7 +125,7 @@ class Command {
125
125
  throw new Error('invalid parameter');
126
126
  }
127
127
  try {
128
- __classPrivateFieldSet$6(this, _Command_tapesCommands, tapesCommands.map((tapeCommand) => {
128
+ __classPrivateFieldSet$7(this, _Command_tapesCommands, tapesCommands.map((tapeCommand) => {
129
129
  if (tapeCommand instanceof TapeCommand) {
130
130
  return tapeCommand;
131
131
  }
@@ -137,17 +137,17 @@ class Command {
137
137
  }
138
138
  }
139
139
  get tapesCommands() {
140
- return [...__classPrivateFieldGet$6(this, _Command_tapesCommands, "f")];
140
+ return [...__classPrivateFieldGet$7(this, _Command_tapesCommands, "f")];
141
141
  }
142
142
  }
143
143
  _Command_tapesCommands = new WeakMap();
144
144
 
145
- var __classPrivateFieldGet$5 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
145
+ var __classPrivateFieldGet$6 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
146
146
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
147
147
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
148
148
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
149
149
  };
150
- var __classPrivateFieldSet$5 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
150
+ var __classPrivateFieldSet$6 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
151
151
  if (kind === "m") throw new TypeError("Private method is not writable");
152
152
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
153
153
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
@@ -159,16 +159,16 @@ class Reference {
159
159
  _Reference_referenceBinding.set(this, null);
160
160
  }
161
161
  get ref() {
162
- if (!__classPrivateFieldGet$5(this, _Reference_referenceBinding, "f")) {
162
+ if (!__classPrivateFieldGet$6(this, _Reference_referenceBinding, "f")) {
163
163
  throw new Error('unbounded reference');
164
164
  }
165
- return __classPrivateFieldGet$5(this, _Reference_referenceBinding, "f");
165
+ return __classPrivateFieldGet$6(this, _Reference_referenceBinding, "f");
166
166
  }
167
167
  bind(state) {
168
- if (__classPrivateFieldGet$5(this, _Reference_referenceBinding, "f") == null) {
169
- __classPrivateFieldSet$5(this, _Reference_referenceBinding, state, "f");
168
+ if (__classPrivateFieldGet$6(this, _Reference_referenceBinding, "f") == null) {
169
+ __classPrivateFieldSet$6(this, _Reference_referenceBinding, state, "f");
170
170
  }
171
- return __classPrivateFieldGet$5(this, _Reference_referenceBinding, "f");
171
+ return __classPrivateFieldGet$6(this, _Reference_referenceBinding, "f");
172
172
  }
173
173
  }
174
174
  _Reference_referenceBinding = new WeakMap();
@@ -320,13 +320,13 @@ function decodeWriteSymbol(symbol) {
320
320
  }
321
321
  // Format converters (toMermaid / fromMermaid) live in ./graphFormats.
322
322
 
323
- var __classPrivateFieldSet$4 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
323
+ var __classPrivateFieldSet$5 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
324
324
  if (kind === "m") throw new TypeError("Private method is not writable");
325
325
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
326
326
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
327
327
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
328
328
  };
329
- var __classPrivateFieldGet$4 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
329
+ var __classPrivateFieldGet$5 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
330
330
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
331
331
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
332
332
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -347,65 +347,65 @@ class Tape {
347
347
  if (!isSymbolsValid) {
348
348
  throw new Error('symbolList contains invalid symbol');
349
349
  }
350
- __classPrivateFieldSet$4(this, _Tape_alphabet, new Alphabet(alphabet), "f");
351
- __classPrivateFieldSet$4(this, _Tape_position, position, "f");
352
- __classPrivateFieldSet$4(this, _Tape_viewportWidth, 1, "f");
353
- const initialSymbols = symbols.length === 0 ? [__classPrivateFieldGet$4(this, _Tape_alphabet, "f").blankSymbol] : symbols;
350
+ __classPrivateFieldSet$5(this, _Tape_alphabet, new Alphabet(alphabet), "f");
351
+ __classPrivateFieldSet$5(this, _Tape_position, position, "f");
352
+ __classPrivateFieldSet$5(this, _Tape_viewportWidth, 1, "f");
353
+ const initialSymbols = symbols.length === 0 ? [__classPrivateFieldGet$5(this, _Tape_alphabet, "f").blankSymbol] : symbols;
354
354
  for (const symbol of initialSymbols) {
355
- __classPrivateFieldGet$4(this, _Tape_right, "f").push(__classPrivateFieldGet$4(this, _Tape_alphabet, "f").index(symbol));
355
+ __classPrivateFieldGet$5(this, _Tape_right, "f").push(__classPrivateFieldGet$5(this, _Tape_alphabet, "f").index(symbol));
356
356
  }
357
357
  this.viewportWidth = viewportWidth;
358
358
  }
359
359
  get alphabet() {
360
- return __classPrivateFieldGet$4(this, _Tape_alphabet, "f");
360
+ return __classPrivateFieldGet$5(this, _Tape_alphabet, "f");
361
361
  }
362
362
  get extraCellsCount() {
363
- return (__classPrivateFieldGet$4(this, _Tape_viewportWidth, "f") - 1) / 2;
363
+ return (__classPrivateFieldGet$5(this, _Tape_viewportWidth, "f") - 1) / 2;
364
364
  }
365
365
  get position() {
366
366
  // Public contract: index of the head in the `symbols` array. With the
367
367
  // two-array deque, `#position` is the head's logical position; adding
368
368
  // `#left.length` shifts it back into "index from the leftmost backed cell".
369
- return __classPrivateFieldGet$4(this, _Tape_position, "f") + __classPrivateFieldGet$4(this, _Tape_left, "f").length;
369
+ return __classPrivateFieldGet$5(this, _Tape_position, "f") + __classPrivateFieldGet$5(this, _Tape_left, "f").length;
370
370
  }
371
371
  get symbol() {
372
- return __classPrivateFieldGet$4(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$4(this, _Tape_instances, "m", _Tape_cellAt).call(this, __classPrivateFieldGet$4(this, _Tape_position, "f")));
372
+ return __classPrivateFieldGet$5(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$5(this, _Tape_instances, "m", _Tape_cellAt).call(this, __classPrivateFieldGet$5(this, _Tape_position, "f")));
373
373
  }
374
374
  set symbol(symbol) {
375
- if (!__classPrivateFieldGet$4(this, _Tape_alphabet, "f").has(symbol)) {
375
+ if (!__classPrivateFieldGet$5(this, _Tape_alphabet, "f").has(symbol)) {
376
376
  throw new Error('Invalid symbol');
377
377
  }
378
- const index = __classPrivateFieldGet$4(this, _Tape_alphabet, "f").index(symbol);
379
- if (__classPrivateFieldGet$4(this, _Tape_position, "f") >= 0) {
380
- __classPrivateFieldGet$4(this, _Tape_right, "f")[__classPrivateFieldGet$4(this, _Tape_position, "f")] = index;
378
+ const index = __classPrivateFieldGet$5(this, _Tape_alphabet, "f").index(symbol);
379
+ if (__classPrivateFieldGet$5(this, _Tape_position, "f") >= 0) {
380
+ __classPrivateFieldGet$5(this, _Tape_right, "f")[__classPrivateFieldGet$5(this, _Tape_position, "f")] = index;
381
381
  }
382
382
  else {
383
- __classPrivateFieldGet$4(this, _Tape_left, "f")[-__classPrivateFieldGet$4(this, _Tape_position, "f") - 1] = index;
383
+ __classPrivateFieldGet$5(this, _Tape_left, "f")[-__classPrivateFieldGet$5(this, _Tape_position, "f") - 1] = index;
384
384
  }
385
- __classPrivateFieldSet$4(this, _Tape_viewportDirty, true, "f");
385
+ __classPrivateFieldSet$5(this, _Tape_viewportDirty, true, "f");
386
386
  }
387
387
  get symbols() {
388
- const result = new Array(__classPrivateFieldGet$4(this, _Tape_left, "f").length + __classPrivateFieldGet$4(this, _Tape_right, "f").length);
389
- for (let i = 0; i < __classPrivateFieldGet$4(this, _Tape_left, "f").length; i += 1) {
390
- result[i] = __classPrivateFieldGet$4(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$4(this, _Tape_left, "f")[__classPrivateFieldGet$4(this, _Tape_left, "f").length - 1 - i]);
388
+ const result = new Array(__classPrivateFieldGet$5(this, _Tape_left, "f").length + __classPrivateFieldGet$5(this, _Tape_right, "f").length);
389
+ for (let i = 0; i < __classPrivateFieldGet$5(this, _Tape_left, "f").length; i += 1) {
390
+ result[i] = __classPrivateFieldGet$5(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$5(this, _Tape_left, "f")[__classPrivateFieldGet$5(this, _Tape_left, "f").length - 1 - i]);
391
391
  }
392
- for (let i = 0; i < __classPrivateFieldGet$4(this, _Tape_right, "f").length; i += 1) {
393
- result[__classPrivateFieldGet$4(this, _Tape_left, "f").length + i] = __classPrivateFieldGet$4(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$4(this, _Tape_right, "f")[i]);
392
+ for (let i = 0; i < __classPrivateFieldGet$5(this, _Tape_right, "f").length; i += 1) {
393
+ result[__classPrivateFieldGet$5(this, _Tape_left, "f").length + i] = __classPrivateFieldGet$5(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$5(this, _Tape_right, "f")[i]);
394
394
  }
395
395
  return result;
396
396
  }
397
397
  get viewport() {
398
- if (__classPrivateFieldGet$4(this, _Tape_viewportDirty, "f")) {
399
- const start = __classPrivateFieldGet$4(this, _Tape_position, "f") - this.extraCellsCount;
400
- for (let i = 0; i < __classPrivateFieldGet$4(this, _Tape_viewportWidth, "f"); i += 1) {
401
- __classPrivateFieldGet$4(this, _Tape_viewportBuffer, "f")[i] = __classPrivateFieldGet$4(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$4(this, _Tape_instances, "m", _Tape_cellAt).call(this, start + i));
398
+ if (__classPrivateFieldGet$5(this, _Tape_viewportDirty, "f")) {
399
+ const start = __classPrivateFieldGet$5(this, _Tape_position, "f") - this.extraCellsCount;
400
+ for (let i = 0; i < __classPrivateFieldGet$5(this, _Tape_viewportWidth, "f"); i += 1) {
401
+ __classPrivateFieldGet$5(this, _Tape_viewportBuffer, "f")[i] = __classPrivateFieldGet$5(this, _Tape_alphabet, "f").get(__classPrivateFieldGet$5(this, _Tape_instances, "m", _Tape_cellAt).call(this, start + i));
402
402
  }
403
- __classPrivateFieldSet$4(this, _Tape_viewportDirty, false, "f");
403
+ __classPrivateFieldSet$5(this, _Tape_viewportDirty, false, "f");
404
404
  }
405
- return [...__classPrivateFieldGet$4(this, _Tape_viewportBuffer, "f")];
405
+ return [...__classPrivateFieldGet$5(this, _Tape_viewportBuffer, "f")];
406
406
  }
407
407
  get viewportWidth() {
408
- return __classPrivateFieldGet$4(this, _Tape_viewportWidth, "f");
408
+ return __classPrivateFieldGet$5(this, _Tape_viewportWidth, "f");
409
409
  }
410
410
  set viewportWidth(width) {
411
411
  let finalWidth = width;
@@ -415,46 +415,46 @@ class Tape {
415
415
  if (finalWidth % 2 === 0) {
416
416
  finalWidth += 1;
417
417
  }
418
- __classPrivateFieldSet$4(this, _Tape_viewportWidth, finalWidth, "f");
419
- __classPrivateFieldGet$4(this, _Tape_viewportBuffer, "f").length = finalWidth;
420
- __classPrivateFieldSet$4(this, _Tape_viewportDirty, true, "f");
418
+ __classPrivateFieldSet$5(this, _Tape_viewportWidth, finalWidth, "f");
419
+ __classPrivateFieldGet$5(this, _Tape_viewportBuffer, "f").length = finalWidth;
420
+ __classPrivateFieldSet$5(this, _Tape_viewportDirty, true, "f");
421
421
  this.normalise();
422
422
  }
423
423
  left() {
424
- __classPrivateFieldSet$4(this, _Tape_position, __classPrivateFieldGet$4(this, _Tape_position, "f") - 1, "f");
424
+ __classPrivateFieldSet$5(this, _Tape_position, __classPrivateFieldGet$5(this, _Tape_position, "f") - 1, "f");
425
425
  this.normalise();
426
- __classPrivateFieldSet$4(this, _Tape_viewportDirty, true, "f");
426
+ __classPrivateFieldSet$5(this, _Tape_viewportDirty, true, "f");
427
427
  }
428
428
  normalise() {
429
- const minLogical = __classPrivateFieldGet$4(this, _Tape_position, "f") - this.extraCellsCount;
430
- const maxLogical = __classPrivateFieldGet$4(this, _Tape_position, "f") + this.extraCellsCount;
431
- while (-__classPrivateFieldGet$4(this, _Tape_left, "f").length > minLogical) {
432
- __classPrivateFieldGet$4(this, _Tape_left, "f").push(BLANK_INDEX);
429
+ const minLogical = __classPrivateFieldGet$5(this, _Tape_position, "f") - this.extraCellsCount;
430
+ const maxLogical = __classPrivateFieldGet$5(this, _Tape_position, "f") + this.extraCellsCount;
431
+ while (-__classPrivateFieldGet$5(this, _Tape_left, "f").length > minLogical) {
432
+ __classPrivateFieldGet$5(this, _Tape_left, "f").push(BLANK_INDEX);
433
433
  }
434
- while (__classPrivateFieldGet$4(this, _Tape_right, "f").length - 1 < maxLogical) {
435
- __classPrivateFieldGet$4(this, _Tape_right, "f").push(BLANK_INDEX);
434
+ while (__classPrivateFieldGet$5(this, _Tape_right, "f").length - 1 < maxLogical) {
435
+ __classPrivateFieldGet$5(this, _Tape_right, "f").push(BLANK_INDEX);
436
436
  }
437
437
  }
438
438
  right() {
439
- __classPrivateFieldSet$4(this, _Tape_position, __classPrivateFieldGet$4(this, _Tape_position, "f") + 1, "f");
439
+ __classPrivateFieldSet$5(this, _Tape_position, __classPrivateFieldGet$5(this, _Tape_position, "f") + 1, "f");
440
440
  this.normalise();
441
- __classPrivateFieldSet$4(this, _Tape_viewportDirty, true, "f");
441
+ __classPrivateFieldSet$5(this, _Tape_viewportDirty, true, "f");
442
442
  }
443
443
  }
444
444
  _Tape_alphabet = new WeakMap(), _Tape_right = new WeakMap(), _Tape_left = new WeakMap(), _Tape_position = new WeakMap(), _Tape_viewportWidth = new WeakMap(), _Tape_viewportBuffer = new WeakMap(), _Tape_viewportDirty = new WeakMap(), _Tape_instances = new WeakSet(), _Tape_cellAt = function _Tape_cellAt(logical) {
445
445
  if (logical >= 0) {
446
- return logical < __classPrivateFieldGet$4(this, _Tape_right, "f").length ? __classPrivateFieldGet$4(this, _Tape_right, "f")[logical] : BLANK_INDEX;
446
+ return logical < __classPrivateFieldGet$5(this, _Tape_right, "f").length ? __classPrivateFieldGet$5(this, _Tape_right, "f")[logical] : BLANK_INDEX;
447
447
  }
448
448
  const ix = -logical - 1;
449
- return ix < __classPrivateFieldGet$4(this, _Tape_left, "f").length ? __classPrivateFieldGet$4(this, _Tape_left, "f")[ix] : BLANK_INDEX;
449
+ return ix < __classPrivateFieldGet$5(this, _Tape_left, "f").length ? __classPrivateFieldGet$5(this, _Tape_left, "f")[ix] : BLANK_INDEX;
450
450
  };
451
451
 
452
- var __classPrivateFieldGet$3 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
452
+ var __classPrivateFieldGet$4 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
453
453
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
454
454
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
455
455
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
456
456
  };
457
- var __classPrivateFieldSet$3 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
457
+ var __classPrivateFieldSet$4 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
458
458
  if (kind === "m") throw new TypeError("Private method is not writable");
459
459
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
460
460
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
@@ -466,30 +466,30 @@ class Lock {
466
466
  _Lock_lockSymbol.set(this, null);
467
467
  }
468
468
  lock(symbol) {
469
- if (__classPrivateFieldGet$3(this, _Lock_lockSymbol, "f") === null) {
470
- __classPrivateFieldSet$3(this, _Lock_lockSymbol, symbol, "f");
469
+ if (__classPrivateFieldGet$4(this, _Lock_lockSymbol, "f") === null) {
470
+ __classPrivateFieldSet$4(this, _Lock_lockSymbol, symbol, "f");
471
471
  }
472
472
  }
473
473
  unlock(symbol) {
474
- if (__classPrivateFieldGet$3(this, _Lock_lockSymbol, "f") === symbol) {
475
- __classPrivateFieldSet$3(this, _Lock_lockSymbol, null, "f");
474
+ if (__classPrivateFieldGet$4(this, _Lock_lockSymbol, "f") === symbol) {
475
+ __classPrivateFieldSet$4(this, _Lock_lockSymbol, null, "f");
476
476
  }
477
477
  }
478
478
  check(symbol) {
479
- if (__classPrivateFieldGet$3(this, _Lock_lockSymbol, "f") && __classPrivateFieldGet$3(this, _Lock_lockSymbol, "f") !== symbol) {
479
+ if (__classPrivateFieldGet$4(this, _Lock_lockSymbol, "f") && __classPrivateFieldGet$4(this, _Lock_lockSymbol, "f") !== symbol) {
480
480
  throw new Error('Lock check failed');
481
481
  }
482
482
  }
483
483
  }
484
484
  _Lock_lockSymbol = new WeakMap();
485
485
 
486
- var __classPrivateFieldSet$2 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
486
+ var __classPrivateFieldSet$3 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
487
487
  if (kind === "m") throw new TypeError("Private method is not writable");
488
488
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
489
489
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
490
490
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
491
491
  };
492
- var __classPrivateFieldGet$2 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
492
+ var __classPrivateFieldGet$3 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
493
493
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
494
494
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
495
495
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -503,7 +503,7 @@ class TapeBlock {
503
503
  _TapeBlock_lock.set(this, new Lock());
504
504
  _TapeBlock_tapes.set(this, void 0);
505
505
  _TapeBlock_buildPatternList.set(this, (symbolList) => symbolList.reduce((result, symbol, ix) => {
506
- const row = Math.floor(ix / __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").length);
506
+ const row = Math.floor(ix / __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").length);
507
507
  if (!Array.isArray(result[row])) {
508
508
  result[row] = [];
509
509
  }
@@ -519,7 +519,7 @@ class TapeBlock {
519
519
  if (patternList.some((pattern) => pattern.every((symbol) => symbol === ifOtherSymbol))) {
520
520
  return ifOtherSymbol;
521
521
  }
522
- const [storedPatternListSymbol] = [...__classPrivateFieldGet$2(this, _TapeBlock_symbolToPatternListMap, "f").entries()]
522
+ const [storedPatternListSymbol] = [...__classPrivateFieldGet$3(this, _TapeBlock_symbolToPatternListMap, "f").entries()]
523
523
  .find(([, storedPatternList]) => {
524
524
  if (storedPatternList.length !== patternList.length) {
525
525
  return false;
@@ -533,8 +533,8 @@ class TapeBlock {
533
533
  symbol = storedPatternListSymbol;
534
534
  }
535
535
  else {
536
- symbol = Symbol(__classPrivateFieldGet$2(_a$1, _a$1, "f", _TapeBlock_generateSymbolHint).call(_a$1, patternList));
537
- __classPrivateFieldGet$2(this, _TapeBlock_symbolToPatternListMap, "f").set(symbol, patternList);
536
+ symbol = Symbol(__classPrivateFieldGet$3(_a$1, _a$1, "f", _TapeBlock_generateSymbolHint).call(_a$1, patternList));
537
+ __classPrivateFieldGet$3(this, _TapeBlock_symbolToPatternListMap, "f").set(symbol, patternList);
538
538
  }
539
539
  return symbol;
540
540
  });
@@ -549,60 +549,60 @@ class TapeBlock {
549
549
  else if (Array.isArray(symbols)) {
550
550
  localSymbols = [...symbols];
551
551
  }
552
- if (localSymbols.length === 0 || localSymbols.length % __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").length > 0) {
552
+ if (localSymbols.length === 0 || localSymbols.length % __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").length > 0) {
553
553
  throw new Error('invalid symbol parameter');
554
554
  }
555
555
  const invalidSymbolIndex = localSymbols.findIndex((symbol, ix) => (symbol !== ifOtherSymbol
556
- && !__classPrivateFieldGet$2(this, _TapeBlock_tapes, "f")[ix % __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").length].alphabet.has(symbol)));
556
+ && !__classPrivateFieldGet$3(this, _TapeBlock_tapes, "f")[ix % __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").length].alphabet.has(symbol)));
557
557
  if (invalidSymbolIndex >= 0) {
558
558
  throw new Error('invalid symbol parameter');
559
559
  }
560
560
  if (localSymbols.every((symbol) => symbol === ifOtherSymbol)) {
561
561
  return ifOtherSymbol;
562
562
  }
563
- return __classPrivateFieldGet$2(this, _TapeBlock_getSymbolForPatternList, "f").call(this, __classPrivateFieldGet$2(this, _TapeBlock_buildPatternList, "f").call(this, localSymbols));
563
+ return __classPrivateFieldGet$3(this, _TapeBlock_getSymbolForPatternList, "f").call(this, __classPrivateFieldGet$3(this, _TapeBlock_buildPatternList, "f").call(this, localSymbols));
564
564
  });
565
- __classPrivateFieldSet$2(this, _TapeBlock_tapes, [], "f");
565
+ __classPrivateFieldSet$3(this, _TapeBlock_tapes, [], "f");
566
566
  if ('alphabets' in argument) {
567
567
  const { alphabets } = argument;
568
568
  if (alphabets.length === 0) {
569
569
  throw new Error('empty alphabet list');
570
570
  }
571
- __classPrivateFieldSet$2(this, _TapeBlock_tapes, alphabets.map((alphabet) => new Tape({
571
+ __classPrivateFieldSet$3(this, _TapeBlock_tapes, alphabets.map((alphabet) => new Tape({
572
572
  alphabet,
573
573
  })), "f");
574
574
  }
575
575
  else if ('tapes' in argument) {
576
- __classPrivateFieldSet$2(this, _TapeBlock_tapes, argument.tapes, "f");
576
+ __classPrivateFieldSet$3(this, _TapeBlock_tapes, argument.tapes, "f");
577
577
  }
578
- if (__classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").length === 0) {
578
+ if (__classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").length === 0) {
579
579
  throw new Error('empty tape list');
580
580
  }
581
581
  }
582
582
  get alphabets() {
583
- return [...__classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").map((tape) => tape.alphabet)];
583
+ return [...__classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").map((tape) => tape.alphabet)];
584
584
  }
585
585
  get currentSymbols() {
586
- return __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").map((tape) => tape.symbol);
586
+ return __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").map((tape) => tape.symbol);
587
587
  }
588
588
  get [(_TapeBlock_symbolToPatternListMap = new WeakMap(), _TapeBlock_lock = new WeakMap(), _TapeBlock_tapes = new WeakMap(), _TapeBlock_buildPatternList = new WeakMap(), _TapeBlock_getSymbolForPatternList = new WeakMap(), _TapeBlock_symbol = new WeakMap(), lockSymbol)]() {
589
- return __classPrivateFieldGet$2(this, _TapeBlock_lock, "f");
589
+ return __classPrivateFieldGet$3(this, _TapeBlock_lock, "f");
590
590
  }
591
591
  get symbol() {
592
- return __classPrivateFieldGet$2(this, _TapeBlock_symbol, "f").bind(this);
592
+ return __classPrivateFieldGet$3(this, _TapeBlock_symbol, "f").bind(this);
593
593
  }
594
594
  get tapes() {
595
- return [...__classPrivateFieldGet$2(this, _TapeBlock_tapes, "f")];
595
+ return [...__classPrivateFieldGet$3(this, _TapeBlock_tapes, "f")];
596
596
  }
597
597
  set [symbolToPatternListMapSymbol](symbolToPatternListMap) {
598
- __classPrivateFieldSet$2(this, _TapeBlock_symbolToPatternListMap, new Map(symbolToPatternListMap), "f");
598
+ __classPrivateFieldSet$3(this, _TapeBlock_symbolToPatternListMap, new Map(symbolToPatternListMap), "f");
599
599
  }
600
600
  applyCommand(command, executionSymbol = null) {
601
- __classPrivateFieldGet$2(this, _TapeBlock_lock, "f").check(executionSymbol);
602
- if (__classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").length !== command.tapesCommands.length) {
601
+ __classPrivateFieldGet$3(this, _TapeBlock_lock, "f").check(executionSymbol);
602
+ if (__classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").length !== command.tapesCommands.length) {
603
603
  throw new Error('invalid command');
604
604
  }
605
- __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").forEach((tape, ix) => {
605
+ __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").forEach((tape, ix) => {
606
606
  const { movement, symbol } = command.tapesCommands[ix];
607
607
  if (typeof symbol === 'string') {
608
608
  tape.symbol = symbol;
@@ -638,17 +638,17 @@ class TapeBlock {
638
638
  else {
639
639
  tapeBlock = _a$1.fromAlphabets(this.alphabets);
640
640
  }
641
- tapeBlock[symbolToPatternListMapSymbol] = __classPrivateFieldGet$2(this, _TapeBlock_symbolToPatternListMap, "f");
641
+ tapeBlock[symbolToPatternListMapSymbol] = __classPrivateFieldGet$3(this, _TapeBlock_symbolToPatternListMap, "f");
642
642
  return tapeBlock;
643
643
  }
644
644
  isMatched({ currentSymbols = this.currentSymbols, symbol }) {
645
645
  if (symbol === ifOtherSymbol) {
646
646
  return true;
647
647
  }
648
- if (!__classPrivateFieldGet$2(this, _TapeBlock_symbolToPatternListMap, "f").has(symbol)) {
648
+ if (!__classPrivateFieldGet$3(this, _TapeBlock_symbolToPatternListMap, "f").has(symbol)) {
649
649
  throw new Error('invalid symbol');
650
650
  }
651
- const patternList = __classPrivateFieldGet$2(this, _TapeBlock_symbolToPatternListMap, "f").get(symbol);
651
+ const patternList = __classPrivateFieldGet$3(this, _TapeBlock_symbolToPatternListMap, "f").get(symbol);
652
652
  return patternList?.some((pattern) => (pattern
653
653
  .every((everySymbol, ix) => (everySymbol === ifOtherSymbol
654
654
  || everySymbol === currentSymbols[ix])))) ?? false;
@@ -678,11 +678,11 @@ class TapeBlock {
678
678
  * the State's normal matching): fall back to all `'literal'`.
679
679
  */
680
680
  patternKinds(symbol, currentSymbols = this.currentSymbols) {
681
- const tapeCount = __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f").length;
681
+ const tapeCount = __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f").length;
682
682
  if (symbol === ifOtherSymbol) {
683
683
  return Array.from({ length: tapeCount }, () => 'wildcard');
684
684
  }
685
- const patternList = __classPrivateFieldGet$2(this, _TapeBlock_symbolToPatternListMap, "f").get(symbol);
685
+ const patternList = __classPrivateFieldGet$3(this, _TapeBlock_symbolToPatternListMap, "f").get(symbol);
686
686
  if (patternList === undefined) {
687
687
  return Array.from({ length: tapeCount }, () => 'literal');
688
688
  }
@@ -694,11 +694,11 @@ class TapeBlock {
694
694
  return winning.map((everySymbol) => (everySymbol === ifOtherSymbol ? 'wildcard' : 'literal'));
695
695
  }
696
696
  replaceTape(tape, tapeIx = 0) {
697
- if (__classPrivateFieldGet$2(this, _TapeBlock_tapes, "f")[tapeIx] == null) {
697
+ if (__classPrivateFieldGet$3(this, _TapeBlock_tapes, "f")[tapeIx] == null) {
698
698
  throw new Error('invalid tapeIx');
699
699
  }
700
- if (tape.alphabet.symbols.join('') === __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f")[tapeIx].alphabet.symbols.join('')) {
701
- __classPrivateFieldGet$2(this, _TapeBlock_tapes, "f")[tapeIx] = tape;
700
+ if (tape.alphabet.symbols.join('') === __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f")[tapeIx].alphabet.symbols.join('')) {
701
+ __classPrivateFieldGet$3(this, _TapeBlock_tapes, "f")[tapeIx] = tape;
702
702
  }
703
703
  else {
704
704
  throw new Error('invalid tape');
@@ -716,16 +716,11 @@ _TapeBlock_generateSymbolHint = { value: (patternList) => JSON.stringify(pattern
716
716
  .map((pattern) => pattern
717
717
  .map((symbol) => (symbol === ifOtherSymbol ? null : symbol)))) };
718
718
 
719
- // Graph serialization/reconstruction for State graphs. Extracted from
720
- // `classes/State.ts` (#180) so the State class stays focused on the runtime
721
- // machinery (transitions, debug, halt-stack composition). Sibling-module
722
- // private access to State's internals goes through the `STATE_INTERNAL`
719
+ // Graph serialization/reconstruction + state collection for State graphs.
720
+ // Sibling-module access to State's internals uses the `STATE_INTERNAL`
723
721
  // Symbol re-exported from State.ts — see the @internal JSDoc there.
724
- //
725
- // Public surface is preserved: `State.toGraph` and `State.fromGraph` static
726
- // methods continue to exist as thin delegates to the functions in this
727
- // module. New consumers (e.g. #195's planned `collectStates`) will live
728
- // here too and share the BFS-walk shape with `toGraph`.
722
+ // `State.toGraph` / `.fromGraph` / `.collectStates` static methods on
723
+ // State are thin delegates to functions in this module.
729
724
  /**
730
725
  * Walks the reachable graph from `initialState` and returns a serializable
731
726
  * `Graph`. The walk is a BFS that visits each State exactly once (keyed by
@@ -827,13 +822,11 @@ function toGraph(initialState, tapeBlock) {
827
822
  movement: decodeMovement(tc.movement.description),
828
823
  })),
829
824
  nextStateId: targetInternal.id,
830
- // Transition id format: `${stateId}.${transitionIx}` (#205).
831
- // Matches `TuringMachine.runStepByStep`'s `MachineState.
832
- // matchedTransition.id` so consumers can do
825
+ // `${stateId}.${transitionIx}` — matches
826
+ // `MachineState.matchedTransition.id` so consumers can do
833
827
  // `graph.nodes[stateId].transitions.find(t => t.id === id)`.
834
- // Was `${stateId}-${ix}` pre-#205 the `.` separator avoids
835
- // the hyphen reading as a minus sign next to negative halt-
836
- // marker ids in adjacent contexts.
828
+ // `.` separator (vs `-`) avoids collision with negative
829
+ // halt-marker ids.
837
830
  id: `${stateInternal.id}.${patternIx}`,
838
831
  });
839
832
  queue.push(target);
@@ -1234,13 +1227,13 @@ function collectStates(initialState, tapeBlock) {
1234
1227
  // source module finishes evaluating. All references here live inside
1235
1228
  // function bodies, so the cycle is safe.
1236
1229
 
1237
- var __classPrivateFieldSet$1 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1230
+ var __classPrivateFieldSet$2 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1238
1231
  if (kind === "m") throw new TypeError("Private method is not writable");
1239
1232
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1240
1233
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1241
1234
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1242
1235
  };
1243
- var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1236
+ var __classPrivateFieldGet$2 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1244
1237
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1245
1238
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1246
1239
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
@@ -1277,7 +1270,7 @@ class DebugConfig {
1277
1270
  _DebugConfig_ownerState.set(this, void 0);
1278
1271
  _DebugConfig_before.set(this, void 0);
1279
1272
  _DebugConfig_after.set(this, void 0);
1280
- __classPrivateFieldSet$1(this, _DebugConfig_ownerState, ownerState, "f");
1273
+ __classPrivateFieldSet$2(this, _DebugConfig_ownerState, ownerState, "f");
1281
1274
  if (initial) {
1282
1275
  if (initial.before !== undefined) {
1283
1276
  this.before = initial.before;
@@ -1294,18 +1287,18 @@ class DebugConfig {
1294
1287
  Object.seal(this);
1295
1288
  }
1296
1289
  get before() {
1297
- return __classPrivateFieldGet$1(this, _DebugConfig_before, "f");
1290
+ return __classPrivateFieldGet$2(this, _DebugConfig_before, "f");
1298
1291
  }
1299
1292
  set before(v) {
1300
- __classPrivateFieldGet$1(this, _DebugConfig_ownerState, "f")[validateDebugFilter]('before', v);
1301
- __classPrivateFieldSet$1(this, _DebugConfig_before, Array.isArray(v) ? Object.freeze([...v]) : v, "f");
1293
+ __classPrivateFieldGet$2(this, _DebugConfig_ownerState, "f")[validateDebugFilter]('before', v);
1294
+ __classPrivateFieldSet$2(this, _DebugConfig_before, Array.isArray(v) ? Object.freeze([...v]) : v, "f");
1302
1295
  }
1303
1296
  get after() {
1304
- return __classPrivateFieldGet$1(this, _DebugConfig_after, "f");
1297
+ return __classPrivateFieldGet$2(this, _DebugConfig_after, "f");
1305
1298
  }
1306
1299
  set after(v) {
1307
- __classPrivateFieldGet$1(this, _DebugConfig_ownerState, "f")[validateDebugFilter]('after', v);
1308
- __classPrivateFieldSet$1(this, _DebugConfig_after, Array.isArray(v) ? Object.freeze([...v]) : v, "f");
1300
+ __classPrivateFieldGet$2(this, _DebugConfig_ownerState, "f")[validateDebugFilter]('after', v);
1301
+ __classPrivateFieldSet$2(this, _DebugConfig_after, Array.isArray(v) ? Object.freeze([...v]) : v, "f");
1309
1302
  }
1310
1303
  }
1311
1304
  _DebugConfig_ownerState = new WeakMap(), _DebugConfig_before = new WeakMap(), _DebugConfig_after = new WeakMap();
@@ -1320,8 +1313,8 @@ class State {
1320
1313
  _State_overriddenHaltState.set(this, null);
1321
1314
  // For wrapper states (produced by `withOverriddenHaltState`), points at the
1322
1315
  // State whose transition map was wrapped. `null` on bare/atomic states.
1323
- // Used by `toGraph` to collapse the wrapper-and-its-bare pair into a single
1324
- // "wrapped bare" graph node — see the v7 emit redesign for #138.
1316
+ // `toGraph` reads this to render wrapper and bare as separate nodes linked
1317
+ // by a `==> call` arrow.
1325
1318
  _State_bareState.set(this, null);
1326
1319
  _State_symbolToDataMap.set(this, new Map());
1327
1320
  // Shared mutable cell — withOverriddenHaltState wrappers reference the same
@@ -1348,11 +1341,11 @@ class State {
1348
1341
  if (stateDefinition) {
1349
1342
  const keys = Object.getOwnPropertyNames(stateDefinition);
1350
1343
  if (keys.length) {
1351
- throw new Error(`invalid state definition while constructing state #${__classPrivateFieldGet$1(this, _State_id, "f")}`);
1344
+ throw new Error(`invalid state definition while constructing state #${__classPrivateFieldGet$2(this, _State_id, "f")}`);
1352
1345
  }
1353
1346
  const symbols = Object.getOwnPropertySymbols(stateDefinition);
1354
1347
  if (symbols.length === 0) {
1355
- throw new Error(`invalid state definition while constructing state #${__classPrivateFieldGet$1(this, _State_id, "f")}`);
1348
+ throw new Error(`invalid state definition while constructing state #${__classPrivateFieldGet$2(this, _State_id, "f")}`);
1356
1349
  }
1357
1350
  symbols.forEach((symbol) => {
1358
1351
  const { nextState } = stateDefinition[symbol];
@@ -1380,7 +1373,7 @@ class State {
1380
1373
  if (!(commandLocal instanceof Command)) {
1381
1374
  throw new Error('invalid command');
1382
1375
  }
1383
- __classPrivateFieldGet$1(this, _State_symbolToDataMap, "f").set(symbol, {
1376
+ __classPrivateFieldGet$2(this, _State_symbolToDataMap, "f").set(symbol, {
1384
1377
  command: commandLocal,
1385
1378
  nextState: nextStateLocal,
1386
1379
  });
@@ -1389,19 +1382,19 @@ class State {
1389
1382
  if (name !== undefined && /[()]/.test(name)) {
1390
1383
  throw new Error(`invalid state name "${name}": must not contain '(' or ')' (reserved as wrapper-composition delimiters in withOverriddenHaltState)`);
1391
1384
  }
1392
- __classPrivateFieldSet$1(this, _State_name, name ?? `id:${__classPrivateFieldGet$1(this, _State_id, "f")}`, "f");
1385
+ __classPrivateFieldSet$2(this, _State_name, name ?? `id:${__classPrivateFieldGet$2(this, _State_id, "f")}`, "f");
1393
1386
  }
1394
1387
  get id() {
1395
- return __classPrivateFieldGet$1(this, _State_id, "f");
1388
+ return __classPrivateFieldGet$2(this, _State_id, "f");
1396
1389
  }
1397
1390
  get name() {
1398
- return __classPrivateFieldGet$1(this, _State_name, "f");
1391
+ return __classPrivateFieldGet$2(this, _State_name, "f");
1399
1392
  }
1400
1393
  get isHalt() {
1401
- return __classPrivateFieldGet$1(this, _State_id, "f") === 0;
1394
+ return __classPrivateFieldGet$2(this, _State_id, "f") === 0;
1402
1395
  }
1403
1396
  get overriddenHaltState() {
1404
- return __classPrivateFieldGet$1(this, _State_overriddenHaltState, "f");
1397
+ return __classPrivateFieldGet$2(this, _State_overriddenHaltState, "f");
1405
1398
  }
1406
1399
  get ref() {
1407
1400
  return this;
@@ -1416,17 +1409,17 @@ class State {
1416
1409
  // declared `DebugConfig` for any rare caller that holds a State
1417
1410
  // reference happening to be haltState.
1418
1411
  if (this.isHalt) {
1419
- return __classPrivateFieldGet$1(this, _State_haltDebug, "f");
1412
+ return __classPrivateFieldGet$2(this, _State_haltDebug, "f");
1420
1413
  }
1421
1414
  // Lazy-init: `state.debug` is never null at read time, so chained writes
1422
1415
  // like `state.debug.before = true` work on a fresh state without a prior
1423
1416
  // whole-object assignment. The setter still accepts `null` to reset the
1424
1417
  // filters; the next read recreates a fresh empty `DebugConfig` on demand.
1425
1418
  // See #150.
1426
- if (__classPrivateFieldGet$1(this, _State_debugRef, "f").current === null) {
1427
- __classPrivateFieldGet$1(this, _State_debugRef, "f").current = new DebugConfig(this);
1419
+ if (__classPrivateFieldGet$2(this, _State_debugRef, "f").current === null) {
1420
+ __classPrivateFieldGet$2(this, _State_debugRef, "f").current = new DebugConfig(this);
1428
1421
  }
1429
- return __classPrivateFieldGet$1(this, _State_debugRef, "f").current;
1422
+ return __classPrivateFieldGet$2(this, _State_debugRef, "f").current;
1430
1423
  }
1431
1424
  // TS signature: non-halt callers (generic `State` reference) get the
1432
1425
  // `DebugConfig | object | null` surface; boolean is rejected statically.
@@ -1445,7 +1438,7 @@ class State {
1445
1438
  // (no own iter to anchor on; halt is terminal).
1446
1439
  if (this.isHalt) {
1447
1440
  if (v === null || typeof v === 'boolean') {
1448
- __classPrivateFieldSet$1(this, _State_haltDebug, v === true, "f");
1441
+ __classPrivateFieldSet$2(this, _State_haltDebug, v === true, "f");
1449
1442
  return;
1450
1443
  }
1451
1444
  throw new Error('haltState.debug only accepts boolean (or null to reset). Use '
@@ -1461,14 +1454,14 @@ class State {
1461
1454
  + '(or null to reset). Boolean assignment is reserved for `haltState`.');
1462
1455
  }
1463
1456
  if (v === null) {
1464
- __classPrivateFieldGet$1(this, _State_debugRef, "f").current = null;
1457
+ __classPrivateFieldGet$2(this, _State_debugRef, "f").current = null;
1465
1458
  return;
1466
1459
  }
1467
1460
  if (v instanceof DebugConfig) {
1468
- __classPrivateFieldGet$1(this, _State_debugRef, "f").current = v;
1461
+ __classPrivateFieldGet$2(this, _State_debugRef, "f").current = v;
1469
1462
  return;
1470
1463
  }
1471
- __classPrivateFieldGet$1(this, _State_debugRef, "f").current = new DebugConfig(this, v);
1464
+ __classPrivateFieldGet$2(this, _State_debugRef, "f").current = new DebugConfig(this, v);
1472
1465
  }
1473
1466
  /**
1474
1467
  * Add one or more tags to this State (#186). Tags are out-of-band metadata
@@ -1478,7 +1471,7 @@ class State {
1478
1471
  */
1479
1472
  tag(...tags) {
1480
1473
  for (const t of tags) {
1481
- __classPrivateFieldGet$1(this, _State_tags, "f").add(t);
1474
+ __classPrivateFieldGet$2(this, _State_tags, "f").add(t);
1482
1475
  }
1483
1476
  return this;
1484
1477
  }
@@ -1488,7 +1481,7 @@ class State {
1488
1481
  */
1489
1482
  untag(...tags) {
1490
1483
  for (const t of tags) {
1491
- __classPrivateFieldGet$1(this, _State_tags, "f").delete(t);
1484
+ __classPrivateFieldGet$2(this, _State_tags, "f").delete(t);
1492
1485
  }
1493
1486
  return this;
1494
1487
  }
@@ -1498,27 +1491,26 @@ class State {
1498
1491
  * code uses). Order matches insertion order of the underlying Set.
1499
1492
  */
1500
1493
  get tags() {
1501
- return Object.freeze([...__classPrivateFieldGet$1(this, _State_tags, "f")]);
1494
+ return Object.freeze([...__classPrivateFieldGet$2(this, _State_tags, "f")]);
1502
1495
  }
1503
1496
  /** @internal — invoked by DebugConfig setters via module-private symbol.
1504
- * Per #207, haltState no longer flows through DebugConfig (its `debug`
1505
- * setter rejects object writes before construction), so the validator
1506
- * only sees non-halt states here. */
1497
+ * haltState's `debug` setter rejects object writes before reaching
1498
+ * DebugConfig, so this validator only sees non-halt states. */
1507
1499
  [(_State_id = new WeakMap(), _State_name = new WeakMap(), _State_overriddenHaltState = new WeakMap(), _State_bareState = new WeakMap(), _State_symbolToDataMap = new WeakMap(), _State_debugRef = new WeakMap(), _State_haltDebug = new WeakMap(), _State_tags = new WeakMap(), _State_instances = new WeakSet(), validateDebugFilter)](fieldName, filter) {
1508
1500
  if (filter === undefined)
1509
1501
  return;
1510
1502
  if (filter === true)
1511
1503
  return;
1512
1504
  for (const sym of filter) {
1513
- if (sym !== ifOtherSymbol && !__classPrivateFieldGet$1(this, _State_symbolToDataMap, "f").has(sym)) {
1505
+ if (sym !== ifOtherSymbol && !__classPrivateFieldGet$2(this, _State_symbolToDataMap, "f").has(sym)) {
1514
1506
  throw new Error(`State.debug.${fieldName}: symbol is not a transition key of this state `
1515
- + `(state name: ${__classPrivateFieldGet$1(this, _State_name, "f")}). Common cause: symbol comes from a `
1507
+ + `(state name: ${__classPrivateFieldGet$2(this, _State_name, "f")}). Common cause: symbol comes from a `
1516
1508
  + 'different tape block, or doesn\'t match any of this state\'s transitions.');
1517
1509
  }
1518
1510
  }
1519
1511
  }
1520
1512
  getSymbol(tapeBlock) {
1521
- const symbol = [...__classPrivateFieldGet$1(this, _State_symbolToDataMap, "f").keys()].find((currentSymbol) => tapeBlock.isMatched({
1513
+ const symbol = [...__classPrivateFieldGet$2(this, _State_symbolToDataMap, "f").keys()].find((currentSymbol) => tapeBlock.isMatched({
1522
1514
  symbol: currentSymbol,
1523
1515
  }));
1524
1516
  if (symbol) {
@@ -1527,10 +1519,10 @@ class State {
1527
1519
  return ifOtherSymbol;
1528
1520
  }
1529
1521
  getCommand(symbol) {
1530
- return __classPrivateFieldGet$1(this, _State_instances, "m", _State_getEntry).call(this, symbol).command;
1522
+ return __classPrivateFieldGet$2(this, _State_instances, "m", _State_getEntry).call(this, symbol).command;
1531
1523
  }
1532
1524
  getNextState(symbol) {
1533
- return __classPrivateFieldGet$1(this, _State_instances, "m", _State_getEntry).call(this, symbol).nextState;
1525
+ return __classPrivateFieldGet$2(this, _State_instances, "m", _State_getEntry).call(this, symbol).nextState;
1534
1526
  }
1535
1527
  /**
1536
1528
  * Like `getNextState`, but also returns the matched Symbol and its index
@@ -1549,13 +1541,13 @@ class State {
1549
1541
  * bare's transition iteration order — they're the same map.
1550
1542
  */
1551
1543
  getMatchedTransition(symbol) {
1552
- const entry = __classPrivateFieldGet$1(this, _State_instances, "m", _State_getEntry).call(this, symbol);
1544
+ const entry = __classPrivateFieldGet$2(this, _State_instances, "m", _State_getEntry).call(this, symbol);
1553
1545
  // Iteration order on a Map is insertion order; index lookup is O(N),
1554
1546
  // acceptable since this fires at most once per iter and N (transitions
1555
1547
  // per state) is typically tiny. If hot-path measurement ever flags it,
1556
1548
  // cache as `#symbolToIxMap` mirror.
1557
1549
  let ix = 0;
1558
- for (const key of __classPrivateFieldGet$1(this, _State_symbolToDataMap, "f").keys()) {
1550
+ for (const key of __classPrivateFieldGet$2(this, _State_symbolToDataMap, "f").keys()) {
1559
1551
  if (key === symbol)
1560
1552
  break;
1561
1553
  ix += 1;
@@ -1567,13 +1559,13 @@ class State {
1567
1559
  // are dead at runtime anyway (only the outermost `.wohs()`'s override is
1568
1560
  // pushed onto the halt-stack on entry; verified empirically). Composite
1569
1561
  // name reflects runtime behavior, not construction history. See #176.
1570
- const bare = __classPrivateFieldGet$1(this, _State_bareState, "f") ?? this;
1562
+ const bare = __classPrivateFieldGet$2(this, _State_bareState, "f") ?? this;
1571
1563
  // Memoize by (bare, override) so identical args return the same instance
1572
1564
  // (#175). The cache uses WeakMaps + WeakRefs so cached wrappers can be
1573
1565
  // GC'd when nothing else holds them. Compounds with the chain-collapse
1574
1566
  // above: `A.wohs(t1).wohs(t2)` keys as (A, t2) after the unwrap, hitting
1575
1567
  // the same cache slot as a direct `A.wohs(t2)`.
1576
- let innerCache = __classPrivateFieldGet$1(_a, _a, "f", _State_wrapperCache).get(bare);
1568
+ let innerCache = __classPrivateFieldGet$2(_a, _a, "f", _State_wrapperCache).get(bare);
1577
1569
  if (innerCache !== undefined) {
1578
1570
  const ref = innerCache.get(overriddenHaltState);
1579
1571
  if (ref !== undefined) {
@@ -1585,17 +1577,17 @@ class State {
1585
1577
  }
1586
1578
  else {
1587
1579
  innerCache = new WeakMap();
1588
- __classPrivateFieldGet$1(_a, _a, "f", _State_wrapperCache).set(bare, innerCache);
1580
+ __classPrivateFieldGet$2(_a, _a, "f", _State_wrapperCache).set(bare, innerCache);
1589
1581
  }
1590
1582
  // Cache miss — construct with no name, then overwrite #name directly
1591
1583
  // (composed names contain `(` and `)` which the constructor's user-facing
1592
1584
  // validation would reject; private-field access bypasses that).
1593
1585
  const state = new _a();
1594
- __classPrivateFieldSet$1(state, _State_name, `${bare.name}(${overriddenHaltState.name})`, "f");
1595
- __classPrivateFieldSet$1(state, _State_symbolToDataMap, __classPrivateFieldGet$1(bare, _State_symbolToDataMap, "f"), "f");
1596
- __classPrivateFieldSet$1(state, _State_overriddenHaltState, overriddenHaltState, "f");
1597
- __classPrivateFieldSet$1(state, _State_debugRef, __classPrivateFieldGet$1(bare, _State_debugRef, "f"), "f");
1598
- __classPrivateFieldSet$1(state, _State_bareState, bare, "f");
1586
+ __classPrivateFieldSet$2(state, _State_name, `${bare.name}(${overriddenHaltState.name})`, "f");
1587
+ __classPrivateFieldSet$2(state, _State_symbolToDataMap, __classPrivateFieldGet$2(bare, _State_symbolToDataMap, "f"), "f");
1588
+ __classPrivateFieldSet$2(state, _State_overriddenHaltState, overriddenHaltState, "f");
1589
+ __classPrivateFieldSet$2(state, _State_debugRef, __classPrivateFieldGet$2(bare, _State_debugRef, "f"), "f");
1590
+ __classPrivateFieldSet$2(state, _State_bareState, bare, "f");
1599
1591
  innerCache.set(overriddenHaltState, new WeakRef(state));
1600
1592
  return state;
1601
1593
  }
@@ -1624,9 +1616,9 @@ class State {
1624
1616
  * each adds to the implicit contract sibling modules can rely on.
1625
1617
  */
1626
1618
  [(_State_getEntry = function _State_getEntry(symbol) {
1627
- const entry = __classPrivateFieldGet$1(this, _State_symbolToDataMap, "f").get(symbol);
1619
+ const entry = __classPrivateFieldGet$2(this, _State_symbolToDataMap, "f").get(symbol);
1628
1620
  if (entry === undefined) {
1629
- throw new Error(`No transition for symbol at state named ${__classPrivateFieldGet$1(this, _State_name, "f")}`);
1621
+ throw new Error(`No transition for symbol at state named ${__classPrivateFieldGet$2(this, _State_name, "f")}`);
1630
1622
  }
1631
1623
  return entry;
1632
1624
  }, STATE_INTERNAL)]() {
@@ -1637,13 +1629,13 @@ class State {
1637
1629
  // eslint-disable-next-line @typescript-eslint/no-this-alias
1638
1630
  const self = this;
1639
1631
  return {
1640
- get id() { return __classPrivateFieldGet$1(self, _State_id, "f"); },
1641
- get name() { return __classPrivateFieldGet$1(self, _State_name, "f"); },
1642
- set name(v) { __classPrivateFieldSet$1(self, _State_name, v, "f"); },
1643
- get bareState() { return __classPrivateFieldGet$1(self, _State_bareState, "f"); },
1644
- get overriddenHaltState() { return __classPrivateFieldGet$1(self, _State_overriddenHaltState, "f"); },
1645
- get symbolToDataMap() { return __classPrivateFieldGet$1(self, _State_symbolToDataMap, "f"); },
1646
- get tags() { return __classPrivateFieldGet$1(self, _State_tags, "f"); },
1632
+ get id() { return __classPrivateFieldGet$2(self, _State_id, "f"); },
1633
+ get name() { return __classPrivateFieldGet$2(self, _State_name, "f"); },
1634
+ set name(v) { __classPrivateFieldSet$2(self, _State_name, v, "f"); },
1635
+ get bareState() { return __classPrivateFieldGet$2(self, _State_bareState, "f"); },
1636
+ get overriddenHaltState() { return __classPrivateFieldGet$2(self, _State_overriddenHaltState, "f"); },
1637
+ get symbolToDataMap() { return __classPrivateFieldGet$2(self, _State_symbolToDataMap, "f"); },
1638
+ get tags() { return __classPrivateFieldGet$2(self, _State_tags, "f"); },
1647
1639
  };
1648
1640
  }
1649
1641
  // Single-state introspection — no traversal, no tapeBlock required.
@@ -1653,7 +1645,7 @@ class State {
1653
1645
  // interned JS Symbol (decode via decodePatternDescription if needed).
1654
1646
  static inspect(state) {
1655
1647
  const transitions = [];
1656
- for (const [sym, { command, nextState }] of __classPrivateFieldGet$1(state, _State_symbolToDataMap, "f")) {
1648
+ for (const [sym, { command, nextState }] of __classPrivateFieldGet$2(state, _State_symbolToDataMap, "f")) {
1657
1649
  let target = null;
1658
1650
  try {
1659
1651
  target = nextState instanceof _a ? nextState : nextState.ref;
@@ -1671,11 +1663,11 @@ class State {
1671
1663
  });
1672
1664
  }
1673
1665
  return {
1674
- id: __classPrivateFieldGet$1(state, _State_id, "f"),
1675
- name: __classPrivateFieldGet$1(state, _State_name, "f"),
1666
+ id: __classPrivateFieldGet$2(state, _State_id, "f"),
1667
+ name: __classPrivateFieldGet$2(state, _State_name, "f"),
1676
1668
  isHalt: state.isHalt,
1677
- overriddenHaltState: __classPrivateFieldGet$1(state, _State_overriddenHaltState, "f")
1678
- ? { id: __classPrivateFieldGet$1(state, _State_overriddenHaltState, "f").id, name: __classPrivateFieldGet$1(state, _State_overriddenHaltState, "f").name }
1669
+ overriddenHaltState: __classPrivateFieldGet$2(state, _State_overriddenHaltState, "f")
1670
+ ? { id: __classPrivateFieldGet$2(state, _State_overriddenHaltState, "f").id, name: __classPrivateFieldGet$2(state, _State_overriddenHaltState, "f").name }
1679
1671
  : null,
1680
1672
  transitions,
1681
1673
  };
@@ -1721,20 +1713,37 @@ _a = State;
1721
1713
  _State_wrapperCache = { value: new WeakMap() };
1722
1714
  const haltState = new State(null);
1723
1715
 
1724
- var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1716
+ var __classPrivateFieldSet$1 = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1725
1717
  if (kind === "m") throw new TypeError("Private method is not writable");
1726
1718
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1727
1719
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1728
1720
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1729
1721
  };
1730
- var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1722
+ var __classPrivateFieldGet$1 = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1731
1723
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1732
1724
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1733
1725
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1734
1726
  };
1735
1727
  var _TuringMachine_tapeBlock;
1736
- // True iff `filter` matches `symbol` per the DebugConfig semantics.
1737
- // undefined / [] -> never; true -> always; symbol[] -> exact membership.
1728
+ /**
1729
+ * @internal package-private accessor key for `MachineState` instances yielded
1730
+ * by `runStepByStep`. Calling `machineState[MACHINE_STATE_INTERNAL]()` returns a
1731
+ * frozen snapshot of the engine's halt-stack at yield time (BEFORE this iter's
1732
+ * applyCommand / pop / push). Consumed by `DebugSession` for step-over /
1733
+ * step-out endpoint detection without exposing the stack to public API.
1734
+ *
1735
+ * Re-exported from this module so the sibling `DebugSession` module can import
1736
+ * it; intentionally NOT re-exported from the package's public `index.ts` —
1737
+ * downstream consumers shouldn't reach for the stack. Same pattern as
1738
+ * `STATE_INTERNAL` (#180).
1739
+ */
1740
+ const MACHINE_STATE_INTERNAL = Symbol('MachineState.internal');
1741
+ /**
1742
+ * @internal — true iff `filter` matches `symbol` per the DebugConfig semantics.
1743
+ * undefined / [] -> never; true -> always; symbol[] -> exact membership.
1744
+ * Exported for sibling-module use in `DebugSession` (which now owns breakpoint
1745
+ * detection); NOT re-exported from the package's public `index.ts`.
1746
+ */
1738
1747
  function matchFilter(filter, symbol) {
1739
1748
  if (filter === undefined)
1740
1749
  return false;
@@ -1748,43 +1757,42 @@ class TuringMachine {
1748
1757
  if (!tapeBlock) {
1749
1758
  throw new Error('invalid tapeBlock');
1750
1759
  }
1751
- __classPrivateFieldSet(this, _TuringMachine_tapeBlock, tapeBlock, "f");
1760
+ __classPrivateFieldSet$1(this, _TuringMachine_tapeBlock, tapeBlock, "f");
1752
1761
  }
1753
1762
  get tapeBlock() {
1754
- return __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f");
1755
- }
1756
- async run({ initialState, stepsLimit = 1e5, onStep, onPause, onIter, debug = true, }) {
1757
- const generator = this.runStepByStep({ initialState, stepsLimit });
1758
- for (const machineState of generator) {
1759
- // Per-iter lifecycle: before step after. All three operate on the
1760
- // same yielded MachineState, so the consumer sees a coherent ordering
1761
- // within each iteration without cross-tick coordination.
1762
- if (debug && machineState.debugBreak?.before && onPause) {
1763
- await onPause({ ...machineState, debugBreak: { before: true } });
1764
- }
1765
- if (onStep) {
1766
- onStep(machineState);
1767
- }
1768
- if (debug && machineState.debugBreak?.after && onPause) {
1769
- await onPause({ ...machineState, debugBreak: { after: true } });
1770
- }
1771
- if (onIter) {
1772
- await onIter(machineState);
1773
- }
1763
+ return __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f");
1764
+ }
1765
+ /**
1766
+ * Run the machine to halt. Pure execution — synchronous, no observation
1767
+ * callbacks, no debug overhead. For breakpoint-driven interactive debugging
1768
+ * use `DebugSession`; for per-iter tracing use `runStepByStep`'s generator
1769
+ * directly.
1770
+ *
1771
+ * Breakpoint metadata (`state.debug` / `haltState.debug` matches) is still
1772
+ * resolved and attached to each yielded MachineState by the underlying
1773
+ * generator — `run()` simply doesn't dispatch on it. A consumer that wants
1774
+ * to dispatch on it constructs a `DebugSession` instead.
1775
+ *
1776
+ * Symmetric reversal of v4's `run` → `async run` change: v4 made the method
1777
+ * async to support awaited `onPause`; with callbacks moved to `DebugSession`
1778
+ * there's no async work left, so the method returns `void` again.
1779
+ */
1780
+ run({ initialState, stepsLimit = 1e5 }) {
1781
+ // Drain the generator. We don't care about the yielded values — the
1782
+ // generator's job is to advance the tape; only side effects matter here.
1783
+ // Casting to unknown so eslint doesn't flag the unused `_` variable.
1784
+ for (const machineState of this.runStepByStep({ initialState, stepsLimit })) {
1774
1785
  }
1775
1786
  }
1776
1787
  *runStepByStep({ initialState, stepsLimit = 1e5 }) {
1777
1788
  const executionSymbol = Symbol('execution');
1778
1789
  try {
1779
- __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f")[lockSymbol].check(executionSymbol);
1780
- __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f")[lockSymbol].lock(executionSymbol);
1781
- // Halt-stack is run-scoped, not machine-scoped (#196). Declaring it
1782
- // local makes that lifetime explicit and prevents leftover entries
1783
- // from a previous `runStepByStep` call (e.g. a build-time peek that
1784
- // never drained the generator) from being popped during a subsequent
1785
- // halt-bound transition. Before this change `#stack` was an instance
1786
- // field and accumulated one extra push per call when the same machine
1787
- // was reused.
1790
+ __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f")[lockSymbol].check(executionSymbol);
1791
+ __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f")[lockSymbol].lock(executionSymbol);
1792
+ // Halt-stack is run-scoped, not machine-scoped (#196) local
1793
+ // declaration prevents leftover entries from a previous
1794
+ // `runStepByStep` call (e.g. a build-time peek that never drained
1795
+ // the generator) from leaking into a subsequent halt-bound transition.
1788
1796
  const stack = [];
1789
1797
  let state = initialState;
1790
1798
  if (state.overriddenHaltState) {
@@ -1796,7 +1804,7 @@ class TuringMachine {
1796
1804
  throw new Error('Long execution');
1797
1805
  }
1798
1806
  i += 1;
1799
- const symbol = state.getSymbol(__classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f"));
1807
+ const symbol = state.getSymbol(__classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f"));
1800
1808
  const command = state.getCommand(symbol);
1801
1809
  const matched = state.getMatchedTransition(symbol);
1802
1810
  let nextState = matched.nextState.ref;
@@ -1812,43 +1820,27 @@ class TuringMachine {
1812
1820
  const resolvableStateId = stateInternal.bareState?.id ?? state.id;
1813
1821
  const matchedTransition = {
1814
1822
  id: `${resolvableStateId}.${matched.ix}`,
1815
- matchKinds: __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f").patternKinds(matched.matchedSymbol),
1823
+ matchKinds: __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f").patternKinds(matched.matchedSymbol),
1816
1824
  };
1817
1825
  try {
1818
- // Both before and after refer to THIS iter (#119 / v6.0.0).
1819
- // The halting iter's after-fire just rides along on the iter's
1820
- // own yield no post-loop drain needed.
1821
- //
1822
- // #207: `haltState.debug` is now a boolean, and pauses on the
1823
- // halt-triggering iter's AFTER side (not before). The previous
1824
- // before-side check (`nextState.debug?.before === true`) was
1825
- // "early-warning" timing — the user paused before the halt-bound
1826
- // transition fired, then had to mentally re-derive what would
1827
- // happen. Now the pause anchors post-step (after the iter's own
1828
- // after-pause if armed), so consumers see the just-fired halt-
1829
- // bound transition + diagram cursor still on the triggering state.
1830
- //
1831
- // `state` here is always non-halt (halt is terminal — the run
1832
- // loop never iterates with state === haltState), so `state.debug`
1833
- // is always `DebugConfig` at runtime. The public getter's return
1834
- // type matches that.
1835
- const beforeMatch = matchFilter(state.debug?.before, symbol);
1836
- const afterMatch = matchFilter(state.debug?.after, symbol)
1837
- || (nextState === haltState && haltState.debug);
1826
+ // `runStepByStep` is the minimal execution primitive: it advances the
1827
+ // machine and reports state. It does NO breakpoint detection — that's
1828
+ // a debug concern that lives entirely in `DebugSession`. The yielded
1829
+ // `MachineState` has no `pause` / `debugBreak` field.
1838
1830
  const nextStateForYield = nextState.isHalt && stack.length
1839
1831
  ? stack.slice(-1)[0]
1840
1832
  : nextState;
1841
1833
  const yielded = {
1842
1834
  step: i,
1843
1835
  state,
1844
- currentSymbols: __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f").currentSymbols,
1836
+ currentSymbols: __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f").currentSymbols,
1845
1837
  nextSymbols: command.tapesCommands.map((tapeCommand, ix) => {
1846
1838
  if (typeof tapeCommand.symbol === 'symbol') {
1847
1839
  switch (tapeCommand.symbol) {
1848
1840
  case symbolCommands.erase:
1849
- return __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f").tapes[ix].alphabet.blankSymbol;
1841
+ return __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f").tapes[ix].alphabet.blankSymbol;
1850
1842
  case symbolCommands.keep:
1851
- return __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f").tapes[ix].symbol;
1843
+ return __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f").tapes[ix].symbol;
1852
1844
  default:
1853
1845
  throw new Error('invalid symbol command');
1854
1846
  }
@@ -1859,16 +1851,24 @@ class TuringMachine {
1859
1851
  nextState: nextStateForYield,
1860
1852
  matchedTransition,
1861
1853
  };
1862
- if (beforeMatch || afterMatch) {
1863
- const dbg = {};
1864
- if (beforeMatch)
1865
- dbg.before = true;
1866
- if (afterMatch)
1867
- dbg.after = true;
1868
- yielded.debugBreak = dbg;
1869
- }
1854
+ // #102: expose the pre-iter halt-stack + the matched symbol to
1855
+ // DebugSession via a Symbol-keyed accessor (non-enumerable, so it
1856
+ // doesn't leak into serialization / spread / toEqual). The stack
1857
+ // snapshot is frozen so a consumer holding a reference can't mutate
1858
+ // the engine's stack. DebugSession reads `matchedSymbol` to evaluate
1859
+ // `state.debug` filters — keeping breakpoint detection out of this
1860
+ // primitive.
1861
+ const stackSnapshot = Object.freeze(stack.slice());
1862
+ // Snapshot halt-imminence on the RAW nextState NOW, before the
1863
+ // post-yield pop reassigns `nextState` — so the closure can't capture
1864
+ // the mutated value.
1865
+ const haltImminent = nextState === haltState;
1866
+ Object.defineProperty(yielded, MACHINE_STATE_INTERNAL, {
1867
+ value: () => ({ stack: stackSnapshot, matchedSymbol: symbol, haltImminent }),
1868
+ enumerable: false,
1869
+ });
1870
1870
  yield yielded;
1871
- __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f").applyCommand(command, executionSymbol);
1871
+ __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f").applyCommand(command, executionSymbol);
1872
1872
  if (nextState.isHalt && stack.length) {
1873
1873
  nextState = stack.pop();
1874
1874
  }
@@ -1886,12 +1886,312 @@ class TuringMachine {
1886
1886
  }
1887
1887
  }
1888
1888
  finally {
1889
- __classPrivateFieldGet(this, _TuringMachine_tapeBlock, "f")[lockSymbol].unlock(executionSymbol);
1889
+ __classPrivateFieldGet$1(this, _TuringMachine_tapeBlock, "f")[lockSymbol].unlock(executionSymbol);
1890
1890
  }
1891
1891
  }
1892
1892
  }
1893
1893
  _TuringMachine_tapeBlock = new WeakMap();
1894
1894
 
1895
+ var __classPrivateFieldSet = (undefined && undefined.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
1896
+ if (kind === "m") throw new TypeError("Private method is not writable");
1897
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
1898
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
1899
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
1900
+ };
1901
+ var __classPrivateFieldGet = (undefined && undefined.__classPrivateFieldGet) || function (receiver, state, kind, f) {
1902
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
1903
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
1904
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
1905
+ };
1906
+ var _DebugSession_instances, _DebugSession_machine, _DebugSession_parameter, _DebugSession_listeners, _DebugSession_started, _DebugSession_stopped, _DebugSession_iterating, _DebugSession_pauseResolver, _DebugSession_activeStepMode, _DebugSession_capturedDepth, _DebugSession_clickTimeDepth, _DebugSession_runIntervalMs, _DebugSession_pauseRequested, _DebugSession_releasePause, _DebugSession_dispatchPause, _DebugSession_readInternal, _DebugSession_readStack, _DebugSession_drive;
1907
+ /**
1908
+ * Interactive debugger session for `TuringMachine`. Owns the coordination
1909
+ * layer that every UI debugger / IDE extension / educational demo would
1910
+ * otherwise reimplement: breakpoint dispatch, step-in / step-over / step-out,
1911
+ * click-pause from outside, per-iter throttle, pause/resume promise plumbing.
1912
+ *
1913
+ * Construction is direct — the engine class stays minimal and doesn't expose a
1914
+ * `debugRun()` factory; consumers import both classes and write
1915
+ * `new DebugSession(machine, {initialState})`.
1916
+ *
1917
+ * Lifecycle:
1918
+ * const session = new DebugSession(machine, {initialState});
1919
+ * session.on('pause', (m) => { ...; session.continue(); });
1920
+ * session.on('halt', () => { ... });
1921
+ * await session.start(); // resolves on natural halt or stop()
1922
+ *
1923
+ * Each session is single-use: `start()` may only be called once. Construct a
1924
+ * fresh session to re-run.
1925
+ */
1926
+ class DebugSession {
1927
+ constructor(machine, parameter) {
1928
+ _DebugSession_instances.add(this);
1929
+ _DebugSession_machine.set(this, void 0);
1930
+ _DebugSession_parameter.set(this, void 0);
1931
+ _DebugSession_listeners.set(this, {
1932
+ pause: [],
1933
+ step: [],
1934
+ iter: [],
1935
+ halt: [],
1936
+ });
1937
+ _DebugSession_started.set(this, false);
1938
+ _DebugSession_stopped.set(this, false);
1939
+ _DebugSession_iterating.set(this, false);
1940
+ _DebugSession_pauseResolver.set(this, null);
1941
+ _DebugSession_activeStepMode.set(this, null);
1942
+ /**
1943
+ * Halt-stack DEPTH snapshotted at the most recent pause dispatch (= number
1944
+ * of frames on the stack). DevTools-style step granularity is depth-based:
1945
+ * stepOver pauses at the next iter with `depth <= clickTimeDepth` (skip
1946
+ * frames the stepped-over iter pushes, pause back at the start level);
1947
+ * stepOut at `depth < clickTimeDepth` (the current frame itself exited).
1948
+ * Captured on EVERY pause so a step* call from the listener can freeze it.
1949
+ */
1950
+ _DebugSession_capturedDepth.set(this, 0);
1951
+ /** The click-time depth frozen when a stepOver / stepOut directive is issued. */
1952
+ _DebugSession_clickTimeDepth.set(this, 0);
1953
+ _DebugSession_runIntervalMs.set(this, 0);
1954
+ _DebugSession_pauseRequested.set(this, false);
1955
+ __classPrivateFieldSet(this, _DebugSession_machine, machine, "f");
1956
+ __classPrivateFieldSet(this, _DebugSession_parameter, parameter, "f");
1957
+ }
1958
+ on(event, listener) {
1959
+ __classPrivateFieldGet(this, _DebugSession_listeners, "f")[event].push(listener);
1960
+ return this;
1961
+ }
1962
+ off(event, listener) {
1963
+ const arr = __classPrivateFieldGet(this, _DebugSession_listeners, "f")[event];
1964
+ const ix = arr.indexOf(listener);
1965
+ if (ix >= 0)
1966
+ arr.splice(ix, 1);
1967
+ return this;
1968
+ }
1969
+ stop() {
1970
+ __classPrivateFieldSet(this, _DebugSession_stopped, true, "f");
1971
+ __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_releasePause).call(this);
1972
+ }
1973
+ /**
1974
+ * Request a pause from outside the run loop. The pause fires on the next
1975
+ * iter's before-side with `cause: 'manual'`. If a breakpoint matches that
1976
+ * same iter, the breakpoint takes precedence and the request is consumed
1977
+ * silently (one pause, cause: 'breakpoint').
1978
+ *
1979
+ * No-op if the session is already paused — the next `continue` / step call
1980
+ * resumes normal execution, then the flag fires on the iter AFTER that.
1981
+ * Equivalent to a debouncing one-shot.
1982
+ */
1983
+ pause() {
1984
+ __classPrivateFieldSet(this, _DebugSession_pauseRequested, true, "f");
1985
+ }
1986
+ /**
1987
+ * Set the per-iter throttle delay in milliseconds. After each iter (including
1988
+ * any pause + step + iter listeners on that iter), the loop awaits
1989
+ * `setTimeout(ms)` before proceeding to the next iter. `0` disables the
1990
+ * throttle.
1991
+ *
1992
+ * Useful for visualization UIs that want to animate execution at a fixed
1993
+ * pace. Updates take effect on the next iter.
1994
+ */
1995
+ setRunInterval(ms) {
1996
+ if (!Number.isFinite(ms) || ms < 0) {
1997
+ throw new Error(`DebugSession.setRunInterval(${ms}): expected a non-negative finite number.`);
1998
+ }
1999
+ __classPrivateFieldSet(this, _DebugSession_runIntervalMs, ms, "f");
2000
+ }
2001
+ /**
2002
+ * Resume from the current pause, returning to normal execution until the
2003
+ * next breakpoint or natural halt. No-op when called outside of a paused
2004
+ * state.
2005
+ */
2006
+ continue() {
2007
+ __classPrivateFieldSet(this, _DebugSession_activeStepMode, null, "f");
2008
+ __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_releasePause).call(this);
2009
+ }
2010
+ /**
2011
+ * Resume and force a pause on the next iter regardless of whether that
2012
+ * iter's `state.debug` filter matches. Step-mode is one-shot: any
2013
+ * subsequent pause dispatch (this step-in's endpoint, an inner
2014
+ * breakpoint, or a manual pause) drops it. To keep stepping, call
2015
+ * stepIn() again from the new pause.
2016
+ */
2017
+ stepIn() {
2018
+ __classPrivateFieldSet(this, _DebugSession_activeStepMode, 'step-in', "f");
2019
+ __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_releasePause).call(this);
2020
+ }
2021
+ /**
2022
+ * Resume and pause at the next iter back at (or above) the click-time depth
2023
+ * — i.e. `depth <= clickTimeDepth`. Frames the stepped-over iter pushes are
2024
+ * run to completion without pausing inside (the engine's continuation-passing
2025
+ * `withOverriddenHaltState` "calls"). Mirrors DevTools Step Over.
2026
+ *
2027
+ * For a plain iter (no frame push) this coincides with stepIn (next iter is
2028
+ * already at the same depth). The Over-vs-In / Over-vs-Out distinction only
2029
+ * appears under genuine nesting (a bare that itself enters a wrapper).
2030
+ *
2031
+ * One-shot: an inner breakpoint or any other pause drops the step-over
2032
+ * intent. The endpoint pause carries `cause: 'step'`.
2033
+ */
2034
+ stepOver() {
2035
+ __classPrivateFieldSet(this, _DebugSession_activeStepMode, 'step-over', "f");
2036
+ __classPrivateFieldSet(this, _DebugSession_clickTimeDepth, __classPrivateFieldGet(this, _DebugSession_capturedDepth, "f"), "f");
2037
+ __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_releasePause).call(this);
2038
+ }
2039
+ /**
2040
+ * Resume and pause at the next iter STRICTLY shallower than the click-time
2041
+ * depth — `depth < clickTimeDepth` — i.e. once the current frame itself has
2042
+ * been popped. Mirrors DevTools Step Out.
2043
+ *
2044
+ * Throws when the click-time depth is 0: there's no enclosing frame to exit
2045
+ * (IDE convention — "step out of nothing" is a programming error, not a
2046
+ * silent no-op).
2047
+ */
2048
+ stepOut() {
2049
+ if (__classPrivateFieldGet(this, _DebugSession_capturedDepth, "f") === 0) {
2050
+ throw new Error('DebugSession.stepOut() called with an empty click-time halt-stack — there is no enclosing frame to exit.');
2051
+ }
2052
+ __classPrivateFieldSet(this, _DebugSession_activeStepMode, 'step-out', "f");
2053
+ __classPrivateFieldSet(this, _DebugSession_clickTimeDepth, __classPrivateFieldGet(this, _DebugSession_capturedDepth, "f"), "f");
2054
+ __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_releasePause).call(this);
2055
+ }
2056
+ async start() {
2057
+ if (__classPrivateFieldGet(this, _DebugSession_started, "f")) {
2058
+ throw new Error('DebugSession.start() has already been called; construct a fresh session to re-run.');
2059
+ }
2060
+ __classPrivateFieldSet(this, _DebugSession_started, true, "f");
2061
+ try {
2062
+ await __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_drive).call(this);
2063
+ }
2064
+ catch (error) {
2065
+ // `runStepByStep` acquires the TapeBlock lock at its first advance. If
2066
+ // another DebugSession (or a bare `run()`) is already active on this
2067
+ // machine, that acquisition throws the low-level 'Lock check failed'.
2068
+ // Remap it to a message that names the real cause. The `#iterating`
2069
+ // guard scopes the remap to the startup acquisition only — once we hold
2070
+ // the lock and are iterating, a same-named error can't originate here.
2071
+ if (!__classPrivateFieldGet(this, _DebugSession_iterating, "f") && error instanceof Error && error.message === 'Lock check failed') {
2072
+ throw new Error('Cannot start this DebugSession: a run is already in progress on this machine. '
2073
+ + 'Only one DebugSession or run() may be active on a TuringMachine at a time — '
2074
+ + 'stop the active session (or let it halt) before starting another.');
2075
+ }
2076
+ throw error;
2077
+ }
2078
+ }
2079
+ }
2080
+ _DebugSession_machine = new WeakMap(), _DebugSession_parameter = new WeakMap(), _DebugSession_listeners = new WeakMap(), _DebugSession_started = new WeakMap(), _DebugSession_stopped = new WeakMap(), _DebugSession_iterating = new WeakMap(), _DebugSession_pauseResolver = new WeakMap(), _DebugSession_activeStepMode = new WeakMap(), _DebugSession_capturedDepth = new WeakMap(), _DebugSession_clickTimeDepth = new WeakMap(), _DebugSession_runIntervalMs = new WeakMap(), _DebugSession_pauseRequested = new WeakMap(), _DebugSession_instances = new WeakSet(), _DebugSession_releasePause = function _DebugSession_releasePause() {
2081
+ const resolver = __classPrivateFieldGet(this, _DebugSession_pauseResolver, "f");
2082
+ if (resolver) {
2083
+ __classPrivateFieldSet(this, _DebugSession_pauseResolver, null, "f");
2084
+ resolver();
2085
+ }
2086
+ }, _DebugSession_dispatchPause =
2087
+ /**
2088
+ * Emit a `pause` event with the synthesized pause descriptor and await the
2089
+ * consumer's resume signal. Resolver is installed BEFORE listeners fire so a listener
2090
+ * that synchronously calls `session.continue()` (or any other resume method)
2091
+ * sees a live resolver to drop.
2092
+ *
2093
+ * One-shot rule: any pause dispatch (step-mode endpoint, inner breakpoint,
2094
+ * manual pause) drops the active step-mode BEFORE listeners fire. Listeners
2095
+ * that want to keep stepping must call stepIn/Over/Out from the new pause.
2096
+ *
2097
+ * The pre-iter halt-stack DEPTH is snapshotted into `#capturedDepth` so a
2098
+ * `stepOver` / `stepOut` issued from inside the listener can freeze it as
2099
+ * the click-time depth.
2100
+ */
2101
+ async function _DebugSession_dispatchPause(machineState, pause) {
2102
+ __classPrivateFieldSet(this, _DebugSession_activeStepMode, null, "f");
2103
+ __classPrivateFieldSet(this, _DebugSession_capturedDepth, __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_readStack).call(this, machineState).length, "f");
2104
+ // Note: the spread drops the non-enumerable MACHINE_STATE_INTERNAL Symbol
2105
+ // accessor — that's intentional. Pause listeners are public API; the
2106
+ // Symbol accessor is package-private and only consumed by the session's
2107
+ // OWN detection (which reads the original `machineState` via #readInternal).
2108
+ const paused = { ...machineState, pause };
2109
+ const pausePromise = new Promise((resolve) => {
2110
+ __classPrivateFieldSet(this, _DebugSession_pauseResolver, resolve, "f");
2111
+ });
2112
+ for (const fn of __classPrivateFieldGet(this, _DebugSession_listeners, "f").pause) {
2113
+ void fn(paused);
2114
+ }
2115
+ await pausePromise;
2116
+ }, _DebugSession_readInternal = function _DebugSession_readInternal(machineState) {
2117
+ const fn = machineState[MACHINE_STATE_INTERNAL];
2118
+ return typeof fn === 'function' ? fn() : null;
2119
+ }, _DebugSession_readStack = function _DebugSession_readStack(machineState) {
2120
+ return __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_readInternal).call(this, machineState)?.stack ?? [];
2121
+ }, _DebugSession_drive = async function _DebugSession_drive() {
2122
+ for (const machineState of __classPrivateFieldGet(this, _DebugSession_machine, "f").runStepByStep(__classPrivateFieldGet(this, _DebugSession_parameter, "f"))) {
2123
+ __classPrivateFieldSet(this, _DebugSession_iterating, true, "f");
2124
+ if (__classPrivateFieldGet(this, _DebugSession_stopped, "f"))
2125
+ return;
2126
+ // Breakpoint detection lives HERE (not in the generator). Evaluate the
2127
+ // current state's debug filters against the matched symbol the generator
2128
+ // stashed in the internal accessor. `machineState.state` is always
2129
+ // non-halt (halt is terminal), so `.debug` is a DebugConfig at runtime.
2130
+ // The after side also fires on halt-imminent (`haltState.debug`, #207) —
2131
+ // read via the internal flag, since the yielded `nextState` shows the
2132
+ // post-pop continuation on subroutine-return iters, not haltState.
2133
+ const internal = __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_readInternal).call(this, machineState);
2134
+ const matchedSymbol = internal?.matchedSymbol;
2135
+ const hasBeforeBreakpoint = matchedSymbol !== undefined
2136
+ && matchFilter(machineState.state.debug?.before, matchedSymbol);
2137
+ const hasAfterBreakpoint = (matchedSymbol !== undefined
2138
+ && matchFilter(machineState.state.debug?.after, matchedSymbol))
2139
+ || (internal?.haltImminent === true && haltState.debug === true);
2140
+ const stepInForcesPause = __classPrivateFieldGet(this, _DebugSession_activeStepMode, "f") === 'step-in';
2141
+ // Depth-based endpoints (DevTools semantics). currentDepth = pre-iter
2142
+ // halt-stack length. stepOver: back at/above click-time depth (skip
2143
+ // pushed frames). stepOut: strictly shallower (current frame exited).
2144
+ const currentDepth = __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_readStack).call(this, machineState).length;
2145
+ const stepOverEndpointReached = __classPrivateFieldGet(this, _DebugSession_activeStepMode, "f") === 'step-over' && currentDepth <= __classPrivateFieldGet(this, _DebugSession_clickTimeDepth, "f");
2146
+ const stepOutEndpointReached = __classPrivateFieldGet(this, _DebugSession_activeStepMode, "f") === 'step-out' && currentDepth < __classPrivateFieldGet(this, _DebugSession_clickTimeDepth, "f");
2147
+ // Consume the manual-pause flag at iter start. If a breakpoint also
2148
+ // matches this iter, the request is silently consumed by the
2149
+ // breakpoint dispatch (one pause, cause: 'breakpoint').
2150
+ const manualPauseFires = __classPrivateFieldGet(this, _DebugSession_pauseRequested, "f");
2151
+ if (manualPauseFires)
2152
+ __classPrivateFieldSet(this, _DebugSession_pauseRequested, false, "f");
2153
+ // Before-side pause: fires if any of breakpoint / step-mode endpoint /
2154
+ // manual request is true. Precedence: breakpoint > step > manual.
2155
+ const fireBeforePause = hasBeforeBreakpoint || stepInForcesPause || stepOverEndpointReached || stepOutEndpointReached || manualPauseFires;
2156
+ if (fireBeforePause) {
2157
+ const cause = hasBeforeBreakpoint ? 'breakpoint'
2158
+ : (stepInForcesPause || stepOverEndpointReached || stepOutEndpointReached) ? 'step'
2159
+ : 'manual';
2160
+ await __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_dispatchPause).call(this, machineState, { side: 'before', cause });
2161
+ if (__classPrivateFieldGet(this, _DebugSession_stopped, "f"))
2162
+ return;
2163
+ }
2164
+ // step: fires once per iter, after any before-pause and before any after-pause.
2165
+ for (const fn of __classPrivateFieldGet(this, _DebugSession_listeners, "f").step) {
2166
+ void fn(machineState);
2167
+ }
2168
+ if (hasAfterBreakpoint) {
2169
+ await __classPrivateFieldGet(this, _DebugSession_instances, "m", _DebugSession_dispatchPause).call(this, machineState, { side: 'after', cause: 'breakpoint' });
2170
+ if (__classPrivateFieldGet(this, _DebugSession_stopped, "f"))
2171
+ return;
2172
+ }
2173
+ // iter: end-of-iter, after both before- and after-pause have fired.
2174
+ // Listeners are AWAITED (sequenced, blocking the engine) — matches the
2175
+ // v6 `onIter` contract that downstream consumers rely on for
2176
+ // throttle / per-iter coordination / step-boundary synthesis.
2177
+ for (const fn of __classPrivateFieldGet(this, _DebugSession_listeners, "f").iter) {
2178
+ await fn(machineState);
2179
+ }
2180
+ if (__classPrivateFieldGet(this, _DebugSession_stopped, "f"))
2181
+ return;
2182
+ if (__classPrivateFieldGet(this, _DebugSession_runIntervalMs, "f") > 0) {
2183
+ await new Promise((resolve) => setTimeout(resolve, __classPrivateFieldGet(this, _DebugSession_runIntervalMs, "f")));
2184
+ if (__classPrivateFieldGet(this, _DebugSession_stopped, "f"))
2185
+ return;
2186
+ }
2187
+ }
2188
+ if (!__classPrivateFieldGet(this, _DebugSession_stopped, "f")) {
2189
+ for (const fn of __classPrivateFieldGet(this, _DebugSession_listeners, "f").halt) {
2190
+ void fn();
2191
+ }
2192
+ }
2193
+ };
2194
+
1895
2195
  // Format converters between a Graph (the data model produced by State.toGraph
1896
2196
  // and consumed by State.fromGraph) and external string representations.
1897
2197
  //
@@ -2607,10 +2907,10 @@ function summarizeGraph(graph) {
2607
2907
  }
2608
2908
  let hasCycles = false;
2609
2909
  const visit = (id) => {
2610
- // No `if (hasCycles) return` guard at function entry: the recursive call
2611
- // pattern (outer for-loop checks before calling, inner loop checks after
2612
- // each recursive call) ensures visit() is never invoked when hasCycles
2613
- // is already true. Static analysis confirmed the guard was unreachable.
2910
+ // No `if (hasCycles) return` guard at function entry: the call pattern
2911
+ // (outer for-loop checks before calling, inner loop checks after each
2912
+ // recursive call) ensures visit() is never invoked when hasCycles is
2913
+ // already true.
2614
2914
  if (color.get(id) === GREY) {
2615
2915
  hasCycles = true;
2616
2916
  return;
@@ -2726,4 +3026,4 @@ function runOnce(runnable, input, stepsLimit) {
2726
3026
  };
2727
3027
  }
2728
3028
 
2729
- export { Alphabet, Command, DebugConfig, Reference, State, Tape, TapeBlock, TapeCommand, TuringMachine, equivalentOn, fromMermaid, haltState, ifOtherSymbol, movements, summarize, summarizeGraph, symbolCommands, toMermaid };
3029
+ export { Alphabet, Command, DebugConfig, DebugSession, Reference, State, Tape, TapeBlock, TapeCommand, TuringMachine, equivalentOn, fromMermaid, haltState, ifOtherSymbol, movements, summarize, summarizeGraph, symbolCommands, toMermaid };