@johnz4021/illuminate 0.2.0 → 0.3.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 CHANGED
@@ -89,10 +89,12 @@ is sent anywhere. Useful for UI work and demos.
89
89
  ### Screens on the map
90
90
 
91
91
  When a flow starts from something you can see (a button, a form), Claude can put a picture of that screen on the box,
92
- with the button marked. It decides case by case; backend-only maps get none. If your app is already running on
93
- localhost, or the repo has an HTML file, illuminate screenshots it with the Chrome you already have, in a clean profile
94
- (pages behind a login show their login page, and Claude then falls back). Otherwise Claude can show an image file from
95
- the repo or a rough sketch of a component. illuminate never starts your app, and a screen is only shown if the checker
92
+ with the button marked. It decides case by case; backend-only maps get none. The usual picture is a wireframe of the
93
+ whole page, drawn from the code: its parts (top bar, sidebar, main area) with the one the step is about marked.
94
+ Nothing has to be running for that. illuminate checks that each part really belongs to the page and that its text is
95
+ in the code; where the parts sit is Claude's reading, so the wireframe says it is approximate. If your app is already
96
+ running on localhost, or the repo has an HTML file, illuminate can screenshot it instead with the Chrome you already
97
+ have, in a clean profile (pages behind a login show their login page, and Claude then falls back). illuminate never starts your app, and a screen is only shown if the checker
96
98
  can tie it to the code. Screenshots are saved under `.illuminate/screens/`.
97
99
 
98
100
  ## How it works
package/dist/cli.mjs CHANGED
@@ -2318,6 +2318,13 @@ function parseMap(input) {
2318
2318
  const edges = ids("edge", map.edges);
2319
2319
  const absences = ids("absence", map.absences);
2320
2320
  ids("tour stop", map.tour);
2321
+ const pages = new Map((map.pages ?? []).map((p) => [p.id, p]));
2322
+ ids("page", map.pages ?? []);
2323
+ for (const p of map.pages ?? []) {
2324
+ ids(`page "${p.id}" region`, p.regions);
2325
+ for (const f of [p.file, ...p.regions.map((r) => r.file)]) if (!isSafeRelativePath(f)) problems.push(`page "${p.id}": file "${f}" must be a path inside the repo`);
2326
+ if (p.regions.some((r) => r.elements.some((e) => e.proposed))) problems.push(`page "${p.id}": a page shows the screen as it is, so its elements can't be \`proposed\` (use a sketch on the proposed box for that)`);
2327
+ }
2321
2328
  const evidence = (where, item) => {
2322
2329
  if (!item.evidence.length && !isAddition(item)) problems.push(`${where}: cite at least one line of code in \`evidence\` (only a proposed addition goes without)`);
2323
2330
  for (const e of item.evidence) if (!isSafeRelativePath(e.file)) problems.push(`${where}: evidence file "${e.file}" must be a path inside the repo`);
@@ -2335,7 +2342,13 @@ function parseMap(input) {
2335
2342
  evidence(`node "${n.id}"`, n);
2336
2343
  const sc = n.screen;
2337
2344
  if (sc?.kind === "capture" && !sc.capture) problems.push(`node "${n.id}": a capture screen needs the \`capture\` id illuminate_capture returned`);
2338
- if (sc && sc.kind !== "capture" && (!sc.file || !isSafeRelativePath(sc.file))) problems.push(`node "${n.id}": a ${sc.kind} screen needs \`file\`, a path inside the repo`);
2345
+ if (sc && (sc.kind === "image" || sc.kind === "sketch") && (!sc.file || !isSafeRelativePath(sc.file))) problems.push(`node "${n.id}": a ${sc.kind} screen needs \`file\`, a path inside the repo`);
2346
+ if (sc?.kind === "wireframe") {
2347
+ const page = pages.get(sc.page ?? "");
2348
+ if (!page) problems.push(`node "${n.id}": a wireframe screen needs \`page\`, the id of one of the map's \`pages\`${sc.page ? ` (there is no page "${sc.page}")` : ""}`);
2349
+ else if (sc.region && !page.regions.some((r) => r.id === sc.region)) problems.push(`node "${n.id}": page "${page.id}" has no region "${sc.region}"`);
2350
+ if (sc.highlight && !sc.region) problems.push(`node "${n.id}": a wireframe's \`highlight\` needs the \`region\` the element is in`);
2351
+ }
2339
2352
  if (sc?.kind === "sketch" && !sc.elements) problems.push(`node "${n.id}": a sketch screen needs \`elements\``);
2340
2353
  if (!n.proposed && sc?.elements?.some((e) => e.proposed)) problems.push(`node "${n.id}": only a box that carries \`proposed\` can have proposed screen elements`);
2341
2354
  gone(`node "${n.id}"`, n);
@@ -2381,7 +2394,7 @@ function parseMap(input) {
2381
2394
  }
2382
2395
  return problems.length ? { ok: false, problems } : { ok: true, map };
2383
2396
  }
2384
- var Id, Evidence, NodeKind, EdgeKind, ScreenElement, Screen, Proposal, GitRef, Area, Node, Edge, Absence, TourStop, CodeMap, isAddition;
2397
+ var Id, Evidence, NodeKind, EdgeKind, ScreenElement, Screen, Slot, PageRegion, Page, Proposal, GitRef, Area, Node, Edge, Absence, TourStop, CodeMap, isAddition;
2385
2398
  var init_format = __esm({
2386
2399
  "packages/core/src/format.ts"() {
2387
2400
  "use strict";
@@ -2400,12 +2413,29 @@ var init_format = __esm({
2400
2413
  proposed: z.boolean().optional()
2401
2414
  });
2402
2415
  Screen = z.object({
2403
- kind: z.enum(["capture", "image", "sketch"]),
2416
+ kind: z.enum(["capture", "image", "sketch", "wireframe"]),
2404
2417
  capture: Id.optional(),
2418
+ /** For a wireframe: the id of one of the map's `pages`, and of the region of it this box is about. */
2419
+ page: Id.optional(),
2420
+ region: Id.optional(),
2405
2421
  file: z.string().min(1).optional(),
2406
2422
  elements: z.array(ScreenElement).min(1).max(12).optional(),
2407
2423
  highlight: z.string().min(1).max(80).optional()
2408
2424
  });
2425
+ Slot = z.enum(["top", "left", "main", "right", "bottom"]);
2426
+ PageRegion = z.object({
2427
+ id: Id,
2428
+ slot: Slot,
2429
+ label: z.string().min(1).max(40),
2430
+ file: z.string().min(1),
2431
+ elements: z.array(ScreenElement).max(6).default([])
2432
+ });
2433
+ Page = z.object({
2434
+ id: Id,
2435
+ name: z.string().min(1).max(60),
2436
+ file: z.string().min(1),
2437
+ regions: z.array(PageRegion).min(1).max(8)
2438
+ });
2409
2439
  Proposal = z.object({
2410
2440
  kind: z.enum(["add", "change", "remove"]),
2411
2441
  /** What would change and why, in a plain sentence. */
@@ -2479,6 +2509,8 @@ var init_format = __esm({
2479
2509
  * so the comparison stays the same after later commits.
2480
2510
  */
2481
2511
  since: GitRef.optional(),
2512
+ /** The pages boxes show as wireframes (`screen.kind: 'wireframe'`). */
2513
+ pages: z.array(Page).optional(),
2482
2514
  areas: z.array(Area).min(1),
2483
2515
  nodes: z.array(Node).min(1),
2484
2516
  edges: z.array(Edge).default([]),
@@ -2773,12 +2805,47 @@ function findOnCapture(capture2, label) {
2773
2805
  const holding = capture2.elements.filter((e) => norm(e.text).includes(want)).sort((a, b) => a.w * a.h - b.w * b.h);
2774
2806
  return holding[0] ?? null;
2775
2807
  }
2776
- function checkScreen(n, repo) {
2808
+ function checkPage(page, repo, importsOf) {
2809
+ const own = repo.read(page.file);
2810
+ if (!own.ok) return { show: null, reason: `${page.file}: ${own.reason}`, dropped: {} };
2811
+ const reached = /* @__PURE__ */ new Set([page.file]);
2812
+ for (const queue = [page.file]; queue.length && reached.size < MAX_PAGE_FILES; ) {
2813
+ for (const to of importsOf(queue.shift())) {
2814
+ if (reached.has(to)) continue;
2815
+ reached.add(to);
2816
+ queue.push(to);
2817
+ }
2818
+ }
2819
+ const dropped = {};
2820
+ const regions = [];
2821
+ for (const r of page.regions) {
2822
+ const read = repo.read(r.file);
2823
+ const missing = read.ok ? r.elements.filter((e) => !norm(read.text).includes(norm(e.text))) : [];
2824
+ if (!read.ok) dropped[r.id] = `${r.file}: ${read.reason}`;
2825
+ else if (!reached.has(r.file)) dropped[r.id] = `${r.file} isn't part of this page: ${page.file} doesn't bring it in`;
2826
+ else if (missing.length) dropped[r.id] = missing.map((e) => `"${e.text}" isn't in ${r.file}`).join("; ");
2827
+ else regions.push({ id: r.id, slot: r.slot, label: r.label, file: r.file, elements: r.elements.map((e) => ({ kind: e.kind, text: e.text })) });
2828
+ }
2829
+ if (!regions.length) return { show: null, reason: `no region of page "${page.id}" checked out: ${Object.values(dropped).join("; ")}`, dropped };
2830
+ return { show: { id: page.id, name: page.name, file: page.file, regions }, reason: null, dropped };
2831
+ }
2832
+ function checkScreen(n, repo, pageOf = () => null) {
2777
2833
  const sc = n.screen;
2778
2834
  if (!sc) return null;
2779
2835
  const fail = (...reasons) => ({ status: "unconfirmed", reasons, show: null });
2780
2836
  const cited = [...new Set(n.evidence.map((e) => e.file))];
2781
2837
  const inCitedCode = (text3) => cited.some((f) => norm(repo.text(f) ?? "").includes(norm(text3)));
2838
+ if (sc.kind === "wireframe") {
2839
+ const page = pageOf(sc.page ?? "");
2840
+ if (!page) return fail(`the map has no page "${sc.page ?? ""}"`);
2841
+ if (!page.show) return fail(page.reason ?? "the page could not be checked");
2842
+ const region = sc.region ? page.show.regions.find((r) => r.id === sc.region) : null;
2843
+ if (sc.region && !region) return fail(page.dropped[sc.region] ?? `page "${page.show.id}" has no region "${sc.region}"`);
2844
+ if (sc.highlight && !region?.elements.some((e) => norm(e.text) === norm(sc.highlight))) return fail(`the highlight "${sc.highlight}" isn't one of the elements of region "${sc.region ?? ""}"`);
2845
+ const about = cited.includes(page.show.file) || !!region && cited.includes(region.file) || !!sc.highlight && inCitedCode(sc.highlight);
2846
+ if (!about) return fail(`the code this box cites (${cited.join(", ")}) isn't part of what it marks on page "${page.show.id}"`);
2847
+ return { status: "confirmed", reasons: [], show: { kind: "wireframe", page: page.show, region: region?.id ?? null, highlight: sc.highlight ?? null } };
2848
+ }
2782
2849
  if (sc.kind === "capture") {
2783
2850
  const got = readCapture(repo.root, sc.capture ?? "");
2784
2851
  if (!got.ok) return fail(got.reason);
@@ -2811,7 +2878,7 @@ function checkScreen(n, repo) {
2811
2878
  const elements = written.map((e) => ({ kind: e.kind, text: e.text, ...text2.includes(norm(e.text)) ? {} : { proposed: true } }));
2812
2879
  return { status: "confirmed", reasons: [], show: { kind: "sketch", file, elements, highlight: sc.highlight ?? null } };
2813
2880
  }
2814
- var SCREENS_DIR, IMAGE_TYPES, MAX_IMAGE_BYTES, CAPTURE_ID, CapturedElement, Capture, norm, capturePaths;
2881
+ var SCREENS_DIR, IMAGE_TYPES, MAX_IMAGE_BYTES, CAPTURE_ID, CapturedElement, Capture, norm, capturePaths, MAX_PAGE_FILES;
2815
2882
  var init_screens = __esm({
2816
2883
  "packages/core/src/screens.ts"() {
2817
2884
  "use strict";
@@ -2846,6 +2913,7 @@ var init_screens = __esm({
2846
2913
  record: path3.join(root, SCREENS_DIR, `${id}.json`),
2847
2914
  image: path3.join(root, SCREENS_DIR, `${id}.png`)
2848
2915
  });
2916
+ MAX_PAGE_FILES = 600;
2849
2917
  }
2850
2918
  });
2851
2919
 
@@ -2867,8 +2935,16 @@ function check(map, root, options = {}) {
2867
2935
  const absences = {};
2868
2936
  for (const a of map.absences) absences[a.id] = checkAbsence(a, repo, files());
2869
2937
  const screens = {};
2938
+ const pageChecks = /* @__PURE__ */ new Map();
2939
+ const pageOf = (id) => {
2940
+ if (!pageChecks.has(id)) {
2941
+ const page = map.pages?.find((p) => p.id === id);
2942
+ pageChecks.set(id, page ? checkPage(page, repo, (file) => now.facts.get(file)?.imports.map((i) => i.to).filter((to) => !to.startsWith("vendor:")) ?? []) : null);
2943
+ }
2944
+ return pageChecks.get(id) ?? null;
2945
+ };
2870
2946
  for (const n of map.nodes) {
2871
- const sc = checkScreen(n, repo);
2947
+ const sc = checkScreen(n, repo, pageOf);
2872
2948
  if (sc) screens[n.id] = sc;
2873
2949
  }
2874
2950
  const tour = {};
@@ -3557,7 +3633,7 @@ ${missing}`] : [],
3557
3633
  '- If they ask what a change would look like, how you would do something, or for a plan, without asking you to make it: draw it on the map as proposals (see Proposals). New boxes and arrows go in `add` with `proposed`; for a box or arrow already on the map that would change or go, put `{ "id": "<its id>", "proposed": { "kind": "change" | "remove", "note": "\u2026" } }` in `propose`. Say in the answer what the proposal is; nothing is edited.',
3558
3634
  "- If they ask you to make a change, don't edit (you can't). Propose a `fix`: illuminate shows it to them on the map, and if they approve, illuminate applies exactly your edits and re-checks the map. So describe it as a proposal waiting for their approval, never as something for them to apply by hand.",
3559
3635
  "- The `fix`: `summary` in plain words; `edits` as exact replacements (`find` copied exactly from the file, occurring once; `replace` is the new text); `creates` for new files. If the fix creates a connection between two boxes, fill `connects` with `from`, `to`, a short `label`, and `evidenceFile` + `evidenceText` (text that will appear in the new code). Keep fixes small and in the style of the surrounding code.",
3560
- '- When the question is about what the person sees at a step ("what does this look like?", "where is that button?"), answer with a picture: put `{ "node": "<box id>", "screen": { \u2026 } }` in `screens`, for a box already on the map or one in `add` (see Screens below). Otherwise leave `screens` out: most questions don\'t need one.',
3636
+ '- When the question is about what the person sees at a step ("what does this look like?", "where is that button?"), answer with a picture: put `{ "node": "<box id>", "screen": { \u2026 } }` in `screens`, for a box already on the map or one in `add` (see Screens below). In an answer a wireframe can only use a page already in the map\'s `pages`; when the map has no page for it, a sketch of the component will do. Otherwise leave `screens` out: most questions don\'t need one.',
3561
3637
  "",
3562
3638
  ...EVIDENCE_RULES,
3563
3639
  "",
@@ -3603,7 +3679,7 @@ var init_prompts = __esm({
3603
3679
  '- Leave out what goes on behind the screen: no boxes for routes, requests, functions, jobs, database writes or other services. When several of those sit between two screens, they are one arrow ("pays, and lands on"), and that arrow cites the code that does it. A step that happens outside the app is a box only if the person sees it (a payment page, an email they get), cited at the line that sends them there or sends it.',
3604
3680
  `- A wait is part of the journey: when the next thing the person sees comes later (an email after a nightly job, an order shipped after approval), say so on the arrow in their terms ("a day later, gets"), and don't draw the job.`,
3605
3681
  "- Each box and arrow still cites the code that makes it so: the component, the handler, the redirect.",
3606
- "- Give every screen box a `screen` (see Screens), so the journey can be followed in pictures. Here more than two is right.",
3682
+ "- Show where each step happens: define the pages the journey goes through once, in `pages`, and give each screen box a wireframe of its page with its own part marked (see Screens). Several boxes usually share one page. A box whose page can't be drawn usefully (nothing recognisable on it, or it isn't in this repo) gets no `screen`: no picture is better than a thin one.",
3607
3683
  "- Where the journey stops short (a button that leads nowhere, a result with no screen, nothing ever telling the person what happened), that is a break: record it as an absence.",
3608
3684
  "- The walkthrough is told as the person's experience too, one stop per screen."
3609
3685
  ];
@@ -3628,12 +3704,15 @@ var init_prompts = __esm({
3628
3704
  "- The walkthrough says what changed first, then follows the changed path in the order things happen."
3629
3705
  ];
3630
3706
  SCREEN_RULES = [
3631
- "## Screens (`screen` on a box; optional, and your call)",
3632
- "- A picture of what the person sees can ground a map for people who don't read code. Add one where the flow touches the screen and seeing it helps: usually the box where it starts (the button or form), sometimes where a result appears. For backend-only questions, add none. One or two per map is plenty.",
3633
- '- `{ "kind": "capture", "capture": "<id>", "highlight": "<label>" }`: a real screenshot. Only if you have the illuminate_capture tool: it screenshots a page already running on this machine or an HTML file in the repo, and returns the id. Look at the image first, and don\'t use one that shows a login page, an error or the wrong state. Never start the app yourself.',
3707
+ "## Screens (`pages` on the map, `screen` on a box; optional, and your call)",
3708
+ "- A picture of where a step happens on the screen can ground a map for people who don't read code. Add one where the flow touches the screen and seeing it helps: usually the box where it starts (the button or form), sometimes where a result appears. For backend-only questions, add none.",
3709
+ '- The usual picture is a wireframe of the whole page, with the part the box is about marked. Define each page once, in the map\'s `pages`: `{ "id": "\u2026", "name": "Patient page", "file": "<the page\'s own component or template>", "regions": [ \u2026 ] }`.',
3710
+ '- A region is one visible part of the page: `{ "id": "\u2026", "slot": "top" | "left" | "main" | "right" | "bottom", "label": "Top bar", "file": "<the file it comes from>", "elements": [{ "kind": "heading|button|field|link|text|image", "text": "\u2026" }] }`. Give the 3\u20136 regions a person would recognise the page by, not only the one the step uses. Put each in the slot where it appears on screen, going by the markup and the styles (a bar across the top is `top`, a sidebar is `left` or `right`, the content is `main`). `elements`: up to 6 of the most recognisable things in the region, in the order they appear, each `text` copied exactly from that region\'s file; a region may have none.',
3711
+ '- Then on a box: `"screen": { "kind": "wireframe", "page": "<page id>", "region": "<region id>", "highlight": "<text of one element in that region>" }`. Boxes that happen on the same page use the same page, each marking its own region and element.',
3712
+ "- A program checks every page: a region's `file` must be the page's `file` or one it imports (directly or through other files), every element's text must be in its region's file, and the box must cite the page's code or the code the marked element is in. A region that fails is left off; where regions sit can't be checked, so read the layout from the code and don't invent parts.",
3713
+ '- `{ "kind": "capture", "capture": "<id>", "highlight": "<label>" }`: a real screenshot, in place of a wireframe, when a page is already running on this machine. Only if you have the illuminate_capture tool: it screenshots a running page or an HTML file in the repo, and returns the id. Look at the image first, and don\'t use one that shows a login page, an error or the wrong state. Never start the app yourself.',
3634
3714
  '- `{ "kind": "image", "file": "<path>" }`: an image file in the repo (an icon, a sprite) that the box\'s cited code names.',
3635
- '- `{ "kind": "sketch", "file": "<markup file>", "elements": [{ "kind": "heading|button|field|link|text|image", "text": "\u2026" }], "highlight": "<one element\'s text>" }`: a rough wireframe of the visible things in a component or template, top to bottom, at most 12. Use it when there is no screenshot to take. Copy each `text` exactly from the file.',
3636
- "- A program checks screens too: a capture's `highlight` must be a label visible on it and appear in the code the box cites; every sketch element must be in its file. A screen that fails is left out; the box stays."
3715
+ '- `{ "kind": "sketch", "file": "<markup file>", "elements": [ \u2026 ], "highlight": "<one element\'s text>" }`: the visible things in one component, as a list. Only for a proposal (see Proposals): it can show elements that aren\'t there yet.'
3637
3716
  ];
3638
3717
  TOUR_RULES = [
3639
3718
  "## Walkthrough (`tour`, written last)",
@@ -5327,7 +5406,7 @@ var init_channel = __esm({
5327
5406
  '- A map can show a change that was made: "what did you just change?", "what did the last commit do?". The request explains how. You draw the code as it is now and name the commit to compare with; illuminate works out from the two versions what is new, different or gone. Use it when the person wants to see what a task changed.',
5328
5407
  "- illuminate gives you work as requests in tool results. Each request says what to do and the JSON to return. Explore the code with Read, Grep and Glob, then call illuminate_submit with the request_id and your output. If the result holds another request, do that one too. If you can't finish one, call illuminate_fail.",
5329
5408
  "- Once a map is ready or an answer is shown, call illuminate_listen and leave it running. It moves to the background, so the person keeps their terminal. When they ask something on the map it returns with a request: do it, submit it, then call illuminate_listen again. If it returns saying nothing was asked yet, call it again without telling the person. Only one is needed at a time.",
5330
- "- A picture of the screen can ground a map for people who don't read code. Use your judgement: when a flow starts from something the person sees (a button, a form, a page) a screen on that box helps; for backend-only questions leave screens out. illuminate_screens lists what this repo can show; illuminate_capture screenshots a page already running on this machine, or an HTML file in the repo, and shows you the result. Look at it before using it: if it shows a login page, an error or the wrong state, don't use it. Never start the app yourself to get a screenshot.",
5409
+ "- A picture of the screen can ground a map for people who don't read code. Use your judgement: when a flow starts from something the person sees (a button, a form, a page) a screen on that box helps; for backend-only questions leave screens out. illuminate_screens lists what this repo can show; illuminate_capture screenshots a page already running on this machine, or an HTML file in the repo, and shows you the result. Look at it before using it: if it shows a login page, an error or the wrong state, don't use it. Never start the app yourself to get a screenshot. When nothing is running, a map can still show a wireframe of the page drawn from the code; the request explains how.",
5331
5410
  "- If an illuminate channel message arrives instead, call illuminate_next to get the request.",
5332
5411
  "- While working on an illuminate request, don't edit files or run commands that change anything, and never read secret files (.env, keys). A fix is only proposed; illuminate applies it after the person approves it on the map.",
5333
5412
  "- Answers are shown on the map. In the terminal, say at most a sentence or two."
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnz4021/illuminate",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Checked, interactive maps of how your code works, drawn by your own Claude Code session.",
5
5
  "license": "MIT",
6
6
  "type": "module",