Skip to content

Commit db68f68

Browse files
committed
docs(diagrams): what was built, where it departs from the spec, and how to check it
docs/RICH-DIAGRAMS.md is the implementation record for the Rich Diagrams spec (2026-10-04), under the spec's own section names, because the code cites them. Per section: the rule, what the code does about it, and each place the build chose differently, with the reason, so the choice can be argued again. A status per requirement; the known limits with their measured rates; what is verified and what is not — no live model has drawn a diagram yet, and the eval has not been run. It is not the spec. The spec is a private document; its links, and one line about pricing, are left out of a public repository. CLAUDE.md gains the feature's entry and three conventions that cost time to learn: the shared diagram modules are pasted into a script block and must never spell a script tag or an HTML comment opener; the host suites' brace matcher cannot read a backtick inside a regex literal; and work in a worktree is not in the editor until it is loaded with --extensionDevelopmentPath. test/fixtures/diagrams/README.md says what each fixture is for, and how to add a real broken spec to the corpus.
1 parent 822cfc2 commit db68f68

3 files changed

Lines changed: 527 additions & 0 deletions

File tree

‎CLAUDE.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ big-file mode badge. Files: extension.js + fileOps/lineOps/columnOps/encodingEol
164164
- `aiEdit.js` — **edit-with-diff**: select code → `Cmd+Alt+E` → instruction → side-by-side diff → ✓ Keep / ✗ Discard
165165
buttons on the diff toolbar (gated on `levelcode.ai.diffActive`).
166166
- `inlineReview.js` — **dead code** (an inline per-hunk Keep/Undo attempt that was reverted; nothing imports it).
167+
- `diagram/` — **rich diagrams, phase 1** (`docs/RICH-DIAGRAMS.md`). The agent calls a `render_diagram` tool with
168+
STRUCTURE only (nodes, edges, groups, one accent — never coordinates or colours); the editor validates it, lays it
169+
out in one house style and paints it in the chat, themed, with nodes that link to code. Graph JSON only — Mermaid,
170+
Vega-Lite and raw SVG are later phases and are **not built**. Not yet run in the packaged editor or against a live
171+
model; the eval (`scripts/diagram-eval.js`) exists and has not been run.
172+
- Shared UMD modules (`theme` `schema` `validate` `repair` `layout` `scene` `text` `ascii`) run in Node AND are
173+
inlined into `chat.html` by `diagram/bundle.js` under the page's existing nonce — the CSP is unchanged. Host-only:
174+
`tool` (tool + prompt block + result text), `service` (ids, the one repair pass, records, stubs), `links`,
175+
`exportCheck`, `stats`.
176+
- Repair ladder: lossless auto-fix → every error back to the model ONCE → degrade with a banner, or source + Retry.
177+
Never a blank card, never a second automatic repair. Records are stored in the session log and re-validated (not
178+
re-repaired) on reopen, by the host and by the page.
179+
- Layout is in-house (layered + orthogonal routing), **not ELK** (EPL-2.0, ~1.5 MB, no build step here);
180+
`layout.layout()` is the one swap point. The validator is a small JSON-Schema-subset interpreter, not Ajv.
181+
- Gated per run by `client.render` (`rich`|`ascii`): off via `levelcode.ai.diagrams.enabled`, or per model with
182+
`diagrams: false` in `providers/catalog.js` `CAPS`. Costs ~970 tokens of tool + prompt per request while on.
183+
- Checks: `test/diagram*.test.js` (in the gate), `scripts/diagram-browser-check.js` (real page in headless Chrome,
184+
not in the gate), `scripts/diagram-editor-check.js` (the REAL editor: a throwaway instance of the dev build with
185+
this checkout's extension and a stand-in provider), `scripts/diagram-eval.js --dry-run`. Local counters: command
186+
`AI: Diagram Statistics`.
167187

168188
## Deferred / known limits (don't waste time re-hitting these)
169189

@@ -189,4 +209,13 @@ big-file mode badge. Files: extension.js + fileOps/lineOps/columnOps/encodingEol
189209
- `// @ts-check` + JSDoc at top of JS files.
190210
- Test JS logic with `node --check` and small unit snippets before wiring into the editor.
191211
- After any change, `./scripts/run-dev.sh` to verify; package with `./scripts/build-macos.sh`.
212+
- `run-dev.sh` runs the extensions of the checkout that HAS `vscode/`. A git worktree has none, so work in a worktree
213+
is not in the editor until you load it: `./scripts/run-dev.sh --extensionDevelopmentPath=<worktree>/extensions/levelcode-ai`
214+
(from the main checkout; the dev extension replaces the built-in one). Uncommitted work is not "on the branch" —
215+
checking the branch out somewhere else gets none of it. Run it in the editor before telling anyone to try it.
192216
- Commit `extensions/`, `patches/`, `branding/`, `scripts/`, `docs/`, `PLAN.md`, `CLAUDE.md`. Never commit `vscode/`.
217+
- `extensions/levelcode-ai/diagram/` modules listed in `bundle.FILES` are pasted INTO a script block in `chat.html`.
218+
They must never contain the text of a script tag or an HTML comment opener — not even in a comment — or the block
219+
ends early; `bundle.js` refuses to build if one does. Keep them dependency-free and free of `require('vscode')`/`fs`.
220+
- Host suites slice functions out of `extension.js` with a brace matcher (`extract()` in `test/*Host.test.js`). It
221+
does not understand a backtick inside a regex literal: write `String.fromCharCode(96)` there instead.

0 commit comments

Comments
 (0)