claude-mem-lite 6.30.10 → 6.30.11

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.
@@ -9,7 +9,7 @@
9
9
  "plugins": [
10
10
  {
11
11
  "name": "claude-mem-lite",
12
- "version": "6.30.10",
12
+ "version": "6.30.11",
13
13
  "source": "./",
14
14
  "homepage": "https://github.com/sdsrss/claude-mem-lite",
15
15
  "description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark)."
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.30.10",
3
+ "version": "6.30.11",
4
4
  "description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
5
5
  "author": {
6
6
  "name": "sdsrss"
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.30.10",
3
+ "version": "6.30.11",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "claude-mem-lite",
9
- "version": "6.30.10",
9
+ "version": "6.30.11",
10
10
  "os": [
11
11
  "darwin",
12
12
  "linux",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-mem-lite",
3
- "version": "6.30.10",
3
+ "version": "6.30.11",
4
4
  "description": "Persistent long-term memory for Claude Code via MCP — captures coding decisions, bugfixes, and context across sessions. FTS5 BM25 keyword search with episode batching. Single SQLite DB, no external services. A lighter, lower-cost alternative to claude-mem (episode batching + a smaller model; cost savings are an internal estimate, not a measured benchmark).",
5
5
  "type": "module",
6
6
  "packageManager": "npm@10.9.2",
package/secret-scrub.mjs CHANGED
@@ -756,6 +756,49 @@ function cutOffKeyEnd(text, b, be, ctx) {
756
756
  const label = text.slice(b, be);
757
757
  const read = readKeyLines(text, next, u, shape, shapeLead, longs, longest, first, end, ctx.memoOf);
758
758
  const found = read.longs > 0 && keyEvidence(read, label, true) ? read.end : -1;
759
+ // The lines below read again with the shape of `prefix`, whose first character after blanks is
760
+ // `lead`: the reading of the key they hold, or null. `accept`: a further test of that reading.
761
+ const reread = (prefix, lead, accept = null) => {
762
+ const alt = ctx.shapeOf(prefix);
763
+ if (!alt || ctx.endFollows(be)) return null;
764
+ const again = readKeyLines(text, next, u, alt, lead, longs, longest, first, end, ctx.memoOf);
765
+ if (!(again.longs > 0 && again.end > found && keyEvidence(again, label, false))) return null;
766
+ if (accept && !accept(again)) return null;
767
+ ctx.reread = true;
768
+ return again;
769
+ };
770
+ // The lines under a diff context BEGIN (D#614 A1, D#641) read with a diff mark's shape, which takes
771
+ // context lines too: where the key ends, or -1. Only when the lines it takes include a removed or
772
+ // added one: Read output starts its lines with spaces as well, and a reading there took the next
773
+ // line's number for a key's short last line. A removed key that ends with its short last line (or a
774
+ // PGP checksum) is followed by the added key's lines, which the reading stopped at: they are read
775
+ // on, as lines of the same key.
776
+ // What D#641 added (a reading of a BEGIN whose next line has no mark, `admitted` false, and the added
777
+ // key's lines) never spans another private-key BEGIN, which no key in a real diff holds: a header line
778
+ // holding one, swallowed by the span, started no reading of its own on a later pass, where it read on
779
+ // over the first pass's ***PEM_KEY*** line and erased a cut line after it (6 of 400,000 r3mix texts).
780
+ // And what D#641 added reads only inside a unified diff's hunk (ctx.inHunk, from the BEGIN's line
781
+ // start `gl`): an indented cut key in prose read the dash list under it as removed and added key
782
+ // lines, losing it (6.30.10 pre-tag r1 F2).
783
+ const diffRead = (admitted, gl) => {
784
+ // Such a reading ends before the next BEGIN and takes a marked line, so with no marked line before
785
+ // that BEGIN there is none to read (header BEGINs over context lines read the same run again each).
786
+ if (!admitted && !(ctx.inHunk(gl, u) && markedLineIn(text, next, ctx.nextBegin(next), u))) return -1;
787
+ let r = reread(
788
+ '-',
789
+ 45,
790
+ (a) => (admitted || ctx.nextBegin(next) >= a.end) && markedLineIn(text, next, a.end, u),
791
+ );
792
+ if (!r) return -1;
793
+ const alt = ctx.shapeOf('-');
794
+ for (;;) {
795
+ const n = r.shorts > 0 ? nextLine(text, r.end, u).next : -1;
796
+ if (n === -1 || (text[n] !== '-' && text[n] !== '+') || !ctx.inHunk(gl, u)) return r.end;
797
+ const again = readKeyLines(text, n, u, alt, 45, 0, 0, '', -1, ctx.memoOf);
798
+ if (again.longs === 0 || ctx.nextBegin(n) < again.end) return r.end;
799
+ r = again;
800
+ }
801
+ };
759
802
  // D#168: code between the line prefix and the BEGIN (`-KEY = '''`, ` 5\tKEY = """`) or a
760
803
  // string opener before it (`'+`, `"-`) made the whole left context the shape, which no line below
761
804
  // starts with, so nothing past the BEGIN line was read and a cut key was stored. Read again with
@@ -789,63 +832,18 @@ function cutOffKeyEnd(text, b, be, ctx) {
789
832
  if (!B64_RUN16_RE.test(gap) && !gap.includes(':')) return found;
790
833
  }
791
834
  }
792
- // The grammar starts the line. In escaped text the prefix above stops at an unescaped single
793
- // quote, which JSON never escapes (`-KEY = '''` in a JSON string leaves ''), so look past single
794
- // quotes for the start of the line: a break, or a double quote that ends a string at this depth
795
- // (the string the line is in), or the start of the text. At most LINE_START_SCAN characters back;
796
- // past that, no grammar.
797
- let gl = ls;
798
- if (u > 0 && ls > 0 && text[ls - 1] === "'") {
799
- gl = -1;
800
- // Native between candidates: a character by character walk was most of the time of a shape
801
- // that repeats one 300-character line (pemEscapedLongCodeBeforeBegin), and now goes the whole line.
802
- const lim = Math.max(0, ls - LINE_START_SCAN);
803
- for (let j = ls - 1; ;) {
804
- LINE_BACK_RE.lastIndex = j;
805
- const k = j - LINE_BACK_RE.exec(text)[1].length;
806
- if (k === 0) {
807
- if (lim === 0) gl = 0;
808
- break;
809
- }
810
- // text[k - 1] is a break, a double quote or a backslash. A backslash run then `n` or `r` at k
811
- // is an escaped break at this depth when the run fits it; the line starts after that letter.
812
- const c = text.charCodeAt(k - 1);
813
- if (c === 92) {
814
- const e = text.charCodeAt(k);
815
- if (k + 1 < lim) break;
816
- if ((e === 110 || e === 114) && isEscBreak(backslashesBefore(text, k, 0), u)) {
817
- gl = k + 1;
818
- break;
819
- }
820
- } else if (k < lim) break;
821
- else if (c === 10 || c === 13 || isStringEnd(backslashesBefore(text, k - 1, 0), u)) {
822
- gl = k;
823
- break;
824
- }
825
- j = k - 1;
826
- }
827
- }
835
+ const gl = lineStartPastQuotes(text, ls, u);
828
836
  const head = gl === -1 ? '' : text.slice(gl, Math.min(b, gl + PREFIX_GRAMMAR_SCAN));
829
837
  const g = gl === -1 ? null : PREFIX_GRAMMAR_RE.exec(head);
830
838
  const gs = g ? gl + g[0].length - g[1].length : -1;
831
839
  let gp = gl;
832
840
  while (gp < b && (text.charCodeAt(gp) === 32 || text.charCodeAt(gp) === 9)) gp++;
833
- // The lines below read again with the shape of `prefix`, whose first character after blanks is
834
- // `lead`: where the key they hold ends, or -1.
835
- const reread = (prefix, lead) => {
836
- const alt = ctx.shapeOf(prefix);
837
- if (!alt || ctx.endFollows(be)) return -1;
838
- const again = readKeyLines(text, next, u, alt, lead, longs, longest, first, end, ctx.memoOf);
839
- if (!(again.longs > 0 && again.end > found && keyEvidence(again, label, false))) return -1;
840
- ctx.reread = true;
841
- return again.end;
842
- };
843
841
  // Only when the line is more than its grammar before the BEGIN: an opener before it or code after it.
844
842
  if (g && !(gs === gp && gl + g[0].length === b)) {
845
843
  let lead = gs;
846
844
  while (text.charCodeAt(lead) === 32 || text.charCodeAt(lead) === 9) lead++;
847
845
  const r = reread(g[1], text.charCodeAt(lead));
848
- if (r !== -1) return r;
846
+ if (r) return r.end;
849
847
  }
850
848
  // D#614 A2: a grep column after a path the grammar refuses; not the column the grammar read
851
849
  // already, nor the first reading's own prefix. That prefix is the column whenever nothing stands
@@ -854,26 +852,219 @@ function cutOffKeyEnd(text, b, be, ctx) {
854
852
  const p = gl === -1 ? null : GREP_ANY_PATH_RE.exec(head);
855
853
  if (p && !(g && g[1] === p[1]) && p[1] !== left.replace(/^[ \t]+/, '')) {
856
854
  const r = reread(p[1], text.charCodeAt(gl + p[0].length - p[1].length));
857
- if (r !== -1) return r;
855
+ if (r) return r.end;
858
856
  }
859
857
  // D#614 A1: a unified diff's context line starts with its space, with code after it or none, and
860
858
  // the removed and added lines below it with `-` and `+`, which the line prefix (that space, or the
861
- // code) never matched. They are read with a diff mark's shape, which takes a context line too.
862
- // Only when the next line starts with a mark: Read output starts its lines with spaces as well,
863
- // and a reading there took the next line's number for a key's short last line. Nor when the line
864
- // holds an escaped break of another depth: it is then several lines, the first one led by a space.
865
- if (
866
- text.charCodeAt(gl) === 32 &&
867
- (text[next] === '-' || text[next] === '+') &&
868
- !/\\[nr]/.test(text.slice(gl, b))
869
- ) {
870
- const r = reread('-', 45);
859
+ // code) never matched.
860
+ if (gl !== -1 && isDiffContextLine(text, gl, b)) {
861
+ const r = diffRead(text[next] === '-' || text[next] === '+', gl);
871
862
  if (r !== -1) return r;
872
863
  }
864
+ } else if (run < 16) {
865
+ // D#641: in a real diff the lines under a context BEGIN can be context lines too: an OpenSSH key's
866
+ // first body line is the same for every key of its type. The reading above took them for the key
867
+ // and stopped at the first removed line, so the removed and added lines were stored.
868
+ const after = nextLine(text, found, u).next;
869
+ if (after !== -1 && (text[after] === '-' || text[after] === '+')) {
870
+ const gl = lineStartPastQuotes(text, ls, u);
871
+ if (gl !== -1 && isDiffContextLine(text, gl, b)) {
872
+ const r = diffRead(false, gl);
873
+ if (r !== -1) return r;
874
+ }
875
+ }
873
876
  }
874
877
  return found;
875
878
  }
876
879
 
880
+ /**
881
+ * Whether the line from `gl` to the BEGIN at `b` is a unified diff's context line: led by its space,
882
+ * with code after it or none. Not when the line holds an escaped break of another depth: it is then
883
+ * several lines, the first one led by a space.
884
+ */
885
+ function isDiffContextLine(text, gl, b) {
886
+ return text.charCodeAt(gl) === 32 && !/\\[nr]/.test(text.slice(gl, b));
887
+ }
888
+
889
+ // A unified diff's hunk header and the counts of old and new lines under it (1 when left out).
890
+ const HUNK_HEADER_RE = /@@ -\d+(?:,(\d+))? \+\d+(?:,(\d+))? @@/g;
891
+
892
+ /**
893
+ * Whether a line starts at `at` at break depth u: the text's start, a break (at an escape depth not a
894
+ * real one right after a backslash, which nextEscapedLine steps over), or the quote that opens a string
895
+ * at that depth (`"patch":"@@ …` in JSON, where the line is the string's first).
896
+ */
897
+ function startsLineAt(text, at, u) {
898
+ if (at === 0) return true;
899
+ const c = text[at - 1];
900
+ if (c === '\n' || c === '\r') return u === 0 || text[at - 2] !== '\\';
901
+ if (c === 'n' || c === 'r') return isEscBreak(backslashesBefore(text, at - 1, 0), u);
902
+ return (c === '"' || c === "'") && isStringEnd(backslashesBefore(text, at - 1, 0), u);
903
+ }
904
+
905
+ // A break at an escape depth, found natively: a backslash run then `n` or `r` (its length decides the
906
+ // depth), or a real break not right after a backslash (nextEscapedLine steps over the character after a
907
+ // run). The lookbehinds start a match at a run's first backslash only, so each run is read once.
908
+ const ESC_BREAK_TOKEN_RE = /(?<!\\)\\+[nr]|(?<!\\)[\n\r]/g;
909
+ const BREAK_RE = /[\n\r]/g;
910
+
911
+ /**
912
+ * nextLine from a line start `s`, its break found natively. A hunk's lines are read at the depth asked,
913
+ * and in text at several depths a line runs across the others' text: nextEscapedLine stopped at each
914
+ * backslash in it, 33% of the time of hunks at four depths in turn under coverage.
915
+ */
916
+ function hunkNextLine(text, s, u) {
917
+ const re = u === 0 ? BREAK_RE : ESC_BREAK_TOKEN_RE;
918
+ re.lastIndex = s;
919
+ for (let m = re.exec(text); m; m = re.exec(text)) {
920
+ const r = m[0].length - 1;
921
+ if (r === 0 || isEscBreak(r, u)) return nextLine(text, m.index, u);
922
+ }
923
+ return { end: text.length, next: -1 };
924
+ }
925
+
926
+ /**
927
+ * Whether a line starting at `s` is in a unified diff's hunk at break depth u (D#649), from the headers
928
+ * `heads` ({ at, old, add }, ascending). A hunk is the lines below a header that starts a line, as
929
+ * nextLine reads them: a `-` line spends one of the old count, a `+` line one of the new, and a context
930
+ * line (led by a space, or empty: git's diff.suppressBlankEmpty and GNU diff's --suppress-blank-empty
931
+ * leave it so) one of each while both last; any other line ends it (`` comes
932
+ * after one side's last line, so no context line follows it). Only context lines are asked about (a
933
+ * BEGIN's line led by a space), so once a count is spent nothing after it is in the hunk. A line's
934
+ * question goes to the nearest header before it that starts a line at u; a header's text inside a line
935
+ * (the diff of a file that holds one) starts no hunk. A hunk is read from its header only as far as the
936
+ * line asked about, and on from there for a later one, so no line is read twice: reading each hunk
937
+ * whole read the last line of every hunk at one depth across the text at the others, 14.7x benign under
938
+ * coverage (hunks at four depths in turn, 3.9x on v6.30.10).
939
+ */
940
+ function hunkReader(text, heads, u) {
941
+ const own = heads.filter((h) => startsLineAt(text, h.at, u));
942
+ const read = new Map();
943
+ return (s) => {
944
+ let lo = 0;
945
+ let hi = own.length;
946
+ while (lo < hi) {
947
+ const mid = (lo + hi) >> 1;
948
+ if (own[mid].at < s) lo = mid + 1;
949
+ else hi = mid;
950
+ }
951
+ const k = lo - 1;
952
+ if (k < 0) return false;
953
+ let h = read.get(k);
954
+ if (h === undefined) {
955
+ const { at, old, add } = own[k];
956
+ read.set(k, (h = { next: hunkNextLine(text, at, u).next, old, add, starts: new Set() }));
957
+ }
958
+ // Never past the next header: it is at or after s (a later line's question goes to its hunk).
959
+ while (h.next !== -1 && h.next <= s) {
960
+ const at = h.next;
961
+ const line = hunkNextLine(text, at, u);
962
+ const c = line.end === at ? 32 : text.charCodeAt(at);
963
+ if (c === 32 && h.old > 0 && h.add > 0) {
964
+ h.old--;
965
+ h.add--;
966
+ } else if (c === 45) h.old--;
967
+ else if (c === 43) h.add--;
968
+ else {
969
+ h.next = -1;
970
+ break;
971
+ }
972
+ h.starts.add(at);
973
+ h.next = line.next;
974
+ }
975
+ return h.starts.has(s);
976
+ };
977
+ }
978
+
979
+ // A diff mark after a character that can end a line: a break, and at an escape depth an escaped
980
+ // break's letter or (one escape deep) the quote that reopens a string concatenated across lines.
981
+ const MARK_AFTER_BREAK_RE = /[\n\r][-+]/g;
982
+ const MARK_AFTER_ESC_RE = /[\n\r"'nr][-+]/g;
983
+
984
+ /**
985
+ * Whether a line that starts in [from, to) at break depth u (`from` a line start) starts with a diff's
986
+ * `-` or `+`. The marks are found natively and each is checked to start a line as nextLine reads them:
987
+ * reading the lines one by one went through every line of a run under a BEGIN in Read output (each led
988
+ * by a space) on each of the 32 passes a chain of labelled secrets takes, 42-57% of two linearity
989
+ * shapes under coverage.
990
+ */
991
+ function markedLineIn(text, from, to, u) {
992
+ if (from === -1 || from >= to) return false;
993
+ const c0 = text.charCodeAt(from);
994
+ if (c0 === 45 || c0 === 43) return true;
995
+ const re = u === 0 ? MARK_AFTER_BREAK_RE : MARK_AFTER_ESC_RE;
996
+ const seg = to === Infinity ? text.slice(from) : text.slice(from, to);
997
+ re.lastIndex = 0;
998
+ for (let m = re.exec(seg); m; m = re.exec(seg)) {
999
+ re.lastIndex = m.index + 1;
1000
+ const c = from + m.index;
1001
+ const ch = text.charCodeAt(c);
1002
+ // At an escape depth a real break right after a backslash run is that run's next character, which
1003
+ // nextEscapedLine steps over.
1004
+ if (ch === 10 || ch === 13) {
1005
+ if (u === 0 || text.charCodeAt(c - 1) !== 92) return true;
1006
+ } else if (ch === 110 || ch === 114) {
1007
+ if (isEscBreak(backslashesBefore(text, c, from), u)) return true;
1008
+ } else if (u === 1) {
1009
+ // The quote that opens the string after `\n" +` and a break: a line start when an escaped break
1010
+ // at depth 1 starts the concatenation (nextEscapedLine's CONCAT_AFTER_RE).
1011
+ if (opensConcat(text, c, from)) return true;
1012
+ }
1013
+ }
1014
+ return false;
1015
+ }
1016
+
1017
+ /**
1018
+ * Whether the quote at `c` opens the string after a depth-1 escaped break, a quote, an optional `+` and a
1019
+ * break, so that a line starts after it: CONCAT_AFTER_RE (nextEscapedLine) read backward, within `from`.
1020
+ */
1021
+ function opensConcat(text, c, from) {
1022
+ const blanks = (j) => {
1023
+ while (j >= from && (text[j] === ' ' || text[j] === '\t')) j--;
1024
+ return j;
1025
+ };
1026
+ let j = blanks(c - 1);
1027
+ if (j < from) return false;
1028
+ if (text[j] === '\n') j -= j - 1 >= from && text[j - 1] === '\r' ? 2 : 1;
1029
+ else if (text[j] === '\r') j--;
1030
+ else return false;
1031
+ j = blanks(j);
1032
+ if (j >= from && text[j] === '+') j = blanks(j - 1);
1033
+ if (j < from || (text[j] !== '"' && text[j] !== "'")) return false;
1034
+ j--;
1035
+ return j >= from && (text[j] === 'n' || text[j] === 'r') && isEscBreak(backslashesBefore(text, j, from), 1);
1036
+ }
1037
+
1038
+ /**
1039
+ * Where the line that holds the BEGIN starts, from `ls`, the start cutOffKeyEnd's prefix walk found:
1040
+ * that, unless the walk stopped at a single quote in escaped text, or -1. The walk stops at an
1041
+ * unescaped single quote, which JSON never escapes (`-KEY = '''` in a JSON string leaves ''), so look
1042
+ * past single quotes for the start of the line: a break, or a double quote that ends a string at this
1043
+ * depth (the string the line is in), or the start of the text. At most LINE_START_SCAN characters
1044
+ * back; past that, -1.
1045
+ */
1046
+ function lineStartPastQuotes(text, ls, u) {
1047
+ if (!(u > 0 && ls > 0 && text[ls - 1] === "'")) return ls;
1048
+ // Native between candidates: a character by character walk was most of the time of a shape that
1049
+ // repeats one 300-character line (pemEscapedLongCodeBeforeBegin), and now goes the whole line.
1050
+ const lim = Math.max(0, ls - LINE_START_SCAN);
1051
+ for (let j = ls - 1; ;) {
1052
+ LINE_BACK_RE.lastIndex = j;
1053
+ const k = j - LINE_BACK_RE.exec(text)[1].length;
1054
+ if (k === 0) return lim === 0 ? 0 : -1;
1055
+ // text[k - 1] is a break, a double quote or a backslash. A backslash run then `n` or `r` at k is
1056
+ // an escaped break at this depth when the run fits it; the line starts after that letter.
1057
+ const c = text.charCodeAt(k - 1);
1058
+ if (c === 92) {
1059
+ const e = text.charCodeAt(k);
1060
+ if (k + 1 < lim) return -1;
1061
+ if ((e === 110 || e === 114) && isEscBreak(backslashesBefore(text, k, 0), u)) return k + 1;
1062
+ } else if (k < lim) return -1;
1063
+ else if (c === 10 || c === 13 || isStringEnd(backslashesBefore(text, k - 1, 0), u)) return k;
1064
+ j = k - 1;
1065
+ }
1066
+ }
1067
+
877
1068
  /**
878
1069
  * Whether a reading is a key: one base64 line of 40+ characters or a start the way a key encoding
879
1070
  * starts; when `loose`, also armor headers or two lines of 16+. The grammar reading (D#168) is not
@@ -993,7 +1184,7 @@ function readKeyLines(text, next, u, shape, shapeLead, longs, longest, first, en
993
1184
  memo ??= memoOf(shape);
994
1185
  const r = memo.long.get(longKey);
995
1186
  if (r !== undefined)
996
- return { longs: r.longs, longest: r.longest, first: r.first, end: r.end, armors };
1187
+ return { longs: r.longs, longest: r.longest, first: r.first, end: r.end, armors, shorts: r.shorts };
997
1188
  }
998
1189
  if (longs++ === 0) first = core;
999
1190
  longest = Math.max(longest, core.length);
@@ -1020,8 +1211,8 @@ function readKeyLines(text, next, u, shape, shapeLead, longs, longest, first, en
1020
1211
  break;
1021
1212
  }
1022
1213
  if (blankKey !== null) memo.blank.set(blankKey, -1);
1023
- if (longKey !== null) memo.long.set(longKey, { longs, longest, first, end });
1024
- return { longs, longest, first, end, armors };
1214
+ if (longKey !== null) memo.long.set(longKey, { longs, longest, first, end, shorts });
1215
+ return { longs, longest, first, end, armors, shorts };
1025
1216
  }
1026
1217
 
1027
1218
  // Separate scanners: KEY_BEGIN_RE's lastIndex drives scrubCutOffKeys' loop while these run.
@@ -1099,7 +1290,23 @@ function scrubCutOffKeys(text) {
1099
1290
  if (m === undefined) memos.set(id, (m = { blank: new Map(), long: new Map() }));
1100
1291
  return m;
1101
1292
  };
1102
- const ctx = { endFollows, nextBegin, shapeOf, memoOf, reread: false };
1293
+ // Whether the line starting at `s` (depth u) is in a unified diff's hunk (hunkReader): the headers
1294
+ // found once per call, on first use, and one reader per depth.
1295
+ let heads = null;
1296
+ const hunks = new Map();
1297
+ const inHunk = (s, u) => {
1298
+ if (heads === null) {
1299
+ heads = [];
1300
+ HUNK_HEADER_RE.lastIndex = 0;
1301
+ for (let h; (h = HUNK_HEADER_RE.exec(text));) {
1302
+ heads.push({ at: h.index, old: h[1] === undefined ? 1 : +h[1], add: h[2] === undefined ? 1 : +h[2] });
1303
+ }
1304
+ }
1305
+ let has = hunks.get(u);
1306
+ if (has === undefined) hunks.set(u, (has = hunkReader(text, heads, u)));
1307
+ return has(s);
1308
+ };
1309
+ const ctx = { endFollows, nextBegin, shapeOf, memoOf, inHunk, reread: false };
1103
1310
  KEY_BEGIN_RE.lastIndex = 0;
1104
1311
  let out = '';
1105
1312
  let last = 0;