flowfig 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +428 -0
- package/dist/check.d.ts +14 -0
- package/dist/check.js +155 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +133 -0
- package/dist/geometry.d.ts +24 -0
- package/dist/geometry.js +80 -0
- package/dist/guide.d.ts +6 -0
- package/dist/guide.js +280 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +638 -0
- package/dist/init.d.ts +25 -0
- package/dist/init.js +171 -0
- package/dist/model.d.ts +191 -0
- package/dist/model.js +71 -0
- package/dist/rail.d.ts +82 -0
- package/dist/rail.js +162 -0
- package/dist/scene.d.ts +35 -0
- package/dist/scene.js +1 -0
- package/dist/svg.d.ts +28 -0
- package/dist/svg.js +563 -0
- package/dist/text.d.ts +2 -0
- package/dist/text.js +13 -0
- package/package.json +80 -0
package/dist/cli.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
3
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
4
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
5
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return path;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Render a figure as one animated SVG — for a README, a PR, an issue, a blog post — and check it first.
|
|
12
|
+
*
|
|
13
|
+
* flowfig - out.svg < spec.json # a spec on stdin: nothing is left on disk
|
|
14
|
+
* flowfig spec.json out.svg # a spec file
|
|
15
|
+
* flowfig figure.ts out.svg # a module whose default export is a spec
|
|
16
|
+
* flowfig --spec out.svg # print back the spec the SVG carries
|
|
17
|
+
* flowfig check <input> [--json] # list the faults; the input can also be an SVG this wrote
|
|
18
|
+
* flowfig docs # print the full guide (Markdown)
|
|
19
|
+
* flowfig init [dir] # write flowfig instructions for the coding agents of a repo
|
|
20
|
+
*
|
|
21
|
+
* A render checks first and writes nothing on an error (--no-check skips that). --strict makes warnings errors; --width and
|
|
22
|
+
* --min-text set the page width and the smallest text the reader should get.
|
|
23
|
+
*
|
|
24
|
+
* Every rendered SVG carries its own spec in <metadata>, so a figure is editable later without anyone having to keep the JSON.
|
|
25
|
+
*/
|
|
26
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
27
|
+
import { resolve } from 'node:path';
|
|
28
|
+
import { pathToFileURL } from 'node:url';
|
|
29
|
+
import { GUIDE } from './guide.js';
|
|
30
|
+
import { runInit } from './init.js';
|
|
31
|
+
import { counts } from './model.js';
|
|
32
|
+
import { check, toSvg } from './svg.js';
|
|
33
|
+
const SPEC_OPEN = '<metadata id="figure-spec"><![CDATA[';
|
|
34
|
+
const SPEC_CLOSE = ']]></metadata>';
|
|
35
|
+
/** Bad use, not a bad figure: exit 2 with a message, not a stack trace. A declaration, so TypeScript narrows after a call. */
|
|
36
|
+
function usage(message) {
|
|
37
|
+
console.error(message);
|
|
38
|
+
process.exit(2);
|
|
39
|
+
}
|
|
40
|
+
const args = process.argv.slice(2);
|
|
41
|
+
const flag = (name) => {
|
|
42
|
+
const i = args.indexOf(name);
|
|
43
|
+
return i !== -1 && args.splice(i, 1).length > 0;
|
|
44
|
+
};
|
|
45
|
+
const value = (name) => {
|
|
46
|
+
const i = args.indexOf(name);
|
|
47
|
+
if (i === -1)
|
|
48
|
+
return undefined;
|
|
49
|
+
const n = Number(args.splice(i, 2)[1] || NaN);
|
|
50
|
+
return n > 0 && Number.isFinite(n) ? n : usage(`${name} needs a positive number`);
|
|
51
|
+
};
|
|
52
|
+
function specOf(svg, name) {
|
|
53
|
+
const at = svg.indexOf(SPEC_OPEN);
|
|
54
|
+
if (at === -1)
|
|
55
|
+
usage(`${name}: no figure spec inside this SVG`);
|
|
56
|
+
return svg.slice(at + SPEC_OPEN.length, svg.indexOf(SPEC_CLOSE, at));
|
|
57
|
+
}
|
|
58
|
+
if (args[0] === 'docs') {
|
|
59
|
+
process.stdout.write(GUIDE);
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
if (args[0] === 'init')
|
|
63
|
+
process.exit(await runInit(args.slice(1)));
|
|
64
|
+
if (args[0] === '--spec') {
|
|
65
|
+
if (!args[1])
|
|
66
|
+
usage('--spec needs the path of an SVG');
|
|
67
|
+
console.log(specOf(readFileSync(args[1], 'utf8'), args[1]));
|
|
68
|
+
process.exit(0);
|
|
69
|
+
}
|
|
70
|
+
const command = args[0] === 'check' ? args.shift() : 'render';
|
|
71
|
+
const json = flag('--json'), strict = flag('--strict'), skip = flag('--no-check');
|
|
72
|
+
const opts = { width: value('--width'), minText: value('--min-text') };
|
|
73
|
+
const unknown = args.find((a) => a.startsWith('-') && a !== '-');
|
|
74
|
+
if (unknown)
|
|
75
|
+
usage(`unknown flag ${unknown}`);
|
|
76
|
+
const [input, out] = args;
|
|
77
|
+
if (!input)
|
|
78
|
+
usage('usage: flowfig <-|spec.json|figure.ts> [out.svg] | flowfig check <-|spec.json|figure.ts|figure.svg> [--json] | flowfig docs | flowfig init [dir]');
|
|
79
|
+
let loaded;
|
|
80
|
+
try {
|
|
81
|
+
loaded =
|
|
82
|
+
input === '-'
|
|
83
|
+
? JSON.parse(readFileSync(0, 'utf8'))
|
|
84
|
+
: input.endsWith('.json')
|
|
85
|
+
? JSON.parse(readFileSync(input, 'utf8'))
|
|
86
|
+
: input.endsWith('.svg')
|
|
87
|
+
? JSON.parse(specOf(readFileSync(input, 'utf8'), input))
|
|
88
|
+
: (await import(__rewriteRelativeImportExtension(pathToFileURL(resolve(input)).href))).default;
|
|
89
|
+
}
|
|
90
|
+
catch (e) {
|
|
91
|
+
usage(`${input}: ${e.message}`);
|
|
92
|
+
}
|
|
93
|
+
const props = loaded?.props ?? loaded;
|
|
94
|
+
if (!props?.layout)
|
|
95
|
+
usage(`${input}: no figure props (expected { props: { layout, edges, steps } })`);
|
|
96
|
+
if (!Array.isArray(props.edges))
|
|
97
|
+
usage(`${input}: edges must be an array (use [] for none)`);
|
|
98
|
+
if (props.steps?.some((s) => !Array.isArray(s?.flow)))
|
|
99
|
+
usage(`${input}: each step needs a flow array`);
|
|
100
|
+
const findings = skip
|
|
101
|
+
? []
|
|
102
|
+
: check(props, opts)
|
|
103
|
+
.map((f) => (strict ? { ...f, severity: 'error' } : f))
|
|
104
|
+
.sort((a, b) => (a.severity === b.severity ? a.rule.localeCompare(b.rule) : a.severity === 'error' ? -1 : 1));
|
|
105
|
+
const errors = findings.filter((f) => f.severity === 'error').length;
|
|
106
|
+
/** The findings for a person: one line each, colored only on a terminal. A render prints them to stderr, next to its own output. */
|
|
107
|
+
const report = (print, tty) => {
|
|
108
|
+
const paint = (s, code) => (tty && !process.env.NO_COLOR ? `\x1b[${code}m${s}\x1b[0m` : s);
|
|
109
|
+
for (const f of findings)
|
|
110
|
+
print(`${paint(f.severity.padEnd(8), f.severity === 'error' ? 31 : 33)} ${f.rule.padEnd(18)} ${f.message}`);
|
|
111
|
+
const n = (k, word) => `${k} ${word}${k === 1 ? '' : 's'}`;
|
|
112
|
+
if (findings.length || print === console.log)
|
|
113
|
+
print(`${n(errors, 'error')}, ${n(findings.length - errors, 'warning')}`);
|
|
114
|
+
const c = counts(props);
|
|
115
|
+
print(`figure: ${n(c.boxes, 'box').replace('boxs', 'boxes')}, ${n(c.groups, 'group')}, ${n(c.edges, 'edge')}, ${n(c.steps, 'step')}, ${n(c.messages, 'message')}`);
|
|
116
|
+
};
|
|
117
|
+
if (command === 'check') {
|
|
118
|
+
if (json)
|
|
119
|
+
console.log(JSON.stringify(findings, null, 2));
|
|
120
|
+
else
|
|
121
|
+
report(console.log, process.stdout.isTTY);
|
|
122
|
+
process.exit(errors ? 1 : 0);
|
|
123
|
+
}
|
|
124
|
+
report(console.error, process.stderr.isTTY);
|
|
125
|
+
if (errors)
|
|
126
|
+
process.exit(1);
|
|
127
|
+
const dest = out ?? (input === '-' ? 'figure.svg' : input.replace(/\.[^./\\]+$/, '') + '.svg');
|
|
128
|
+
// The spec rides along in <metadata>: an SVG is then its own source, and no JSON has to be kept.
|
|
129
|
+
// `]]>` would close the CDATA early; it cannot appear in JSON-encoded text, but be sure.
|
|
130
|
+
const spec = JSON.stringify({ props }).replaceAll(']]>', ']]\\u003e');
|
|
131
|
+
const withSpec = toSvg(props).replace(/(<svg[^>]*>\n?)/, (tag) => `${tag}${SPEC_OPEN}${spec}${SPEC_CLOSE}\n`);
|
|
132
|
+
writeFileSync(dest, withSpec);
|
|
133
|
+
console.log(`${dest} — ${(withSpec.length / 1024).toFixed(1)} kB`);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type Rect = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
w: number;
|
|
5
|
+
h: number;
|
|
6
|
+
};
|
|
7
|
+
export type Pt = {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
export type Routed = {
|
|
12
|
+
id: string;
|
|
13
|
+
d: string;
|
|
14
|
+
mid: Pt;
|
|
15
|
+
curve: [Pt, Pt, Pt, Pt];
|
|
16
|
+
};
|
|
17
|
+
type Around = 'above' | 'below';
|
|
18
|
+
export declare function route(edges: {
|
|
19
|
+
id: string;
|
|
20
|
+
from: string;
|
|
21
|
+
to: string;
|
|
22
|
+
around?: Around;
|
|
23
|
+
}[], rects: Record<string, Rect>, tips?: Set<string>): Routed[];
|
|
24
|
+
export {};
|
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
const cx = (r) => r.x + r.w / 2;
|
|
2
|
+
const cy = (r) => r.y + r.h / 2;
|
|
3
|
+
// Turns edges between measured boxes into curved SVG paths.
|
|
4
|
+
// Boxes stacked on top of each other connect bottom->top, otherwise side->side.
|
|
5
|
+
// Several edges leaving the same side of a box are spread out so they don't overlap,
|
|
6
|
+
// except on `tips` boxes (diamonds), where they all meet at the point.
|
|
7
|
+
// `around` makes an edge leave and enter from the top or bottom, arcing over whatever sits between.
|
|
8
|
+
export function route(edges, rects, tips = new Set()) {
|
|
9
|
+
const picks = [];
|
|
10
|
+
for (const e of edges) {
|
|
11
|
+
const a = rects[e.from], b = rects[e.to];
|
|
12
|
+
if (!a || !b)
|
|
13
|
+
continue;
|
|
14
|
+
const stacked = a.x < b.x + b.w && b.x < a.x + a.w;
|
|
15
|
+
const [sa, sb] = e.around
|
|
16
|
+
? e.around === 'above'
|
|
17
|
+
? ['t', 't']
|
|
18
|
+
: ['b', 'b']
|
|
19
|
+
: stacked
|
|
20
|
+
? a.y < b.y
|
|
21
|
+
? ['b', 't']
|
|
22
|
+
: ['t', 'b']
|
|
23
|
+
: a.x < b.x
|
|
24
|
+
? ['r', 'l']
|
|
25
|
+
: ['l', 'r'];
|
|
26
|
+
picks.push({ ...e, a, b, sa, sb });
|
|
27
|
+
}
|
|
28
|
+
// For every (box, side), list the edge ends that sit there, sorted by where the other end is.
|
|
29
|
+
const ends = new Map();
|
|
30
|
+
for (const pick of picks) {
|
|
31
|
+
for (const start of [true, false]) {
|
|
32
|
+
const key = (start ? pick.from : pick.to) + ':' + (start ? pick.sa : pick.sb);
|
|
33
|
+
if (!ends.has(key))
|
|
34
|
+
ends.set(key, []);
|
|
35
|
+
ends.get(key).push({ pick, start });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const anchor = new Map();
|
|
39
|
+
for (const [key, list] of ends) {
|
|
40
|
+
const tip = tips.has(key.slice(0, key.lastIndexOf(':')));
|
|
41
|
+
const side = list[0].start ? list[0].pick.sa : list[0].pick.sb;
|
|
42
|
+
const horiz = side === 't' || side === 'b';
|
|
43
|
+
const other = (x) => {
|
|
44
|
+
const r = x.start ? x.pick.b : x.pick.a;
|
|
45
|
+
return horiz ? cx(r) : cy(r);
|
|
46
|
+
};
|
|
47
|
+
list.sort((p, q) => other(p) - other(q)); // stable: ties keep declaration order
|
|
48
|
+
list.forEach((x, i) => {
|
|
49
|
+
const r = x.start ? x.pick.a : x.pick.b;
|
|
50
|
+
const f = tip ? 0.5 : (i + 1) / (list.length + 1);
|
|
51
|
+
const pt = side === 'l'
|
|
52
|
+
? { x: r.x, y: r.y + r.h * f }
|
|
53
|
+
: side === 'r'
|
|
54
|
+
? { x: r.x + r.w, y: r.y + r.h * f }
|
|
55
|
+
: side === 't'
|
|
56
|
+
? { x: r.x + r.w * f, y: r.y }
|
|
57
|
+
: { x: r.x + r.w * f, y: r.y + r.h };
|
|
58
|
+
anchor.set(x.pick.id + (x.start ? ':s' : ':e'), pt);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
// The four points travel with the path string: `flowfig check` samples the curve, and nothing has to parse `d`.
|
|
62
|
+
const drawn = (id, curve, mid) => {
|
|
63
|
+
const [s, c1, c2, e] = curve;
|
|
64
|
+
return { id, d: `M ${s.x} ${s.y} C ${c1.x} ${c1.y}, ${c2.x} ${c2.y}, ${e.x} ${e.y}`, mid, curve };
|
|
65
|
+
};
|
|
66
|
+
return picks.map((p) => {
|
|
67
|
+
const s = anchor.get(p.id + ':s'), e = anchor.get(p.id + ':e');
|
|
68
|
+
if (p.around) {
|
|
69
|
+
// ponytail: arcs 50px past the two ends' boxes; a taller box in between can still be crossed.
|
|
70
|
+
const y = p.around === 'above' ? Math.min(p.a.y, p.b.y) - 50 : Math.max(p.a.y + p.a.h, p.b.y + p.b.h) + 50;
|
|
71
|
+
return drawn(p.id, [s, { x: s.x, y }, { x: e.x, y }, e], { x: (s.x + e.x) / 2, y: (s.y + 6 * y + e.y) / 8 });
|
|
72
|
+
}
|
|
73
|
+
const horiz = p.sa === 'l' || p.sa === 'r';
|
|
74
|
+
const k = (horiz ? Math.abs(e.x - s.x) : Math.abs(e.y - s.y)) / 2;
|
|
75
|
+
const sign = p.sa === 'r' || p.sa === 'b' ? 1 : -1;
|
|
76
|
+
const c1 = horiz ? { x: s.x + sign * k, y: s.y } : { x: s.x, y: s.y + sign * k };
|
|
77
|
+
const c2 = horiz ? { x: e.x - sign * k, y: e.y } : { x: e.x, y: e.y - sign * k };
|
|
78
|
+
return drawn(p.id, [s, c1, c2, e], { x: (s.x + e.x) / 2, y: (s.y + e.y) / 2 });
|
|
79
|
+
});
|
|
80
|
+
}
|
package/dist/guide.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
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.\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. Shorten labels, or split the figure. Use more steps in one figure before\n you make a second figure. Do not change `--width` to pass the check: the 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\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 check line, exactly as the command printed it, and whether 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| `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\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? }`.\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.\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 --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";
|
|
3
|
+
/** The short instruction text that `flowfig init` writes for each coding agent. */
|
|
4
|
+
export declare const AGENT_TEXT = "# Diagrams with flowfig\n\nUse flowfig when the user wants a diagram of how something works: 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 does not draw class or ER diagrams, Gantt charts or charts of numbers. For those, tell the user so, suggest Mermaid\n(`classDiagram`, `erDiagram`, `gantt`), and 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.\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`. Fix every fault by\n changing the layout first (rows, `around`, the gap). Never remove a fact to pass the check; if you must remove one, name it\n in the reply. If `small-text` appears, split the figure; do not change `--width`.\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.\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 check line exactly as the command printed it.\n";
|
|
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 flowchart; when the user pastes a Mermaid flowchart, stateDiagram or sequenceDiagram to convert; or when the user asks for a class, ER or Gantt diagram.";
|
package/dist/guide.js
ADDED
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
// The texts that `flowfig docs` and `flowfig init` print or write. Plain strings, so they ship in dist/.
|
|
2
|
+
/** The full guide, as Markdown. `flowfig docs` prints it. */
|
|
3
|
+
export const GUIDE = `# flowfig guide
|
|
4
|
+
|
|
5
|
+
flowfig draws animated flow figures. A figure has boxes, the edges between the boxes, and steps. In each step, a packet moves along
|
|
6
|
+
the 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
|
|
7
|
+
posts. A figure is about 5 to 50 kB.
|
|
8
|
+
|
|
9
|
+
You write a JSON spec. You never write SVG by hand. The command \`npx flowfig\` checks the spec and renders it.
|
|
10
|
+
|
|
11
|
+
## What flowfig draws
|
|
12
|
+
|
|
13
|
+
A spec has three forms.
|
|
14
|
+
|
|
15
|
+
- The map (the default). The map shows the boxes and the edges. A packet moves along an edge in each beat.
|
|
16
|
+
- The map with a rail (\`"rail": true\`). The rail is a lifeline diagram under the map. It has one row for each message.
|
|
17
|
+
- 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.
|
|
18
|
+
|
|
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
|
+
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\`.
|
|
22
|
+
|
|
23
|
+
## Scope: what flowfig draws and what it does not
|
|
24
|
+
|
|
25
|
+
flowfig draws how something works: parts, the messages between them, and the order of the messages.
|
|
26
|
+
|
|
27
|
+
| The user asks for | Draw |
|
|
28
|
+
| ------------------------------------------ | ------------------------------------------------------------------------------------------ |
|
|
29
|
+
| An architecture, a data flow, a pipeline | The map. Group parts by service, network or trust boundary. \`store\` for data at rest. |
|
|
30
|
+
| A request lifecycle, a call chain | The map with \`"rail": true\`. One message per hop, with its real payload in \`data\`. |
|
|
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 each end state, for example with \`sub: "end state"\`. |
|
|
33
|
+
| A flowchart with branches | \`shape: "decision"\` for each branch. One step per path. |
|
|
34
|
+
|
|
35
|
+
flowfig does not draw class or ER diagrams (fields, types, cardinality), Gantt charts, timelines with dates, charts of numbers,
|
|
36
|
+
or mind maps. If the user asks for one of these, say that flowfig does not draw it, suggest Mermaid (\`classDiagram\`,
|
|
37
|
+
\`erDiagram\`, \`gantt\`), and draw nothing with flowfig.
|
|
38
|
+
|
|
39
|
+
## Workflow
|
|
40
|
+
|
|
41
|
+
### 1. Pick the scope
|
|
42
|
+
|
|
43
|
+
If 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
|
|
44
|
+
structure view. If the user asks for the whole system, draw one top view with groups, or a set of figures that together cover
|
|
45
|
+
every part. Keep each figure to 12 boxes or fewer.
|
|
46
|
+
|
|
47
|
+
### 2. Write the fact list
|
|
48
|
+
|
|
49
|
+
Before the spec, write a list of the facts that the figure must show. Take each fact from the code and from its wiring: config
|
|
50
|
+
files, compose files, route tables and queue bindings (or from the pasted Mermaid). Give each fact its \`file:line\`:
|
|
51
|
+
|
|
52
|
+
- every part (service, function, store, queue, external system);
|
|
53
|
+
- every call, in order, written as \`caller → callee: payload (file:line of the call)\`. The edge in the spec goes from that caller
|
|
54
|
+
to that callee;
|
|
55
|
+
- every call that does not wait for an answer (fire and forget, a queue, a webhook, a callback), and every consumer of each queue
|
|
56
|
+
or topic;
|
|
57
|
+
- every branch and every error path (a rejected input, a retry, a dead-letter path);
|
|
58
|
+
- every end state.
|
|
59
|
+
|
|
60
|
+
If the code does not show a fact, leave the fact out. Do not guess a part, a name or an order.
|
|
61
|
+
|
|
62
|
+
### 3. Write the spec
|
|
63
|
+
|
|
64
|
+
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
|
+
real example data from the code or its tests. Keep each fact that you leave out, with the reason, for the reply.
|
|
66
|
+
|
|
67
|
+
Mermaid mapping:
|
|
68
|
+
|
|
69
|
+
| Mermaid | flowfig |
|
|
70
|
+
| ---------------------------------------- | ------------------------------------------------------------------ |
|
|
71
|
+
| \`participant\` | a box |
|
|
72
|
+
| \`A->>B: text\` | an edge from A to B, and a hop with \`data: "text"\` |
|
|
73
|
+
| \`B-->>A: text\` (a reply) | a hop on the same edge with \`back: true\` |
|
|
74
|
+
| \`A-)B: text\` (async) | a hop with \`async: true\` |
|
|
75
|
+
| \`par ... and ... end\` | the hops of all branches in one beat |
|
|
76
|
+
| \`alt\` / \`opt\` | one step per path |
|
|
77
|
+
| \`stateDiagram\` states and transitions | boxes, and edges labeled with the event |
|
|
78
|
+
|
|
79
|
+
### 4. Render, then fix
|
|
80
|
+
|
|
81
|
+
\`\`\`bash
|
|
82
|
+
npx flowfig - out.svg <<'SPEC'
|
|
83
|
+
{ "props": { "layout": ..., "edges": [...], "steps": [...] } }
|
|
84
|
+
SPEC
|
|
85
|
+
\`\`\`
|
|
86
|
+
|
|
87
|
+
The quoted \`<<'SPEC'\` heredoc passes the JSON with no change. The command checks the spec first. If the check finds an error, the
|
|
88
|
+
command writes no SVG and lists the faults. Fix each fault and render again.
|
|
89
|
+
|
|
90
|
+
- Fix a layout fault by changing the layout first: put parts in rows or columns, route an edge \`around\`, or change a gap.
|
|
91
|
+
Never remove a fact from the fact list to pass the check. If you must remove one, name it in the reply.
|
|
92
|
+
- If \`small-text\` appears, the figure is too wide. Shorten labels, or split the figure. Use more steps in one figure before
|
|
93
|
+
you make a second figure. Do not change \`--width\` to pass the check: the reader sees the figure at the real page width.
|
|
94
|
+
- Fix every other warning, or tell the user why it stays.
|
|
95
|
+
- Do not use \`--no-check\` to hide a fault.
|
|
96
|
+
|
|
97
|
+
### 5. Read the figure back
|
|
98
|
+
|
|
99
|
+
Run \`npx flowfig --spec out.svg\`. Compare the spec with the fact list. Check that each edge goes from the caller to the callee
|
|
100
|
+
that its fact names. Add each fact that is missing, fix each wrong edge, and render again.
|
|
101
|
+
|
|
102
|
+
### 6. Look at the SVG
|
|
103
|
+
|
|
104
|
+
The check estimates the text width, so it cannot see everything. If you can open a browser, open the SVG and take a
|
|
105
|
+
screenshot. Wait a few seconds and take a second screenshot to see a later beat. If you cannot open a browser, write "not
|
|
106
|
+
looked 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
|
|
107
|
+
with \`python3 -m http.server\`.
|
|
108
|
+
|
|
109
|
+
### 7. Write the reply
|
|
110
|
+
|
|
111
|
+
The reply has these parts, in this order:
|
|
112
|
+
|
|
113
|
+
1. the path of each SVG;
|
|
114
|
+
2. what each figure shows: the parts and the steps. Copy the counts from the \`figure:\` line of the check output. Copy every name
|
|
115
|
+
from the read-back spec. Never count from memory;
|
|
116
|
+
3. the scope: the flow you drew, why, and the other flows that exist;
|
|
117
|
+
4. what the figure leaves out, and why;
|
|
118
|
+
5. the check line, exactly as the command printed it, and whether you looked at the SVG.
|
|
119
|
+
|
|
120
|
+
To change an SVG later, print its spec with \`--spec\`, change the spec, and render again.
|
|
121
|
+
|
|
122
|
+
## Spec reference
|
|
123
|
+
|
|
124
|
+
\`props\` has these fields.
|
|
125
|
+
|
|
126
|
+
| Field | Type | Meaning |
|
|
127
|
+
| ---------- | ----------------------- | ---------------------------------------------------------------------------------------------- |
|
|
128
|
+
| \`layout\` | group | The boxes and how they line up. Required. |
|
|
129
|
+
| \`edges\` | edge[] | The arrows between the boxes. Required. |
|
|
130
|
+
| \`steps\` | step[] | The stories the figure tells. With no steps, the figure is a still map. |
|
|
131
|
+
| \`rail\` | \`true\` or \`"only"\` | Draw the steps as a lifeline rail under the map. \`"only"\` draws the rail without the map. |
|
|
132
|
+
| \`speed\` | number | Milliseconds a packet takes to cross one edge. Default: 900. |
|
|
133
|
+
| \`theme\` | object | Colors: \`accent\`, \`fg\`, \`muted\`, \`bg\`, \`surface\`, \`border\`, \`font\`. Each color you omit keeps its built-in value. |
|
|
134
|
+
|
|
135
|
+
### layout
|
|
136
|
+
|
|
137
|
+
The layout is a tree. A group has \`children\` and these optional fields.
|
|
138
|
+
|
|
139
|
+
- \`id\`: a name that an edge can use to reach the group as a whole.
|
|
140
|
+
- \`label\`: the title on the frame. Only a group with a \`label\` gets a frame.
|
|
141
|
+
- \`direction\`: \`"row"\` (the default) or \`"column"\`.
|
|
142
|
+
- \`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).
|
|
143
|
+
- \`align\`: \`"start"\`, \`"center"\` or \`"end"\`. This sets where the children line up across the direction.
|
|
144
|
+
|
|
145
|
+
Every other item is a box.
|
|
146
|
+
|
|
147
|
+
| Box field | Meaning |
|
|
148
|
+
| --------- | --------------------------------------------------------------------------------------------------------- |
|
|
149
|
+
| \`id\` | Required. The name that edges and steps use. It must be unique in the figure. |
|
|
150
|
+
| \`label\` | Required. The title in the box. |
|
|
151
|
+
| \`sub\` | A smaller line under the label. |
|
|
152
|
+
| \`shape\` | \`"box"\` (default), \`"decision"\` (a diamond) or \`"store"\` (a database cylinder for data at rest). |
|
|
153
|
+
| \`width\` | Width in px. This overrides the width that the layout picks. |
|
|
154
|
+
| \`lines\` | The least number of text lines that a content card keeps. The card still grows to fit its content. |
|
|
155
|
+
|
|
156
|
+
### edges
|
|
157
|
+
|
|
158
|
+
An edge has these fields.
|
|
159
|
+
|
|
160
|
+
- \`id\`: the name that steps use. Default: \`from->to\`.
|
|
161
|
+
- \`from\` and \`to\`: the \`id\` of a box or a group.
|
|
162
|
+
- \`label\`: text on the edge, drawn as a small pill.
|
|
163
|
+
- \`around\`: \`"above"\` or \`"below"\`. This routes the edge over or under the boxes in between (loops, skip-ahead edges).
|
|
164
|
+
- \`quiet\`: if \`true\`, the SVG draws the edge only while a step uses it.
|
|
165
|
+
|
|
166
|
+
### steps
|
|
167
|
+
|
|
168
|
+
A 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
|
|
169
|
+
boxes to highlight for the whole step).
|
|
170
|
+
|
|
171
|
+
\`flow\` is a list of beats. A beat is one of these:
|
|
172
|
+
|
|
173
|
+
- an edge id (a string);
|
|
174
|
+
- an array of edge ids, which run at the same time;
|
|
175
|
+
- an object \`{ edges?, say?, show?, light?, ms? }\`. A beat with no \`edges\` is a pause.
|
|
176
|
+
|
|
177
|
+
The beat fields:
|
|
178
|
+
|
|
179
|
+
- \`edges\`: an edge id, a hop object, or an array of these. A hop object is \`{ edge, back?, data?, async? }\`.
|
|
180
|
+
- \`back: true\` runs the packet from the \`to\` box to the \`from\` box.
|
|
181
|
+
- \`data\` is a small card that moves with the packet.
|
|
182
|
+
- \`async: true\` marks a message that does not wait for an answer. The rail draws it dashed, with an \`async\` tag.
|
|
183
|
+
- \`say\`: the caption for the beat.
|
|
184
|
+
- \`show\`: \`{ boxId: [row, ...] }\`. This fills the content card of each named box. The card keeps the rows until the step ends.
|
|
185
|
+
- \`light\`: ids of boxes to highlight for this beat.
|
|
186
|
+
- \`ms\`: how long the beat lasts. Default: the time one packet needs to cross an edge.
|
|
187
|
+
|
|
188
|
+
A row of a content card is \`{ tag?, tone?, text, meta?, mark?, mono? }\`.
|
|
189
|
+
|
|
190
|
+
- \`tag\`: a short colored label at the start of the line.
|
|
191
|
+
- \`tone\`: the color of the tag: \`blue\` (default), \`purple\`, \`green\`, \`orange\` or \`gray\`.
|
|
192
|
+
- \`text\`: the main text.
|
|
193
|
+
- \`meta\`: muted text after the main text.
|
|
194
|
+
- \`mark\`: a mark at the right end of the line, such as a check or "new".
|
|
195
|
+
- \`mono\`: if \`true\`, the text uses a monospace font.
|
|
196
|
+
|
|
197
|
+
## Content rules
|
|
198
|
+
|
|
199
|
+
- Give every box a stable \`id\`.
|
|
200
|
+
- 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.
|
|
201
|
+
- Keep one clear main path, left to right. Put side parts in a \`column\` group.
|
|
202
|
+
- Use \`quiet: true\` on a long edge that crosses the picture.
|
|
203
|
+
- Keep an SVG to one or two steps. The SVG plays every step in a loop, with no controls.
|
|
204
|
+
- Use the React player, \`<Flow {...props} />\` from \`flowfig\`, for a page that needs tabs, pause or hover.
|
|
205
|
+
|
|
206
|
+
## Example
|
|
207
|
+
|
|
208
|
+
\`\`\`json
|
|
209
|
+
{
|
|
210
|
+
"props": {
|
|
211
|
+
"layout": {
|
|
212
|
+
"children": [
|
|
213
|
+
{ "id": "client", "label": "Browser" },
|
|
214
|
+
{ "id": "api", "label": "API Server" },
|
|
215
|
+
{ "id": "db", "label": "Database", "shape": "store" }
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
"edges": [
|
|
219
|
+
{ "id": "req", "from": "client", "to": "api", "label": "GET /users/42" },
|
|
220
|
+
{ "id": "q", "from": "api", "to": "db", "label": "SELECT" }
|
|
221
|
+
],
|
|
222
|
+
"steps": [
|
|
223
|
+
{
|
|
224
|
+
"label": "read",
|
|
225
|
+
"flow": [
|
|
226
|
+
{ "edges": { "edge": "req", "data": "GET /users/42" }, "say": "The browser asks for user 42." },
|
|
227
|
+
{ "edges": "q", "show": { "db": [{ "tag": "row", "tone": "gray", "text": "Ada Lovelace" }] }, "say": "The API server reads the row." },
|
|
228
|
+
{ "edges": { "edge": "req", "back": true, "data": "200 OK" }, "say": "The API server sends the user." }
|
|
229
|
+
]
|
|
230
|
+
}
|
|
231
|
+
]
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
\`\`\`
|
|
235
|
+
|
|
236
|
+
## Commands
|
|
237
|
+
|
|
238
|
+
\`\`\`bash
|
|
239
|
+
npx flowfig - out.svg < spec.json # render a spec from stdin
|
|
240
|
+
npx flowfig spec.json out.svg # render a spec file
|
|
241
|
+
npx flowfig figure.ts out.svg # render a module whose default export is a spec
|
|
242
|
+
npx flowfig check <input> [--json] # list the faults. The input can also be an SVG that flowfig wrote.
|
|
243
|
+
npx flowfig --spec out.svg # print the spec that an SVG carries
|
|
244
|
+
npx flowfig docs # print this guide
|
|
245
|
+
npx flowfig init # write these instructions for the coding agents of a repo
|
|
246
|
+
\`\`\`
|
|
247
|
+
|
|
248
|
+
A render checks first and writes nothing on an error. \`--strict\` makes warnings errors. \`--width\` sets the page width.
|
|
249
|
+
\`--min-text\` sets the smallest text that the reader should get. \`--no-check\` skips the check.
|
|
250
|
+
`;
|
|
251
|
+
/** The short instruction text that `flowfig init` writes for each coding agent. */
|
|
252
|
+
export const AGENT_TEXT = `# Diagrams with flowfig
|
|
253
|
+
|
|
254
|
+
Use flowfig when the user wants a diagram of how something works: an architecture, a data flow or pipeline, a request lifecycle,
|
|
255
|
+
a call sequence, a state lifecycle, or a flowchart. flowfig also converts a pasted Mermaid flowchart, \`stateDiagram\` or
|
|
256
|
+
\`sequenceDiagram\`.
|
|
257
|
+
|
|
258
|
+
flowfig does not draw class or ER diagrams, Gantt charts or charts of numbers. For those, tell the user so, suggest Mermaid
|
|
259
|
+
(\`classDiagram\`, \`erDiagram\`, \`gantt\`), and draw nothing with flowfig.
|
|
260
|
+
|
|
261
|
+
1. Run \`npx flowfig docs\` and read it. If the command fails, stop: tell the user that flowfig is not available, give them
|
|
262
|
+
\`npm install --save-dev flowfig\`, and draw nothing with another tool.
|
|
263
|
+
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
|
|
264
|
+
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
|
|
265
|
+
that together cover every part. Keep each figure to 12 boxes or fewer.
|
|
266
|
+
3. Write a fact list from the code and from its wiring (config, compose, route and queue files). Write each call as
|
|
267
|
+
\`caller → callee: payload (file:line of the call)\`, in order. Include each async call and every consumer of a queue, each
|
|
268
|
+
branch and error path, and each end state. Leave out what the code does not show.
|
|
269
|
+
4. Write the spec from the fact list, with the real names and data. Render it with \`npx flowfig - out.svg\`. Fix every fault by
|
|
270
|
+
changing the layout first (rows, \`around\`, the gap). Never remove a fact to pass the check; if you must remove one, name it
|
|
271
|
+
in the reply. If \`small-text\` appears, split the figure; do not change \`--width\`.
|
|
272
|
+
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
|
|
273
|
+
fact names. Fix each gap.
|
|
274
|
+
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.
|
|
275
|
+
Never report a look that you did not do.
|
|
276
|
+
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;
|
|
277
|
+
the check line exactly as the command printed it.
|
|
278
|
+
`;
|
|
279
|
+
/** The description of the Claude skill: the words that make the agent load it. */
|
|
280
|
+
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 flowchart; when the user pastes a Mermaid flowchart, stateDiagram or sequenceDiagram to convert; or when the user asks for a class, ER or Gantt diagram.';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type FlowProps } from './model.ts';
|
|
2
|
+
export type * from './model.ts';
|
|
3
|
+
export { LIGHT, DARK } from './model.ts';
|
|
4
|
+
/**
|
|
5
|
+
* The interactive player for one figure: tabs for the steps, play and pause, speed, hover and full screen.
|
|
6
|
+
* Give it a `FlowProps` spec. Use `toSvg` from `flowfig/svg` for a static animated SVG instead.
|
|
7
|
+
*/
|
|
8
|
+
export declare function Flow({ layout, edges, steps, theme, speed, autoplay, check, rail: withRail }: FlowProps): import("react").JSX.Element;
|