@rotorsoft/act-diagram 0.3.10 → 1.0.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/README.md +117 -152
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/cli/colors.d.ts +19 -0
- package/dist/@types/cli/colors.d.ts.map +1 -0
- package/dist/@types/cli/contract-index.d.ts +57 -0
- package/dist/@types/cli/contract-index.d.ts.map +1 -0
- package/dist/@types/cli/format.d.ts +22 -0
- package/dist/@types/cli/format.d.ts.map +1 -0
- package/dist/@types/cli/index.d.ts +32 -0
- package/dist/@types/cli/index.d.ts.map +1 -0
- package/dist/@types/cli/json-schema.d.ts +13 -0
- package/dist/@types/cli/json-schema.d.ts.map +1 -0
- package/dist/@types/cli/load-project.d.ts +15 -0
- package/dist/@types/cli/load-project.d.ts.map +1 -0
- package/dist/@types/cli/markdown.d.ts +3 -0
- package/dist/@types/cli/markdown.d.ts.map +1 -0
- package/dist/@types/cli/open-editor.d.ts +23 -0
- package/dist/@types/cli/open-editor.d.ts.map +1 -0
- package/dist/@types/cli/repl.d.ts +3 -0
- package/dist/@types/cli/repl.d.ts.map +1 -0
- package/dist/@types/cli/vim-keys.d.ts +34 -0
- package/dist/@types/cli/vim-keys.d.ts.map +1 -0
- package/dist/@types/client/components/Diagram.d.ts.map +1 -1
- package/dist/@types/client/lib/build-model.d.ts.map +1 -1
- package/dist/@types/client/lib/layout.d.ts +6 -0
- package/dist/@types/client/lib/layout.d.ts.map +1 -1
- package/dist/@types/client/lib/schema-extract.d.ts +37 -0
- package/dist/@types/client/lib/schema-extract.d.ts.map +1 -0
- package/dist/@types/client/types/domain-model.d.ts +15 -0
- package/dist/@types/client/types/domain-model.d.ts.map +1 -1
- package/dist/cli/act.js +3324 -0
- package/dist/cli/act.js.map +1 -0
- package/dist/index.cjs +413 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +413 -39
- package/dist/index.js.map +1 -1
- package/dist/styles.css +2 -2
- package/package.json +14 -8
package/README.md
CHANGED
|
@@ -4,79 +4,45 @@
|
|
|
4
4
|
[](https://www.npmjs.com/package/@rotorsoft/act-diagram)
|
|
5
5
|
[](https://opensource.org/licenses/MIT)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
_Interactive domain model diagram for [@rotorsoft/act](https://www.npmjs.com/package/@rotorsoft/act). Reads your TypeScript, renders an SVG of states, slices, projections, and reactions — with click-through to source._
|
|
8
8
|
|
|
9
|
-
##
|
|
9
|
+
## Why this package
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
- **High test coverage** — over 300 tests covering extraction, layout, navigation, and error paths
|
|
11
|
+
Act apps grow horizontally — more states, more slices, more projections, more reactions — and at some point the mental model of "what fires what" stops fitting in your head. This package solves that two ways:
|
|
12
|
+
|
|
13
|
+
A **React component** that renders the live domain model as an interactive SVG, with click-to-source navigation. Drop it into an IDE webview (VS Code, Cursor, Neovim via [`act-nvim`](https://github.com/Rotorsoft/act-nvim)), a docs site, or a standalone explorer. Per-slice error isolation means a broken file shows its error in the slice boundary while healthy slices keep rendering.
|
|
14
|
+
|
|
15
|
+
A **terminal CLI** (`act`) that walks the same parsed model interactively, surfaces captured Zod schemas, flags deprecation via the `_v<n>` convention, and jumps into `$EDITOR` at the exact `file:line`. Use it when you want the structural answer ("who emits `TicketOpened`?") without leaving the terminal.
|
|
16
|
+
|
|
17
|
+
Both reuse the same extraction pipeline — mock builders + Sucrase transpile — so the diagram and the CLI always agree.
|
|
19
18
|
|
|
20
19
|
## Installation
|
|
21
20
|
|
|
22
|
-
```
|
|
23
|
-
npm install @rotorsoft/act-diagram
|
|
24
|
-
# or
|
|
21
|
+
```bash
|
|
25
22
|
pnpm add @rotorsoft/act-diagram
|
|
26
23
|
```
|
|
27
24
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
The component ships its own stylesheet — import it once at the host's entry point:
|
|
25
|
+
The React component ships its own stylesheet — import it once at your host's entry point:
|
|
31
26
|
|
|
32
27
|
```ts
|
|
33
28
|
import "@rotorsoft/act-diagram/styles.css";
|
|
34
29
|
```
|
|
35
30
|
|
|
36
|
-
|
|
31
|
+
The CLI ships as the `act` bin:
|
|
37
32
|
|
|
33
|
+
```bash
|
|
34
|
+
npx -p @rotorsoft/act-diagram act
|
|
35
|
+
# or, in a workspace that depends on it:
|
|
36
|
+
pnpm act
|
|
38
37
|
```
|
|
39
|
-
TypeScript files (.ts)
|
|
40
|
-
|
|
|
41
|
-
v
|
|
42
|
-
topoSort() ← order files by import dependencies
|
|
43
|
-
|
|
|
44
|
-
v
|
|
45
|
-
extractModel() ← transpile + execute with mock builders → DomainModel
|
|
46
|
-
| inventory scan → per-state validation → per-slice error isolation
|
|
47
|
-
v
|
|
48
|
-
validate() ← check for missing emits, orphan reactions, etc.
|
|
49
|
-
|
|
|
50
|
-
v
|
|
51
|
-
computeLayout() ← pure layout: positions nodes, edges, slice boxes, projections
|
|
52
|
-
|
|
|
53
|
-
v
|
|
54
|
-
<Diagram /> ← SVG rendering with pan/zoom/model tree/errors section
|
|
55
|
-
|
|
|
56
|
-
v
|
|
57
|
-
navigateToCode() ← click element → { file, line, col }
|
|
58
|
-
```
|
|
59
|
-
|
|
60
|
-
### Extraction Pipeline
|
|
61
|
-
|
|
62
|
-
The extraction uses mock versions of `state()`, `slice()`, `projection()`, and `act()` that capture the builder structure without needing the real framework runtime. Code is transpiled with [Sucrase](https://github.com/alangpierce/sucrase) and evaluated in an isolated scope.
|
|
63
|
-
|
|
64
|
-
**Bottom-up model building:**
|
|
65
|
-
|
|
66
|
-
1. **Inventory** — scan source files for all `state()`, `slice()`, `projection()`, `act()` declarations
|
|
67
|
-
2. **Build states** — validate each state independently (detects undefined schemas from broken imports)
|
|
68
|
-
3. **Build slices** — compose states from step 2, track missing/corrupted references per slice
|
|
69
|
-
4. **Build projections** — extract projection handlers
|
|
70
|
-
5. **Compose act** — wire slices + projections + reactions into entries, standalone states into a "global" slice
|
|
71
38
|
|
|
72
|
-
|
|
39
|
+
## Quick start
|
|
73
40
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
### Standalone Component
|
|
41
|
+
### React component
|
|
77
42
|
|
|
78
43
|
```tsx
|
|
79
44
|
import { ActDiagram } from "@rotorsoft/act-diagram";
|
|
45
|
+
import "@rotorsoft/act-diagram/styles.css";
|
|
80
46
|
|
|
81
47
|
function App() {
|
|
82
48
|
return (
|
|
@@ -86,25 +52,82 @@ function App() {
|
|
|
86
52
|
{ path: "src/app.ts", content: "..." },
|
|
87
53
|
]}
|
|
88
54
|
onNavigate={(file, line, col) => {
|
|
89
|
-
console.log(`
|
|
55
|
+
console.log(`open ${file}:${line}:${col}`);
|
|
90
56
|
}}
|
|
91
57
|
/>
|
|
92
58
|
);
|
|
93
59
|
}
|
|
94
60
|
```
|
|
95
61
|
|
|
96
|
-
###
|
|
62
|
+
### CLI
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pnpm act # interactive: pick category → entry → detail
|
|
66
|
+
pnpm act packages/wolfdesk # target a specific package
|
|
67
|
+
pnpm act -q TicketOpened # non-interactive: print one entity, exit
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Interactive mode uses arrow-key navigation ([`@clack/prompts`](https://github.com/natemoo-re/clack)). Each entry shows producers, consumers, captured Zod schema text, deprecation status, and a one-key shortcut to open the source in `$EDITOR` (VS Code, Cursor, vim, nvim, nano, emacs all recognized). `-q <name>` is the script-friendly path — exits 0 with the detail on a single match, 0 with the match list on ambiguity, 1 with no matches. CI smoke-tests parsing with this mode.
|
|
71
|
+
|
|
72
|
+
## API
|
|
73
|
+
|
|
74
|
+
### React components
|
|
75
|
+
|
|
76
|
+
| Component | Purpose |
|
|
77
|
+
|---|---|
|
|
78
|
+
| `ActDiagram` | Standalone wrapper — pipeline + diagram + optional AI bar. `onNavigate(file, line, col, type?)` for click-to-source. |
|
|
79
|
+
| `Diagram` | Raw SVG diagram with pan/zoom/model tree/warnings. Use when you want to drive the pipeline yourself. |
|
|
80
|
+
| `AiBar` | Resizable prompt input with model and token controls (optional refinement bar). |
|
|
81
|
+
| `Logo`, `Tooltip` | Small UI primitives used inside the diagram, exported for host reuse. |
|
|
82
|
+
|
|
83
|
+
### Functions
|
|
84
|
+
|
|
85
|
+
| Function | Purpose |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `extractModel(files)` | High-level extract: `topoSort` + `buildModel`. Returns `{ model, error? }`. |
|
|
88
|
+
| `buildModel(files)` | Lower-level: transpile + execute per-file, returns merged inventory + per-file errors. |
|
|
89
|
+
| `validate(model)` | Check for missing emits, orphan reactions, etc. Returns `ValidationWarning[]`. |
|
|
90
|
+
| `navigateToCode(files, name, type?)` | Pure function — find `{ file, line, col }` for a named element. |
|
|
91
|
+
| `topoSort(files)` | Sort files by import dependency order. |
|
|
92
|
+
| `computeLayout(model)` | Pure layout — positions nodes, edges, slice boxes. |
|
|
93
|
+
| `emptyModel()` | Construct an empty `DomainModel`. |
|
|
94
|
+
| `parseMultiFileResponse(text)`, `stripFences(text)`, `deriveProjectName(files)` | AI-pipeline helpers used by `ActDiagram` when `onAiRequest` is wired. |
|
|
95
|
+
|
|
96
|
+
### IDE plugin protocol (postMessage)
|
|
97
|
+
|
|
98
|
+
```ts
|
|
99
|
+
// Host → Diagram
|
|
100
|
+
type HostMessage =
|
|
101
|
+
| { type: "files"; files: FileTab[] }
|
|
102
|
+
| { type: "fileAdded"; path: string; content: string }
|
|
103
|
+
| { type: "fileChanged"; path: string; content: string }
|
|
104
|
+
| { type: "fileDeleted"; path: string };
|
|
105
|
+
|
|
106
|
+
// Diagram → Host
|
|
107
|
+
type DiagramMessage =
|
|
108
|
+
| { type: "navigate"; file: string; line: number; col: number }
|
|
109
|
+
| { type: "aiRequest"; prompt: string; files: FileTab[] };
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
Full type reference: [typedoc](https://github.com/Rotorsoft/act-root/blob/master/docs/docs/api/act-diagram/src/README.md).
|
|
113
|
+
|
|
114
|
+
## Common patterns
|
|
115
|
+
|
|
116
|
+
### IDE webview (postMessage)
|
|
97
117
|
|
|
98
118
|
```tsx
|
|
99
|
-
// In the webview
|
|
100
119
|
<ActDiagram usePostMessage onNavigate={handleNavigate} />
|
|
120
|
+
```
|
|
101
121
|
|
|
102
|
-
|
|
122
|
+
```ts
|
|
123
|
+
// From the extension host:
|
|
103
124
|
webview.postMessage({ type: "files", files: [...] });
|
|
104
125
|
webview.postMessage({ type: "fileChanged", path: "src/app.ts", content: "..." });
|
|
105
126
|
```
|
|
106
127
|
|
|
107
|
-
|
|
128
|
+
The webview side picks up host messages automatically when `usePostMessage` is set; the diagram emits `navigate` and `aiRequest` back through `window.parent.postMessage`.
|
|
129
|
+
|
|
130
|
+
### Bring-your-own pipeline
|
|
108
131
|
|
|
109
132
|
```tsx
|
|
110
133
|
import { Diagram, extractModel, validate } from "@rotorsoft/act-diagram";
|
|
@@ -115,123 +138,65 @@ const warnings = validate(model);
|
|
|
115
138
|
<Diagram
|
|
116
139
|
model={model}
|
|
117
140
|
warnings={warnings}
|
|
118
|
-
onClickElement={(name, type, file) => {
|
|
141
|
+
onClickElement={(name, type, file) => {/* … */}}
|
|
119
142
|
/>
|
|
120
143
|
```
|
|
121
144
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```typescript
|
|
125
|
-
import { navigateToCode } from "@rotorsoft/act-diagram";
|
|
126
|
-
|
|
127
|
-
const result = navigateToCode(files, "OpenTicket", "action");
|
|
128
|
-
// → { file: "src/states.ts", line: 24, col: 7 }
|
|
129
|
-
```
|
|
145
|
+
Use when you want to cache the extracted model, run extraction in a worker, or wire it to a non-standard file source.
|
|
130
146
|
|
|
131
|
-
|
|
147
|
+
### Optional AI refinement
|
|
132
148
|
|
|
133
|
-
|
|
149
|
+
The `AiBar` component dispatches refinement prompts to a streaming endpoint. A reference SSE server lives at `src/server/server.ts` (port 4002) and forwards prompts to Anthropic's API:
|
|
134
150
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
| `Diagram` | `model`, `warnings`, `onClickElement?`, `onFixWithAi?`, `toolbarExtra?` | Raw SVG diagram with pan/zoom/model tree/warnings |
|
|
139
|
-
| `AiBar` | `onSubmit`, `generating?` | Resizable prompt input with model and token controls |
|
|
140
|
-
| `Logo` | `size?` | Act logo SVG |
|
|
141
|
-
| `Tooltip` | `title`, `description?`, `details?`, `children`, `position?`, `align?` | Hover tooltip |
|
|
151
|
+
```bash
|
|
152
|
+
ANTHROPIC_API_KEY=sk-ant-... pnpm -F @rotorsoft/act-diagram dev:server
|
|
153
|
+
```
|
|
142
154
|
|
|
143
|
-
|
|
155
|
+
In your host:
|
|
144
156
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
| `topoSort` | `(files: FileTab[]) => FileTab[]` | Sort files by import dependency order |
|
|
152
|
-
| `computeLayout` | `(model: DomainModel) => Layout` | Pure layout computation — positions all nodes, edges, and slice boxes |
|
|
153
|
-
| `emptyModel` | `() => DomainModel` | Create an empty domain model |
|
|
154
|
-
| `parseMultiFileResponse` | `(text: string) => FileTab[]` | Parse a multi-file AI response into individual `FileTab`s |
|
|
155
|
-
| `stripFences` | `(text: string) => string` | Strip Markdown code fences from a block — used by the AI pipeline to extract raw code |
|
|
156
|
-
| `deriveProjectName` | `(files: FileTab[]) => string` | Best-effort project name from the file set — used in the AI prompt context |
|
|
157
|
-
|
|
158
|
-
### Types
|
|
159
|
-
|
|
160
|
-
```typescript
|
|
161
|
-
type FileTab = { path: string; content: string };
|
|
162
|
-
|
|
163
|
-
type ExecuteResult = {
|
|
164
|
-
model: DomainModel;
|
|
165
|
-
errors: Record<string, string>; // keyed by file path
|
|
166
|
-
};
|
|
167
|
-
|
|
168
|
-
type DomainModel = {
|
|
169
|
-
entries: EntryPoint[];
|
|
170
|
-
states: StateNode[];
|
|
171
|
-
slices: SliceNode[];
|
|
172
|
-
projections: ProjectionNode[];
|
|
173
|
-
reactions: ReactionNode[];
|
|
174
|
-
orchestrator?: ActNode; // present only after `act()` is composed
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
type StateNode = { name, varName, events: EventNode[], actions: ActionNode[], file?, line? };
|
|
178
|
-
type ActionNode = { name, emits: string[], invariants: string[], line? };
|
|
179
|
-
type EventNode = { name, hasCustomPatch: boolean, line? };
|
|
180
|
-
type SliceNode = { name, states: string[], stateVars: string[], projections: string[], reactions: ReactionNode[], error?, file?, line? };
|
|
181
|
-
type ProjectionNode = { name, varName, handles: string[], line? };
|
|
182
|
-
type ReactionNode = { event, handlerName, dispatches: string[], line? };
|
|
183
|
-
|
|
184
|
-
// Layout types
|
|
185
|
-
type Box = { x, y, w, h, label, error? };
|
|
186
|
-
type Layout = { ns: N[], es: E[], boxes: Box[], minX, minY, width, height };
|
|
157
|
+
```tsx
|
|
158
|
+
<ActDiagram
|
|
159
|
+
onAiRequest={(prompt, files) =>
|
|
160
|
+
fetch("http://localhost:4002/api/generate", { /* … */ })
|
|
161
|
+
}
|
|
162
|
+
/>
|
|
187
163
|
```
|
|
188
164
|
|
|
189
|
-
|
|
165
|
+
The reference server is a thin SSE relay — bring your own API key, model selection, and prompt strategy. AI mode is opt-in: omit `onAiRequest` and the `AiBar` doesn't render.
|
|
190
166
|
|
|
191
|
-
|
|
192
|
-
// Host → Diagram
|
|
193
|
-
type HostMessage =
|
|
194
|
-
| { type: "files"; files: FileTab[] }
|
|
195
|
-
| { type: "fileAdded"; path: string; content: string }
|
|
196
|
-
| { type: "fileChanged"; path: string; content: string }
|
|
197
|
-
| { type: "fileDeleted"; path: string };
|
|
167
|
+
### Neovim integration
|
|
198
168
|
|
|
199
|
-
|
|
200
|
-
type DiagramMessage =
|
|
201
|
-
| { type: "navigate"; file: string; line: number; col: number }
|
|
202
|
-
| { type: "aiRequest"; prompt: string; files: FileTab[] };
|
|
203
|
-
```
|
|
169
|
+
[`@rotorsoft/act-nvim`](https://github.com/Rotorsoft/act-nvim) renders this diagram in the browser with bidirectional navigation, live refresh, and LSP diagnostic forwarding. The diagram is launched from inside Neovim; you click an element in the browser and the cursor jumps to the corresponding source line.
|
|
204
170
|
|
|
205
|
-
##
|
|
171
|
+
## How it works
|
|
206
172
|
|
|
207
|
-
The `
|
|
173
|
+
The extraction pipeline uses mock versions of `state()`, `slice()`, `projection()`, and `act()` that capture the builder structure without needing the real framework runtime. Code is transpiled with [Sucrase](https://github.com/alangpierce/sucrase) and evaluated in an isolated scope.
|
|
208
174
|
|
|
209
|
-
|
|
210
|
-
# In one terminal
|
|
211
|
-
ANTHROPIC_API_KEY=sk-ant-... pnpm -F @rotorsoft/act-diagram dev:server
|
|
175
|
+
Bottom-up: inventory scan → per-state validation → per-slice composition (with error isolation) → projection extraction → `act()` composition. Every item from the inventory is always displayed — with a diagram on success, or an error box on failure. Standalone states without a slice land in a synthetic "global" slice so nothing gets dropped.
|
|
212
176
|
|
|
213
|
-
|
|
214
|
-
<ActDiagram onAiRequest={(prompt, files) => fetch("http://localhost:4002/api/generate", { ... })} />
|
|
215
|
-
```
|
|
177
|
+
## Compatibility
|
|
216
178
|
|
|
217
|
-
|
|
179
|
+
- **Node**: >=22.18.0
|
|
180
|
+
- **Peer**: `react` ^18 || ^19, `react-dom` ^18 || ^19, `zod` ^4.4.3
|
|
181
|
+
- **Bundled deps**: `lucide-react`, `sucrase`
|
|
182
|
+
- **CLI**: works from any project where the package is installed; recognizes `$VISUAL` / `$EDITOR` (vim, nvim, nano, emacs, VS Code, Cursor)
|
|
183
|
+
- **Browser**: the component is a React SPA — runs in any browser that supports modern ES (the host's bundler picks the target)
|
|
184
|
+
- **400+ tests** covering extraction, layout, navigation, CLI, error paths
|
|
218
185
|
|
|
219
|
-
##
|
|
186
|
+
## Stability
|
|
220
187
|
|
|
221
|
-
|
|
188
|
+
Public API governed by the [Act Stability Charter](../../STABILITY.md). The diagram's **output shape** (SVG structure, click-through anchors) is *not* part of the stability surface and may evolve. Charter is **in effect as of 1.0.0**; the milestone tracker is [milestone 1.0](https://github.com/Rotorsoft/act-root/milestone/1).
|
|
222
189
|
|
|
223
|
-
##
|
|
190
|
+
## Related packages
|
|
224
191
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
pnpm -F @rotorsoft/act-diagram dev
|
|
192
|
+
- **[@rotorsoft/act](https://www.npmjs.com/package/@rotorsoft/act)** — the framework whose builders this parses (`state`, `slice`, `projection`, `act`).
|
|
193
|
+
- **[@rotorsoft/act-inspector](https://github.com/rotorsoft/act-root/tree/master/packages/inspector)** — runtime observatory (sibling to this build-time tool). Inspector shows live events + drain state; diagram shows the structural contract.
|
|
228
194
|
|
|
229
|
-
|
|
230
|
-
pnpm -F @rotorsoft/act-diagram test
|
|
195
|
+
## Documentation
|
|
231
196
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
197
|
+
- **[Contracts CLI guide](https://rotorsoft.github.io/act-root/docs/guides/contracts-cli)** — full reference for the `act` CLI's interactive and non-interactive modes.
|
|
198
|
+
- **[State management](https://rotorsoft.github.io/act-root/docs/concepts/state-management)** — how the builders this parses compose into an app.
|
|
199
|
+
- **[`act-nvim`](https://github.com/Rotorsoft/act-nvim)** — Neovim integration repo.
|
|
235
200
|
|
|
236
201
|
## License
|
|
237
202
|
|