@itsthecsguy/linework 0.1.3 → 0.2.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.
@@ -6,49 +6,49 @@ compatibility: Needs Node 20+, a Chromium-based browser (Chrome, Edge, or Playwr
6
6
 
7
7
  # Linework
8
8
 
9
- You describe the diagram as a small YAML spec. Linework does the layout, styling and rendering, and writes a `.drawio.svg`. That's a normal SVG for docs, with the editable draw.io model embedded inside it. Never write coordinates, SVG or draw.io XML yourself.
9
+ You describe the diagram as a small YAML spec. Linework does the layout, styling and rendering, and writes a `.drawio.svg`: a normal SVG for docs with the editable draw.io model inside it. Never write coordinates, SVG or draw.io XML yourself, and don't fall back to Mermaid, PlantUML or ASCII art unless the user asks for one.
10
10
 
11
- Use Linework instead of Mermaid, PlantUML or ASCII art. Write Mermaid only if the user asks for it, or if the doc lives somewhere that renders Mermaid and can't show images.
11
+ `linework` below means `npx -y @itsthecsguy/linework` (plain `linework` if it's on the PATH). Keep specs and preview PNGs in your temp directory, not in the repo. If a command fails to download, find a browser or accept an option this guide names, read `references/troubleshooting.md`.
12
12
 
13
- ## Running it
13
+ ## New diagram
14
14
 
15
- In this guide, `linework` means `npx -y @itsthecsguy/linework`. Run plain `linework` only if `command -v linework` (or `where linework` on Windows) finds it. `/tmp` stands for your temp directory (`%TEMP%` on Windows). Keep specs and preview PNGs there, not in the repo.
15
+ 1. **Look for existing diagrams.** Search for `*.drawio.svg`. If one already shows what you need, change it (next section). Save new ones where the others live, else `docs/diagrams/`.
16
+ 2. **Pick the type.** One diagram makes one point.
17
+ - `architecture`: components and how they talk.
18
+ - `flow`: a process with steps and decisions.
19
+ - `state`: the lifecycle of one thing.
20
+ - `sequence`: who calls whom, in order, for one scenario.
21
+ - `er`: tables, columns and relationships.
22
+ 3. **Write the spec**, starting from the closest file in `examples/` next to this guide: `checkout.yaml` and `platform.yaml` (architecture), `serverless-aws.yaml` and `gcp-ingest.yaml` (cloud icons), `refund-flow.yaml` and `deploy-flow.yaml` (flow), `payment-state.yaml` and `job-state.yaml` (state), `pay-sequence.yaml` and `auth-seq.yaml` (sequence), `billing-er.yaml` and `shop-er.yaml` (ER). A Mermaid block converts directly: `linework import doc.md --block 1 -o out.drawio.svg`.
23
+ 4. **Build:** `linework build /tmp/spec.yaml -o docs/diagrams/checkout.drawio.svg --png /tmp/checkout.png`
24
+ 5. **Read the output.** `spec error` lines say exactly what to fix. `check:` lists layout problems. Fix every error and the warnings that matter, then rebuild. Look at the PNG if you can view images.
25
+ 6. **Embed the `.drawio.svg`**, never the PNG: `![Checkout API charges cards through Stripe and writes orders to Postgres](diagrams/checkout.drawio.svg)`. Write alt text that says what the diagram shows in one sentence.
26
+ 7. **Tell the user** where the file is and that they can edit it by hand in draw.io (`linework edit <file>` opens it in their browser).
16
27
 
17
- If a command fails:
18
- - **The download fails** (`ENOTFOUND`, `EAI_AGAIN`, `ETIMEDOUT`, `403`): you probably have no network, often because of a sandbox. Ask the user to let the command run with network access, or to run `npm install -g @itsthecsguy/linework` themselves.
19
- - **"none was found":** no browser is installed. Run `linework install-browser`, or ask the user to install Chrome.
20
- - **"found a Chromium-based browser but it could not start":** a sandbox is blocking it. Ask the user to run `npx -y @itsthecsguy/linework install-browser` once outside the sandbox (Linework's own Chromium starts inside Codex's sandbox), or to let the command run outside the sandbox. Don't tell them to install Chrome; they already have a browser.
21
- - **An option or field is rejected that this guide says exists:** this guide may be newer or older than the installed package. Run `linework skill` to get the path of the guide that ships with the package, and read its SKILL.md. That copy always matches.
28
+ ## Changing a diagram
22
29
 
23
- Never fall back to writing SVG or draw.io XML by hand. Tell the user what failed and what they can do about it.
30
+ The `.drawio.svg` is the source of truth. Every command below keeps what is already there in place, including boxes someone moved by hand in draw.io. Only what you change moves.
24
31
 
25
- ## Workflow
32
+ For one or two changes, edit the file directly:
26
33
 
27
- 1. **Look for existing diagrams first.** Search the repo for `*.drawio.svg`. If one already shows what you need, change it (see "Editing an existing diagram") instead of drawing a new one. Save new diagrams where the existing ones live. With none yet, use `docs/diagrams/`, or the folder of the doc you're editing if the repo has no `docs/`.
28
- 2. **Decide what the diagram is for.** One diagram makes one point. Pick the type:
29
- - `architecture`: components and how they talk. Services, data stores, queues, external systems, trust boundaries.
30
- - `flow`: a process with steps and decisions.
31
- - `state`: the lifecycle of one thing, like an order, payment or job.
32
- - `sequence`: who calls whom, in what order, for one scenario.
33
- - `er`: database tables, their columns and how they relate.
34
-
35
- If the doc already has a Mermaid diagram, convert it instead of rewriting it: `linework import doc.md --block 1 -o docs/diagrams/x.drawio.svg`.
36
- 3. **Write the spec** to `/tmp/spec.yaml`, or pipe it on stdin with `-` as the file. Start from the closest file in `examples/` next to this guide:
37
- - architecture: `checkout.yaml` (small), `platform.yaml` (clients, nested groups, 17 nodes), `serverless-aws.yaml` (AWS icons), `gcp-ingest.yaml` (GCP icons)
38
- - flow: `refund-flow.yaml` (branches), `deploy-flow.yaml` (a retry loop back to an earlier step)
39
- - state: `payment-state.yaml`, `job-state.yaml` (pause/resume pairs and a self-transition)
40
- - sequence: `pay-sequence.yaml` (alt, note), `auth-seq.yaml` (loop with a nested opt)
41
- - ER: `billing-er.yaml` (small), `shop-er.yaml` (7 tables, composite keys)
42
-
43
- The `.drawio.svg` is the source of truth, so you don't need to keep the YAML.
44
- 4. **Build with a preview:**
45
- ```bash
46
- linework build /tmp/spec.yaml -o docs/diagrams/checkout.drawio.svg --png /tmp/checkout.png
47
- ```
48
- 5. **Read the output.** `spec error` lines tell you exactly what to fix. `check:` lists layout problems. Fix every `error` and the warnings that matter, then rebuild.
49
- 6. **Look at the PNG** if you can view images. Check that the diagram tells the story you meant, flows in a sensible direction and doesn't sprawl. If `check` says `too-wide`, remove `direction` (or set `TB`) or split it. If you can't view images, rely on `check` and keep the diagram small.
50
- 7. **Embed the `.drawio.svg`**, never the PNG (see "Putting it in a doc").
51
- 8. **Tell the user** where the file is, what it shows, and that they can edit it by hand in draw.io.
34
+ ```bash
35
+ linework set d.drawio.svg api.label="Checkout API v2" api.highlight=true # id.field=value; empty value clears; also theme= title= direction=
36
+ linework add d.drawio.svg "fraud: { label: Fraud check, in: vpc }" "api -> fraud: score"
37
+ linework rm d.drawio.svg cache "api -> stripe" # a box goes with its edges
38
+ ```
39
+
40
+ For a larger change, round-trip the spec. Always start from the file, never from an old copy of the spec:
41
+
42
+ ```bash
43
+ linework show d.drawio.svg > /tmp/spec.yaml # current spec, hand edits included
44
+ # edit it; keep the "# linework-base:" line at the top
45
+ linework build /tmp/spec.yaml -o d.drawio.svg --png /tmp/d.png
46
+ ```
47
+
48
+ - The `merged into the existing layout:` line says what was kept, placed, grown and rerouted. Pass it on to the user.
49
+ - If the user moved boxes by hand and left lines or labels in odd places, `linework tidy d.drawio.svg` reroutes those edges and re-places those labels. Boxes stay put.
50
+ - `--relayout` throws the layout away and starts over. Use it only if the user asks: it undoes their work.
51
+ - When the user says they finished editing in draw.io, run `show` and carry on from its output.
52
52
 
53
53
  ## Spec
54
54
 
@@ -57,184 +57,41 @@ type: architecture # architecture | flow | state | sequence | er
57
57
  title: Checkout # optional
58
58
  direction: auto # auto (default) | TB | LR | BT | RL
59
59
  theme: clean # clean (default) | soft | dark | sketch | blueprint | c4
60
- groups: # optional boxes around nodes; can nest with `in`
60
+ groups: # optional boxes around nodes; nest with `in`
61
61
  vpc: { label: Production VPC }
62
- data: { label: Data tier, in: vpc }
63
- nodes: # id: { label, kind, tech, in } (all optional)
64
- user: { label: Shopper, kind: person }
62
+ nodes: # id: { label, kind, tech, in }, all optional
65
63
  web: { label: Web app, kind: client, tech: Next.js }
66
64
  api: { label: Checkout API, tech: Go, in: vpc, highlight: true }
67
65
  queue: { label: order-events, kind: queue, tech: Kafka, in: vpc }
68
- db: { label: Orders, kind: database, tech: Postgres, in: data }
69
- stripe: { kind: external, tech: Payments API } # label defaults to "Stripe"
66
+ db: { label: Orders, kind: database, tech: Postgres, in: vpc }
67
+ stripe: { kind: external } # label defaults to "Stripe"
70
68
  edges: # "from ARROW to: label"
71
- - user -> web
72
- - web ==> api: HTTPS # ==> highlighted: the path the doc is about
69
+ - web ==> api: HTTPS # ==> highlighted: the path the doc is about
73
70
  - api -> db: SQL
74
- - api -.-> queue: OrderPlaced # -.-> async/event, dashed
71
+ - api -.-> queue: OrderPlaced # -.-> async or event, dashed
75
72
  - api -> stripe: charge
76
73
  ```
77
74
 
78
- - Ids use letters, digits, `_`, `.` and `-`. The label defaults to the id with its first letter capitalized.
79
- - Arrows: `->` call or flow, `==>` the same but highlighted, `-.->` async or event, `<->` two-way, `--` no arrowhead. Put spaces around the arrow.
80
- - `tech` is the small, quieter second line. Use it for the technology, not a description.
81
- - Node order matters a little. Layout tries to keep the declaration order, so list nodes roughly in reading order.
82
- - Quote an edge if its label contains `: ` or `#`, for example `- "api -> db: SELECT: orders"`.
83
- - Architecture nodes can carry a cloud icon: `icon: aws.lambda`, `gcp.cloud_run`, `k8s.pod`, `azure.<name>`. Run `linework icons aws lambda` to search names. Use icons when the doc is about a specific cloud; leave them off for logical diagrams.
84
- - Styles (`theme:`): use `clean` unless asked. It's minimal: white boxes, hairline borders, groups as gray grounds, IBM Plex Sans, and color only where it means something.
85
- - `soft`: borderless pastel cards, tinted by kind. For slides and docs that want color coding.
86
- - `dark`: for dark-mode docs and slides.
87
- - `sketch`: hand-drawn lines and handwriting. For early proposals ("this is a draft") and whiteboard-style explainers.
88
- - `blueprint`: blue ink on pale drafting paper, monospace. For technical deep dives that want a distinct look.
89
- - `c4`: C4-model conventions; labels each box with its element type.
90
- - Color is for meaning, so most nodes stay neutral:
91
- - `highlight: true` on a node, group or participant, or `==>` on an edge or message, makes it the first thing a reader sees. Highlight the one path or component the surrounding text is about: often one node and the 2 or 3 edges into and out of it. `build` warns when you highlight so much that nothing stands out.
92
- - `color: <name>` tints a node, group or edge to mark a category, like red for failure paths or green for what's new in this proposal. Say what the color means in the doc text. Names: `blue`, `violet`, `pink`, `red`, `orange`, `amber`, `green`, `teal`, `gray`.
93
- - Kinds `error` and `success` are red and green in every style.
94
- - An edge with a color uses the object form: `- { from: api, to: dlq, label: on failure, style: async, color: red }`.
95
-
96
- Node kinds, also listed by `linework kinds`:
75
+ - Arrows: `->` call or flow, `==>` highlighted, `-.->` async, `<->` two-way, `--` no arrowhead. Spaces around the arrow. Quote an edge whose label contains `: ` or `#`.
76
+ - List nodes and edges in reading order. Layout follows it, and an edge that points back at an earlier node is drawn as the loop.
77
+ - `tech` is the quiet second line: the technology, not a description.
78
+ - Color is for meaning. `highlight: true` or `==>` marks the one path the text is about. `color: red|green|blue|...` marks a category; say what it means in the doc.
79
+ - Cloud icons on architecture nodes: `icon: aws.lambda`, `gcp.cloud_run`, `k8s.pod`, `azure.<name>`. Search with `linework icons aws lambda`.
97
80
 
98
81
  | type | kinds (default first) |
99
82
  |---|---|
100
83
  | architecture | `service`, `person`, `client`, `function`, `database`, `cache`, `storage`, `queue`, `external` |
101
84
  | flow | `step`, `decision`, `terminal`, `data`, `error` |
102
- | state | `state`, `success`, `error` (start and end come from `[*]`) |
103
- | sequence | `service`, `person`, `client`, `function`, `database`, `queue`, `external` |
104
- | er | `entity`, `view`, `external` |
85
+ | state | `state`, `success`, `error`; start and end are `"[*] -> first"` and `"last -> [*]"`, quoted |
86
+ | sequence | `participants:` and `messages:` instead of nodes and edges; `-->` is a reply |
87
+ | er | `fields:` on nodes (`- id: uuid pk`), crow's-foot edges (`users }o--|| orgs: belongs to`) |
105
88
 
106
- Flow and state specifics:
89
+ In a flow, keep decision text to a short question and label every edge leaving it (`window -> refund: "yes"`).
107
90
 
108
- ```yaml
109
- type: flow
110
- nodes:
111
- start: { label: Refund requested, kind: terminal }
112
- window: { label: Within 30 days?, kind: decision }
113
- refund: { label: Issue refund }
114
- deny: { label: Deny with reason, kind: error }
115
- edges:
116
- - start -> window
117
- - window -> refund: "yes" # label every edge leaving a decision
118
- - window -> deny: "no"
119
- ```
91
+ ## More
120
92
 
121
- ```yaml
122
- type: state
123
- nodes:
124
- pending: {}
125
- paid: { kind: success }
126
- failed: { kind: error }
127
- edges:
128
- - "[*] -> pending" # quote edges that use [*]
129
- - pending -> paid: payment_succeeded
130
- - pending -> failed: declined
131
- - "paid -> [*]"
132
- ```
133
-
134
- Sequence diagrams use `participants` (in left-to-right order) and `messages`:
135
-
136
- ```yaml
137
- type: sequence
138
- participants:
139
- web: { label: Web app, kind: client }
140
- api: { label: Checkout API }
141
- stripe: { kind: external }
142
- messages:
143
- - web ==> api: POST /checkout # -> call; ==> highlighted call
144
- - api -> stripe: create PaymentIntent
145
- - stripe --> api: client_secret # --> reply (dashed)
146
- - api --> web: 200 OK
147
- - note over api, stripe: retried with an idempotency key
148
- - alt: # alt and par take branches
149
- - when: payment succeeded
150
- do:
151
- - stripe -.-> api: webhook # -.-> async
152
- - when: declined
153
- do:
154
- - api --> web: 402
155
- - loop: every 30s # loop, opt, critical, break take one block
156
- do:
157
- - web -> api: poll status
158
- ```
159
-
160
- Activation bars come from call/reply pairs automatically: each `a -> b` closed by a later `b --> a`. Participants take `color` and `highlight` like nodes.
161
-
162
- ER diagrams put `fields` on nodes and use Mermaid's crow's-foot notation for edges:
163
-
164
- ```yaml
165
- type: er
166
- nodes:
167
- users:
168
- fields:
169
- - id: uuid pk
170
- - org_id: uuid fk
171
- - email: text unique
172
- orgs:
173
- label: organizations
174
- fields: [ "id: uuid pk", "name: text" ]
175
- edges:
176
- - users }o--|| orgs: belongs to # many users to exactly one org
177
- ```
178
-
179
- Field flags: `pk`, `fk`, `unique`, `null`. Cardinality ends: `||` one, `|o` zero or one, `}o` / `o{` many, `}|` / `|{` one or many. Use `--` for identifying relationships, `..` for the rest.
180
-
181
- Every option and more examples are in `references/spec.md`, and full specs for each type are in `examples/`. Read `references/style-guide.md` before drawing anything non-trivial.
182
-
183
- ## Editing an existing diagram
184
-
185
- Always start from the file, never from an old copy of the spec:
186
-
187
- ```bash
188
- linework show docs/diagrams/checkout.drawio.svg > /tmp/spec.yaml # current spec, hand edits included
189
- # edit /tmp/spec.yaml; keep the "# linework-base:" line at the top
190
- linework build /tmp/spec.yaml -o docs/diagrams/checkout.drawio.svg --png /tmp/checkout.png
191
- ```
192
-
193
- If someone has arranged the diagram by hand in draw.io, `build` merges your changes into their layout instead of starting over. (For sequence diagrams, hand-placed lifeline columns stay; rows always follow message order.)
194
- - Existing nodes stay exactly where they are.
195
- - New nodes go next to the node they connect to.
196
- - Removed nodes disappear.
197
- - Groups grow to fit new members.
198
- - Only new edges, and edges whose routes went stale, get rerouted.
199
- - Their colours, label edits and notes survive.
200
-
201
- The `merged into the existing layout:` line tells you what happened. Mention it to the user.
202
-
203
- The `# linework-base:` line tells `build` your spec includes the latest hand edits. Without it, `build` won't delete shapes someone added by hand that your spec doesn't mention. It keeps them and prints a note. If you see that note, run `show` again and redo your edit from its output.
204
-
205
- `--relayout` throws the hand-made layout away and lays everything out from scratch. **Only use it if the user asks,** because it undoes their layout work.
206
-
207
- If someone moved shapes by hand and left edges crossing through boxes, `linework tidy file.drawio.svg` reroutes just the broken edges and changes nothing else.
208
-
209
- ## Putting it in a doc
210
-
211
- - Markdown (GitHub, GitLab, most renderers): `![Checkout API calls Stripe to charge cards and writes orders to Postgres](diagrams/checkout.drawio.svg)`
212
- - HTML: `<img src="diagrams/checkout.drawio.svg" alt="Checkout API calls Stripe to charge cards and writes orders to Postgres">`
213
- - Write alt text that says what the diagram shows, in one sentence, not just its title. Someone using a screen reader should get the point from it.
214
- - If you used `color:` for categories, add a sentence under the diagram saying what each color means.
215
- - Tell the user they can edit it by hand: open the file in VS Code with the "Draw.io Integration" extension, in draw.io desktop, or at app.diagrams.net. It saves back into the same file, and your later edits will keep their layout.
216
- - In a git repo, offer to run `linework git-setup` once, so `git diff` on diagrams shows readable spec changes.
217
- - Google Docs can't hold SVG. `linework publish file.drawio.svg` copies it into the user's Google Drive folder, and draw.io's Google Docs add-on inserts it from there and refreshes it after changes. Setup and the update steps are in `references/google-docs.md`; walk the user through them the first time.
218
-
219
- ## Letting the user edit
220
-
221
- If the user wants to adjust a diagram by hand, `linework edit file.drawio.svg` opens it in draw.io in their browser, served from their machine. Saving there writes the file. When they say they're done, run `show` and carry on from its output; their changes are in it.
222
-
223
- ## Commands
224
-
225
- | command | does |
226
- |---|---|
227
- | `build <spec\|-> -o out.drawio.svg [--png p.png] [--relayout]` | layout (or merge into an existing file), write, lint |
228
- | `show <file> [--geometry]` | print the spec, stamped with `linework-base` |
229
- | `tidy <file>` | reroute edges that pass through nodes; nothing else changes |
230
- | `import <file.mmd\|doc.md> [--block N] [-o out.drawio.svg]` | convert Mermaid (flowchart, state, sequence, ER) |
231
- | `icons <aws\|gcp\|k8s\|azure> [filter]` | list icon names |
232
- | `edit <file>` | open the diagram in draw.io in the user's browser; saving writes the file |
233
- | `publish <file...> [--to dir] [--pull]` | copy diagrams into Google Drive for the Docs add-on; `--pull` brings Drive edits back |
234
- | `git-setup` | make `git diff` show diagram changes as spec changes |
235
- | `render <file> -o out.png [--scale 2]` | preview image |
236
- | `check <file>` | lint only; exit 1 on errors |
237
- | `kinds [type]` | list node kinds |
238
- | `schema` | JSON Schema of the spec |
239
- | `skill` | print the path of the guide that matches the installed version |
240
- | `install-browser` | download the headless Chromium this version uses |
93
+ - `references/spec.md`: every option, sequence blocks (`alt`, `loop`, notes), ER fields and cardinalities, themes, colors.
94
+ - `references/style-guide.md`: what makes a diagram read well. Read it before anything non-trivial.
95
+ - `references/troubleshooting.md`: download, browser and sandbox failures.
96
+ - `references/google-docs.md`: putting a diagram in Google Docs with `linework publish`.
97
+ - `linework help` lists every command, including `check`, `render`, `kinds`, `schema` and `git-setup` (readable `git diff` for diagrams).
@@ -0,0 +1,11 @@
1
+ # When a command fails
2
+
3
+ `linework` in the guide means `npx -y @itsthecsguy/linework`. Run plain `linework` only if `command -v linework` (or `where linework` on Windows) finds it.
4
+
5
+ - **The download fails** (`ENOTFOUND`, `EAI_AGAIN`, `ETIMEDOUT`, `403`): there is probably no network, often because of a sandbox. Ask the user to let the command run with network access, or to run `npm install -g @itsthecsguy/linework` themselves.
6
+ - **"none was found":** no browser is installed. Run `linework install-browser`, or ask the user to install Chrome.
7
+ - **"found a Chromium-based browser but it could not start":** a sandbox is blocking it. Ask the user to run `npx -y @itsthecsguy/linework install-browser` once outside the sandbox (Linework's own Chromium starts inside Codex's sandbox), or to let the command run outside the sandbox. Don't tell them to install Chrome; they already have a browser.
8
+ - **An option or field is rejected that the guide says exists:** the guide may be newer or older than the installed package. Run `linework skill` to get the path of the guide that ships with the package, and read its SKILL.md. That copy always matches.
9
+ - **A build hangs or behaves oddly after an upgrade:** builds reuse a background process that keeps the browser running. `linework daemon stop` ends it, and `LINEWORK_NO_DAEMON=1` or `--no-daemon` runs without it.
10
+
11
+ Never fall back to writing SVG or draw.io XML by hand. Tell the user what failed and what they can do about it.