flowfig 0.2.0 → 0.4.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 +80 -6
- package/dist/browser.d.ts +33 -0
- package/dist/browser.js +201 -0
- package/dist/check.js +82 -4
- package/dist/cli.js +180 -5
- package/dist/diff.js +2 -2
- package/dist/draw.d.ts +12 -0
- package/dist/draw.js +195 -0
- package/dist/geometry.d.ts +4 -1
- package/dist/geometry.js +39 -12
- package/dist/gif.d.ts +12 -0
- package/dist/gif.js +245 -0
- package/dist/guide.d.ts +3 -3
- package/dist/guide.js +35 -13
- package/dist/index.d.ts +1 -1
- package/dist/index.js +280 -35
- package/dist/init.d.ts +5 -0
- package/dist/init.js +58 -22
- package/dist/model.d.ts +107 -3
- package/dist/model.js +185 -7
- package/dist/open.d.ts +15 -0
- package/dist/open.js +82 -0
- package/dist/page.d.ts +2 -0
- package/dist/page.js +16 -0
- package/dist/picker.d.ts +33 -0
- package/dist/picker.js +148 -0
- package/dist/png.d.ts +7 -0
- package/dist/png.js +70 -0
- package/dist/rail.d.ts +2 -1
- package/dist/rail.js +15 -1
- package/dist/scene.d.ts +2 -0
- package/dist/source.d.ts +2 -0
- package/dist/source.js +5 -0
- package/dist/svg.js +313 -40
- package/dist/verify.d.ts +1 -1
- package/dist/verify.js +10 -3
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/dist/gif.js
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/** The delay of each of `count` frames in cs. The sum is round(count * 100 / fps). */
|
|
2
|
+
export function delays(count, fps) {
|
|
3
|
+
// Each delay is a whole cs: the rounding error moves between frames and does not add up.
|
|
4
|
+
return Array.from({ length: count }, (_, i) => Math.round(((i + 1) * 100) / fps) - Math.round((i * 100) / fps));
|
|
5
|
+
}
|
|
6
|
+
// A color bin: 5 bits per channel, 32768 bins.
|
|
7
|
+
const binOf = (rgb) => ((rgb >> 9) & 0x7c00) | ((rgb >> 6) & 0x3e0) | ((rgb >> 3) & 0x1f);
|
|
8
|
+
const channel = (bin, c) => (bin >> (10 - 5 * c)) & 31;
|
|
9
|
+
/** Median cut: split the box with the widest channel range at its weighted median, until 256 boxes or one bin per box. */
|
|
10
|
+
function medianCut(bins, counts) {
|
|
11
|
+
const boxes = [bins];
|
|
12
|
+
while (boxes.length < 256) {
|
|
13
|
+
let pick = -1, widest = 0, axis = 0;
|
|
14
|
+
boxes.forEach((box, i) => {
|
|
15
|
+
for (let c = 0; c < 3; c++) {
|
|
16
|
+
let lo = 31, hi = 0;
|
|
17
|
+
for (const b of box) {
|
|
18
|
+
const v = channel(b, c);
|
|
19
|
+
if (v < lo)
|
|
20
|
+
lo = v;
|
|
21
|
+
if (v > hi)
|
|
22
|
+
hi = v;
|
|
23
|
+
}
|
|
24
|
+
if (hi - lo > widest)
|
|
25
|
+
[widest, pick, axis] = [hi - lo, i, c];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
if (pick === -1)
|
|
29
|
+
break;
|
|
30
|
+
const box = boxes[pick].sort((a, b) => channel(a, axis) - channel(b, axis));
|
|
31
|
+
const half = box.reduce((s, b) => s + counts[b], 0) / 2;
|
|
32
|
+
let at = 1, seen = counts[box[0]];
|
|
33
|
+
while (at < box.length - 1 && seen + counts[box[at]] <= half)
|
|
34
|
+
seen += counts[box[at++]];
|
|
35
|
+
boxes.splice(pick, 1, box.slice(0, at), box.slice(at));
|
|
36
|
+
}
|
|
37
|
+
return boxes;
|
|
38
|
+
}
|
|
39
|
+
/** The palette: the exact colors if there are 256 or fewer, else median cut over the bins. No dither. */
|
|
40
|
+
function palette(exact, counts, sums) {
|
|
41
|
+
const colors = new Uint8Array(768);
|
|
42
|
+
if (exact) {
|
|
43
|
+
for (const [rgb, k] of exact)
|
|
44
|
+
colors.set([rgb >> 16, (rgb >> 8) & 255, rgb & 255], k * 3);
|
|
45
|
+
return { colors, index: (rgb) => exact.get(rgb) };
|
|
46
|
+
}
|
|
47
|
+
const bins = [];
|
|
48
|
+
for (let b = 0; b < 32768; b++)
|
|
49
|
+
if (counts[b])
|
|
50
|
+
bins.push(b);
|
|
51
|
+
const boxes = medianCut(bins, counts);
|
|
52
|
+
boxes.forEach((box, k) => {
|
|
53
|
+
let n = 0, r = 0, g = 0, b = 0;
|
|
54
|
+
for (const x of box) {
|
|
55
|
+
n += counts[x];
|
|
56
|
+
r += sums[x * 3];
|
|
57
|
+
g += sums[x * 3 + 1];
|
|
58
|
+
b += sums[x * 3 + 2];
|
|
59
|
+
}
|
|
60
|
+
colors.set([Math.round(r / n), Math.round(g / n), Math.round(b / n)], k * 3);
|
|
61
|
+
});
|
|
62
|
+
// Each bin maps to the palette color nearest to the mean color of the bin.
|
|
63
|
+
const table = new Uint8Array(32768);
|
|
64
|
+
for (const x of bins) {
|
|
65
|
+
const r = sums[x * 3] / counts[x], g = sums[x * 3 + 1] / counts[x], b = sums[x * 3 + 2] / counts[x];
|
|
66
|
+
let best = 0, dist = Infinity;
|
|
67
|
+
for (let k = 0; k < boxes.length; k++) {
|
|
68
|
+
const d = (colors[k * 3] - r) ** 2 + (colors[k * 3 + 1] - g) ** 2 + (colors[k * 3 + 2] - b) ** 2;
|
|
69
|
+
if (d < dist)
|
|
70
|
+
[dist, best] = [d, k];
|
|
71
|
+
}
|
|
72
|
+
table[x] = best;
|
|
73
|
+
}
|
|
74
|
+
return { colors, index: (rgb) => table[binOf(rgb)] };
|
|
75
|
+
}
|
|
76
|
+
/** GIF LZW: minimum code size 8, a clear code first, codes up to 12 bits, data in sub-blocks of 255 bytes or fewer. */
|
|
77
|
+
function lzw(px, width, rect, byte) {
|
|
78
|
+
const [x0, y0, x1, y1] = rect;
|
|
79
|
+
const CLEAR = 256, END = 257;
|
|
80
|
+
const block = new Uint8Array(255);
|
|
81
|
+
const dict = new Map();
|
|
82
|
+
let blen = 0, acc = 0, bits = 0, size = 9, next = 258, prefix = -1;
|
|
83
|
+
const flush = () => {
|
|
84
|
+
byte(blen);
|
|
85
|
+
for (let i = 0; i < blen; i++)
|
|
86
|
+
byte(block[i]);
|
|
87
|
+
blen = 0;
|
|
88
|
+
};
|
|
89
|
+
const emit = (code) => {
|
|
90
|
+
acc |= code << bits;
|
|
91
|
+
for (bits += size; bits >= 8; bits -= 8, acc >>>= 8) {
|
|
92
|
+
block[blen++] = acc & 255;
|
|
93
|
+
if (blen === 255)
|
|
94
|
+
flush();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
byte(8);
|
|
98
|
+
emit(CLEAR);
|
|
99
|
+
for (let y = y0; y <= y1; y++)
|
|
100
|
+
for (let x = x0; x <= x1; x++) {
|
|
101
|
+
const k = px[y * width + x];
|
|
102
|
+
if (prefix < 0) {
|
|
103
|
+
prefix = k;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const code = dict.get((prefix << 8) | k);
|
|
107
|
+
if (code !== undefined) {
|
|
108
|
+
prefix = code;
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
emit(prefix);
|
|
112
|
+
if (next === 4096) {
|
|
113
|
+
emit(CLEAR);
|
|
114
|
+
dict.clear();
|
|
115
|
+
[next, size] = [258, 9];
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
// The decoder runs one code behind: grow the size when the new code no longer fits.
|
|
119
|
+
if (next >= 1 << size)
|
|
120
|
+
size++;
|
|
121
|
+
dict.set((prefix << 8) | k, next++);
|
|
122
|
+
}
|
|
123
|
+
prefix = k;
|
|
124
|
+
}
|
|
125
|
+
emit(prefix);
|
|
126
|
+
emit(END);
|
|
127
|
+
if (bits > 0) {
|
|
128
|
+
block[blen++] = acc & 255;
|
|
129
|
+
if (blen === 255)
|
|
130
|
+
flush();
|
|
131
|
+
}
|
|
132
|
+
if (blen)
|
|
133
|
+
flush();
|
|
134
|
+
byte(0);
|
|
135
|
+
}
|
|
136
|
+
/** An animated GIF that loops forever. All frames have the size of the first frame. */
|
|
137
|
+
// It yields to the event loop between frames, so a signal handler can run while the encode goes on.
|
|
138
|
+
export async function encodeGif(frames) {
|
|
139
|
+
if (!frames.length)
|
|
140
|
+
throw new Error('a GIF needs at least one frame');
|
|
141
|
+
// Pass 1: count the colors of all frames.
|
|
142
|
+
const counts = new Uint32Array(32768), sums = new Float64Array(32768 * 3);
|
|
143
|
+
let exact = new Map(), width = 0, height = 0;
|
|
144
|
+
for (let f = 0; f < frames.length; f++) {
|
|
145
|
+
if (frames[f].same && f > 0)
|
|
146
|
+
continue;
|
|
147
|
+
// A run of equal frames counts once, with the weight of the run.
|
|
148
|
+
let weight = 1;
|
|
149
|
+
while (f + weight < frames.length && frames[f + weight].same)
|
|
150
|
+
weight++;
|
|
151
|
+
await new Promise(setImmediate);
|
|
152
|
+
const { width: w, height: h, data } = frames[f].load();
|
|
153
|
+
if (f === 0)
|
|
154
|
+
[width, height] = [w, h];
|
|
155
|
+
else if (w !== width || h !== height)
|
|
156
|
+
throw new Error(`frame ${f + 1} is ${w} x ${h}; the first frame is ${width} x ${height}`);
|
|
157
|
+
let last = -1, bin = 0;
|
|
158
|
+
for (let i = 0; i < data.length; i += 4) {
|
|
159
|
+
const rgb = (data[i] << 16) | (data[i + 1] << 8) | data[i + 2];
|
|
160
|
+
if (rgb !== last) {
|
|
161
|
+
last = rgb;
|
|
162
|
+
bin = binOf(rgb);
|
|
163
|
+
if (exact && !exact.has(rgb))
|
|
164
|
+
exact = exact.size < 256 ? exact.set(rgb, exact.size) : null;
|
|
165
|
+
}
|
|
166
|
+
counts[bin] += weight;
|
|
167
|
+
sums[bin * 3] += data[i] * weight;
|
|
168
|
+
sums[bin * 3 + 1] += data[i + 1] * weight;
|
|
169
|
+
sums[bin * 3 + 2] += data[i + 2] * weight;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const { colors, index } = palette(exact, counts, sums);
|
|
173
|
+
let buf = new Uint8Array(1 << 20), len = 0;
|
|
174
|
+
const byte = (v) => {
|
|
175
|
+
if (len === buf.length) {
|
|
176
|
+
const grown = new Uint8Array(buf.length * 2);
|
|
177
|
+
grown.set(buf);
|
|
178
|
+
buf = grown;
|
|
179
|
+
}
|
|
180
|
+
buf[len++] = v;
|
|
181
|
+
};
|
|
182
|
+
const word = (v) => {
|
|
183
|
+
byte(v & 255);
|
|
184
|
+
byte(v >> 8);
|
|
185
|
+
};
|
|
186
|
+
const bytes = (...vs) => vs.forEach(byte);
|
|
187
|
+
const text = (s) => {
|
|
188
|
+
for (const c of s)
|
|
189
|
+
byte(c.charCodeAt(0));
|
|
190
|
+
};
|
|
191
|
+
text('GIF89a');
|
|
192
|
+
word(width);
|
|
193
|
+
word(height);
|
|
194
|
+
bytes(0xf7, 0, 0); // a global color table of 256 colors; background color 0; no aspect ratio
|
|
195
|
+
colors.forEach(byte);
|
|
196
|
+
bytes(0x21, 0xff, 11);
|
|
197
|
+
text('NETSCAPE2.0');
|
|
198
|
+
bytes(3, 1, 0, 0, 0); // loop count 0: loop forever
|
|
199
|
+
// Pass 2: each frame as palette indices. A later frame sends only the rectangle that changed.
|
|
200
|
+
let prev = null;
|
|
201
|
+
for (const frame of frames) {
|
|
202
|
+
await new Promise(setImmediate);
|
|
203
|
+
let cur = prev;
|
|
204
|
+
if (!(frame.same && prev)) {
|
|
205
|
+
const { data } = frame.load();
|
|
206
|
+
cur = new Uint8Array(width * height);
|
|
207
|
+
let last = -1, k = 0;
|
|
208
|
+
for (let p = 0, i = 0; p < cur.length; p++, i += 4) {
|
|
209
|
+
const rgb = (data[i] << 16) | (data[i + 1] << 8) | data[i + 2];
|
|
210
|
+
if (rgb !== last)
|
|
211
|
+
[last, k] = [rgb, index(rgb)];
|
|
212
|
+
cur[p] = k;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
let rect = [0, 0, width - 1, height - 1];
|
|
216
|
+
if (cur === prev)
|
|
217
|
+
rect = [0, 0, -1, -1];
|
|
218
|
+
else if (prev) {
|
|
219
|
+
rect = [width, height, -1, -1];
|
|
220
|
+
for (let y = 0, p = 0; y < height; y++)
|
|
221
|
+
for (let x = 0; x < width; x++, p++)
|
|
222
|
+
if (cur[p] !== prev[p]) {
|
|
223
|
+
if (x < rect[0])
|
|
224
|
+
rect[0] = x;
|
|
225
|
+
if (x > rect[2])
|
|
226
|
+
rect[2] = x;
|
|
227
|
+
if (y < rect[1])
|
|
228
|
+
rect[1] = y;
|
|
229
|
+
rect[3] = y;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// No change: a 1 x 1 frame that paints the old color keeps the frame and its delay.
|
|
233
|
+
if (rect[2] < 0)
|
|
234
|
+
rect = [0, 0, 0, 0];
|
|
235
|
+
bytes(0x21, 0xf9, 4, 1 << 2); // disposal method 1: the next frame draws over this frame
|
|
236
|
+
word(frame.delay);
|
|
237
|
+
bytes(0, 0, 0x2c);
|
|
238
|
+
[rect[0], rect[1], rect[2] - rect[0] + 1, rect[3] - rect[1] + 1].forEach(word);
|
|
239
|
+
byte(0);
|
|
240
|
+
lzw(cur, width, rect, byte);
|
|
241
|
+
prev = cur;
|
|
242
|
+
}
|
|
243
|
+
byte(0x3b);
|
|
244
|
+
return buf.slice(0, len);
|
|
245
|
+
}
|
package/dist/guide.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** The full guide, as Markdown. `flowfig docs` prints it. */
|
|
2
|
-
export declare const GUIDE = "# flowfig guide\n\nflowfig draws animated flow figures. A figure has boxes, the edges between the boxes, and steps. In each step, a packet moves along\nthe edges. The output is one animated SVG with no script. The SVG plays in a GitHub README, in PR and issue comments, and in blog\nposts. A figure is about 5 to 50 kB.\n\nYou write a JSON spec. You never write SVG by hand. The command `npx flowfig` checks the spec and renders it.\n\n## What flowfig draws\n\nA spec has three forms.\n\n- The map (the default). The map shows the boxes and the edges. A packet moves along an edge in each beat.\n- The map with a rail (`\"rail\": true`). The rail is a lifeline diagram under the map. It has one row for each message.\n- The rail alone (`\"rail\": \"only\"`). Use it when the reader needs only the order of the messages, for example when the map is already in the same document.\n\nUse the rail for a sequence of messages: a request lifecycle, an API call chain, or a Mermaid `sequenceDiagram`. Put each message on\nan edge. Put each phase in a step. Put messages that run at the same time in one beat. Mark a message that does not wait for an\nanswer with `\"async\": true`.\n\n## Scope: what flowfig draws and what it does not\n\nflowfig draws how something works: parts, the messages between them, and the order of the messages.\n\n| The user asks for | Draw |\n| ------------------------------------------ | ------------------------------------------------------------------------------------------ |\n| An architecture, a data flow, a pipeline | The map. Group parts by service, network or trust boundary. `store` for data at rest. |\n| A request lifecycle, a call chain | The map with `\"rail\": true`. One message per hop, with its real payload in `data`. |\n| A sequence diagram only | `\"rail\": \"only\"`. |\n| A state lifecycle, a state machine | One box per state, one edge per transition, labeled with its event. One step per path. Mark each end state, for example with `sub: \"end state\"`. |\n| A flowchart with branches | `shape: \"decision\"` for each branch. One step per path. |\n\nflowfig does not draw class or ER diagrams (fields, types, cardinality), Gantt charts, timelines with dates, charts of numbers,\nor mind maps. If the user asks for one of these, say that flowfig does not draw it, suggest Mermaid (`classDiagram`,\n`erDiagram`, `gantt`), and draw nothing with flowfig.\n\n## Workflow\n\n### 1. Pick the scope\n\nIf the code has more than one flow, name each flow in the reply. Then draw one flow, or draw one structure view and call it a\nstructure view. If the user asks for the whole system, draw one top view with groups, or a set of figures that together cover\nevery part. Keep each figure to 12 boxes or fewer.\n\n### 2. Write the fact list\n\nBefore the spec, write a list of the facts that the figure must show. Take each fact from the code and from its wiring: config\nfiles, compose files, route tables and queue bindings (or from the pasted Mermaid). Give each fact its `file:line`:\n\n- every part (service, function, store, queue, external system);\n- every call, in order, written as `caller \u2192 callee: payload (file:line of the call)`. The edge in the spec goes from that caller\n to that callee;\n- every call that does not wait for an answer (fire and forget, a queue, a webhook, a callback), and every consumer of each queue\n or topic;\n- every branch and every error path (a rejected input, a retry, a dead-letter path);\n- every end state.\n\nIf the code does not show a fact, leave the fact out. Do not guess a part, a name or an order.\n\n### 3. Write the spec\n\nEach fact becomes a box, an edge, a beat, a `data` card or a `show` row. Use the real names from the code as labels, and\nreal example data from the code or its tests. Keep each fact that you leave out, with the reason, for the reply.\nGive each box and edge that draws code a `source`, from the fact list: `\"src/auth/login.ts#verifyPassword\"`. A store or an outside part may have none.\n\nMermaid mapping:\n\n| Mermaid | flowfig |\n| ---------------------------------------- | ------------------------------------------------------------------ |\n| `participant` | a box |\n| `A->>B: text` | an edge from A to B, and a hop with `data: \"text\"` |\n| `B-->>A: text` (a reply) | a hop on the same edge with `back: true` |\n| `A-)B: text` (async) | a hop with `async: true` |\n| `par ... and ... end` | the hops of all branches in one beat |\n| `alt` / `opt` | one step per path |\n| `stateDiagram` states and transitions | boxes, and edges labeled with the event |\n\n### 4. Render, then fix\n\n```bash\nnpx flowfig - out.svg <<'SPEC'\n{ \"props\": { \"layout\": ..., \"edges\": [...], \"steps\": [...] } }\nSPEC\n```\n\nThe quoted `<<'SPEC'` heredoc passes the JSON with no change. The command checks the spec first. If the check finds an error, the\ncommand writes no SVG and lists the faults. Fix each fault and render again.\n\n- Fix a layout fault by changing the layout first: put parts in rows or columns, route an edge `around`, or change a gap.\n Never remove a fact from the fact list to pass the check. If you must remove one, name it in the reply.\n- If `small-text` appears, the figure is too wide. Put the parts in two rows, move a detail from `label` to `sub`, or split\n the figure. Use more steps in one figure before you make a second figure. Keep the real name from the code in the label:\n `ReportsController` stays `ReportsController`, not `Controller`. Do not change `--width` to pass the check: the\n reader sees the figure at the real page width.\n- Fix every other warning, or tell the user why it stays.\n- Do not use `--no-check` to hide a fault.\n\n### 5. Read the figure back\n\nRun `npx flowfig --spec out.svg`. Compare the spec with the fact list. Check that each edge goes from the caller to the callee\nthat its fact names. Add each fact that is missing, fix each wrong edge, and render again.\n\nRun `npx flowfig verify out.svg` from the repo root. Fix each `missing-file` or `missing-symbol`.\n\n### 6. Look at the SVG\n\nThe check estimates the text width, so it cannot see everything. If you can open a browser, open the SVG and take a\nscreenshot. Wait a few seconds and take a second screenshot to see a later beat. If you cannot open a browser, write \"not\nlooked at\" in the reply. Never report a look that you did not do. A browser tool can block `file://` URLs. If it does, serve the folder\nwith `python3 -m http.server`.\n\n### 7. Write the reply\n\nThe reply has these parts, in this order:\n\n1. the path of each SVG;\n2. what each figure shows: the parts and the steps. Copy the counts from the `figure:` line of the check output. Copy every name\n from the read-back spec. Never count from memory;\n3. the scope: the flow you drew, why, and the other flows that exist;\n4. what the figure leaves out, and why;\n5. the two check lines that the render printed, `0 errors, 0 warnings` and `figure: ...`, copied as printed, and whether\n you looked at the SVG.\n\nTo change an SVG later, print its spec with `--spec`, change the spec, and render again.\n\n## Spec reference\n\n`props` has these fields.\n\n| Field | Type | Meaning |\n| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------- |\n| `layout` | group | The boxes and how they line up. Required. |\n| `edges` | edge[] | The arrows between the boxes. Required. |\n| `steps` | step[] | The stories the figure tells. With no steps, the figure is a still map. |\n| `rail` | `true` or `\"only\"` | Draw the steps as a lifeline rail under the map. `\"only\"` draws the rail without the map. |\n| `speed` | number | Milliseconds a packet takes to cross one edge. Default: 900. |\n| `theme` | object | Colors: `accent`, `fg`, `muted`, `bg`, `surface`, `border`, `font`. Each color you omit keeps its built-in value. |\n\n### layout\n\nThe layout is a tree. A group has `children` and these optional fields.\n\n- `id`: a name that an edge can use to reach the group as a whole.\n- `label`: the title on the frame. Only a group with a `label` gets a frame.\n- `direction`: `\"row\"` (the default) or `\"column\"`.\n- `gap`: the space between children in px. Default: 28 for a column. For a row, the gap fits the widest edge label between two children (at least 56).\n- `align`: `\"start\"`, `\"center\"` or `\"end\"`. This sets where the children line up across the direction.\n\nEvery other item is a box.\n\n| Box field | Meaning |\n| --------- | --------------------------------------------------------------------------------------------------------- |\n| `id` | Required. The name that edges and steps use. It must be unique in the figure. |\n| `label` | Required. The title in the box. |\n| `sub` | A smaller line under the label. |\n| `shape` | `\"box\"` (default), `\"decision\"` (a diamond) or `\"store\"` (a database cylinder for data at rest). |\n| `width` | Width in px. This overrides the width that the layout picks. |\n| `source` | The code this draws: `path` or `path#symbol`, relative to the repo root. `flowfig verify` checks it. |\n| `lines` | The least number of text lines that a content card keeps. The card still grows to fit its content. |\n\n### edges\n\nAn edge has these fields.\n\n- `id`: the name that steps use. Default: `from->to`.\n- `from` and `to`: the `id` of a box or a group.\n- `label`: text on the edge, drawn as a small pill.\n- `around`: `\"above\"` or `\"below\"`. This routes the edge over or under the boxes in between (loops, skip-ahead edges).\n- `quiet`: if `true`, the SVG draws the edge only while a step uses it.\n- `source`: the code this edge draws, as `path` or `path#symbol`. `flowfig verify` checks it.\n\n### steps\n\nA step has `label` and `flow`. It can also have `caption` (the line under the figure while no beat has a `say`) and `nodes` (ids of\nboxes to highlight for the whole step).\n\n`flow` is a list of beats. A beat is one of these:\n\n- an edge id (a string);\n- an array of edge ids, which run at the same time;\n- an object `{ edges?, say?, show?, light?, ms? }`. A beat with no `edges` is a pause.\n\nThe beat fields:\n\n- `edges`: an edge id, a hop object, or an array of these. A hop object is `{ edge, back?, data?, async?, source? }`.\n - `back: true` runs the packet from the `to` box to the `from` box.\n - `data` is a small card that moves with the packet.\n - `async: true` marks a message that does not wait for an answer. The rail draws it dashed, with an `async` tag.\n- `say`: the caption for the beat.\n- `show`: `{ boxId: [row, ...] }`. This fills the content card of each named box. The card keeps the rows until the step ends.\n- `light`: ids of boxes to highlight for this beat.\n- `ms`: how long the beat lasts. Default: the time one packet needs to cross an edge.\n\nA row of a content card is `{ tag?, tone?, text, meta?, mark?, mono? }`.\n\n- `tag`: a short colored label at the start of the line.\n- `tone`: the color of the tag: `blue` (default), `purple`, `green`, `orange` or `gray`.\n- `text`: the main text.\n- `meta`: muted text after the main text.\n- `mark`: a mark at the right end of the line, such as a check or \"new\".\n- `mono`: if `true`, the text uses a monospace font.\n\n## Content rules\n\n- Give every box a stable `id`.\n- Use `shape: \"store\"` for data at rest (a database, a cache, a file, a queue). Use a plain box for a part that does work. Use `shape: \"decision\"` for a branch.\n- Keep one clear main path, left to right. Put side parts in a `column` group.\n- Use `quiet: true` on a long edge that crosses the picture. A quiet edge needs a beat that uses it, or the check reports\n `hidden-edge`.\n- In a rail, draw an error reply as a hop back on the same edge, with the error in `data` (`{ \"edge\": \"login\", \"back\": true,\n \"data\": \"401 CREDENTIALS_INVALID\" }`). A call that stays inside one part (a hash check, a guard) is not a message: put it in\n `say` or in a `show` row of that part.\n- Keep an SVG to one or two steps. The SVG plays every step in a loop, with no controls.\n- Use the React player, `<Flow {...props} />` from `flowfig`, for a page that needs tabs, pause or hover.\n\n## Example\n\n```json\n{\n \"props\": {\n \"layout\": {\n \"children\": [\n { \"id\": \"client\", \"label\": \"Browser\" },\n { \"id\": \"api\", \"label\": \"API Server\" },\n { \"id\": \"db\", \"label\": \"Database\", \"shape\": \"store\" }\n ]\n },\n \"edges\": [\n { \"id\": \"req\", \"from\": \"client\", \"to\": \"api\", \"label\": \"GET /users/42\" },\n { \"id\": \"q\", \"from\": \"api\", \"to\": \"db\", \"label\": \"SELECT\" }\n ],\n \"steps\": [\n {\n \"label\": \"read\",\n \"flow\": [\n { \"edges\": { \"edge\": \"req\", \"data\": \"GET /users/42\" }, \"say\": \"The browser asks for user 42.\" },\n { \"edges\": \"q\", \"show\": { \"db\": [{ \"tag\": \"row\", \"tone\": \"gray\", \"text\": \"Ada Lovelace\" }] }, \"say\": \"The API server reads the row.\" },\n { \"edges\": { \"edge\": \"req\", \"back\": true, \"data\": \"200 OK\" }, \"say\": \"The API server sends the user.\" }\n ]\n }\n ]\n }\n}\n```\n\n## Commands\n\n```bash\nnpx flowfig - out.svg < spec.json # render a spec from stdin\nnpx flowfig spec.json out.svg # render a spec file\nnpx flowfig figure.ts out.svg # render a module whose default export is a spec\nnpx flowfig check <input> [--json] # list the faults. The input can also be an SVG that flowfig wrote.\nnpx flowfig verify <input>... # check that the code each source names still exists\nnpx flowfig diff <old> <new> # list what changed in the spec between two figures\nnpx flowfig --spec out.svg # print the spec that an SVG carries\nnpx flowfig docs # print this guide\nnpx flowfig init # write these instructions for the coding agents of a repo\n```\n\nA render checks first and writes nothing on an error. `--strict` makes warnings errors. `--width` sets the page width.\n`--min-text` sets the smallest text that the reader should get. `--no-check` skips the check.\n";
|
|
2
|
+
export declare const GUIDE = "# flowfig guide\n\nflowfig draws animated flow figures. A figure has boxes, the edges between the boxes, and steps. In each step, a packet moves along\nthe edges. The output is one animated SVG with no script. The SVG plays in a GitHub README, in PR and issue comments, and in blog\nposts. A figure is about 5 to 50 kB.\n\nYou write a JSON spec. You never write SVG by hand. The command `npx flowfig` checks the spec and renders it.\n\n## What flowfig draws\n\nA spec has three forms.\n\n- The map (the default). The map shows the boxes and the edges. A packet moves along an edge in each beat.\n- The map with a rail (`\"rail\": true`). The rail is a lifeline diagram under the map. It has one row for each message.\n- The rail alone (`\"rail\": \"only\"`). Use it when the reader needs only the order of the messages, for example when the map is already in the same document.\n\nUse the rail for a sequence of messages: a request lifecycle, an API call chain, or a Mermaid `sequenceDiagram`. Put each message on\nan edge. Put each phase in a step. Put messages that run at the same time in one beat. Mark a message that does not wait for an\nanswer with `\"async\": true`: every send to a queue or a topic, every emitted event, and every call the caller does not await.\n\n## Scope: what flowfig draws and what it does not\n\nflowfig draws how something works: parts, the messages between them, and the order of the messages.\n\n| The user asks for | Draw |\n| ------------------------------------------ | ------------------------------------------------------------------------------------------ |\n| An architecture, a data flow, a pipeline | The map. Group parts by service, network or trust boundary. `store` for data at rest. |\n| A request lifecycle, a call chain | The map with `\"rail\": true`. One message per hop, with its real payload in `data`. |\n| A sequence diagram only | `\"rail\": \"only\"`. |\n| A state lifecycle, a state machine | One box per state, one edge per transition, labeled with its event. One step per path. Mark the first state with `mark: \"start\"` and each final state with `mark: \"end\"`. |\n| A flowchart with branches | `shape: \"decision\"` for each branch. One step per path. |\n| A roadmap or a timeline | `timeline: true`. One labeled group per track, in a `column` group. Items with `from` and `to` (dates), a milestone with `from` only, an edge for a dependency, `today` for the line. A dependent item starts after its source ends. |\n| A process across roles (a ticket, an order, a refund) | `lanes: true`. One labeled group per role, in a `column` group. Put each step in the lane of the role that does it. Link each step with `source` to the SOP heading. About four time columns fit at 830 px: merge steps, give the outcomes of one decision the same `at`, or split the figure. |\n\nflowfig draws a roadmap or a timeline with dates (`timeline: true`), and converts a Mermaid `gantt` to it. flowfig does not\ndraw class or ER diagrams (fields, types, cardinality), charts of numbers or mind maps. If the user asks for one of these, say that\nflowfig does not draw it, suggest Mermaid (`classDiagram`, `erDiagram`), and draw nothing with flowfig.\n\n## Workflow\n\n### 1. Pick the scope\n\nIf the code has more than one flow, name each flow in the reply. Then draw one flow, or draw one structure view and call it a\nstructure view. If the user asks for the whole system, draw one top view with groups, or a set of figures that together cover\nevery part. Keep each figure to 12 boxes or fewer.\n\n### 2. Write the fact list\n\nBefore the spec, write a list of the facts that the figure must show. Take each fact from the code and from its wiring: config\nfiles, compose files, route tables and queue bindings (or from the pasted Mermaid). Give each fact its `file:line`:\n\n- every part (service, function, store, queue, external system);\n- every call, in order, written as `caller \u2192 callee: payload (file:line of the call)`. The edge in the spec goes from that caller\n to that callee;\n- every call that does not wait for an answer (fire and forget, a queue, a webhook, a callback), and every consumer of each queue\n or topic;\n- every branch and every error path (a rejected input, a retry, a dead-letter path);\n- every end state.\n\nIf the code does not show a fact, leave the fact out. Do not guess a part, a name or an order.\n\n### 3. Write the spec\n\nEach fact becomes a box, an edge, a beat, a `data` card or a `show` row. Use the real names from the code as labels, and\nreal example data from the code or its tests. Keep each fact that you leave out, with the reason, for the reply.\nGive each box and edge that draws code a `source`, from the fact list: `\"src/auth/login.ts#verifyPassword\"`. A store or an outside part may have none.\nA box that draws a step from a document links to that document: `\"docs/sop/refunds.md#step-3-approve-the-refund\"`, the heading as a GitHub anchor. `verify` checks it the same way.\n\nMermaid mapping:\n\n| Mermaid | flowfig |\n| ---------------------------------------- | ------------------------------------------------------------------ |\n| `participant` | a box |\n| `A->>B: text` | an edge from A to B, and a hop with `data: \"text\"` |\n| `B-->>A: text` (a reply) | a hop on the same edge with `back: true` |\n| `A-)B: text` (async) | a hop with `async: true` |\n| `par ... and ... end` | the hops of all branches in one beat |\n| `alt` / `opt` | one step per path |\n| `stateDiagram` states and transitions | boxes, and edges labeled with the event |\n\n### 4. Render, then fix\n\n```bash\nnpx flowfig - out.svg <<'SPEC'\n{ \"props\": { \"layout\": ..., \"edges\": [...], \"steps\": [...] } }\nSPEC\n```\n\nThe quoted `<<'SPEC'` heredoc passes the JSON with no change. The command checks the spec first. If the check finds an error, the\ncommand writes no SVG and lists the faults. Fix each fault and render again.\n\n- Fix a layout fault by changing the layout first: put parts in rows or columns, route an edge `around`, or change a gap.\n Never remove a fact from the fact list to pass the check. If you must remove one, name it in the reply.\n- If `small-text` appears, the figure is too wide. Put the parts in two rows, move a detail from `label` to `sub`, or split\n the figure. Use more steps in one figure before you make a second figure. Keep the real name from the code in the label:\n `ReportsController` stays `ReportsController`, not `Controller`. Do not change `--width` to pass the check: the\n reader sees the figure at the real page width.\n- Fix every other warning, or tell the user why it stays.\n- Do not use `--no-check` to hide a fault.\n\n### 5. Read the figure back\n\nRun `npx flowfig --spec out.svg`. Compare the spec with the fact list. Check that each edge goes from the caller to the callee\nthat its fact names. Add each fact that is missing, fix each wrong edge, and render again.\n\nRun `npx flowfig verify out.svg` from the repo root. Fix each `missing-file` or `missing-symbol`.\n\n### 6. Look at the SVG\n\nThe check estimates the text width, so it cannot see everything. If you can open a browser, open the SVG and take a\nscreenshot. Wait a few seconds and take a second screenshot to see a later beat. If you cannot open a browser, write \"not\nlooked at\" in the reply. Never report a look that you did not do. A browser tool can block `file://` URLs. If it does, serve the folder\nwith `python3 -m http.server`.\n\n### 7. Write the reply\n\nThe reply has these parts, in this order:\n\n1. the path of each SVG;\n2. what each figure shows: the parts and the steps. Copy the counts from the `figure:` line of the check output. Copy every name\n from the read-back spec. Never count from memory;\n3. the scope: the flow you drew, why, and the other flows that exist;\n4. what the figure leaves out, and why;\n5. the two check lines that the render printed, `0 errors, 0 warnings` and `figure: ...`, copied as printed, and whether\n you looked at the SVG;\n6. one line `npx flowfig open <path>` for each SVG, at the end of the reply. Do not run that command yourself.\n\nTo change an SVG later, print its spec with `--spec`, change the spec, and render again.\n\n## Spec reference\n\n`props` has these fields.\n\n| Field | Type | Meaning |\n| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------- |\n| `layout` | group | The boxes and how they line up. Required. |\n| `edges` | edge[] | The arrows between the boxes. Required. |\n| `steps` | step[] | The stories the figure tells. With no steps, the figure is a still map. |\n| `lanes` | `true` | Draw the layout as swimlanes: a `column` group of labeled groups, one per role. The boxes run left to right in step order. |\n| `timeline` | `true` | Draw the layout as a timeline: one labeled group per track, with the boxes placed by their `from` and `to` dates. |\n| `today` | `YYYY-MM-DD` | In a `timeline` figure: the date where the today line stops. Default: the last date of the items. |\n| `rail` | `true` or `\"only\"` | Draw the steps as a lifeline rail under the map. `\"only\"` draws the rail without the map. |\n| `speed` | number | Milliseconds a packet takes to cross one edge. Default: 900. |\n| `theme` | object | Colors: `accent`, `fg`, `muted`, `bg`, `surface`, `border`, `font`. Each color you omit keeps its built-in value. |\n\n### layout\n\nThe layout is a tree. A group has `children` and these optional fields.\n\n- `id`: a name that an edge can use to reach the group as a whole.\n- `label`: the title on the frame. Only a group with a `label` gets a frame.\n- `direction`: `\"row\"` (the default) or `\"column\"`.\n- `gap`: the space between children in px. Default: 28 for a column. For a row, the gap fits the widest edge label between two children (at least 56).\n- `align`: `\"start\"`, `\"center\"` or `\"end\"`. This sets where the children line up across the direction.\n\nEvery other item is a box.\n\n| Box field | Meaning |\n| --------- | --------------------------------------------------------------------------------------------------------- |\n| `id` | Required. The name that edges and steps use. It must be unique in the figure. |\n| `label` | Required. The title in the box. |\n| `sub` | A smaller line under the label. |\n| `shape` | `\"box\"` (default), `\"decision\"` (a diamond) or `\"store\"` (a database cylinder for data at rest). |\n| `at` | In a `lanes` figure: the time column of the box, 0 first. Default: the order in which the steps first reach the box. |\n| `from` | In a `timeline` figure: the start of the item, or the date of a milestone, as YYYY-MM-DD. |\n| `to` | In a `timeline` figure: the last day of the item, as YYYY-MM-DD. Without it the box is a milestone. |\n| `width` | Width in px. This overrides the width that the layout picks. |\n| `source` | The code this draws: `path` or `path#symbol`, relative to the repo root. `flowfig verify` checks it. |\n| `lines` | The least number of text lines that a content card keeps. The card still grows to fit its content. |\n| `tone` | The state color of the box: a 1 px border and a light tint. Use `blue`, `purple`, `green`, `orange`, `red` or `gray`. |\n| `mark` | `\"start\"` or `\"end\"` | A lifecycle mark: a filled dot before a start state, a ringed dot after an end state. |\n\n### edges\n\nAn edge has these fields.\n\n- `id`: the name that steps use. Default: `from->to`.\n- `from` and `to`: the `id` of a box or a group.\n- `label`: text on the edge, drawn as a small pill.\n- `around`: `\"above\"` or `\"below\"`. This routes the edge over or under the boxes in between (loops, skip-ahead edges).\n- `quiet`: if `true`, the SVG draws the edge only while a step uses it.\n- `source`: the code this edge draws, as `path` or `path#symbol`. `flowfig verify` checks it.\n\n### steps\n\nA step has `label` and `flow`. It can also have `caption` (the line under the figure while no beat has a `say`) and `nodes` (ids of\nboxes to highlight for the whole step).\n\n`flow` is a list of beats. A beat is one of these:\n\n- an edge id (a string);\n- an array of edge ids, which run at the same time;\n- an object `{ edges?, say?, show?, light?, ms? }`. A beat with no `edges` is a pause.\n\nThe beat fields:\n\n- `edges`: an edge id, a hop object, or an array of these. A hop object is `{ edge, back?, data?, tone?, async?, source? }`.\n - `back: true` runs the packet from the `to` box to the `from` box.\n - `data` is a small card that moves with the packet.\n - `async: true` marks a message that does not wait for an answer. The rail draws it dashed, with an `async` tag.\n - `tone`: the color of this hop for its beat. The packet, the data card, the edge, the label pill and the arrival box take the color. The trail after the beat stays the accent.\n - `green`: a success or a cache hit. `orange`: a warning, a miss or a retry. `red`: an error or a rejected input.\n - `gray`: idle or skipped. `purple`: async or background. `blue`: the default row color.\n - If the hop has no `tone`, the arrival box uses its box `tone`, then the accent. A hop `tone` wins over a box `tone`.\n- `say`: the caption for the beat.\n- `show`: `{ boxId: [row, ...] }`. This fills the content card of each named box. The card keeps the rows until the step ends.\n- `light`: ids of boxes to highlight for this beat.\n- `ms`: how long the beat lasts. Default: the time one packet needs to cross an edge.\n\nA row of a content card is `{ tag?, tone?, text, meta?, mark?, mono? }`.\n\n- `tag`: a short colored label at the start of the line.\n- `tone`: the color of the tag: `blue` (default), `purple`, `green`, `orange`, `red` or `gray`.\n- `text`: the main text.\n- `meta`: muted text after the main text.\n- `mark`: a mark at the right end of the line, such as a check or \"new\".\n- `mono`: if `true`, the text uses a monospace font.\n\n## Content rules\n\n- Give every box a stable `id`.\n- Use `shape: \"store\"` for data at rest (a database, a cache, a file, a queue). Use a plain box for a part that does work. Use `shape: \"decision\"` for a branch.\n- Keep one clear main path, left to right. Put side parts in a `column` group.\n- Use `quiet: true` on a long edge that crosses the picture. A quiet edge needs a beat that uses it, or the check reports\n `hidden-edge`.\n- In a rail, draw an error reply as a hop back on the same edge, with the error in `data` (`{ \"edge\": \"login\", \"back\": true,\n \"data\": \"401 CREDENTIALS_INVALID\" }`). A call that stays inside one part (a hash check, a guard) is not a message: put it in\n `say` or in a `show` row of that part.\n- Keep an SVG to one or two steps. The SVG plays every step in a loop, with no controls.\n- Use the React player, `<Flow {...props} />` from `flowfig`, for a page that needs tabs, pause or hover.\n\n## Example\n\n```json\n{\n \"props\": {\n \"layout\": {\n \"children\": [\n { \"id\": \"client\", \"label\": \"Browser\" },\n { \"id\": \"api\", \"label\": \"API Server\" },\n { \"id\": \"db\", \"label\": \"Database\", \"shape\": \"store\" }\n ]\n },\n \"edges\": [\n { \"id\": \"req\", \"from\": \"client\", \"to\": \"api\", \"label\": \"GET /users/42\" },\n { \"id\": \"q\", \"from\": \"api\", \"to\": \"db\", \"label\": \"SELECT\" }\n ],\n \"steps\": [\n {\n \"label\": \"read\",\n \"flow\": [\n { \"edges\": { \"edge\": \"req\", \"data\": \"GET /users/42\" }, \"say\": \"The browser asks for user 42.\" },\n { \"edges\": \"q\", \"show\": { \"db\": [{ \"tag\": \"row\", \"tone\": \"gray\", \"text\": \"Ada Lovelace\" }] }, \"say\": \"The API server reads the row.\" },\n { \"edges\": { \"edge\": \"req\", \"back\": true, \"data\": \"200 OK\" }, \"say\": \"The API server sends the user.\" }\n ]\n }\n ]\n }\n}\n```\n\n## Commands\n\n```bash\nnpx flowfig - out.svg < spec.json # render a spec from stdin\nnpx flowfig spec.json out.svg # render a spec file\nnpx flowfig figure.ts out.svg # render a module whose default export is a spec\nnpx flowfig check <input> [--json] # list the faults. The input can also be an SVG that flowfig wrote.\nnpx flowfig verify <input>... # check that the code each source names still exists\nnpx flowfig diff <old> <new> # list what changed in the spec between two figures\nnpx flowfig --spec out.svg # print the spec that an SVG carries\nnpx flowfig open out.svg # show the figure in the default browser\nnpx flowfig gif out.svg [out.gif] # write an animated GIF (needs Chrome, Edge, Chromium or Brave)\nnpx flowfig docs # print this guide\nnpx flowfig init # write these instructions for the coding agents of a repo\n```\n\nA render checks first and writes nothing on an error. `--strict` makes warnings errors. `--width` sets the page width.\n`--min-text` sets the smallest text that the reader should get. `--no-check` skips the check.\n";
|
|
3
3
|
/** The short instruction text that `flowfig init` writes for each coding agent. */
|
|
4
|
-
export declare const AGENT_TEXT = "# Diagrams with flowfig\n\
|
|
4
|
+
export declare const AGENT_TEXT = "# Diagrams with flowfig\n\nIf the user names no other tool, use flowfig for every diagram, figure, flowchart or picture of how something works. Do not answer with a Mermaid block or ASCII art. Use it for an architecture, a data flow or pipeline, a request lifecycle,\na call sequence, a state lifecycle, or a flowchart. flowfig also converts a pasted Mermaid flowchart, `stateDiagram` or\n`sequenceDiagram`.\n\nflowfig draws a roadmap or a timeline with dates (`timeline: true`), and converts a Mermaid `gantt` to it. flowfig does not\ndraw class or ER diagrams or charts of numbers. For those, tell the user so, suggest Mermaid (`classDiagram`, `erDiagram`),\nand draw nothing with flowfig.\n\n1. Run `npx flowfig docs` and read it. If the command fails, stop: tell the user that flowfig is not available, give them\n `npm install --save-dev flowfig`, and draw nothing with another tool.\n2. Pick the scope. If the code has more than one flow, name each flow in the reply, then draw one flow, or draw one structure\n view and call it a structure view. If the user asks for the whole system, draw one top view with groups, or a set of figures\n that together cover every part. Keep each figure to 12 boxes or fewer. For a process that several roles do, use\n `lanes: true`, one labeled group per role. For a plan or a roadmap, read the dates from the document and use `timeline: true`.\n3. Write a fact list from the code and from its wiring (config, compose, route and queue files). Write each call as\n `caller \u2192 callee: payload (file:line of the call)`, in order. Include each async call and every consumer of a queue, each\n branch and error path, and each end state. Leave out what the code does not show.\n4. Write the spec from the fact list, with the real names and data. Render it with `npx flowfig - out.svg <<'SPEC'` and the\n JSON in the heredoc. Fix every fault by changing the layout first (rows, `around`, the gap). Never remove a fact to pass\n the check; if you must remove one, name it in the reply. If `small-text` appears, use two rows or split the figure; keep\n the real names; do not change `--width`. Give each box and edge that draws code a `source` (`file#symbol`) from the fact list.\n Mark every send to a queue or a topic, every emitted event, and every call the caller does not await with `async: true`.\n5. Run `npx flowfig --spec out.svg` and compare it with the fact list: each edge must go from the caller to the callee that the\n fact names. Fix each gap. Then run `npx flowfig verify out.svg` from the repo root and fix each fault.\n6. If you can open a browser, look at the SVG at two moments of the loop. If you cannot, write \"not looked at\" in the reply.\n Never report a look that you did not do.\n7. Reply with: the SVG path; what it shows, with the counts copied from the `figure:` line and the names copied from the read-back spec; what it leaves out and why;\n the two lines the render printed, `0 errors, 0 warnings` and `figure: ...`, copied as printed.\n End the reply with one line `npx flowfig open <path>` for each SVG. Do not run that command yourself.\n";
|
|
5
5
|
/** The description of the Claude skill: the words that make the agent load it. */
|
|
6
|
-
export declare const SKILL_DESCRIPTION = "Use when the user asks for a diagram, figure or animation of how code or a system works: an architecture, a data flow, a pipeline, a request lifecycle, a call sequence, a state lifecycle or a
|
|
6
|
+
export declare const SKILL_DESCRIPTION = "Use for every request for a diagram, figure, flowchart or picture of how something works, when the user names no other tool. Do not answer with a Mermaid block or ASCII art. Use when the user asks for a diagram, figure or animation of how code or a system works: an architecture, a data flow, a pipeline, a request lifecycle, a call sequence, a state lifecycle, a flowchart, a roadmap or a timeline; when the user pastes a Mermaid flowchart, stateDiagram, sequenceDiagram or gantt to convert; or when the user asks for a class or ER diagram.";
|
package/dist/guide.js
CHANGED
|
@@ -18,7 +18,7 @@ A spec has three forms.
|
|
|
18
18
|
|
|
19
19
|
Use the rail for a sequence of messages: a request lifecycle, an API call chain, or a Mermaid \`sequenceDiagram\`. Put each message on
|
|
20
20
|
an edge. Put each phase in a step. Put messages that run at the same time in one beat. Mark a message that does not wait for an
|
|
21
|
-
answer with \`"async": true
|
|
21
|
+
answer with \`"async": true\`: every send to a queue or a topic, every emitted event, and every call the caller does not await.
|
|
22
22
|
|
|
23
23
|
## Scope: what flowfig draws and what it does not
|
|
24
24
|
|
|
@@ -29,12 +29,14 @@ flowfig draws how something works: parts, the messages between them, and the ord
|
|
|
29
29
|
| An architecture, a data flow, a pipeline | The map. Group parts by service, network or trust boundary. \`store\` for data at rest. |
|
|
30
30
|
| A request lifecycle, a call chain | The map with \`"rail": true\`. One message per hop, with its real payload in \`data\`. |
|
|
31
31
|
| A sequence diagram only | \`"rail": "only"\`. |
|
|
32
|
-
| A state lifecycle, a state machine | One box per state, one edge per transition, labeled with its event. One step per path. Mark
|
|
32
|
+
| A state lifecycle, a state machine | One box per state, one edge per transition, labeled with its event. One step per path. Mark the first state with \`mark: "start"\` and each final state with \`mark: "end"\`. |
|
|
33
33
|
| A flowchart with branches | \`shape: "decision"\` for each branch. One step per path. |
|
|
34
|
+
| A roadmap or a timeline | \`timeline: true\`. One labeled group per track, in a \`column\` group. Items with \`from\` and \`to\` (dates), a milestone with \`from\` only, an edge for a dependency, \`today\` for the line. A dependent item starts after its source ends. |
|
|
35
|
+
| A process across roles (a ticket, an order, a refund) | \`lanes: true\`. One labeled group per role, in a \`column\` group. Put each step in the lane of the role that does it. Link each step with \`source\` to the SOP heading. About four time columns fit at 830 px: merge steps, give the outcomes of one decision the same \`at\`, or split the figure. |
|
|
34
36
|
|
|
35
|
-
flowfig
|
|
36
|
-
or mind maps. If the user asks for one of these, say that
|
|
37
|
-
\`
|
|
37
|
+
flowfig draws a roadmap or a timeline with dates (\`timeline: true\`), and converts a Mermaid \`gantt\` to it. flowfig does not
|
|
38
|
+
draw class or ER diagrams (fields, types, cardinality), charts of numbers or mind maps. If the user asks for one of these, say that
|
|
39
|
+
flowfig does not draw it, suggest Mermaid (\`classDiagram\`, \`erDiagram\`), and draw nothing with flowfig.
|
|
38
40
|
|
|
39
41
|
## Workflow
|
|
40
42
|
|
|
@@ -64,6 +66,7 @@ If the code does not show a fact, leave the fact out. Do not guess a part, a nam
|
|
|
64
66
|
Each fact becomes a box, an edge, a beat, a \`data\` card or a \`show\` row. Use the real names from the code as labels, and
|
|
65
67
|
real example data from the code or its tests. Keep each fact that you leave out, with the reason, for the reply.
|
|
66
68
|
Give each box and edge that draws code a \`source\`, from the fact list: \`"src/auth/login.ts#verifyPassword"\`. A store or an outside part may have none.
|
|
69
|
+
A box that draws a step from a document links to that document: \`"docs/sop/refunds.md#step-3-approve-the-refund"\`, the heading as a GitHub anchor. \`verify\` checks it the same way.
|
|
67
70
|
|
|
68
71
|
Mermaid mapping:
|
|
69
72
|
|
|
@@ -121,7 +124,8 @@ The reply has these parts, in this order:
|
|
|
121
124
|
3. the scope: the flow you drew, why, and the other flows that exist;
|
|
122
125
|
4. what the figure leaves out, and why;
|
|
123
126
|
5. the two check lines that the render printed, \`0 errors, 0 warnings\` and \`figure: ...\`, copied as printed, and whether
|
|
124
|
-
you looked at the SVG
|
|
127
|
+
you looked at the SVG;
|
|
128
|
+
6. one line \`npx flowfig open <path>\` for each SVG, at the end of the reply. Do not run that command yourself.
|
|
125
129
|
|
|
126
130
|
To change an SVG later, print its spec with \`--spec\`, change the spec, and render again.
|
|
127
131
|
|
|
@@ -134,6 +138,9 @@ To change an SVG later, print its spec with \`--spec\`, change the spec, and ren
|
|
|
134
138
|
| \`layout\` | group | The boxes and how they line up. Required. |
|
|
135
139
|
| \`edges\` | edge[] | The arrows between the boxes. Required. |
|
|
136
140
|
| \`steps\` | step[] | The stories the figure tells. With no steps, the figure is a still map. |
|
|
141
|
+
| \`lanes\` | \`true\` | Draw the layout as swimlanes: a \`column\` group of labeled groups, one per role. The boxes run left to right in step order. |
|
|
142
|
+
| \`timeline\` | \`true\` | Draw the layout as a timeline: one labeled group per track, with the boxes placed by their \`from\` and \`to\` dates. |
|
|
143
|
+
| \`today\` | \`YYYY-MM-DD\` | In a \`timeline\` figure: the date where the today line stops. Default: the last date of the items. |
|
|
137
144
|
| \`rail\` | \`true\` or \`"only"\` | Draw the steps as a lifeline rail under the map. \`"only"\` draws the rail without the map. |
|
|
138
145
|
| \`speed\` | number | Milliseconds a packet takes to cross one edge. Default: 900. |
|
|
139
146
|
| \`theme\` | object | Colors: \`accent\`, \`fg\`, \`muted\`, \`bg\`, \`surface\`, \`border\`, \`font\`. Each color you omit keeps its built-in value. |
|
|
@@ -156,9 +163,14 @@ Every other item is a box.
|
|
|
156
163
|
| \`label\` | Required. The title in the box. |
|
|
157
164
|
| \`sub\` | A smaller line under the label. |
|
|
158
165
|
| \`shape\` | \`"box"\` (default), \`"decision"\` (a diamond) or \`"store"\` (a database cylinder for data at rest). |
|
|
166
|
+
| \`at\` | In a \`lanes\` figure: the time column of the box, 0 first. Default: the order in which the steps first reach the box. |
|
|
167
|
+
| \`from\` | In a \`timeline\` figure: the start of the item, or the date of a milestone, as YYYY-MM-DD. |
|
|
168
|
+
| \`to\` | In a \`timeline\` figure: the last day of the item, as YYYY-MM-DD. Without it the box is a milestone. |
|
|
159
169
|
| \`width\` | Width in px. This overrides the width that the layout picks. |
|
|
160
170
|
| \`source\` | The code this draws: \`path\` or \`path#symbol\`, relative to the repo root. \`flowfig verify\` checks it. |
|
|
161
171
|
| \`lines\` | The least number of text lines that a content card keeps. The card still grows to fit its content. |
|
|
172
|
+
| \`tone\` | The state color of the box: a 1 px border and a light tint. Use \`blue\`, \`purple\`, \`green\`, \`orange\`, \`red\` or \`gray\`. |
|
|
173
|
+
| \`mark\` | \`"start"\` or \`"end"\` | A lifecycle mark: a filled dot before a start state, a ringed dot after an end state. |
|
|
162
174
|
|
|
163
175
|
### edges
|
|
164
176
|
|
|
@@ -184,10 +196,14 @@ boxes to highlight for the whole step).
|
|
|
184
196
|
|
|
185
197
|
The beat fields:
|
|
186
198
|
|
|
187
|
-
- \`edges\`: an edge id, a hop object, or an array of these. A hop object is \`{ edge, back?, data?, async?, source? }\`.
|
|
199
|
+
- \`edges\`: an edge id, a hop object, or an array of these. A hop object is \`{ edge, back?, data?, tone?, async?, source? }\`.
|
|
188
200
|
- \`back: true\` runs the packet from the \`to\` box to the \`from\` box.
|
|
189
201
|
- \`data\` is a small card that moves with the packet.
|
|
190
202
|
- \`async: true\` marks a message that does not wait for an answer. The rail draws it dashed, with an \`async\` tag.
|
|
203
|
+
- \`tone\`: the color of this hop for its beat. The packet, the data card, the edge, the label pill and the arrival box take the color. The trail after the beat stays the accent.
|
|
204
|
+
- \`green\`: a success or a cache hit. \`orange\`: a warning, a miss or a retry. \`red\`: an error or a rejected input.
|
|
205
|
+
- \`gray\`: idle or skipped. \`purple\`: async or background. \`blue\`: the default row color.
|
|
206
|
+
- If the hop has no \`tone\`, the arrival box uses its box \`tone\`, then the accent. A hop \`tone\` wins over a box \`tone\`.
|
|
191
207
|
- \`say\`: the caption for the beat.
|
|
192
208
|
- \`show\`: \`{ boxId: [row, ...] }\`. This fills the content card of each named box. The card keeps the rows until the step ends.
|
|
193
209
|
- \`light\`: ids of boxes to highlight for this beat.
|
|
@@ -196,7 +212,7 @@ The beat fields:
|
|
|
196
212
|
A row of a content card is \`{ tag?, tone?, text, meta?, mark?, mono? }\`.
|
|
197
213
|
|
|
198
214
|
- \`tag\`: a short colored label at the start of the line.
|
|
199
|
-
- \`tone\`: the color of the tag: \`blue\` (default), \`purple\`, \`green\`, \`orange\` or \`gray\`.
|
|
215
|
+
- \`tone\`: the color of the tag: \`blue\` (default), \`purple\`, \`green\`, \`orange\`, \`red\` or \`gray\`.
|
|
200
216
|
- \`text\`: the main text.
|
|
201
217
|
- \`meta\`: muted text after the main text.
|
|
202
218
|
- \`mark\`: a mark at the right end of the line, such as a check or "new".
|
|
@@ -255,6 +271,8 @@ npx flowfig check <input> [--json] # list the faults. The input can also be
|
|
|
255
271
|
npx flowfig verify <input>... # check that the code each source names still exists
|
|
256
272
|
npx flowfig diff <old> <new> # list what changed in the spec between two figures
|
|
257
273
|
npx flowfig --spec out.svg # print the spec that an SVG carries
|
|
274
|
+
npx flowfig open out.svg # show the figure in the default browser
|
|
275
|
+
npx flowfig gif out.svg [out.gif] # write an animated GIF (needs Chrome, Edge, Chromium or Brave)
|
|
258
276
|
npx flowfig docs # print this guide
|
|
259
277
|
npx flowfig init # write these instructions for the coding agents of a repo
|
|
260
278
|
\`\`\`
|
|
@@ -265,18 +283,20 @@ A render checks first and writes nothing on an error. \`--strict\` makes warning
|
|
|
265
283
|
/** The short instruction text that `flowfig init` writes for each coding agent. */
|
|
266
284
|
export const AGENT_TEXT = `# Diagrams with flowfig
|
|
267
285
|
|
|
268
|
-
|
|
286
|
+
If the user names no other tool, use flowfig for every diagram, figure, flowchart or picture of how something works. Do not answer with a Mermaid block or ASCII art. Use it for an architecture, a data flow or pipeline, a request lifecycle,
|
|
269
287
|
a call sequence, a state lifecycle, or a flowchart. flowfig also converts a pasted Mermaid flowchart, \`stateDiagram\` or
|
|
270
288
|
\`sequenceDiagram\`.
|
|
271
289
|
|
|
272
|
-
flowfig
|
|
273
|
-
(\`classDiagram\`, \`erDiagram
|
|
290
|
+
flowfig draws a roadmap or a timeline with dates (\`timeline: true\`), and converts a Mermaid \`gantt\` to it. flowfig does not
|
|
291
|
+
draw class or ER diagrams or charts of numbers. For those, tell the user so, suggest Mermaid (\`classDiagram\`, \`erDiagram\`),
|
|
292
|
+
and draw nothing with flowfig.
|
|
274
293
|
|
|
275
294
|
1. Run \`npx flowfig docs\` and read it. If the command fails, stop: tell the user that flowfig is not available, give them
|
|
276
295
|
\`npm install --save-dev flowfig\`, and draw nothing with another tool.
|
|
277
296
|
2. Pick the scope. If the code has more than one flow, name each flow in the reply, then draw one flow, or draw one structure
|
|
278
297
|
view and call it a structure view. If the user asks for the whole system, draw one top view with groups, or a set of figures
|
|
279
|
-
that together cover every part. Keep each figure to 12 boxes or fewer.
|
|
298
|
+
that together cover every part. Keep each figure to 12 boxes or fewer. For a process that several roles do, use
|
|
299
|
+
\`lanes: true\`, one labeled group per role. For a plan or a roadmap, read the dates from the document and use \`timeline: true\`.
|
|
280
300
|
3. Write a fact list from the code and from its wiring (config, compose, route and queue files). Write each call as
|
|
281
301
|
\`caller → callee: payload (file:line of the call)\`, in order. Include each async call and every consumer of a queue, each
|
|
282
302
|
branch and error path, and each end state. Leave out what the code does not show.
|
|
@@ -284,12 +304,14 @@ flowfig does not draw class or ER diagrams, Gantt charts or charts of numbers. F
|
|
|
284
304
|
JSON in the heredoc. Fix every fault by changing the layout first (rows, \`around\`, the gap). Never remove a fact to pass
|
|
285
305
|
the check; if you must remove one, name it in the reply. If \`small-text\` appears, use two rows or split the figure; keep
|
|
286
306
|
the real names; do not change \`--width\`. Give each box and edge that draws code a \`source\` (\`file#symbol\`) from the fact list.
|
|
307
|
+
Mark every send to a queue or a topic, every emitted event, and every call the caller does not await with \`async: true\`.
|
|
287
308
|
5. Run \`npx flowfig --spec out.svg\` and compare it with the fact list: each edge must go from the caller to the callee that the
|
|
288
309
|
fact names. Fix each gap. Then run \`npx flowfig verify out.svg\` from the repo root and fix each fault.
|
|
289
310
|
6. If you can open a browser, look at the SVG at two moments of the loop. If you cannot, write "not looked at" in the reply.
|
|
290
311
|
Never report a look that you did not do.
|
|
291
312
|
7. Reply with: the SVG path; what it shows, with the counts copied from the \`figure:\` line and the names copied from the read-back spec; what it leaves out and why;
|
|
292
313
|
the two lines the render printed, \`0 errors, 0 warnings\` and \`figure: ...\`, copied as printed.
|
|
314
|
+
End the reply with one line \`npx flowfig open <path>\` for each SVG. Do not run that command yourself.
|
|
293
315
|
`;
|
|
294
316
|
/** The description of the Claude skill: the words that make the agent load it. */
|
|
295
|
-
export const SKILL_DESCRIPTION = 'Use when the user asks for a diagram, figure or animation of how code or a system works: an architecture, a data flow, a pipeline, a request lifecycle, a call sequence, a state lifecycle or a
|
|
317
|
+
export const SKILL_DESCRIPTION = 'Use for every request for a diagram, figure, flowchart or picture of how something works, when the user names no other tool. Do not answer with a Mermaid block or ASCII art. Use when the user asks for a diagram, figure or animation of how code or a system works: an architecture, a data flow, a pipeline, a request lifecycle, a call sequence, a state lifecycle, a flowchart, a roadmap or a timeline; when the user pastes a Mermaid flowchart, stateDiagram, sequenceDiagram or gantt to convert; or when the user asks for a class or ER diagram.';
|
package/dist/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export { LIGHT, DARK } from './model.ts';
|
|
|
5
5
|
* The interactive player for one figure: tabs for the steps, play and pause, speed, hover and full screen.
|
|
6
6
|
* Give it a `FlowProps` spec. Use `toSvg` from `flowfig/svg` for a static animated SVG instead.
|
|
7
7
|
*/
|
|
8
|
-
export declare function Flow({ layout, edges, steps, theme, speed, autoplay, check, rail: withRail }: FlowProps): import("react").JSX.Element;
|
|
8
|
+
export declare function Flow({ layout, edges, steps: stepsIn, theme, speed, autoplay, check, rail: withRail, lanes, timeline, today, }: FlowProps): import("react").JSX.Element;
|