@vsirotin/ts-stop 1.13.1 → 2.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/README.md +20 -5
  2. package/ai/skills/sfsm-compare-json-uml-diagram/SKILL.md +62 -0
  3. package/ai/skills/sfsm-json-to-uml-diagram/SKILL.md +50 -0
  4. package/ai/skills/sfsm-uml-diagram-to-json/SKILL.md +49 -0
  5. package/lib/esm/index.js +2 -9
  6. package/lib/esm/sfsm/CommandReceiver.js +17 -0
  7. package/lib/esm/sfsm/ControllerHub.js +82 -0
  8. package/lib/esm/sfsm/FaResolver.js +24 -3
  9. package/lib/esm/sfsm/Sfsm.js +48 -7
  10. package/lib/esm/sfsm/SignalSender.js +27 -0
  11. package/lib/esm/sfsm/index.js +3 -1
  12. package/lib/index.d.ts +1 -9
  13. package/lib/index.d.ts.map +1 -1
  14. package/lib/index.js +2 -9
  15. package/lib/index.js.map +1 -1
  16. package/lib/sfsm/CommandReceiver.d.ts +23 -0
  17. package/lib/sfsm/CommandReceiver.d.ts.map +1 -0
  18. package/lib/sfsm/CommandReceiver.js +22 -0
  19. package/lib/sfsm/CommandReceiver.js.map +1 -0
  20. package/lib/sfsm/ControllerHub.d.ts +56 -0
  21. package/lib/sfsm/ControllerHub.d.ts.map +1 -0
  22. package/lib/sfsm/ControllerHub.js +87 -0
  23. package/lib/sfsm/ControllerHub.js.map +1 -0
  24. package/lib/sfsm/FaResolver.d.ts +14 -0
  25. package/lib/sfsm/FaResolver.d.ts.map +1 -1
  26. package/lib/sfsm/FaResolver.js +24 -3
  27. package/lib/sfsm/FaResolver.js.map +1 -1
  28. package/lib/sfsm/Sfsm.d.ts +26 -0
  29. package/lib/sfsm/Sfsm.d.ts.map +1 -1
  30. package/lib/sfsm/Sfsm.js +48 -7
  31. package/lib/sfsm/Sfsm.js.map +1 -1
  32. package/lib/sfsm/SignalSender.d.ts +24 -0
  33. package/lib/sfsm/SignalSender.d.ts.map +1 -0
  34. package/lib/sfsm/SignalSender.js +32 -0
  35. package/lib/sfsm/SignalSender.js.map +1 -0
  36. package/lib/sfsm/index.d.ts +3 -1
  37. package/lib/sfsm/index.d.ts.map +1 -1
  38. package/lib/sfsm/index.js +7 -3
  39. package/lib/sfsm/index.js.map +1 -1
  40. package/lib/sfsm/interfaces.d.ts +1 -1
  41. package/lib/sfsm/types.d.ts +21 -0
  42. package/lib/sfsm/types.d.ts.map +1 -1
  43. package/package.json +12 -9
  44. package/scripts/compare-compact-jsons.js +146 -0
  45. package/scripts/drawio-to-json.js +149 -0
  46. package/scripts/json-to-drawio-old.js +311 -0
  47. package/scripts/json-to-drawio.js +309 -0
  48. package/scripts/merge-fas.js +0 -0
  49. package/scripts/reduce-fa.js +0 -0
  50. package/scripts/update-fa.js +0 -0
  51. package/tutorial/01-finite-state-machine.md +223 -0
  52. package/tutorial/02-stacked-finite-state-machine.md +32 -0
  53. package/tutorial/03-advanced-themes.md +110 -0
  54. package/tutorial/04-tools.md +164 -0
  55. package/tutorial/images/Turnstile-img.png +0 -0
  56. package/tutorial/images/TurnstileBaseFA.png +0 -0
  57. package/LICENSE +0 -201
  58. package/LICENSE-COMMERCIAL.md +0 -41
  59. package/lib/DefaultState.d.ts +0 -9
  60. package/lib/DefaultState.d.ts.map +0 -1
  61. package/lib/DefaultState.js +0 -15
  62. package/lib/DefaultState.js.map +0 -1
  63. package/lib/FiniteStateMachine.d.ts +0 -227
  64. package/lib/FiniteStateMachine.d.ts.map +0 -1
  65. package/lib/FiniteStateMachine.js +0 -410
  66. package/lib/FiniteStateMachine.js.map +0 -1
  67. package/lib/IStateWithActions.d.ts +0 -18
  68. package/lib/IStateWithActions.d.ts.map +0 -1
  69. package/lib/IStateWithActions.js +0 -3
  70. package/lib/IStateWithActions.js.map +0 -1
  71. package/lib/IStateWithOutputSignal.d.ts +0 -4
  72. package/lib/IStateWithOutputSignal.d.ts.map +0 -1
  73. package/lib/IStateWithOutputSignal.js +0 -3
  74. package/lib/IStateWithOutputSignal.js.map +0 -1
  75. package/lib/MatrixBasedStateMachine.d.ts +0 -108
  76. package/lib/MatrixBasedStateMachine.d.ts.map +0 -1
  77. package/lib/MatrixBasedStateMachine.js +0 -132
  78. package/lib/MatrixBasedStateMachine.js.map +0 -1
  79. package/lib/TransitionMatrix.d.ts +0 -61
  80. package/lib/TransitionMatrix.d.ts.map +0 -1
  81. package/lib/TransitionMatrix.js +0 -104
  82. package/lib/TransitionMatrix.js.map +0 -1
  83. package/lib/esm/DefaultState.js +0 -10
  84. package/lib/esm/FiniteStateMachine.js +0 -405
  85. package/lib/esm/IStateWithActions.js +0 -1
  86. package/lib/esm/IStateWithOutputSignal.js +0 -1
  87. package/lib/esm/MatrixBasedStateMachine.js +0 -127
  88. package/lib/esm/TransitionMatrix.js +0 -98
  89. package/lib/esm/fa/DefaultState.js +0 -10
  90. package/lib/esm/fa/FiniteStateMachine.js +0 -405
  91. package/lib/esm/fa/IStateWithActions.js +0 -1
  92. package/lib/esm/fa/IStateWithOutputSignal.js +0 -1
  93. package/lib/esm/fa/MatrixBasedStateMachine.js +0 -127
  94. package/lib/esm/fa/TransitionMatrix.js +0 -98
  95. package/lib/esm/sfsm/ExternalWorldHub.js +0 -80
  96. package/lib/esm/sfsm/index.browser.js +0 -5
  97. package/lib/fa/DefaultState.d.ts +0 -9
  98. package/lib/fa/DefaultState.d.ts.map +0 -1
  99. package/lib/fa/DefaultState.js +0 -15
  100. package/lib/fa/DefaultState.js.map +0 -1
  101. package/lib/fa/FiniteStateMachine.d.ts +0 -227
  102. package/lib/fa/FiniteStateMachine.d.ts.map +0 -1
  103. package/lib/fa/FiniteStateMachine.js +0 -410
  104. package/lib/fa/FiniteStateMachine.js.map +0 -1
  105. package/lib/fa/IStateWithActions.d.ts +0 -18
  106. package/lib/fa/IStateWithActions.d.ts.map +0 -1
  107. package/lib/fa/IStateWithActions.js +0 -3
  108. package/lib/fa/IStateWithActions.js.map +0 -1
  109. package/lib/fa/IStateWithOutputSignal.d.ts +0 -4
  110. package/lib/fa/IStateWithOutputSignal.d.ts.map +0 -1
  111. package/lib/fa/IStateWithOutputSignal.js +0 -3
  112. package/lib/fa/IStateWithOutputSignal.js.map +0 -1
  113. package/lib/fa/MatrixBasedStateMachine.d.ts +0 -108
  114. package/lib/fa/MatrixBasedStateMachine.d.ts.map +0 -1
  115. package/lib/fa/MatrixBasedStateMachine.js +0 -132
  116. package/lib/fa/MatrixBasedStateMachine.js.map +0 -1
  117. package/lib/fa/TransitionMatrix.d.ts +0 -61
  118. package/lib/fa/TransitionMatrix.d.ts.map +0 -1
  119. package/lib/fa/TransitionMatrix.js +0 -104
  120. package/lib/fa/TransitionMatrix.js.map +0 -1
  121. package/lib/sfsm/ExternalWorldHub.d.ts +0 -52
  122. package/lib/sfsm/ExternalWorldHub.d.ts.map +0 -1
  123. package/lib/sfsm/ExternalWorldHub.js +0 -85
  124. package/lib/sfsm/ExternalWorldHub.js.map +0 -1
  125. package/lib/sfsm/index.browser.d.ts +0 -7
@@ -0,0 +1,110 @@
1
+ # StOP Tutorial. Part 3: Advanced Themes
2
+
3
+ ## 5. How stacked states are processed
4
+
5
+ Once an FA can contain other FAs, "processing a signal" needs a precise algorithm — not just "look up the transition," but also "where do I look, and what happens once I find (or fail to find) one." Here are the rules the `Sfsm` engine actually implements (verified directly against its source, `Sfsm.ts`):
6
+
7
+ 1. After `loadFA()`, the root FA is the only element on the stack and its active state is `"I"`. The engine now waits for a signal.
8
+ 2. When a signal `s` arrives, the engine searches for a matching transition, starting at the **head** of the stack (the innermost, currently active FA) and, if needed, continuing down through each ancestor FA towards the root:
9
+ - **2.1** — If the head FA has a transition matching its own active state and `s` (including joker fallbacks, see chapter 3), that transition is applied directly: the head's active state becomes the transition's target. This step is logged with rule `"2.1"`.
10
+ - **2.2** — If the head FA has *no* matching transition, the search continues in its parent FA, then that FA's parent, and so on down to the root.
11
+ - **2.2.1** — If a matching transition is found in some ancestor FA, every FA above it on the stack is popped (they are abandoned mid-flight), that ancestor becomes the new head, and the transition is applied there.
12
+ - **2.2.2** — If **no** FA anywhere in the stack — from the head all the way down to the root — has a matching transition, **no log entry is created**, and the engine instead applies the `byMissingTransition` policy (`'error'` throws, `'log_warning'` warns and does nothing, `'ignore'` silently does nothing).
13
+ 3. If the transition found in step 2 carries a command (its 4th element), the command is sent to the registered command receiver.
14
+ 4. If the transition's target state is itself the name of a sub-FA, that sub-FA is pushed onto the stack with active state `"I"`, and the very same signal `s` is immediately forwarded into it, restarting this whole process (step 2) one level deeper.
15
+ 5. If the transition's target state is an exit state (starts with `"E_"`):
16
+ - **5.1** — if the current FA is the only one left on the stack (the root), it simply resets its own active state back to `"I"`;
17
+ - **5.2** — otherwise, the current FA is popped off the stack, and the very same signal `s` is forwarded to the FA that is now the head, restarting this whole process (step 2) one level up.
18
+
19
+
20
+ The example of using the SFSM engine can be found in [Sfsm.log.test.ts](../../ts-stop/test/sfsm/Sfsm.log.test.ts).
21
+
22
+ ## 6. Signal Senders, Command Receivers, Controllers, and the Controller Hub
23
+
24
+ Everything so far has driven the `Sfsm` engine directly, by calling `receiveSignal()` from test code. In a real application, signals come from real devices — a coin slot, a push sensor, a button — and commands need to reach real devices too — a lock, a light, a dispenser. The library gives you three small building blocks to wire this up cleanly:
25
+
26
+ - **`SignalSender`** — an abstract base class you extend on any component that needs to emit signals into the SFSM. You implement `getSignalNames()` (the list of signal names it may ever send) and call the protected `sendSignal(name, data?)` method whenever something happens in the real world.
27
+ - **`CommandReceiver`** — an abstract base class (or, if a class already extends something else, the `ICommandReceiver` interface it mirrors) for any component that needs to react to commands coming *from* the SFSM. You implement `getCommandNames()` (the commands it can handle) and `receiveCommand(command, data?)`.
28
+ - **Controller** — not a class, but a *role*: any component that plays the `SignalSender` role, the `CommandReceiver` role, or (as most real devices do) both at once, is called a Controller.
29
+ - **`ControllerHub`** — the wiring hub that connects every Controller to one `Sfsm` instance. You register each Controller once with `registerSignalSender()` and/or `registerCommandReceiver()`, then call `connectTo(sfsm)`. From then on, the hub automatically routes every command the SFSM sends to the right Controller (by the exact command name), and forwards every signal a Controller sends into the SFSM.
30
+
31
+ Here is a minimal physical turnstile "gate" Controller — it plays both roles at once, exactly like the real simulators used elsewhere in this library's own test suite:
32
+
33
+ ```typescript
34
+ import { Sfsm, FaDefinition, SignalSender, ICommandReceiver, ControllerHub } from '@vsirotin/ts-stop/sfsm';
35
+
36
+ class TurnstileGate extends SignalSender implements ICommandReceiver {
37
+ private locked = true;
38
+
39
+ getSignalNames(): readonly string[] { return ['start', 'coin', 'push']; }
40
+ getCommandNames(): readonly string[] { return ['GATE.lock', 'GATE.unlock']; }
41
+
42
+ receiveCommand(command: string): void {
43
+ this.locked = command === 'GATE.lock';
44
+ }
45
+
46
+ isLocked(): boolean { return this.locked; }
47
+
48
+ start(): void { this.sendSignal('start'); }
49
+ insertCoin(): void { this.sendSignal('coin'); }
50
+ walkThrough(): void { this.sendSignal('push'); }
51
+ }
52
+
53
+ const turnstileFa: FaDefinition = {
54
+ Turnstile: [
55
+ ['I', 'start', 'locked'],
56
+ ['locked', 'coin', 'unlocked', 'GATE.unlock'],
57
+ ['unlocked', 'push', 'locked', 'GATE.lock']
58
+ ]
59
+ };
60
+
61
+ const sfsm = new Sfsm();
62
+ const gate = new TurnstileGate();
63
+
64
+ new ControllerHub()
65
+ .registerSignalSender(gate)
66
+ .registerCommandReceiver(gate)
67
+ .connectTo(sfsm);
68
+
69
+ sfsm.loadFA(turnstileFa);
70
+
71
+ gate.start();
72
+ gate.insertCoin();
73
+ gate.isLocked(); // false — the SFSM sent 'GATE.unlock' in response to 'coin'
74
+
75
+ gate.walkThrough();
76
+ gate.isLocked(); // true — the SFSM sent 'GATE.lock' in response to 'push'
77
+ ```
78
+
79
+ Notice that `TurnstileGate` never touches the `Sfsm` instance directly: it only knows how to emit its own signals and react to its own commands. All the wiring — "which Controller sends which signal," "which Controller handles which command" — lives in one place, the `ControllerHub`, which also gives you `getRegisteredSignals()` / `getRegisteredCommands()` for diagnostics (e.g. to validate that every signal and command mentioned in an FA definition actually has a Controller behind it).
80
+
81
+ A runnable version of this example is available as a unit test: [06-controllers-and-controller-hub.test.ts](../../ts-stop/test/sfsm/tutorial/06-controllers-and-controller-hub.test.ts).
82
+
83
+ ### 7. Name conventions
84
+
85
+ Every example so far has named the entry state simply `"I"` and exit states `"E_something"` — perfectly fine for a small, self-contained FA. Once a stacked SFSM grows to dozens of FAs, plain abbreviations like `"L"`, `"U"`, `"I"`, `"E_R"` start colliding in your head across FAs, and it becomes hard to tell, just by looking at a state name, *which* FA it belongs to.
86
+
87
+ For larger SFSMs, it is recommended to namespace state names with their own FA's name, using a dot: `<FaName>.I` for the entry state, and `<FaName>.<state>` for ordinary states — e.g. `TS.I`, `TS.L`, `TS.U` instead of bare `I`, `L`, `U`. Exit states keep their familiar `E_` marker but move it after the FA-name dot: `<FaName>.E_<name>` — e.g. `TS.E_ok` instead of bare `E_ok`.
88
+
89
+ ```json
90
+ {
91
+ "TS": [
92
+ ["TS.I", "TS.s", "TS.L"],
93
+ ["TS.L", "TS.coin", "TS.U"],
94
+ ["TS.U", "TS.push", "TS.L"]
95
+ ]
96
+ }
97
+ ```
98
+
99
+ The `Sfsm` engine recognises **both** forms everywhere, automatically:
100
+ - an entry state is whatever from-state a FA's own transitions use that is exactly `"I"` **or** ends with `".I"`;
101
+ - an exit state is any target state that starts with `"E_"` **or** contains `".E_"`.
102
+
103
+ This means:
104
+ - every FA fixture used earlier in this tutorial (bare `"I"` / `"E_..."`) keeps working exactly as written — no migration is required;
105
+ - you can freely mix both styles across FAs in the same SFSM (e.g. namespace only the FAs that are large enough to benefit from it);
106
+ - nothing else changes — this is purely a naming convention for readability, not a new engine feature: no new `SfsmOptions`, no change to how transitions, pushes, pops, or jokers are matched.
107
+
108
+ A runnable version of this example, built entirely with namespaced names, is available as a unit test: [08-namespaced-state-names.test.ts](../../ts-stop/test/sfsm/tutorial/08-namespaced-state-names.test.ts).
109
+
110
+ In future this part of tutorial will be expanded with more advanced topics, including description of best practices for building large SFSMs, and a few more examples of real-world applications.
@@ -0,0 +1,164 @@
1
+ # StOP Tutorial. Part 4: Tools
2
+
3
+ ## 7. Tools
4
+
5
+ Beyond the core `Sfsm` engine, the StOP SDK ships a handful of functions with corresponding CLI-scripts for working with FA definitions themselves.
6
+
7
+ StOP SDK ships with a few AI-skills, that can be useful by working with SFSMs. These skills are described in the paragraph 7.6 of this document.
8
+
9
+ ### 7.1 Extended vs. compact format, and `reduceFA`
10
+
11
+ Every example so far has used the **compact** (runtime) format: a plain list of `[from, signal, to]` tuples or `[from, signal, to, command]` tuples. For larger FAs, an **extended** (declaration) format is available where every state, signal, and command can carry a human-readable `name`/`description`, and a `sender`/`receiver` — much more pleasant to read and maintain by hand, and to auto-generate documentation from.
12
+
13
+ The `reduceFA()` function converts an extended definition into the flat compact form that `Sfsm.loadFA()` actually consumes internally:
14
+
15
+ ```typescript
16
+ import { reduceFA, FaDefinition } from '@vsirotin/ts-stop/sfsm';
17
+
18
+ const compact = reduceFA(extendedTurnstileFa as FaDefinition);
19
+ ```
20
+
21
+ Passing an already-compact definition through `reduceFA()` returns it unchanged, so it is always safe to call.
22
+
23
+ ### 7.2 The multi-FA compact format
24
+
25
+ Once an FA has children, the compact format lists **every** FA (root and all descendants) as separate top-level keys of the same object — the parent's `ts` list simply refers to a child by name as a transition target, exactly like `CoinCheck` in the example below. The root FA is auto-detected as whichever key is never referenced as a target (3rd element) in any FA's transitions. Both this format and a single flat FA are accepted by `loadFA()` without any change to the calling code.
26
+
27
+ ### 7.3 `updateCompactFA` / `updateFullFA` — evolving an FA definition without rewriting it
28
+
29
+ `updateCompactFA()` (and its extended-format counterpart `updateFullFA()`) apply a small, structured `FaUpdate` descriptor — `{ remove?: string[], add?: Record<string, ...> }` — to an existing FA definition and return a new one, without mutating the source. This is the mechanism the CLI tools `update-compact-fa` / `update-full-fa` use under the hood.
30
+
31
+ A particularly useful pattern: **turning a plain leaf state into a sub-FA**, so a device's behaviour becomes more detailed over time without touching the rest of the definition. Suppose our turnstile starts out trusting any coin unconditionally:
32
+
33
+ ```json
34
+ {
35
+ "Turnstile": [
36
+ ["I", "start", "locked"],
37
+ ["locked", "coin", "unlocked"],
38
+ ["unlocked", "push", "locked"]
39
+ ]
40
+ }
41
+ ```
42
+
43
+ Later, we decide coins should actually be validated before unlocking. Instead of hand-editing this list, we describe the change as an update that (a) adds a new `CoinCheck` sub-FA, and (b) replaces the root so that `"coin"` now leads into it instead of straight to `"unlocked"`:
44
+
45
+ ```typescript
46
+ import { updateCompactFA, FaDefinition, FaUpdate } from '@vsirotin/ts-stop/sfsm';
47
+
48
+ const update: FaUpdate = {
49
+ add: {
50
+ Turnstile: [
51
+ ["I", "start", "locked"],
52
+ ["locked", "coin", "CoinCheck"],
53
+ ["CoinCheck", "CC.ok", "unlocked"],
54
+ ["CoinCheck", "CC.bad", "locked"],
55
+ ["unlocked", "push", "locked"]
56
+ ],
57
+ CoinCheck: [
58
+ ["I", "coin", "checking"],
59
+ ["checking", "CC.ok", "E_ok"],
60
+ ["checking", "CC.bad", "E_bad"]
61
+ ]
62
+ }
63
+ };
64
+
65
+ const detailedTurnstileFa = updateCompactFA(simpleTurnstileFa as FaDefinition, update);
66
+ ```
67
+
68
+ `simpleTurnstileFa` is untouched; `detailedTurnstileFa` now behaves exactly like the original for `start`/`push`, but pushes `CoinCheck` onto the stack on `"coin"` (rule 4 from the previous chapter) and only reaches `"unlocked"` once a `CC.ok` signal arrives — otherwise it falls back to `"locked"` on `CC.bad`. No existing consumer of the FA (nor the SFSM engine itself) needs to change for this to work.
69
+
70
+ A runnable version of this example is available as a unit test: [07-update-fa-add-detail.test.ts](../../ts/ts-stop/test/sfsm/tutorial/07-update-fa-add-detail.test.ts). The full behaviour of `updateCompactFA` / `updateFullFA` (removing FAs, replacing existing ones, pruning dangling transitions, non-mutation of the source) is covered by [FaUpdater.test.ts](../../ts/ts-stop/test/sfsm/FaUpdater.test.ts).
71
+
72
+ ### 7.4 Loading FA definitions from files and URLs
73
+
74
+ Two small helpers load a `FaDefinition` from outside the source code, so FA JSON files can live alongside the code that uses them (or be served remotely) instead of being inlined:
75
+
76
+ ```typescript
77
+ import { Sfsm, loadFAFromFile, FaDefinition } from '@vsirotin/ts-stop/sfsm';
78
+
79
+ const sfsm = new Sfsm({ byMissingTransition: 'error' });
80
+ sfsm.loadFA(loadFAFromFile('./turnstile-fa.json')); // Node.js only (uses fs)
81
+ ```
82
+
83
+ ```typescript
84
+ import { Sfsm, loadFAFromURL, FaDefinition } from '@vsirotin/ts-stop/sfsm';
85
+
86
+ const sfsm = new Sfsm({ byMissingTransition: 'error' });
87
+ sfsm.loadFA(await loadFAFromURL('https://example.com/turnstile-fa.json')); // browser & Node.js ≥ 18
88
+ ```
89
+
90
+ Both accept extended or compact JSON and throw on a failed read/fetch or invalid JSON. Their full behaviour is covered by [FaLoader.test.ts](../../ts/ts-stop/test/sfsm/FaLoader.test.ts).
91
+
92
+ ### 7.5 CLI tools and scripts
93
+
94
+ For one-off conversions and FA manipulations without writing code, the package ships several npm scripts (run from `ts/ts-stop`, after `npm run build`).
95
+
96
+ #### 7.5.1 `reduce-fa` — Convert extended FA to compact format
97
+
98
+ ```bash
99
+ npm run reduce-fa -- <path-to-fa-file>
100
+ # writes <path-to-fa-file>-compact.json (or to stdout if no file extension)
101
+ ```
102
+
103
+ Converts an **extended** (hand-authored) FA definition into the flat **compact** format used at runtime by `Sfsm.loadFA()`. Input can be either extended or compact; compact input passes through unchanged. Thin wrapper around `reduceFA()`, whose behaviour is covered by [FaReducer.test.ts](../../ts/ts-stop/test/sfsm/FaReducer.test.ts).
104
+
105
+ #### 7.5.2 `update-compact-fa` / `update-full-fa` — Apply structured changes to FA definitions
106
+
107
+ ```bash
108
+ npm run update-compact-fa -- --source=<path> --update=<path> [--result=<path>]
109
+ npm run update-full-fa -- --source=<path> --update=<path> [--result=<path>]
110
+ ```
111
+
112
+ Applies a small structured `FaUpdate` descriptor (JSON file with `remove` and/or `add` keys) to an existing FA definition, returning a modified copy without mutating the source. By default, `--result` outputs to `<source-basename>-updated.json` if omitted. Thin wrappers around `updateCompactFA()` / `updateFullFA()`, whose behaviour is covered by [FaUpdater.test.ts](../../ts-stop/test/sfsm/FaUpdater.test.ts).
113
+
114
+ #### 7.5.3 `json-to-drawio` — Convert compact FA JSON to UML state diagram
115
+
116
+ ```bash
117
+ node scripts/json-to-drawio.js <input.json> <output.drawio>
118
+ ```
119
+
120
+ Converts a compact SFSM JSON file into a professional draw.io (.drawio) UML state diagram. Features:
121
+ - **Hierarchical container layout**: Each FA rendered as a swimlane; sub-FAs as nested light-grey containers (100×60 px).
122
+ - **ELK.js hierarchical layout**: Professional automatic positioning of states within each FA using Eclipse Layout Kernel.
123
+ - **Vertical stacking**: Multiple FAs stacked without overlap with 30px spacing.
124
+ - **SFSM metadata preservation**: All state roles, FA names, signals, and commands embedded in cell styles for round-trip conversion.
125
+ - **Initial, plain, sub-FA, and exit states**: All SFSM state types rendered correctly with appropriate UML shapes.
126
+
127
+ Output diagram can be opened in draw.io, inspected visually, and subjected to small manual adjustments (state/container repositioning, style tweaks) to achieve visual perfection without affecting the underlying SFSM data.
128
+
129
+ #### 7.5.4 `drawio-to-json` — Extract compact FA JSON from UML diagram
130
+
131
+ ```bash
132
+ node scripts/drawio-to-json.js <input.drawio> <output.json>
133
+ ```
134
+
135
+ Reverse conversion: reads a draw.io diagram (preferably generated by `json-to-drawio.js`, but can parse hand-drawn diagrams with heuristic fallbacks) and extracts a compact SFSM JSON file. Parses the custom SFSM metadata (sfsmRole, sfsmFa, sfsmKey, sfsmSignal, sfsmCommand) from cell styles; if metadata is absent, applies shape-based heuristics (ellipses for states, swimlanes for sub-FAs, etc.).
136
+
137
+ Output is a valid compact-format FA ready for `Sfsm.loadFA()`.
138
+
139
+ #### 7.5.5 `compare-compact-jsons` — Validate diagram vs. JSON correspondence
140
+
141
+ ```bash
142
+ node scripts/compare-compact-jsons.js <file-a.json> <file-b.json>
143
+ ```
144
+
145
+ Intelligent comparison of two compact SFSM JSON files. Reports per-FA alignment: matching transitions, missing/extra transitions, mismatched targets or commands. Exits with code 0 if files are identical, non-zero if differences found. Designed for round-trip validation: after converting JSON → Diagram → JSON, this script confirms the resulting file matches the original exactly.
146
+
147
+ #### 7.5.6 `merge-fas` / `merge-fas-from-dir` — Combine FA definitions
148
+
149
+ ```bash
150
+ node scripts/merge-fas.js <input1.json> <input2.json> ... --result=<output.json>
151
+ node scripts/merge-fas-from-dir.js <input-dir> --result=<output.json>
152
+ ```
153
+
154
+ Combine multiple compact or extended FA definitions into a single multi-FA output file. Later input files override earlier ones with the same FA key. Useful for modular FA composition and testing multi-FA hierarchies.
155
+
156
+ ### 7.6 AI skills for diagram generation and validation
157
+
158
+ Three AI skills in the [ai-skills directory](../../ts/ts-stop/ai/skills) automate common diagram workflows:
159
+
160
+ - **`sfsm-json-to-uml-diagram`**: Wraps `json-to-drawio.js`. Use when you need to visualize an SFSM JSON definition as a professional draw.io UML state diagram. Generates hierarchical layout with nested sub-FAs and full metadata preservation. Note: the generated diagram is production-ready but may benefit from small manual repositioning of states or containers for optimal visual polish.
161
+
162
+ - **`sfsm-uml-diagram-to-json`**: Wraps `drawio-to-json.js`. Use when you need to extract or reverse-convert a draw.io state diagram back to compact SFSM JSON (e.g., after hand-editing the diagram, or starting from a collaborator's visual design).
163
+
164
+ - **`sfsm-compare-json-uml-diagram`**: Combines `drawio-to-json.js` and `compare-compact-jsons.js`. Use when you need to validate a draw.io diagram against its source JSON (or vice versa). Identifies every discrepancy—missing transitions, state mismatches, command errors—and reports them in a clear diff format. Accepts user-specified input/output paths, requesting them if not provided.
package/LICENSE DELETED
@@ -1,201 +0,0 @@
1
- Apache License
2
- Version 2.0, January 2004
3
- http://www.apache.org/licenses/
4
-
5
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
-
7
- 1. Definitions.
8
-
9
- "License" shall mean the terms and conditions for use, reproduction,
10
- and distribution as defined by Sections 1 through 9 of this document.
11
-
12
- "Licensor" shall mean the copyright owner or entity authorized by
13
- the copyright owner that is granting the License.
14
-
15
- "Legal Entity" shall mean the union of the acting entity and all
16
- other entities that control, are controlled by, or are under common
17
- control with that entity. For the purposes of this definition,
18
- "control" means (i) the power, direct or indirect, to cause the
19
- direction or management of such entity, whether by contract or
20
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
- outstanding shares, or (iii) beneficial ownership of such entity.
22
-
23
- "You" (or "Your") shall mean an individual or Legal Entity
24
- exercising permissions granted by this License.
25
-
26
- "Source" form shall mean the preferred form for making modifications,
27
- including but not limited to software source code, documentation
28
- source, and configuration files.
29
-
30
- "Object" form shall mean any form resulting from mechanical
31
- transformation or translation of a Source form, including but
32
- not limited to compiled object code, generated documentation,
33
- and conversions to other media types.
34
-
35
- "Work" shall mean the work of authorship, whether in Source or
36
- Object form, made available under the License, as indicated by a
37
- copyright notice that is included in or attached to the work
38
- (an example is provided in the Appendix below).
39
-
40
- "Derivative Works" shall mean any work, whether in Source or Object
41
- form, that is based on (or derived from) the Work and for which the
42
- editorial revisions, annotations, elaborations, or other modifications
43
- represent, as a whole, an original work of authorship. For the purposes
44
- of this License, Derivative Works shall not include works that remain
45
- separable from, or merely link (or bind by name) to the interfaces of,
46
- the Work and Derivative Works thereof.
47
-
48
- "Contribution" shall mean any work of authorship, including
49
- the original version of the Work and any modifications or additions
50
- to that Work or Derivative Works thereof, that is intentionally
51
- submitted to Licensor for inclusion in the Work by the copyright owner
52
- or by an individual or Legal Entity authorized to submit on behalf of
53
- the copyright owner. For the purposes of this definition, "submitted"
54
- means any form of electronic, verbal, or written communication sent
55
- to the Licensor or its representatives, including but not limited to
56
- communication on electronic mailing lists, source code control systems,
57
- and issue tracking systems that are managed by, or on behalf of, the
58
- Licensor for the purpose of discussing and improving the Work, but
59
- excluding communication that is conspicuously marked or otherwise
60
- designated in writing by the copyright owner as "Not a Contribution."
61
-
62
- "Contributor" shall mean Licensor and any individual or Legal Entity
63
- on behalf of whom a Contribution has been received by Licensor and
64
- subsequently incorporated within the Work.
65
-
66
- 2. Grant of Copyright License. Subject to the terms and conditions of
67
- this License, each Contributor hereby grants to You a perpetual,
68
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
- copyright license to reproduce, prepare Derivative Works of,
70
- publicly display, publicly perform, sublicense, and distribute the
71
- Work and such Derivative Works in Source or Object form.
72
-
73
- 3. Grant of Patent License. Subject to the terms and conditions of
74
- this License, each Contributor hereby grants to You a perpetual,
75
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
- (except as stated in this section) patent license to make, have made,
77
- use, offer to sell, sell, import, and otherwise transfer the Work,
78
- where such license applies only to those patent claims licensable
79
- by such Contributor that are necessarily infringed by their
80
- Contribution(s) alone or by combination of their Contribution(s)
81
- with the Work to which such Contribution(s) was submitted. If You
82
- institute patent litigation against any entity (including a
83
- cross-claim or counterclaim in a lawsuit) alleging that the Work
84
- or a Contribution incorporated within the Work constitutes direct
85
- or contributory patent infringement, then any patent licenses
86
- granted to You under this License for that Work shall terminate
87
- as of the date such litigation is filed.
88
-
89
- 4. Redistribution. You may reproduce and distribute copies of the
90
- Work or Derivative Works thereof in any medium, with or without
91
- modifications, and in Source or Object form, provided that You
92
- meet the following conditions:
93
-
94
- (a) You must give any other recipients of the Work or
95
- Derivative Works a copy of this License; and
96
-
97
- (b) You must cause any modified files to carry prominent notices
98
- stating that You changed the files; and
99
-
100
- (c) You must retain, in the Source form of any Derivative Works
101
- that You distribute, all copyright, patent, trademark, and
102
- attribution notices from the Source form of the Work,
103
- excluding those notices that do not pertain to any part of
104
- the Derivative Works; and
105
-
106
- (d) If the Work includes a "NOTICE" text file as part of its
107
- distribution, then any Derivative Works that You distribute must
108
- include a readable copy of the attribution notices contained
109
- within such NOTICE file, excluding those notices that do not
110
- pertain to any part of the Derivative Works, in at least one
111
- of the following places: within a NOTICE text file distributed
112
- as part of the Derivative Works; within the Source form or
113
- documentation, if provided along with the Derivative Works; or,
114
- within a display generated by the Derivative Works, if and
115
- wherever such third-party notices normally appear. The contents
116
- of the NOTICE file are for informational purposes only and
117
- do not modify the License. You may add Your own attribution
118
- notices within Derivative Works that You distribute, alongside
119
- or as an addendum to the NOTICE text from the Work, provided
120
- that such additional attribution notices cannot be construed
121
- as modifying the License.
122
-
123
- You may add Your own copyright statement to Your modifications and
124
- may provide additional or different license terms and conditions
125
- for use, reproduction, or distribution of Your modifications, or
126
- for any such Derivative Works as a whole, provided Your use,
127
- reproduction, and distribution of the Work otherwise complies with
128
- the conditions stated in this License.
129
-
130
- 5. Submission of Contributions. Unless You explicitly state otherwise,
131
- any Contribution intentionally submitted for inclusion in the Work
132
- by You to the Licensor shall be under the terms and conditions of
133
- this License, without any additional terms or conditions.
134
- Notwithstanding the above, nothing herein shall supersede or modify
135
- the terms of any separate license agreement you may have executed
136
- with Licensor regarding such Contributions.
137
-
138
- 6. Trademarks. This License does not grant permission to use the trade
139
- names, trademarks, service marks, or product names of the Licensor,
140
- except as required for reasonable and customary use in describing the
141
- origin of the Work and reproducing the content of the NOTICE file.
142
-
143
- 7. Disclaimer of Warranty. Unless required by applicable law or
144
- agreed to in writing, Licensor provides the Work (and each
145
- Contributor provides its Contributions) on an "AS IS" BASIS,
146
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
- implied, including, without limitation, any warranties or conditions
148
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
- PARTICULAR PURPOSE. You are solely responsible for determining the
150
- appropriateness of using or redistributing the Work and assume any
151
- risks associated with Your exercise of permissions under this License.
152
-
153
- 8. Limitation of Liability. In no event and under no legal theory,
154
- whether in tort (including negligence), contract, or otherwise,
155
- unless required by applicable law (such as deliberate and grossly
156
- negligent acts) or agreed to in writing, shall any Contributor be
157
- liable to You for damages, including any direct, indirect, special,
158
- incidental, or consequential damages of any character arising as a
159
- result of this License or out of the use or inability to use the
160
- Work (including but not limited to damages for loss of goodwill,
161
- work stoppage, computer failure or malfunction, or any and all
162
- other commercial damages or losses), even if such Contributor
163
- has been advised of the possibility of such damages.
164
-
165
- 9. Accepting Warranty or Additional Liability. While redistributing
166
- the Work or Derivative Works thereof, You may choose to offer,
167
- and charge a fee for, acceptance of support, warranty, indemnity,
168
- or other liability obligations and/or rights consistent with this
169
- License. However, in accepting such obligations, You may act only
170
- on Your own behalf and on Your sole responsibility, not on behalf
171
- of any other Contributor, and only if You agree to indemnify,
172
- defend, and hold each Contributor harmless for any liability
173
- incurred by, or claims asserted against, such Contributor by reason
174
- of your accepting any such warranty or additional liability.
175
-
176
- END OF TERMS AND CONDITIONS
177
-
178
- APPENDIX: How to apply the Apache License to your work.
179
-
180
- To apply the Apache License to your work, attach the following
181
- boilerplate notice, with the fields enclosed by brackets "[]"
182
- replaced with your own identifying information. (Don't include
183
- the brackets!) The text should be enclosed in the appropriate
184
- comment syntax for the file format. We also recommend that a
185
- file or class name and description of purpose be included on the
186
- same "printed page" as the copyright notice for easier
187
- identification within third-party archives.
188
-
189
- Copyright [yyyy] [name of copyright owner]
190
-
191
- Licensed under the Apache License, Version 2.0 (the "License");
192
- you may not use this file except in compliance with the License.
193
- You may obtain a copy of the License at
194
-
195
- http://www.apache.org/licenses/LICENSE-2.0
196
-
197
- Unless required by applicable law or agreed to in writing, software
198
- distributed under the License is distributed on an "AS IS" BASIS,
199
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
- See the License for the specific language governing permissions and
201
- limitations under the License.
@@ -1,41 +0,0 @@
1
- # StOP Commercial License
2
-
3
- **Version 1.0**
4
-
5
- ## 1. Grant of Commercial License
6
-
7
- This Commercial License grants you permission to use the StOP library in commercial projects under the conditions specified in Section 2.
8
-
9
- ## 2. Commercial Use Restrictions
10
-
11
- You may use StOP under the **free Apache 2.0 license** if:
12
-
13
- - Your organization has fewer than 10 employees, **AND**
14
- - Your project generates less than $10,000 USD in annual revenue
15
-
16
- If your organization or project exceeds either threshold, you must:
17
-
18
- - Obtain a separate Commercial License from the copyright holder, or
19
- - Use the library under the Apache 2.0 license with explicit written permission from the copyright holder
20
-
21
- ## 3. Obtaining a Commercial License
22
-
23
- To request a Commercial License for organizations with 10+ employees or projects generating $10,000+ USD annually:
24
-
25
- **Contact the author through the GitHub repository for licensing terms and pricing.**
26
-
27
- Commercial licenses are available at reasonable rates. Please reach out to discuss your specific use case.
28
-
29
- ## 4. Terms
30
-
31
- - Commercial licenses are granted on a per-project or per-organization basis
32
- - Licensing terms will be negotiated based on project scope and revenue
33
- - All commercial licensees must comply with the underlying Apache 2.0 obligations regarding patents and attribution
34
-
35
- ## 5. Disclaimer
36
-
37
- This Commercial License is provided in addition to, not in place of, the Apache 2.0 License. In the event of conflict, the more restrictive terms apply. For clarity on your licensing obligations, please contact the copyright holder.
38
-
39
- ## 6. Termination
40
-
41
- If you exceed the commercial use thresholds (10+ employees or $10,000+ annual revenue) without obtaining a Commercial License, your right to use the library terminates immediately upon notice.
@@ -1,9 +0,0 @@
1
- /**
2
- * Marker base class for states that should be used processed by invalid signals and
3
- * in situation, then no transitions set for pair (current signal, current state).
4
- * Only one state in a state machine can have this role.
5
- */
6
- export declare abstract class DefaultState {
7
- isDefaultState(): boolean;
8
- }
9
- //# sourceMappingURL=DefaultState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DefaultState.d.ts","sourceRoot":"","sources":["../src/DefaultState.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,8BAAsB,YAAY;IAC9B,cAAc,IAAI,OAAO;CAG5B"}
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DefaultState = void 0;
4
- /**
5
- * Marker base class for states that should be used processed by invalid signals and
6
- * in situation, then no transitions set for pair (current signal, current state).
7
- * Only one state in a state machine can have this role.
8
- */
9
- class DefaultState {
10
- isDefaultState() {
11
- return true;
12
- }
13
- }
14
- exports.DefaultState = DefaultState;
15
- //# sourceMappingURL=DefaultState.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DefaultState.js","sourceRoot":"","sources":["../src/DefaultState.ts"],"names":[],"mappings":";;;AAAA;;;;GAIG;AACH,MAAsB,YAAY;IAC9B,cAAc;QACV,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAJD,oCAIC"}