@rotorsoft/act-diagram 0.1.0 → 0.1.1
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 +34 -80
- package/dist/.tsbuildinfo +1 -1
- package/dist/@types/index.d.ts +2 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/index.cjs +4 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,13 +7,16 @@
|
|
|
7
7
|
|
|
8
8
|
Interactive domain model diagram for [@rotorsoft/act](https://www.npmjs.com/package/@rotorsoft/act) event-sourced apps. Extracts states, actions, events, reactions, slices, and projections from TypeScript source code and renders them as an interactive SVG.
|
|
9
9
|
|
|
10
|
-
##
|
|
10
|
+
## Features
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
- **Real-time visualization** — SVG diagram updates as source files change
|
|
13
|
+
- **Code navigation** — click any diagram element to jump to its `file:line:col` location
|
|
14
|
+
- **Per-slice error isolation** — broken files show errors in their slice boundary while healthy slices render normally
|
|
15
|
+
- **Bottom-up model building** — states → slices → act, each level independently validated
|
|
16
|
+
- **IDE-agnostic** — works over props, postMessage, or WebSocket (see [act-nvim](https://github.com/Rotorsoft/act-nvim) for Neovim integration)
|
|
17
|
+
- **Embeddable** — React component for any host (IDE webview, standalone app, docs site)
|
|
18
|
+
- **AI refinement** — optional prompt bar to generate code via a streaming endpoint
|
|
19
|
+
- **100% test coverage** — 305 tests across all metrics
|
|
17
20
|
|
|
18
21
|
## Installation
|
|
19
22
|
|
|
@@ -35,23 +38,33 @@ pnpm add @rotorsoft/act-diagram
|
|
|
35
38
|
|
|
|
36
39
|
v
|
|
37
40
|
extractModel() ← transpile + execute with mock builders → DomainModel
|
|
38
|
-
|
|
|
41
|
+
| inventory scan → per-state validation → per-slice error isolation
|
|
39
42
|
v
|
|
40
43
|
validate() ← check for missing emits, orphan reactions, etc.
|
|
41
44
|
|
|
|
42
45
|
v
|
|
43
|
-
computeLayout() ← pure layout: positions nodes, edges, slice boxes
|
|
46
|
+
computeLayout() ← pure layout: positions nodes, edges, slice boxes, projections
|
|
44
47
|
|
|
|
45
48
|
v
|
|
46
|
-
<Diagram /> ← SVG rendering with pan/zoom/model tree
|
|
49
|
+
<Diagram /> ← SVG rendering with pan/zoom/model tree/errors section
|
|
47
50
|
|
|
|
48
51
|
v
|
|
49
52
|
navigateToCode() ← click element → { file, line, col }
|
|
50
53
|
```
|
|
51
54
|
|
|
52
|
-
|
|
55
|
+
### Extraction Pipeline
|
|
53
56
|
|
|
54
|
-
|
|
57
|
+
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.
|
|
58
|
+
|
|
59
|
+
**Bottom-up model building:**
|
|
60
|
+
|
|
61
|
+
1. **Inventory** — scan source files for all `state()`, `slice()`, `projection()`, `act()` declarations
|
|
62
|
+
2. **Build states** — validate each state independently (detects undefined schemas from broken imports)
|
|
63
|
+
3. **Build slices** — compose states from step 2, track missing/corrupted references per slice
|
|
64
|
+
4. **Build projections** — extract projection handlers
|
|
65
|
+
5. **Compose act** — wire slices + projections + reactions into entries, standalone states into a "global" slice
|
|
66
|
+
|
|
67
|
+
Every item from the inventory is always displayed — with a diagram on success, or an error box on failure.
|
|
55
68
|
|
|
56
69
|
## Usage
|
|
57
70
|
|
|
@@ -68,7 +81,6 @@ function App() {
|
|
|
68
81
|
{ path: "src/app.ts", content: "..." },
|
|
69
82
|
]}
|
|
70
83
|
onNavigate={(file, line, col) => {
|
|
71
|
-
// Open file in your editor at this position
|
|
72
84
|
console.log(`Navigate to ${file}:${line}:${col}`);
|
|
73
85
|
}}
|
|
74
86
|
/>
|
|
@@ -84,9 +96,7 @@ function App() {
|
|
|
84
96
|
|
|
85
97
|
// From the IDE extension host
|
|
86
98
|
webview.postMessage({ type: "files", files: [...] });
|
|
87
|
-
webview.postMessage({ type: "fileAdded", path: "src/new.ts", content: "..." });
|
|
88
99
|
webview.postMessage({ type: "fileChanged", path: "src/app.ts", content: "..." });
|
|
89
|
-
webview.postMessage({ type: "fileDeleted", path: "src/old.ts" });
|
|
90
100
|
```
|
|
91
101
|
|
|
92
102
|
### Raw Diagram (bring your own pipeline)
|
|
@@ -101,7 +111,6 @@ const warnings = validate(model);
|
|
|
101
111
|
model={model}
|
|
102
112
|
warnings={warnings}
|
|
103
113
|
onClickElement={(name, type, file) => { /* ... */ }}
|
|
104
|
-
toolbarExtra={<MyCustomButtons />}
|
|
105
114
|
/>
|
|
106
115
|
```
|
|
107
116
|
|
|
@@ -134,11 +143,8 @@ const result = navigateToCode(files, "OpenTicket", "action");
|
|
|
134
143
|
| `validate` | `(model: DomainModel) => ValidationWarning[]` | Validate model for missing emits, etc. |
|
|
135
144
|
| `navigateToCode` | `(files, name, type?, targetFile?) => { file, line, col } \| undefined` | Find source location of a named element |
|
|
136
145
|
| `topoSort` | `(files: FileTab[]) => FileTab[]` | Sort files by import dependency order |
|
|
137
|
-
| `parseMultiFileResponse` | `(raw: string) => FileTab[]` | Parse AI response with path-annotated fenced blocks |
|
|
138
|
-
| `stripFences` | `(code: string) => string` | Remove markdown fences from code |
|
|
139
|
-
| `deriveProjectName` | `(prompt, code?) => string` | Derive a project name from prompt or code |
|
|
140
|
-
| `emptyModel` | `() => DomainModel` | Create an empty domain model |
|
|
141
146
|
| `computeLayout` | `(model: DomainModel) => Layout` | Pure layout computation — positions all nodes, edges, and slice boxes |
|
|
147
|
+
| `emptyModel` | `() => DomainModel` | Create an empty domain model |
|
|
142
148
|
|
|
143
149
|
### Types
|
|
144
150
|
|
|
@@ -157,64 +163,34 @@ type DomainModel = {
|
|
|
157
163
|
type StateNode = { name, varName, events: EventNode[], actions: ActionNode[], file?, line? };
|
|
158
164
|
type ActionNode = { name, emits: string[], invariants: string[], line? };
|
|
159
165
|
type EventNode = { name, hasCustomPatch: boolean, line? };
|
|
160
|
-
type SliceNode = { name, states: string[], stateVars: string[], projections: string[], reactions: ReactionNode[], line? };
|
|
166
|
+
type SliceNode = { name, states: string[], stateVars: string[], projections: string[], reactions: ReactionNode[], error?, file?, line? };
|
|
161
167
|
type ProjectionNode = { name, varName, handles: string[], line? };
|
|
162
168
|
type ReactionNode = { event, handlerName, dispatches: string[], isVoid: boolean, line? };
|
|
163
|
-
type ValidationWarning = { message, severity: "warning" | "error", element? };
|
|
164
169
|
|
|
165
|
-
// Layout types
|
|
166
|
-
type
|
|
167
|
-
type N = { key, pos: Pos, type, label, sub?, file?, projections?, guards?, reactions? };
|
|
168
|
-
type E = { from: Pos, to: Pos, color: string, dash?: string };
|
|
169
|
-
type Box = { x, y, w, h, label, color, border };
|
|
170
|
+
// Layout types
|
|
171
|
+
type Box = { x, y, w, h, label, error? };
|
|
170
172
|
type Layout = { ns: N[], es: E[], boxes: Box[], minX, minY, width, height };
|
|
171
173
|
```
|
|
172
174
|
|
|
173
175
|
### IDE Plugin Protocol
|
|
174
176
|
|
|
175
177
|
```typescript
|
|
176
|
-
// Host → Diagram
|
|
178
|
+
// Host → Diagram
|
|
177
179
|
type HostMessage =
|
|
178
180
|
| { type: "files"; files: FileTab[] }
|
|
179
181
|
| { type: "fileAdded"; path: string; content: string }
|
|
180
182
|
| { type: "fileChanged"; path: string; content: string }
|
|
181
183
|
| { type: "fileDeleted"; path: string };
|
|
182
184
|
|
|
183
|
-
// Diagram → Host
|
|
185
|
+
// Diagram → Host
|
|
184
186
|
type DiagramMessage =
|
|
185
187
|
| { type: "navigate"; file: string; line: number; col: number }
|
|
186
188
|
| { type: "aiRequest"; prompt: string; files: FileTab[] };
|
|
187
189
|
```
|
|
188
190
|
|
|
189
|
-
##
|
|
190
|
-
|
|
191
|
-
A minimal streaming endpoint for AI code generation:
|
|
192
|
-
|
|
193
|
-
```sh
|
|
194
|
-
# Start the AI server
|
|
195
|
-
ANTHROPIC_API_KEY=sk-... pnpm -F @rotorsoft/act-diagram dev:server
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
Single endpoint: `POST /api/generate` with SSE response.
|
|
199
|
-
|
|
200
|
-
```typescript
|
|
201
|
-
// Request
|
|
202
|
-
{ prompt: string; currentFiles?: FileTab[]; model?: string; maxTokens?: number; refine?: boolean }
|
|
203
|
-
|
|
204
|
-
// SSE events
|
|
205
|
-
{ type: "text", text: "..." }
|
|
206
|
-
{ type: "done", truncated: boolean, usage: {...} }
|
|
207
|
-
{ type: "error", message: "..." }
|
|
208
|
-
```
|
|
209
|
-
|
|
210
|
-
## Architecture
|
|
191
|
+
## Neovim Integration
|
|
211
192
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
- **Extraction** (`extractModel`) — transpile + eval with mock builders to produce a `DomainModel`
|
|
215
|
-
- **Validation** (`validate`) — check for missing emits, orphan reactions, dangling references
|
|
216
|
-
- **Layout** (`computeLayout`) — pure function that maps a `DomainModel` to absolute positions for nodes, edges, and slice boxes. No React or DOM dependencies, fully unit-testable
|
|
217
|
-
- **Rendering** (`<Diagram />`) — SVG component that renders the `Layout` with pan, zoom, and click-to-navigate
|
|
193
|
+
See [@rotorsoft/act-nvim](https://github.com/Rotorsoft/act-nvim) — a Neovim plugin that renders act-diagram in the browser with bidirectional navigation, live refresh, and LSP diagnostic forwarding.
|
|
218
194
|
|
|
219
195
|
## Development
|
|
220
196
|
|
|
@@ -222,35 +198,13 @@ The diagram pipeline is split into testable layers:
|
|
|
222
198
|
# Visual dev server with sample diagram
|
|
223
199
|
pnpm -F @rotorsoft/act-diagram dev
|
|
224
200
|
|
|
225
|
-
# Run tests
|
|
201
|
+
# Run tests (305 tests, 100% coverage)
|
|
226
202
|
pnpm -F @rotorsoft/act-diagram test
|
|
227
203
|
|
|
228
204
|
# Build library
|
|
229
205
|
pnpm -F @rotorsoft/act-diagram build
|
|
230
206
|
```
|
|
231
207
|
|
|
232
|
-
**Dev mode features:**
|
|
233
|
-
|
|
234
|
-
- **Folder picker** — open a local Act project via the browser File System Access API; diagram updates live, polling for file changes every 2 seconds
|
|
235
|
-
- **Code preview** — click any diagram element to see its source with the target line highlighted in the element's color (blue for actions, orange for events, etc.)
|
|
236
|
-
- **AI integration** — resizable prompt bar with model selector (Sonnet/Opus/Haiku) and token limit (4k–32k); streams AI output in real-time with save/discard workflow for generated files
|
|
237
|
-
- **Fix with AI** — clickable warnings panel with per-warning and bulk "fix all" buttons that send issues to the AI for resolution
|
|
238
|
-
- **Navigation** — events navigate to `.emits()` declaration; guards to `.given()` usage; reactions to `.do()` handler registration
|
|
239
|
-
|
|
240
|
-
```sh
|
|
241
|
-
# Start the AI server (requires ANTHROPIC_API_KEY in libs/act-diagram/.env)
|
|
242
|
-
pnpm -F @rotorsoft/act-diagram dev:server
|
|
243
|
-
```
|
|
244
|
-
|
|
245
|
-
## Related
|
|
246
|
-
|
|
247
|
-
- [@rotorsoft/act](https://www.npmjs.com/package/@rotorsoft/act) - Core framework
|
|
248
|
-
- [@rotorsoft/act-pg](https://www.npmjs.com/package/@rotorsoft/act-pg) - PostgreSQL adapter
|
|
249
|
-
- [@rotorsoft/act-sse](https://www.npmjs.com/package/@rotorsoft/act-sse) - SSE state broadcast
|
|
250
|
-
- [@rotorsoft/act-patch](https://www.npmjs.com/package/@rotorsoft/act-patch) - Deep merge patches
|
|
251
|
-
- [Documentation](https://rotorsoft.github.io/act-root/)
|
|
252
|
-
|
|
253
208
|
## License
|
|
254
209
|
|
|
255
|
-
|
|
256
|
-
|
|
210
|
+
MIT
|