@skillstech/thunderlang 1.0.3 → 1.1.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 (74) hide show
  1. package/CHANGELOG.md +207 -0
  2. package/dist/core.cjs +13779 -10043
  3. package/dist/index.cjs +28500 -24392
  4. package/dist/learn.cjs +12853 -9579
  5. package/intent-graph.schema.json +11 -0
  6. package/package.json +6 -2
  7. package/src/cli.mjs +141 -58
  8. package/src/codegen.mjs +145 -55
  9. package/src/conformance.mjs +15 -6
  10. package/src/core/check.mjs +725 -0
  11. package/src/core/cli.mjs +133 -0
  12. package/src/core/diagnostics.mjs +81 -0
  13. package/src/core/format.mjs +20 -0
  14. package/src/core/from-python.mjs +645 -0
  15. package/src/core/index.mjs +38 -0
  16. package/src/core/lexer.mjs +115 -0
  17. package/src/core/parser.mjs +742 -0
  18. package/src/core/project.mjs +167 -0
  19. package/src/core/round-trip.mjs +150 -0
  20. package/src/core/runtime-python.mjs +801 -0
  21. package/src/core/target-python.mjs +486 -0
  22. package/src/core.d.ts +5 -2
  23. package/src/core.mjs +5 -2
  24. package/src/data-schema.mjs +8 -1
  25. package/src/emit.mjs +1 -1
  26. package/src/evidence.mjs +1 -1
  27. package/src/expr.mjs +81 -4
  28. package/src/form-words.mjs +2 -0
  29. package/src/index.d.ts +8 -1
  30. package/src/index.mjs +5 -1
  31. package/src/intent-schema.mjs +1 -0
  32. package/src/libraries.mjs +2 -2
  33. package/src/mcp.mjs +23 -0
  34. package/src/meaning.mjs +47 -7
  35. package/src/model.d.mts +7 -3
  36. package/src/model.mjs +30 -9
  37. package/src/money.d.mts +18 -0
  38. package/src/money.mjs +124 -0
  39. package/src/plain-contract.mjs +18 -2
  40. package/src/powershell.mjs +24 -5
  41. package/src/read-repo.mjs +1 -0
  42. package/src/read.d.mts +11 -0
  43. package/src/read.mjs +121 -13
  44. package/src/review-comment.d.mts +16 -0
  45. package/src/review-comment.mjs +145 -0
  46. package/src/rlang.mjs +10 -3
  47. package/src/say-less.mjs +1432 -0
  48. package/src/shell.mjs +45 -8
  49. package/src/sql-proc.mjs +1198 -0
  50. package/src/sql.mjs +87 -119
  51. package/src/steps.mjs +188 -37
  52. package/src/system.mjs +153 -44
  53. package/src/target-cs.mjs +39 -34
  54. package/src/target-elixir.mjs +40 -30
  55. package/src/target-go.mjs +41 -36
  56. package/src/target-java.mjs +34 -27
  57. package/src/target-kotlin.mjs +43 -35
  58. package/src/target-py.mjs +57 -55
  59. package/src/target-result.d.mts +48 -0
  60. package/src/target-result.mjs +112 -0
  61. package/src/target-rust.mjs +42 -38
  62. package/src/target-scala.mjs +45 -35
  63. package/src/target-ts.mjs +37 -45
  64. package/src/target-types.mjs +41 -5
  65. package/src/target-util.mjs +55 -2
  66. package/src/trace-cli.mjs +58 -0
  67. package/src/trace-fs.mjs +76 -0
  68. package/src/trace.mjs +261 -0
  69. package/src/translate.d.mts +3 -0
  70. package/src/translate.mjs +62 -32
  71. package/src/why-cli.mjs +31 -0
  72. package/src/why.d.mts +28 -0
  73. package/src/why.mjs +532 -0
  74. package/src/write-steps.mjs +22 -5
package/src/shell.mjs CHANGED
@@ -399,13 +399,16 @@ function braceWords(inner) {
399
399
  return `${d} when ${subj} ${colon ? 'is set and not empty' : 'is set'}, otherwise nothing`;
400
400
  }
401
401
  if ((m = rest.match(/^(##?|%%?)([\s\S]*)$/))) {
402
- const [, op, p] = m;
402
+ // (Shell quotes in a pattern only mark text as literal: `${x%', '}` removes ", ".)
403
+ const [, op, p0] = m;
404
+ const p = p0.replace(/'([^']*)'|"([^"$`\\]*)"/g, '$1$2');
403
405
  if (/\$/.test(p)) return null;
404
406
  const what = GLOBBY.test(p) ? `the ${op.length === 2 ? 'longest' : 'shortest'} match of "${p}"` : `"${p}"`;
405
407
  return `${subj} without ${what} at the ${op[0] === '#' ? 'start' : 'end'}`;
406
408
  }
407
409
  if ((m = rest.match(/^\/([/#%]?)((?:\\.|[^/\\])*)(?:\/([\s\S]*))?$/))) {
408
- const [, mode, p, r] = m;
410
+ const [, mode, p0, r] = m;
411
+ const p = p0.replace(/'([^']*)'|"([^"$`\\]*)"/g, '$1$2');
409
412
  if (!p || /\$/.test(p)) return null;
410
413
  const pat = GLOBBY.test(p) ? `match of "${p}"` : `"${p}"`;
411
414
  const which = mode === '/' ? `every ${pat}` : mode === '#' ? `${pat} at the start` : mode === '%' ? `${pat} at the end` : `the first ${pat}`;
@@ -575,8 +578,9 @@ const arithSays = (expr) => { const st = arithStatement(expr); if (st) return st
575
578
 
576
579
  // ── Tests and conditions ──────────────────────────────────────────────────────────────────────────────
577
580
 
578
- const PLACE = /(?:^|\s)(?:file|dir|directory|folder|path)$/;
579
- const fileLeaf = (noun, x, neg) => { const w = sayWord(x); const own = PLACE.test(w); return neg ? (own ? `${w} does not exist` : `there is no ${noun} ${w}`) : (own ? `${w} exists` : `the ${noun} ${w} exists`); };
581
+ // (A name says what it is only when it names that kind: `config_dir` is a folder, but `path` can be a file or a folder,
582
+ // so `[ -d "$path" ]` is "the folder path exists", never just "path exists".)
583
+ const fileLeaf = (noun, x, neg) => { const w = sayWord(x); const own = noun === 'file' ? /(?:^|\s)file$/.test(w) : /(?:^|\s)(?:dir|directory|folder)$/.test(w); return neg ? (own ? `${w} does not exist` : `there is no ${noun} ${w}`) : (own ? `${w} exists` : `the ${noun} ${w} exists`); };
580
584
  const UNARY = {
581
585
  '-f': (x, n) => fileLeaf('file', x, n), '-d': (x, n) => fileLeaf('folder', x, n),
582
586
  '-e': (x, n) => `${sayWord(x)} ${n ? 'does not exist' : 'exists'}`, '-a': (x, n) => `${sayWord(x)} ${n ? 'does not exist' : 'exists'}`,
@@ -615,7 +619,7 @@ function testWords(ws, neg, double) {
615
619
  if (BINARY[ws[i + 1]] && ws[i + 2] !== undefined) {
616
620
  const [a, op, b] = [ws[i], ws[i + 1], ws[i + 2]];
617
621
  i += 3;
618
- if ((op === '==' || op === '=' || op === '!=') && double && isGlob(b)) { const pos = op !== '!='; return `${sayWord(a)} ${pos !== n ? 'matches' : 'does not match'} ${b}`; }
622
+ if ((op === '==' || op === '=' || op === '!=') && double && isGlob(b)) { const pos = op !== '!='; return `${sayWord(a)} ${pos !== n ? 'matches' : 'does not match'} the pattern \`${b}\``; }
619
623
  // Compared with "" is a question about being empty.
620
624
  if ((op === '=' || op === '==' || op === '!=') && /^(?:""|'')$/.test(b)) return `${sayWord(a)} is ${(op === '!=') !== n ? 'not empty' : 'empty'}`;
621
625
  const pair = BINARY[op];
@@ -715,6 +719,25 @@ const TRAP_WHEN = (sigs) => {
715
719
  return `When it gets the signal ${s.join(' or ')}`;
716
720
  };
717
721
 
722
+ /** The words of a list, split at spaces outside quotes, `$( … )`, `${ … }`, and backticks: `a "b c" $(ls -a)`. */
723
+ function shellWordsOf(text) {
724
+ const out = [];
725
+ let cur = '', depth = 0, q = null;
726
+ for (let i = 0; i < text.length; i++) {
727
+ const c = text[i];
728
+ if (q) { cur += c; if (c === '\\' && q === '"') { cur += text[++i] ?? ''; continue; } if (c === q) q = null; continue; }
729
+ if (c === '\\') { cur += c + (text[++i] ?? ''); continue; }
730
+ if (c === '"' || c === "'" || c === '`') { q = c; cur += c; continue; }
731
+ if (c === '$' && (text[i + 1] === '(' || text[i + 1] === '{')) { depth++; cur += c + text[++i]; continue; }
732
+ if (depth && (c === '(' || c === '{')) { depth++; cur += c; continue; }
733
+ if (depth && (c === ')' || c === '}')) { depth--; cur += c; continue; }
734
+ if (!depth && /\s/.test(c)) { if (cur) out.push(cur); cur = ''; continue; }
735
+ cur += c;
736
+ }
737
+ if (cur) out.push(cur);
738
+ return out;
739
+ }
740
+
718
741
  /** One assignment word (`X=val`, `X+=val`, `arr=(a b)`) in words. */
719
742
  function assignWords(a, { exported = false, readonly = false } = {}) {
720
743
  const m = a.match(/^([A-Za-z_]\w*)(\[[^\]]*\])?(\+?)=([\s\S]*)$/);
@@ -722,11 +745,12 @@ function assignWords(a, { exported = false, readonly = false } = {}) {
722
745
  const [, name, index, plus, val] = m;
723
746
  const who = `${varWords(name)}${index ? `'s ${sayWord(index.slice(1, -1))}` : ''}`;
724
747
  const tail = exported ? ' and shares it with the programs it runs' : readonly ? ' (it cannot change after this)' : '';
725
- if (name === 'PATH' && /\$\{?PATH\}?/.test(val)) { const added = val.split(':').filter((x) => !/\$\{?PATH\}?/.test(x)); return `Adds ${listWords(added.map(sayWord))} to the PATH (where commands are found)`; }
748
+ // (`"${BIN}:${PATH}"`: the quotes go round the whole value, so each part is read inside them.)
749
+ if (name === 'PATH' && /\$\{?PATH\}?/.test(val)) { const q = /^"[^"]*"$/.test(val); const added = (q ? val.slice(1, -1) : val).split(':').filter((x) => !/\$\{?PATH\}?/.test(x)).map((x) => (q ? `"${x}"` : x)); return `Adds ${listWords(added.map(sayWord))} to the PATH (where commands are found)`; }
726
750
  if (/^\(/.test(val)) {
727
751
  const inner = val.slice(1, -1).trim();
728
752
  if (!inner) return `Starts ${who} as an empty list`;
729
- const items = inner.split(/\s+/).filter(Boolean);
753
+ const items = shellWordsOf(inner);
730
754
  return `${plus ? 'Adds' : 'Sets'} ${plus ? `${listWords(items.map(sayWord))} to ${who}` : `${who} to the list ${listWords(items.slice(0, 6).map(sayWord))}${items.length > 6 ? ', …' : ''}`}${tail}`;
731
755
  }
732
756
  if (val === '' || val === '""' || val === "''") return `Empties ${who}${tail}`;
@@ -754,8 +778,21 @@ function redirWords(redirs) {
754
778
  }
755
779
  const toStderr = (redirs) => redirs.some((r) => (r.op === '>&' && r.target === '2' && (!r.fd || r.fd === '1')) || (r.fd === '1' && r.op === '>&' && r.target === '2') || ((r.op === '>' || r.op === '>>') && r.target === '/dev/stderr'));
756
780
 
757
- /** A simple command as { kind, says, ... }, or null when it does nothing a reader needs (`:`, `true`). */
781
+ /**
782
+ * `exec prog args` runs prog in place of this script: the script ends there (`exec -a NAME prog` names it NAME).
783
+ * (`exec >&2` with no command only moves the output, and the script carries on.)
784
+ */
758
785
  function simpleSays(n, ctx = null) {
786
+ const w0 = String(n.words[0] ?? '').replace(/^\\/, '');
787
+ if (w0 !== 'exec' || n.words.length < 2) return simpleSaysInner(n, ctx);
788
+ let ws = n.words.slice(1);
789
+ while (/^-/.test(ws[0] ?? '')) ws = ws[0] === '-a' ? ws.slice(2) : ws.slice(1);
790
+ if (!ws.length) return simpleSaysInner(n, ctx);
791
+ const r = simpleSaysInner({ ...n, words: ws }, ctx);
792
+ return { kind: 'return', says: `${r?.says || `Runs ${sayWord(ws[0])}`}, in place of this script (it does not come back here)`, exec: true };
793
+ }
794
+
795
+ function simpleSaysInner(n, ctx = null) {
759
796
  // `\command`, `\cd`: a leading backslash only skips aliases; the command is the same.
760
797
  let ws = n.words.map((w, i) => (i === 0 ? w.replace(/^\\(?=[\w.])/, '') : w));
761
798
  if (!ws.length) {