@skillstech/thunderlang 1.1.0 → 1.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +212 -0
  2. package/README.md +4 -1
  3. package/dist/core.cjs +2080 -278
  4. package/dist/index.cjs +12742 -10943
  5. package/dist/learn.cjs +12976 -3598
  6. package/package.json +2 -2
  7. package/src/cli-home.mjs +242 -0
  8. package/src/cli.mjs +135 -41
  9. package/src/core/ThunderRuntime.cs +1367 -0
  10. package/src/core/check.mjs +158 -2
  11. package/src/core/cli.mjs +208 -17
  12. package/src/core/csharp-run.mjs +184 -0
  13. package/src/core/diagnostics.mjs +13 -0
  14. package/src/core/engine-core.mjs +855 -0
  15. package/src/core/engine-values.mjs +1054 -0
  16. package/src/core/engine-worker.mjs +15 -0
  17. package/src/core/engine.mjs +63 -0
  18. package/src/core/format.mjs +191 -3
  19. package/src/core/go-run.mjs +106 -0
  20. package/src/core/index.mjs +3 -1
  21. package/src/core/java/thunder/T.java +6 -0
  22. package/src/core/java/thunder/ThunderRuntime.java +1374 -0
  23. package/src/core/java-run.mjs +89 -0
  24. package/src/core/parser.mjs +331 -5
  25. package/src/core/project.mjs +43 -8
  26. package/src/core/react-run.mjs +96 -0
  27. package/src/core/runtime-go/thunder_runtime.go +3038 -0
  28. package/src/core/runtime-react.mjs +133 -0
  29. package/src/core/runtime-typescript.mjs +119 -0
  30. package/src/core/rust/thunder_runtime.rs +1645 -0
  31. package/src/core/rust-run.mjs +192 -0
  32. package/src/core/screen-values.mjs +30 -0
  33. package/src/core/target-csharp.mjs +484 -0
  34. package/src/core/target-go.mjs +555 -0
  35. package/src/core/target-java.mjs +587 -0
  36. package/src/core/target-python.mjs +2 -1
  37. package/src/core/target-react.mjs +270 -0
  38. package/src/core/target-rust.mjs +534 -0
  39. package/src/core/target-typescript.mjs +466 -0
  40. package/src/core/typescript-run.mjs +114 -0
  41. package/src/core.d.ts +18 -0
  42. package/src/core.mjs +1 -0
  43. package/src/emit.mjs +1 -1
  44. package/src/faithful.mjs +30 -0
  45. package/src/learn-lessons.mjs +245 -1
  46. package/src/learn.d.mts +8 -0
  47. package/src/learn.mjs +40 -4
  48. package/src/libraries.mjs +10 -3
  49. package/src/model.mjs +50 -8
  50. package/src/read-level.mjs +192 -0
  51. package/src/read-repo-fs.mjs +3 -1
  52. package/src/read.mjs +28 -5
  53. package/src/replay-cli.mjs +123 -0
  54. package/src/say-less.mjs +152 -11
  55. package/src/screens.mjs +833 -0
  56. package/src/steps.mjs +430 -19
  57. package/src/term.mjs +132 -0
  58. package/src/try-cli.mjs +225 -0
  59. package/src/why-cli.mjs +17 -7
  60. package/src/why.d.mts +17 -7
  61. package/src/why.mjs +114 -33
package/dist/core.cjs CHANGED
@@ -234,6 +234,7 @@ __export(core_exports, {
234
234
  readFiles: () => readFiles,
235
235
  readLevel: () => readLevel,
236
236
  readRepo: () => readRepo,
237
+ readScreens: () => readScreens,
237
238
  readableFile: () => readableFile,
238
239
  readableLanguage: () => readableLanguage,
239
240
  readingOf: () => readingOf,
@@ -268,6 +269,7 @@ __export(core_exports, {
268
269
  sayFull: () => sayFull,
269
270
  scanIntent: () => scanIntent,
270
271
  scanProject: () => scanProject,
272
+ screenText: () => screenText,
271
273
  searchAtlas: () => searchAtlas,
272
274
  searchReading: () => searchReading,
273
275
  searchRepo: () => searchRepo,
@@ -1052,14 +1054,14 @@ function parseIntent(source) {
1052
1054
  break;
1053
1055
  // ── System profile ──
1054
1056
  case "capability": {
1055
- const cap5 = { name: arg, description: null, implements: [], line: node2.line };
1057
+ const cap6 = { name: arg, description: null, implements: [], line: node2.line };
1056
1058
  for (const c of kids(node2)) {
1057
1059
  const k = firstWord(c.text);
1058
1060
  const a = rest(c.text);
1059
- if (k === "description") cap5.description = stripQuotes(a || leafItems(c).join(" "));
1060
- else if (k === "implements") cap5.implements.push(...a ? [a] : leafItems(c));
1061
+ if (k === "description") cap6.description = stripQuotes(a || leafItems(c).join(" "));
1062
+ else if (k === "implements") cap6.implements.push(...a ? [a] : leafItems(c));
1061
1063
  }
1062
- ast.capabilities.push(cap5);
1064
+ ast.capabilities.push(cap6);
1063
1065
  break;
1064
1066
  }
1065
1067
  case "interface": {
@@ -6165,6 +6167,31 @@ var asCodeWords = (code3, n = 120) => {
6165
6167
  return `\`${t.length > n ? `${t.slice(0, n - 1)}\u2026` : t}\``;
6166
6168
  };
6167
6169
  var isCodeWords = (said) => /^`[^]*`$/.test(String(said).trim());
6170
+ function pythonImportSays(code3) {
6171
+ const t = String(code3).trim().replace(/\s*#.*$/, "");
6172
+ const named2 = (x) => {
6173
+ const m3 = /^([A-Za-z_]\w*)(?:\s+as\s+([A-Za-z_]\w*))?$/.exec(x.trim());
6174
+ return m3 ? m3[2] && m3[2] !== m3[1] ? `${m3[1]} (called ${m3[2]} here)` : m3[1] : null;
6175
+ };
6176
+ const list3 = (xs) => xs.length <= 1 ? xs.join("") : `${xs.slice(0, -1).join(", ")} and ${xs.at(-1)}`;
6177
+ let m;
6178
+ if (m = /^import\s+([A-Za-z_][\w.]*)(?:\s+as\s+([A-Za-z_]\w*))?$/.exec(t)) return `Loads the ${m[1]} module${m[2] && m[2] !== m[1] ? `, called ${m[2]} here` : ""}`;
6179
+ if (m = /^from\s+(\.?)([A-Za-z_][\w.]*)?\s+import\s+\(?([^()*]+?)\)?$/.exec(t)) {
6180
+ const names = m[3].split(",").map((x) => x.trim()).filter(Boolean).map(named2);
6181
+ if (!names.length || names.some((x) => !x) || !m[1] && !m[2]) return null;
6182
+ const from = m[1] ? m[2] ? `the ${m[2]} module in this package` : "this package" : `the ${m[2]} module`;
6183
+ return `Loads ${list3(names)} from ${from}`;
6184
+ }
6185
+ return null;
6186
+ }
6187
+ function sliceWords(start, end, single) {
6188
+ if (single != null) return single === "-1" ? "the last of {x}" : null;
6189
+ const n = (x) => x == null || x === "" ? null : Number(x);
6190
+ const a = n(start), b = n(end);
6191
+ if (a != null && b == null) return a > 0 ? `{x} without the first ${a}` : a < 0 ? `the last ${-a} of {x}` : null;
6192
+ if (a == null && b != null) return b > 0 ? `the first ${b} of {x}` : b < 0 ? `{x} without the last ${-b}` : null;
6193
+ return null;
6194
+ }
6168
6195
 
6169
6196
  // src/say-less.mjs
6170
6197
  var NODES = /* @__PURE__ */ new WeakMap();
@@ -6298,6 +6325,12 @@ function codeWordSet(code3) {
6298
6325
  if (/\b0\b/.test(code3)) out.add("zero");
6299
6326
  return out;
6300
6327
  }
6328
+ var IDIOM_EXTRA = /* @__PURE__ */ new Set([
6329
+ [/^(?:module|loads)$/, /^\s*(?:from\s+\S+\s+)?import\s/],
6330
+ [/^package$/, /^\s*from\s+\.\w*\s+import\s/],
6331
+ [/^(?:called|here)$/, /^\s*(?:from\s+\S+\s+)?import\s.*\bas\b/]
6332
+ ]);
6333
+ IDIOM.push(...IDIOM_EXTRA);
6301
6334
  var IDIOM_OF = /* @__PURE__ */ new Map();
6302
6335
  function unsourcedWord(says, code3) {
6303
6336
  let have = null;
@@ -6314,7 +6347,7 @@ function unsourcedWord(says, code3) {
6314
6347
  }
6315
6348
  if (idiom) {
6316
6349
  if (idiom[1].test(code3) || inCode(w)) continue;
6317
- return w;
6350
+ if (!IDIOM_EXTRA.has(idiom)) return w;
6318
6351
  }
6319
6352
  if (GLUE.has(w) || FORM_WORDS.has(w)) continue;
6320
6353
  if (/ing$/.test(w)) {
@@ -6370,19 +6403,19 @@ function inventedValue(says, code3) {
6370
6403
  const text2 = String(code3);
6371
6404
  for (const num3 of said.replace(/"(?:\\.|[^"\\])*"/g, " ").match(/(?<![\w.«])-?\d+(?:\.\d+)?(?![\w.»])/g) || []) {
6372
6405
  const n = num3.replace(/^-/, "");
6373
- if (!text2.includes(n) && !/^[01]$/.test(n) && !statusNamed(n, text2) && !text2.includes(`..<${Number(n) + 1}`) && !new RegExp(`\\.\\.<\\s*${Number(n) + 1}\\b`).test(text2)) return num3;
6406
+ if (!text2.includes(n) && !/^[01]$/.test(n) && !statusNamed(n, text2) && !text2.includes(`..<${Number(n) + 1}`) && !new RegExp(`\\.\\.<?\\s*${Number(n) + 1}\\b`).test(text2) && !new RegExp(`\\brange\\((?:\\s*\\d+\\s*,)?\\s*${Number(n) + 1}\\s*\\)`).test(text2)) return num3;
6374
6407
  }
6375
6408
  for (const q2 of String(says).replace(/^(?:If (?:not: )?|Repeats: |Fails with )?`[^]*`$/, "").match(/"(?:\\.|[^"\\])*"/g) || []) {
6376
6409
  if (!exactText(q2.slice(1, -1), text2)) return q2;
6377
6410
  }
6378
6411
  return null;
6379
6412
  }
6380
- function textSkeleton(t, words13 = false, open = false) {
6413
+ function textSkeleton(t, words14 = false, open = false) {
6381
6414
  const s = String(t);
6382
6415
  let out = "";
6383
6416
  for (let i = 0; i < s.length; i++) {
6384
6417
  const c = s[i], n = s[i + 1];
6385
- if (words13 && c === "\xAB") {
6418
+ if (words14 && c === "\xAB") {
6386
6419
  const e = s.indexOf("\xBB", i);
6387
6420
  if (e > i) {
6388
6421
  out += "";
@@ -6430,7 +6463,7 @@ function textSkeleton(t, words13 = false, open = false) {
6430
6463
  i++;
6431
6464
  continue;
6432
6465
  }
6433
- if (c === "%" && /[-+ #0-9.]*[sdifgxXoucpqvT]/.test(s.slice(i + 1, i + 6))) {
6466
+ if (c === "%" && /^[-+ #0-9.]*[sdifgxXoucpqvT]/.test(s.slice(i + 1, i + 6))) {
6434
6467
  const m = /^[-+ #0-9.]*[a-zA-Z]/.exec(s.slice(i + 1));
6435
6468
  out += "";
6436
6469
  i += m[0].length;
@@ -6650,10 +6683,24 @@ function namesKept(tree, said) {
6650
6683
  const name = c?.kind === "member" ? c.property : c?.kind === "name" ? c.name : null;
6651
6684
  const own = c?.kind === "member" && !(c.object?.kind === "name" && /^[A-Z]/.test(c.object.name)) ? c.object : null;
6652
6685
  if (name && /^(?:enumerate|iter|iter_mut|into_iter|items|entries|values|stream|ToList|toList|AsEnumerable|toArray|asList|each_with_index|with_index|indices|withIndex|Values|Keys|keys)$/.test(name)) return ok(own) && ok(n.args);
6686
+ if (name && /^(?:chars|lines|bytes)$/.test(name) && own && sw.includes(` ${{ chars: "characters", lines: "lines", bytes: "bytes" }[name]} of `)) return ok(own) && ok(n.args);
6653
6687
  if (name && /^(?:str|strn|mem|wcs|wcsn)(?:case)?cmp$|^_?str(?:n)?icmp$/.test(name) && / is /.test(sw)) return ok(n.args);
6654
6688
  if (name && /^(?:get|Get|fetch|at|get_or_default|getOrDefault|GetValueOrDefault|TryGetValue|getOrNull|Item)$/.test(name) && / entry | entries /.test(sw)) return ok(c.kind === "member" ? c.object : null) && ok(n.args);
6689
+ if (name === "get" && c?.kind === "member" && n.args?.[0]?.kind === "literal" && n.args[0].type === "text" && / value from /.test(sw) && (n.args.length === 1 || n.args.length === 2 && / if it has none /.test(sw))) return ok(c.object) && ok(n.args);
6655
6690
  if (name && has2(name) && sw.includes(` result of ${splitWords(name).join(" ")} `)) return true;
6656
6691
  if (name && /^(?:new|New|create|of|from|make)$/.test(name) && / new /.test(sw) && c.kind === "member") return ok(c.object);
6692
+ const onType = c?.kind === "member" && c.object?.kind === "name" ? c.object.name : null;
6693
+ if (onType === "Math" && /^(?:max|min)$/.test(name) && / (?:largest|smallest) /.test(sw)) return ok(n.args);
6694
+ if (onType === "Math" && /^(?:round|floor|ceil|abs|trunc)$/.test(name) && / (?:rounded|absolute|fraction) /.test(sw)) return ok(n.args);
6695
+ if (onType === "Date" && name === "parse" && / time written /.test(sw)) return ok(n.args);
6696
+ if (name === "exec" && / first match of /.test(sw)) return ok(c.kind === "member" ? c.object : null) && ok(n.args);
6697
+ if (name === "parse" && onType && /^[A-Z]/.test(onType) && / checked and read by /.test(sw) && has2(onType)) return ok(n.args);
6698
+ if (name === "from" && onType && / made from /.test(sw)) return ok(n.args);
6699
+ if (c?.kind === "name" && /^(?:list|tuple)$/.test(name) && / as a (?:list|tuple) /.test(sw)) return ok(n.args);
6700
+ if (c?.kind === "name" && /^(?:set|frozenset)$/.test(name) && / different values in /.test(sw)) return ok(n.args);
6701
+ if (c?.kind === "name" && name === "sorted" && / sorted /.test(sw)) return ok(n.args);
6702
+ if (c?.kind === "name" && name === "reversed" && / reverse order /.test(sw)) return ok(n.args);
6703
+ if (name === "index" && c?.kind === "member" && / position of /.test(sw)) return ok(c.object) && ok(n.args);
6657
6704
  if (name && /^(?:any|some|all|every|none|find|first|filter|where|select|detect|find_index|findIndex|includes|include\?|contains|Contains|any\?|all\?|none\?|exists|Any|All|Exists|in_array|has|hasOwnProperty|has_key|key\?|containsKey|ContainsKey|startswith|endswith|startsWith|endsWith|StartsWith|EndsWith|start_with\?|end_with\?)$/.test(name) && / (?:any|every|all|no|first|matches|match|in|has|contains|starts|ends|one of) /.test(sw)) return ok(own) && n.args.every((a) => a.kind === "lambda" || ok(a));
6658
6705
  if (name && /^(?:len|length|size|count|nrow|NROW|Count|sizeof|strlen|wcslen|mb_strlen|nchar|str_length|lengths|Length)$/.test(name) && howMany) return ok(c.kind === "member" ? c.object : null) && ok(n.args);
6659
6706
  if (name && /^(?:isinstance|is_a\??|kind_of\??|instance_of\??|inherits|is)$/.test(name) && isA) return ok(c.kind === "member" ? c.object : null) && ok(n.args);
@@ -6721,6 +6768,17 @@ function chainCallees(e) {
6721
6768
  return out;
6722
6769
  }
6723
6770
  var sameWords = (a, b) => splitWords(a).join("") === splitWords(b).join("");
6771
+ var PREPOSITION_END = /(?:for|from|to|of|with|by|in|on|at|about|into|as|via)$/i;
6772
+ function callNamed(callee2, said, code3) {
6773
+ if (sameWords(callee2, said)) return true;
6774
+ const cw = splitWords(callee2);
6775
+ if (!cw.length || !PREPOSITION_END.test(cw[cw.length - 1])) return false;
6776
+ const sw = splitWords(said);
6777
+ if (sw.join("") === cw.slice(0, -1).join("")) return true;
6778
+ if (sw.length <= cw.length || sw.slice(0, cw.length).join("") !== cw.join("")) return false;
6779
+ const rest2 = sw.slice(cw.length).join("");
6780
+ return splitWords(String(code3)).some((w, i, all) => all.slice(i, i + sw.length - cw.length).join("") === rest2);
6781
+ }
6724
6782
  var leadingWord = (code3) => (String(code3).trim().match(/^[A-Za-z_]+/) || [""])[0];
6725
6783
  var ENDING_CODE = /(?:^|[;&|]\s*)(?:exit|return|exec)\b|^\s*(?:return\b|yield\b|throw\b|raise\b|exit\b|die\b|abort\b|panic!?|halt\b|fail\b|Exit\b|exit\(|_exit\(|os\.Exit\(|sys\.exit\(|process\.exit\(|System\.exit\(|stop\(|Throw-|throw\(|break\b|Write-Error\b.*-ErrorAction\s+Stop|quit\(|q\()/i;
6726
6784
  var IMPLICIT_RETURN_LANGS = /* @__PURE__ */ new Set(["ruby", "rust", "kotlin", "scala", "swift", "r", "elixir", "typescript", "javascript", "csharp", "java", "powershell", "shell", "python", "go", "php", "cpp", "c", "sql"]);
@@ -6874,29 +6932,49 @@ ${full}`)) return WHY.form;
6874
6932
  break;
6875
6933
  }
6876
6934
  }
6935
+ const entryNamed = (a) => {
6936
+ if (a?.kind !== "object") return false;
6937
+ const keys = (a.entries || []).map((e2) => e2.key?.kind === "literal" ? String(e2.key.value) : null);
6938
+ if (/^an empty entry$/.test(adds[1])) return keys.length === 0;
6939
+ if (/^an entry$/.test(adds[1])) return keys.length > 0;
6940
+ const listed = /^an entry \(([^)]*)\)/.exec(adds[1]);
6941
+ if (!listed) return false;
6942
+ const named2 = listed[1].split(", ").filter((k) => k !== "\u2026");
6943
+ return named2.length > 0 && named2.every((k, i) => keys[i] != null && splitWords(keys[i]).join(" ") === splitWords(k).join(" "));
6944
+ };
6945
+ const textNamed = (a) => (a?.kind === "literal" && a.type === "text" || a?.kind === "template") && /^"/.test(adds[1]);
6946
+ const kept = (a) => namesKept(a, adds[1]) || entryNamed(a) || textNamed(a) || /^several values$/.test(adds[1]);
6877
6947
  if (tree.kind === "assign" && tree.op !== "=" && tree.op !== ":=") {
6878
6948
  if (!namesKept(tree.value, adds[1])) return M("adds-value");
6879
- } else if (core?.kind === "call" && core.args?.length && !core.args.some((a) => namesKept(a, adds[1]))) return M("adds-value");
6949
+ } else if (core?.kind === "call" && core.args?.length && !core.args.some(kept)) return M("adds-value");
6880
6950
  else if (core?.kind === "call" && core.args?.some((a) => a.kind === "index") && !core.args.every((a) => namesKept(a, adds[1]) || a.kind === "name")) return M("adds-value");
6881
6951
  }
6882
6952
  if (/^Calls /.test(says)) return callKept(step, tree, says, code3, lang);
6883
6953
  if (tree) {
6884
- const summary2 = /^(?:Works out|Calls|Runs|Defines|Creates|Writes|Adds to|Takes|Declares|Starts with|Makes|Stores the result of)\b| the result of /.test(says);
6954
+ const summary2 = /^(?:Works out|Calls|Runs|Defines|Creates|Writes|Adds to|Adds an entry\b|Adds an empty entry\b|Adds several values\b|Takes|Declares|Starts with|Makes|Stores the result of)\b| the result of |«…»/.test(says);
6885
6955
  const neg = treeNegations(tree, summary2), w = saidNegations(says);
6886
- if (w !== neg && !(w < neg && /^(?:Works out|Calls|Runs|Defines|Creates|Writes|Adds to|Takes|Declares|Starts with|Makes)\b/.test(says) && !/\b(?:whether|if|when)\b/.test(said))) return M("L320");
6956
+ if (w !== neg && !(w < neg && (/^(?:Works out|Calls|Runs|Defines|Creates|Writes|Adds to|Adds an entry\b|Adds an empty entry\b|Adds several values\b|Takes|Declares|Starts with|Makes)\b/.test(says) || /«…»/.test(says)) && !/\b(?:whether|if|when)\b/.test(said))) return M("L320");
6887
6957
  if (w > neg) return M("L321");
6888
6958
  if (/^Sets .+ to /.test(says)) {
6889
6959
  const v = tree.kind === "assign" ? tree.value : null;
6890
6960
  if (v) {
6891
- if (!newThing(v, says) && !namesKept(v, says)) return M("L327");
6961
+ const sl = sliceOf(v);
6962
+ if (sl) {
6963
+ if (!sliceSaid(sl, says)) return M("L327s");
6964
+ } else if (v.kind === "template" && /^Sets [^"]+ to "[^"]*«…»[^"]*"$/.test(says)) {
6965
+ } else if (!newThing(v, says) && !namesKept(v, says)) return M("L327");
6892
6966
  if (castCount(v) && !/\bas\b|\bcopy\b|\bconverted\b|\bturned\b/.test(said)) return M("L328");
6893
6967
  if (!orderingKept(v, says)) return M("L329");
6894
6968
  }
6895
6969
  }
6970
+ if (lang === "rust" && tree.kind === "assign" && /^(?:Works out|Sets) /.test(says)) {
6971
+ const q2 = tree.value?.kind === "unary" && tree.value.op === "?";
6972
+ if (q2 !== / and stops here if that fails$/.test(says)) return M("rust-q");
6973
+ }
6896
6974
  if (/^Works out (.+?) from (.+)$/.test(says) && tree.kind === "assign") {
6897
- const m = /^Works out (.+?) from ([\w ]+)$/.exec(says);
6975
+ const m = /^Works out (.+?) from ([\w ]+?)(?:, and stops here if that fails)?$/.exec(says);
6898
6976
  const callees = chainCallees(tree.value);
6899
- if (m && callees.length && !callees.some((c) => sameWords(c, m[2]))) return M("L335");
6977
+ if (m && callees.length && !callees.some((c) => callNamed(c, m[2], code3))) return M("L335");
6900
6978
  }
6901
6979
  if (/\bif\b.*\botherwise\b/.test(said) && ![...nodesOf2(tree)].some((n) => n.kind === "conditional" || n.kind === "if")) return WHY.form;
6902
6980
  }
@@ -6956,7 +7034,7 @@ function conditionCore(test, says, code3, lang) {
6956
7034
  }
6957
7035
  function conditionKept(step, tree, says, code3, lang) {
6958
7036
  if (isCodeWords(says.replace(/^If (?:not: )?/, "").replace(/ \(\d+ steps? inside\)$/, ""))) return null;
6959
- const words13 = says.replace(/^If (?:not: )?/, "").replace(/ \(\d+ steps? inside\)$/, "");
7037
+ const words14 = says.replace(/^If (?:not: )?/, "").replace(/ \(\d+ steps? inside\)$/, "");
6960
7038
  const not = /^If not: /.test(says);
6961
7039
  if (tree && tree.kind === "if") {
6962
7040
  if (tree.init) {
@@ -6970,14 +7048,14 @@ function conditionKept(step, tree, says, code3, lang) {
6970
7048
  return WHY.form;
6971
7049
  }
6972
7050
  const test = tree.negate && not ? tree.test : tree.negate ? { kind: "not", value: tree.test } : tree.test;
6973
- if (not && !tree.negate) return conditionCore({ kind: "not", value: test }, `not ${words13}`, code3, lang);
6974
- return conditionCore(test, words13, code3, lang);
7051
+ if (not && !tree.negate) return conditionCore({ kind: "not", value: test }, `not ${words14}`, code3, lang);
7052
+ return conditionCore(test, words14, code3, lang);
6975
7053
  }
6976
7054
  if (tree) return WHY.form;
6977
7055
  if (lang === "powershell" || lang === "r" || lang === "sql") return null;
6978
7056
  if (lang === "shell") return shellConditionKept(code3, says);
6979
7057
  const cond = String(step.cond ?? code3);
6980
- if (!accountsFor(cond, `${not ? "not " : ""}${claimText(words13)}`)) return M("L402");
7058
+ if (!accountsFor(cond, `${not ? "not " : ""}${claimText(words14)}`)) return M("L402");
6981
7059
  return null;
6982
7060
  }
6983
7061
  function shellConditionKept(code3, says) {
@@ -7008,6 +7086,62 @@ function shellConditionKept(code3, says) {
7008
7086
  return null;
7009
7087
  }
7010
7088
  var ctx_full = "";
7089
+ function sliceOf(v) {
7090
+ if (v?.kind !== "index" || currentLang !== "python") return null;
7091
+ const path = (n) => n?.kind === "name" ? n.name : n?.kind === "member" ? path(n.object) ? `${path(n.object)}.${n.property}` : null : null;
7092
+ const p = path(v.object);
7093
+ const num3 = (x) => x == null ? void 0 : x.kind === "literal" && x.type === "number" ? String(x.raw ?? x.value) : x.kind === "unary" && x.op === "-" && x.value?.kind === "literal" ? `-${x.value.raw ?? x.value.value}` : NaN;
7094
+ const ix = v.index;
7095
+ let t = null;
7096
+ if (ix?.kind === "slice" && !ix.step) {
7097
+ const a = num3(ix.start), b = num3(ix.end);
7098
+ if (!Number.isNaN(a) && !Number.isNaN(b)) t = sliceWords(a, b);
7099
+ } else if (ix) {
7100
+ const k = num3(ix);
7101
+ if (k === "-1") t = sliceWords(void 0, void 0, "-1");
7102
+ }
7103
+ return p && t ? { path: p, words: t } : null;
7104
+ }
7105
+ function sliceSaid(sl, said) {
7106
+ const [pre, post] = sl.words.split("{x}").map((x) => x.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"));
7107
+ const at2 = said.indexOf(" to ");
7108
+ const m = at2 >= 0 && new RegExp(`^${pre}(?:the ([\\w ]+)'s )?([\\w ]+?)${post}$`).exec(said.slice(at2 + 4));
7109
+ return !!m && pathSaid(sl.path, m[1], m[2]);
7110
+ }
7111
+ function pathSaid(path, owner, last) {
7112
+ const parts = String(path).split(".").filter((x) => !/^(?:self|this)$/.test(x));
7113
+ if (!parts.length || !sameWords(parts[parts.length - 1], last)) return false;
7114
+ return parts.length > 1 ? !!owner && sameWords(parts[parts.length - 2], owner) : !owner;
7115
+ }
7116
+ function pythonRangeKept(v, argText, says) {
7117
+ const args = argText.split(",").map((x) => x.trim());
7118
+ const tail = "(?: \\(\\d+ steps? inside\\))?$";
7119
+ const P = "(?:the ([\\w ]+)'s )?([\\w ]+)";
7120
+ let w;
7121
+ if (args.length === 1 && v === "_") return new RegExp(`^Repeats ${args[0]} times${tail}`).test(says) && /^\w+$/.test(args[0]);
7122
+ const len2 = args.length === 1 && /^len\(\s*([A-Za-z_][\w.]*)\s*\)$/.exec(args[0]);
7123
+ if (len2) return !!(w = new RegExp(`^For each position (.+?) in ${P}${tail}`).exec(says)) && sameWords(w[1], v) && pathSaid(len2[1], w[2], w[3]);
7124
+ if (args.length === 2 && /^[A-Za-z_][\w.]*\s*\+\s*1$/.test(args[1]) && /^(?:\d+|[A-Za-z_][\w.]*)$/.test(args[0])) {
7125
+ w = new RegExp(`^Counts (.+?) from (.+?) to ${P}${tail}`).exec(says);
7126
+ if (!w || !sameWords(w[1], v) || / up to /.test(says)) return false;
7127
+ const from = /^\d+$/.test(args[0]) ? w[2] === args[0] : (() => {
7128
+ const p = new RegExp(`^${P}$`).exec(w[2]);
7129
+ return !!p && pathSaid(args[0], p[1], p[2]);
7130
+ })();
7131
+ return from && pathSaid(args[1].replace(/\s*\+\s*1$/, ""), w[3], w[4]);
7132
+ }
7133
+ const [a, b] = args.length === 1 ? ["0", args[0]] : args;
7134
+ if (args.length > 2 || !/^(?:\d+|[A-Za-z_][\w.]*)$/.test(a) || !/^(?:\d+|[A-Za-z_][\w.]*)$/.test(b)) return false;
7135
+ if (/^\d+$/.test(a) && /^\d+$/.test(b)) return !!(w = new RegExp(`^Counts (.+?) from (\\d+) to (\\d+)${tail}`).exec(says)) && sameWords(w[1], v) && w[2] === a && Number(w[3]) === Number(b) - 1 && Number(b) > Number(a);
7136
+ w = new RegExp(`^Counts (.+?) from (.+?) up to (.+?) \\(not (.+?) itself\\)${tail}`).exec(says);
7137
+ if (!w || !sameWords(w[1], v) || w[3] !== w[4]) return false;
7138
+ const side2 = (code3, said) => {
7139
+ if (/^\d+$/.test(code3)) return said === code3;
7140
+ const p = new RegExp(`^${P}$`).exec(said);
7141
+ return !!p && pathSaid(code3, p[1], p[2]);
7142
+ };
7143
+ return side2(a, w[2]) && side2(b, w[3]);
7144
+ }
7011
7145
  function repeatsKept(says, full) {
7012
7146
  const n = /^Repeats (\w+) times/.exec(says)[1];
7013
7147
  return new RegExp(`\\b${n}\\b`).test(full) && /\b(?:times|range|repeat|for|Repeat|seq|upto)\b|\.\./.test(full);
@@ -7023,32 +7157,54 @@ function loopKept(step, tree, says, code3, lang) {
7023
7157
  if (/^Runs once, then repeats/.test(says)) return doWhileKept(says, ctx_full, lang);
7024
7158
  if (/^Repeats (\w+) times/.test(says)) return repeatsKept(says, ctx_full) ? null : WHY.form;
7025
7159
  if (/^`/.test(says) || /^Repeats (?:for|while) `/.test(says)) return null;
7160
+ let m;
7161
+ if (lang === "python" && (m = /^for\s+(\w+)\s+in\s+range\((.*)\)\s*:$/.exec(String(code3).trim()))) return pythonRangeKept(m[1], m[2], says) ? null : WHY.unparsed;
7162
+ if (lang === "python" && (m = /^for\s+\(?\s*(\w+)\s*,\s*(\w+)\s*\)?\s+in\s+enumerate\(\s*([A-Za-z_][\w.]*)\s*\)\s*:$/.exec(String(code3).trim()))) {
7163
+ const w = /^For each (.+?) in (?:the ([\w ]+)'s )?([\w ]+), with its position (.+?) \(from 0\)(?: \(\d+ steps? inside\))?$/.exec(says);
7164
+ return w && sameWords(w[1], m[2]) && sameWords(w[4], m[1]) && pathSaid(m[3], w[2], w[3]) ? null : WHY.unparsed;
7165
+ }
7166
+ if (lang === "rust" && (m = /^for\s+(\w+)\s+in\s+(\d+|[A-Za-z_][\w.]*)\s*\.\.(=?)\s*(\d+|[A-Za-z_][\w.]*)\s*\{?$/.exec(String(code3).trim()))) {
7167
+ const [, v, a, inc, b] = m;
7168
+ const P = "(?:the ([\\w ]+)'s )?([\\w ]+)";
7169
+ const side2 = (c, said) => {
7170
+ if (/^\d+$/.test(c)) return said === c;
7171
+ const p = new RegExp(`^${P}$`).exec(said);
7172
+ return !!p && pathSaid(c, p[1], p[2]);
7173
+ };
7174
+ const tail = "(?: \\(\\d+ steps? inside\\))?$";
7175
+ if (/^\d+$/.test(a) && /^\d+$/.test(b) && !inc) {
7176
+ const w2 = new RegExp(`^Counts (.+?) from (\\d+) to (\\d+)${tail}`).exec(says);
7177
+ return w2 && sameWords(w2[1], v) && w2[2] === a && Number(w2[3]) === Number(b) - 1 ? null : WHY.unparsed;
7178
+ }
7179
+ const w = inc ? new RegExp(`^Counts (.+?) from (.+?) to (.+?)${tail}`).exec(says) : new RegExp(`^Counts (.+?) from (.+?) up to (.+?) \\(not (.+?) itself\\)${tail}`).exec(says);
7180
+ return w && sameWords(w[1], v) && (inc ? !/ up to /.test(says) : w[3] === w[4]) && side2(a, w[2]) && side2(b, w[3]) ? null : WHY.unparsed;
7181
+ }
7026
7182
  if (tree && tree.kind === "loop") {
7027
7183
  if (tree.form === "each") {
7028
- const m = /^For each (.+?) in (.+?)(?:, only those where .*)?(?: \(\d+ steps? inside\))?$/.exec(says);
7184
+ const m3 = /^For each (.+?) in (.+?)(?:, only those where .*)?(?: \(\d+ steps? inside\))?$/.exec(says);
7029
7185
  if (/^(?:For each item in|Repeats once for each item in)/.test(says)) return iterableKept(tree.iterable, says.replace(/^.*? in /, "").replace(/ \(\d+ steps? inside\)$/, "")) ? null : M("L411");
7030
- if (!m) return WHY.form;
7031
- for (const t of tree.targets) if (!namesKept(t, m[1])) return M("L413");
7032
- return iterableKept(tree.iterable, m[2]) ? null : M("L416");
7186
+ if (!m3) return WHY.form;
7187
+ for (const t of tree.targets) if (!namesKept(t, m3[1])) return M("L413");
7188
+ return iterableKept(tree.iterable, m3[2]) ? null : M("L416");
7033
7189
  }
7034
7190
  if (tree.form === "while" || tree.form === "until") {
7035
7191
  if (/^Repeats until (?:something|a step) inside/.test(says)) return tree.test?.kind === "literal" && (tree.test.value === true || tree.test.value === 1) ? null : WHY.form;
7036
- const m = /^(?:Repeats while|Runs once, then repeats while|Repeats until) (.+?)(?: \(\d+ steps? inside\))?$/.exec(says);
7037
- if (!m) return WHY.form;
7192
+ const m3 = /^(?:Repeats while|Runs once, then repeats while|Repeats until) (.+?)(?: \(\d+ steps? inside\))?$/.exec(says);
7193
+ if (!m3) return WHY.form;
7038
7194
  const neg = /^Repeats until/.test(says) !== (tree.form === "until");
7039
- return conditionCore(neg ? { kind: "not", value: tree.test } : tree.test, m[1], code3, lang);
7195
+ return conditionCore(neg ? { kind: "not", value: tree.test } : tree.test, m3[1], code3, lang);
7040
7196
  }
7041
7197
  if (tree.form === "for") {
7042
- const m = /^Counts (\w[\w ]*?) from (.+?) while (.+?)(?:, (?:adding|in steps of|going) (.+?))?(?: \(\d+ steps? inside\))?$/.exec(says);
7043
- if (!m) return /^Repeats until (?:something|a step) inside/.test(says) && !tree.test ? null : WHY.form;
7198
+ const m3 = /^Counts (\w[\w ]*?) from (.+?) while (.+?)(?:, (?:adding|in steps of|going) (.+?))?(?: \(\d+ steps? inside\))?$/.exec(says);
7199
+ if (!m3) return /^Repeats until (?:something|a step) inside/.test(says) && !tree.test ? null : WHY.form;
7044
7200
  const init = tree.init, upd = tree.update;
7045
7201
  const v = init?.kind === "assign" ? init.target : null;
7046
- if (!v || v.kind !== "name" || !sameWords(v.name, m[1])) return M("L429");
7202
+ if (!v || v.kind !== "name" || !sameWords(v.name, m3[1])) return M("L429");
7047
7203
  if (!upd || !(upd.kind === "unary" && /^(?:\+\+|--)$/.test(upd.op) && upd.value.kind === "name" && upd.value.name === v.name)) {
7048
- if (!m[4]) return M("L431");
7204
+ if (!m3[4]) return M("L431");
7049
7205
  } else if (upd.op === "--" && !/\bdown\b|\bsubtract/.test(says)) return M("L432");
7050
- if (!namesKept(init.value, m[2]) && !/^-?\d+$/.test(m[2].trim())) return M("L433");
7051
- return conditionCore(tree.test, m[3], code3, lang);
7206
+ if (!namesKept(init.value, m3[2]) && !/^-?\d+$/.test(m3[2].trim())) return M("L433");
7207
+ return conditionCore(tree.test, m3[3], code3, lang);
7052
7208
  }
7053
7209
  if (tree.form === "forever") return /^Repeats until/.test(says) ? null : WHY.form;
7054
7210
  if (/^Repeats (\w+) times/.test(says)) return repeatsKept(says, ctx_full) ? null : WHY.form;
@@ -7059,13 +7215,19 @@ function loopKept(step, tree, says, code3, lang) {
7059
7215
  if (/\bwhile\b[^;]*\bread\b(?:\s+-\w+)*\s+\w+\s+\w+/.test(code3) || /;\s*read\b/.test(code3)) return WHY.form;
7060
7216
  return null;
7061
7217
  }
7062
- function iterableKept(it, words13) {
7218
+ function iterableKept(it, words14) {
7063
7219
  if (!it) return false;
7064
- if (namesKept(it, words13)) return true;
7065
- const w = ` ${splitWords(words13).join(" ")} `;
7220
+ const ro = /^the result of ([\w ]+)$/.exec(words14);
7221
+ if (ro) {
7222
+ const c2 = coreOf(it);
7223
+ const n = c2?.kind === "call" ? c2.callee.kind === "member" ? c2.callee.property : c2.callee.name : null;
7224
+ return !!n && sameWords(n, ro[1]);
7225
+ }
7226
+ if (namesKept(it, words14)) return true;
7227
+ const w = ` ${splitWords(words14).join(" ")} `;
7066
7228
  let c = coreOf(it);
7067
- if (c?.kind === "member" && w.includes(` ${splitWords(c.property).join(" ")} `) && splitWords(words13).length <= splitWords(c.property).length + 1) return true;
7068
- return chainCallees(it).some((x) => sameWords(x, words13) || w.includes(` ${splitWords(x).join(" ")} `));
7229
+ if (c?.kind === "member" && w.includes(` ${splitWords(c.property).join(" ")} `) && splitWords(words14).length <= splitWords(c.property).length + 1) return true;
7230
+ return chainCallees(it).some((x) => sameWords(x, words14) || w.includes(` ${splitWords(x).join(" ")} `));
7069
7231
  }
7070
7232
  function callLoopKept(tree, says) {
7071
7233
  const callees = chainCallees(tree);
@@ -7146,6 +7308,7 @@ function safeForm(step, says, code3, lang = "") {
7146
7308
  }
7147
7309
  if ((m = /^(?:(?:let|const|static|var|val|final|readonly)\s+)?(?:mut\s+)?([A-Za-z_]\w*)\s*(?::[^=]+)?=\s*("(?:\\.|[^"\\])*"|-?\d+(?:\.\d+)?|true|false)\s*;?$/.exec(c)) && says === `Sets ${splitWords(m[1]).join(" ")} to ${m[2]}`) return null;
7148
7310
  if ((m = /^(?:(?:let|const|static|var|val)\s+)?(?:mut\s+)?([A-Za-z_]\w*)\s*(?::[^=]+)?=\s*(?:r#*)?"(?:\\.|[^"\\])*\\?$/.exec(c)) && says === `Sets ${splitWords(m[1]).join(" ")} to a text written over several lines`) return null;
7311
+ if (lang === "python" && /^(?:from|import)\s/.test(c)) return pythonImportSays(c) === says ? null : WHY.unparsed;
7149
7312
  if (m = /^(?:const|let|var)\s*\{([^}]*)\}\s*=\s*(?:await\s+)?(?:import|require)\(\s*['"`]([^'"`]+)['"`]\s*\)/.exec(c)) {
7150
7313
  const w = /^Loads (.+) from (\S+)$/.exec(says);
7151
7314
  return w && w[2] === m[2] && m[1].split(",").every((x) => x.trim() && ` ${splitWords(w[1]).join(" ")} `.includes(` ${splitWords(x.split(":").pop()).join(" ")} `)) ? null : WHY.unparsed;
@@ -7188,7 +7351,7 @@ function safeForm(step, says, code3, lang = "") {
7188
7351
  if (!w || KEYWORD_CALLEE.test(lastName(m[2]))) return WHY.unparsed;
7189
7352
  const tw = w[1].replace(/^the (?:[\w ]+?'s )?/, "");
7190
7353
  if (!sameWords(target, tw) && !sameWords(m[1].replace(/->/g, "."), w[1])) return WHY.unparsed;
7191
- if (w[2] && !sameWords(lastName(m[2]), w[2])) return WHY.unparsed;
7354
+ if (w[2] && !callNamed(lastName(m[2]), w[2], c)) return WHY.unparsed;
7192
7355
  return null;
7193
7356
  }
7194
7357
  if (step.kind === "return" && (m = /^return\s+(?:\([A-Za-z_][\w\s*]*\)\s*)?(?:await\s+)?([A-Za-z_][\w]*(?:\s*(?:\.|->|::)\s*[A-Za-z_][\w]*)*)\s*(\()?/.exec(c))) {
@@ -7695,11 +7858,11 @@ function lexSql(src, from = 0, to = src.length, dialect = "pg") {
7695
7858
  continue;
7696
7859
  }
7697
7860
  if (c === "$" && dialect === "pg") {
7698
- const m2 = /^\$([A-Za-z_][\w]*)?\$/.exec(src.slice(i, i + 66));
7699
- if (m2) {
7700
- const close = src.indexOf(m2[0], i + m2[0].length);
7701
- const e = close < 0 || close + m2[0].length > to ? to : close + m2[0].length;
7702
- toks.push({ t: "str", dollar: m2[0], v: src.slice(i, e), s: i, e });
7861
+ const m3 = /^\$([A-Za-z_][\w]*)?\$/.exec(src.slice(i, i + 66));
7862
+ if (m3) {
7863
+ const close = src.indexOf(m3[0], i + m3[0].length);
7864
+ const e = close < 0 || close + m3[0].length > to ? to : close + m3[0].length;
7865
+ toks.push({ t: "str", dollar: m3[0], v: src.slice(i, e), s: i, e });
7703
7866
  i = e;
7704
7867
  continue;
7705
7868
  }
@@ -8752,10 +8915,10 @@ function sqlDialect(src) {
8752
8915
  return "pg";
8753
8916
  }
8754
8917
  var ROUTINE_WORDS = ["FUNCTION", "PROCEDURE", "PROC"];
8755
- function sqlRoutines(src, lineAt3, dialect = sqlDialect(src)) {
8918
+ function sqlRoutines(src, lineAt4, dialect = sqlDialect(src)) {
8756
8919
  const toks = lexSql(src, 0, src.length, dialect);
8757
8920
  const out = [];
8758
- const lineOf6 = (k) => lineAt3(toks[Math.min(k, toks.length - 1)].s);
8921
+ const lineOf6 = (k) => lineAt4(toks[Math.min(k, toks.length - 1)].s);
8759
8922
  for (let k = 0; k < toks.length; k++) {
8760
8923
  const start = k;
8761
8924
  let j = k;
@@ -8901,7 +9064,7 @@ function sqlRoutines(src, lineAt3, dialect = sqlDialect(src)) {
8901
9064
  }
8902
9065
  }
8903
9066
  let steps = [], bodyEnd3 = end;
8904
- const ctx = { src, lineAt: lineAt3, dialect: bodyDialect, routine, setof, trigger, depth: 0 };
9067
+ const ctx = { src, lineAt: lineAt4, dialect: bodyDialect, routine, setof, trigger, depth: 0 };
8905
9068
  try {
8906
9069
  if (dialect === "pg") {
8907
9070
  if (bodyToks && language !== "c" && language !== "internal") {
@@ -9107,7 +9270,7 @@ function sqlCondition(cond, { aliases = {}, vars = false, keepAt = true, raw = f
9107
9270
  }
9108
9271
  function readSchema(src) {
9109
9272
  const m = mask(src);
9110
- const lineAt3 = lineFinder(src);
9273
+ const lineAt4 = lineFinder(src);
9111
9274
  const tables = [], choices = [], rules = [];
9112
9275
  const docs = /* @__PURE__ */ new Map();
9113
9276
  for (const c of src.matchAll(/COMMENT\s+ON\s+TABLE\s+([\w."]+)\s+IS\s+'((?:[^']|'')*)'/gi)) docs.set(bare(c[1]).toLowerCase(), c[2].replace(/''/g, "'"));
@@ -9116,10 +9279,10 @@ function readSchema(src) {
9116
9279
  const close = parenEnd(m, open);
9117
9280
  if (close < 0) continue;
9118
9281
  const name = bare(src.slice(t.index, open).match(/([\w."[\]`]+)\s*$/)[1]);
9119
- const table = { name, lines: [lineAt3(t.index), lineAt3(close)], doc: docs.get(name.toLowerCase()) ?? docAbove(src, t.index), columns: [], checks: [], uniques: [], refs: [] };
9282
+ const table = { name, lines: [lineAt4(t.index), lineAt4(close)], doc: docs.get(name.toLowerCase()) ?? docAbove(src, t.index), columns: [], checks: [], uniques: [], refs: [] };
9120
9283
  for (const part of splitTop(src.slice(open + 1, close), m.slice(open + 1, close))) {
9121
9284
  const text2 = part.text.trim().replace(/\s+/g, " ");
9122
- const line = lineAt3(open + 1 + part.at + (part.text.length - part.text.trimStart().length));
9285
+ const line = lineAt4(open + 1 + part.at + (part.text.length - part.text.trimStart().length));
9123
9286
  let x;
9124
9287
  if (x = text2.match(/^(?:CONSTRAINT\s+([\w"]+)\s+)?CHECK\s*\((.*)\)$/i)) {
9125
9288
  table.checks.push({ name: x[1] && unquote(x[1]), cond: x[2], line });
@@ -9152,7 +9315,7 @@ function readSchema(src) {
9152
9315
  const close = parenEnd(m, open);
9153
9316
  if (close < 0) continue;
9154
9317
  const values = [...src.slice(open + 1, close).matchAll(/'((?:[^']|'')*)'/g)].map((v) => v[1].replace(/''/g, "'").replace(/_/g, " "));
9155
- choices.push({ name: bare(e[1]), lines: [lineAt3(e.index), lineAt3(close)], doc: docAbove(src, e.index), values });
9318
+ choices.push({ name: bare(e[1]), lines: [lineAt4(e.index), lineAt4(close)], doc: docAbove(src, e.index), values });
9156
9319
  }
9157
9320
  for (const t of tables) {
9158
9321
  for (const c of t.checks) rules.push({ table: t.name, kind: "check", ...c });
@@ -9255,7 +9418,7 @@ function sqlTemplateReason(src) {
9255
9418
  }
9256
9419
  function sqlItems(src) {
9257
9420
  const m = mask(src);
9258
- const lineAt3 = lineFinder(src);
9421
+ const lineAt4 = lineFinder(src);
9259
9422
  const items = [];
9260
9423
  const push = (name, line, steps, extra = {}) => {
9261
9424
  const code3 = steps.filter((s) => s.kind === "other").length;
@@ -9285,9 +9448,9 @@ function sqlItems(src) {
9285
9448
  const end = m.indexOf(";", v.index);
9286
9449
  const query = src.slice(v.index + v[0].length, end < 0 ? src.length : end);
9287
9450
  const name = bare(v[1]);
9288
- push(name, lineAt3(v.index), selectSteps(query, lineAt3(v.index + v[0].length)), { doc: docAbove(src, v.index), endLine: lineAt3(end < 0 ? src.length : end), says: `${words2(name)} is a saved query.`, headline: `${words2(name)}: a saved query.` });
9451
+ push(name, lineAt4(v.index), selectSteps(query, lineAt4(v.index + v[0].length)), { doc: docAbove(src, v.index), endLine: lineAt4(end < 0 ? src.length : end), says: `${words2(name)} is a saved query.`, headline: `${words2(name)}: a saved query.` });
9289
9452
  }
9290
- for (const r of sqlRoutines(src, lineAt3)) {
9453
+ for (const r of sqlRoutines(src, lineAt4)) {
9291
9454
  const inputs = r.inputs.map(({ name, type }) => ({ name, type }));
9292
9455
  const returns = r.returns ?? (r.outs.length ? listWords(r.outs.map((o) => words2(o.name))) : null);
9293
9456
  const steps = r.unreadWhy ? [] : r.steps;
@@ -9305,7 +9468,7 @@ function sqlItems(src) {
9305
9468
  const events = t[3].split(/\s+OR\s+/i).map((e) => ({ INSERT: "added", UPDATE: "changed", DELETE: "removed", TRUNCATE: "emptied" })[e.trim().split(/\s+/)[0].toUpperCase()] || words2(e)).filter(Boolean);
9306
9469
  const what = article(singular(words2(bare(t[4]))));
9307
9470
  const when = `${t[2].toUpperCase() === "BEFORE" ? "Before" : t[2].toUpperCase() === "AFTER" ? "After" : "Instead of when"} ${what} is ${events.join(" or ")}`;
9308
- push(bare(t[1]), lineAt3(t.index), [{ kind: "call", says: `${when}, runs ${words2(bare(t[5]))}`, code: t[0].replace(/\s+/g, " "), line: lineAt3(t.index) }], { says: `${when}, the database runs ${words2(bare(t[5]))}.`, headline: `${when}.`, doc: docAbove(src, t.index) });
9471
+ push(bare(t[1]), lineAt4(t.index), [{ kind: "call", says: `${when}, runs ${words2(bare(t[5]))}`, code: t[0].replace(/\s+/g, " "), line: lineAt4(t.index) }], { says: `${when}, the database runs ${words2(bare(t[5]))}.`, headline: `${when}.`, doc: docAbove(src, t.index) });
9309
9472
  }
9310
9473
  for (const r of readSchema(src).rules) {
9311
9474
  const table = words2(r.table);
@@ -9575,8 +9738,8 @@ function clause(n, negate = false) {
9575
9738
  const path = l.path ?? r.path, lit4 = l.path ? r.lit : l.lit;
9576
9739
  const isNot = n.cmp === "!=" !== negate;
9577
9740
  if (["<", ">", "<=", ">="].includes(n.cmp)) {
9578
- const words13 = { "<": "less than", ">": "more than", "<=": "at most", ">=": "at least" }[n.cmp];
9579
- return `${valueOf(l)} is ${negate ? "not " : ""}${words13} ${valueOf(r)}`;
9741
+ const words14 = { "<": "less than", ">": "more than", "<=": "at most", ">=": "at least" }[n.cmp];
9742
+ return `${valueOf(l)} is ${negate ? "not " : ""}${words14} ${valueOf(r)}`;
9580
9743
  }
9581
9744
  if (path === "github.ref" && lit4 != null) {
9582
9745
  if (lit4.startsWith("refs/heads/")) return `the branch is ${isNot ? "not " : ""}${lit4.slice(11)}`;
@@ -9860,16 +10023,16 @@ function commandSays(cmd) {
9860
10023
  if (SECRET_NAME.test(m[1]) && v && !/\$/.test(v)) return { kind: "set", says: `Sets ${m[1]} (its value is written here, not shown)` };
9861
10024
  return { kind: "set", says: `Sets ${m[1]} to ${v.replace(/^["']|["']$/g, "") || "nothing"}` };
9862
10025
  }
9863
- let words13 = shellWords(text2);
9864
- while (words13.length > 1 && (/^[A-Za-z_]\w*=/.test(words13[0]) || words13[0] === "sudo" || words13[0] === "time" || words13[0] === "exec" || words13[0] === "command")) words13.shift();
10026
+ let words14 = shellWords(text2);
10027
+ while (words14.length > 1 && (/^[A-Za-z_]\w*=/.test(words14[0]) || words14[0] === "sudo" || words14[0] === "time" || words14[0] === "exec" || words14[0] === "command")) words14.shift();
9865
10028
  const redir = [];
9866
- for (let i = 0; i < words13.length; i++) {
9867
- const w = words13[i];
10029
+ for (let i = 0; i < words14.length; i++) {
10030
+ const w = words14[i];
9868
10031
  const r2 = /^(\d?>>?|&>|<)(.*)$/.exec(w);
9869
10032
  if (!r2 || w === ">" && false) continue;
9870
- const target = r2[2] || words13[i + 1] || "";
10033
+ const target = r2[2] || words14[i + 1] || "";
9871
10034
  redir.push({ op: r2[1], target });
9872
- words13.splice(i, r2[2] ? 1 : 2);
10035
+ words14.splice(i, r2[2] ? 1 : 2);
9873
10036
  i--;
9874
10037
  }
9875
10038
  for (const r2 of redir) {
@@ -9880,7 +10043,7 @@ function commandSays(cmd) {
9880
10043
  else if (/GITHUB_STEP_SUMMARY/.test(t)) tail = "summary";
9881
10044
  else if (r2.op.includes(">") && !/^\/dev\/(null|stderr|stdout)$|^&\d$/.test(t) && t) tail = tail || `file:${t}`;
9882
10045
  }
9883
- let [tool0, ...args] = words13;
10046
+ let [tool0, ...args] = words14;
9884
10047
  if (tool0 === "[" || tool0 === "[[" || tool0 === "test") return { kind: "check", says: `Checks: ${lc(shellQuestion(text2))}` };
9885
10048
  if (!tool0) return { kind: "call", says: `Runs \`${short(text2)}\`` };
9886
10049
  const tool = tool0.replace(/^.*\//, "");
@@ -11739,7 +11902,7 @@ function scanInterp(src, j, dialect) {
11739
11902
  }
11740
11903
  return j;
11741
11904
  }
11742
- function tokenize2(src, dialect, from = 0, to = src.length, lineAt3 = lineIndex(src)) {
11905
+ function tokenize2(src, dialect, from = 0, to = src.length, lineAt4 = lineIndex(src)) {
11743
11906
  const hcl = dialect === "hcl";
11744
11907
  const toks = [], comments = [];
11745
11908
  let i = from;
@@ -11757,14 +11920,14 @@ function tokenize2(src, dialect, from = 0, to = src.length, lineAt3 = lineIndex(
11757
11920
  if (c === "#" || c === "/" && src[i + 1] === "/") {
11758
11921
  let j = i;
11759
11922
  while (j < to && src[j] !== "\n") j++;
11760
- comments.push({ line: lineAt3(i), endLine: lineAt3(i), text: src.slice(i, j).replace(/^(#|\/\/)\s?/, "").trim(), s: i });
11923
+ comments.push({ line: lineAt4(i), endLine: lineAt4(i), text: src.slice(i, j).replace(/^(#|\/\/)\s?/, "").trim(), s: i });
11761
11924
  i = j;
11762
11925
  continue;
11763
11926
  }
11764
11927
  if (c === "/" && src[i + 1] === "*") {
11765
11928
  let j = src.indexOf("*/", i + 2);
11766
11929
  if (j < 0 || j > to) j = to - 2;
11767
- comments.push({ line: lineAt3(i), endLine: lineAt3(j), text: src.slice(i + 2, j).replace(/^\s*\*+/gm, "").trim(), s: i });
11930
+ comments.push({ line: lineAt4(i), endLine: lineAt4(j), text: src.slice(i + 2, j).replace(/^\s*\*+/gm, "").trim(), s: i });
11768
11931
  i = j + 2;
11769
11932
  continue;
11770
11933
  }
@@ -11839,12 +12002,12 @@ function tokenize2(src, dialect, from = 0, to = src.length, lineAt3 = lineIndex(
11839
12002
  }
11840
12003
  var BIN = { "??": 1, "||": 2, "&&": 3, "==": 4, "!=": 4, "=~": 4, "!~": 4, "<": 5, ">": 5, "<=": 5, ">=": 5, "+": 6, "-": 6, "*": 7, "/": 7, "%": 7 };
11841
12004
  var Parser2 = class _Parser {
11842
- constructor(src, toks, dialect, lineAt3, hooks = {}) {
12005
+ constructor(src, toks, dialect, lineAt4, hooks = {}) {
11843
12006
  this.src = src;
11844
12007
  this.toks = toks;
11845
12008
  this.i = 0;
11846
12009
  this.dialect = dialect;
11847
- this.lineAt = lineAt3;
12010
+ this.lineAt = lineAt4;
11848
12011
  this.hooks = hooks;
11849
12012
  this.skipNl = [false];
11850
12013
  }
@@ -12357,9 +12520,9 @@ function docAbove2(comments, line) {
12357
12520
  }
12358
12521
  function parseHcl(src) {
12359
12522
  const text2 = String(src ?? "").replace(/^/, "");
12360
- const lineAt3 = lineIndex(text2);
12361
- const { toks, comments } = tokenize2(text2, "hcl", 0, text2.length, lineAt3);
12362
- const p = new Parser2(text2, toks, "hcl", lineAt3);
12523
+ const lineAt4 = lineIndex(text2);
12524
+ const { toks, comments } = tokenize2(text2, "hcl", 0, text2.length, lineAt4);
12525
+ const p = new Parser2(text2, toks, "hcl", lineAt4);
12363
12526
  const errors = [];
12364
12527
  const body2 = [];
12365
12528
  for (; ; ) {
@@ -12374,7 +12537,7 @@ function parseHcl(src) {
12374
12537
  p.i = resync(toks, start);
12375
12538
  }
12376
12539
  }
12377
- return { body: body2, comments, errors, lineAt: lineAt3, src: text2 };
12540
+ return { body: body2, comments, errors, lineAt: lineAt4, src: text2 };
12378
12541
  }
12379
12542
  function resync(toks, i) {
12380
12543
  let depth = 0, seen = false;
@@ -12839,8 +13002,8 @@ function tfRefWords(ref) {
12839
13002
  default: {
12840
13003
  const t = tfTarget(ref);
12841
13004
  if (!t) return p.length === 1 ? `the value ${p[0]}` : null;
12842
- const attr = rest2(2);
12843
- return `${attr ? `the ${attr} of ` : ""}the ${typeWords2(p[0])} ${p[1]}`;
13005
+ const attr2 = rest2(2);
13006
+ return `${attr2 ? `the ${attr2} of ` : ""}the ${typeWords2(p[0])} ${p[1]}`;
12844
13007
  }
12845
13008
  }
12846
13009
  }
@@ -13369,9 +13532,9 @@ function ingressFacts(d, fact) {
13369
13532
  // src/bicep.mjs
13370
13533
  function parseBicep(src) {
13371
13534
  const text2 = String(src ?? "").replace(/^/, "");
13372
- const lineAt3 = lineIndex(text2);
13373
- const { toks, comments } = tokenize2(text2, "bicep", 0, text2.length, lineAt3);
13374
- const p = new Parser2(text2, toks, "bicep", lineAt3, { objectKey: nestedResource });
13535
+ const lineAt4 = lineIndex(text2);
13536
+ const { toks, comments } = tokenize2(text2, "bicep", 0, text2.length, lineAt4);
13537
+ const p = new Parser2(text2, toks, "bicep", lineAt4, { objectKey: nestedResource });
13375
13538
  const decls = [], errors = [];
13376
13539
  let decorators = [];
13377
13540
  for (; ; ) {
@@ -13400,7 +13563,7 @@ function parseBicep(src) {
13400
13563
  decorators = [];
13401
13564
  }
13402
13565
  }
13403
- return { decls, comments, errors, lineAt: lineAt3, src: text2 };
13566
+ return { decls, comments, errors, lineAt: lineAt4, src: text2 };
13404
13567
  }
13405
13568
  function resync2(toks, i) {
13406
13569
  let depth = 0;
@@ -13618,16 +13781,16 @@ function readBicep(src, file = "main.bicep") {
13618
13781
  }
13619
13782
  if (n.t !== "ref") return null;
13620
13783
  const [root, ...rest2] = n.path;
13621
- const attr = rest2.filter((x) => x !== "properties" && x !== "*" && !x.startsWith("[")).map(words5).join(" ");
13622
- if (params.has(root)) return `the setting ${root}${attr ? `'s ${attr}` : ""}`;
13623
- if (vars.has(root)) return `the value ${root}${attr ? `'s ${attr}` : ""}`;
13624
- if (loopVars.has(root)) return attr ? `each item's ${attr}` : "each item";
13784
+ const attr2 = rest2.filter((x) => x !== "properties" && x !== "*" && !x.startsWith("[")).map(words5).join(" ");
13785
+ if (params.has(root)) return `the setting ${root}${attr2 ? `'s ${attr2}` : ""}`;
13786
+ if (vars.has(root)) return `the value ${root}${attr2 ? `'s ${attr2}` : ""}`;
13787
+ if (loopVars.has(root)) return attr2 ? `each item's ${attr2}` : "each item";
13625
13788
  const child = rest2[0] && bySym.get(rest2[0])?.parent === root ? rest2[0] : null;
13626
13789
  if (child) return refWords({ t: "ref", path: n.path.slice(1) });
13627
13790
  const r = bySym.get(root);
13628
13791
  if (r) {
13629
13792
  if (r.kind === "module") return rest2[0] === "outputs" && rest2[1] ? `the ${words5(rest2[1])} from the module ${root}` : `the module ${root}`;
13630
- return `${attr ? `the ${attr} of ` : ""}the ${r.existing ? "existing " : ""}${typeWords2(r.type)} ${root}`;
13793
+ return `${attr2 ? `the ${attr2} of ` : ""}the ${r.existing ? "existing " : ""}${typeWords2(r.type)} ${root}`;
13631
13794
  }
13632
13795
  return null;
13633
13796
  };
@@ -15157,6 +15320,11 @@ var URL_WORDS = (u) => {
15157
15320
  if (/^["'`]/.test(t)) return t.slice(1, -1).replace(/\$\{[^}]*\}/g, "\u2026");
15158
15321
  return /^[A-Za-z_][\w.]*$/.test(t) ? `the ${words6(t.split(".").pop()).replace(/\burl\b/, "URL")}` : "an address worked out by the code";
15159
15322
  };
15323
+ var FILE_WORDS = (u) => {
15324
+ const t = String(u || "").trim();
15325
+ if (/^["'`]/.test(t)) return t.slice(1, -1).replace(/\$\{[^}]*\}/g, "\u2026");
15326
+ return /^[A-Za-z_][\w.]*$/.test(t) ? `at ${t.includes(".") ? `the ${words6(t.split(".").pop())}` : words6(t)}` : "at a path worked out by the code";
15327
+ };
15160
15328
  function derivedWhose(name, args) {
15161
15329
  const m = name.match(/^(?:find|get|read|query|search|stream|count|exists|delete|remove)(?:All|First|Top\d*|One)?By(\w+)$/);
15162
15330
  if (!m) return null;
@@ -15274,9 +15442,9 @@ var CATALOG = [
15274
15442
  { re: /^json\s*\.\s*Marshal\s*\(\s*(.+)\)$/, say: (m) => ({ says: `Turns ${valueWords3(m[1])} into JSON`, does: "calculate" }) },
15275
15443
  { re: /^json\s*\.\s*Unmarshal\s*\(\s*[^,]+,\s*&?(\w+)\s*\)$/, say: (m) => ({ says: `Reads the JSON into ${words6(m[1])}`, does: "calculate" }) },
15276
15444
  { re: /^json\s*\.\s*NewDecoder\s*\(\s*r\.Body\s*\)\s*\.\s*Decode\s*\(\s*&?(\w+)\s*\)$/, say: (m) => ({ says: `Reads what it was sent into ${words6(m[1])}`, does: "calculate" }) },
15277
- { re: /^(?:fs|fsp|fs\.promises)\s*\.\s*(readFile|readFileSync)\s*\(\s*([^,)]+)/, say: (m) => ({ says: `Reads the file ${URL_WORDS(m[2])}`, does: "find" }) },
15278
- { re: /^(?:fs|fsp|fs\.promises)\s*\.\s*(writeFile|writeFileSync|appendFile|appendFileSync)\s*\(\s*([^,)]+)/, say: (m) => ({ says: `${/append/.test(m[1]) ? "Adds to" : "Writes"} the file ${URL_WORDS(m[2])}`, does: "save" }) },
15279
- { re: /^(?:fs|fsp|fs\.promises)\s*\.\s*(unlink|unlinkSync|rm|rmSync)\s*\(\s*([^,)]+)/, say: (m) => ({ says: `Removes the file ${URL_WORDS(m[2])}`, does: "save" }) },
15445
+ { re: /^(?:fs|fsp|fs\.promises)\s*\.\s*(readFile|readFileSync)\s*\(\s*([^,)]+)/, say: (m) => ({ says: `Reads the file ${FILE_WORDS(m[2])}`, does: "find" }) },
15446
+ { re: /^(?:fs|fsp|fs\.promises)\s*\.\s*(writeFile|writeFileSync|appendFile|appendFileSync)\s*\(\s*([^,)]+)/, say: (m) => ({ says: `${/append/.test(m[1]) ? "Adds to" : "Writes"} the file ${FILE_WORDS(m[2])}`, does: "save" }) },
15447
+ { re: /^(?:fs|fsp|fs\.promises)\s*\.\s*(unlink|unlinkSync|rm|rmSync)\s*\(\s*([^,)]+)/, say: (m) => ({ says: `Removes the file ${FILE_WORDS(m[2])}`, does: "save" }) },
15280
15448
  { re: /^(?:Date\.now|datetime\.now|datetime\.utcnow|time\.Now|DateTime\.Now|DateTime\.UtcNow|Instant\.now|LocalDateTime\.now|Time\.now)\s*\(?\s*\)?$/, say: () => ({ says: "the current time", does: "calculate", value: true }) }
15281
15449
  ];
15282
15450
  function sayLibraryCall(expr) {
@@ -15423,6 +15591,33 @@ var KNOWN_CALLS = [
15423
15591
  { re: /^(?:events?|bus|publisher|emitter|queue)\.(?:publish|emit|send|enqueue|push)$/i, say: () => "Announces an event" },
15424
15592
  { re: /^(?:log|logger|console|logging|fmt|Log|System\.out|println|print|puts|echo|printf|fprintf|fputs|perror|NSLog|os_log|debugPrint|syslog|std\.(?:cout|cerr|print|println))\b/i, say: () => "Writes a log or message" }
15425
15593
  ];
15594
+ function pythonRangeWords(v, argText) {
15595
+ const args = splitTopArgs(argText).map((x) => x.trim());
15596
+ const plainPath = (x) => /^[A-Za-z_][\w.]*$/.test(x);
15597
+ const num3 = (x) => /^\d+$/.test(x);
15598
+ if (args.length === 1) {
15599
+ const n = args[0];
15600
+ if (v === "_") return /^\w+$/.test(n) ? `Repeats ${n} times` : null;
15601
+ const len2 = /^len\(\s*([A-Za-z_][\w.]*)\s*\)$/.exec(n);
15602
+ if (len2) return `For each position ${words7(v)} in ${possessiveWords(len2[1])}`;
15603
+ if (num3(n)) return Number(n) > 0 ? `Counts ${words7(v)} from 0 to ${Number(n) - 1}` : null;
15604
+ if (plainPath(n)) return `Counts ${words7(v)} from 0 up to ${possessiveWords(n)} (not ${possessiveWords(n)} itself)`;
15605
+ return null;
15606
+ }
15607
+ if (args.length === 2 && v !== "_" && /^(?:\d+|[A-Za-z_][\w.]*)$/.test(args[0]) && /^[A-Za-z_][\w.]*\s*\+\s*1$/.test(args[1])) {
15608
+ const end = args[1].replace(/\s*\+\s*1$/, "");
15609
+ return `Counts ${words7(v)} from ${num3(args[0]) ? args[0] : possessiveWords(args[0])} to ${possessiveWords(end)}`;
15610
+ }
15611
+ if (args.length === 2 && v !== "_") {
15612
+ const [a, b] = args;
15613
+ if (num3(a) && num3(b)) return Number(b) > Number(a) ? `Counts ${words7(v)} from ${a} to ${Number(b) - 1}` : null;
15614
+ if ((num3(a) || plainPath(a)) && (num3(b) || plainPath(b))) {
15615
+ const say = (x) => num3(x) ? x : possessiveWords(x);
15616
+ return `Counts ${words7(v)} from ${say(a)} up to ${say(b)} (not ${say(b)} itself)`;
15617
+ }
15618
+ }
15619
+ return null;
15620
+ }
15426
15621
  var possessiveWords = (path) => {
15427
15622
  if ((C_FAMILY.has(LANG) || LANG === "swift") && /\[/.test(String(path)) && !/\[\s*['"]/.test(String(path))) return indexedWords(String(path).replace(/->/g, "."));
15428
15623
  return possessivePlain(path);
@@ -15509,12 +15704,12 @@ function sayCodeConditionInner(cond) {
15509
15704
  if (c === "super") return "the parent version says yes";
15510
15705
  if ((ty = c.match(/^typeof\s+([\w$.]+)\s*(===?|!==?)\s*["'](\w+)["']$/)) && TYPEOF_WORDS[ty[3]]) return `${possessiveWords(ty[1])} is ${/^!/.test(ty[2]) ? "not " : ""}${TYPEOF_WORDS[ty[3]]}`;
15511
15706
  if ((ty = c.match(/^(!|not\s+)?\\?(is_\w+)\(\s*\$?([\w$.\[\]'">-]+)\s*\)$/)) && PHP_IS[ty[2]]) return `${possessiveWords(ty[3])} is ${ty[1] ? "not " : ""}${PHP_IS[ty[2]]}`;
15512
- if (ty = c.match(/^(!|not\s+)?\(?\s*([\w$.]+)\s+instanceof\s+([\w$.\\]+)\s*\)?$/)) return `${possessiveWords(ty[2])} is ${ty[1] ? "not " : ""}a ${ty[3].split(/[.\\]/).pop()}`;
15513
- if ((ty = c.match(/^([\w$.]+)\s+(is|!is)\s+([A-Z][\w.<>?]*)$/)) && !/^(?:True|False|None|Null|Nil|NULL)$/.test(ty[3])) return `${possessiveWords(ty[1])} is ${ty[2] === "!is" ? "not " : ""}a ${ty[3].split(".").pop()}`;
15514
- if (ty = c.match(/^(!|not\s+)?\(?\s*([\w$.@]+)\.(?:is_a|kind_of|instance_of)\?\s*\(?\s*([A-Z][\w:]*)\s*\)?\s*\)?$/)) return `${possessiveWords(ty[2].replace(/^@/, ""))} is ${ty[1] ? "not " : ""}a ${ty[3].split("::").pop()}`;
15707
+ if (ty = c.match(/^(!|not\s+)?\(?\s*([\w$.]+)\s+instanceof\s+([\w$.\\]+)\s*\)?$/)) return `${possessiveWords(ty[2])} is ${ty[1] ? "not " : ""}${aWord(ty[3].split(/[.\\]/).pop())}`;
15708
+ if ((ty = c.match(/^([\w$.]+)\s+(is|!is)\s+([A-Z][\w.<>?]*)$/)) && !/^(?:True|False|None|Null|Nil|NULL)$/.test(ty[3])) return `${possessiveWords(ty[1])} is ${ty[2] === "!is" ? "not " : ""}${aWord(ty[3].split(".").pop())}`;
15709
+ if (ty = c.match(/^(!|not\s+)?\(?\s*([\w$.@]+)\.(?:is_a|kind_of|instance_of)\?\s*\(?\s*([A-Z][\w:]*)\s*\)?\s*\)?$/)) return `${possessiveWords(ty[2].replace(/^@/, ""))} is ${ty[1] ? "not " : ""}${aWord(ty[3].split("::").pop())}`;
15515
15710
  if (ty = c.match(/^(not\s+)?isinstance\(\s*([\w.]+)\s*,\s*\(?\s*([\w.]+(?:\s*,\s*[\w.]+)*)\s*\)?\s*\)$/)) {
15516
15711
  const kinds = ty[3].split(/\s*,\s*/).map((x) => x.split(".").pop());
15517
- return `${possessiveWords(ty[2])} is ${ty[1] ? "not " : ""}${kinds.length > 1 ? `one of ${kinds.join(", ")}` : `a ${kinds[0]}`}`;
15712
+ return `${possessiveWords(ty[2])} is ${ty[1] ? "not " : ""}${kinds.length > 1 ? `one of ${kinds.join(", ")}` : aWord(kinds[0])}`;
15518
15713
  }
15519
15714
  const prop = c.match(/^(not\s+|!)?(?:self\.|this\.)?([A-Za-z_]\w*)\.([A-Za-z_]\w*)(\(\))?$/);
15520
15715
  const plural6 = (w, call2) => !call2 && !/ /.test(w) && /[^sui]s$/.test(w) && w.length > 3;
@@ -15567,6 +15762,32 @@ function matchingClose(str3, open) {
15567
15762
  return -1;
15568
15763
  }
15569
15764
  var lastWords = (path) => words7(String(path).split(".").pop());
15765
+ var aWord = (w) => {
15766
+ const t = String(w);
15767
+ const an = /^(?:[AEIOaeio]|U(?:n|m|nd|tt|pp)|u(?:n|m)|[FHLMNRSX][A-Z0-9]|[fhlmnrsx](?=[A-Z0-9]))/.test(t) && !/^(?:Eu|eu|Uni|uni|Use|use|Usu|One|one|Ur)/.test(t);
15768
+ return `${an ? "an" : "a"} ${t}`;
15769
+ };
15770
+ var ENDS_ON_PREPOSITION = /\s(?:for|from|to|of|with|by|in|on|at|about|into|as|via)$/;
15771
+ function callWords2(c, text2) {
15772
+ const w = lastWords(c);
15773
+ if (!ENDS_ON_PREPOSITION.test(w)) return w;
15774
+ const args = String(text2 ?? "");
15775
+ const open = args.indexOf("(");
15776
+ if (open >= 0) {
15777
+ let depth = 0, end = open + 1;
15778
+ for (; end < args.length; end++) {
15779
+ const ch = args[end];
15780
+ if ("([{".includes(ch)) depth++;
15781
+ else if (")]}".includes(ch)) {
15782
+ if (depth === 0) break;
15783
+ depth--;
15784
+ } else if (ch === "," && depth === 0) break;
15785
+ }
15786
+ const first = args.slice(open + 1, end).trim();
15787
+ if (/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(first)) return `${w} ${words7(first.split(".").pop())}`;
15788
+ }
15789
+ return w.replace(ENDS_ON_PREPOSITION, "");
15790
+ }
15570
15791
  function targetWords2(path) {
15571
15792
  if ((C_FAMILY.has(LANG) || LANG === "swift") && /\[[^\]]*\]\s*(?:\.|->)/.test(String(path))) return indexedWords(String(path).replace(/->/g, "."));
15572
15793
  if (/\][^\]]|\[.*\]$/.test(String(path).trim()) && !/^[@$]?[\w.]+\[\s*['"]?[\w-]+['"]?\s*\]$/.test(String(path).trim())) return `\`${String(path).trim()}\``;
@@ -15587,10 +15808,80 @@ function sayCall(name, args) {
15587
15808
  for (const k of KNOWN_CALLS) if (k.re.test(name)) {
15588
15809
  const target = (args.match(/^\s*["'`]([\w.\-/: ]{1,60})["'`]/) || [])[1];
15589
15810
  const base2 = k.say(name);
15811
+ if (base2 === "Writes a log or message" && (LANG === "typescript" || LANG === "javascript" || LANG === "python")) {
15812
+ const what = messageWhat(args);
15813
+ if (what) return `${base2}: ${what}`;
15814
+ }
15590
15815
  return target ? `${base2}: ${target}` : base2;
15591
15816
  }
15592
15817
  return null;
15593
15818
  }
15819
+ var wholeWords = (q2) => q2 && q2.endsWith("\u2026") && q2.length > 24 ? `${q2.slice(0, -1).replace(/\s+\S*$/, "").replace(/[\s,;:.-]+$/, "")}\u2026` : q2;
15820
+ function templateWithValues(lit4, n = 70) {
15821
+ const t = String(lit4).trim();
15822
+ if (!t.startsWith("`")) return null;
15823
+ let out = "";
15824
+ for (let i = 1; i < t.length; i++) {
15825
+ const c = t[i];
15826
+ if (c === "\\") {
15827
+ out += t[i + 1] === "`" ? "`" : t[i + 1] === "$" ? "$" : c + (t[i + 1] ?? "");
15828
+ i++;
15829
+ continue;
15830
+ }
15831
+ if (c === "`") return i === t.length - 1 ? out.length > n ? wholeWords(`${out.slice(0, n - 1).trimEnd()}\u2026`) : out : null;
15832
+ if (c === "$" && t[i + 1] === "{") {
15833
+ let d = 0, j = i + 1;
15834
+ for (; j < t.length; j++) {
15835
+ if (t[j] === "{") d++;
15836
+ else if (t[j] === "}" && --d === 0) break;
15837
+ }
15838
+ const hole = t.slice(i + 2, j).trim();
15839
+ out += /^[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)*$/.test(hole) ? `\xAB${hole}\xBB` : "\xAB\u2026\xBB";
15840
+ i = j;
15841
+ continue;
15842
+ }
15843
+ out += c;
15844
+ }
15845
+ return null;
15846
+ }
15847
+ function messageWhat(args) {
15848
+ const t = String(args ?? "");
15849
+ let depth = 0, end = 0, q2 = null;
15850
+ for (; end < t.length; end++) {
15851
+ const c2 = t[end];
15852
+ if (q2) {
15853
+ if (c2 === "\\") {
15854
+ end++;
15855
+ continue;
15856
+ }
15857
+ if (c2 === q2) q2 = null;
15858
+ continue;
15859
+ }
15860
+ if (c2 === '"' || c2 === "'" || c2 === "`") {
15861
+ q2 = c2;
15862
+ continue;
15863
+ }
15864
+ if ("([{".includes(c2)) depth++;
15865
+ else if (")]}".includes(c2)) {
15866
+ if (depth === 0) break;
15867
+ depth--;
15868
+ } else if (c2 === "," && depth === 0) break;
15869
+ }
15870
+ let a = t.slice(0, end).trim();
15871
+ if (!a) return null;
15872
+ const more = t[end] === ",";
15873
+ if (LANG === "python") a = a.replace(/^[fFrR]{1,2}(?=["'])/, "");
15874
+ if (/^["'`]/.test(a)) {
15875
+ let text2 = a.startsWith("`") ? templateWithValues(a, 80) : wholeWords(firstText(a, 80));
15876
+ if (text2 && more) text2 = text2.replace(/%[-+ #0-9.]*[sdifrxXeEgGcuo]|\{\}/g, "\u2026");
15877
+ return text2 && /\w/.test(text2) ? `"${text2}"${more && !/…/.test(text2) ? ", and more" : ""}` : null;
15878
+ }
15879
+ const tail = more ? ", and more" : "";
15880
+ if (/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*$/.test(a)) return `${possessiveWords(a)}${tail}`;
15881
+ const c = callee(a);
15882
+ if (c && closeOf(a, a.indexOf("(")) === a.length - 1) return `the result of ${callWords2(c, a)}${tail}`;
15883
+ return null;
15884
+ }
15594
15885
  function firstArgs(text2) {
15595
15886
  const open = text2.indexOf("(");
15596
15887
  return open >= 0 ? text2.slice(open + 1, open + 120) : "";
@@ -15634,7 +15925,7 @@ function sayValue(expr) {
15634
15925
  if (close >= 0 && close !== e.length - 1) return null;
15635
15926
  if (/^new\s/.test(e)) return `a new ${c.split(".").pop()}`;
15636
15927
  if ((LANG === "swift" || LANG === "cpp") && /^[A-Z]\w*$/.test(c) && !/^[A-Z][A-Z0-9_]+$/.test(c) && !C_STYLE_FUNCTION.test(c)) return `a new ${c}`;
15637
- return `the result of ${lastWords(c)}`;
15928
+ return `the result of ${callWords2(c, e)}`;
15638
15929
  }
15639
15930
  if (LANG === "swift" && /^[A-Za-z_][\w.]*\.count$/.test(e)) return `how many ${possessiveWords(e.replace(/\.count$/, ""))}`;
15640
15931
  if (/^[A-Za-z_$][\w$.]*$/.test(e)) {
@@ -15705,7 +15996,35 @@ function sayCommon(value) {
15705
15996
  if (m = e.match(/^new\s*\(\s*(?:[\w]+\.)?([A-Z]\w*)\s*\)$/)) return `a new ${m[1]}`;
15706
15997
  if (m = e.match(/^&([A-Z]\w*)$/)) return `a new ${m[1]}`;
15707
15998
  if (m = e.match(/^[\w.]+\.(?:get|get_or_404|find|Find|findById|find_by_id)\(\s*([A-Z]\w*)\s*,\s*([\w.]+)\s*\)$/)) return `the ${m[1]} with ${lastSeg(m[2])}`;
15708
- if ((m = e.match(/^([\w.]+)\.get\(\s*([A-Za-z_][\w.]*)\s*[,)]/)) || (m = e.match(/^([\w.]+)\[\s*([A-Za-z_][\w.]*)\s*\]$/))) return `the ${lastSeg(m[2])} entry in ${possessiveWords(m[1])}`;
15999
+ if ((m = e.match(/^([\w.]+)\.get\(\s*([A-Za-z_][\w.]*)\s*[,)]/)) || (m = e.match(/^([\w.]+)\[\s*([A-Za-z_][\w.]*)\s*\]$/))) return /\./.test(m[2]) && !/^(?:self|this)\./.test(m[2]) ? `the entry for ${possessiveWords(m[2])} in ${possessiveWords(m[1])}` : `the ${lastSeg(m[2])} entry in ${possessiveWords(m[1])}`;
16000
+ if (LANG === "python") {
16001
+ const plain = (x) => /^[A-Za-z_][\w]*(?:\.[A-Za-z_][\w]*)*$/.test(String(x).trim()) ? possessiveWords(String(x).trim()) : null;
16002
+ let mm;
16003
+ if (mm = e.match(/^([A-Z][A-Za-z0-9]*[a-z][A-Za-z0-9]*)\(\s*\)$/)) return `a new ${mm[1]}`;
16004
+ if ((mm = e.match(/^(list|tuple|set|frozenset|sorted|reversed)\(\s*([^(),]+?)\s*\)$/)) && plain(mm[2])) return { list: `${plain(mm[2])}, as a list`, tuple: `${plain(mm[2])}, as a tuple`, set: `the different values in ${plain(mm[2])}`, frozenset: `the different values in ${plain(mm[2])}`, sorted: `${plain(mm[2])}, sorted`, reversed: `${plain(mm[2])}, in reverse order` }[mm[1]];
16005
+ if ((mm = e.match(/^([\w.]+)\.index\(\s*([^(),]+?)\s*\)$/)) && plain(mm[1]) && plain(mm[2])) return `the position of ${plain(mm[2])} in ${plain(mm[1])}`;
16006
+ }
16007
+ if (LANG === "typescript" || LANG === "javascript") {
16008
+ const plain = (x) => /^[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*)*$/.test(String(x).trim()) ? possessiveWords(String(x).trim().replace(/\?\./g, ".")) : null;
16009
+ const one = (re) => {
16010
+ const mm = e.match(re);
16011
+ return mm ? plain(mm[1]) : null;
16012
+ };
16013
+ let w;
16014
+ if (w = one(/^Object\.keys\(\s*([^(),]+?)\s*\)$/)) return `the keys of ${w}`;
16015
+ if (w = one(/^Object\.values\(\s*([^(),]+?)\s*\)$/)) return `the values in ${w}`;
16016
+ if (w = one(/^Object\.entries\(\s*([^(),]+?)\s*\)$/)) return `each key and value in ${w}`;
16017
+ if (w = one(/^Date\.parse\(\s*([^(),]+?)\s*\)$/)) return `the time written in ${w}`;
16018
+ if (w = one(/^Array\.from\(\s*([^(),]+?)\s*\)$/)) return `a list made from ${w}`;
16019
+ if ((m = e.match(/^([A-Z][\w$]*)\.from\(\s*([^(),]+?)\s*\)$/)) && plain(m[2])) return `a ${m[1]} made from ${plain(m[2])}`;
16020
+ if ((m = e.match(/^([\w$.]+)\.exec\(\s*([^(),]+?)\s*\)$/)) && plain(m[1]) && plain(m[2])) return `the first match of ${plain(m[1])} in ${plain(m[2])}`;
16021
+ if ((m = e.match(/^([A-Z][\w$]*)\.parse\(\s*([^(),]+?)\s*\)$/)) && plain(m[2]) && m[1] !== "JSON" && m[1] !== "Date") return `${plain(m[2])}, checked and read by ${m[1]}`;
16022
+ if (m = e.match(/^Math\.(max|min)\(\s*([^()]+?)\s*\)$/)) {
16023
+ const xs = splitTopArgs(m[2]).map(plain);
16024
+ if (xs.length >= 2 && xs.every(Boolean)) return `the ${m[1] === "max" ? "largest" : "smallest"} of ${xs.slice(0, -1).join(", ")} and ${xs[xs.length - 1]}`;
16025
+ }
16026
+ if ((m = e.match(/^Math\.(round|floor|ceil|abs|trunc)\(\s*([^(),]+?)\s*\)$/)) && plain(m[2])) return { round: `${plain(m[2])} rounded`, floor: `${plain(m[2])} rounded down`, ceil: `${plain(m[2])} rounded up`, abs: `the absolute value of ${plain(m[2])}`, trunc: `${plain(m[2])} without its fraction` }[m[1]];
16027
+ }
15709
16028
  const wholeCall = (() => {
15710
16029
  const c = e.match(/^(?:new\s+)?[\w$.]+(?:<[^()]*?>)?\s*\(/);
15711
16030
  return !!c && closeOf(e, c[0].length - 1) === e.length - 1;
@@ -15718,8 +16037,20 @@ function sayCommon(value) {
15718
16037
  if (m[1] === "[]" && a.length > 1 && !/^0$/.test(a[1].trim())) return null;
15719
16038
  return m[1] === "[]" ? "an empty list" : "an empty lookup table";
15720
16039
  }
16040
+ if (/^`/.test(e) || /^f["']/.test(e)) {
16041
+ const tv = templateTextWithValues(e);
16042
+ if (tv) return tv.length > 90 ? `${tv.slice(0, 88)}\u2026"` : tv;
16043
+ }
16044
+ if (/^`/.test(e) && /\$\{/.test(e)) {
16045
+ const q2 = templateWithValues(e, 80);
16046
+ if (q2 != null && !/"/.test(q2)) return `"${q2}"`;
16047
+ }
15721
16048
  if (/^(?:f|rf|fr)["']/.test(e) || /^`[^`]*\$\{/.test(e) || /^\$"/.test(e) || /^(?:fmt\.Sprintf|String\.format|format!)\(/.test(e)) return "text built from its parts";
15722
- if (m = e.match(/^([\w.]+)\.get\(\s*["'`]([\w.\-: ]{1,40})["'`]/)) return `the "${m[2]}" value from ${lastSeg(m[1])}`;
16049
+ if (m = e.match(/^([\w.]+)\.get\(\s*["'`]([\w.\-: ]{1,40})["'`]\s*\)$/)) return `the "${m[2]}" value from ${lastSeg(m[1])}`;
16050
+ if (LANG === "python" && (m = e.match(/^([\w.]+)\.get\(\s*["'`]([\w.\-: ]{1,40})["'`]\s*,\s*(.+?)\s*\)$/)) && balancedText(m[3])) {
16051
+ const d = /^[A-Za-z_][\w.]*$/.test(m[3]) && !/^(?:None|True|False)$/.test(m[3]) ? possessiveWords(m[3]) : sayValue(m[3]);
16052
+ if (d && d.length < 40) return `the "${m[2]}" value from ${lastSeg(m[1])}, or ${d} if it has none`;
16053
+ }
15723
16054
  if (m = e.match(/^([\w.]+)\[\s*["'`]([\w.\-: ]{1,40})["'`]\s*\]$/)) return `the "${m[2]}" value from ${lastSeg(m[1])}`;
15724
16055
  if (FN_CONTEXT?.language === "ruby" && (m = e.match(/^@?([\w.]+)\[\s*:(\w+)\s*\]$/))) return `the "${m[2]}" value from ${lastSeg(m[1])}`;
15725
16056
  if (m = e.match(/^([\w.]+)\.split\(\s*["'`]([^"'`]{0,10})["'`]/)) return `${lastSeg(m[1])} split at "${m[2]}"`;
@@ -15732,6 +16063,16 @@ function sayCommon(value) {
15732
16063
  if (/^(?:dict|Map|HashMap|map)\(\s*\)$|^\{\s*\}$|^new (?:Map|HashMap|Dictionary)(?:<[^()]*>)?\s*(?:\(\s*\))?\s*(?:\{\s*\})?$/.test(e)) return "an empty lookup table";
15733
16064
  if (/^(?:list|Array|ArrayList|vec!?)\(?\s*\)?$|^\[\s*\]$|^new (?:ArrayList|List)(?:<[^()]*>)?\s*(?:\(\s*\))?\s*(?:\{\s*\})?$/.test(e)) return "an empty list";
15734
16065
  if ((m = e.match(/^len\(\s*([\w.]+)\s*\)$/)) || (m = e.match(/^([\w.]+)\.(?:length|size\(\)|Count|count\(\)|len\(\))$/))) return `how many ${lastSeg(m[1])}`;
16066
+ if (/^(?:set|frozenset)\(\s*\)$|^new Set(?:<[^()]*>)?\(\s*\)$/.test(e)) return "an empty set";
16067
+ if ((m = e.match(/^\[\s*(.+?)\s*,?\s*\]$/)) && !/\bfor\b/.test(m[1])) {
16068
+ const items = splitTopArgs(m[1]).map((x) => x.trim());
16069
+ const said = items.map((x) => /^[A-Za-z_][\w.]*$/.test(x) && !/^(?:None|null|undefined|True|False|true|false|self|this)$/.test(x) ? possessiveWords(x) : /^-?\d+(?:\.\d+)?$/.test(x) ? x : /^(["'])[\w .:/-]{0,24}\1$/.test(x) ? `"${x.slice(1, -1)}"` : null);
16070
+ if (items.length && items.length <= 4 && said.every(Boolean)) return items.length === 1 ? `a list with only ${said[0]}` : `a list of ${listWords3(said)}`;
16071
+ }
16072
+ if (LANG === "python" && (m = e.match(/^([A-Za-z_][\w.]*)\[\s*(-?\d+)?\s*(:)?\s*(-?\d+)?\s*\]$/)) && (m[3] || m[2] === "-1")) {
16073
+ const t = sliceWords(m[3] ? m[2] : void 0, m[3] ? m[4] : void 0, m[3] ? null : m[2]);
16074
+ if (t) return t.replace("{x}", possessiveWords(m[1]));
16075
+ }
15735
16076
  return null;
15736
16077
  }
15737
16078
  function ifAsValue(e) {
@@ -16140,7 +16481,7 @@ function responseOf(head) {
16140
16481
  if (status && status >= 300) return null;
16141
16482
  return sentStep(payloadWords(body2), status === 200 ? null : status);
16142
16483
  }
16143
- if (/^return\b/.test(head) && (m = expr.match(/^(Ok|Accepted|Created|CreatedAtAction|CreatedAtRoute|NoContent|Json)\s*\((.*)\)$/))) {
16484
+ if (/^return\b/.test(head) && LANG !== "rust" && (m = expr.match(/^(Ok|Accepted|Created|CreatedAtAction|CreatedAtRoute|NoContent|Json)\s*\((.*)\)$/))) {
16144
16485
  const args = callArgs(m[2]);
16145
16486
  const status = { Ok: null, Json: null, Accepted: 202, Created: 201, CreatedAtAction: 201, CreatedAtRoute: 201, NoContent: 204 }[m[1]];
16146
16487
  return sentStep(payloadWords(args.at(-1)), status);
@@ -16197,6 +16538,57 @@ function quotedBody(lit4) {
16197
16538
  }
16198
16539
  return t.slice(1, -1);
16199
16540
  }
16541
+ var PLAIN_PLACEHOLDER = /^[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*|\[\d+\])*(?:\(\))?$/;
16542
+ function templateTextWithValues(lit4) {
16543
+ const t = String(lit4).trim();
16544
+ const js = t[0] === "`";
16545
+ if (!js && !/^f(["'])/.test(t)) return null;
16546
+ const q2 = js ? "`" : t[1];
16547
+ if (!js && t.slice(1, 4) === q2.repeat(3)) return null;
16548
+ let out = "", i = js ? 1 : 2, any = false;
16549
+ for (; i < t.length; i++) {
16550
+ const c = t[i];
16551
+ if (c === q2) break;
16552
+ if (c === "\\") {
16553
+ out += c + (t[i + 1] ?? "");
16554
+ i++;
16555
+ continue;
16556
+ }
16557
+ if (js ? c === "$" && t[i + 1] === "{" : c === "{") {
16558
+ if (!js && t[i + 1] === "{") {
16559
+ out += "{";
16560
+ i++;
16561
+ continue;
16562
+ }
16563
+ const open = js ? i + 1 : i;
16564
+ const close = t.indexOf("}", open);
16565
+ if (close < 0) return null;
16566
+ let inner = t.slice(open + 1, close).trim(), spec = "";
16567
+ if (!js) {
16568
+ const m = /^([^:!]+?)\s*((?:![rsa])?(?::[^{}]*)?)$/.exec(inner);
16569
+ if (!m) return null;
16570
+ inner = m[1].trim();
16571
+ spec = m[2];
16572
+ }
16573
+ if (!PLAIN_PLACEHOLDER.test(inner)) return null;
16574
+ out += spec ? `\xAB${inner} as {${spec}}\xBB` : `\xAB${inner}\xBB`;
16575
+ any = true;
16576
+ i = close;
16577
+ continue;
16578
+ }
16579
+ if (!js && c === "}" && t[i + 1] === "}") {
16580
+ out += "}";
16581
+ i++;
16582
+ continue;
16583
+ }
16584
+ if (c === '"') {
16585
+ out += '\\"';
16586
+ continue;
16587
+ }
16588
+ out += c;
16589
+ }
16590
+ return any && i === t.length - 1 ? `"${out}"` : null;
16591
+ }
16200
16592
  function swiftTextWithValues(lit4) {
16201
16593
  const t = String(lit4).trim();
16202
16594
  if (!/^"/.test(t) || /^"""/.test(t)) return null;
@@ -16350,7 +16742,98 @@ function sayExactly(first, head) {
16350
16742
  }
16351
16743
  var stripQuotedText = (s) => String(s).replace(/(["'])(?:\\.|(?!\1)[^\\])*\1/g, "Q");
16352
16744
  var NOT_CALLED = /^Calls (unsafe|using|foreach|for|while|if|else|return|lock|fixed|checked|unchecked|try|do|switch|match|loop|static|const|let|var|val|mut|typeof|sizeof)$/;
16745
+ function stripTsTypes(text2) {
16746
+ let s = String(text2);
16747
+ const typeEnd = (from, stops) => {
16748
+ let depth = 0, q2 = null;
16749
+ for (let i = from; i < s.length; i++) {
16750
+ const c = s[i];
16751
+ if (q2) {
16752
+ if (c === q2 && s[i - 1] !== "\\") q2 = null;
16753
+ continue;
16754
+ }
16755
+ if (c === "'" || c === '"' || c === "`") {
16756
+ q2 = c;
16757
+ continue;
16758
+ }
16759
+ if (c === "<" || c === "{" || c === "(" || c === "[") depth++;
16760
+ else if (c === ">" && s[i - 1] !== "=" || c === "}" || c === ")" || c === "]") {
16761
+ if (depth === 0) return i;
16762
+ depth--;
16763
+ } else if (depth === 0 && stops.includes(c)) return i;
16764
+ }
16765
+ return s.length;
16766
+ };
16767
+ for (let guard = 0; guard < 20; guard++) {
16768
+ const re = /\s+as\s+(?=[A-Za-z_${(\['"])/g;
16769
+ let m;
16770
+ while ((m = re.exec(s)) && ['"', "'", "`"].some((q2) => (s.slice(0, m.index).split(q2).length - 1) % 2 === 1)) ;
16771
+ if (!m || /\bimport\b|\bexport\b/.test(s.slice(0, m.index))) break;
16772
+ const end = typeEnd(m.index + m[0].length, ",;=");
16773
+ s = s.slice(0, m.index) + s.slice(end);
16774
+ }
16775
+ const decl2 = /^(\s*(?:export\s+)?(?:const|let|var)\s+[A-Za-z_$][\w$]*)\s*:\s*/.exec(s);
16776
+ if (decl2) {
16777
+ const end = typeEnd(decl2[0].length, "=;");
16778
+ if (s[end] === "=") s = `${decl2[1]} ${s.slice(end)}`;
16779
+ }
16780
+ s = s.replace(/([\w$\])])!(?![=\w(])/g, "$1").replace(/\(([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)\)(?=\.)/g, "$1");
16781
+ const wrapped2 = /^(\s*(?:export\s+)?(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*=\s*|\s*return\s+)\(([\s\S]*)\)(\s*;?\s*)$/.exec(s);
16782
+ if (wrapped2) {
16783
+ let depth = 0, whole = true;
16784
+ for (let i = 0; i < wrapped2[2].length; i++) {
16785
+ const c = wrapped2[2][i];
16786
+ if (c === "(") depth++;
16787
+ else if (c === ")") {
16788
+ if (depth === 0) {
16789
+ whole = false;
16790
+ break;
16791
+ }
16792
+ depth--;
16793
+ }
16794
+ }
16795
+ if (whole && depth === 0) s = `${wrapped2[1]}${wrapped2[2]}${wrapped2[3]}`;
16796
+ }
16797
+ return s;
16798
+ }
16353
16799
  function classifyStatement(raw, opts) {
16800
+ if (LANG === "typescript" || LANG === "javascript") {
16801
+ const ev = /^\s*[\w$.]+\.(?:on|once|addEventListener|addListener)\(\s*(['"`])([\w:.\-]+)\1\s*,\s*(?:async\s*)?(?:\([^()]*\)|[\w$]+)\s*=>\s*(?!\{)([\s\S]+?)\)\s*;?\s*$/.exec(String(raw));
16802
+ if (ev && balancedText(ev[3])) {
16803
+ const body2 = ev[3].trim();
16804
+ const c = callee(body2);
16805
+ if (c && closeOf(body2, body2.indexOf("(")) === body2.length - 1) return { kind: "call", says: `Whenever "${ev[2]}" happens, it calls ${callWords2(c, body2)}`, code: clip(String(raw).replace(/\s+/g, " ").trim(), 90), callee: c, expr: statementExpr(raw) };
16806
+ }
16807
+ }
16808
+ if (LANG === "typescript" || LANG === "javascript") {
16809
+ const t = String(raw).trim();
16810
+ const m = /^for\s*\(/.exec(t);
16811
+ if (m) {
16812
+ let depth = 0, close = -1;
16813
+ for (let i = t.indexOf("("); i < t.length; i++) {
16814
+ if (t[i] === "(") depth++;
16815
+ else if (t[i] === ")" && --depth === 0) {
16816
+ close = i;
16817
+ break;
16818
+ }
16819
+ }
16820
+ const rest2 = close > 0 ? t.slice(close + 1).trim() : "";
16821
+ if (/^for\s*\(/.test(rest2)) {
16822
+ const outer = classifyStatement(`${t.slice(0, close + 1)} {`, opts);
16823
+ const inner = classifyStatement(rest2.replace(/\{?\s*$/, " {"), opts);
16824
+ if (outer.kind === "loop" && inner.kind === "loop") {
16825
+ return { ...outer, says: `${outer.says.replace(/:$/, "")}, and in each, ${inner.says.charAt(0).toLowerCase()}${inner.says.slice(1)}`, code: clip(t.replace(/\s+/g, " "), 90), nestedLoop: true };
16826
+ }
16827
+ }
16828
+ }
16829
+ }
16830
+ if (LANG === "typescript" && /\sas\s|[\w$\])]!(?![=\w(])|^\s*(?:export\s+)?(?:const|let|var)\s+[A-Za-z_$][\w$]*\s*:/.test(String(raw))) {
16831
+ const plain = stripTsTypes(raw);
16832
+ if (plain !== String(raw)) {
16833
+ const r2 = classifyStatement(plain, opts);
16834
+ if (r2.kind !== "other") return { ...r2, code: clip(String(raw).replace(/\s+/g, " ").trim(), 90) };
16835
+ }
16836
+ }
16354
16837
  const un = LANG === "rust" ? String(raw).trim().match(/^(return\s+)?unsafe\s*\{\s*([^{};]+?)\s*;?\s*\}\s*;?$/s) : null;
16355
16838
  if (un) {
16356
16839
  const r2 = classifyStatement(`${un[1] ?? ""}${un[2]}`, opts);
@@ -16359,6 +16842,15 @@ function classifyStatement(raw, opts) {
16359
16842
  let r = classifyWords(raw, opts);
16360
16843
  const nc = r.kind === "call" && String(r.says || "").match(NOT_CALLED);
16361
16844
  if (nc && new RegExp(`^(?:#\\w+\\s+)?${nc[1]}\\b(?![.(?!])`).test(String(raw).trim().replace(/^#.*\n\s*/, ""))) r = { kind: "other", says: clip(String(raw).trim(), 70), code: clip(String(raw).replace(/\s+/g, " ").trim(), 90) };
16845
+ let rq;
16846
+ if (LANG === "rust" && r.kind === "set" && /^Works out [\w ]+$/.test(String(r.says)) && (rq = /^(\s*let\s+(?:mut\s+)?\w+\s*(?::[^=]+)?=\s*)(.+?)\?\s*;?\s*$/.exec(String(raw))) && !/\?/.test(rq[2])) {
16847
+ const inner = classifyWords(`${rq[1]}${rq[2]};`, opts);
16848
+ if (inner.kind === "set" && /^(?:Works out [\w ]+ from |Sets )/.test(String(inner.says)) && !/, /.test(String(inner.says))) r = { ...r, says: `${inner.says}, and stops here if that fails`, callee: inner.callee };
16849
+ }
16850
+ let so;
16851
+ if (r.kind === "set" && (so = /^Sets (.+) to (.+)$/.exec(String(r.says))) && so[1] === so[2] && (so = /^\s*(?:(?:const|let|var)\s+)?([A-Za-z_$][\w$]*)\s*=\s*(self|this)\.([A-Za-z_$][\w$]*)\s*;?\s*$/.exec(String(raw))) && so[1] === so[3]) {
16852
+ r = { ...r, says: `Sets ${words7(so[1])} to ${so[2]}.${so[3]}` };
16853
+ }
16362
16854
  if (!r.expr) r.expr = statementExpr(raw);
16363
16855
  return r;
16364
16856
  }
@@ -16479,6 +16971,10 @@ function classifyWords(raw, { inner = 0 } = {}) {
16479
16971
  const said = name && /^[a-z]/.test(name) ? `the error made by ${words7(name)}` : name;
16480
16972
  return { kind: "fail", says: `Fails${said ? ` with ${said}` : ""}${msg ? `: "${msg}"` : ""}`, code: code3, ...name ? { error: name } : {}, ...msg ? { message: msg } : {} };
16481
16973
  }
16974
+ if (LANG === "python" && /^(?:from|import)\s/.test(head)) {
16975
+ const said = pythonImportSays(head);
16976
+ if (said) return { kind: "set", says: said, code: code3 };
16977
+ }
16482
16978
  let dyn;
16483
16979
  if (dyn = head.match(/^(?:const|let|var)\s*(?:\{([^}]*)\}|([A-Za-z_$][\w$]*))\s*=\s*(?:await\s+)?(?:import|require)\(\s*['"`]([^'"`]+)['"`]\s*\)\s*;?$/)) {
16484
16980
  const names = dyn[1] ? dyn[1].split(",").map((x) => x.split(":").pop().trim()).filter(Boolean).map(words7) : [words7(dyn[2])];
@@ -16546,6 +17042,35 @@ function classifyWords(raw, { inner = 0 } = {}) {
16546
17042
  return { kind: "loop", says: `Counts ${words7(m[1])} from ${clip(m[2], 20)}${m[3] ? ` while ${sayCodeCondition(m[3])}` : ""}${innerNote}`, code: code3 };
16547
17043
  }
16548
17044
  if (m = head.match(/^for\s*\(\s*[^;]*;\s*([^;]*?)\s*;[^)]*\)\s*\{?\s*$/)) return { kind: "loop", says: m[1] ? `Repeats while ${sayCodeCondition(m[1])}${innerNote}` : `Repeats${innerNote}`, code: code3 };
17045
+ if (LANG === "rust" && (m = head.match(/^for\s+(\(\s*\w+\s*,\s*\w+\s*\)|\w+)\s+in\s+(.+?)\s*\{?\s*$/))) {
17046
+ const it = m[2].replace(/^&(?:mut\s+)?/, "");
17047
+ const pair = /^\(\s*(\w+)\s*,\s*(\w+)\s*\)$/.exec(m[1]);
17048
+ const who = pair ? `${words7(pair[1])} and ${words7(pair[2])}` : words7(m[1]);
17049
+ let k;
17050
+ const r = !pair && rangeWords(it);
17051
+ if (r && m[1] !== "_") return { kind: "loop", says: `Counts ${who} ${r.says}${innerNote}`, code: code3 };
17052
+ if ((k = it.match(/^([A-Za-z_][\w.]*?)(?:\.(?:iter|iter_mut|into_iter)\(\s*\))?$/)) && m[1] !== "_") return { kind: "loop", says: `For each ${who} in ${possessiveWords(k[1])}${innerNote}`, code: code3 };
17053
+ if ((k = it.match(/^([A-Za-z_][\w.]*)\.(chars|lines|bytes|keys|values)\(\s*\)$/)) && m[1] !== "_") return { kind: "loop", says: `For each ${who} in the ${{ chars: "characters", lines: "lines", bytes: "bytes", keys: "keys", values: "values" }[k[2]]} of ${possessiveWords(k[1])}${innerNote}`, code: code3 };
17054
+ }
17055
+ if (LANG === "python" && (m = head.match(/^for\s+(\w+)\s+in\s+range\((.*)\)\s*:$/))) {
17056
+ const r = pythonRangeWords(m[1], m[2]);
17057
+ if (r) return { kind: "loop", says: `${r}${innerNote}`, code: code3 };
17058
+ }
17059
+ if (LANG === "python" && (m = head.match(/^for\s+\(?\s*(\w+)\s*,\s*(\w+)\s*\)?\s+in\s+enumerate\(\s*([A-Za-z_][\w.]*)\s*\)\s*:$/)) && m[1] !== "_") {
17060
+ return { kind: "loop", says: `For each ${words7(m[2])} in ${possessiveWords(m[3])}, with its position ${words7(m[1])} (from 0)${innerNote}`, code: code3 };
17061
+ }
17062
+ if (LANG === "python" && (m = head.match(/^for\s+(\w+)\s+in\s+(.+?)\s*:$/)) && !/^range\(|^enumerate\(/.test(m[2])) {
17063
+ const it = m[2];
17064
+ let w = null, k;
17065
+ if (k = it.match(/^([A-Za-z_][\w.]*)\.(values|keys)\(\s*\)$/)) w = `the ${k[2]} of ${possessiveWords(k[1])}`;
17066
+ else if (k = it.match(/^sorted\(\s*([A-Za-z_][\w.]*)\s*\)$/)) w = `${possessiveWords(k[1])}, sorted`;
17067
+ else if (k = it.match(/^reversed\(\s*([A-Za-z_][\w.]*)\s*\)$/)) w = `${possessiveWords(k[1])}, in reverse order`;
17068
+ else if (/^[A-Za-z_]/.test(it) && /\)$/.test(it)) {
17069
+ const last = [...it.matchAll(/([A-Za-z_]\w*)\(/g)].reverse().find((x) => closeOf(it, x.index + x[0].length - 1) === it.length - 1);
17070
+ if (last && !/^(?:zip|map|filter|iter|list|tuple|set)$/.test(last[1]) && (last.index === 0 || it[last.index - 1] === ".") && balancedText(it)) w = `the result of ${words7(last[1])}`;
17071
+ }
17072
+ if (w) return { kind: "loop", says: `For each ${words7(m[1])} in ${w}${innerNote}`, code: code3 };
17073
+ }
16549
17074
  if (m = head.match(/^for\b\s*\(?\s*(?:(?:const|let|var|val)\s+)?&?[\[{(]?\s*([\w$]+)\s*,\s*([\w$]+)\s*[\]})]?\s+(?:of|in)\s+(.+?)\)?\s*(?:\{|:|do)?\s*$/)) {
16550
17075
  const src = stripTail(m[3]).replace(/\($/, "()").replace(/^Object\.entries\((.+)\)$/, "$1").replace(/\.(?:items|entries|enumerated)\(\)$/, "");
16551
17076
  return { kind: "loop", says: `For each ${words7(m[1])} and ${words7(m[2])} in ${words7(src.split(".").pop())}${innerNote}`, code: code3 };
@@ -16560,6 +17085,7 @@ function classifyWords(raw, { inner = 0 } = {}) {
16560
17085
  if (m = head.match(/^@?([\w.]+(?:\([^()]*\))?)\.each(?:_with_index)?\s+do\s*\|(\w+)/)) return { kind: "loop", says: `For each ${words7(m[2])} in ${words7(m[1].replace(/\(.*$/, "").split(".").pop())}${innerNote}`, code: code3 };
16561
17086
  if (m = head.match(/^([\w.]+)\.(?:forEach|each|map|filter|for_each)\s*[({]/)) return { kind: "loop", says: `For each item in ${words7(m[1].split(".").pop())}${innerNote}`, code: code3 };
16562
17087
  if (/^for\s*\{$/.test(head)) return { kind: "loop", says: `Repeats until something inside leaves the loop${innerNote}`, code: code3 };
17088
+ if (LANG === "rust" && /^loop\s*\{?\s*$/.test(head)) return { kind: "loop", says: `Repeats until a step inside stops it${innerNote}`, code: code3 };
16563
17089
  if (m = head.match(/^(?:while|until|loop)\b\s*\(?(.*?)\)?\s*(?:\{|:|do)?\s*$/)) return { kind: "loop", says: m[1] ? `Repeats while ${sayCodeCondition(m[1])}${innerNote}` : `Repeats${innerNote}`, code: code3 };
16564
17090
  if (m = head.match(/^(?:if|else\s+if)\s+(?:[\w]+\s*,\s*)?err\s*:?=\s*(.+?)(?:\.Error)?;\s*err\s*!=\s*nil\s*\{?\s*$/)) {
16565
17091
  const lib2 = sayLibraryCall(m[1]);
@@ -16592,7 +17118,7 @@ function classifyWords(raw, { inner = 0 } = {}) {
16592
17118
  return { kind: "branch", says: `If ${/^unless\b/.test(head) ? "not: " : ""}${cond}${innerNote}`, cond: m[1].replace(/^\((.*)\)$/, "$1"), code: code3, negate: /^unless\b/.test(head) };
16593
17119
  }
16594
17120
  if (/^switch\s*(?:true\s*)?\{$/.test(head)) return { kind: "branch", says: `Checks these cases in order${innerNote}`, code: code3 };
16595
- if (m = head.match(/^(?:switch|match|case|select)\b\s*\(?(.*?)\)?\s*(?:\{|:)?\s*$/)) return { kind: "branch", says: `Chooses by ${words7(clip(m[1], 40)) || "value"}${innerNote}`, code: code3 };
17121
+ if (m = head.match(/^(?:switch|match|case|select)\b(?!\s*(?:=(?!=)|\.|,|\)|\]|[-+*/%]=))\s*\(?(.*?)\)?\s*(?:\{|:)?\s*$/)) return { kind: "branch", says: `Chooses by ${words7(clip(m[1], 40)) || "value"}${innerNote}`, code: code3 };
16596
17122
  if (/^(?:try|begin)\b/.test(head)) return { kind: "try", says: `Tries the next steps and handles any error${innerNote}`, code: code3 };
16597
17123
  if (m = head.match(/^assert\b\s*(.*?)\s*;?$/)) return { kind: "check", says: `Checks that ${m[1] ? sayCodeCondition(m[1].replace(/,\s*["'].*$/, "")) : "a condition holds"}`, code: code3 };
16598
17124
  if (m = head.match(/^assert(?:_\w+|That|Equals|True|False|NotNull|Null)\b/)) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code: code3 };
@@ -16625,6 +17151,11 @@ function classifyWords(raw, { inner = 0 } = {}) {
16625
17151
  if (((m = head.match(/^([A-Z]\w*)(?:::\w+)*\s*\{\s*$/)) || (m = head.match(/^([A-Z]\w*)\s*\{.*\}$/))) && !(closeOf(text2, text2.indexOf("{")) > 0 && text2.slice(closeOf(text2, text2.indexOf("{")) + 1).trim())) return { kind: "return", says: `Returns a new ${words7(m[1])}`, code: code3 };
16626
17152
  if (m = head.match(/^(?:[A-Z]\w*::)+([A-Z]\w*)$/)) return { kind: "return", says: `Returns ${m[1]}`, code: code3 };
16627
17153
  if (/^vec!?\[/.test(head)) return { kind: "return", says: "Returns a list", code: code3 };
17154
+ if (LANG === "rust" && /^loop\s*\{?\s*$/.test(head)) return { kind: "loop", says: `Repeats until a step inside stops it${innerNote}`, code: code3 };
17155
+ if (LANG === "rust" && /^(?:Ok|Some)\s*\(/.test(head) && closeOf(head, head.indexOf("(")) === head.length - 1) {
17156
+ const v = sayValue(head);
17157
+ if (v) return { kind: "return", says: `Returns ${v}`, code: code3 };
17158
+ }
16628
17159
  if (FN_CONTEXT && !/^(?:ruby|rust|kotlin|scala|elixir)$/.test(FN_CONTEXT.language || "") && /^(?:self|this|[a-z_][\w]*)\.[\w.]+$/.test(head)) return { kind: "call", says: `Reads ${targetWords2(head)}`, code: code3 };
16629
17160
  if (/^(?:["'`].*["'`]|-?\d+(?:\.\d+)?|true|false|nil|null|None|self|[a-z_][\w.]*)$/.test(head) && !/^(?:else|end|break|next|redo|retry|pass)$/.test(head)) {
16630
17161
  const v = sayValue(head);
@@ -16641,7 +17172,7 @@ function classifyWords(raw, { inner = 0 } = {}) {
16641
17172
  const names = m[2].split(",").map((x) => x.trim().split(/\s*[:=]\s*/)[0].replace(/^\.\.\./, "")).filter(Boolean).map(words7);
16642
17173
  const value = stripTail(m[3]);
16643
17174
  const c2 = callee(value);
16644
- const from = c2 ? lastWords(c2) : sayValue(value) || words7(value.split(".").pop());
17175
+ const from = c2 ? callWords2(c2, value) : sayValue(value) || words7(value.split(".").pop());
16645
17176
  return { kind: "set", says: `Takes ${names.slice(0, 4).join(", ")}${names.length > 4 ? ", \u2026" : ""} from ${from}`, code: code3 };
16646
17177
  }
16647
17178
  if (m = head.match(/^(?:var|const)\s*\($/)) return { kind: "set", says: "Declares some values", code: code3 };
@@ -16657,7 +17188,7 @@ function classifyWords(raw, { inner = 0 } = {}) {
16657
17188
  const known = sayCall(c2, firstArgs(value));
16658
17189
  if (known) return { kind: "call", says: `${known}, keeping the result as ${target}`, code: code3, callee: c2 };
16659
17190
  if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, m[1]))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
16660
- return { kind: "set", says: `Works out ${target} from ${lastWords(c2)}`, code: code3, callee: c2 };
17191
+ return { kind: "set", says: `Works out ${target} from ${callWords2(c2, value)}`, code: code3, callee: c2 };
16661
17192
  }
16662
17193
  const v = value ? sayValue(value) : null;
16663
17194
  return { kind: "set", says: v ? `Sets ${target} to ${v}` : `Works out ${target}`, code: code3 };
@@ -16671,17 +17202,17 @@ function classifyWords(raw, { inner = 0 } = {}) {
16671
17202
  also = ` (and as ${targetWords2(chained[1])})`;
16672
17203
  value = chained[2];
16673
17204
  }
16674
- const valueWords5 = (v2) => sayValue(v2) ?? sayArithmetic(v2);
17205
+ const valueWords6 = (v2) => sayValue(v2) ?? sayArithmetic(v2);
16675
17206
  const fb = /[=!<>]=|\bnot\b|!(?!=)|\s[<>]\s|\bis\b/.test(value.replace(/(["'`])(?:\\.|(?!\1)[^\\])*\1/g, "Q")) ? null : fallbackWords(value);
16676
17207
  if (fb === false) return { kind: "other", says: clip(head, 70), code: code3 };
16677
17208
  if (fb && m[2] === "=" && !/\[/.test(m[1])) return { kind: "set", says: `Sets ${target} to ${fb}${also}`, code: code3 };
16678
17209
  const app = m[2] !== "+=" && value.match(/^append\(\s*([\w$.]+)\s*,\s*(.+)\)$/);
16679
17210
  if (app && app[1] === m[1].trim()) {
16680
- const v2 = /,/.test(app[2].replace(/\([^()]*\)/g, "")) ? null : valueWords5(app[2].trim());
17211
+ const v2 = /,/.test(app[2].replace(/\([^()]*\)/g, "")) ? null : valueWords6(app[2].trim());
16681
17212
  return { kind: "set", says: `Adds ${v2 ?? "to the end of"}${v2 ? " to the end of" : ""} ${target}`, code: code3 };
16682
17213
  }
16683
17214
  if (/\[\s*\]$/.test(m[1]) && m[2] === "=") {
16684
- const v2 = valueWords5(value);
17215
+ const v2 = valueWords6(value);
16685
17216
  return { kind: "set", says: `Adds ${v2 ?? "a value"} to the end of ${targetWords2(m[1].replace(/\[\s*\]$/, ""))}`, code: code3 };
16686
17217
  }
16687
17218
  const keyedAt = m[1].indexOf("[");
@@ -16689,7 +17220,7 @@ function classifyWords(raw, { inner = 0 } = {}) {
16689
17220
  const container = targetWords2(m[1].slice(0, keyedAt));
16690
17221
  const keys = [...m[1].slice(keyedAt).matchAll(/\[\s*([^\]]*?)\s*\]/g)].map((k) => k[1]);
16691
17222
  const keyWords = (k) => /^\$\d/.test(k) ? `\`${k}\`` : /^["'`].*["'`]$/.test(k) ? `"${k.slice(1, -1)}"` : /^:\w+$/.test(k) && FN_CONTEXT?.language === "ruby" ? `"${k.slice(1)}"` : /^[\w$.]+$/.test(k) ? possessiveWords(k) : `\`${k}\``;
16692
- const v2 = value ? valueWords5(value) : null;
17223
+ const v2 = value ? valueWords6(value) : null;
16693
17224
  const what = v2 ?? "a value";
16694
17225
  const where = keys.length === 1 ? `under ${keyWords(keys[0])} in ${container}` : `at ${keys.map(keyWords).join(", then ")} in ${container}`;
16695
17226
  if (m[2] === "=") return { kind: "set", says: / if .*, otherwise /.test(what) ? `Stores ${where}${also}: ${what}` : `Stores ${what} ${where}${also}`, code: code3 };
@@ -16698,15 +17229,15 @@ function classifyWords(raw, { inner = 0 } = {}) {
16698
17229
  return { kind: "other", says: clip(head, 70), code: code3 };
16699
17230
  }
16700
17231
  if (m[2] === "*=" || m[2] === "/=") {
16701
- const v2 = valueWords5(value) ?? null;
17232
+ const v2 = valueWords6(value) ?? null;
16702
17233
  return v2 ? { kind: "set", says: `${m[2] === "*=" ? "Multiplies" : "Divides"} ${target} by ${v2}`, code: code3 } : { kind: "other", says: clip(head, 70), code: code3 };
16703
17234
  }
16704
17235
  if (m[2] === "||=" || m[2] === "??=") {
16705
- const v2 = valueWords5(value);
17236
+ const v2 = valueWords6(value);
16706
17237
  return { kind: "set", says: v2 ? `Sets ${target} to ${v2}, if it has no value yet` : `Sets ${target}, if it has no value yet`, code: code3 };
16707
17238
  }
16708
17239
  if (m[2] === ".=") {
16709
- const v2 = valueWords5(value);
17240
+ const v2 = valueWords6(value);
16710
17241
  return { kind: "set", says: v2 ? `Adds ${v2} to the end of ${target}` : `Adds to the end of ${target}`, code: code3 };
16711
17242
  }
16712
17243
  if (m[2] === "%=" || m[2] === "&&=") return { kind: "other", says: clip(head, 70), code: code3 };
@@ -16716,7 +17247,7 @@ function classifyWords(raw, { inner = 0 } = {}) {
16716
17247
  return { kind: "set", says: given ? `Keeps the ${words7(value)} it is given` : `Keeps ${words7(value)} as its own ${words7(value)}`, code: code3 };
16717
17248
  }
16718
17249
  if ((m[2] === "+=" || m[2] === "-=") && value) {
16719
- const v2 = /^[\w.]+$/.test(value) && !/^\d/.test(value) ? value.split(".").filter((p) => !/^(self|this)$/.test(p)).slice(-2).map(words7).join(" ") : valueWords5(value) ?? sayCommon(value);
17250
+ const v2 = /^[\w.]+$/.test(value) && !/^\d/.test(value) ? value.split(".").filter((p) => !/^(self|this)$/.test(p)).slice(-2).map(words7).join(" ") : valueWords6(value) ?? sayCommon(value);
16720
17251
  const add = m[2] === "+=";
16721
17252
  return { kind: "set", says: v2 ? `${add ? "Adds" : "Subtracts"} ${v2} ${add ? "to" : "from"} ${target}` : `${add ? "Adds to" : "Subtracts from"} ${target}`, code: code3 };
16722
17253
  }
@@ -16730,14 +17261,14 @@ function classifyWords(raw, { inner = 0 } = {}) {
16730
17261
  const known = sayCall(c2, firstArgs(value));
16731
17262
  if (known) return { kind: "call", says: `${known}, keeping the result as ${target}`, code: code3, callee: c2 };
16732
17263
  if (/^new\s/.test(value) || makesType(c2) && (LANG !== "cpp" || sameType(c2, declType))) return { kind: "set", says: `Creates a new ${c2.split(".").pop()} as ${target}`, code: code3 };
16733
- return { kind: "set", says: `Works out ${target} from ${lastWords(c2)}`, code: code3, callee: c2 };
17264
+ return { kind: "set", says: `Works out ${target} from ${callWords2(c2, value)}`, code: code3, callee: c2 };
16734
17265
  }
16735
17266
  if (!value) return { kind: "set", says: `Works out ${target}`, code: code3 };
16736
17267
  if (m[2] === "+=" || m[2] === "-=") {
16737
17268
  const what = /^[\w.]+$/.test(value) ? `${value.split(".").filter((p) => !/^(self|this)$/.test(p)).slice(-2).map(words7).join(" ")} ` : /^-?\d+(\.\d+)?$/.test(value) ? `${value} ` : "";
16738
17269
  return { kind: "set", says: what ? `${m[2] === "+=" ? "Adds" : "Subtracts"} ${what}${m[2] === "+=" ? "to" : "from"} ${target}` : `${m[2] === "+=" ? "Adds to" : "Subtracts from"} ${target}`, code: code3 };
16739
17270
  }
16740
- const v = sayValue(value);
17271
+ const v = sayValue(value) ?? sayArithmetic(value);
16741
17272
  return { kind: "set", says: v ? `Sets ${target} to ${v}` : `Works out ${target}`, code: code3 };
16742
17273
  }
16743
17274
  if (m = head.match(/^([\w$.]+)\.(?:set|Set|put|setdefault|Add)\(\s*["'`]([\w.\-: ]{1,40})["'`]\s*,/)) return { kind: "call", says: `Sets "${m[2]}" on ${lastSeg(m[1])}`, code: code3, callee: `${m[1]}.set` };
@@ -16750,15 +17281,57 @@ function classifyWords(raw, { inner = 0 } = {}) {
16750
17281
  const owner = m[1].split(".").filter((p) => !/^(self|this)$/.test(p));
16751
17282
  const where = owner.length > 1 ? `${words7(owner[owner.length - 2])}'s ${words7(owner[owner.length - 1])}` : words7(owner[0] || m[1]);
16752
17283
  const added = /^new\s+([A-Z]\w*)/.exec(head.slice(head.indexOf("(") + 1))?.[1];
16753
- const open0 = head.indexOf("("), close0 = closeOf(head, open0);
16754
- const argText = close0 > open0 ? head.slice(open0 + 1, close0) : "";
16755
- if (splitTopArgs(argText).length > 1) return { kind: "call", says: `Adds to ${where}`, code: code3, callee: m[1] };
16756
- return { kind: "call", says: added ? `Adds a new ${words7(added)} to ${where}` : m[2] && /^[A-Za-z_][\w$]*$/.test(m[2]) && m[2] !== "new" ? `Adds ${words7(m[2])} to ${where}` : `Adds to ${where}`, code: code3, callee: m[1] };
17284
+ const whole = closeOf(head, head.indexOf("(")) > head.indexOf("(") ? head : text2.replace(/\s+/g, " ");
17285
+ const open0 = whole.indexOf("("), close0 = closeOf(whole, open0);
17286
+ const argText = close0 > open0 ? whole.slice(open0 + 1, close0) : "";
17287
+ const args = argText.trim() ? splitTopArgs(argText) : [];
17288
+ const addedWhat = (a) => {
17289
+ const t = String(a).trim();
17290
+ if (/^\{[\s\S]*\}$/.test(t)) {
17291
+ if (text2.split("\n").length > 7) return "an entry";
17292
+ const parts = splitTopArgs(t.slice(1, -1));
17293
+ const keys = parts.map((p) => /^\.\.\./.test(p) ? null : (p.match(/^\s*['"]?([A-Za-z_$][\w$]*)['"]?\s*(?::|$|\()/) || [])[1]).filter(Boolean);
17294
+ if (!parts.length) return "an empty entry";
17295
+ if (!keys.length) return null;
17296
+ return `an entry (${keys.slice(0, 4).map(words7).join(", ")}${keys.length > 4 || keys.length < parts.length ? ", \u2026" : ""})`;
17297
+ }
17298
+ if (/^(?:''|""|``)$/.test(t)) return '""';
17299
+ if (t.startsWith("`")) {
17300
+ const q2 = templateWithValues(t, 60);
17301
+ return q2 != null ? `"${q2}"` : null;
17302
+ }
17303
+ if (/^["']/.test(t)) {
17304
+ const q2 = wholeWords(firstText(t, 60));
17305
+ return q2 ? `"${q2}"` : null;
17306
+ }
17307
+ if (/^new\s+[A-Z]\w*/.test(t)) return `a new ${t.match(/^new\s+([A-Z]\w*)/)[1]}`;
17308
+ if (/^[A-Za-z_$][\w$]*$/.test(t)) return words7(t);
17309
+ if (/^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(t)) return possessiveWords(t);
17310
+ const c2 = callee(t);
17311
+ if (c2 && closeOf(t, t.indexOf("(")) === t.length - 1) return `the result of ${callWords2(c2, t)}`;
17312
+ return null;
17313
+ };
17314
+ if (args.length > 1 && !/\.(?:push|unshift)\(/.test(whole)) return { kind: "call", says: `Adds to ${where}`, code: code3, callee: m[1] };
17315
+ if (args.length > 1) {
17316
+ const ws = args.map(addedWhat);
17317
+ const said = ws.every(Boolean) && args.length <= 3 ? `${ws.slice(0, -1).join(", ")} and ${ws[ws.length - 1]}` : null;
17318
+ return { kind: "call", says: said ? `Adds ${said} to ${where}` : `Adds several values to ${where}`, code: code3, callee: m[1] };
17319
+ }
17320
+ const one = args.length === 1 ? addedWhat(args[0]) : null;
17321
+ return { kind: "call", says: added ? `Adds a new ${words7(added)} to ${where}` : one ? `Adds ${one} to ${where}` : `Adds to ${where}`, code: code3, callee: m[1] };
16757
17322
  }
16758
17323
  const c = callee(head);
16759
17324
  if (c) {
16760
17325
  const known = sayCall(c, firstArgs(head));
16761
- return { kind: "call", says: known || `Calls ${lastWords(c)}`, code: code3, callee: c };
17326
+ if (known) return { kind: "call", says: known, code: code3, callee: c };
17327
+ const o = head.indexOf("("), cl = o >= 0 ? closeOf(head, o) : -1;
17328
+ const only = cl > o && /^\s*;?\s*$/.test(head.slice(cl + 1)) ? splitTopArgs(head.slice(o + 1, cl)) : [];
17329
+ if ((LANG === "typescript" || LANG === "javascript" || LANG === "python") && only.length === 1 && !/^\s*(?:async\s*)?(?:\(|function\b|[A-Za-z_$][\w$]*\s*=>)/.test(only[0]) && !/^(?:exec|eval|compile|__import__|execfile|Function|setTimeout|setInterval)$/.test(c)) {
17330
+ const t = only[0].trim();
17331
+ const w = t.startsWith("`") ? templateWithValues(t, 60) ? `"${templateWithValues(t, 60)}"` : null : /^["']/.test(t) ? wholeWords(firstText(t, 60)) ? `"${wholeWords(firstText(t, 60))}"` : null : /^[A-Za-z_$][\w$]*$/.test(t) ? words7(t) : /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)+$/.test(t) ? possessiveWords(t) : callee(t) && closeOf(t, t.indexOf("(")) === t.length - 1 && !/^new\s/.test(t) ? `the result of ${callWords2(callee(t), t)}` : null;
17332
+ if (w && !ENDS_ON_PREPOSITION.test(callWords2(c, head))) return { kind: "call", says: `Calls ${callWords2(c, head)} (with ${w})`, code: code3, callee: c };
17333
+ }
17334
+ return { kind: "call", says: `Calls ${callWords2(c, head)}`, code: code3, callee: c };
16762
17335
  }
16763
17336
  if ((m = head.match(/^([a-z_][\w.]*[?!]?)\s+(?![=<>!+\-*/%]|and\b|or\b|if\b|unless\b)(.+)$/)) && !/^(?:if|for|while|return|else|elsif|when|case|def|class|module|end|not|const|let|var|val|new|await|typeof|delete|void|in|of|throw|import|export|from|as|is)$/.test(m[1])) {
16764
17337
  if (/^assert/.test(m[1])) return { kind: "check", says: `Checks: ${clip(head, 60)}`, code: code3 };
@@ -17298,6 +17871,31 @@ function stepsFrom(statements) {
17298
17871
  giveValue(st.children, t);
17299
17872
  giveValue(st.otherwise, t);
17300
17873
  }
17874
+ if (LANG === "typescript" || LANG === "javascript") {
17875
+ for (const st of steps) {
17876
+ const r = /^\s*[A-Za-z_$][\w$]*\.(get|post|put|patch|delete|all)\(\s*['"`]([^'"`]+)['"`]\s*,/.exec(String(st.code ?? ""));
17877
+ if (!r || !/^\//.test(r[2])) continue;
17878
+ st.kind = "call";
17879
+ st.says = `Handles ${r[1] === "all" ? "every request to" : r[1].toUpperCase()} ${r[2]} (its steps are in that action)`;
17880
+ delete st.children;
17881
+ delete st.nested;
17882
+ delete st.restates;
17883
+ delete st.value;
17884
+ st.route = { method: r[1].toUpperCase(), path: r[2] };
17885
+ }
17886
+ }
17887
+ if (LANG === "typescript" || LANG === "javascript") {
17888
+ for (const st of steps) {
17889
+ const said = /^Calls ([\w ]+) with these steps$/.exec(String(st.says ?? ""));
17890
+ if (!said) continue;
17891
+ const code3 = String(st.code ?? "");
17892
+ let m;
17893
+ if (m = /\.command\(\s*(['"`])([\w:.\-]+)(?:\s[^'"`]*)?\1\s*\)/.exec(code3)) st.says = `Defines the command "${m[2]}"; when it runs, it does these steps`;
17894
+ else if (/\.transaction\(\s*(?:async\s*)?\(/.test(code3)) st.says = "Does these steps in one database transaction";
17895
+ else if (/\.withProgress\(/.test(code3)) st.says = "Shows progress while it does these steps";
17896
+ else if (m = /^\s*(?:await\s+)?[\w$.]+\(\s*(['"`])([^'"`$]{1,60})\1\s*,/.exec(code3)) st.says = `Calls ${said[1]} ("${m[2]}") with these steps`;
17897
+ }
17898
+ }
17301
17899
  const more = Math.max(0, steps.length - MAX_STEPS);
17302
17900
  for (const st of steps) if (restates(st)) st.restates = true;
17303
17901
  return { steps, more, skipped, readable: readableShare(steps) };
@@ -17655,8 +18253,8 @@ function braceStatements(stmts, split = null) {
17655
18253
  function cBlockOpen(text2, head0) {
17656
18254
  const o = text2.indexOf("(");
17657
18255
  const c = o >= 0 ? closeOf(text2, o) : -1;
17658
- const attr = c > 0 ? text2.slice(c + 1).match(/^\s*\[\[[^\[\]]*\]\]\s*\{/) : null;
17659
- return attr ? c + attr[0].length : blockOpen(text2, head0);
18256
+ const attr2 = c > 0 ? text2.slice(c + 1).match(/^\s*\[\[[^\[\]]*\]\]\s*\{/) : null;
18257
+ return attr2 ? c + attr2[0].length : blockOpen(text2, head0);
17660
18258
  }
17661
18259
  function blockBrace(text2) {
17662
18260
  let depth = 0;
@@ -18733,7 +19331,7 @@ function notesSummary(ast) {
18733
19331
  byLens
18734
19332
  };
18735
19333
  }
18736
- var COMPILER_VERSION = "1.1.0";
19334
+ var COMPILER_VERSION = "1.3.0";
18737
19335
  var PROOF_SCHEMA_VERSION = "0.1.0";
18738
19336
  var SOURCE_PRODUCT = "skillstech-compiler";
18739
19337
  function buildContractGraph(ast, generatedAt) {
@@ -22228,7 +22826,7 @@ function sayNode(n) {
22228
22826
  }
22229
22827
  var CODE_MAX = 160;
22230
22828
  function makeStepper(src) {
22231
- const lineAt3 = lineFinder2(src);
22829
+ const lineAt4 = lineFinder2(src);
22232
22830
  const codeOf = (n) => {
22233
22831
  const t = src.slice(n.at, n.end).replace(/\s+/g, " ").trim();
22234
22832
  return t.length > CODE_MAX ? `${t.slice(0, CODE_MAX - 1)}\u2026` : t;
@@ -22237,8 +22835,8 @@ function makeStepper(src) {
22237
22835
  const t = src.slice(n.at, n.end).split("\n")[0].trim();
22238
22836
  return t.length > CODE_MAX ? `${t.slice(0, CODE_MAX - 1)}\u2026` : t;
22239
22837
  };
22240
- const span = (n) => ({ startLine: lineAt3(n.at), endLine: lineAt3(Math.max(n.at, n.end - 1)) });
22241
- const base2 = (n, code3 = codeOf(n)) => ({ code: code3, line: lineAt3(n.at), span: span(n) });
22838
+ const span = (n) => ({ startLine: lineAt4(n.at), endLine: lineAt4(Math.max(n.at, n.end - 1)) });
22839
+ const base2 = (n, code3 = codeOf(n)) => ({ code: code3, line: lineAt4(n.at), span: span(n) });
22242
22840
  function steps(nodes2) {
22243
22841
  const out = [];
22244
22842
  for (let k = 0; k < nodes2.length; k++) {
@@ -22250,7 +22848,7 @@ function makeStepper(src) {
22250
22848
  if (ex && (ex.kind === "fail" || ex.failCode) && !ex.message) {
22251
22849
  const code3 = ex.exitCode ?? ex.failCode;
22252
22850
  const what = ex.exitCode ? `exit code ${code3}` : `return code ${code3}`;
22253
- out.push({ kind: "fail", says: `Fails with ${what}: "${got[0].stderr}"`, error: what, message: got[0].stderr, code: `${codeOf(n)}; ${codeOf(next)}`, line: lineAt3(n.at), span: { startLine: lineAt3(n.at), endLine: lineAt3(next.end - 1) } });
22851
+ out.push({ kind: "fail", says: `Fails with ${what}: "${got[0].stderr}"`, error: what, message: got[0].stderr, code: `${codeOf(n)}; ${codeOf(next)}`, line: lineAt4(n.at), span: { startLine: lineAt4(n.at), endLine: lineAt4(next.end - 1) } });
22254
22852
  k++;
22255
22853
  continue;
22256
22854
  }
@@ -22303,7 +22901,7 @@ function makeStepper(src) {
22303
22901
  case "if": {
22304
22902
  let first = null, tail = null;
22305
22903
  for (const c of n.clauses) {
22306
- const b = { kind: "branch", says: `If ${condWords2(c.cond)}`, code: src.slice(c.at, src.indexOf("\n", c.at) < 0 ? void 0 : src.indexOf("\n", c.at)).trim().slice(0, CODE_MAX), line: lineAt3(c.at), span: first ? { startLine: lineAt3(c.at), endLine: lineAt3(n.end - 1) } : span(n) };
22904
+ const b = { kind: "branch", says: `If ${condWords2(c.cond)}`, code: src.slice(c.at, src.indexOf("\n", c.at) < 0 ? void 0 : src.indexOf("\n", c.at)).trim().slice(0, CODE_MAX), line: lineAt4(c.at), span: first ? { startLine: lineAt4(c.at), endLine: lineAt4(n.end - 1) } : span(n) };
22307
22905
  const kids2 = steps(c.body);
22308
22906
  if (kids2.length) b.children = kids2;
22309
22907
  if (!first) first = b;
@@ -22316,7 +22914,7 @@ function makeStepper(src) {
22316
22914
  if (n.otherwise) {
22317
22915
  const kids2 = steps(n.otherwise);
22318
22916
  tail.otherwise = kids2;
22319
- tail.otherwiseLine = lineAt3(n.elseAt);
22917
+ tail.otherwiseLine = lineAt4(n.elseAt);
22320
22918
  }
22321
22919
  return [first];
22322
22920
  }
@@ -22365,7 +22963,7 @@ function makeStepper(src) {
22365
22963
  says = `When it is ${ws.length > 1 ? `${ws.slice(0, -1).join(", ")} or ${ws.at(-1)}` : ws[0]}`;
22366
22964
  } else says = `When it matches ${pats.map((p) => asCode3(p)).join(" or ")}`;
22367
22965
  const kids2 = steps(a.body);
22368
- return { kind: "check", says, caseLabel: true, code: src.slice(a.at, src.indexOf(")", a.at) + 1).trim().slice(0, 90), line: lineAt3(a.at), span: { startLine: lineAt3(a.at), endLine: lineAt3(Math.max(a.at, a.end - 1)) }, ...kids2.length ? { children: kids2 } : {} };
22966
+ return { kind: "check", says, caseLabel: true, code: src.slice(a.at, src.indexOf(")", a.at) + 1).trim().slice(0, 90), line: lineAt4(a.at), span: { startLine: lineAt4(a.at), endLine: lineAt4(Math.max(a.at, a.end - 1)) }, ...kids2.length ? { children: kids2 } : {} };
22369
22967
  });
22370
22968
  return [{ kind: "branch", says: `Chooses by ${sayWord(n.word)}`, ...base2(n, headOf2(n)), ...arms.length ? { children: arms } : {} }];
22371
22969
  }
@@ -22424,7 +23022,7 @@ function makeStepper(src) {
22424
23022
  };
22425
23023
  return build(0);
22426
23024
  }
22427
- return { steps, lineAt: lineAt3, codeOf, headOf: headOf2 };
23025
+ return { steps, lineAt: lineAt4, codeOf, headOf: headOf2 };
22428
23026
  }
22429
23027
  function docAbove3(lines, line) {
22430
23028
  const run = [];
@@ -22545,7 +23143,7 @@ function shellReading(src, file = "") {
22545
23143
  const last = f.body[f.body.length - 1];
22546
23144
  if (last?.type === "simple" && last.words[0] === "exit" && /^[1-9]\d*$/.test(last.words[1] ?? "")) DIES.set(f.name, last.words[1]);
22547
23145
  }
22548
- const { steps, lineAt: lineAt3 } = makeStepper(src);
23146
+ const { steps, lineAt: lineAt4 } = makeStepper(src);
22549
23147
  const errors = /* @__PURE__ */ new Map();
22550
23148
  const noteErrors = (list3) => {
22551
23149
  for (const s of list3 || []) {
@@ -22555,19 +23153,19 @@ function shellReading(src, file = "") {
22555
23153
  }
22556
23154
  };
22557
23155
  for (const f of all) {
22558
- const line = lineAt3(f.at);
23156
+ const line = lineAt4(f.at);
22559
23157
  const st = steps(f.body);
22560
- if (!st.length) st.push({ kind: "return", says: "Does nothing", code: src.slice(f.at, f.end).replace(/\s+/g, " ").trim().slice(0, 160), line, span: { startLine: line, endLine: lineAt3(f.end - 1) } });
23158
+ if (!st.length) st.push({ kind: "return", says: "Does nothing", code: src.slice(f.at, f.end).replace(/\s+/g, " ").trim().slice(0, 160), line, span: { startLine: line, endLine: lineAt4(f.end - 1) } });
22561
23159
  noteErrors(st);
22562
23160
  const first = f.body[0], lastN = f.body[f.body.length - 1];
22563
- fns.push({ name: f.name, line, params: inputsOf(f.body, src), doc: docAbove3(lines, line), steps: st, body: first ? [lineAt3(first.at), lineAt3(lastN.end - 1)] : null });
23161
+ fns.push({ name: f.name, line, params: inputsOf(f.body, src), doc: docAbove3(lines, line), steps: st, body: first ? [lineAt4(first.at), lineAt4(lastN.end - 1)] : null });
22564
23162
  }
22565
23163
  const top = nodes2.filter((n) => n.type !== "function");
22566
23164
  if (top.length) {
22567
23165
  const st = steps(top);
22568
23166
  noteErrors(st);
22569
23167
  const name = file ? String(file).split(/[\\/]/).pop() : "script";
22570
- fns.push({ name, line: lineAt3(top[0].at), params: inputsOf(top, src), doc: headerDoc(lines), steps: st, body: [lineAt3(top[0].at), lineAt3(top[top.length - 1].end - 1)], topLevel: true, headline: `Runs ${name}, from top to bottom.` });
23168
+ fns.push({ name, line: lineAt4(top[0].at), params: inputsOf(top, src), doc: headerDoc(lines), steps: st, body: [lineAt4(top[0].at), lineAt4(top[top.length - 1].end - 1)], topLevel: true, headline: `Runs ${name}, from top to bottom.` });
22571
23169
  }
22572
23170
  fns.sort((a, b) => a.line - b.line);
22573
23171
  KNOWN_FNS = /* @__PURE__ */ new Set();
@@ -23619,7 +24217,7 @@ function docBefore(toks, idx) {
23619
24217
  }
23620
24218
  function makeReader(src) {
23621
24219
  const toks = tokenize3(src);
23622
- const lineAt3 = lineFinder3(src);
24220
+ const lineAt4 = lineFinder3(src);
23623
24221
  const fns = [], things = [], errors = /* @__PURE__ */ new Map(), tests = [];
23624
24222
  const code3 = (s, e) => {
23625
24223
  const t = src.slice(toks[s].at, toks[e - 1].end).replace(/\s+/g, " ").trim();
@@ -23629,8 +24227,8 @@ function makeReader(src) {
23629
24227
  const t = src.slice(toks[s].at, toks[e - 1].end).split("\n")[0].trim();
23630
24228
  return t.length > 160 ? `${t.slice(0, 159)}\u2026` : t;
23631
24229
  };
23632
- const spanOf2 = (s, e) => ({ startLine: lineAt3(toks[s].at), endLine: lineAt3(toks[e - 1].end - 1) });
23633
- const base2 = (s, e, c = code3(s, e)) => ({ code: c, line: lineAt3(toks[s].at), span: spanOf2(s, e) });
24230
+ const spanOf2 = (s, e) => ({ startLine: lineAt4(toks[s].at), endLine: lineAt4(toks[e - 1].end - 1) });
24231
+ const base2 = (s, e, c = code3(s, e)) => ({ code: c, line: lineAt4(toks[s].at), span: spanOf2(s, e) });
23634
24232
  const nextTok = (i, to) => {
23635
24233
  while (i < to && (toks[i].t === "nl" || toks[i].t === "comment")) i++;
23636
24234
  return i;
@@ -23669,7 +24267,7 @@ function makeReader(src) {
23669
24267
  const blk = blockAt(toks[p].match + 1, e);
23670
24268
  if (!blk) break;
23671
24269
  const cond = toks.slice(p + 1, toks[p].match);
23672
- const b = { kind: "branch", says: `If ${gated(cond, condWords3(cond, false)) ?? asCodeWords(code3(p + 1, toks[p].match))}`, cond: condJs(cond), code: head(i, blk[1] + 1), line: lineAt3(toks[i].at), span: first ? spanOf2(i, e) : spanOf2(s, e) };
24270
+ const b = { kind: "branch", says: `If ${gated(cond, condWords3(cond, false)) ?? asCodeWords(code3(p + 1, toks[p].match))}`, cond: condJs(cond), code: head(i, blk[1] + 1), line: lineAt4(toks[i].at), span: first ? spanOf2(i, e) : spanOf2(s, e) };
23673
24271
  const kids2 = stepsIn(blk[0], blk[1], ctx);
23674
24272
  if (kids2.length) b.children = kids2;
23675
24273
  if (!first) first = b;
@@ -23685,7 +24283,7 @@ function makeReader(src) {
23685
24283
  const blk = blockAt(i + 1, e);
23686
24284
  if (!blk) break;
23687
24285
  tail.otherwise = stepsIn(blk[0], blk[1], ctx);
23688
- tail.otherwiseLine = lineAt3(toks[i].at);
24286
+ tail.otherwiseLine = lineAt4(toks[i].at);
23689
24287
  i = blk[1] + 1;
23690
24288
  continue;
23691
24289
  }
@@ -23766,7 +24364,7 @@ function makeReader(src) {
23766
24364
  if (!body2) break;
23767
24365
  const kids2 = stepsIn(body2[0], body2[1], ctx);
23768
24366
  const label = /^default$/i.test(pat.text) ? "Otherwise" : pat.text === "{" ? `When ${gated(toks.slice(patStart + 1, pat.match), condWords3(toks.slice(patStart + 1, pat.match), false)) ?? asCodeWords(code3(patStart + 1, pat.match))}` : flags2.includes("-regex") ? `When it matches the pattern ${sayValue2([pat])}` : flags2.includes("-wildcard") ? `When it matches ${sayValue2([pat])}` : `When it is ${sayValue2(toks.slice(patStart, k)) ?? pat.text}`;
23769
- arms.push({ kind: "check", says: label, caseLabel: true, code: head(patStart, body2[1] + 1).slice(0, 90), line: lineAt3(pat.at), span: spanOf2(patStart, body2[1] + 1), ...kids2.length ? { children: kids2 } : {}, _pat: pat });
24367
+ arms.push({ kind: "check", says: label, caseLabel: true, code: head(patStart, body2[1] + 1).slice(0, 90), line: lineAt4(pat.at), span: spanOf2(patStart, body2[1] + 1), ...kids2.length ? { children: kids2 } : {}, _pat: pat });
23770
24368
  k = body2[1] + 1;
23771
24369
  }
23772
24370
  for (const a of arms) delete a._pat;
@@ -23797,14 +24395,14 @@ function makeReader(src) {
23797
24395
  } finally {
23798
24396
  IN_CATCH--;
23799
24397
  }
23800
- (step.handlers ||= []).push({ says: types.length ? `If ${types.join(" or ")} goes wrong` : "If anything goes wrong", line: lineAt3(toks[i].at), steps: hs });
24398
+ (step.handlers ||= []).push({ says: types.length ? `If ${types.join(" or ")} goes wrong` : "If anything goes wrong", line: lineAt4(toks[i].at), steps: hs });
23801
24399
  i = nextTok(b[1] + 1, e);
23802
24400
  continue;
23803
24401
  }
23804
24402
  if (w === "finally") {
23805
24403
  const b = blockAt(i + 1, e);
23806
24404
  if (!b) break;
23807
- step.always = { line: lineAt3(toks[i].at), steps: stepsIn(b[0], b[1], ctx) };
24405
+ step.always = { line: lineAt4(toks[i].at), steps: stepsIn(b[0], b[1], ctx) };
23808
24406
  i = nextTok(b[1] + 1, e);
23809
24407
  continue;
23810
24408
  }
@@ -23840,8 +24438,8 @@ function makeReader(src) {
23840
24438
  msg = null;
23841
24439
  name = varWords2(rest2[0].name);
23842
24440
  } else if (!rest2.length) return [{ kind: "fail", says: "Fails again with the same error", error: "the same error", ...base2(s, e) }];
23843
- if (msg) errors.set(msg, errors.get(msg) ?? lineAt3(t.at));
23844
- else if (name !== "an error") errors.set(name, errors.get(name) ?? lineAt3(t.at));
24441
+ if (msg) errors.set(msg, errors.get(msg) ?? lineAt4(t.at));
24442
+ else if (name !== "an error") errors.set(name, errors.get(name) ?? lineAt4(t.at));
23845
24443
  return [{ kind: "fail", says: `Fails with ${name}${msg ? `: "${msg}"` : ""}`, error: name, ...msg ? { message: msg } : {}, ...base2(s, e) }];
23846
24444
  }
23847
24445
  case "return": {
@@ -23901,7 +24499,7 @@ function makeReader(src) {
23901
24499
  if (/^(describe|context|it)$/i.test(t.text) && toks[nextTok(s + 1, e)]?.t === "str") {
23902
24500
  const name = stringText(toks[nextTok(s + 1, e)]);
23903
24501
  const blk = toks.slice(s, e).find((x) => x.text === "{" && x.match != null);
23904
- if (/^it$/i.test(t.text)) tests.push({ name, line: lineAt3(t.at) });
24502
+ if (/^it$/i.test(t.text)) tests.push({ name, line: lineAt4(t.at) });
23905
24503
  else if (blk) stepsIn(blk.i + 1, blk.match, ctx);
23906
24504
  return [];
23907
24505
  }
@@ -23966,7 +24564,7 @@ function makeReader(src) {
23966
24564
  const msg = a.named.message ? sayValue2(a.named.message) : a.pos[0] ? sayValue2(a.pos[0]) : null;
23967
24565
  const text2 = msg ? msg.replace(/^"|"$/g, "") : null;
23968
24566
  const stops = STOP_ON_ERROR || /stop/i.test(a.named.erroraction?.map((x) => x.text).join("") ?? "");
23969
- if (text2) errors.set(text2, errors.get(text2) ?? lineAt3(head0.at));
24567
+ if (text2) errors.set(text2, errors.get(text2) ?? lineAt4(head0.at));
23970
24568
  return [stops ? { kind: "fail", says: `Fails with an error${text2 ? `: "${text2}"` : ""}`, error: "an error", ...text2 ? { message: text2 } : {}, ...base2(s, e) } : { kind: "call", says: `Reports an error${text2 ? `: "${text2}"` : ""} and carries on`, ...base2(s, e) }];
23971
24569
  }
23972
24570
  const lg = groups(list3);
@@ -24054,7 +24652,7 @@ function makeReader(src) {
24054
24652
  if (!steps.length) steps.push({ kind: "return", says: "Does nothing", ...base2(s, e, head(s, e)) });
24055
24653
  lastValueToReturn(steps);
24056
24654
  const first = nextTok(parts.from, blk[1]);
24057
- fns.push({ name, line: lineAt3(nameTok.at), params, doc, steps, body: first < blk[1] ? [lineAt3(toks[first].at), lineAt3(toks[blk[1]].at)] : null, _range: [parts.from, blk[1]] });
24655
+ fns.push({ name, line: lineAt4(nameTok.at), params, doc, steps, body: first < blk[1] ? [lineAt4(toks[first].at), lineAt4(toks[blk[1]].at)] : null, _range: [parts.from, blk[1]] });
24058
24656
  }
24059
24657
  function podeRoute(s, e) {
24060
24658
  const a = argsOf(toks.slice(s + 1, e));
@@ -24064,14 +24662,14 @@ function makeReader(src) {
24064
24662
  const sb = a.named.scriptblock;
24065
24663
  if (!sb || sb[0].text !== "{") return;
24066
24664
  const open = sb[0].i;
24067
- fns.push({ name: `${method} ${path}`, line: lineAt3(toks[s].at), params: [], route: { method, path }, steps: stepsIn(open + 1, sb[0].match), body: [lineAt3(toks[nextTok(open + 1, sb[0].match)]?.at ?? toks[open].at), lineAt3(toks[sb[0].match].at)] });
24665
+ fns.push({ name: `${method} ${path}`, line: lineAt4(toks[s].at), params: [], route: { method, path }, steps: stepsIn(open + 1, sb[0].match), body: [lineAt4(toks[nextTok(open + 1, sb[0].match)]?.at ?? toks[open].at), lineAt4(toks[sb[0].match].at)] });
24068
24666
  }
24069
24667
  function defineType(s, e, kw) {
24070
24668
  const nameTok = toks[nextTok(s + 1, e)];
24071
24669
  const blk = toks.slice(s, e).find((x) => x.text === "{" && x.match != null);
24072
24670
  if (!nameTok || !blk) return;
24073
24671
  const open = blk.i, close = blk.match;
24074
- const lines = [lineAt3(toks[s].at), lineAt3(toks[close].at)];
24672
+ const lines = [lineAt4(toks[s].at), lineAt4(toks[close].at)];
24075
24673
  const doc = docBefore(toks, s);
24076
24674
  if (kw === "enum") {
24077
24675
  const choices = [];
@@ -24088,7 +24686,7 @@ function makeReader(src) {
24088
24686
  const type = st.slice(0, v).reverse().find((x) => x.t === "type");
24089
24687
  const eq2 = st.findIndex((x, i) => i > v && x.text === "=");
24090
24688
  const def = eq2 > 0 ? st.slice(eq2 + 1) : null;
24091
- thing.knows.push({ name: st[v].name, type: type?.name ?? null, start: def ? def.map((x) => x.text).join(" ") : null, line: lineAt3(st[v].at) });
24689
+ thing.knows.push({ name: st[v].name, type: type?.name ?? null, start: def ? def.map((x) => x.text).join(" ") : null, line: lineAt4(st[v].at) });
24092
24690
  continue;
24093
24691
  }
24094
24692
  const nameAt = st.findIndex((x, i) => x.t === "word" && st[i + 1]?.text === "(");
@@ -24104,7 +24702,7 @@ function makeReader(src) {
24104
24702
  const first = nextTok(bOpen + 1, body2.match);
24105
24703
  const ret = st.slice(0, nameAt).reverse().find((x) => x.t === "type");
24106
24704
  if (mTok.text !== nameTok.text) thing.methods++;
24107
- fns.push({ name: mTok.text, line: lineAt3(mTok.at), params, returns: ret && !/^void$/i.test(ret.name) ? ret.name : null, doc: docBefore(toks, st[0].i), steps, body: first < body2.match ? [lineAt3(toks[first].at), lineAt3(toks[body2.match].at)] : null, _range: [bOpen + 1, body2.match] });
24705
+ fns.push({ name: mTok.text, line: lineAt4(mTok.at), params, returns: ret && !/^void$/i.test(ret.name) ? ret.name : null, doc: docBefore(toks, st[0].i), steps, body: first < body2.match ? [lineAt4(toks[first].at), lineAt4(toks[body2.match].at)] : null, _range: [bOpen + 1, body2.match] });
24108
24706
  if (mTok.text === nameTok.text) {
24109
24707
  for (const [x, y] of splitStatements(toks, bOpen + 1, body2.match)) {
24110
24708
  const st2 = at0(toks.slice(x, y));
@@ -24115,7 +24713,7 @@ function makeReader(src) {
24115
24713
  const start = param ? param.default ? { param: param.default } : { given: true } : val.map((q2) => q2.text).join(" ");
24116
24714
  if (k2) {
24117
24715
  if (k2.start == null || param) k2.start = start;
24118
- } else thing.knows.push({ name: st2[2].text, type: null, start, line: lineAt3(st2[0].at) });
24716
+ } else thing.knows.push({ name: st2[2].text, type: null, start, line: lineAt4(st2[0].at) });
24119
24717
  }
24120
24718
  }
24121
24719
  }
@@ -24123,7 +24721,7 @@ function makeReader(src) {
24123
24721
  delete thing.methods;
24124
24722
  things.push(thing);
24125
24723
  }
24126
- return { toks, fns, things, errors, tests, stepsIn, lineAt: lineAt3, splitStatements: () => splitStatements(toks, 0, toks.length), statement: statement2, nextTok, code: code3, cleanSteps };
24724
+ return { toks, fns, things, errors, tests, stepsIn, lineAt: lineAt4, splitStatements: () => splitStatements(toks, 0, toks.length), statement: statement2, nextTok, code: code3, cleanSteps };
24127
24725
  }
24128
24726
  var fixedOf = (toks) => {
24129
24727
  const v = at0(toks || []);
@@ -25202,7 +25800,7 @@ var KNOWN_FNS3 = /* @__PURE__ */ new Set();
25202
25800
  function makeReader2(src) {
25203
25801
  SRC = src;
25204
25802
  const toks = tokenize4(src);
25205
- const lineAt3 = lineFinder4(src);
25803
+ const lineAt4 = lineFinder4(src);
25206
25804
  const fns = [], things = [], errors = /* @__PURE__ */ new Map(), tests = [], defs = [];
25207
25805
  const code3 = (s, e) => {
25208
25806
  const t = src.slice(toks[s].at, toks[e - 1].end).replace(/\s+/g, " ").trim();
@@ -25212,8 +25810,8 @@ function makeReader2(src) {
25212
25810
  const t = src.slice(toks[s].at, toks[e - 1].end).split("\n")[0].trim();
25213
25811
  return t.length > 160 ? `${t.slice(0, 159)}\u2026` : t;
25214
25812
  };
25215
- const spanOf2 = (s, e) => ({ startLine: lineAt3(toks[s].at), endLine: lineAt3(toks[e - 1].end - 1) });
25216
- const base2 = (s, e, c = code3(s, e)) => ({ code: c, line: lineAt3(toks[s].at), span: spanOf2(s, e) });
25813
+ const spanOf2 = (s, e) => ({ startLine: lineAt4(toks[s].at), endLine: lineAt4(toks[e - 1].end - 1) });
25814
+ const base2 = (s, e, c = code3(s, e)) => ({ code: c, line: lineAt4(toks[s].at), span: spanOf2(s, e) });
25217
25815
  const next = (i, to) => {
25218
25816
  while (i < to && (toks[i].t === "nl" || toks[i].t === "comment")) i++;
25219
25817
  return i;
@@ -25265,7 +25863,7 @@ function makeReader2(src) {
25265
25863
  thenTo = elseAt >= 0 ? elseAt : e;
25266
25864
  }
25267
25865
  const c = condSaid(condT);
25268
- const step = { kind: "branch", says: `If ${c ?? `\`${code3(open + 1, close)}\``}`, cond: condJs2(condT), code: head(s, e), line: lineAt3(toks[s].at), span: spanOf2(s, e) };
25866
+ const step = { kind: "branch", says: `If ${c ?? `\`${code3(open + 1, close)}\``}`, cond: condJs2(condT), code: head(s, e), line: lineAt4(toks[s].at), span: spanOf2(s, e) };
25269
25867
  const kids2 = stepsOfBody(close + 1, thenTo, ctx);
25270
25868
  if (kids2.length) step.children = kids2;
25271
25869
  if (elseAt >= 0) {
@@ -25279,7 +25877,7 @@ function makeReader2(src) {
25279
25877
  }
25280
25878
  } else {
25281
25879
  step.otherwise = stepsOfBody(elseAt + 1, e, ctx);
25282
- step.otherwiseLine = lineAt3(toks[elseAt].at);
25880
+ step.otherwiseLine = lineAt4(toks[elseAt].at);
25283
25881
  }
25284
25882
  }
25285
25883
  return step;
@@ -25372,7 +25970,7 @@ function makeReader2(src) {
25372
25970
  const fnSteps = stepsOfBody(fv.from, fv.to, { last: true, fn: true });
25373
25971
  if (!fnSteps.length) fnSteps.push({ kind: "return", says: "Does nothing", ...base2(nameTok.i, fv.to, head(nameTok.i, fv.to)) });
25374
25972
  const [a, b] = bodyRange2(fv.from, fv.to);
25375
- const f = { name: route && !name ? `${route.method} ${route.path}` : name, line: lineAt3(nameTok.at), params, doc, steps: fnSteps, body: a < b && next(a, b) < b ? [lineAt3(toks[next(a, b)].at), lineAt3(toks[b - 1].end - 1)] : null, ...route ? { route } : {}, _fv: fv, ...owner ? { owner } : {} };
25973
+ const f = { name: route && !name ? `${route.method} ${route.path}` : name, line: lineAt4(nameTok.at), params, doc, steps: fnSteps, body: a < b && next(a, b) < b ? [lineAt4(toks[next(a, b)].at), lineAt4(toks[b - 1].end - 1)] : null, ...route ? { route } : {}, _fv: fv, ...owner ? { owner } : {} };
25376
25974
  fns.push(f);
25377
25975
  return f;
25378
25976
  }
@@ -25528,11 +26126,11 @@ function makeReader2(src) {
25528
26126
  const fv = fnValue(a.toks);
25529
26127
  const r = at02(a.toks).length ? range(at02(a.toks)) : null;
25530
26128
  if (a.name === "finally") {
25531
- step.always = { line: lineAt3(at02(a.toks)[0]?.at ?? toks[s].at), steps: r ? stepsOfBody(r[0], r[1], { ...ctx, last: false }) : [] };
26129
+ step.always = { line: lineAt4(at02(a.toks)[0]?.at ?? toks[s].at), steps: r ? stepsOfBody(r[0], r[1], { ...ctx, last: false }) : [] };
25532
26130
  continue;
25533
26131
  }
25534
26132
  const says = a.name === "error" ? "If anything goes wrong" : a.name === "warning" ? "If there is a warning" : a.name === "message" ? "If a message is written" : a.name === "interrupt" ? "If it is stopped" : `If ${a.name} goes wrong`;
25535
- (step.handlers ||= []).push({ says, line: lineAt3(at02(a.toks)[0]?.at ?? toks[s].at), steps: fv ? stepsOfBody(fv.from, fv.to, { ...ctx, last: !!target || ctx.last, fn: true }) : [] });
26133
+ (step.handlers ||= []).push({ says, line: lineAt4(at02(a.toks)[0]?.at ?? toks[s].at), steps: fv ? stepsOfBody(fv.from, fv.to, { ...ctx, last: !!target || ctx.last, fn: true }) : [] });
25536
26134
  }
25537
26135
  if (target) {
25538
26136
  for (const list3 of [step.children, ...(step.handlers || []).map((h) => h.steps)]) if (list3?.length) giveValue2({ kind: "branch", children: list3 }, target);
@@ -25553,7 +26151,7 @@ function makeReader2(src) {
25553
26151
  pending = [];
25554
26152
  const r = vtoks.length ? range(vtoks) : null;
25555
26153
  const kids2 = r ? stepsOfBody(r[0], r[1], ctx) : [];
25556
- arms.push({ kind: "check", says: names ? `When it is ${list2(names.map((n) => `"${n}"`)).replace(/,? and ([^,]*)$/, " or $1")}` : "Otherwise", caseLabel: true, code: names ? `${names.join(", ")} =` : "(default)", line: lineAt3(vtoks[0]?.at ?? toks[s].at), span: r ? spanOf2(r[0], r[1]) : spanOf2(s, e), ...kids2.length ? { children: kids2 } : {} });
26154
+ arms.push({ kind: "check", says: names ? `When it is ${list2(names.map((n) => `"${n}"`)).replace(/,? and ([^,]*)$/, " or $1")}` : "Otherwise", caseLabel: true, code: names ? `${names.join(", ")} =` : "(default)", line: lineAt4(vtoks[0]?.at ?? toks[s].at), span: r ? spanOf2(r[0], r[1]) : spanOf2(s, e), ...kids2.length ? { children: kids2 } : {} });
25557
26155
  }
25558
26156
  return { kind: "branch", says: `Chooses by ${sayValue3(subject?.toks ?? []) ?? "value"}`, ...base2(s, e, head(s, e)), ...arms.length ? { children: arms } : {} };
25559
26157
  }
@@ -25579,7 +26177,7 @@ function makeReader2(src) {
25579
26177
  const isVar = parts.length === 1 && one.length === 1 && one[0].t === "id";
25580
26178
  const single = !isVar && oneValue(parts) ? sayValue3(parts[0].toks) : null;
25581
26179
  const msg = isVar || single || !parts.length ? null : textOf2(parts, "", bare2 === "cli_abort" || bare2 === "ui_abort");
25582
- if (msg) errors.set(msg, errors.get(msg) ?? lineAt3(toks[s].at));
26180
+ if (msg) errors.set(msg, errors.get(msg) ?? lineAt4(toks[s].at));
25583
26181
  const cls = args.find((a) => a.name === "class");
25584
26182
  const name = cls ? at02(cls.toks)[0]?.value ?? "an error" : "an error";
25585
26183
  const says = isVar ? `Fails with the error in ${rWords(one[0].text)}` : single ? `Fails with the error ${/^the result of /.test(single) ? single.replace(/^the result of /, "made by ") : `in ${single}`}` : `Fails with ${name}${msg ? `: "${msg}"` : ""}`;
@@ -25607,7 +26205,7 @@ function makeReader2(src) {
25607
26205
  if (bare2 === "try") {
25608
26206
  const r = args[0] && at02(args[0].toks).length ? range(at02(args[0].toks)) : null;
25609
26207
  const kids2 = r ? stepsOfBody(r[0], r[1], { ...ctx, last: false }) : [];
25610
- return [{ kind: "try", says: "Tries these steps, and carries on if they fail", ...base2(s, e, head(s, e)), ...kids2.length ? { children: kids2 } : {}, handlers: [{ says: "If anything goes wrong", line: lineAt3(toks[s].at), steps: [] }] }];
26208
+ return [{ kind: "try", says: "Tries these steps, and carries on if they fail", ...base2(s, e, head(s, e)), ...kids2.length ? { children: kids2 } : {}, handlers: [{ says: "If anything goes wrong", line: lineAt4(toks[s].at), steps: [] }] }];
25611
26209
  }
25612
26210
  if (bare2 === "on.exit") {
25613
26211
  const r = args[0] && at02(args[0].toks).length ? range(at02(args[0].toks)) : null;
@@ -25621,7 +26219,7 @@ function makeReader2(src) {
25621
26219
  }
25622
26220
  if (bare2 === "test_that") {
25623
26221
  const name = at02(args[0]?.toks ?? [])[0]?.value;
25624
- if (name) tests.push({ name, line: lineAt3(toks[s].at) });
26222
+ if (name) tests.push({ name, line: lineAt4(toks[s].at) });
25625
26223
  return [];
25626
26224
  }
25627
26225
  if (bare2 === "return" || bare2 === "invisible") {
@@ -25658,7 +26256,7 @@ function makeReader2(src) {
25658
26256
  return [val ? { kind: "call", says: `Works out ${val}`, ...base2(s, e) } : { kind: "other", says: code3(s, e), ...base2(s, e) }];
25659
26257
  }
25660
26258
  function defineThing(name, call, s, e) {
25661
- const lines = [lineAt3(toks[s].at), lineAt3(toks[e - 1].end - 1)];
26259
+ const lines = [lineAt4(toks[s].at), lineAt4(toks[e - 1].end - 1)];
25662
26260
  const className = at02(call.args[0]?.toks ?? [])[0]?.value ?? at02(call.args.find((a) => a.name === "Classname")?.toks ?? [])[0]?.value ?? name;
25663
26261
  const { doc } = docAbove5(s);
25664
26262
  const thing = { kind: "record", name: className || name, lines, ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
@@ -25671,13 +26269,13 @@ function makeReader2(src) {
25671
26269
  for (const a of args || []) {
25672
26270
  if (!a.name) {
25673
26271
  const sv = at02(a.toks)[0];
25674
- if (sv?.t === "str") thing.knows.push({ name: sv.value, type: null, start: null, line: lineAt3(sv.at) });
26272
+ if (sv?.t === "str") thing.knows.push({ name: sv.value, type: null, start: null, line: lineAt4(sv.at) });
25675
26273
  continue;
25676
26274
  }
25677
26275
  const vt = at02(a.toks);
25678
26276
  if (fnValue(vt)) continue;
25679
26277
  const tv = typed && vt.length === 1 && vt[0].t === "str" ? vt[0].value : null;
25680
- thing.knows.push({ name: a.name, type: tv ? R_TYPE[tv] ?? tv : null, start: typed ? null : vt.map((x) => x.text).join(""), line: lineAt3(vt[0]?.at ?? toks[s].at) });
26278
+ thing.knows.push({ name: a.name, type: tv ? R_TYPE[tv] ?? tv : null, start: typed ? null : vt.map((x) => x.text).join(""), line: lineAt4(vt[0]?.at ?? toks[s].at) });
25681
26279
  }
25682
26280
  };
25683
26281
  let methods = 0;
@@ -25686,7 +26284,7 @@ function makeReader2(src) {
25686
26284
  const fv = a.name ? fnValue(a.toks) : null;
25687
26285
  if (!fv) continue;
25688
26286
  const f = defineFunction(a.name, fv, at02(a.toks)[0].i, toks[at02(a.toks)[0].i - 2] ?? toks[s]);
25689
- f.line = lineAt3(toks[at02(a.toks)[0].i - 2]?.at ?? toks[s].at);
26287
+ f.line = lineAt4(toks[at02(a.toks)[0].i - 2]?.at ?? toks[s].at);
25690
26288
  if (a.name !== "initialize") methods++;
25691
26289
  if (a.name === "initialize") {
25692
26290
  const byName = new Map(fv.params.map((p) => [p.name, p.default ? at02(p.default).map((x) => x.text).join("") : null]));
@@ -25700,7 +26298,7 @@ function makeReader2(src) {
25700
26298
  const start = val.length === 1 && byName.has(val[0].text) ? { param: byName.get(val[0].text) } : val.map((q2) => q2.text).join("");
25701
26299
  if (k) {
25702
26300
  if (k.start == null || typeof start === "object") k.start = start;
25703
- } else thing.knows.push({ name: field, type: null, start, line: lineAt3(st[0].at) });
26301
+ } else thing.knows.push({ name: field, type: null, start, line: lineAt4(st[0].at) });
25704
26302
  }
25705
26303
  }
25706
26304
  }
@@ -25725,7 +26323,7 @@ function makeReader2(src) {
25725
26323
  thing._methods = methods;
25726
26324
  things.push(thing);
25727
26325
  }
25728
- return { toks, fns, things, errors, tests, stepsIn, lineAt: lineAt3, next, statement: statement2, code: code3, base: base2 };
26326
+ return { toks, fns, things, errors, tests, stepsIn, lineAt: lineAt4, next, statement: statement2, code: code3, base: base2 };
25729
26327
  }
25730
26328
  function decisionOf2(r, fv) {
25731
26329
  const { toks } = r;
@@ -26105,7 +26703,7 @@ function balancedReturnHead(after) {
26105
26703
  if (c === "<" || c === "(" || c === "[") depth++;
26106
26704
  else if (c === ">" || c === ")" || c === "]") depth--;
26107
26705
  else if (c === "{") {
26108
- if (depth === 0) break;
26706
+ if (depth === 0 && !/^$|[|&]$/.test(after.slice(lead[0].length, i).trim())) break;
26109
26707
  depth++;
26110
26708
  } else if (c === "}") depth--;
26111
26709
  else if (c === ";" && depth === 0) break;
@@ -26188,7 +26786,8 @@ function findFunctions(src, language) {
26188
26786
  const patterns = {
26189
26787
  typescript: [
26190
26788
  /(?:export\s+)?(?:default\s+)?(?:async\s+)?function\s*\*?\s*(\w+)\s*(?:<[^>]*>)?\s*\(/g,
26191
- /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::[^=]+)?=\s*(?:async\s*)?(?:<[^>]*>)?\(/g,
26789
+ // The type annotation stops at the end of its statement (";"), or `let a: T;` would name the next line's function.
26790
+ /(?:export\s+)?(?:const|let|var)\s+(\w+)\s*(?::[^=;]+)?=\s*(?:async\s*)?(?:<[^>]*>)?\(/g,
26192
26791
  /^\s*(?:public\s+|private\s+|protected\s+|static\s+|async\s+|readonly\s+)*(\w+)\s*(?:<[^>]*>)?\s*\(/gm
26193
26792
  ],
26194
26793
  go: [/func\s+(?:\([^)]*\)\s*)?(\w+)\s*(?:\[[^\]]*\])?\s*\(/g],
@@ -26261,18 +26860,43 @@ function findFunctions(src, language) {
26261
26860
  fns.push({ name: `${m[1].toUpperCase()} ${m[2]}`, line: lineAt(src, m.index), params: [], returns: null, bodyStart: brace + 1, body: src.slice(brace + 1, bc), route: { method: m[1].toUpperCase(), path: m[2] } });
26262
26861
  }
26263
26862
  }
26264
- const routeRes = language === "php" ? [/\bRoute::(get|post|put|patch|delete|any)\(\s*['"]([^'"]+)['"]\s*,\s*(?:static\s+)?function\s*\(/g] : language === "go" ? [/\.(Get|Post|Put|Patch|Delete|GET|POST|PUT|PATCH|DELETE|HandleFunc|Handle)\(\s*"([^"]+)"\s*,\s*func\s*\(/g] : language === "typescript" || language === "javascript" ? [/\b\w+\.(get|post|put|patch|delete|all)\(\s*['"`]([^'"`]+)['"`]\s*,(?:[^,()]*,)*?\s*(?:async\s*)?(?:function\s*\w*\s*)?\(/g] : [];
26863
+ const routeRes = language === "php" ? [/\bRoute::(get|post|put|patch|delete|any)\(\s*['"]([^'"]+)['"]\s*,\s*(?:static\s+)?function\s*\(/g] : language === "go" ? [/\.(Get|Post|Put|Patch|Delete|GET|POST|PUT|PATCH|DELETE|HandleFunc|Handle)\(\s*"([^"]+)"\s*,\s*func\s*\(/g] : language === "typescript" || language === "javascript" ? [/\b\w+\.(get|post|put|patch|delete|all)\(\s*['"`]([^'"`]+)['"`]\s*,(?:[^,()]*,)*?\s*(?:[A-Za-z_$][\w$.]*(?:<[^<>()]*>)?\(\s*)*(?:async\s*)?(?:function\s*\w*\s*)?\(/g] : [];
26265
26864
  for (const re of routeRes) {
26266
26865
  let m;
26267
26866
  while (m = re.exec(src)) {
26268
26867
  const open = src.indexOf("(", m.index + m[0].length - 1);
26269
26868
  const close = matchClose(src, open);
26270
26869
  if (close < 0) continue;
26870
+ const method = /^handle/i.test(m[1]) ? "ANY" : m[1].toUpperCase();
26271
26871
  const brace = src.indexOf("{", close);
26272
- if (brace < 0 || !/^\s*(=>\s*)?(\w[\w.*\s]*)?\s*$/.test(src.slice(close + 1, brace))) continue;
26872
+ if (brace < 0 || !/^\s*(=>\s*)?(\w[\w.*\s]*)?\s*$/.test(src.slice(close + 1, brace))) {
26873
+ const arrow = /^\s*(?::\s*[^=()]+)?=>\s*/.exec(src.slice(close + 1));
26874
+ if (!(language === "typescript" || language === "javascript") || !arrow || src[close + 1 + arrow[0].length] === "{") continue;
26875
+ const from = close + 1 + arrow[0].length;
26876
+ let depth = 0, end = from, q2 = null;
26877
+ for (; end < src.length; end++) {
26878
+ const c = src[end];
26879
+ if (q2) {
26880
+ if (c === q2 && src[end - 1] !== "\\") q2 = null;
26881
+ continue;
26882
+ }
26883
+ if (c === "'" || c === '"' || c === "`") {
26884
+ q2 = c;
26885
+ continue;
26886
+ }
26887
+ if ("([{".includes(c)) depth++;
26888
+ else if (")]}".includes(c)) {
26889
+ if (depth === 0) break;
26890
+ depth--;
26891
+ } else if ((c === "," || c === ";") && depth === 0) break;
26892
+ }
26893
+ const expr = src.slice(from, end).trim();
26894
+ if (!expr) continue;
26895
+ fns.push({ name: `${method} ${m[2]}`, line: lineAt(src, m.index), params: [], returns: null, bodyStart: from - 7, body: `return ${expr};`, route: { method, path: m[2] }, expressionBody: true });
26896
+ continue;
26897
+ }
26273
26898
  const bc = matchClose(src, brace);
26274
26899
  if (bc < 0) continue;
26275
- const method = /^handle/i.test(m[1]) ? "ANY" : m[1].toUpperCase();
26276
26900
  fns.push({ name: `${method} ${m[2]}`, line: lineAt(src, m.index), params: [], returns: null, bodyStart: brace + 1, body: src.slice(brace + 1, bc), route: { method, path: m[2] } });
26277
26901
  }
26278
26902
  }
@@ -29198,9 +29822,9 @@ function candidates(type, u) {
29198
29822
  if (!out.size) out.add(0);
29199
29823
  return [...out].sort((a, b) => a - b);
29200
29824
  }
29201
- function assignments(inputs, values, cap5 = 4096) {
29825
+ function assignments(inputs, values, cap6 = 4096) {
29202
29826
  const total = inputs.reduce((n, i) => n * values[i].length, 1);
29203
- if (total <= cap5) {
29827
+ if (total <= cap6) {
29204
29828
  let acc = [{}];
29205
29829
  for (const name of inputs) acc = acc.flatMap((a) => values[name].map((v) => ({ ...a, [name]: v })));
29206
29830
  return acc;
@@ -29540,7 +30164,7 @@ function changedCases(before, after) {
29540
30164
  return { checked: a.all.length, changed, note: `Checked ${a.all.length} boundary input${a.all.length === 1 ? "" : "s"}; ${changed.length} now get${changed.length === 1 ? "s" : ""} a different answer. These are the values on each side of every limit, not every possible input.` };
29541
30165
  }
29542
30166
  var CMP_WORDS = { "<=": "at most", "<": "less than", ">=": "at least", ">": "more than", "==": "is", "!=": "is not" };
29543
- var COMPARISON_CHOICES = Object.entries(CMP_WORDS).map(([op, words13]) => ({ op, words: words13 }));
30167
+ var COMPARISON_CHOICES = Object.entries(CMP_WORDS).map(([op, words14]) => ({ op, words: words14 }));
29544
30168
  function ruleParts(when) {
29545
30169
  return tokenize(when).map((t) => {
29546
30170
  if (t.t === "num") return { kind: "number", value: t.v };
@@ -29861,8 +30485,8 @@ function parsePlainContract(source) {
29861
30485
  const input = parseInputLine(text2, line);
29862
30486
  if (RESERVED2.has(input.id) || !input.id) fail3(line, "Choose a different name for this input.");
29863
30487
  if (model.inputs.some((i) => i.id === input.id)) fail3(line, `${input.label} is listed twice.`);
29864
- const words13 = model.inputs.flatMap((i) => i.kind === "yesno" ? [i.yes, i.no] : []);
29865
- if (input.kind === "yesno" && (words13.includes(input.yes) || words13.includes(input.no))) fail3(line, "Each yes/no word must be unique across inputs.");
30488
+ const words14 = model.inputs.flatMap((i) => i.kind === "yesno" ? [i.yes, i.no] : []);
30489
+ if (input.kind === "yesno" && (words14.includes(input.yes) || words14.includes(input.no))) fail3(line, "Each yes/no word must be unique across inputs.");
29866
30490
  model.inputs.push(input);
29867
30491
  } else if (section === "decision") {
29868
30492
  let m;
@@ -30355,7 +30979,7 @@ function thunderTokens(line) {
30355
30979
  push(m[2]);
30356
30980
  push(m[3], "failure");
30357
30981
  push(m[4]);
30358
- words13(m[5]);
30982
+ words14(m[5]);
30359
30983
  } else if (m = rest2.match(/^(Answer:|Gives back|Returns)(\s*)(.*)$/)) {
30360
30984
  push(m[1], "structure");
30361
30985
  push(m[2]);
@@ -30363,7 +30987,7 @@ function thunderTokens(line) {
30363
30987
  } else if (m = rest2.match(/^(Ask:)(\s*)(.*)$/)) {
30364
30988
  push(m[1], "structure");
30365
30989
  push(m[2]);
30366
- words13(m[3], "question");
30990
+ words14(m[3], "question");
30367
30991
  } else if (m = rest2.match(/^`(.*)`(.*)$/)) {
30368
30992
  push(`\`${m[1]}\``, "unread");
30369
30993
  push(m[2], "unread");
@@ -30371,12 +30995,12 @@ function thunderTokens(line) {
30371
30995
  const s = rest2.match(STRUCTURE_WORDS);
30372
30996
  if (s) {
30373
30997
  push(s[0], "structure");
30374
- words13(rest2.slice(s[0].length));
30375
- } else words13(rest2);
30998
+ words14(rest2.slice(s[0].length));
30999
+ } else words14(rest2);
30376
31000
  }
30377
31001
  push(tail, "unread");
30378
31002
  return out;
30379
- function words13(text2, base2 = null) {
31003
+ function words14(text2, base2 = null) {
30380
31004
  const re = /("[^"]*")|(\$?-?\d[\d,]*(?:\.\d+)?%?)|\b(and|or|not|if|otherwise|for each|in|from|to|of)\b|\b(is at least|is at most|is less than|is more than|is not in|is in|is not set|is set|is not empty|is empty|is not|at least|at most|less than|more than|exactly|whether|has no)\b/g;
30381
31005
  let last = 0, x;
30382
31006
  while (x = re.exec(text2)) {
@@ -30555,6 +31179,1141 @@ function renderSame(r) {
30555
31179
  `;
30556
31180
  }
30557
31181
 
31182
+ // src/screens.mjs
31183
+ var words11 = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
31184
+ var cap3 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
31185
+ var lineAt2 = (src, i) => src.slice(0, Math.max(0, i)).split("\n").length;
31186
+ var squash2 = (s) => String(s).replace(/\s+/g, " ").trim();
31187
+ var clip3 = (s, n = 80) => {
31188
+ s = squash2(s);
31189
+ return s.length > n ? `${s.slice(0, n - 1)}\u2026` : s;
31190
+ };
31191
+ var SIMPLE_PATH = /^[A-Za-z_$][\w$]*(?:\??\.[A-Za-z_$][\w$]*|\(\))*$/;
31192
+ function pathWords(path) {
31193
+ const parts = String(path).replace(/\?\./g, ".").replace(/\(\)/g, "").split(".").filter(Boolean).map(words11);
31194
+ if (parts.length === 1) return parts[0];
31195
+ if (parts.length === 2) return parts[1] === "length" ? `how many ${parts[0]}` : `${parts[0]}'s ${parts[1]}`;
31196
+ return `the ${parts[parts.length - 1]} of ${parts.slice(0, -1).join("'s ")}`;
31197
+ }
31198
+ function conditionWords2(code3) {
31199
+ const c = squash2(code3).replace(/^\((.*)\)$/, "$1").replace(/\b([a-z]\w*)\(\)/g, "$1");
31200
+ let m;
31201
+ if ((m = /^!\s*([\w$.?]+)\.length$/.exec(c)) || (m = /^([\w$.?]+)\.length\s*===?\s*0$/.exec(c))) return `${pathWords(m[1])} is empty`;
31202
+ if (m = /^([\w$.?]+)\.length(?:\s*>\s*0)?$/.exec(c)) return `${pathWords(m[1])} is not empty`;
31203
+ if (m = /^!\s*([\w$.?]+)$/.exec(c)) return `not ${pathWords(m[1])}`;
31204
+ if (SIMPLE_PATH.test(c)) return /(?:^|\.)(?:is|has|can|should|show|open|visible|loading|enabled|disabled|active|checked|selected|done|ready|expanded|editing|valid)[A-Z\w]*$/.test(c) ? pathWords(c) : `${pathWords(c)} is set`;
31205
+ try {
31206
+ return withLanguage("typescript", () => sayCodeCondition(c));
31207
+ } catch {
31208
+ return `\`${clip3(c, 60)}\``;
31209
+ }
31210
+ }
31211
+ function skipString3(src, i) {
31212
+ const q2 = src[i];
31213
+ for (let j = i + 1; j < src.length; j++) {
31214
+ if (src[j] === "\\") {
31215
+ j++;
31216
+ continue;
31217
+ }
31218
+ if (q2 === "`" && src[j] === "$" && src[j + 1] === "{") {
31219
+ j = matchBrace(src, j + 1);
31220
+ continue;
31221
+ }
31222
+ if (src[j] === q2) return j + 1;
31223
+ }
31224
+ return src.length;
31225
+ }
31226
+ function jsxStartsAt(src, i) {
31227
+ if (src[i] !== "<" || !/[A-Za-z>]/.test(src[i + 1] ?? "")) return false;
31228
+ const before = src.slice(Math.max(0, i - 12), i).replace(/\s+$/, "");
31229
+ return before === "" || /(?:[(,{[?:=&|!]|=>|\breturn|\bdefault)$/.test(before);
31230
+ }
31231
+ function matchBrace(src, i) {
31232
+ const open = src[i], close = { "{": "}", "(": ")", "[": "]" }[open];
31233
+ let depth = 0;
31234
+ for (let j = i; j < src.length; j++) {
31235
+ const c = src[j];
31236
+ if (c === '"' || c === "'" || c === "`") {
31237
+ j = skipString3(src, j) - 1;
31238
+ continue;
31239
+ }
31240
+ if (c === "/" && src[j + 1] === "/") {
31241
+ const e = src.indexOf("\n", j);
31242
+ j = e < 0 ? src.length : e;
31243
+ continue;
31244
+ }
31245
+ if (c === "/" && src[j + 1] === "*") {
31246
+ const e = src.indexOf("*/", j + 2);
31247
+ j = e < 0 ? src.length : e + 1;
31248
+ continue;
31249
+ }
31250
+ if (c === "<" && jsxStartsAt(src, j)) {
31251
+ const r = parseJsx(src, j);
31252
+ if (r) {
31253
+ j = r.end - 1;
31254
+ continue;
31255
+ }
31256
+ }
31257
+ if (c === open) depth++;
31258
+ else if (c === close && --depth === 0) return j;
31259
+ }
31260
+ return -1;
31261
+ }
31262
+ function parseJsx(src, i) {
31263
+ if (src[i] !== "<") return null;
31264
+ const line = lineAt2(src, i);
31265
+ let j = i + 1;
31266
+ if (src[j] === ">") {
31267
+ const kids2 = jsxChildren(src, j + 1, "");
31268
+ return kids2 ? { node: { type: "el", tag: "Fragment", attrs: [], kids: kids2.kids, line }, end: kids2.end } : null;
31269
+ }
31270
+ const tm = /^[A-Za-z][\w.:-]*/.exec(src.slice(j));
31271
+ if (!tm) return null;
31272
+ const tag = tm[0];
31273
+ j += tag.length;
31274
+ const attrs = [];
31275
+ for (; ; ) {
31276
+ while (/\s/.test(src[j] ?? "")) j++;
31277
+ if (j >= src.length) return null;
31278
+ if (src.startsWith("/>", j)) return { node: { type: "el", tag, attrs, kids: [], line }, end: j + 2 };
31279
+ if (src[j] === ">") {
31280
+ const kids2 = jsxChildren(src, j + 1, tag);
31281
+ return kids2 ? { node: { type: "el", tag, attrs, kids: kids2.kids, line }, end: kids2.end } : null;
31282
+ }
31283
+ if (src[j] === "{") {
31284
+ const e = matchBrace(src, j);
31285
+ if (e < 0) return null;
31286
+ const code3 = src.slice(j + 1, e).trim();
31287
+ attrs.push(code3.startsWith("...") ? { name: "...", value: code3.slice(3), kind: "spread" } : { name: "?", value: code3, kind: "expr" });
31288
+ j = e + 1;
31289
+ continue;
31290
+ }
31291
+ const am = /^[^\s=/>{]+/.exec(src.slice(j));
31292
+ if (!am) return null;
31293
+ const name = am[0];
31294
+ j += name.length;
31295
+ while (/\s/.test(src[j] ?? "")) j++;
31296
+ if (src[j] !== "=") {
31297
+ attrs.push({ name, value: true, kind: "flag" });
31298
+ continue;
31299
+ }
31300
+ j++;
31301
+ while (/\s/.test(src[j] ?? "")) j++;
31302
+ if (src[j] === '"' || src[j] === "'") {
31303
+ const e = src.indexOf(src[j], j + 1);
31304
+ if (e < 0) return null;
31305
+ attrs.push({ name, value: src.slice(j + 1, e), kind: "text" });
31306
+ j = e + 1;
31307
+ } else if (src[j] === "{") {
31308
+ const e = matchBrace(src, j);
31309
+ if (e < 0) return null;
31310
+ attrs.push({ name, value: src.slice(j + 1, e).trim(), kind: "expr" });
31311
+ j = e + 1;
31312
+ } else return null;
31313
+ }
31314
+ }
31315
+ function jsxChildren(src, j, tag) {
31316
+ const kids2 = [];
31317
+ let text2 = [], textLine = lineAt2(src, j);
31318
+ const flush = () => {
31319
+ const t = text2.join("").replace(/\s*\n\s*/g, "").replace(/\s+/g, " ");
31320
+ if (t.trim()) kids2.push({ type: "text", parts: [t], line: textLine });
31321
+ text2 = [];
31322
+ };
31323
+ while (j < src.length) {
31324
+ if (src.startsWith("</", j)) {
31325
+ flush();
31326
+ const e = src.indexOf(">", j);
31327
+ if (e < 0) return null;
31328
+ return { kids: kids2, end: e + 1 };
31329
+ }
31330
+ if (src[j] === "<") {
31331
+ flush();
31332
+ const r = parseJsx(src, j);
31333
+ if (!r) return null;
31334
+ kids2.push(r.node);
31335
+ j = r.end;
31336
+ textLine = lineAt2(src, j);
31337
+ continue;
31338
+ }
31339
+ if (src[j] === "{") {
31340
+ flush();
31341
+ const e = matchBrace(src, j);
31342
+ if (e < 0) return null;
31343
+ const code3 = src.slice(j + 1, e).trim();
31344
+ if (code3 && !/^\/\*[\s\S]*\*\/$/.test(code3)) kids2.push({ type: "expr", code: code3, line: lineAt2(src, j) });
31345
+ j = e + 1;
31346
+ textLine = lineAt2(src, j);
31347
+ continue;
31348
+ }
31349
+ if (!text2.length) textLine = lineAt2(src, j);
31350
+ text2.push(src[j]);
31351
+ j++;
31352
+ }
31353
+ return null;
31354
+ }
31355
+ var VOID = /* @__PURE__ */ new Set(["area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"]);
31356
+ function parseTemplate(html, fileSrc = null, offset = 0) {
31357
+ const lineOf6 = (i2) => fileSrc ? lineAt2(fileSrc, offset + i2) : lineAt2(html, i2);
31358
+ let i = 0;
31359
+ const parseNodes = (stopTag, stopBrace) => {
31360
+ const out = [];
31361
+ let text2 = "", tl = lineOf6(i);
31362
+ const flush = () => {
31363
+ if (text2.trim()) out.push(textNode(text2, tl));
31364
+ text2 = "";
31365
+ };
31366
+ while (i < html.length) {
31367
+ if (stopBrace && html[i] === "}") {
31368
+ flush();
31369
+ i++;
31370
+ return out;
31371
+ }
31372
+ if (html.startsWith("<!--", i)) {
31373
+ flush();
31374
+ const e = html.indexOf("-->", i);
31375
+ i = e < 0 ? html.length : e + 3;
31376
+ continue;
31377
+ }
31378
+ if (html.startsWith("</", i)) {
31379
+ flush();
31380
+ const e = html.indexOf(">", i);
31381
+ i = e < 0 ? html.length : e + 1;
31382
+ return out;
31383
+ }
31384
+ if (html[i] === "@" && /^@(if|for|switch|defer|else|empty|case|default)\b/.test(html.slice(i))) {
31385
+ flush();
31386
+ const b = parseBlock();
31387
+ if (b) out.push(b);
31388
+ tl = lineOf6(i);
31389
+ continue;
31390
+ }
31391
+ if (html[i] === "<" && /[A-Za-z]/.test(html[i + 1] ?? "")) {
31392
+ flush();
31393
+ const el = parseElement();
31394
+ if (el) out.push(el);
31395
+ tl = lineOf6(i);
31396
+ continue;
31397
+ }
31398
+ if (!text2) tl = lineOf6(i);
31399
+ text2 += html[i];
31400
+ i++;
31401
+ }
31402
+ flush();
31403
+ return out;
31404
+ };
31405
+ const textNode = (t, line) => {
31406
+ const parts = [];
31407
+ let rest2 = squash2(t), m;
31408
+ while (m = /\{\{\s*([\s\S]*?)\s*\}\}/.exec(rest2)) {
31409
+ if (m.index) parts.push(rest2.slice(0, m.index));
31410
+ parts.push({ expr: m[1] });
31411
+ rest2 = rest2.slice(m.index + m[0].length);
31412
+ }
31413
+ if (rest2) parts.push(rest2);
31414
+ return { type: "text", parts, line };
31415
+ };
31416
+ const parseElement = () => {
31417
+ const line = lineOf6(i);
31418
+ const tm = /^<([A-Za-z][\w:-]*)/.exec(html.slice(i));
31419
+ const tag = tm[1];
31420
+ i += tm[0].length;
31421
+ const attrs = [];
31422
+ for (; ; ) {
31423
+ while (/\s/.test(html[i] ?? "")) i++;
31424
+ if (i >= html.length) break;
31425
+ if (html.startsWith("/>", i)) {
31426
+ i += 2;
31427
+ return { type: "el", tag, attrs, kids: [], line };
31428
+ }
31429
+ if (html[i] === ">") {
31430
+ i++;
31431
+ break;
31432
+ }
31433
+ const am = /^[^\s=/>]+/.exec(html.slice(i));
31434
+ if (!am) {
31435
+ i++;
31436
+ continue;
31437
+ }
31438
+ const name = am[0];
31439
+ i += name.length;
31440
+ while (/\s/.test(html[i] ?? "")) i++;
31441
+ if (html[i] !== "=") {
31442
+ attrs.push({ name, value: true, kind: "flag" });
31443
+ continue;
31444
+ }
31445
+ i++;
31446
+ while (/\s/.test(html[i] ?? "")) i++;
31447
+ let value;
31448
+ if (html[i] === '"' || html[i] === "'") {
31449
+ const e = html.indexOf(html[i], i + 1);
31450
+ value = html.slice(i + 1, e < 0 ? html.length : e);
31451
+ i = e < 0 ? html.length : e + 1;
31452
+ } else {
31453
+ const vm = /^[^\s>]+/.exec(html.slice(i));
31454
+ value = vm ? vm[0] : "";
31455
+ i += value.length;
31456
+ }
31457
+ attrs.push({ name, value, kind: /^[[(*]/.test(name) ? "expr" : "text" });
31458
+ }
31459
+ const kids2 = VOID.has(tag.toLowerCase()) ? [] : parseNodes(tag, false);
31460
+ return { type: "el", tag, attrs, kids: kids2, line };
31461
+ };
31462
+ const parseBlock = () => {
31463
+ const line = lineOf6(i);
31464
+ const m = /^@(\w+)\s*(?:\(([^)]*(?:\([^)]*\)[^)]*)*)\))?\s*\{/.exec(html.slice(i));
31465
+ if (!m) {
31466
+ const e = html.indexOf("\n", i);
31467
+ i = e < 0 ? html.length : e;
31468
+ return null;
31469
+ }
31470
+ i += m[0].length;
31471
+ const body2 = parseNodes(null, true);
31472
+ return { type: "block", kind: m[1], head: (m[2] ?? "").trim(), kids: body2, line };
31473
+ };
31474
+ const nodes2 = parseNodes(null, false);
31475
+ const join2 = (list3) => {
31476
+ const out = [];
31477
+ for (const n of list3) {
31478
+ if (n.type === "el") {
31479
+ n.kids = join2(n.kids);
31480
+ out.push(n);
31481
+ continue;
31482
+ }
31483
+ if (n.type !== "block") {
31484
+ out.push(n);
31485
+ continue;
31486
+ }
31487
+ n.kids = join2(n.kids);
31488
+ const prev = out[out.length - 1];
31489
+ if (n.kind === "else" && prev?.type === "cond") {
31490
+ let tail = prev;
31491
+ while (tail.otherwise?.length === 1 && tail.otherwise[0].type === "cond") tail = tail.otherwise[0];
31492
+ const ei = /^if\s*\((.*)\)$/s.exec(n.head) || (/^if\b/.test(n.head) ? [null, n.head.replace(/^if\s*/, "")] : null);
31493
+ tail.otherwise = ei ? [{ type: "cond", test: ei[1], then: n.kids, otherwise: null, line: n.line }] : n.kids;
31494
+ continue;
31495
+ }
31496
+ if (n.kind === "empty" && prev?.type === "each") {
31497
+ prev.empty = n.kids;
31498
+ continue;
31499
+ }
31500
+ if (n.kind === "if") {
31501
+ out.push({ type: "cond", test: n.head.replace(/;\s*as\s+\w+$/, ""), then: n.kids, otherwise: null, line: n.line });
31502
+ continue;
31503
+ }
31504
+ if (n.kind === "for") {
31505
+ const f = /^(?:let\s+)?(\w+)\s+of\s+([^;]+)/.exec(n.head);
31506
+ out.push(f ? { type: "each", item: f[1], list: f[2].trim(), body: n.kids, line: n.line } : { type: "unread", code: `@for (${n.head})`, why: "a loop Thunder does not read yet", line: n.line });
31507
+ continue;
31508
+ }
31509
+ out.push({ type: "unread", code: `@${n.kind} (${n.head})`, why: `an @${n.kind} block, not read yet`, line: n.line, kids: n.kids });
31510
+ }
31511
+ return out;
31512
+ };
31513
+ return join2(nodes2);
31514
+ }
31515
+ var CONTAINERS = /* @__PURE__ */ new Set(["div", "span", "section", "main", "article", "aside", "Fragment", "React.Fragment", "ng-container", "ng-template", "template", "body", "html"]);
31516
+ var INLINE = /* @__PURE__ */ new Set(["strong", "em", "b", "i", "small", "code", "mark", "u", "sup", "sub", "abbr", "time"]);
31517
+ var SKIP = /* @__PURE__ */ new Set(["br", "hr", "wbr", "script", "style", "meta", "link"]);
31518
+ var TAG_WORDS = {
31519
+ h1: "a heading",
31520
+ h2: "a heading",
31521
+ h3: "a heading",
31522
+ h4: "a heading",
31523
+ h5: "a heading",
31524
+ h6: "a heading",
31525
+ p: "a paragraph",
31526
+ button: "a button",
31527
+ a: "a link",
31528
+ img: "an image",
31529
+ textarea: "a text area",
31530
+ select: "a dropdown",
31531
+ option: "a choice",
31532
+ label: "a label",
31533
+ li: "a row",
31534
+ tr: "a row",
31535
+ td: "a cell",
31536
+ th: "a column heading",
31537
+ table: "a table",
31538
+ ul: "a list",
31539
+ ol: "a numbered list",
31540
+ form: "a form",
31541
+ nav: "a navigation bar",
31542
+ header: "a header",
31543
+ footer: "a footer",
31544
+ svg: "a drawing",
31545
+ video: "a video",
31546
+ audio: "a sound player",
31547
+ dialog: "a dialog",
31548
+ iframe: "an embedded page",
31549
+ progress: "a progress bar",
31550
+ thead: "the table heading",
31551
+ tbody: "the table rows",
31552
+ fieldset: "a group of fields",
31553
+ legend: "a group title",
31554
+ blockquote: "a quote",
31555
+ pre: "a block of code",
31556
+ "router-outlet": "the page for the current address"
31557
+ };
31558
+ var INPUT_WORDS = { checkbox: "a checkbox", radio: "a choice button", submit: "a submit button", email: "an email box", password: "a password box", number: "a number box", search: "a search box", date: "a date box", file: "a file picker", range: "a slider", tel: "a phone box", url: "an address box", hidden: null, color: "a color picker" };
31559
+ var EVENT_WORDS2 = { click: "is pressed", dblclick: "is double-clicked", change: "changes", input: "is typed in", submit: "is sent", ngsubmit: "is sent", keydown: "gets a key press", keyup: "gets a key press", keypress: "gets a key press", blur: "is left", focus: "is chosen", mouseenter: "is pointed at", mouseleave: "is no longer pointed at", scroll: "is scrolled", load: "loads", select: "is selected" };
31560
+ var attr = (el, ...names) => el.attrs.find((a) => names.includes(a.name));
31561
+ var attrText = (el, ...names) => {
31562
+ const a = attr(el, ...names);
31563
+ return a && a.kind === "text" ? a.value : null;
31564
+ };
31565
+ function describe(nodes2, ctx) {
31566
+ const out = [];
31567
+ for (const n of nodes2) {
31568
+ if (n.type === "text") {
31569
+ const t = textWords(n.parts, ctx);
31570
+ if (t) out.push({ says: `text: ${t}`, line: n.line });
31571
+ continue;
31572
+ }
31573
+ if (n.type === "expr") {
31574
+ out.push(...exprChild(n, ctx));
31575
+ continue;
31576
+ }
31577
+ if (n.type === "cond") {
31578
+ out.push(condLine(n.test, describe(n.then, ctx), n.otherwise ? describe(n.otherwise, ctx) : null, n.line, ctx));
31579
+ continue;
31580
+ }
31581
+ if (n.type === "each") {
31582
+ out.push(eachLine(n, describe(n.body, ctx), n.empty ? describe(n.empty, ctx) : null));
31583
+ continue;
31584
+ }
31585
+ if (n.type === "unread") {
31586
+ ctx.notRead.push({ line: n.line, code: clip3(n.code), why: n.why });
31587
+ out.push({ says: `not read: \`${clip3(n.code, 60)}\``, line: n.line, notRead: true, code: clip3(n.code, 60) });
31588
+ continue;
31589
+ }
31590
+ if (n.type === "el") out.push(...elementLines(n, ctx));
31591
+ }
31592
+ return out;
31593
+ }
31594
+ function elementLines(el, ctx) {
31595
+ const ngIf = attr(el, "*ngIf");
31596
+ if (ngIf) {
31597
+ const [test, elseRef] = String(ngIf.value).split(/;\s*else\s+/);
31598
+ const inner = { ...el, attrs: el.attrs.filter((a) => a !== ngIf) };
31599
+ if (elseRef) ctx.notRead.push({ line: el.line, code: `*ngIf="${clip3(ngIf.value, 50)}"`, why: 'the "else" template is elsewhere; it is not shown here' });
31600
+ return [condLine(test.trim(), elementLines(inner, ctx), null, el.line, ctx)];
31601
+ }
31602
+ const ngFor = attr(el, "*ngFor");
31603
+ if (ngFor) {
31604
+ const m = /^\s*let\s+(\w+)\s+of\s+([^;]+)/.exec(String(ngFor.value));
31605
+ const inner = { ...el, attrs: el.attrs.filter((a) => a !== ngFor) };
31606
+ if (!m) {
31607
+ ctx.notRead.push({ line: el.line, code: `*ngFor="${clip3(ngFor.value, 50)}"`, why: "a repeat Thunder does not read yet" });
31608
+ return [{ says: `not read: \`*ngFor="${clip3(ngFor.value, 40)}"\``, line: el.line, notRead: true, code: `*ngFor="${clip3(ngFor.value, 40)}"` }];
31609
+ }
31610
+ return [eachLine({ item: m[1], list: m[2].trim(), line: el.line }, elementLines(inner, ctx))];
31611
+ }
31612
+ const otherStructural = el.attrs.find((a) => /^\*/.test(a.name));
31613
+ if (otherStructural) ctx.notRead.push({ line: el.line, code: `${otherStructural.name}="${clip3(otherStructural.value, 40)}"`, why: "a directive Thunder does not read yet" });
31614
+ for (const a of el.attrs) if (a.kind === "spread") ctx.notRead.push({ line: el.line, code: `{...${clip3(a.value, 40)}}`, why: "spread props: which values they hold is not known here" });
31615
+ const tag = el.tag;
31616
+ if (SKIP.has(tag)) return [];
31617
+ const kids2 = describe(el.kids.filter((k) => !(k.type === "el" && INLINE.has(k.tag))), ctx);
31618
+ if (CONTAINERS.has(tag) && !eventsOf(el, ctx, "it").length) return kids2;
31619
+ const what = elementWhat(el, ctx);
31620
+ if (!what) return kids2;
31621
+ const label = elementLabel(el, ctx);
31622
+ const labelFromText = label != null && !attrText(el, "aria-label", "alt", "placeholder", "title", "name");
31623
+ const extra = [];
31624
+ const disabled = attr(el, "disabled", "[disabled]");
31625
+ if (disabled?.kind === "expr") extra.push(`turned off when ${conditionWords2(disabled.value)}`);
31626
+ else if (disabled?.kind === "flag") extra.push("turned off");
31627
+ const shown = attr(el, "value", "[value]", "checked", "[checked]", "[(ngModel)]", "[ngModel]", "v-model");
31628
+ if (shown?.kind === "expr" && SIMPLE_PATH.test(String(shown.value).trim())) extra.push(`${/ngModel/.test(shown.name) && shown.name.startsWith("[(") ? "showing and changing" : "showing"} ${pathWords(shown.value.trim())}`);
31629
+ const to = attrText(el, "href", "routerLink", "to") ?? (attr(el, "[routerLink]", "to")?.kind === "expr" ? `\xAB${clip3(attr(el, "[routerLink]", "to").value, 40)}\xBB` : null);
31630
+ if (to && (tag === "a" || attr(el, "routerLink", "[routerLink]"))) extra.push(`to ${to}`);
31631
+ const evs = eventsOf(el, ctx, label ?? what.replace(/^an? /, "the "));
31632
+ const says = `${what}${label ? `: ${label}` : ""}${extra.length ? ` (${extra.join("; ")})` : ""}${evs.length ? `; when it ${evs.map((e) => `${e.verb}: ${e.runs}`).join("; when it ")}` : ""}`;
31633
+ const keepKids = labelFromText ? kids2.filter((k) => !k.says.startsWith("text: ")) : kids2;
31634
+ return [{ says, line: el.line, ...keepKids.length ? { kids: keepKids } : {} }];
31635
+ }
31636
+ function elementWhat(el, ctx) {
31637
+ const tag = el.tag;
31638
+ if (tag === "input") {
31639
+ const type = (attrText(el, "type") ?? "text").toLowerCase();
31640
+ return type in INPUT_WORDS ? INPUT_WORDS[type] : "a text box";
31641
+ }
31642
+ if (TAG_WORDS[tag]) return TAG_WORDS[tag];
31643
+ const screen = /^[A-Z]/.test(tag) ? ctx.screensByName.get(tag.split(".").pop()) : ctx.selectors.get(tag);
31644
+ if (screen) {
31645
+ ctx.uses.add(screen.name);
31646
+ return `the ${screen.label} screen`;
31647
+ }
31648
+ if (/^[A-Z]/.test(tag)) {
31649
+ ctx.uses.add(tag);
31650
+ return `the ${tag} component`;
31651
+ }
31652
+ if (tag.includes("-")) {
31653
+ ctx.uses.add(tag);
31654
+ return `the <${tag}> element`;
31655
+ }
31656
+ return null;
31657
+ }
31658
+ function elementLabel(el, ctx) {
31659
+ const inline = (kids2) => kids2.flatMap((k) => k.type === "text" ? k.parts : k.type === "el" && INLINE.has(k.tag) ? inline(k.kids) : k.type === "expr" && SIMPLE_PATH.test(k.code) ? [{ expr: k.code }] : []);
31660
+ const parts = inline(el.kids);
31661
+ const hasOther = el.kids.some((k) => k.type === "el" && !INLINE.has(k.tag) || k.type === "expr" && !SIMPLE_PATH.test(k.code));
31662
+ if (parts.length && !hasOther) return textWords(parts, ctx);
31663
+ const a = attrText(el, "aria-label", "alt", "placeholder", "title", "name");
31664
+ return a ? `"${a}"` : null;
31665
+ }
31666
+ function textWords(parts, ctx) {
31667
+ const t = parts.map((p) => typeof p === "string" ? p : SIMPLE_PATH.test(squash2(p.expr)) ? `{${pathWords(squash2(p.expr))}}` : `{${clip3(p.expr, 40)}}`).join("").replace(/\s+/g, " ").trim();
31668
+ if (!t) return null;
31669
+ return parts.length === 1 && typeof parts[0] === "string" ? `"${t}"` : `"${t}"`;
31670
+ }
31671
+ function eventsOf(el, ctx, who) {
31672
+ const out = [];
31673
+ for (const a of el.attrs) {
31674
+ let name = null;
31675
+ if (/^on[A-Z]/.test(a.name) && a.kind === "expr") name = a.name.slice(2).toLowerCase();
31676
+ else if (/^\(([\w.]+)\)$/.test(a.name)) name = a.name.slice(1, -1).toLowerCase().split(".")[0];
31677
+ if (!name) continue;
31678
+ const verb = EVENT_WORDS2[name] ?? `gets "${name}"`;
31679
+ const runs = handlerWords(String(a.value), ctx);
31680
+ out.push({ verb, runs });
31681
+ ctx.events.push({ on: who, event: name, when: `When ${who} ${verb}`, runs: runs.text ?? runs, line: el.line, ...runs.member ? { member: runs.member } : {} });
31682
+ }
31683
+ return out.map((e) => ({ verb: e.verb, runs: e.runs.text ?? e.runs }));
31684
+ }
31685
+ function handlerWords(code3, ctx) {
31686
+ let c = squash2(code3).replace(/;$/, "");
31687
+ const arrow = /^(?:async\s*)?(?:\(([^)]*)\)|(\w+))\s*=>\s*([\s\S]+)$/.exec(c);
31688
+ if (arrow) c = arrow[3].replace(/^\{([\s\S]*)\}$/, "$1").trim().replace(/;$/, "");
31689
+ const statements = c.split(/;\s*/).filter(Boolean);
31690
+ const said = statements.map((s) => statementWords(s.trim(), ctx));
31691
+ if (said.some((s) => s == null)) {
31692
+ ctx.notRead.push({ line: null, code: clip3(code3), why: "an event handler Thunder does not read yet" });
31693
+ return { text: `runs \`${clip3(code3, 50)}\`` };
31694
+ }
31695
+ const member = statements.length === 1 ? said[0].member : null;
31696
+ return { text: said.map((s) => s.text).join(", then "), ...member ? { member } : {} };
31697
+ }
31698
+ function statementWords(s, ctx) {
31699
+ let m;
31700
+ if (SIMPLE_PATH.test(s) || (m = /^([\w$.]+)\(\)$/.exec(s))) {
31701
+ const name = (m ? m[1] : s).replace(/\(\)$/, "").replace(/^this\./, "");
31702
+ if (ctx.outputs.has(name.replace(/\.emit$/, ""))) return { text: `sends the ${words11(name.replace(/\.emit$/, ""))} event` };
31703
+ if (ctx.inputs.has(name)) return { text: `tells the parent (${words11(name)})` };
31704
+ return { text: `runs ${words11(name.split(".").pop())}`, member: ctx.memberOf(name.split(".").pop()) };
31705
+ }
31706
+ if ((m = /^(set[A-Z]\w*)\(([\s\S]*)\)$/.exec(s)) && ctx.setters.has(m[1])) {
31707
+ const target = ctx.setters.get(m[1]);
31708
+ const v = m[2].trim();
31709
+ return { text: `sets ${words11(target)} to ${valueWords5(v, target)}` };
31710
+ }
31711
+ if ((m = /^(?:this\.)?(\w+)\.(set|update)\(([\s\S]*)\)$/.exec(s)) && ctx.stateNames.has(m[1])) return { text: m[2] === "set" ? `sets ${words11(m[1])} to ${valueWords5(m[3].trim(), m[1])}` : `changes ${words11(m[1])}` };
31712
+ if ((m = /^(?:this\.)?(\w+)\.emit\(([\s\S]*)\)$/.exec(s)) && ctx.outputs.has(m[1])) return { text: `sends the ${words11(m[1])} event${m[2].trim() ? ` with ${valueWords5(m[2].trim())}` : ""}` };
31713
+ if (m = /^(?:this\.)?(\w+)\(([\s\S]*)\)$/.exec(s)) {
31714
+ const args = m[2].trim();
31715
+ if (ctx.inputs.has(m[1])) return { text: `tells the parent (${words11(m[1])})${args ? ` with ${valueWords5(args)}` : ""}` };
31716
+ if (/^[\w$.]*$|^[\w$.]+(?:,\s*[\w$.]+)*$/.test(args)) return { text: `runs ${words11(m[1])}${args ? ` with ${args.split(/,\s*/).map((a) => valueWords5(a)).join(" and ")}` : ""}`, member: ctx.memberOf(m[1]) };
31717
+ return null;
31718
+ }
31719
+ if (m = /^(?:this\.)?(\w+)\s*=\s*([^=][\s\S]*)$/.exec(s)) return { text: `sets ${words11(m[1])} to ${valueWords5(m[2].trim(), m[1])}` };
31720
+ return null;
31721
+ }
31722
+ function valueWords5(v, target = null) {
31723
+ const s = squash2(v).replace(/\b([a-z]\w*)\(\)/g, "$1");
31724
+ if (/^(?:e|event|ev|\$event)\.target\.(?:value|checked)$/.test(s) || s === "$event") return "what was typed or chosen";
31725
+ if (/^["'`]/.test(s)) return `"${s.slice(1, -1)}"`;
31726
+ if (/^-?\d+(\.\d+)?$/.test(s)) return s;
31727
+ if (s === "true") return "yes";
31728
+ if (s === "false") return "no";
31729
+ if (s === "null" || s === "undefined") return "nothing";
31730
+ if (s === "[]") return "an empty list";
31731
+ if (s === "{}") return "nothing yet";
31732
+ if (target && m2(s, target)) return m2(s, target);
31733
+ if (SIMPLE_PATH.test(s)) return pathWords(s);
31734
+ return `\`${clip3(s, 40)}\``;
31735
+ }
31736
+ function m2(s, target) {
31737
+ let m;
31738
+ if (m = new RegExp(`^(?:\\(?\\w+\\)?\\s*=>\\s*)?(?:${target}|\\w+)\\s*([+-])\\s*(\\d+)$`).exec(s)) return `${words11(target)} ${m[1] === "+" ? "plus" : "minus"} ${m[2]}`;
31739
+ if (m = new RegExp(`^!\\s*${target}$`).exec(s)) return `the opposite of ${words11(target)}`;
31740
+ return null;
31741
+ }
31742
+ function exprChild(n, ctx) {
31743
+ let c = n.code.trim();
31744
+ while (/^\(/.test(c) && matchBrace(c, 0) === c.length - 1) c = c.slice(1, -1).trim();
31745
+ const jsxIn = (code3) => {
31746
+ const t = code3.trim().replace(/^\(([\s\S]*)\)$/, "$1").trim();
31747
+ if (t === "null" || t === "undefined" || t === "false" || t === "''" || t === '""') return [];
31748
+ if (t.startsWith("<")) {
31749
+ const r = parseJsx(t, 0);
31750
+ return r ? describe([shiftLines(r.node, n.line - 1)], ctx) : null;
31751
+ }
31752
+ if (/^["'`]/.test(t) && skipString3(t, 0) === t.length) return [{ says: `text: "${t.slice(1, -1)}"`, line: n.line }];
31753
+ if (SIMPLE_PATH.test(t)) return [{ says: `text: {${pathWords(t)}}`, line: n.line }];
31754
+ return null;
31755
+ };
31756
+ const and = topLevelSplit(c, "&&");
31757
+ if (and && /^\s*\(?\s*</.test(and[1])) {
31758
+ const then = jsxIn(and[1]);
31759
+ if (then) return [condLine(and[0], then, null, n.line, ctx)];
31760
+ }
31761
+ const tern = ternary(c);
31762
+ if (tern) {
31763
+ const a = jsxIn(tern[1]), b = jsxIn(tern[2]);
31764
+ if (a && b) return [condLine(tern[0], a, b.length ? b : null, n.line, ctx)];
31765
+ }
31766
+ const mp = /^([\s\S]+?)\.map\(\s*(?:\(\s*(\w+)(?:\s*,\s*\w+)?\s*\)|(\w+))\s*=>\s*([\s\S]+)\)$/.exec(c);
31767
+ if (mp) {
31768
+ let body2 = mp[4].trim();
31769
+ const block = /^\{\s*return\s+([\s\S]*?);?\s*\}$/.exec(body2);
31770
+ if (block) body2 = block[1];
31771
+ const kids2 = jsxIn(body2);
31772
+ if (kids2) return [eachLine({ item: mp[2] ?? mp[3], list: mp[1].trim(), line: n.line }, kids2)];
31773
+ }
31774
+ if (SIMPLE_PATH.test(c)) return [{ says: `text: {${pathWords(c)}}`, line: n.line }];
31775
+ ctx.notRead.push({ line: n.line, code: clip3(c), why: "an expression in what it shows that Thunder does not read yet" });
31776
+ return [{ says: `not read: \`{${clip3(c, 60)}}\``, line: n.line, notRead: true, code: `{${clip3(c, 60)}}` }];
31777
+ }
31778
+ function topLevelSplit(c, op) {
31779
+ let depth = 0;
31780
+ for (let i = 0; i < c.length - 1; i++) {
31781
+ const ch = c[i];
31782
+ if (ch === '"' || ch === "'" || ch === "`") {
31783
+ i = skipString3(c, i) - 1;
31784
+ continue;
31785
+ }
31786
+ if (ch === "<" && jsxStartsAt(c, i)) return null;
31787
+ if ("([{".includes(ch)) depth++;
31788
+ else if (")]}".includes(ch)) depth--;
31789
+ else if (depth === 0 && c.startsWith(op, i)) return [c.slice(0, i).trim(), c.slice(i + op.length).trim()];
31790
+ }
31791
+ return null;
31792
+ }
31793
+ function ternary(c) {
31794
+ let depth = 0, q2 = -1;
31795
+ for (let i = 0; i < c.length; i++) {
31796
+ const ch = c[i];
31797
+ if (ch === '"' || ch === "'" || ch === "`") {
31798
+ i = skipString3(c, i) - 1;
31799
+ continue;
31800
+ }
31801
+ if (ch === "<" && jsxStartsAt(c, i)) {
31802
+ const r = parseJsx(c, i);
31803
+ if (r) {
31804
+ i = r.end - 1;
31805
+ continue;
31806
+ }
31807
+ }
31808
+ if ("([{".includes(ch)) depth++;
31809
+ else if (")]}".includes(ch)) depth--;
31810
+ else if (depth === 0 && ch === "?" && c[i + 1] !== "." && c[i + 1] !== "?" && q2 < 0) q2 = i;
31811
+ else if (depth === 0 && ch === ":" && q2 >= 0) return [c.slice(0, q2).trim(), c.slice(q2 + 1, i).trim(), c.slice(i + 1).trim()];
31812
+ }
31813
+ return null;
31814
+ }
31815
+ function condLine(test, then, otherwise, line, ctx) {
31816
+ const words0 = conditionWords2(test);
31817
+ const line0 = { says: `when ${words0}, it shows:`, line, kids: then.length ? then : [{ says: "nothing", line }] };
31818
+ if (otherwise) return { ...line0, otherwise: { says: "otherwise, it shows:", line, kids: otherwise } };
31819
+ return line0;
31820
+ }
31821
+ function eachLine(n, kids2, empty = null) {
31822
+ const list3 = SIMPLE_PATH.test(n.list) ? pathWords(n.list) : `\`${clip3(n.list, 40)}\``;
31823
+ return { says: `one of these per ${words11(n.item)} in ${list3}:`, line: n.line, kids: kids2, ...empty ? { otherwise: { says: `when ${list3} is empty, it shows:`, line: n.line, kids: empty } } : {} };
31824
+ }
31825
+ function reactComponents(src) {
31826
+ const out = [];
31827
+ const seen = /* @__PURE__ */ new Set();
31828
+ const re = /(?:^|\n)[ \t]*(?:export\s+(?:default\s+)?)?(?:function\s+([A-Z]\w*)\s*(?:<[^>]*>)?\s*\(|(?:const|let)\s+([A-Z]\w*)\s*(?::[^=\n]+)?=\s*(?:(?:React\.)?(?:memo|forwardRef)\s*(?:<[^>]*>)?\(\s*)?(?:function\s*\w*\s*)?(?:async\s*)?(?:<[^>]*>)?\()/g;
31829
+ let m;
31830
+ while (m = re.exec(src)) {
31831
+ const name = m[1] ?? m[2];
31832
+ const pOpen = m.index + m[0].length - 1;
31833
+ const pClose = matchBrace(src, pOpen);
31834
+ if (pClose < 0) continue;
31835
+ let j = pClose + 1;
31836
+ const ret = /^\s*(?::\s*[^={]+?)?\s*(=>)?\s*/.exec(src.slice(j));
31837
+ j += ret[0].length;
31838
+ let body2, bodyStart, exprBody = false;
31839
+ if (src[j] === "{") {
31840
+ const e = matchBrace(src, j);
31841
+ if (e < 0) continue;
31842
+ body2 = src.slice(j + 1, e);
31843
+ bodyStart = j + 1;
31844
+ } else if (ret[1]) {
31845
+ if (src[j] === "(") {
31846
+ const e = matchBrace(src, j);
31847
+ if (e < 0) continue;
31848
+ body2 = `return ${src.slice(j, e + 1)};`;
31849
+ bodyStart = j - 7;
31850
+ } else if (src[j] === "<") {
31851
+ const r = parseJsx(src, j);
31852
+ if (!r) continue;
31853
+ body2 = `return ${src.slice(j, r.end)};`;
31854
+ bodyStart = j - 7;
31855
+ } else continue;
31856
+ exprBody = true;
31857
+ } else continue;
31858
+ if (!/\breturn\s*\(?\s*</.test(body2)) continue;
31859
+ if (seen.has(name)) continue;
31860
+ seen.add(name);
31861
+ out.push({ name, params: src.slice(pOpen + 1, pClose), body: body2, bodyStart, start: m.index + (src[m.index] === "\n" ? 1 : 0), end: bodyStart + body2.length, exprBody });
31862
+ }
31863
+ return out;
31864
+ }
31865
+ function topStatements(body2) {
31866
+ const out = [];
31867
+ let depth = 0, start = 0;
31868
+ for (let i = 0; i < body2.length; i++) {
31869
+ const c = body2[i];
31870
+ if (c === '"' || c === "'" || c === "`") {
31871
+ i = skipString3(body2, i) - 1;
31872
+ continue;
31873
+ }
31874
+ if (c === "/" && body2[i + 1] === "/") {
31875
+ const e = body2.indexOf("\n", i);
31876
+ i = e < 0 ? body2.length : e;
31877
+ continue;
31878
+ }
31879
+ if (c === "<" && jsxStartsAt(body2, i)) {
31880
+ const r = parseJsx(body2, i);
31881
+ if (r) {
31882
+ i = r.end - 1;
31883
+ continue;
31884
+ }
31885
+ }
31886
+ if ("([{".includes(c)) depth++;
31887
+ else if (")]}".includes(c)) {
31888
+ depth--;
31889
+ if (depth === 0 && c === "}") {
31890
+ const rest2 = body2.slice(i + 1).match(/^\s*(else\b)?/);
31891
+ if (!rest2[1] && !/^\s*[).,;:?]/.test(body2.slice(i + 1))) {
31892
+ out.push({ text: body2.slice(start, i + 1).trim(), at: start });
31893
+ start = i + 1;
31894
+ }
31895
+ }
31896
+ } else if (depth === 0 && c === ";") {
31897
+ out.push({ text: body2.slice(start, i).trim(), at: start });
31898
+ start = i + 1;
31899
+ }
31900
+ }
31901
+ if (body2.slice(start).trim()) out.push({ text: body2.slice(start).trim(), at: start });
31902
+ return out.filter((s) => s.text);
31903
+ }
31904
+ function startWords(init) {
31905
+ const s = squash2(init ?? "");
31906
+ if (!s || s === "undefined") return "nothing";
31907
+ return valueWords5(s);
31908
+ }
31909
+ function typeWords3(t) {
31910
+ const s = squash2(t ?? "").replace(/;$/, "");
31911
+ if (!s) return null;
31912
+ if (/=>/.test(s)) return "an action to run";
31913
+ if (s === "string") return "text";
31914
+ if (/^\[\s*\]$/.test(s)) return "a list";
31915
+ if (s === "number") return "a number";
31916
+ if (s === "boolean") return "yes or no";
31917
+ let m;
31918
+ if ((m = /^(\w+)\[\]$/.exec(s)) || (m = /^(?:Array|ReadonlyArray)<(\w+)>$/.exec(s))) return `a list of ${typeWords3(m[1])?.replace(/^an? /, "") ?? m[1]}`;
31919
+ if (m = /^(.+?)\s*\|\s*(?:null|undefined)$/.exec(s)) return `${typeWords3(m[1]) ?? m[1]}, or nothing`;
31920
+ if (/^['"]/.test(s)) return `one of ${s.split("|").map((x) => x.trim()).join(", ")}`;
31921
+ return /^[A-Z]/.test(s) ? `a ${s}` : s;
31922
+ }
31923
+ function typeFields(src, typeName) {
31924
+ const m = new RegExp(`(?:interface\\s+${typeName}\\b[^{]*|type\\s+${typeName}\\s*=\\s*)\\{`).exec(src);
31925
+ if (!m) return null;
31926
+ const open = m.index + m[0].length - 1, close = matchBrace(src, open);
31927
+ if (close < 0) return null;
31928
+ const fields = /* @__PURE__ */ new Map();
31929
+ for (const f of src.slice(open + 1, close).split(/[;\n]/)) {
31930
+ const fm = /^\s*(?:readonly\s+)?(\w+)(\?)?\s*:\s*(.+?)\s*,?\s*$/.exec(f);
31931
+ if (fm) fields.set(fm[1], { type: fm[3], optional: !!fm[2] });
31932
+ }
31933
+ return fields;
31934
+ }
31935
+ function reactScreen(file, src, comp, ctxBase) {
31936
+ const ctx = { ...ctxBase, notRead: [], events: [], uses: /* @__PURE__ */ new Set(), setters: /* @__PURE__ */ new Map(), stateNames: /* @__PURE__ */ new Set(), inputs: /* @__PURE__ */ new Set(), outputs: /* @__PURE__ */ new Set() };
31937
+ const line0 = lineAt2(src, comp.start);
31938
+ const inputs = [];
31939
+ const p = comp.params.trim();
31940
+ const typed = /:\s*([A-Z]\w*)\s*$/.exec(p.replace(/=\s*\{\s*\}\s*$/, "").trim());
31941
+ const fcType = /:\s*(?:React\.)?FC<\s*(\w+)\s*>/.exec(src.slice(comp.start, comp.start + 200));
31942
+ const fields = typeFields(src, typed?.[1] ?? fcType?.[1] ?? `${comp.name}Props`) ?? /* @__PURE__ */ new Map();
31943
+ const destr = /^\{([\s\S]*)\}/.exec(p);
31944
+ if (destr) {
31945
+ for (const part of destr[1].split(",").map((x) => x.trim()).filter(Boolean)) {
31946
+ if (part.startsWith("...")) {
31947
+ ctx.notRead.push({ line: line0, code: `{${clip3(part)}}`, why: "the rest of its props are passed on without names" });
31948
+ continue;
31949
+ }
31950
+ const nm = /^(\w+)(?:\s*:\s*\w+)?(?:\s*=\s*([\s\S]+))?$/.exec(part);
31951
+ if (nm) inputs.push({ name: nm[1], ...nm[2] ? { start: startWords(nm[2]) } : {} });
31952
+ }
31953
+ } else if (/^(\w+)/.test(p)) {
31954
+ const pn = /^(\w+)/.exec(p)[1];
31955
+ const used = [...new Set([...comp.body.matchAll(new RegExp(`\\b${pn}\\.(\\w+)`, "g"))].map((x) => x[1]))];
31956
+ inputs.push(...used.filter((u) => u !== "children" || true).map((name) => ({ name })));
31957
+ }
31958
+ for (const i of inputs) {
31959
+ const f = fields.get(i.name);
31960
+ i.label = words11(i.name);
31961
+ if (f) {
31962
+ i.kind = typeWords3(f.type);
31963
+ if (f.optional) i.optional = true;
31964
+ }
31965
+ if (/^on[A-Z]/.test(i.name) || i.kind === "an action to run") i.callback = true;
31966
+ ctx.inputs.add(i.name);
31967
+ }
31968
+ const state = [];
31969
+ const effects = [];
31970
+ const early = [];
31971
+ let main = null;
31972
+ for (const st of topStatements(comp.body)) {
31973
+ const t = st.text, line = lineAt2(src, comp.bodyStart + st.at + (comp.body.slice(st.at).length - comp.body.slice(st.at).trimStart().length));
31974
+ let m;
31975
+ if (m = /^(?:const|let)\s+\[\s*(\w+)\s*,\s*(\w+)\s*\]\s*=\s*(?:React\.)?useState(?:<[^>]*>)?\(([\s\S]*)\)$/.exec(t)) {
31976
+ state.push({ name: m[1], label: words11(m[1]), start: startWords(m[3]), how: "useState", line });
31977
+ ctx.setters.set(m[2], m[1]);
31978
+ ctx.stateNames.add(m[1]);
31979
+ continue;
31980
+ }
31981
+ if (m = /^(?:const|let)\s+\[\s*(\w+)\s*,\s*(\w+)\s*\]\s*=\s*(?:React\.)?useReducer\(\s*(\w+)\s*,\s*([\s\S]*)\)$/.exec(t)) {
31982
+ state.push({ name: m[1], label: words11(m[1]), start: startWords(m[4]), how: `useReducer (changed by ${words11(m[3])} when ${words11(m[2])} is called)`, line });
31983
+ ctx.stateNames.add(m[1]);
31984
+ continue;
31985
+ }
31986
+ if (m = /^(?:const|let)\s+(\w+|\{[^}]*\})\s*=\s*(?:React\.)?useContext\(\s*(\w+)\s*\)$/.exec(t)) {
31987
+ state.push({ name: m[1], label: words11(m[1].replace(/[{}]/g, "")), start: `from the app's ${words11(m[2].replace(/Context$/, ""))}`, how: "useContext", line });
31988
+ continue;
31989
+ }
31990
+ if (m = /^(?:const|let)\s+(\w+)\s*=\s*(?:React\.)?useMemo\(\s*\(\)\s*=>\s*([\s\S]+?),\s*\[[^\]]*\]\s*\)$/.exec(t)) {
31991
+ state.push({ name: m[1], label: words11(m[1]), start: `worked out from ${valueWords5(m[2])}`, how: "useMemo", line });
31992
+ continue;
31993
+ }
31994
+ if ((m = /^(?:const|let)\s+(\w+|\{[^}]*\}|\[[^\]]*\])\s*=\s*(use[A-Z]\w*)\(([\s\S]*)\)$/.exec(t)) && !/^use(State|Reducer|Context|Memo|Callback|Ref|Effect|LayoutEffect)$/.test(m[2])) {
31995
+ state.push({ name: m[1], label: words11(m[1].replace(/[{}[\]]/g, "")), start: `from ${words11(m[2])}`, how: m[2], line });
31996
+ continue;
31997
+ }
31998
+ if (m = /^(?:React\.)?use(?:Layout)?Effect\(\s*(?:async\s*)?\(\)\s*=>\s*([\s\S]*?)(?:,\s*\[([^\]]*)\])?\s*\)$/.exec(t)) {
31999
+ const deps = m[2] == null ? null : m[2].split(",").map((x) => x.trim()).filter(Boolean);
32000
+ const when = deps == null ? "After every change" : deps.length ? `When ${deps.map((d) => pathWords(d)).join(" or ")} changes` : "When the screen first shows";
32001
+ const bodyText = m[1].trim().replace(/^\{([\s\S]*)\}$/, "$1");
32002
+ const runs = topStatements(bodyText).map((s) => statementWords(s.text.replace(/^await\s+/, ""), ctx));
32003
+ effects.push({ when, runs: runs.every(Boolean) && runs.length ? runs.map((r) => r.text).join(", then ") : `runs \`${clip3(bodyText, 60)}\``, line });
32004
+ if (!runs.every(Boolean)) ctx.notRead.push({ line, code: clip3(bodyText), why: "what this effect does is not read yet" });
32005
+ continue;
32006
+ }
32007
+ if ((m = /^if\s*\(([\s\S]+?)\)\s*(?:\{\s*)?return\s+([\s\S]*?);?\s*\}?$/.exec(t)) && !main) {
32008
+ const r = m[2].trim();
32009
+ const shows = r === "null" || r === "" ? [] : r.replace(/^\(([\s\S]*)\)$/, "$1").trim().startsWith("<") ? (() => {
32010
+ const x = parseJsx(r.replace(/^\(([\s\S]*)\)$/, "$1").trim(), 0);
32011
+ return x ? describe([shiftLines(x.node, line - 1)], ctx) : null;
32012
+ })() : null;
32013
+ if (shows) {
32014
+ early.push({ when: conditionWords2(m[1]), shows, line });
32015
+ continue;
32016
+ }
32017
+ }
32018
+ if (m = /^return\s*\(?\s*</.exec(t)) {
32019
+ const lead = comp.body.slice(st.at).length - comp.body.slice(st.at).trimStart().length;
32020
+ const at2 = comp.bodyStart + st.at + lead + t.indexOf("<");
32021
+ const r = parseJsx(src, at2);
32022
+ if (r) main = describe([r.node], ctx);
32023
+ else ctx.notRead.push({ line, code: clip3(t), why: "what it shows could not be read" });
32024
+ }
32025
+ }
32026
+ return {
32027
+ framework: "react",
32028
+ name: comp.name,
32029
+ label: cap3(words11(comp.name)),
32030
+ file,
32031
+ lines: [line0, lineAt2(src, comp.end)],
32032
+ inputs,
32033
+ state,
32034
+ shows: main ?? [],
32035
+ ...early.length ? { early } : {},
32036
+ events: ctx.events,
32037
+ effects,
32038
+ outputs: [],
32039
+ uses: [...ctx.uses],
32040
+ notRead: ctx.notRead
32041
+ };
32042
+ }
32043
+ function shiftLines(node2, by) {
32044
+ const s = (n) => {
32045
+ if (n.line) n.line += by;
32046
+ for (const k of n.kids ?? []) s(k);
32047
+ return n;
32048
+ };
32049
+ return s(node2);
32050
+ }
32051
+ function angularComponents(file, src, files) {
32052
+ const out = [];
32053
+ const re = /@Component\s*\(\s*\{/g;
32054
+ let m;
32055
+ while (m = re.exec(src)) {
32056
+ const open = m.index + m[0].length - 1, close = matchBrace(src, open);
32057
+ if (close < 0) continue;
32058
+ const meta = src.slice(open + 1, close);
32059
+ const cls = /export\s+(?:default\s+)?class\s+(\w+)[^{]*\{/.exec(src.slice(close));
32060
+ if (!cls) continue;
32061
+ const cOpen = close + cls.index + cls[0].length - 1, cClose = matchBrace(src, cOpen);
32062
+ const selector = /selector\s*:\s*['"`]([^'"`]+)['"`]/.exec(meta)?.[1] ?? null;
32063
+ let template = null, templateAt = null, templateFile = null, missing = null;
32064
+ const tm = /template\s*:\s*(`|'|")/.exec(meta);
32065
+ if (tm) {
32066
+ const s = open + 1 + tm.index + tm[0].length - 1;
32067
+ const e = skipString3(src, s);
32068
+ template = src.slice(s + 1, e - 1);
32069
+ templateAt = s + 1;
32070
+ }
32071
+ const tu = /templateUrl\s*:\s*['"`]([^'"`]+)['"`]/.exec(meta);
32072
+ if (tu) {
32073
+ const dir = file.includes("/") ? file.slice(0, file.lastIndexOf("/") + 1) : "";
32074
+ const want = normalize(dir + tu[1]);
32075
+ const hit = files.find((f) => normalize(f.path) === want) ?? files.find((f) => f.path.endsWith(tu[1].replace(/^\.\//, "")));
32076
+ if (hit) {
32077
+ template = hit.source;
32078
+ templateFile = hit.path;
32079
+ } else missing = tu[1];
32080
+ }
32081
+ out.push({ name: cls[1], selector, template, templateAt, templateFile, missing, start: m.index, classOpen: cOpen, classBody: src.slice(cOpen + 1, cClose), classEnd: cClose });
32082
+ }
32083
+ return out;
32084
+ }
32085
+ var normalize = (p) => {
32086
+ const out = [];
32087
+ for (const seg of p.split("/")) {
32088
+ if (seg === "..") out.pop();
32089
+ else if (seg && seg !== ".") out.push(seg);
32090
+ }
32091
+ return out.join("/");
32092
+ };
32093
+ function angularScreen(file, src, comp, ctxBase) {
32094
+ const ctx = { ...ctxBase, notRead: [], events: [], uses: /* @__PURE__ */ new Set(), setters: /* @__PURE__ */ new Map(), stateNames: /* @__PURE__ */ new Set(), inputs: /* @__PURE__ */ new Set(), outputs: /* @__PURE__ */ new Set() };
32095
+ const inputs = [], outputs = [], state = [], effects = [], services = [];
32096
+ const body2 = comp.classBody;
32097
+ const lineIn = (i) => lineAt2(src, comp.classOpen + 1 + i);
32098
+ let m;
32099
+ const fieldRe = /(@Input\([^)]*\)\s*|@Output\(\)\s*)?(?:(?:public|private|protected|readonly|override)\s+)*(\w+)\s*([!?])?\s*(?::\s*([^=;\n]+?))?\s*(?:=\s*([^;\n]+))?;/g;
32100
+ let depth = 0, k = 0;
32101
+ const level0 = [];
32102
+ for (let i = 0; i < body2.length; i++) {
32103
+ const c = body2[i];
32104
+ if (c === '"' || c === "'" || c === "`") {
32105
+ i = skipString3(body2, i) - 1;
32106
+ continue;
32107
+ }
32108
+ if (c === "{" || c === "(" || c === "[") {
32109
+ if (depth === 0) level0.push([k, i]);
32110
+ depth++;
32111
+ } else if (c === "}" || c === ")" || c === "]") {
32112
+ depth--;
32113
+ if (depth === 0) k = i + 1;
32114
+ }
32115
+ }
32116
+ level0.push([k, body2.length]);
32117
+ const flat2 = body2.replace(/\{[^{}]*\}/g, (x) => " ".repeat(x.length));
32118
+ while (m = fieldRe.exec(flat2)) {
32119
+ const [, deco, name, mark, type, init] = m;
32120
+ if (/^(constructor|if|return|for|while|switch|const|let|var)$/.test(name)) continue;
32121
+ const before = flat2.slice(Math.max(0, m.index - 2), m.index);
32122
+ if (/[(.]/.test(before.trim().slice(-1))) continue;
32123
+ const line = lineIn(m.index + (deco ? 0 : 0));
32124
+ const initS = squash2(body2.slice(m.index, m.index + m[0].length).replace(/^[\s\S]*?=\s*/, "").replace(/;$/, ""));
32125
+ if (deco?.startsWith("@Input")) {
32126
+ inputs.push({ name, label: words11(name), ...type ? { kind: typeWords3(type) } : {}, .../required\s*:\s*true/.test(deco) || mark === "!" ? { required: true } : {}, ...init ? { start: startWords(initS) } : {}, line });
32127
+ ctx.inputs.add(name);
32128
+ continue;
32129
+ }
32130
+ if (deco?.startsWith("@Output")) {
32131
+ outputs.push({ name, label: words11(name), line });
32132
+ ctx.outputs.add(name);
32133
+ continue;
32134
+ }
32135
+ if (init) {
32136
+ let s;
32137
+ if (s = /^input(?:\.required)?(?:<([^>]+)>)?\(([\s\S]*)\)$/.exec(initS)) {
32138
+ inputs.push({ name, label: words11(name), ...s[1] ? { kind: typeWords3(s[1]) } : {}, .../^input\.required/.test(initS) ? { required: true } : s[2].trim() ? { start: startWords(s[2]) } : {}, line });
32139
+ ctx.inputs.add(name);
32140
+ continue;
32141
+ }
32142
+ if (/^output(?:<[^>]*>)?\(\)$/.test(initS) || /^new EventEmitter/.test(initS)) {
32143
+ outputs.push({ name, label: words11(name), line });
32144
+ ctx.outputs.add(name);
32145
+ continue;
32146
+ }
32147
+ if (s = /^signal(?:<[^>]*>)?\(([\s\S]*)\)$/.exec(initS)) {
32148
+ state.push({ name, label: words11(name), start: startWords(s[1]), how: "signal", line });
32149
+ ctx.stateNames.add(name);
32150
+ continue;
32151
+ }
32152
+ if (s = /^computed\(\s*\(\)\s*=>\s*([\s\S]*)\)$/.exec(initS)) {
32153
+ state.push({ name, label: words11(name), start: `worked out from ${valueWords5(s[1].replace(/this\./g, ""))}`, how: "computed", line });
32154
+ continue;
32155
+ }
32156
+ if (/^inject\(/.test(initS)) {
32157
+ services.push(/^inject\(\s*(\w+)/.exec(initS)?.[1] ?? name);
32158
+ continue;
32159
+ }
32160
+ state.push({ name, label: words11(name), start: startWords(initS), how: "field", line });
32161
+ ctx.stateNames.add(name);
32162
+ continue;
32163
+ }
32164
+ if (type && !/\(/.test(type)) {
32165
+ state.push({ name, label: words11(name), ...typeWords3(type) ? { kind: typeWords3(type) } : {}, start: "nothing yet", how: "field", line });
32166
+ ctx.stateNames.add(name);
32167
+ }
32168
+ }
32169
+ const ctor = /constructor\s*\(([^)]*)\)/.exec(body2);
32170
+ if (ctor) for (const p of ctor[1].split(",")) {
32171
+ const pm = /(\w+)\s*:\s*(\w+)/.exec(p);
32172
+ if (pm) services.push(pm[2]);
32173
+ }
32174
+ for (const [hook, when] of [["ngOnInit", "When the screen first shows"], ["ngOnChanges", "When an input changes"], ["ngAfterViewInit", "After the screen is drawn"], ["ngOnDestroy", "When the screen goes away"]]) {
32175
+ const hm = new RegExp(`\\b${hook}\\s*\\(`).exec(body2);
32176
+ if (hm) effects.push({ when, runs: `runs ${words11(hook.replace(/^ng/, ""))} (its steps are in that function)`, member: ctx.memberOf(hook), line: lineIn(hm.index) });
32177
+ }
32178
+ let shows = [];
32179
+ if (comp.template != null) {
32180
+ const tree = parseTemplate(comp.template, comp.templateFile ? null : src, comp.templateAt ?? 0);
32181
+ shows = describe(tree, ctx);
32182
+ if (comp.templateFile) for (const e of [...ctx.events, ...ctx.notRead]) e.file = comp.templateFile;
32183
+ } else if (comp.missing) ctx.notRead.push({ line: lineAt2(src, comp.start), code: `templateUrl: '${comp.missing}'`, why: `its template file (${comp.missing}) was not among the files read` });
32184
+ return {
32185
+ framework: "angular",
32186
+ name: comp.name,
32187
+ label: cap3(words11(comp.name.replace(/Component$/, ""))),
32188
+ file,
32189
+ lines: [lineAt2(src, comp.start), lineAt2(src, comp.classEnd)],
32190
+ ...comp.selector ? { selector: comp.selector } : {},
32191
+ ...comp.templateFile ? { template: comp.templateFile } : {},
32192
+ inputs,
32193
+ state,
32194
+ shows,
32195
+ events: ctx.events,
32196
+ effects,
32197
+ outputs,
32198
+ ...services.length ? { services: [...new Set(services)] } : {},
32199
+ uses: [...ctx.uses],
32200
+ notRead: ctx.notRead
32201
+ };
32202
+ }
32203
+ function readScreens(files, { members = [] } = {}) {
32204
+ const ts = files.filter((f) => /\.(tsx|jsx|ts|js|mjs)$/.test(f.path) && f.source);
32205
+ const found = [];
32206
+ for (const f of ts) {
32207
+ const reacts = /<[A-Za-z]/.test(f.source) && /\.(tsx|jsx|js)$/.test(f.path) ? reactComponents(f.source) : [];
32208
+ const angulars = /@Component\s*\(/.test(f.source) ? angularComponents(f.path, f.source, files) : [];
32209
+ for (const c of reacts) found.push({ f, c, kind: "react" });
32210
+ for (const c of angulars) found.push({ f, c, kind: "angular" });
32211
+ }
32212
+ const screensByName = new Map(found.map(({ c, kind }) => [c.name, { name: c.name, label: cap3(words11(kind === "angular" ? c.name.replace(/Component$/, "") : c.name)) }]));
32213
+ const selectors = new Map(found.filter((x) => x.kind === "angular" && x.c.selector).map(({ c }) => [c.selector, screensByName.get(c.name)]));
32214
+ const screens = [];
32215
+ for (const { f, c, kind } of found) {
32216
+ const memberOf = (name) => members.find((mm) => mm.file === f.path && mm.name === name)?.id ?? members.find((mm) => mm.name === name)?.id ?? null;
32217
+ const base2 = { screensByName, selectors, memberOf };
32218
+ let s;
32219
+ try {
32220
+ s = kind === "react" ? reactScreen(f.path, f.source, c, base2) : angularScreen(f.path, f.source, c, base2);
32221
+ } catch (e) {
32222
+ s = { framework: kind, name: c.name, label: cap3(words11(c.name)), file: f.path, lines: [lineAt2(f.source, c.start ?? 0), lineAt2(f.source, c.start ?? 0)], inputs: [], state: [], shows: [], events: [], effects: [], outputs: [], uses: [], notRead: [{ line: lineAt2(f.source, c.start ?? 0), code: c.name, why: `this screen could not be read: ${e.message}` }] };
32223
+ }
32224
+ for (const e of s.events) if (e.line == null) delete e.line;
32225
+ for (const n of s.notRead) {
32226
+ if (n.line == null) delete n.line;
32227
+ }
32228
+ screens.push({ id: `${f.path}#screen:${c.name}`, kind: "screen", symbol: "screen", ...s });
32229
+ }
32230
+ const byName = new Map(screens.map((s) => [s.name, s]));
32231
+ const bySelector = new Map(screens.filter((s) => s.selector).map((s) => [s.selector, s]));
32232
+ for (const s of screens) {
32233
+ s.uses = s.uses.map((u) => {
32234
+ const t = byName.get(u) ?? bySelector.get(u);
32235
+ return t ? { id: t.id, label: t.label } : { label: u, outside: true };
32236
+ });
32237
+ s.usedBy = [];
32238
+ }
32239
+ for (const s of screens) for (const u of s.uses) if (u.id) {
32240
+ const t = screens.find((x) => x.id === u.id);
32241
+ if (t && !t.usedBy.some((x) => x.id === s.id)) t.usedBy.push({ id: s.id, label: s.label });
32242
+ }
32243
+ const routed = routedNames(files);
32244
+ for (const s of screens) {
32245
+ const page = pageFile(s.file);
32246
+ if (page) {
32247
+ s.role = "page";
32248
+ s.roleWhy = page;
32249
+ } else if (routed.has(s.name)) {
32250
+ s.role = "page";
32251
+ s.roleWhy = `a router opens it (${routed.get(s.name)})`;
32252
+ } else if (s.usedBy.length) {
32253
+ s.role = "part";
32254
+ s.roleWhy = `shown inside ${s.usedBy.map((u) => u.label).join(", ")}`;
32255
+ } else {
32256
+ s.role = "top";
32257
+ s.roleWhy = "no other screen here shows it";
32258
+ }
32259
+ }
32260
+ return screens;
32261
+ }
32262
+ function pageFile(file) {
32263
+ const f = file.replace(/\\/g, "/");
32264
+ if (/(^|\/)app\/(.+\/)?page\.(tsx|jsx|ts|js)$/.test(f)) return "a Next.js page file (app router)";
32265
+ if (/(^|\/)pages\/(?!api\/)(?!_app\.|_document\.|_error\.)[^]*\.(tsx|jsx|ts|js)$/.test(f)) return "a Next.js page file (pages folder)";
32266
+ return null;
32267
+ }
32268
+ function routedNames(files) {
32269
+ const out = /* @__PURE__ */ new Map();
32270
+ for (const f of files) {
32271
+ const src = f.source ?? "";
32272
+ if (/\bRoutes\b|RouterModule|provideRouter/.test(src)) {
32273
+ for (const m of src.matchAll(/\bcomponent\s*:\s*([A-Z]\w*)/g)) if (!out.has(m[1])) out.set(m[1], `${f.path}, line ${lineAt2(src, m.index)}`);
32274
+ }
32275
+ if (/<Route\b|createBrowserRouter|createRoutesFromElements/.test(src)) {
32276
+ for (const m of src.matchAll(/(?:\belement\s*[=:]\s*\{?\s*<|\bComponent\s*:\s*)([A-Z]\w*)/g)) if (!out.has(m[1])) out.set(m[1], `${f.path}, line ${lineAt2(src, m.index)}`);
32277
+ }
32278
+ }
32279
+ return out;
32280
+ }
32281
+ function outlineLines(items, depth, out) {
32282
+ for (const it of items) {
32283
+ out.push(`${" ".repeat(depth)}- ${it.says}${it.line ? ` (line ${it.line})` : ""}`);
32284
+ if (it.kids) outlineLines(it.kids, depth + 1, out);
32285
+ if (it.otherwise) {
32286
+ out.push(`${" ".repeat(depth)}- ${it.otherwise.says}`);
32287
+ outlineLines(it.otherwise.kids, depth + 1, out);
32288
+ }
32289
+ }
32290
+ return out;
32291
+ }
32292
+ function screenText(s) {
32293
+ const L = [`${s.label}: ${s.framework === "react" ? "a React" : "an Angular"} screen${s.selector ? ` (<${s.selector}>)` : ""}`];
32294
+ if (s.role === "page") L.push(` It is a page: ${s.roleWhy}`);
32295
+ if (s.inputs.length) L.push(` It receives: ${s.inputs.map((i) => `${i.label}${i.kind ? ` (${i.kind}${i.optional ? ", optional" : ""}${i.required ? ", required" : ""})` : i.required ? " (required)" : ""}${i.start ? `, ${i.start} if not given` : ""}`).join("; ")}`);
32296
+ if (s.state.length) L.push(` It remembers: ${s.state.map((x) => `${x.label}${x.start ? ` (${/^(from|worked out)/.test(x.start) ? x.start : `starts as ${x.start}`})` : ""}`).join("; ")}`);
32297
+ if (s.services?.length) L.push(` It uses the services: ${s.services.join(", ")}`);
32298
+ for (const e of s.early ?? []) {
32299
+ L.push(` When ${e.when}, it shows only:`);
32300
+ outlineLines(e.shows.length ? e.shows : [{ says: "nothing" }], 2, L);
32301
+ }
32302
+ if (s.shows.length) {
32303
+ L.push(" It shows:");
32304
+ outlineLines(s.shows, 2, L);
32305
+ }
32306
+ for (const e of s.effects) L.push(` ${e.when}: ${e.runs}${e.line ? ` (line ${e.line})` : ""}`);
32307
+ if (s.outputs.length) L.push(` It sends: ${s.outputs.map((o) => `${o.label} (an event)`).join(", ")}`);
32308
+ if (s.uses.length) L.push(` It shows these screens and components: ${s.uses.map((u) => u.label).join(", ")}`);
32309
+ if (s.notRead.length) {
32310
+ L.push(" Not read:");
32311
+ for (const n of s.notRead) L.push(` ${n.line ? `line ${n.line}: ` : ""}\`${n.code}\`: ${n.why}`);
32312
+ }
32313
+ return `${L.join("\n")}
32314
+ `;
32315
+ }
32316
+
30558
32317
  // src/things-langs.mjs
30559
32318
  function braceEnd(src, open) {
30560
32319
  let depth = 0;
@@ -30665,10 +32424,10 @@ function goDoc(src, at2, name) {
30665
32424
  const t = d.replace(new RegExp(`^${name}\\s+(?:is|holds|represents)\\s+`), "").replace(new RegExp(`^${name}\\s+`), "");
30666
32425
  return t.charAt(0).toUpperCase() + t.slice(1);
30667
32426
  }
30668
- function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: startValue2 }) {
30669
- const know = (name, type, start, params, line = null) => ({ name, label: words13(name.replace(/^[_$]+|_$/g, "")), kind: type ? kindWords3(type) : null, start: start != null && start !== "" ? startValue2(start, params) : null, line });
32427
+ function makeThingReaders({ words: words14, kindWords: kindWords3, startValue: startValue2 }) {
32428
+ const know = (name, type, start, params, line = null) => ({ name, label: words14(name.replace(/^[_$]+|_$/g, "")), kind: type ? kindWords3(type) : null, start: start != null && start !== "" ? startValue2(start, params) : null, line });
30670
32429
  function curlyThings(src, file, language) {
30671
- const lineAt3 = lineFinder5(src);
32430
+ const lineAt4 = lineFinder5(src);
30672
32431
  const out = [];
30673
32432
  const kw = {
30674
32433
  java: /(?:^|\n)[ \t]*(?:@\w+(?:\([^)]*\))?\s*)*(?:(?:public|private|protected|static|final|abstract|sealed|non-sealed)\s+)*(class|enum|record)\s+(\w+)\s*(?:<[^>{]*>)?\s*(\([^)]*\))?[^{;]*\{/g,
@@ -30695,7 +32454,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30695
32454
  kind: isEnum ? "choices" : isRecord ? "record" : "thing",
30696
32455
  name,
30697
32456
  file,
30698
- lines: [lineAt3(declAt), lineAt3(close >= 0 ? close : m.index + head.length)],
32457
+ lines: [lineAt4(declAt), lineAt4(close >= 0 ? close : m.index + head.length)],
30699
32458
  ...docAbove4(src, declAt) ? { doc: docAbove4(src, declAt) } : {},
30700
32459
  knows: [],
30701
32460
  choices: []
@@ -30714,7 +32473,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30714
32473
  if (isEnum) {
30715
32474
  const own2 = ownLevel(body2.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, ""));
30716
32475
  const list3 = language === "php" ? [...own2.matchAll(/\bcase\s+(\w+)(?:\s*=\s*([^;]+))?;/g)].map((x) => [x[1], x[2]]) : own2.split(";")[0].split(",").map((x) => x.trim().match(/^(?:@\w+\s+)*(\w+)\s*(?:\((.*)\))?(?:\s*=\s*(.+))?/s)).filter(Boolean).map((x) => [x[1], x[2] ?? x[3]]);
30717
- for (const [n, v] of list3) if (n && !/^(public|private|protected|fun|val|var|companion)$/.test(n)) thing.choices.push(v && /^\s*["']/.test(v) ? v.trim().replace(/^["'](.*)["']$/s, "$1") : words13(n));
32476
+ for (const [n, v] of list3) if (n && !/^(public|private|protected|fun|val|var|companion)$/.test(n)) thing.choices.push(v && /^\s*["']/.test(v) ? v.trim().replace(/^["'](.*)["']$/s, "$1") : words14(n));
30718
32477
  out.push(thing);
30719
32478
  continue;
30720
32479
  }
@@ -30762,7 +32521,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30762
32521
  return out;
30763
32522
  }
30764
32523
  function goThings(src, file) {
30765
- const lineAt3 = lineFinder5(src);
32524
+ const lineAt4 = lineFinder5(src);
30766
32525
  const out = [];
30767
32526
  const byName = /* @__PURE__ */ new Map();
30768
32527
  for (const m of src.matchAll(/(?:^|\n)type\s+(\w+)\s+struct\s*\{/g)) {
@@ -30770,7 +32529,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30770
32529
  const open = m.index + m[0].length - 1;
30771
32530
  const close = braceEnd(src, open);
30772
32531
  if (close < 0) continue;
30773
- const t = { kind: "record", name: m[1], file, lines: [lineAt3(at2), lineAt3(close)], ...goDoc(src, at2, m[1]) ? { doc: goDoc(src, at2, m[1]) } : {}, knows: [], choices: [], memberRanges: [] };
32532
+ const t = { kind: "record", name: m[1], file, lines: [lineAt4(at2), lineAt4(close)], ...goDoc(src, at2, m[1]) ? { doc: goDoc(src, at2, m[1]) } : {}, knows: [], choices: [], memberRanges: [] };
30774
32533
  for (const raw of src.slice(open + 1, close).split("\n")) {
30775
32534
  const f = raw.replace(/\/\/.*$/, "").replace(/`[^`]*`/g, "").trim().match(/^([A-Za-z_]\w*(?:\s*,\s*[A-Za-z_]\w*)*)\s+(\S.*)$/);
30776
32535
  if (f) for (const n of f[1].split(",")) t.knows.push(know(n.trim(), f[2].trim(), null, {}));
@@ -30785,7 +32544,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30785
32544
  const open = src.indexOf("{", at2);
30786
32545
  const close = open >= 0 ? braceEnd(src, open) : -1;
30787
32546
  t.kind = "thing";
30788
- t.memberRanges.push([lineAt3(at2), lineAt3(close >= 0 ? close : at2)]);
32547
+ t.memberRanges.push([lineAt4(at2), lineAt4(close >= 0 ? close : at2)]);
30789
32548
  }
30790
32549
  for (const m of src.matchAll(/func\s+New(\w+)\s*\(([^)]*)\)[^{]*\{/g)) {
30791
32550
  const t = byName.get(m[1]);
@@ -30816,22 +32575,22 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30816
32575
  if (!f) continue;
30817
32576
  if (f[2]) inType = f[2] === name;
30818
32577
  if (!inType) continue;
30819
- const label = f[3] && /^"/.test(f[3].trim()) ? f[3].trim().slice(1, -1) : words13(f[1].replace(new RegExp(`^${name}`), "") || f[1]);
32578
+ const label = f[3] && /^"/.test(f[3].trim()) ? f[3].trim().slice(1, -1) : words14(f[1].replace(new RegExp(`^${name}`), "") || f[1]);
30820
32579
  choices.push(label);
30821
32580
  }
30822
- if (choices.length) out.push({ kind: "choices", name, file, lines: [lineAt3(at2), lineAt3(at2)], ...goDoc(src, at2, name) ? { doc: goDoc(src, at2, name) } : {}, knows: [], choices });
32581
+ if (choices.length) out.push({ kind: "choices", name, file, lines: [lineAt4(at2), lineAt4(at2)], ...goDoc(src, at2, name) ? { doc: goDoc(src, at2, name) } : {}, knows: [], choices });
30823
32582
  }
30824
32583
  return out;
30825
32584
  }
30826
32585
  function rustThings(src, file) {
30827
- const lineAt3 = lineFinder5(src);
32586
+ const lineAt4 = lineFinder5(src);
30828
32587
  const out = [];
30829
32588
  const byName = /* @__PURE__ */ new Map();
30830
32589
  for (const m of src.matchAll(/(?:^|\n)[ \t]*(?:#\[[^\]]*\]\s*)*(?:pub(?:\([^)]*\))?\s+)?(struct|enum)\s+(\w+)\s*(?:<[^>{]*>)?\s*(?:where[^{]*)?(\{|\(|;)/g)) {
30831
32590
  const at2 = m.index + (m[0].startsWith("\n") ? 1 : 0);
30832
32591
  const doc = docAbove4(src, at2);
30833
32592
  if (m[3] !== "{") {
30834
- const t2 = { kind: "record", name: m[2], file, lines: [lineAt3(at2), lineAt3(at2)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
32593
+ const t2 = { kind: "record", name: m[2], file, lines: [lineAt4(at2), lineAt4(at2)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
30835
32594
  out.push(t2);
30836
32595
  byName.set(m[2], t2);
30837
32596
  continue;
@@ -30840,11 +32599,11 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30840
32599
  const close = braceEnd(src, open);
30841
32600
  if (close < 0) continue;
30842
32601
  const body2 = ownLevel(src.slice(open + 1, close));
30843
- const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [lineAt3(at2), lineAt3(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
32602
+ const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [lineAt4(at2), lineAt4(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
30844
32603
  if (m[1] === "enum") {
30845
32604
  for (const v of splitParams2(body2.replace(/\/\/[^\n]*/g, "").replace(/#\[[^\]]*\]/g, ""))) {
30846
32605
  const n = v.trim().match(/^(\w+)/);
30847
- if (n) t.choices.push(words13(n[1]));
32606
+ if (n) t.choices.push(words14(n[1]));
30848
32607
  }
30849
32608
  } else {
30850
32609
  for (const f of splitParams2(body2.replace(/\/\/[^\n]*/g, "").replace(/#\[[^\]]*\]/g, ""))) {
@@ -30864,7 +32623,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
30864
32623
  if (/\bfn\s+\w+\s*(?:<[^>]*>)?\s*\(\s*&?(?:mut\s+)?self\b/.test(src.slice(at2, close))) {
30865
32624
  if (t.kind === "record") t.kind = "thing";
30866
32625
  }
30867
- t.memberRanges.push([lineAt3(at2), lineAt3(close)]);
32626
+ t.memberRanges.push([lineAt4(at2), lineAt4(close)]);
30868
32627
  const block = src.slice(at2, close);
30869
32628
  const fnNew = block.match(/fn\s+new\s*\(([^)]*)\)[^{;]*\{/);
30870
32629
  const fnOpen = fnNew ? fnNew.index + fnNew[0].length - 1 : -1;
@@ -31016,7 +32775,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31016
32775
  }
31017
32776
  function cThings(src, file) {
31018
32777
  const code3 = src.replace(/^[ \t]*#.*(?:\\\r?\n.*)*$/gm, (m) => m.replace(/[^\n]/g, " "));
31019
- const lineAt3 = lineFinder5(code3);
32778
+ const lineAt4 = lineFinder5(code3);
31020
32779
  const out = [];
31021
32780
  for (const m of code3.matchAll(/(?:^|\n)[ \t]*(typedef\s+)?(struct|union|enum)\b\s*(\w+)?\s*\{/g)) {
31022
32781
  const at2 = m.index + (m[0].startsWith("\n") ? 1 : 0);
@@ -31027,10 +32786,10 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31027
32786
  const name = alias || m[3];
31028
32787
  if (!name) continue;
31029
32788
  const doc = cDocAbove(code3, at2);
31030
- const t = { kind: m[2] === "enum" ? "choices" : "record", name, ...m[3] && m[3] !== name ? { tag: m[3] } : {}, file, lines: [lineAt3(at2), lineAt3(close)], ...doc ? { doc } : {}, knows: [], choices: [] };
32789
+ const t = { kind: m[2] === "enum" ? "choices" : "record", name, ...m[3] && m[3] !== name ? { tag: m[3] } : {}, file, lines: [lineAt4(at2), lineAt4(close)], ...doc ? { doc } : {}, knows: [], choices: [] };
31031
32790
  const body2 = code3.slice(open + 1, close);
31032
32791
  if (m[2] === "enum") {
31033
- t.choices = enumNames(splitParams2(body2.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "")).map((x) => (x.trim().match(/^(\w+)/) || [])[1]).filter(Boolean)).map((n) => words13(n));
32792
+ t.choices = enumNames(splitParams2(body2.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "")).map((x) => (x.trim().match(/^(\w+)/) || [])[1]).filter(Boolean)).map((n) => words14(n));
31034
32793
  } else {
31035
32794
  for (const { head } of members(body2)) {
31036
32795
  const fp = head.match(/\(\s*\*\s*(\w+)\s*\)\s*\(/);
@@ -31051,7 +32810,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31051
32810
  out.push(t);
31052
32811
  }
31053
32812
  for (const t of out.filter((x) => x.kind === "record")) {
31054
- const snake2 = words13(t.name).replace(/ /g, "_");
32813
+ const snake2 = words14(t.name).replace(/ /g, "_");
31055
32814
  const ctor = code3.match(new RegExp(`\\b(?:${snake2}_(?:new|create|init|make|alloc)|(?:new|create|init|make)_${snake2})\\s*\\(([^)]*)\\)\\s*\\{`));
31056
32815
  if (!ctor) continue;
31057
32816
  const open = ctor.index + ctor[0].length - 1;
@@ -31077,7 +32836,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31077
32836
  }
31078
32837
  function cppThings(src, file) {
31079
32838
  const code3 = src.replace(/^[ \t]*#.*(?:\\\r?\n.*)*$/gm, (m) => m.replace(/[^\n]/g, " "));
31080
- const lineAt3 = lineFinder5(code3);
32839
+ const lineAt4 = lineFinder5(code3);
31081
32840
  const out = [];
31082
32841
  const byName = /* @__PURE__ */ new Map();
31083
32842
  for (const m of code3.matchAll(/(?:^|\n)[ \t]*(?:template\s*<[^>{;]*>\s*)?(?:(class|struct|union)\s+(?:alignas\([^)]*\)\s*)?(?:[A-Z_][A-Z0-9_]*\s+)*(\w+)(?:\s+final)?\s*(?::[^{;]*)?|enum(?:\s+(?:class|struct))?\s+(\w+)(?:\s*:\s*[\w:]+)?\s*)\{/g)) {
@@ -31090,10 +32849,10 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31090
32849
  const body2 = code3.slice(open + 1, close);
31091
32850
  if (m[3]) {
31092
32851
  const vals = splitParams2(body2.replace(/\/\*[\s\S]*?\*\//g, "").replace(/\/\/[^\n]*/g, "")).map((x) => (x.trim().match(/^(\w+)/) || [])[1]).filter(Boolean);
31093
- out.push({ kind: "choices", name, file, lines: [lineAt3(at2), lineAt3(close)], ...doc ? { doc } : {}, knows: [], choices: enumNames(vals).map((n) => words13(n)) });
32852
+ out.push({ kind: "choices", name, file, lines: [lineAt4(at2), lineAt4(close)], ...doc ? { doc } : {}, knows: [], choices: enumNames(vals).map((n) => words14(n)) });
31094
32853
  continue;
31095
32854
  }
31096
- const t = { kind: "record", name, file, lines: [lineAt3(at2), lineAt3(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
32855
+ const t = { kind: "record", name, file, lines: [lineAt4(at2), lineAt4(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
31097
32856
  let methods = false;
31098
32857
  const inits = {}, params = {};
31099
32858
  for (const mem of members(body2)) {
@@ -31132,7 +32891,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31132
32891
  if (brace < 0 || semi >= 0 && semi < brace || /[()]/.test(code3.slice(pClose + 1, brace).replace(/:\s*[\s\S]*$/, ""))) continue;
31133
32892
  methods = true;
31134
32893
  const bClose = braceEnd(code3, brace);
31135
- t.memberRanges.push([lineAt3(d.index), lineAt3(bClose >= 0 ? bClose : brace)]);
32894
+ t.memberRanges.push([lineAt4(d.index), lineAt4(bClose >= 0 ? bClose : brace)]);
31136
32895
  if (d[1] === name) cppCtor(code3.slice(pOpen + 1, pClose), (code3.slice(pClose + 1, brace).match(/^\s*(?:noexcept\s*)?:\s*([\s\S]+)$/) || [])[1], bClose > 0 ? code3.slice(brace + 1, bClose) : "", params, inits);
31137
32896
  }
31138
32897
  for (const k of t.knows) {
@@ -31163,7 +32922,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31163
32922
  for (const a of String(bodyText || "").matchAll(/(?:this->)?(\w+)\s*=\s*([^;\n]+);/g)) if (inits[a[1]] == null) inits[a[1]] = a[2];
31164
32923
  }
31165
32924
  function swiftThings(src, file) {
31166
- const lineAt3 = lineFinder5(src);
32925
+ const lineAt4 = lineFinder5(src);
31167
32926
  const out = [];
31168
32927
  const byName = /* @__PURE__ */ new Map();
31169
32928
  for (const m of src.matchAll(/(?:^|\n)[ \t]*(?:@\w+(?:\([^)\n]*\))?\s+)*(?:(?:public|private|internal|fileprivate|open|final|indirect|nonisolated)\s+)*(class|struct|enum|actor|protocol)\s+(\w+)(?:<[^>{\n]*>)?[ \t]*(?::[ \t]*([^{\n]+?))?[ \t]*\{/g)) {
@@ -31174,7 +32933,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31174
32933
  if (close < 0) continue;
31175
32934
  const doc = docAbove4(src, at2);
31176
32935
  const body2 = src.slice(open + 1, close);
31177
- const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [lineAt3(at2), lineAt3(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
32936
+ const t = { kind: m[1] === "enum" ? "choices" : "record", name: m[2], file, lines: [lineAt4(at2), lineAt4(close)], ...doc ? { doc } : {}, knows: [], choices: [], memberRanges: [] };
31178
32937
  const mems = members(body2, { newlines: true });
31179
32938
  if (m[1] === "enum") {
31180
32939
  for (const { head } of mems) {
@@ -31182,7 +32941,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31182
32941
  if (!c) continue;
31183
32942
  for (const part of splitParams2(c[1])) {
31184
32943
  const v = part.trim().match(/^(\w+)\s*(?:\([^)]*\))?\s*(?:=\s*(.+))?$/);
31185
- if (v) t.choices.push(v[2] && /^"/.test(v[2].trim()) ? v[2].trim().slice(1, -1) : words13(v[1]));
32944
+ if (v) t.choices.push(v[2] && /^"/.test(v[2].trim()) ? v[2].trim().slice(1, -1) : words14(v[1]));
31186
32945
  }
31187
32946
  }
31188
32947
  out.push(t);
@@ -31223,7 +32982,7 @@ function makeThingReaders({ words: words13, kindWords: kindWords3, startValue: s
31223
32982
  const at2 = m.index + (m[0].startsWith("\n") ? 1 : 0);
31224
32983
  const close = braceEnd(src, m.index + m[0].length - 1);
31225
32984
  if (close < 0) continue;
31226
- t.memberRanges.push([lineAt3(at2), lineAt3(close)]);
32985
+ t.memberRanges.push([lineAt4(at2), lineAt4(close)]);
31227
32986
  if (t.kind === "record" && /(?:^|\s)func\s/.test(src.slice(at2, close))) t.kind = "thing";
31228
32987
  }
31229
32988
  return out;
@@ -31263,7 +33022,7 @@ var join = (...parts) => {
31263
33022
  return out.join("/");
31264
33023
  };
31265
33024
  var stripStrings = (s) => s.replace(/"(?:[^"\\\n]|\\.)*"|'(?:[^'\\\n]|\\.)*'|`(?:[^`\\]|\\.)*`/g, (m) => m.replace(/[^\n]/g, " "));
31266
- var lineAt2 = (src, idx) => {
33025
+ var lineAt3 = (src, idx) => {
31267
33026
  let n = 1;
31268
33027
  for (let i = src.indexOf("\n"); i >= 0 && i < idx; i = src.indexOf("\n", i + 1)) n++;
31269
33028
  return n;
@@ -31301,7 +33060,7 @@ function jsImports(src, file, ctx, out) {
31301
33060
  else out.unresolved.push({ file, line, import: spec, why: r.why });
31302
33061
  };
31303
33062
  for (const m of clean.matchAll(/\bimport\s+(?:type\s+)?([\w$*{}\s,]+?)\s+from\s+(['"])([^'"]+)\2/g)) {
31304
- const line = lineAt2(clean, m.index);
33063
+ const line = lineAt3(clean, m.index);
31305
33064
  let clause2 = m[1].trim();
31306
33065
  const named2 = clause2.match(/\{([^}]*)\}/);
31307
33066
  if (named2) {
@@ -31318,16 +33077,16 @@ function jsImports(src, file, ctx, out) {
31318
33077
  }
31319
33078
  if (/^[\w$]+$/.test(clause2)) add(clause2, m[3], "default", line);
31320
33079
  }
31321
- for (const m of clean.matchAll(/\b(?:const|let|var)\s+([\w$]+)\s*=\s*require\(\s*(['"])([^'"]+)\2\s*\)(?:\s*\.\s*([\w$]+))?/g)) add(m[1], m[3], m[4] ?? "module.exports", lineAt2(clean, m.index));
33080
+ for (const m of clean.matchAll(/\b(?:const|let|var)\s+([\w$]+)\s*=\s*require\(\s*(['"])([^'"]+)\2\s*\)(?:\s*\.\s*([\w$]+))?/g)) add(m[1], m[3], m[4] ?? "module.exports", lineAt3(clean, m.index));
31322
33081
  for (const m of clean.matchAll(/\b(?:const|let|var)\s*\{([^}]*)\}\s*=\s*require\(\s*(['"])([^'"]+)\2\s*\)/g)) {
31323
33082
  for (const part of m[1].split(",")) {
31324
33083
  const p = part.trim().match(/^([\w$]+)(?:\s*:\s*([\w$]+))?$/);
31325
- if (p) add(p[2] || p[1], m[3], p[1], lineAt2(clean, m.index));
33084
+ if (p) add(p[2] || p[1], m[3], p[1], lineAt3(clean, m.index));
31326
33085
  }
31327
33086
  }
31328
33087
  for (const m of clean.matchAll(/\b(?:import|require)\s*\(\s*([^'"`\s)][^)]*)\)/g)) {
31329
33088
  if (/^\s*$/.test(m[1])) continue;
31330
- out.unresolved.push({ file, line: lineAt2(clean, m.index), import: m[1].trim().slice(0, 60), why: "dynamic import: the module is worked out when it runs" });
33089
+ out.unresolved.push({ file, line: lineAt3(clean, m.index), import: m[1].trim().slice(0, 60), why: "dynamic import: the module is worked out when it runs" });
31331
33090
  }
31332
33091
  }
31333
33092
  var stripComments2 = (s) => s.replace(/\/\*[\s\S]*?\*\//g, (m) => m.replace(/[^\n]/g, " ")).replace(/(^|[^:\\])\/\/.*$/gm, "$1");
@@ -31407,7 +33166,7 @@ function goImports(src, file, ctx, out) {
31407
33166
  for (const m of b.text.matchAll(/(?:^|\n)\s*([\w.]+\s+)?"([^"]+)"/g)) {
31408
33167
  const alias = m[1]?.trim();
31409
33168
  const r = ctx.goPackage(m[2]);
31410
- const line = lineAt2(src, b.at);
33169
+ const line = lineAt3(src, b.at);
31411
33170
  if (!r.files) {
31412
33171
  out.unresolved.push({ file, line, import: m[2], why: r.why });
31413
33172
  continue;
@@ -31423,7 +33182,7 @@ function goImports(src, file, ctx, out) {
31423
33182
  }
31424
33183
  function jvmImports(src, file, ctx, out, language) {
31425
33184
  for (const m of src.matchAll(/^\s*import\s+(static\s+)?([\w.]+)(\.\*)?\s*(?:as\s+(\w+))?\s*;?\s*$/gm)) {
31426
- const line = lineAt2(src, m.index);
33185
+ const line = lineAt3(src, m.index);
31427
33186
  const parts = m[2].split(".");
31428
33187
  if (m[3]) {
31429
33188
  out.packages.push(m[2]);
@@ -31448,7 +33207,7 @@ function csharpImports(src, file, ctx, out) {
31448
33207
  if (m[1]) {
31449
33208
  const parts = m[2].split(".");
31450
33209
  const t = ctx.classIn(parts.slice(0, -1).join("."), parts.at(-1), "csharp");
31451
- if (t.thing) out.bindings.set(m[1], bind([t.thing.file], parts.at(-1), { thing: t.thing, line: lineAt2(src, m.index) }));
33210
+ if (t.thing) out.bindings.set(m[1], bind([t.thing.file], parts.at(-1), { thing: t.thing, line: lineAt3(src, m.index) }));
31452
33211
  continue;
31453
33212
  }
31454
33213
  out.packages.push(m[2]);
@@ -31458,13 +33217,13 @@ function phpImports(src, file, ctx, out) {
31458
33217
  for (const m of src.matchAll(/^\s*use\s+([\w\\]+)(?:\s+as\s+(\w+))?\s*;/gm)) {
31459
33218
  const parts = m[1].replace(/^\\/, "").split("\\");
31460
33219
  const t = ctx.classIn(parts.slice(0, -1).join("\\"), parts.at(-1), "php");
31461
- if (t.thing) out.bindings.set(m[2] || parts.at(-1), bind([t.thing.file], parts.at(-1), { thing: t.thing, line: lineAt2(src, m.index) }));
31462
- else out.unresolved.push({ file, line: lineAt2(src, m.index), import: m[1], why: t.why });
33220
+ if (t.thing) out.bindings.set(m[2] || parts.at(-1), bind([t.thing.file], parts.at(-1), { thing: t.thing, line: lineAt3(src, m.index) }));
33221
+ else out.unresolved.push({ file, line: lineAt3(src, m.index), import: m[1], why: t.why });
31463
33222
  }
31464
33223
  }
31465
33224
  function rustImports(src, file, ctx, out) {
31466
33225
  for (const m of src.matchAll(/^\s*(?:pub\s+)?use\s+((?:crate|super|self)(?:::\w+)*)(?:::\{([^}]*)\}|::(\w+)(?:\s+as\s+(\w+))?)?\s*;/gm)) {
31467
- const line = lineAt2(src, m.index);
33226
+ const line = lineAt3(src, m.index);
31468
33227
  const names = m[2] ? m[2].split(",").map((x) => x.trim().match(/^(\w+)(?:\s+as\s+(\w+))?$/)).filter(Boolean).map((x) => [x[1], x[2] || x[1]]) : m[3] ? [[m[3], m[4] || m[3]]] : [];
31469
33228
  for (const [name, local] of names) {
31470
33229
  const asMod = ctx.rustModule(file, `${m[1]}::${name}`);
@@ -31623,16 +33382,16 @@ function listenersIn(model, sources, membersOf2) {
31623
33382
  const ms2 = membersOf2.get(f.path) || [];
31624
33383
  for (const m of src.matchAll(EVENT_SUBSCRIBE)) {
31625
33384
  if (GENERIC_EVENTS.has(m[3])) continue;
31626
- const line = lineAt2(src, m.index);
33385
+ const line = lineAt3(src, m.index);
31627
33386
  const handler = m[4] ? ms2.find((x) => x.name === m[4].replace(/^(this|self)\./, "") && !x.callback) ?? null : ms2.filter((x) => x.lines[0] >= line && x.lines[0] <= line + 2).sort((a, b) => a.lines[0] - b.lines[0])[0];
31628
33387
  addListener(m[3], handler, m[1]);
31629
33388
  }
31630
33389
  for (const m of src.matchAll(/new\s+Worker\(\s*(['"`])([^'"`]+)\1\s*,/g)) {
31631
- const line = lineAt2(src, m.index);
33390
+ const line = lineAt3(src, m.index);
31632
33391
  addListener(m[2], ms2.filter((x) => x.lines[0] >= line && x.lines[0] <= line + 2).sort((a, b) => a.lines[0] - b.lines[0])[0], "worker");
31633
33392
  }
31634
33393
  for (const m of src.matchAll(EVENT_DECORATOR)) {
31635
- const line = lineAt2(src, m.index);
33394
+ const line = lineAt3(src, m.index);
31636
33395
  addListener(m[3], ms2.filter((x) => x.lines[0] > line && x.lines[0] <= line + 6).sort((a, b) => a.lines[0] - b.lines[0])[0], m[1]);
31637
33396
  }
31638
33397
  }
@@ -32204,8 +33963,8 @@ var MODEL_SCHEMA = "thunder-model-v1";
32204
33963
  var THING_LANGUAGES = ["python", "typescript", "javascript", "java", "csharp", "kotlin", "php", "go", "rust", "ruby", "sql", "c", "cpp", "swift", "r", "powershell"];
32205
33964
  var CATEGORY = { dockerfile: "infrastructure", "github-actions": "delivery", terraform: "infrastructure", bicep: "infrastructure", kubernetes: "infrastructure", "docker-compose": "infrastructure" };
32206
33965
  var categoryOf = (language) => CATEGORY[language] ?? "application";
32207
- var words11 = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
32208
- var cap3 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
33966
+ var words12 = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
33967
+ var cap4 = (s) => s.charAt(0).toUpperCase() + s.slice(1);
32209
33968
  var stripQuotes2 = (v) => v.replace(/^[rbuf]*(["'`])(.*)\1$/s, "$2");
32210
33969
  function startValue(expr, params = {}) {
32211
33970
  const e = String(expr ?? "").trim();
@@ -32219,7 +33978,7 @@ function startValue(expr, params = {}) {
32219
33978
  if (/^-?\d+(\.\d+)?$/.test(e)) return `${e} at first`;
32220
33979
  if (/^[rbuf]*["'`].*["'`]$/.test(e)) return `"${stripQuotes2(e)}" at first`;
32221
33980
  const en = e.match(/^[A-Z]\w*(?:\.|::)([A-Z][A-Z0-9_]+|[A-Z][a-z]\w*)$/) || e.match(/^(?:[A-Z]\w*)?\.([a-z]\w*)$/);
32222
- if (en) return `${words11(en[1])} at first`;
33981
+ if (en) return `${words12(en[1])} at first`;
32223
33982
  return "worked out when it starts";
32224
33983
  }
32225
33984
  var KIND_WORDS2 = [
@@ -32240,13 +33999,18 @@ function kindWords2(type) {
32240
33999
  const opt2 = t.match(/^Optional\[(.+)\]$|^(.+?)\s*\|\s*None$|^(.+?)\s*\|\s*(null|undefined)$|^(?:Option|Optional|Nullable)<(.+)>$|^(.+)\?$|^\*(\w+)$/);
32241
34000
  if (opt2) {
32242
34001
  const inner = opt2[1] || opt2[2] || opt2[3] || opt2[5] || opt2[6] || opt2[7];
32243
- return `${kindWords2(inner) ?? `a ${inner}`}, or nothing`;
34002
+ return `${kindWords2(inner) ?? withArticle(inner)}, or nothing`;
32244
34003
  }
32245
34004
  const map = t.match(/^(?:Map|HashMap|Dictionary|IDictionary|MutableMap|BTreeMap|dict|Dict|Record)[<\[]/) || /^map\[/.test(t);
32246
34005
  if (map) return "a lookup table";
32247
- return /^[A-Z]/.test(t) ? `a ${t}` : null;
34006
+ return /^[A-Z]/.test(t) ? withArticle(t) : null;
34007
+ }
34008
+ function withArticle(w) {
34009
+ const t = String(w);
34010
+ const an = /^(?:[AEIOaeio]|U(?:n|m|nd|tt|pp)|u(?:n|m)|[FHLMNRSX][A-Z0-9]|[fhlmnrsx](?=[A-Z0-9]))/.test(t) && !/^(?:Eu|eu|Uni|uni|Use|use|Usu|One|one|Ur)/.test(t);
34011
+ return `${an ? "an" : "a"} ${t}`;
32248
34012
  }
32249
- var snakeOf = (t) => words11(t.name).replace(/ /g, "_");
34013
+ var snakeOf = (t) => words12(t.name).replace(/ /g, "_");
32250
34014
  function cOwns(t, item4) {
32251
34015
  const first = String(item4.inputs?.[0]?.type ?? "").replace(/\s+/g, "");
32252
34016
  const names = [t.name, t.tag].filter(Boolean);
@@ -32257,7 +34021,7 @@ function cShortName(t, name) {
32257
34021
  for (const n of [snakeOf(t), t.tag].filter(Boolean)) if (String(name).toLowerCase().startsWith(`${String(n).toLowerCase()}_`) && name.length > n.length + 1) return name.slice(n.length + 1);
32258
34022
  return name;
32259
34023
  }
32260
- var THING_HELPERS = { words: (x) => words11(x), kindWords: (x) => kindWords2(x), startValue: (x, p) => startValue(x, p) };
34024
+ var THING_HELPERS = { words: (x) => words12(x), kindWords: (x) => kindWords2(x), startValue: (x, p) => startValue(x, p) };
32261
34025
  var thingsFor = makeThingReaders(THING_HELPERS);
32262
34026
  function pythonThings(src, file) {
32263
34027
  const lines = src.split("\n");
@@ -32287,8 +34051,8 @@ function pythonThings(src, file) {
32287
34051
  const t = l.text.trim();
32288
34052
  if (/^(def|async def|class|@|"""|'''|#)/.test(t)) continue;
32289
34053
  let f;
32290
- if (isEnum && (f = t.match(/^([A-Z][A-Z0-9_]*)\s*=\s*(.+)$/))) thing.choices.push(/^[rbuf]*["']/.test(f[2]) ? stripQuotes2(f[2].trim()) : words11(f[1]));
32291
- else if (f = t.match(/^(\w+)\s*:\s*([^=]+?)(?:\s*=\s*(.+))?$/)) thing.knows.push({ name: f[1], label: words11(f[1]), kind: kindWords2(f[2]), start: f[3] ? startValue(f[3]) : null, line: l.line });
34054
+ if (isEnum && (f = t.match(/^([A-Z][A-Z0-9_]*)\s*=\s*(.+)$/))) thing.choices.push(/^[rbuf]*["']/.test(f[2]) ? stripQuotes2(f[2].trim()) : words12(f[1]));
34055
+ else if (f = t.match(/^(\w+)\s*:\s*([^=]+?)(?:\s*=\s*(.+))?$/)) thing.knows.push({ name: f[1], label: words12(f[1]), kind: kindWords2(f[2]), start: f[3] ? startValue(f[3]) : null, line: l.line });
32292
34056
  }
32293
34057
  const init = body2.findIndex((l) => /^\s*def\s+__init__\s*\(/.test(l));
32294
34058
  if (init >= 0) {
@@ -32305,7 +34069,7 @@ function pythonThings(src, file) {
32305
34069
  const a = ln.trim().match(/^self\.(\w+)\s*(?::\s*([^=]+))?=\s*(.+)$/);
32306
34070
  if (a && !thing.knows.some((x) => x.name === a[1])) {
32307
34071
  const pType = /^\w+$/.test(a[3].trim()) ? (sig?.[1] || "").match(new RegExp(`\\b${a[3].trim()}\\s*:\\s*([\\w\\[\\]. |]+)`))?.[1] : void 0;
32308
- thing.knows.push({ name: a[1], label: words11(a[1]), kind: kindWords2(a[2] || pType) ?? (/^\[/.test(a[3]) ? "a list" : null), start: startValue(a[3], params), line: i + 2 + k });
34072
+ thing.knows.push({ name: a[1], label: words12(a[1]), kind: kindWords2(a[2] || pType) ?? (/^\[/.test(a[3]) ? "a list" : null), start: startValue(a[3], params), line: i + 2 + k });
32309
34073
  }
32310
34074
  }
32311
34075
  }
@@ -32357,7 +34121,7 @@ function tsThings(src, file) {
32357
34121
  if (m[1] === "enum") {
32358
34122
  for (const part of body2.split(",")) {
32359
34123
  const e = part.trim().match(/^(\w+)(?:\s*=\s*(.+))?$/s);
32360
- if (e) thing.choices.push(e[2] && /^["'`]/.test(e[2].trim()) ? stripQuotes2(e[2].trim()) : words11(e[1]));
34124
+ if (e) thing.choices.push(e[2] && /^["'`]/.test(e[2].trim()) ? stripQuotes2(e[2].trim()) : words12(e[1]));
32361
34125
  }
32362
34126
  } else {
32363
34127
  let depth = 0, own = "";
@@ -32371,7 +34135,7 @@ function tsThings(src, file) {
32371
34135
  const f = l.match(/^(?:(?:public|private|protected|readonly|static|declare)\s+)*(\w+)(\?)?\s*:\s*([^=]+?)(?:\s*=\s*(.+))?$/) || l.match(/^(?:(?:public|private|protected|readonly|static)\s+)*(\w+)()\s*=\s*(.+)$/);
32372
34136
  if (!f || /\(/.test(f[1])) continue;
32373
34137
  const hasType = f.length > 4 && f[3] && !l.match(/^(?:(?:public|private|protected|readonly|static)\s+)*\w+\s*=/);
32374
- thing.knows.push({ name: f[1], label: words11(f[1]), kind: hasType ? kindWords2(f[3]) : null, start: hasType ? f[4] ? startValue(f[4]) : null : startValue(f[3]), line: null });
34138
+ thing.knows.push({ name: f[1], label: words12(f[1]), kind: hasType ? kindWords2(f[3]) : null, start: hasType ? f[4] ? startValue(f[4]) : null : startValue(f[3]), line: null });
32375
34139
  }
32376
34140
  const ctor = body2.match(/constructor\s*\(([^)]*)\)\s*\{/);
32377
34141
  if (ctor) {
@@ -32383,7 +34147,7 @@ function tsThings(src, file) {
32383
34147
  const cOpen = body2.indexOf("{", ctor.index + ctor[0].length - 1);
32384
34148
  const cBody = body2.slice(cOpen + 1, braceEnd2(body2, cOpen));
32385
34149
  for (const a of cBody.matchAll(/this\.(\w+)\s*=\s*([^;\n]+)/g)) {
32386
- if (!thing.knows.some((x) => x.name === a[1])) thing.knows.push({ name: a[1], label: words11(a[1]), kind: null, start: startValue(a[2], params), line: null });
34150
+ if (!thing.knows.some((x) => x.name === a[1])) thing.knows.push({ name: a[1], label: words12(a[1]), kind: null, start: startValue(a[2], params), line: null });
32387
34151
  else {
32388
34152
  const k = thing.knows.find((x) => x.name === a[1]);
32389
34153
  if (!k.start) k.start = startValue(a[2], params);
@@ -32417,7 +34181,7 @@ function jsAssignedThings(items, src, file, existing) {
32417
34181
  if (ctor?.anchor?.bodyLines) {
32418
34182
  const body2 = src.split("\n").slice(ctor.anchor.bodyLines[0] - 1, ctor.anchor.bodyLines[1]).join("\n");
32419
34183
  const params = Object.fromEntries((ctor.inputs || []).map((p) => [p.name, null]));
32420
- for (const a of body2.matchAll(/\bthis\.([A-Za-z_$][\w$]*)\s*=(?!=)\s*([^;\n]+)/g)) if (!thing.knows.some((k) => k.name === a[1])) thing.knows.push({ name: a[1], label: words11(a[1]), kind: null, start: startValue(a[2].trim(), params), line: null });
34184
+ for (const a of body2.matchAll(/\bthis\.([A-Za-z_$][\w$]*)\s*=(?!=)\s*([^;\n]+)/g)) if (!thing.knows.some((k) => k.name === a[1])) thing.knows.push({ name: a[1], label: words12(a[1]), kind: null, start: startValue(a[2].trim(), params), line: null });
32421
34185
  }
32422
34186
  out.push(thing);
32423
34187
  }
@@ -32442,11 +34206,11 @@ function stepDoes(step) {
32442
34206
  }
32443
34207
  var outsideQuotes = (text2, fn) => String(text2).split(/("(?:\\.|[^"\\])*"|`[^`]*`|«[^»]*»)/).map((part, i) => i % 2 ? part : fn(part)).join("");
32444
34208
  var possessive2 = (text2) => outsideQuotes(text2, possessiveWords2);
32445
- var possessiveWords2 = (text2) => String(text2).replace(/\b([a-z_][\w]*)\.([a-z_][\w]*)\b(?!\s*\()/gi, (m, a, b) => /^(self|this)$/.test(a) ? `the ${words11(b)}` : `the ${words11(a)}'s ${words11(b)}`).replace(/\b([a-z]+(?:_[a-z0-9]+)+|[a-z]+(?:[A-Z][a-z0-9]*)+)\b/g, (m) => words11(m));
32446
- var answerWords = (r) => /^true$/i.test(r) ? "Yes" : /^false$/i.test(r) ? "No" : /^(["'`]).*\1$/s.test(String(r).trim()) ? String(r).trim() : /^[A-Za-z]{2,4}$/.test(String(r).trim()) && /[a-z][A-Z]|[A-Z][a-z]+[A-Z]/.test(String(r)) ? String(r).trim() : cap3(words11(r));
34209
+ var possessiveWords2 = (text2) => String(text2).replace(/\b([a-z_][\w]*)\.([a-z_][\w]*)\b(?!\s*\()/gi, (m, a, b) => /^(self|this)$/.test(a) ? `the ${words12(b)}` : `the ${words12(a)}'s ${words12(b)}`).replace(/\b([a-z]+(?:_[a-z0-9]+)+|[a-z]+(?:[A-Z][a-z0-9]*)+)\b/g, (m) => words12(m));
34210
+ var answerWords = (r) => /^true$/i.test(r) ? "Yes" : /^false$/i.test(r) ? "No" : /^(["'`]).*\1$/s.test(String(r).trim()) ? String(r).trim() : /^[A-Za-z]{2,4}$/.test(String(r).trim()) && /[a-z][A-Z]|[A-Z][a-z]+[A-Z]/.test(String(r)) ? String(r).trim() : cap4(words12(r));
32447
34211
  function askAsQuestion(step, ruleLabel) {
32448
34212
  const run = String(step.says).match(/^If (not: )?([A-Z]?[a-z]+ing\b[^]* (?:works|fails))$/);
32449
- if (run && !ruleLabel) return { text: `${cap3(run[2])}?`, flip: !!run[1] };
34213
+ if (run && !ruleLabel) return { text: `${cap4(run[2])}?`, flip: !!run[1] };
32450
34214
  const held = [];
32451
34215
  const says = String(step.says).replace(/"(?:\\.|[^"\\])*"|`[^`]*`|«[^»]*»/g, (m) => isCodeWords(String(step.says).replace(/^If (?:not: )?/, "")) ? m : `${held.push(m) - 1}`);
32452
34216
  const r = askWords({ ...step, says }, ruleLabel);
@@ -32468,8 +34232,8 @@ function askWords(step, ruleLabel) {
32468
34232
  return { text: `${ruleLabel.replace(/\?$/, "")}?`, flip: negated !== outer };
32469
34233
  }
32470
34234
  let m;
32471
- if (compoundWords(c)) return { text: `${cap3(possessive2(c))}?`, flip, holds: { yes: possessive2(c), no: `it is not true that ${possessive2(c)}` } };
32472
- if ((m = c.match(/^not \((.+)\)$/)) && closeOf(c, 4) === c.length - 1) return { text: `${cap3(possessive2(m[1]))}?`, flip: !flip };
34235
+ if (compoundWords(c)) return { text: `${cap4(possessive2(c))}?`, flip, holds: { yes: possessive2(c), no: `it is not true that ${possessive2(c)}` } };
34236
+ if ((m = c.match(/^not \((.+)\)$/)) && closeOf(c, 4) === c.length - 1) return { text: `${cap4(possessive2(m[1]))}?`, flip: !flip };
32473
34237
  if (m = c.match(/^not (.+)$/)) {
32474
34238
  c = m[1];
32475
34239
  flip = !flip;
@@ -32477,12 +34241,12 @@ function askWords(step, ruleLabel) {
32477
34241
  if (compoundWords(c)) return { text: `Not ${possessive2(c)}?`, flip: !flip };
32478
34242
  const is = (a, b) => ({ yes: `${possessive2(a)} is ${possessive2(b)}`, no: `${possessive2(a)} is not ${possessive2(b)}` });
32479
34243
  const has2 = (a, b) => ({ yes: `${possessive2(a)} has ${b}`, no: `${possessive2(a)} has no ${b}` });
32480
- if (/[()]/.test(c) && !balancedText(c.split(/ is | has /)[0])) return { text: `${cap3(possessive2(c))}?`, flip };
34244
+ if (/[()]/.test(c) && !balancedText(c.split(/ is | has /)[0])) return { text: `${cap4(possessive2(c))}?`, flip };
32481
34245
  if (m = c.match(/^(.+?) is not (.+)$/)) return { text: `Is ${possessive2(m[1])} ${possessive2(m[2])}?`, flip: !flip, holds: is(m[1], m[2]) };
32482
34246
  if (m = c.match(/^(.+?) has no (.+)$/)) return { text: `Does ${possessive2(m[1])} have ${m[2]}?`, flip: !flip, holds: has2(m[1], m[2]) };
32483
34247
  if (m = c.match(/^(.+?) is (.+)$/)) return { text: `Is ${possessive2(m[1])} ${possessive2(m[2])}?`, flip, holds: is(m[1], m[2]) };
32484
34248
  if (m = c.match(/^(.+?) has (.+)$/)) return { text: `Does ${possessive2(m[1])} have ${m[2]}?`, flip, holds: has2(m[1], m[2]) };
32485
- return { text: `${cap3(possessive2(c))}?`, flip };
34249
+ return { text: `${cap4(possessive2(c))}?`, flip };
32486
34250
  }
32487
34251
  function compoundWords(c) {
32488
34252
  const parts = splitLogic(String(c).replace(/`[^`]*`/g, "Q").replace(/"[^"]*"/g, "Q").replace(/'/g, ""));
@@ -32499,7 +34263,7 @@ function ruleFlow(item4, start) {
32499
34263
  let prev = node2("start", start, { lane: 0, does: "start" });
32500
34264
  let label;
32501
34265
  for (const r of item4.rules || []) {
32502
- const d = node2("decision", `${cap3(possessive2(r.says ?? r.when))}?`, { lane: 0, line: r.line, does: "decide" });
34266
+ const d = node2("decision", `${cap4(possessive2(r.says ?? r.when))}?`, { lane: 0, line: r.line, does: "decide" });
32503
34267
  edges.push({ from: prev, to: d, ...label ? { label } : {} });
32504
34268
  const out = node2("end", answerWords(r.result), { lane: 1, line: r.line, does: "answer", answer: true, value: r.result });
32505
34269
  edges.push({ from: d, to: out, label: "yes" });
@@ -32686,7 +34450,7 @@ function inputKindsOf(item4) {
32686
34450
  for (const p of item4.inputs || []) {
32687
34451
  if (/^(self|this|cls)$/.test(p.name) || p.plumbing || !p.type) continue;
32688
34452
  const k = kindWords2(p.type) ?? (/^[A-Z]\w*$/.test(String(p.type).trim()) ? `a ${String(p.type).trim()}` : null);
32689
- if (k) kinds[words11(p.name)] = k;
34453
+ if (k) kinds[words12(p.name)] = k;
32690
34454
  }
32691
34455
  return Object.keys(kinds).length ? kinds : null;
32692
34456
  }
@@ -32725,7 +34489,7 @@ function destructuredNames(text2) {
32725
34489
  return out;
32726
34490
  }
32727
34491
  function youGiveOf(item4) {
32728
- const given = (item4.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).flatMap((p) => /^\{/.test(String(p.name).trim()) ? destructuredNames(String(p.name).trim()) : [p.name]).map((n) => words11(n)).filter(Boolean);
34492
+ const given = (item4.inputs || []).filter((p) => !/^(self|this|cls)$/.test(p.name) && !p.plumbing).flatMap((p) => /^\{/.test(String(p.name).trim()) ? destructuredNames(String(p.name).trim()) : [p.name]).map((n) => words12(n)).filter(Boolean);
32729
34493
  const codes = [];
32730
34494
  const walk = (steps) => {
32731
34495
  for (const s of steps || []) {
@@ -32742,7 +34506,7 @@ function youGiveOf(item4) {
32742
34506
  }
32743
34507
  if ((item4.inputs || []).some((p) => !p.plumbing && /^(?:req|request)$/.test(p.name))) continue;
32744
34508
  for (const r of c.matchAll(/\b(?:req|request|ctx\.request|ctx|c\.req)\s*\.\s*(query|params|body)\s*(?:\.\s*([A-Za-z_][\w]*)|\[\s*['"`]([^'"`]+)['"`]\s*\])/g)) {
32745
- const n = `${words11(r[2] || r[3])} ${r[1] === "body" ? "(sent in the request)" : "(in the address)"}`;
34509
+ const n = `${words12(r[2] || r[3])} ${r[1] === "body" ? "(sent in the request)" : "(in the address)"}`;
32746
34510
  if (!given.includes(n)) given.push(n);
32747
34511
  }
32748
34512
  const m = c.match(/^(?:const|let|var)\s*\{([^}]+)\}\s*=\s*\(?\s*(?:await\s+)?(?:req|request|ctx\.request|c\.req|event)\s*\.\s*(body|query|params|json\(\))/);
@@ -32750,7 +34514,7 @@ function youGiveOf(item4) {
32750
34514
  if (!m) continue;
32751
34515
  for (const part of m[1].split(",")) {
32752
34516
  const name = part.split(/[:=]/)[0].replace(/^\.\.\./, "").trim();
32753
- if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words11(name) + where)) given.push(words11(name) + where);
34517
+ if (/^[A-Za-z_$][\w$]*$/.test(name) && !given.includes(words12(name) + where)) given.push(words12(name) + where);
32754
34518
  }
32755
34519
  }
32756
34520
  return given;
@@ -32825,7 +34589,7 @@ function thunderModel(files, { name = "app" } = {}) {
32825
34589
  }
32826
34590
  for (const t of fileThings) {
32827
34591
  t.id = idOf(f.path, t.name);
32828
- t.label = infra && t.label ? t.label : cap3(words11(t.name));
34592
+ t.label = infra && t.label ? t.label : cap4(words12(t.name));
32829
34593
  t.can = [];
32830
34594
  things.push(t);
32831
34595
  }
@@ -32862,7 +34626,7 @@ function thunderModel(files, { name = "app" } = {}) {
32862
34626
  id: idOf(f.path, inside2?.name ?? "", item4.name, item4.line),
32863
34627
  kind,
32864
34628
  name: item4.name,
32865
- label: setup ? `A new ${owner.label} starts with` : infra && item4.label ? item4.label : /^~/.test(item4.name) ? "Clean up" : cap3(words11(own.replace(/^__|__$/g, ""))),
34629
+ label: setup ? `A new ${owner.label} starts with` : infra && item4.label ? item4.label : /^~/.test(item4.name) ? "Clean up" : cap4(words12(own.replace(/^__|__$/g, ""))),
32866
34630
  ...owner ? { owner: owner.id } : {},
32867
34631
  file: f.path,
32868
34632
  language,
@@ -32973,6 +34737,26 @@ function thunderModel(files, { name = "app" } = {}) {
32973
34737
  } catch (e) {
32974
34738
  model.notLinked = [{ file: fileInfo[0]?.path ?? null, line: 1, why: `Calls across files could not be linked: ${e.message}` }];
32975
34739
  }
34740
+ try {
34741
+ const screens = readScreens(files, { members });
34742
+ if (screens.length) {
34743
+ model.screens = screens;
34744
+ for (const sc of screens) {
34745
+ const m = members.find((x) => x.file === sc.file && x.name === sc.name);
34746
+ if (m) {
34747
+ m.screen = sc.id;
34748
+ sc.member = m.id;
34749
+ }
34750
+ const t = things.find((x) => x.file === sc.file && x.name === sc.name);
34751
+ if (t) {
34752
+ t.screen = sc.id;
34753
+ sc.thing = t.id;
34754
+ }
34755
+ }
34756
+ }
34757
+ } catch (e) {
34758
+ unknowns.push({ file: fileInfo[0]?.path ?? null, line: 1, why: `Screens could not be read: ${e.message}` });
34759
+ }
32976
34760
  return model;
32977
34761
  }
32978
34762
  function flowLines(flow, depth = 1, note = null, full = false) {
@@ -33022,6 +34806,8 @@ function flowLines(flow, depth = 1, note = null, full = false) {
33022
34806
  return out;
33023
34807
  }
33024
34808
  function modelText(model, id2, { note = null, full = false } = {}) {
34809
+ const sc = (model.screens ?? []).find((x) => x.id === id2);
34810
+ if (sc) return screenText(sc);
33025
34811
  const t = model.things.find((x) => x.id === id2);
33026
34812
  if (t) {
33027
34813
  const lines2 = [t.kind === "resource" ? `Resource ${t.label} (${t.resourceType})` : `${t.kind === "thing" ? "Thing" : t.kind === "record" ? "Record" : "Choices"} ${t.label}`];
@@ -33031,10 +34817,10 @@ function modelText(model, id2, { note = null, full = false } = {}) {
33031
34817
  lines2.push(" It knows");
33032
34818
  for (const k of t.knows) lines2.push(` ${k.label}: ${[k.kind, k.start].filter(Boolean).join(", ") || "a value"}`);
33033
34819
  }
33034
- const can = t.can.map((c) => model.members.find((m2) => m2.id === c)).filter((m2) => m2 && !m2.callback);
34820
+ const can = t.can.map((c) => model.members.find((m3) => m3.id === c)).filter((m3) => m3 && !m3.callback);
33035
34821
  if (can.length) {
33036
34822
  lines2.push(" It can");
33037
- for (const m2 of can) lines2.push(` ${m2.label}`);
34823
+ for (const m3 of can) lines2.push(` ${m3.label}`);
33038
34824
  }
33039
34825
  return `${lines2.join("\n")}
33040
34826
  `;
@@ -33052,7 +34838,7 @@ function modelText(model, id2, { note = null, full = false } = {}) {
33052
34838
  return `${lines.join("\n")}
33053
34839
  `;
33054
34840
  }
33055
- var SYMBOL_OF = { action: "action", rule: "rule", steps: "steps", setup: "setup", "not-read": "not-read", thing: "thing", record: "record", choices: "choices", pipeline: "action", "image-build": "steps", resource: "resource" };
34841
+ var SYMBOL_OF = { screen: "screen", action: "action", rule: "rule", steps: "steps", setup: "setup", "not-read": "not-read", thing: "thing", record: "record", choices: "choices", pipeline: "action", "image-build": "steps", resource: "resource" };
33056
34842
  var SETTING_WORDS = { parameter: "given when it starts or is built", variable: "a variable kept outside the file", secret: "a secret (only its name is shown)", literal: "written in the file", computed: "worked out when it runs" };
33057
34843
  var APPLIED_WORDS = { parameter: "given when it is applied", computed: "worked out when it is applied" };
33058
34844
  function settingWords(x, model) {
@@ -33217,9 +35003,20 @@ function detailsFacts(model, member) {
33217
35003
  const openQuestions = (member.rule?.needsReview ?? []).filter((q2) => !/^No examples yet/.test(q2));
33218
35004
  return { inputs, changes, stops, givesBack, reliesOn, ...answers ? { answers } : {}, ...limits ? { limits } : {}, openQuestions };
33219
35005
  }
35006
+ function screenLevel(lv, sc, model) {
35007
+ const base2 = { level: lv.id, name: lv.name, question: lv.question };
35008
+ const about = { scope: "screen", id: sc.id, title: sc.label, symbol: "screen", file: sc.file, lines: sc.lines, framework: sc.framework, ...sc.selector ? { selector: sc.selector } : {} };
35009
+ if (lv.id === "big-picture") return { ...base2, ...about, inputs: sc.inputs, state: sc.state, outputs: sc.outputs, ...sc.services ? { services: sc.services } : {}, uses: sc.uses, usedBy: sc.usedBy ?? [], events: sc.events.length, notRead: sc.notRead.length };
35010
+ if (lv.id === "flow") return { ...base2, ...about, shows: sc.shows, ...sc.early ? { early: sc.early } : {} };
35011
+ if (lv.id === "details") return { ...base2, ...about, inputs: sc.inputs, state: sc.state, events: sc.events, effects: sc.effects, outputs: sc.outputs, notRead: sc.notRead, source: "Read from code by the Thunder compiler, with no AI." };
35012
+ if (lv.id === "text") return { ...base2, ...about, text: screenText(sc) };
35013
+ return { ...base2, ...about, language: model.files.find((f) => f.path === sc.file)?.language ?? null, ...sc.template ? { template: sc.template } : {} };
35014
+ }
33220
35015
  function readLevel(model, level, focus, { full = false } = {}) {
33221
35016
  const lv = LEVELS.find((l) => l.id === level);
33222
35017
  if (!lv) throw new Error(`Unknown reading level "${level}". Use one of: ${LEVELS.map((l) => l.id).join(", ")}.`);
35018
+ const screen = focus ? (model.screens ?? []).find((x) => x.id === focus) : void 0;
35019
+ if (screen) return screenLevel(lv, screen, model);
33223
35020
  const member = focus ? model.members.find((m) => m.id === focus) : void 0;
33224
35021
  const thing = focus && !member ? model.things.find((t) => t.id === focus) : void 0;
33225
35022
  if (focus && !member && !thing) throw new Error(`Nothing in this model has the id "${focus}".`);
@@ -33242,7 +35039,8 @@ function readLevel(model, level, focus, { full = false } = {}) {
33242
35039
  const usedBy = member ? once(model.links.filter((l) => l.to === member.id), "from").map((l) => ({ id: l.from, label: labelOf(l.from), ...linkFacts(l, memberById(l.from), member) })) : [];
33243
35040
  if (!member && (lv.id === "flow" || lv.id === "details")) {
33244
35041
  const inScope = model.members.filter((m) => m.kind !== "setup" && (!thing || m.owner === thing.id));
33245
- return { ...base2, ...about, needsFocus: true, says: `${lv.name} shows one action or rule. Choose one.`, choose: inScope.map(short5) };
35042
+ const screens = thing ? [] : (model.screens ?? []).map((x) => ({ id: x.id, label: x.label, symbol: "screen" }));
35043
+ return { ...base2, ...about, needsFocus: true, says: `${lv.name} shows one ${screens.length ? "screen, action, or rule" : "action or rule"}. Choose one.`, choose: [...screens, ...inScope.filter((m) => !m.screen).map(short5)] };
33246
35044
  }
33247
35045
  if (lv.id === "big-picture") {
33248
35046
  if (member) {
@@ -33258,7 +35056,7 @@ function readLevel(model, level, focus, { full = false } = {}) {
33258
35056
  usedBy
33259
35057
  };
33260
35058
  }
33261
- const inScope = (m) => m.kind !== "setup" && (thing ? m.owner === thing.id : true);
35059
+ const inScope = (m) => m.kind !== "setup" && (thing ? m.owner === thing.id : !m.screen);
33262
35060
  const resourceCard = (t) => ({
33263
35061
  id: t.id,
33264
35062
  label: t.label,
@@ -33275,15 +35073,17 @@ function readLevel(model, level, focus, { full = false } = {}) {
33275
35073
  ...base2,
33276
35074
  ...about,
33277
35075
  ...thing?.doc ?? model.files[0]?.purpose ? { purpose: thing?.doc ?? model.files[0]?.purpose } : {},
33278
- things: (resource ? [] : thing ? [thing] : model.things.filter((t) => t.kind === "thing")).map(thingCard),
35076
+ things: (resource ? [] : thing ? [thing] : model.things.filter((t) => t.kind === "thing" && !t.screen)).map(thingCard),
33279
35077
  resources: (resource ? [resource] : thing ? [] : model.things.filter((t) => t.kind === "resource")).map(resourceCard),
33280
35078
  ...thing ? {} : { permissions: model.permissions ?? [], settings: model.settings ?? [], facts: model.facts ?? [] },
33281
35079
  data: thing ? [] : model.things.filter((t) => t.kind !== "thing" && t.kind !== "resource").map((t) => ({ id: t.id, label: t.label, symbol: SYMBOL_OF[t.kind], ...t.choices.length ? { choices: t.choices } : {}, knows: t.knows.map((k) => k.label) })),
33282
35080
  actions: model.members.filter((m) => inScope(m) && m.kind === "action").map(short5),
33283
35081
  rules: model.members.filter((m) => inScope(m) && m.kind === "rule").map(short5),
33284
35082
  // (A callback is reached from the step that passes it, not listed on its own.)
33285
- loose: thing ? [] : model.members.filter((m) => !m.owner && !m.callback && m.kind !== "setup" && m.kind !== "action" && m.kind !== "rule").map(short5),
35083
+ loose: thing ? [] : model.members.filter((m) => !m.owner && !m.callback && !m.screen && m.kind !== "setup" && m.kind !== "action" && m.kind !== "rule").map(short5),
33286
35084
  unknowns: thing ? [] : model.unknowns,
35085
+ // The app's screens (React and Angular components), and the screens and components each one shows.
35086
+ ...!thing && model.screens?.length ? { screens: [...model.screens].sort((x, y) => ["page", "top", "part"].indexOf(x.role) - ["page", "top", "part"].indexOf(y.role)).map((x) => ({ id: x.id, label: x.label, framework: x.framework, file: x.file, ...x.selector ? { selector: x.selector } : {}, ...x.role ? { role: x.role } : {}, uses: x.uses.map((u) => u.label) })) } : {},
33287
35087
  // The app's map: which areas (folders) call which, and send requests or events to which.
33288
35088
  ...thing ? {} : { calls: callsSummary(model), notLinked: model.notLinked ?? [] }
33289
35089
  };
@@ -33317,7 +35117,7 @@ ${model.permissions.map((p) => ` ${p.says ?? `${p.who} can ${p.can} ${p.on}`}${
33317
35117
  if (!focus && model.settings?.length) extra.push(`Settings
33318
35118
  ${model.settings.map((x) => ` Setting ${x.name}: ${settingWords(x, model)} (line ${x.line})`).join("\n")}
33319
35119
  `);
33320
- const text2 = focus ? modelText(model, focus, { full }) : [...model.things.map((t) => modelText(model, t.id)), ...model.members.filter((m) => !m.owner && m.kind !== "setup").map((m) => modelText(model, m.id, { full })), ...extra].join("\n");
35120
+ const text2 = focus ? modelText(model, focus, { full }) : [...(model.screens ?? []).map((sc) => screenText(sc)), ...model.things.filter((t) => !t.screen).map((t) => modelText(model, t.id)), ...model.members.filter((m) => !m.owner && m.kind !== "setup" && !m.screen).map((m) => modelText(model, m.id, { full })), ...extra].join("\n");
33321
35121
  return { ...base2, ...about, text: text2 };
33322
35122
  }
33323
35123
  return { ...base2, ...about, language: member ?? thing ? member?.language ?? model.files.find((f) => f.path === thing.file)?.language ?? null : model.files[0]?.language ?? null };
@@ -35550,7 +37350,7 @@ function runtimeOverlay(model, evidence2 = []) {
35550
37350
  had.count += ev.count ?? 1;
35551
37351
  return;
35552
37352
  }
35553
- notMatched.push({ key, source: ev.source ?? "evidence", kind: ev.kind, file: ev.file ?? null, line: ev.line ?? null, ...ev.function ? { function: String(ev.function) } : {}, what: what ?? describe(ev), reason, count: ev.count ?? 1 });
37353
+ notMatched.push({ key, source: ev.source ?? "evidence", kind: ev.kind, file: ev.file ?? null, line: ev.line ?? null, ...ev.function ? { function: String(ev.function) } : {}, what: what ?? describe2(ev), reason, count: ev.count ?? 1 });
35554
37354
  };
35555
37355
  const mem = (m) => members[m.id] ||= { id: m.id, name: m.name, label: m.label, file: m.file, lines: m.lines, calls: 0, failures: 0, nodes: {}, sources: [] };
35556
37356
  const nodeRun = (r, n) => r.nodes[n.id] ||= { id: n.id, kind: n.kind, text: n.text, line: n.line ?? null };
@@ -35756,7 +37556,7 @@ function runtimeOverlay(model, evidence2 = []) {
35756
37556
  for (const x of notMatched) delete x.key;
35757
37557
  return { schema: RUNNING_SCHEMA, members, notMatched, sources, summary: { members: Object.keys(members).length, events: evidence2.length, notMatched: notMatched.reduce((a, x) => a + x.count, 0) } };
35758
37558
  }
35759
- function describe(ev) {
37559
+ function describe2(ev) {
35760
37560
  const where = `${ev.file ?? "?"}${ev.line != null ? `:${ev.line}` : ""}${ev.function ? ` (${ev.function})` : ""}`;
35761
37561
  if (ev.kind === "raise") return `${ev.error ?? "an error"}${ev.message ? `: ${quoteText2(ev.message, 60)}` : ""} at ${where}`;
35762
37562
  if (ev.kind === "decision") return `a question answered at ${where}`;
@@ -35845,13 +37645,13 @@ function explainError(model, stack) {
35845
37645
  placed.push({ frame: f });
35846
37646
  continue;
35847
37647
  }
35848
- const m2 = memberAt(model, got.file, f.line);
35849
- if (!m2) {
37648
+ const m3 = memberAt(model, got.file, f.line);
37649
+ if (!m3) {
35850
37650
  reason ??= `line ${f.line} of ${got.file} is not inside any action or rule Thunder read`;
35851
37651
  placed.push({ frame: f, file: got.file });
35852
37652
  continue;
35853
37653
  }
35854
- placed.push({ frame: f, file: got.file, member: m2, at: nodeAt(m2, f.line, "raise") });
37654
+ placed.push({ frame: f, file: got.file, member: m3, at: nodeAt(m3, f.line, "raise") });
35855
37655
  }
35856
37656
  const first = placed.findIndex((p) => p.member);
35857
37657
  const errWords = `${s.error}${s.message ? `: ${s.message}` : ""}`;
@@ -36046,10 +37846,10 @@ var KIND_ORDER = [
36046
37846
  "moved",
36047
37847
  "form"
36048
37848
  ];
36049
- var words12 = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
36050
- var cap4 = (s) => s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
37849
+ var words13 = (s) => String(s).replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().trim();
37850
+ var cap5 = (s) => s ? s.charAt(0).toUpperCase() + s.slice(1) : s;
36051
37851
  var lc2 = (s) => s && !/^[A-Z]{2}|^[A-Z]\w*[A-Z_]/.test(s) ? s.charAt(0).toLowerCase() + s.slice(1) : s;
36052
- var answerWords2 = (r) => /^true$/i.test(r) ? "Yes" : /^false$/i.test(r) ? "No" : cap4(words12(r));
37852
+ var answerWords2 = (r) => /^true$/i.test(r) ? "Yes" : /^false$/i.test(r) ? "No" : cap5(words13(r));
36053
37853
  var stemKey2 = (path) => nameKey(String(path).replace(/\.[^./]+$/, "").replace(/\\/g, "/"));
36054
37854
  var KIND_WORD = { action: "action", rule: "rule", steps: "function", setup: "setup", "not-read": "function" };
36055
37855
  var HASH_COMMENTS = /* @__PURE__ */ new Set(["python", "ruby", "php"]);
@@ -36472,7 +38272,7 @@ function compareMember(o, n, items) {
36472
38272
  "form",
36473
38273
  subject,
36474
38274
  whereOf2(n),
36475
- `${renamedOrMoved.length ? `${cap4(renamedOrMoved.join(" and "))}. ` : ""}Only the form changed: ${why}`
38275
+ `${renamedOrMoved.length ? `${cap5(renamedOrMoved.join(" and "))}. ` : ""}Only the form changed: ${why}`
36476
38276
  ));
36477
38277
  if (sameCode && sameThunder) {
36478
38278
  if (!renamedOrMoved.length && o.code.join("\n") === n.code.join("\n")) return "unchanged";
@@ -36480,7 +38280,7 @@ function compareMember(o, n, items) {
36480
38280
  return "form";
36481
38281
  }
36482
38282
  const noteMove = () => {
36483
- if (renamedOrMoved.length) items.push(item2(moveKind, "form", subject, whereOf2(n), `${cap4(renamedOrMoved.join(" and "))}.`));
38283
+ if (renamedOrMoved.length) items.push(item2(moveKind, "form", subject, whereOf2(n), `${cap5(renamedOrMoved.join(" and "))}.`));
36484
38284
  };
36485
38285
  const renames = localRenames(o.tokens, n.tokens, n.m.language, [o.m.name]);
36486
38286
  if (renames) {
@@ -37718,11 +39518,11 @@ function buildIntentGraph(ast) {
37718
39518
  relationships.push(rel(mId, "constrained_by", id2));
37719
39519
  }
37720
39520
  const nodeIds = new Set(nodes2.map((n) => n.id));
37721
- for (const cap5 of ast.capabilities || []) {
37722
- const id2 = `capability.${slug(cap5.name || "capability")}`;
37723
- nodes2.push(node(id2, "Capability", cap5.name, { description: cap5.description || null }));
39521
+ for (const cap6 of ast.capabilities || []) {
39522
+ const id2 = `capability.${slug(cap6.name || "capability")}`;
39523
+ nodes2.push(node(id2, "Capability", cap6.name, { description: cap6.description || null }));
37724
39524
  relationships.push(rel(mId, "requires", id2));
37725
- for (const m of cap5.implements || []) {
39525
+ for (const m of cap6.implements || []) {
37726
39526
  const target = [`command.${slug(m)}`, `decision.${slug(m)}`, `mission.${slug(m)}`].find((cand) => nodeIds.has(cand));
37727
39527
  if (target) relationships.push(rel(id2, "implemented_by", target));
37728
39528
  }
@@ -37987,10 +39787,10 @@ function graphToSource(graph) {
37987
39787
  const m = String(h.description || "").match(/compensate (.+)$/);
37988
39788
  if (m) for (const step of m[1].split(",")) push(` compensate ${step.trim()}`);
37989
39789
  }
37990
- for (const cap5 of byType("Capability")) {
37991
- push(`capability ${title(cap5)}`);
37992
- if (cap5.description) push(` description "${cap5.description}"`);
37993
- for (const m of out(cap5.id, "implemented_by")) push(` implements ${title(m)}`);
39790
+ for (const cap6 of byType("Capability")) {
39791
+ push(`capability ${title(cap6)}`);
39792
+ if (cap6.description) push(` description "${cap6.description}"`);
39793
+ for (const m of out(cap6.id, "implemented_by")) push(` implements ${title(m)}`);
37994
39794
  }
37995
39795
  for (const iface of byType("SystemContract")) {
37996
39796
  push(`interface ${title(iface)}`);
@@ -38915,9 +40715,9 @@ var SECRET_TYPES3 = /* @__PURE__ */ new Set(["secret", "password", "passwd", "jw
38915
40715
  var SECRET_NAME2 = /pass(word|wd)?|secret|token|jwt|ssn|api[-_]?key|apikey|credential|cvv|private[-_]?key|card/i;
38916
40716
  var isSecretField = (f) => f && (SECRET_TYPES3.has(String(f.type || "").toLowerCase()) || SECRET_NAME2.test(f.name || ""));
38917
40717
  function pascalish(text2) {
38918
- const words13 = String(text2 || "Mission").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/);
38919
- if (words13.length === 1) return words13[0].charAt(0).toUpperCase() + words13[0].slice(1);
38920
- return words13.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
40718
+ const words14 = String(text2 || "Mission").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^A-Za-z0-9]+/g, " ").trim().split(/\s+/);
40719
+ if (words14.length === 1) return words14[0].charAt(0).toUpperCase() + words14[0].slice(1);
40720
+ return words14.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
38921
40721
  }
38922
40722
  var normRules = (list3) => (Array.isArray(list3) ? list3 : []).map((r) => typeof r === "string" ? { statement: r } : { ...r }).filter((r) => r.statement);
38923
40723
  function draftIntent(brief = {}) {
@@ -40948,6 +42748,7 @@ function translateDecisions(ast, lang) {
40948
42748
  readFiles,
40949
42749
  readLevel,
40950
42750
  readRepo,
42751
+ readScreens,
40951
42752
  readableFile,
40952
42753
  readableLanguage,
40953
42754
  readingOf,
@@ -40982,6 +42783,7 @@ function translateDecisions(ast, lang) {
40982
42783
  sayFull,
40983
42784
  scanIntent,
40984
42785
  scanProject,
42786
+ screenText,
40985
42787
  searchAtlas,
40986
42788
  searchReading,
40987
42789
  searchRepo,