aifsmjs 0.4.0 → 0.5.0
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/LICENSE +1 -1
- package/llms-full.txt +17 -4
- package/package.json +2 -3
- package/STABILITY.md +0 -87
package/LICENSE
CHANGED
package/llms-full.txt
CHANGED
|
@@ -543,6 +543,19 @@ All notable changes to this project will be documented in this file.
|
|
|
543
543
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
544
544
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
545
545
|
|
|
546
|
+
## [0.4.1] — 2026-05-29
|
|
547
|
+
|
|
548
|
+
### Changed
|
|
549
|
+
|
|
550
|
+
- **`STABILITY.md` is now repo-only** — removed from the npm `files`
|
|
551
|
+
allowlist, aligning with the majority of the ai*js family (5 of 7
|
|
552
|
+
packages already ship the stability contract repo-only). The file stays
|
|
553
|
+
in the repository and remains visible on GitHub and the rendered npm
|
|
554
|
+
package page; it is simply no longer bundled inside the published
|
|
555
|
+
tarball. Packaging consistency patch: **no runtime API change, no
|
|
556
|
+
signature change**; the built bundles (`dist/`) are byte-identical to
|
|
557
|
+
0.4.0 (core gzip 4,387 B).
|
|
558
|
+
|
|
546
559
|
## [0.4.0] — 2026-05-29
|
|
547
560
|
|
|
548
561
|
### Changed
|
|
@@ -956,10 +969,10 @@ pnpm example:form-wizard # 04-form-wizard
|
|
|
956
969
|
|
|
957
970
|
| # | Example | What it shows | Real-world pattern |
|
|
958
971
|
|---|---|---|---|
|
|
959
|
-
| 01 | [traffic-light](01-traffic-light/index.ts) | Minimal `setup → defineMachine → createRuntime → send` loop with `assign` and a snapshot subscriber. | Cyclic scene flow (loading → menu → playing → result → loading) — or any 3-state cycle. |
|
|
960
|
-
| 02 | [approval-workflow](02-approval-workflow/index.ts) | Multi-candidate guarded transitions (`and([...])`), effects + handlers, `persist` + `recorder` middleware, and `replay()` to reproduce the final snapshot. | Document approval, ticket triage, turn-based games with branching outcomes + post-mortem replay. |
|
|
961
|
-
| 03 | [checkout-funnel](03-checkout-funnel/index.ts) | E-commerce checkout: cart → shipping → payment → review → confirmed. Per-stage validation as guards, payment + analytics as effects, full replay of the funnel. | Plain web app — no canvas, no game loop. Demonstrates that aifsmjs models classic UX funnels. |
|
|
962
|
-
| 04 | [form-wizard](04-form-wizard/index.ts) | Multi-step form wizard with back / next / jump-to-step navigation. Per-step validation, draft persistence via the `persist` middleware. | Account onboarding, settings editor, multi-page survey. |
|
|
972
|
+
| 01 | [traffic-light](https://github.com/yshengliao/aifsmjs/blob/main/examples/01-traffic-light/index.ts) | Minimal `setup → defineMachine → createRuntime → send` loop with `assign` and a snapshot subscriber. | Cyclic scene flow (loading → menu → playing → result → loading) — or any 3-state cycle. |
|
|
973
|
+
| 02 | [approval-workflow](https://github.com/yshengliao/aifsmjs/blob/main/examples/02-approval-workflow/index.ts) | Multi-candidate guarded transitions (`and([...])`), effects + handlers, `persist` + `recorder` middleware, and `replay()` to reproduce the final snapshot. | Document approval, ticket triage, turn-based games with branching outcomes + post-mortem replay. |
|
|
974
|
+
| 03 | [checkout-funnel](https://github.com/yshengliao/aifsmjs/blob/main/examples/03-checkout-funnel/index.ts) | E-commerce checkout: cart → shipping → payment → review → confirmed. Per-stage validation as guards, payment + analytics as effects, full replay of the funnel. | Plain web app — no canvas, no game loop. Demonstrates that aifsmjs models classic UX funnels. |
|
|
975
|
+
| 04 | [form-wizard](https://github.com/yshengliao/aifsmjs/blob/main/examples/04-form-wizard/index.ts) | Multi-step form wizard with back / next / jump-to-step navigation. Per-step validation, draft persistence via the `persist` middleware. | Account onboarding, settings editor, multi-page survey. |
|
|
963
976
|
|
|
964
977
|
## Notes
|
|
965
978
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aifsmjs",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Small, strict FSM library for deterministic, replayable state machines in any TypeScript/JS app — multi-step forms, checkout funnels, auth flows, tutorials, scene flow. Pure step() lifecycle, opt-in effects, inspect, replay, and a fast-check property-based testing adapter. Browser / Node / Bun / Deno / WebView / Worker friendly.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"fsm",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"typescript",
|
|
19
19
|
"esm"
|
|
20
20
|
],
|
|
21
|
-
"author": "
|
|
21
|
+
"author": "yshengliao",
|
|
22
22
|
"license": "MIT",
|
|
23
23
|
"homepage": "https://github.com/yshengliao/aifsmjs#readme",
|
|
24
24
|
"repository": {
|
|
@@ -74,7 +74,6 @@
|
|
|
74
74
|
"dist",
|
|
75
75
|
"README.md",
|
|
76
76
|
"README_ZHTW.md",
|
|
77
|
-
"STABILITY.md",
|
|
78
77
|
"LICENSE",
|
|
79
78
|
"llms.txt",
|
|
80
79
|
"llms-full.txt"
|
package/STABILITY.md
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
# Stability
|
|
2
|
-
|
|
3
|
-
This document defines the stability tier of every public symbol exported by
|
|
4
|
-
`aifsmjs`. Tiers govern what breaks may occur in future minor / major bumps.
|
|
5
|
-
|
|
6
|
-
## Stable (since 0.1.0)
|
|
7
|
-
|
|
8
|
-
Fully stable. Breaking changes only at a major version bump (1.0+).
|
|
9
|
-
|
|
10
|
-
- `createMachine`, `defineMachine`, `setup`, `createRuntime`, `initialSnapshot`
|
|
11
|
-
- `step`, `resolveTransitions`, `evalGuard`, `resolveGuard`, `isAsyncGuardFn`
|
|
12
|
-
- `assign`, `mergeContext`, `createSnapshot`, `deepFreeze`, `freezeSnapshot`
|
|
13
|
-
- `Runtime.send`, `Runtime.reset`, `Runtime.can`, `Runtime.getSnapshot`,
|
|
14
|
-
`Runtime.snapshot`, `Runtime.subscribe`, `Runtime.on`, `Runtime.dispose`,
|
|
15
|
-
`Runtime.signal`, `Runtime.disposed`
|
|
16
|
-
- All error classes from 0.1.0–0.2.1: `RuntimeDisposedError`,
|
|
17
|
-
`InvalidDefinitionError`, `UnknownActionError`, `UnknownGuardError`,
|
|
18
|
-
`AsyncGuardError`
|
|
19
|
-
- Types: `MachineDef`, `StateDef` (fields `on`, `entry`, `exit`, `final`),
|
|
20
|
-
`TransitionDef`, `Snapshot`, `Implementations`, `Guard`, `Action`,
|
|
21
|
-
`EffectHandler`, `Effect`, `Enqueuer`, `Middleware`, `MiddlewareContext`,
|
|
22
|
-
`RuntimeOptions`, `StepResult`, `ResetEvent`, `RESET_EVENT_TYPE`,
|
|
23
|
-
`RuntimeTransitionEvent`, `RuntimeErrorEvent`, `RuntimeEventMap`
|
|
24
|
-
- All subpath exports: `aifsmjs/guards`, `aifsmjs/effects`, `aifsmjs/inspect`,
|
|
25
|
-
`aifsmjs/replay`, `aifsmjs/pbt`, `aifsmjs/timer`
|
|
26
|
-
- `Runtime.onTransition` (added in 0.3.0) — pure sugar over the stable
|
|
27
|
-
`on('transition', ...)` API; listed under Stable because the underlying
|
|
28
|
-
contract is unchanged.
|
|
29
|
-
|
|
30
|
-
### Sub-machines (stable since 0.4.0)
|
|
31
|
-
|
|
32
|
-
The hierarchical sub-machine surface shipped experimentally in 0.3.0 is
|
|
33
|
-
stable as of 0.4.0. Signatures and runtime semantics — including the
|
|
34
|
-
init-failure quarantine behaviour described below — are frozen for the 1.x
|
|
35
|
-
line. The boundaries listed are intentional design trade-offs, not bugs or
|
|
36
|
-
pending instability.
|
|
37
|
-
|
|
38
|
-
- `StateDef.sub` (optional `SubMachineDef`) — when present, a child runtime
|
|
39
|
-
is lazily initialised on entry and disposed on exit. Per-transition
|
|
40
|
-
ordering is parent `step()` (exit / actions / entry) → child dispose →
|
|
41
|
-
child init → snapshot commit.
|
|
42
|
-
- `StateDef.subImpl` (optional `Implementations`) — paired with `sub`;
|
|
43
|
-
passed to the child `createRuntime`. Defaults to `{}`.
|
|
44
|
-
- `Runtime.subRuntime()` — returns the live child handle, or `undefined`.
|
|
45
|
-
Returned generic is `Runtime<unknown, { type: string }, string>`; caller
|
|
46
|
-
narrows via cast if necessary.
|
|
47
|
-
- `SubMachineError` — thrown by `send()` / `reset()` on child init/dispose
|
|
48
|
-
failure. Fields: `parentState`, `phase ("init" | "dispose")`, `cause`.
|
|
49
|
-
- `SubMachineDef` type alias.
|
|
50
|
-
|
|
51
|
-
#### Design boundaries
|
|
52
|
-
|
|
53
|
-
- **Replay / PBT do not see child state.** `replay()` and
|
|
54
|
-
`commandsFromMachine` only inspect parent snapshots. If your business
|
|
55
|
-
logic lives in the parent layer, replay is still deterministic.
|
|
56
|
-
- **`subRuntime()` may return a disposed handle** if an external caller
|
|
57
|
-
disposed it. The handle is not reinitialised until the parent leaves and
|
|
58
|
-
re-enters the sub-bearing state. Detect with `child.disposed`.
|
|
59
|
-
- **Self-targeting external (`A → A`) is treated as full exit/entry**:
|
|
60
|
-
child is disposed and reinitialised. The dispatcher re-resolves guards to
|
|
61
|
-
identify the chosen transition before deciding external vs internal, so
|
|
62
|
-
guarded internal transitions on the same event do not trigger a reinit.
|
|
63
|
-
- **Init-failure mid-transition leaves the parent without a live child.**
|
|
64
|
-
If `applySubLifecycle` successfully disposes the old child and then the
|
|
65
|
-
new child's `createRuntime` throws, the parent's snapshot is rolled back
|
|
66
|
-
to `prev` but `subRuntime()` returns `undefined`. Callers catching
|
|
67
|
-
`SubMachineError(phase: "init")` should treat the runtime as quarantined
|
|
68
|
-
— call `runtime.dispose()` (idempotent) or `runtime.reset()` (which
|
|
69
|
-
attempts re-init) before sending further events. This quarantine
|
|
70
|
-
behaviour is part of the stable contract; a future **major** version may
|
|
71
|
-
switch to a two-phase "init before dispose" commit strategy (a breaking
|
|
72
|
-
change reserved for 1.0+), but the current semantics are frozen for the
|
|
73
|
-
1.x line.
|
|
74
|
-
|
|
75
|
-
## Experimental
|
|
76
|
-
|
|
77
|
-
No experimental APIs as of 0.4.0. The 0.3.0 sub-machine surface graduated to
|
|
78
|
-
Stable in 0.4.0 — see "Sub-machines" above.
|
|
79
|
-
|
|
80
|
-
## Draft (planned, not implemented)
|
|
81
|
-
|
|
82
|
-
API sketched, not shipped. May change before release.
|
|
83
|
-
|
|
84
|
-
- `historyState` (candidate for a future minor) — opt-in pseudo-state that
|
|
85
|
-
remembers the last active sub-state on re-entry. Workaround in 0.3.0:
|
|
86
|
-
snapshot the sub-runtime's value on exit via `onTransition`, restore
|
|
87
|
-
manually.
|