@johnz4021/illuminate 0.2.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,16 +2913,16 @@ 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
 
2852
2920
  // packages/core/src/check.ts
2853
2921
  function check(map, root, options = {}) {
2854
- const repo = createRepoReader(root);
2855
- const window = options.lineWindow ?? 3;
2856
- const now = { repo, facts: factsFor(repo, fileExistsIn(repo.root)) };
2857
- const baseRepo = map.since ? createBaseReader(repo.root, map.since) : null;
2858
- const base = baseRepo && { repo: baseRepo, facts: factsFor(baseRepo, carryResolver((p) => baseRepo.has(p), fileExistsIn(repo.root))) };
2922
+ const window = options.lineWindow ?? DEFAULT_LINE_WINDOW;
2923
+ const { now, base } = sidesOf(map, root);
2924
+ const repo = now.repo;
2925
+ const baseRepo = base?.repo ?? null;
2859
2926
  const cmp = map.since ? { ref: map.since, base } : null;
2860
2927
  const byId = new Map(map.nodes.map((n) => [n.id, n]));
2861
2928
  let repoFiles = null;
@@ -2867,8 +2934,16 @@ function check(map, root, options = {}) {
2867
2934
  const absences = {};
2868
2935
  for (const a of map.absences) absences[a.id] = checkAbsence(a, repo, files());
2869
2936
  const screens = {};
2937
+ const pageChecks = /* @__PURE__ */ new Map();
2938
+ const pageOf = (id) => {
2939
+ if (!pageChecks.has(id)) {
2940
+ const page = map.pages?.find((p) => p.id === id);
2941
+ pageChecks.set(id, page ? checkPage(page, repo, (file) => now.facts.get(file)?.imports.map((i) => i.to).filter((to) => !to.startsWith("vendor:")) ?? []) : null);
2942
+ }
2943
+ return pageChecks.get(id) ?? null;
2944
+ };
2870
2945
  for (const n of map.nodes) {
2871
- const sc = checkScreen(n, repo);
2946
+ const sc = checkScreen(n, repo, pageOf);
2872
2947
  if (sc) screens[n.id] = sc;
2873
2948
  }
2874
2949
  const tour = {};
@@ -2931,6 +3006,13 @@ function factsFor(repo, exists) {
2931
3006
  }
2932
3007
  };
2933
3008
  }
3009
+ function sidesOf(map, root) {
3010
+ const repo = createRepoReader(root);
3011
+ const now = { repo, facts: factsFor(repo, fileExistsIn(repo.root)) };
3012
+ const baseRepo = map.since ? createBaseReader(repo.root, map.since) : null;
3013
+ const base = baseRepo && { repo: baseRepo, facts: factsFor(baseRepo, carryResolver((p) => baseRepo.has(p), fileExistsIn(repo.root))) };
3014
+ return { now, base };
3015
+ }
2934
3016
  function checkEvidence(repo, e, window) {
2935
3017
  const base = { file: e.file, line: e.line };
2936
3018
  const read = repo.read(e.file);
@@ -3103,7 +3185,7 @@ function checkAbsence(a, repo, files) {
3103
3185
  if (!searched) reasons.push(a.search.paths ? `no files match ${a.search.paths.join(", ")}, so nothing was searched` : "there were no files to search");
3104
3186
  return { status: reasons.length ? "unconfirmed" : "confirmed", found, searched, locations, reasons };
3105
3187
  }
3106
- var MAX_LOCATIONS, fileOf, within, short, symbolIn;
3188
+ var MAX_LOCATIONS, fileOf, within, short, DEFAULT_LINE_WINDOW, symbolIn;
3107
3189
  var init_check = __esm({
3108
3190
  "packages/core/src/check.ts"() {
3109
3191
  "use strict";
@@ -3116,10 +3198,132 @@ var init_check = __esm({
3116
3198
  fileOf = (symbol) => symbol.slice(0, symbol.indexOf("#"));
3117
3199
  within = (from, symbol) => from === symbol || from.startsWith(`${symbol}.`);
3118
3200
  short = (text2) => text2.length > 60 ? `${text2.slice(0, 57)}\u2026` : text2;
3201
+ DEFAULT_LINE_WINDOW = 3;
3119
3202
  symbolIn = (side, symbol) => side.facts.get(fileOf(symbol))?.symbols.find((s) => s.id === symbol) ?? null;
3120
3203
  }
3121
3204
  });
3122
3205
 
3206
+ // packages/core/src/code.ts
3207
+ function lineFinder(text2) {
3208
+ const starts = [0];
3209
+ for (let i = text2.indexOf("\n"); i !== -1; i = text2.indexOf("\n", i + 1)) starts.push(i + 1);
3210
+ return (offset) => {
3211
+ let lo = 0;
3212
+ let hi = starts.length - 1;
3213
+ while (lo < hi) {
3214
+ const mid = lo + hi + 1 >> 1;
3215
+ if (starts[mid] <= offset) lo = mid;
3216
+ else hi = mid - 1;
3217
+ }
3218
+ return lo + 1;
3219
+ };
3220
+ }
3221
+ function join5(a, b) {
3222
+ const from = Math.min(a.from, b.from);
3223
+ const to = Math.max(a.to, b.to);
3224
+ const outer = [a, b].find((r) => r.from === from && r.to === to);
3225
+ const inner = outer === a ? b : a;
3226
+ return outer ? { ...outer, name: outer.whole ? outer.name : inner.whole ? inner.name : outer.name ?? inner.name } : { from, to, name: a.name === b.name ? a.name : a.name ?? b.name, whole: false };
3227
+ }
3228
+ function blocksFor(side, marks, symbol) {
3229
+ const files = [.../* @__PURE__ */ new Set([...symbol ? [fileOf2(symbol)] : [], ...marks.map((m) => m.file)])];
3230
+ const out = [];
3231
+ let total = 0;
3232
+ for (const file of files) {
3233
+ const text2 = side.repo.text(file);
3234
+ if (text2 === null) continue;
3235
+ const lines = text2.split("\n");
3236
+ const lineOf2 = lineFinder(text2);
3237
+ const span = (s) => ({ from: lineOf2(s.span.start), to: lineOf2(Math.max(s.span.start, s.span.end - 1)) });
3238
+ const symbols = (side.facts.get(file)?.symbols ?? []).filter((s) => s.kind !== "property").map((s) => ({ name: s.name, id: s.id, ...span(s) }));
3239
+ const here = marks.filter((m) => m.file === file && m.line >= 1 && m.line <= lines.length);
3240
+ const around = (line, name) => ({ from: Math.max(1, line - CONTEXT), to: Math.min(lines.length, line + CONTEXT), name, whole: false });
3241
+ const ranges = [];
3242
+ const named = symbol && fileOf2(symbol) === file ? symbols.find((s) => s.id === symbol) : void 0;
3243
+ if (named) {
3244
+ if (named.to - named.from < WHOLE_NAMED) ranges.push({ from: named.from, to: named.to, name: named.name, whole: true });
3245
+ else if (!here.some((m) => m.line >= named.from && m.line <= named.to)) ranges.push({ from: named.from, to: named.from + 2 * CONTEXT, name: named.name, whole: false });
3246
+ }
3247
+ for (const m of here) {
3248
+ const inside = symbols.filter((s) => s.from <= m.line && m.line <= s.to && s.to - s.from >= 2).sort((a, b) => a.to - a.from - (b.to - b.from))[0];
3249
+ if (inside && inside.to - inside.from < WHOLE_FOUND) ranges.push({ from: inside.from, to: inside.to, name: inside.name, whole: true });
3250
+ else ranges.push(around(m.line, inside?.name ?? null));
3251
+ }
3252
+ ranges.sort((a, b) => a.from - b.from || b.to - a.to);
3253
+ const merged = [];
3254
+ for (const r of ranges) {
3255
+ const last = merged[merged.length - 1];
3256
+ if (last && r.from <= last.to + 1) merged[merged.length - 1] = join5(last, r);
3257
+ else merged.push(r);
3258
+ }
3259
+ for (const r of merged) {
3260
+ if (out.length >= MAX_BLOCKS || total >= MAX_LINES) return out;
3261
+ const to = Math.min(r.to, r.from + (MAX_LINES - total) - 1);
3262
+ const inRange = here.filter((m) => m.line >= r.from && m.line <= to);
3263
+ out.push({
3264
+ file,
3265
+ name: r.name,
3266
+ whole: r.whole && to === r.to,
3267
+ start: r.from,
3268
+ lines: lines.slice(r.from - 1, to).map((l) => l.length > MAX_LINE_CHARS ? `${l.slice(0, MAX_LINE_CHARS)}\u2026` : l),
3269
+ cited: [...new Set(inRange.map((m) => m.line))].sort((a, b) => a - b),
3270
+ notes: inRange.flatMap((m) => m.note ? [{ line: m.line, note: m.note }] : [])
3271
+ });
3272
+ total += to - r.from + 1;
3273
+ }
3274
+ }
3275
+ return out;
3276
+ }
3277
+ function locate(side, evidence) {
3278
+ const found = [];
3279
+ let missing = 0;
3280
+ for (const e of evidence) {
3281
+ const c = checkEvidence(side.repo, e, DEFAULT_LINE_WINDOW);
3282
+ if (c.ok && c.foundAt !== null) found.push({ ...e, line: c.foundAt });
3283
+ else missing++;
3284
+ }
3285
+ return { found, missing };
3286
+ }
3287
+ function codeOf(map, root, id, when = "now") {
3288
+ const item = map.nodes.find((n) => n.id === id) ?? map.edges.find((e) => e.id === id);
3289
+ if (!item) return null;
3290
+ const { now, base } = sidesOf(map, root);
3291
+ const side = when === "before" ? base : now;
3292
+ if (!side) return null;
3293
+ const { found, missing } = locate(side, item.evidence);
3294
+ return { when, blocks: blocksFor(side, found, "symbol" in item ? item.symbol : void 0), missing };
3295
+ }
3296
+ function checkNotes(root, notes) {
3297
+ const { now } = sidesOf({}, root);
3298
+ const kept = [];
3299
+ const dropped = [];
3300
+ for (const n of notes) {
3301
+ const c = checkEvidence(now.repo, n, DEFAULT_LINE_WINDOW);
3302
+ if (!c.ok || c.foundAt === null) dropped.push(`${n.file}:${n.line}: ${c.reason ?? "not found"}`);
3303
+ else if (!kept.some((k) => k.file === n.file && k.line === c.foundAt)) kept.push({ ...n, line: c.foundAt });
3304
+ }
3305
+ return { notes: kept, dropped };
3306
+ }
3307
+ function codeForNotes(root, notes) {
3308
+ const { now } = sidesOf({}, root);
3309
+ const { found, missing } = locate(now, notes);
3310
+ return { when: "now", blocks: blocksFor(now, found), missing };
3311
+ }
3312
+ var WHOLE_NAMED, WHOLE_FOUND, CONTEXT, MAX_BLOCKS, MAX_LINES, MAX_LINE_CHARS, fileOf2;
3313
+ var init_code = __esm({
3314
+ "packages/core/src/code.ts"() {
3315
+ "use strict";
3316
+ init_check();
3317
+ WHOLE_NAMED = 160;
3318
+ WHOLE_FOUND = 60;
3319
+ CONTEXT = 6;
3320
+ MAX_BLOCKS = 8;
3321
+ MAX_LINES = 500;
3322
+ MAX_LINE_CHARS = 400;
3323
+ fileOf2 = (symbol) => symbol.slice(0, symbol.indexOf("#"));
3324
+ }
3325
+ });
3326
+
3123
3327
  // packages/core/src/index.ts
3124
3328
  var init_src2 = __esm({
3125
3329
  "packages/core/src/index.ts"() {
@@ -3128,6 +3332,7 @@ var init_src2 = __esm({
3128
3332
  init_edit();
3129
3333
  init_base();
3130
3334
  init_check();
3335
+ init_code();
3131
3336
  init_repo();
3132
3337
  init_screens();
3133
3338
  }
@@ -3522,6 +3727,7 @@ function quickAnswerPrompt(map, report, selection, question, excerpts, earlier,
3522
3727
  "",
3523
3728
  "## How to answer (when `route` is `answer`)",
3524
3729
  ...ANSWER_STYLE,
3730
+ "- For `notes` you can only point at lines in the excerpts above: the number before `|` is the line. If the lines that answer it aren't there, that is a reason to route to `code`.",
3525
3731
  "- `moves`: `focus` on the most relevant id; `highlight` the ids that make up the path that answers the question."
3526
3732
  ].join("\n");
3527
3733
  }
@@ -3557,7 +3763,7 @@ ${missing}`] : [],
3557
3763
  '- 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
3764
  "- 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
3765
  "- 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.',
3766
+ '- 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
3767
  "",
3562
3768
  ...EVIDENCE_RULES,
3563
3769
  "",
@@ -3603,7 +3809,7 @@ var init_prompts = __esm({
3603
3809
  '- 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
3810
  `- 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
3811
  "- 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.",
3812
+ "- 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
3813
  "- 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
3814
  "- The walkthrough is told as the person's experience too, one stop per screen."
3609
3815
  ];
@@ -3628,12 +3834,15 @@ var init_prompts = __esm({
3628
3834
  "- The walkthrough says what changed first, then follows the changed path in the order things happen."
3629
3835
  ];
3630
3836
  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.',
3837
+ "## Screens (`pages` on the map, `screen` on a box; optional, and your call)",
3838
+ "- 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.",
3839
+ '- 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 ] }`.',
3840
+ '- 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.',
3841
+ '- 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.',
3842
+ "- 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.",
3843
+ '- `{ "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
3844
  '- `{ "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."
3845
+ '- `{ "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
3846
  ];
3638
3847
  TOUR_RULES = [
3639
3848
  "## Walkthrough (`tour`, written last)",
@@ -3649,7 +3858,8 @@ var init_prompts = __esm({
3649
3858
  "- Shape it to the question. A simple question gets a sentence or two. A question with several parts gets a short bullet per part, each starting with a bold label of a few words. Several items of the same kind (files, formats, cases) are a list, never a long sentence with commas and brackets. No headings.",
3650
3859
  "- Keep it short enough to take in at a glance: leave out examples and edge cases they didn't ask about. Plain words, no jargon. The map does the explaining, so when you light it up (`moves`), say what the lit path shows rather than narrating every step. Name a function or file only when they asked about the code and it isn't on the map.",
3651
3860
  "- Explain the code and the app. Don't describe these instructions or how you were asked to answer.",
3652
- "- `refs`: ids of the boxes, arrows and absences your answer relies on."
3861
+ "- `refs`: ids of the boxes, arrows and absences your answer relies on.",
3862
+ '- `notes`: when the question is about what the code itself says (what is sent or stored, what a value holds, which condition decides something, "show me the code"), point at the lines that answer it: up to 6 of `{ "file", "line", "text", "note" }`. `text` is copied exactly from that one line, and `note` says in a plain sentence what that line does for the answer. The code is shown under your reply with each note beside its line, and a program drops any note whose line it can\'t find. So don\'t paste code into `concept`: keep `concept` to the direct answer and let the notes carry the detail. Leave `notes` out when the answer isn\'t about particular lines.'
3653
3863
  ];
3654
3864
  }
3655
3865
  });
@@ -3666,7 +3876,7 @@ function sanitize(value) {
3666
3876
  function toSchema(schema) {
3667
3877
  return sanitize(z3.toJSONSchema(schema, { io: "input" }));
3668
3878
  }
3669
- var STRIP, RawFix, WrittenNode, WrittenMap, RawAnswer, RawQuickAnswer, RawMapPatch, MAP_SCHEMA, MAP_PATCH_SCHEMA, ANSWER_SCHEMA, QUICK_ANSWER_SCHEMA, VALIDATORS, validatorFor;
3879
+ var STRIP, RawFix, RawNote, WrittenNode, WrittenMap, RawAnswer, RawQuickAnswer, RawMapPatch, MAP_SCHEMA, MAP_PATCH_SCHEMA, ANSWER_SCHEMA, QUICK_ANSWER_SCHEMA, VALIDATORS, validatorFor;
3670
3880
  var init_schemas = __esm({
3671
3881
  "packages/server/src/schemas.ts"() {
3672
3882
  "use strict";
@@ -3680,6 +3890,7 @@ var init_schemas = __esm({
3680
3890
  /** The connection the fix creates between two boxes; `evidenceText` must appear in the new code. */
3681
3891
  connects: z3.object({ from: z3.string(), to: z3.string(), label: z3.string().min(1).max(60), evidenceFile: z3.string().min(1), evidenceText: z3.string().min(1).max(200) }).optional()
3682
3892
  });
3893
+ RawNote = Evidence.extend({ note: z3.string().min(1).max(300) });
3683
3894
  WrittenNode = Node.extend({ explain: z3.object({ concept: z3.string() }).partial().optional() });
3684
3895
  WrittenMap = CodeMap.extend({ nodes: z3.array(WrittenNode).min(1) });
3685
3896
  RawAnswer = z3.object({
@@ -3690,13 +3901,15 @@ var init_schemas = __esm({
3690
3901
  /** New things found while exploring, with evidence, same rules as the map. */
3691
3902
  add: z3.object({ areas: z3.array(Area).optional(), nodes: z3.array(WrittenNode).optional(), edges: z3.array(Edge).optional(), absences: z3.array(Absence).optional() }).optional(),
3692
3903
  moves: z3.object({ focus: z3.string().optional(), highlight: z3.array(z3.string()).optional() }).optional(),
3904
+ /** Lines of code the answer points at, each with a note, when the question is about what the code itself says. */
3905
+ notes: z3.array(RawNote).max(8).optional(),
3693
3906
  /** Pictures of the screen for boxes on the map (existing ones, or ones in `add`), when the question is about what the person sees. */
3694
3907
  screens: z3.array(z3.object({ node: z3.string(), screen: Screen })).max(4).optional(),
3695
3908
  /** Boxes or arrows already on the map that a suggested change would alter or remove (new ones go in `add`, marked there). */
3696
3909
  propose: z3.array(z3.object({ id: z3.string(), proposed: Proposal })).max(12).optional(),
3697
3910
  fix: RawFix.optional()
3698
3911
  });
3699
- RawQuickAnswer = RawAnswer.pick({ refs: true, moves: true }).extend({
3912
+ RawQuickAnswer = RawAnswer.pick({ refs: true, moves: true, notes: true }).extend({
3700
3913
  /**
3701
3914
  * `answer`: the map and the excerpts fully answer it. `code`: about this map, but needs code it doesn't show.
3702
3915
  * `elsewhere`: about a different part of the app than this map covers.
@@ -3778,6 +3991,10 @@ function selectionLines(map, s) {
3778
3991
  })
3779
3992
  ];
3780
3993
  }
3994
+ function notesOf(root, raw) {
3995
+ const r = checkNotes(root, raw ?? []);
3996
+ return { notes: r.notes, problems: r.dropped.map((d) => `A note on the code wasn't shown, its line isn't there: ${d}`) };
3997
+ }
3781
3998
  function statusOf(report, id) {
3782
3999
  const c = report.nodes[id] ?? report.edges[id] ?? report.absences[id];
3783
4000
  return c ? c.status : "unknown";
@@ -3826,6 +4043,7 @@ async function answer(o) {
3826
4043
  }
3827
4044
  if (quick.success && quick.data.route === "answer" && quick.data.concept.trim()) {
3828
4045
  const q = quick.data;
4046
+ const noted2 = notesOf(o.root, q.notes);
3829
4047
  const result3 = {
3830
4048
  id: `ans-${crypto3.randomBytes(4).toString("hex")}`,
3831
4049
  question: o.question,
@@ -3837,7 +4055,8 @@ async function answer(o) {
3837
4055
  highlight: (q.moves?.highlight ?? []).filter((id) => live0.has(id))
3838
4056
  },
3839
4057
  added: [],
3840
- problems: [],
4058
+ notes: noted2.notes,
4059
+ problems: noted2.problems,
3841
4060
  fix: null,
3842
4061
  source: "map",
3843
4062
  offer: null,
@@ -3941,6 +4160,8 @@ async function answer(o) {
3941
4160
  if (proposed.ok) fix = proposed.proposal;
3942
4161
  else problems.push(...proposed.problems.map((p) => `The proposed fix can't be applied: ${p}`));
3943
4162
  }
4163
+ const noted = notesOf(o.root, raw.notes);
4164
+ problems.push(...noted.problems);
3944
4165
  const live = mapIds(map);
3945
4166
  const result2 = {
3946
4167
  id: `ans-${crypto3.randomBytes(4).toString("hex")}`,
@@ -3955,6 +4176,7 @@ async function answer(o) {
3955
4176
  added,
3956
4177
  proposed: marked,
3957
4178
  screens: screened.filter((id) => live.has(id)),
4179
+ notes: noted.notes,
3958
4180
  problems,
3959
4181
  fix,
3960
4182
  source: "code",
@@ -4085,18 +4307,18 @@ async function headStart(root) {
4085
4307
  ].join("\n");
4086
4308
  return { text: text2 || "(The automatic scan found no entry points; explore the repo directly.)", scan };
4087
4309
  }
4088
- var MAX_LINES, MAX_SYMBOL_FILES, MAX_SYMBOLS_PER_FILE, CITABLE, TEST_FILE, section;
4310
+ var MAX_LINES2, MAX_SYMBOL_FILES, MAX_SYMBOLS_PER_FILE, CITABLE, TEST_FILE, section;
4089
4311
  var init_hints = __esm({
4090
4312
  "packages/server/src/hints.ts"() {
4091
4313
  "use strict";
4092
4314
  init_src();
4093
4315
  init_changes();
4094
- MAX_LINES = 40;
4316
+ MAX_LINES2 = 40;
4095
4317
  MAX_SYMBOL_FILES = 150;
4096
4318
  MAX_SYMBOLS_PER_FILE = 40;
4097
4319
  CITABLE = /* @__PURE__ */ new Set(["function", "method", "component", "class"]);
4098
4320
  TEST_FILE = /(^|\/)(test|tests|__tests__|__mocks__|e2e|fixtures?)\/|\.(test|spec)\.[cm]?[jt]sx?$|_test\.(go|py)$|(^|\/)test_[^/]*\.py$/;
4099
- section = (title, lines, max = MAX_LINES) => lines.length ? [`${title}:`, ...lines.slice(0, max), ...lines.length > max ? [` \u2026and ${lines.length - max} more`] : [], ""] : [];
4321
+ section = (title, lines, max = MAX_LINES2) => lines.length ? [`${title}:`, ...lines.slice(0, max), ...lines.length > max ? [` \u2026and ${lines.length - max} more`] : [], ""] : [];
4100
4322
  }
4101
4323
  });
4102
4324
 
@@ -4490,6 +4712,17 @@ async function startServer(o) {
4490
4712
  }
4491
4713
  return json(res, 200, { ...stored, report: check(stored.map, root), job, failure: null, answers: stored.answers ?? [], fixes: fixStates(stored) });
4492
4714
  }
4715
+ if (mapId && parts[2] === "code" && parts.length === 3 && m === "GET") {
4716
+ const stored = store.get(mapId);
4717
+ const view2 = stored && codeOf(stored.map, root, url2.searchParams.get("item") ?? "", url2.searchParams.get("when") === "before" ? "before" : "now");
4718
+ if (!view2) throw new HttpError(404, "No code to show for that.");
4719
+ return json(res, 200, { ...view2, root });
4720
+ }
4721
+ if (mapId && parts[2] === "answers" && parts[3] && parts[4] === "code" && m === "GET") {
4722
+ const notes = store.get(mapId)?.answers?.find((a) => a.id === parts[3])?.notes;
4723
+ if (!notes?.length) throw new HttpError(404, "No code to show for that.");
4724
+ return json(res, 200, { ...codeForNotes(root, notes), root });
4725
+ }
4493
4726
  if (mapId && parts[2] === "answers" && parts[3] && parts[4] === "offer" && m === "POST") {
4494
4727
  const body = await readBody(req);
4495
4728
  return json(res, 200, takeOffer(mapId, parts[3], body.choice === "map" ? "map" : body.choice === "words" ? "words" : null));
@@ -5327,7 +5560,7 @@ var init_channel = __esm({
5327
5560
  '- 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
5561
  "- 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
5562
  "- 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.",
5563
+ "- 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
5564
  "- If an illuminate channel message arrives instead, call illuminate_next to get the request.",
5332
5565
  "- 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
5566
  "- Answers are shown on the map. In the terminal, say at most a sentence or two."
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@johnz4021/illuminate",
3
- "version": "0.2.0",
3
+ "version": "0.4.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",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/johnz4021/codemap.git"
9
+ "url": "git+https://github.com/johnz4021/illuminate.git"
10
10
  },
11
- "homepage": "https://github.com/johnz4021/codemap#readme",
11
+ "homepage": "https://github.com/johnz4021/illuminate#readme",
12
12
  "keywords": [
13
13
  "claude-code",
14
14
  "mcp",