hillclimb 0.9.2 → 0.9.4

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.
@@ -1,6 +1,295 @@
1
1
  // src/middleware/pattern-worker.ts
2
2
  import { parentPort, workerData } from "worker_threads";
3
3
 
4
+ // src/middleware/large-file.ts
5
+ import { constants as bufferConstants } from "buffer";
6
+ var MAX_STRINGIFIABLE_BYTES = bufferConstants.MAX_STRING_LENGTH;
7
+ var NEWLINE = 10;
8
+ var OVERSIZED_LINE_PLACEHOLDER = '{"_hillclimb_omitted":"line exceeded max string length; dropped to allow redaction"}';
9
+ function scanBufferLines(buffer, redactLine, options = {}) {
10
+ const maxLineBytes = options.maxLineBytes ?? MAX_STRINGIFIABLE_BYTES;
11
+ const oversizedPlaceholder = options.oversizedPlaceholder ?? OVERSIZED_LINE_PLACEHOLDER;
12
+ const end = options.end ?? buffer.length;
13
+ const ownsFinalLine = end === buffer.length;
14
+ const edits = [];
15
+ let totalCount = 0;
16
+ let oversizedLines = 0;
17
+ let start = options.start ?? 0;
18
+ while (ownsFinalLine || start < end) {
19
+ const nl = buffer.indexOf(NEWLINE, start);
20
+ const lineEnd = nl === -1 ? buffer.length : nl;
21
+ if (lineEnd - start > maxLineBytes) {
22
+ oversizedLines++;
23
+ edits.push({ start, end: lineEnd, value: oversizedPlaceholder });
24
+ } else {
25
+ const { value, count } = redactLine(
26
+ buffer.toString("utf-8", start, lineEnd)
27
+ );
28
+ if (count > 0) {
29
+ totalCount += count;
30
+ edits.push({ start, end: lineEnd, value });
31
+ }
32
+ }
33
+ if (nl === -1) break;
34
+ start = nl + 1;
35
+ }
36
+ return { edits, count: totalCount, oversizedLines };
37
+ }
38
+
39
+ // src/middleware/pattern-prefilter.ts
40
+ var MIN_LITERAL = 3;
41
+ function score(req) {
42
+ if (!req) return -1;
43
+ let min = Number.POSITIVE_INFINITY;
44
+ for (const s of req) min = Math.min(min, s.length);
45
+ return min * 1e3 - req.length;
46
+ }
47
+ function better(a, b) {
48
+ return score(b) > score(a) ? b : a;
49
+ }
50
+ function isAsciiLiteral(ch) {
51
+ const c = ch.charCodeAt(0);
52
+ return c >= 32 && c < 127;
53
+ }
54
+ var UNKNOWN = { literals: null, minLength: 0 };
55
+ function analyzeRegex(source, flags = "") {
56
+ if (flags.includes("v")) return UNKNOWN;
57
+ let i = 0;
58
+ function skipPast(close) {
59
+ const at = source.indexOf(close, i);
60
+ if (at === -1) throw new Error("unterminated escape");
61
+ i = at + 1;
62
+ }
63
+ function flush(seq) {
64
+ if (seq.run.length > 0) {
65
+ seq.req = better(seq.req, [seq.run.toLowerCase()]);
66
+ seq.run = "";
67
+ }
68
+ }
69
+ function quantifier() {
70
+ const ch = source[i];
71
+ let min = null;
72
+ if (ch === "*" || ch === "?") {
73
+ min = 0;
74
+ i++;
75
+ } else if (ch === "+") {
76
+ min = 1;
77
+ i++;
78
+ } else if (ch === "{") {
79
+ const m = /^\{(\d+)(?:,\d*)?\}/.exec(source.slice(i));
80
+ if (m) {
81
+ min = Number(m[1]);
82
+ i += m[0].length;
83
+ }
84
+ }
85
+ if (min !== null && source[i] === "?") i++;
86
+ return min;
87
+ }
88
+ function skipClass() {
89
+ i++;
90
+ while (i < source.length && source[i] !== "]") {
91
+ if (source[i] === "\\") i++;
92
+ i++;
93
+ }
94
+ i++;
95
+ }
96
+ function alternation() {
97
+ const branches = [];
98
+ let seq = { req: null, run: "", min: 0 };
99
+ while (i < source.length && source[i] !== ")") {
100
+ const ch = source[i];
101
+ if (ch === "|") {
102
+ flush(seq);
103
+ branches.push(seq);
104
+ seq = { req: null, run: "", min: 0 };
105
+ i++;
106
+ continue;
107
+ }
108
+ if (ch === "(") {
109
+ i++;
110
+ let lookaround = false;
111
+ if (source[i] === "?") {
112
+ const m = /^\?(?:[:=!]|<[=!]|<[A-Za-z_$][\w$]*>)/.exec(
113
+ source.slice(i)
114
+ );
115
+ if (!m) throw new Error(`unsupported group at ${i}`);
116
+ lookaround = m[0] !== "?:" && !m[0].endsWith(">");
117
+ i += m[0].length;
118
+ }
119
+ const inner = alternation();
120
+ if (source[i] !== ")") throw new Error("unbalanced group");
121
+ i++;
122
+ const min3 = quantifier();
123
+ flush(seq);
124
+ if (!lookaround) {
125
+ seq.min += inner.min * (min3 ?? 1);
126
+ if (min3 === null || min3 >= 1) seq.req = better(seq.req, inner.req);
127
+ }
128
+ continue;
129
+ }
130
+ if (ch === "[" || ch === ".") {
131
+ if (ch === "[") skipClass();
132
+ else i++;
133
+ seq.min += quantifier() ?? 1;
134
+ flush(seq);
135
+ continue;
136
+ }
137
+ if (ch === "^" || ch === "$") {
138
+ i++;
139
+ quantifier();
140
+ flush(seq);
141
+ continue;
142
+ }
143
+ let lit;
144
+ let width = 1;
145
+ if (ch === "\\") {
146
+ const e = source[i + 1];
147
+ i += 2;
148
+ if (/[A-Za-z0-9]/.test(e)) {
149
+ if (!/[dDwWsS]/.test(e)) width = 0;
150
+ if (e === "x") i += 2;
151
+ else if (e === "u") {
152
+ if (source[i] === "{") skipPast("}");
153
+ else i += 4;
154
+ } else if (e === "c") i += 1;
155
+ else if (e === "k" && source[i] === "<") skipPast(">");
156
+ else if ((e === "p" || e === "P") && source[i] === "{") skipPast("}");
157
+ lit = null;
158
+ } else {
159
+ lit = e;
160
+ }
161
+ } else {
162
+ lit = ch;
163
+ i++;
164
+ }
165
+ const min2 = quantifier();
166
+ seq.min += width * (min2 ?? 1);
167
+ if (lit === null || !isAsciiLiteral(lit)) {
168
+ flush(seq);
169
+ } else if (min2 === null) {
170
+ seq.run += lit;
171
+ } else {
172
+ if (min2 >= 1) seq.run += lit;
173
+ flush(seq);
174
+ }
175
+ }
176
+ flush(seq);
177
+ branches.push(seq);
178
+ let min = Number.POSITIVE_INFINITY;
179
+ let all = [];
180
+ for (const b of branches) {
181
+ min = Math.min(min, b.min);
182
+ if (!b.req) all = null;
183
+ else all?.push(...b.req);
184
+ }
185
+ return { req: all ? [...new Set(all)] : null, min };
186
+ }
187
+ try {
188
+ const { req, min } = alternation();
189
+ if (i !== source.length) return UNKNOWN;
190
+ const foldsBeyondAscii = flags.includes("i") && flags.includes("u");
191
+ const usable = req && !foldsBeyondAscii && !req.some((s) => s.length < MIN_LITERAL);
192
+ return { literals: usable ? req : null, minLength: min };
193
+ } catch {
194
+ return UNKNOWN;
195
+ }
196
+ }
197
+ function isAscii(text) {
198
+ for (let k = 0; k < text.length; k++) {
199
+ if (text.charCodeAt(k) >= 128) return false;
200
+ }
201
+ return true;
202
+ }
203
+ function buildPrefilter(literalsByRule) {
204
+ const alwaysRun = [];
205
+ const goto = [/* @__PURE__ */ new Map()];
206
+ const outs = [[]];
207
+ literalsByRule.forEach((given, rule) => {
208
+ const lits = given?.map((lit) => lit.toLowerCase());
209
+ if (!lits || lits.some((lit) => lit === "" || !isAscii(lit))) {
210
+ alwaysRun.push(rule);
211
+ return;
212
+ }
213
+ for (const lit of lits) {
214
+ let s = 0;
215
+ for (let k = 0; k < lit.length; k++) {
216
+ const c = lit.charCodeAt(k);
217
+ let n = goto[s].get(c);
218
+ if (n === void 0) {
219
+ n = goto.length;
220
+ goto.push(/* @__PURE__ */ new Map());
221
+ outs.push([]);
222
+ goto[s].set(c, n);
223
+ }
224
+ s = n;
225
+ }
226
+ outs[s].push(rule);
227
+ }
228
+ });
229
+ const nStates = goto.length;
230
+ const next = new Int32Array(nStates << 7);
231
+ const fail = new Int32Array(nStates);
232
+ const queue = [];
233
+ for (const [c, n] of goto[0]) {
234
+ next[c] = n;
235
+ queue.push(n);
236
+ }
237
+ for (let q = 0; q < queue.length; q++) {
238
+ const s = queue[q];
239
+ const f = fail[s];
240
+ if (outs[f].length) outs[s] = [.../* @__PURE__ */ new Set([...outs[s], ...outs[f]])];
241
+ const base = s << 7;
242
+ const fbase = f << 7;
243
+ for (let c = 0; c < 128; c++) next[base | c] = next[fbase | c];
244
+ for (const [c, n] of goto[s]) {
245
+ fail[n] = next[fbase | c];
246
+ next[base | c] = n;
247
+ queue.push(n);
248
+ }
249
+ }
250
+ for (let s = 0; s < nStates; s++) {
251
+ const base = s << 7;
252
+ for (let c = 65; c <= 90; c++) next[base | c] = next[base | c + 32];
253
+ }
254
+ const hasOut = new Uint8Array(nStates);
255
+ const outRules = outs.map((o, s) => {
256
+ if (o.length === 0) return null;
257
+ hasOut[s] = 1;
258
+ return o;
259
+ });
260
+ const ruleStamp = new Uint32Array(literalsByRule.length);
261
+ const stateStamp = new Uint32Array(nStates);
262
+ let stamp = 0;
263
+ return {
264
+ alwaysRun,
265
+ candidates(value, out) {
266
+ stamp++;
267
+ if (stamp === 4294967295) {
268
+ ruleStamp.fill(0);
269
+ stateStamp.fill(0);
270
+ stamp = 1;
271
+ }
272
+ let s = 0;
273
+ let found = false;
274
+ for (let k = 0, n = value.length; k < n; k++) {
275
+ const c = value.charCodeAt(k);
276
+ s = c < 128 ? next[s << 7 | c] : 0;
277
+ if (hasOut[s] === 1 && stateStamp[s] !== stamp) {
278
+ stateStamp[s] = stamp;
279
+ for (const r of outRules[s]) {
280
+ if (ruleStamp[r] !== stamp) {
281
+ ruleStamp[r] = stamp;
282
+ out.push(r);
283
+ found = true;
284
+ }
285
+ }
286
+ }
287
+ }
288
+ if (found) out.sort((a, b) => a - b);
289
+ }
290
+ };
291
+ }
292
+
4
293
  // src/middleware/patterns.json
5
294
  var patterns_default = {
6
295
  patterns: [
@@ -8483,11 +8772,12 @@ function applyPattern(content, regex, groupCount, validate, prefixRun) {
8483
8772
  result += content.slice(lastIndex);
8484
8773
  return { value: result, count };
8485
8774
  }
8486
- function redactString(value, patterns, owningKey = null) {
8775
+ function redactStringSlow(value, patterns, owningKey = null, from = 0) {
8487
8776
  let result = value;
8488
8777
  let totalCount = 0;
8489
8778
  let lower = null;
8490
- for (const p of patterns) {
8779
+ for (let idx = from; idx < patterns.length; idx++) {
8780
+ const p = patterns[idx];
8491
8781
  if (p.precheck) {
8492
8782
  if (lower === null) lower = result.toLowerCase();
8493
8783
  let hit = false;
@@ -8515,6 +8805,69 @@ function redactString(value, patterns, owningKey = null) {
8515
8805
  }
8516
8806
  return { value: result, count: totalCount };
8517
8807
  }
8808
+ var engines = /* @__PURE__ */ new WeakMap();
8809
+ var candidateScratch = [];
8810
+ function engineFor(patterns) {
8811
+ let engine = engines.get(patterns);
8812
+ if (!engine) {
8813
+ const minLength = new Int32Array(patterns.length);
8814
+ const literals = patterns.map((p, idx) => {
8815
+ const facts = analyzeRegex(p.regex.source, p.regex.flags);
8816
+ minLength[idx] = facts.minLength;
8817
+ return p.precheck ?? facts.literals;
8818
+ });
8819
+ engine = { prefilter: buildPrefilter(literals), minLength };
8820
+ engines.set(patterns, engine);
8821
+ }
8822
+ return engine;
8823
+ }
8824
+ function redactString(value, patterns, owningKey = null) {
8825
+ const { prefilter, minLength } = engineFor(patterns);
8826
+ const hits = candidateScratch;
8827
+ hits.length = 0;
8828
+ prefilter.candidates(value, hits);
8829
+ const always = prefilter.alwaysRun;
8830
+ let lower = null;
8831
+ let h = 0;
8832
+ let a = 0;
8833
+ while (h < hits.length || a < always.length) {
8834
+ const idx = a >= always.length || h < hits.length && hits[h] < always[a] ? hits[h++] : always[a++];
8835
+ if (value.length < minLength[idx]) continue;
8836
+ const p = patterns[idx];
8837
+ if (p.precheck) {
8838
+ if (lower === null) lower = value.toLowerCase();
8839
+ let hit = false;
8840
+ for (const needle of p.precheck) {
8841
+ if (lower.includes(needle)) {
8842
+ hit = true;
8843
+ break;
8844
+ }
8845
+ }
8846
+ if (!hit) continue;
8847
+ }
8848
+ if (p.context) {
8849
+ const keyHit = owningKey !== null && p.context.test(owningKey);
8850
+ if (!keyHit && (p.keyOnlyContext || !p.context.test(value))) continue;
8851
+ }
8852
+ const applied = applyPattern(
8853
+ value,
8854
+ p.regex,
8855
+ p.groupCount,
8856
+ p.validate,
8857
+ p.prefixRun
8858
+ );
8859
+ if (applied.count > 0) {
8860
+ const rest = redactStringSlow(
8861
+ applied.value,
8862
+ patterns,
8863
+ owningKey,
8864
+ idx + 1
8865
+ );
8866
+ return { value: rest.value, count: applied.count + rest.count };
8867
+ }
8868
+ }
8869
+ return { value, count: 0 };
8870
+ }
8518
8871
  var keyMaskCaches = /* @__PURE__ */ new WeakMap();
8519
8872
  var memoStringUnits = /* @__PURE__ */ new WeakMap();
8520
8873
  var MAX_MEMO_STRING_UNITS = 8 * 1024 * 1024;
@@ -8579,42 +8932,63 @@ function walkAndRedactAll(value, patterns, memo, owningKey = null) {
8579
8932
  }
8580
8933
  return { value, count: 0 };
8581
8934
  }
8582
- function processFiles(files2) {
8935
+ function redactJsonlLine(line, patterns, memo) {
8936
+ if (!line.trim()) return { value: line, count: 0 };
8937
+ try {
8938
+ const parsed = JSON.parse(line);
8939
+ const walked = walkAndRedactAll(parsed, patterns, memo);
8940
+ return { value: JSON.stringify(walked.value), count: walked.count };
8941
+ } catch {
8942
+ return redactString(line, patterns);
8943
+ }
8944
+ }
8945
+ function processFiles(files) {
8583
8946
  const patterns = compilePatterns();
8584
- const results2 = [];
8585
- for (const { index, content, isJsonl } of files2) {
8947
+ const results = [];
8948
+ for (const { index, content, isJsonl } of files) {
8586
8949
  let totalCount;
8587
- let output;
8950
+ let output2;
8588
8951
  if (isJsonl) {
8589
8952
  const memo = /* @__PURE__ */ new Map();
8590
8953
  let count = 0;
8591
- const lines = content.split("\n");
8592
- const processed = lines.map((line) => {
8593
- if (!line.trim()) return line;
8594
- try {
8595
- const parsed = JSON.parse(line);
8596
- const walked = walkAndRedactAll(parsed, patterns, memo);
8597
- count += walked.count;
8598
- return JSON.stringify(walked.value);
8599
- } catch {
8600
- const r = redactString(line, patterns);
8601
- count += r.count;
8602
- return r.value;
8603
- }
8954
+ const processed = content.split("\n").map((line) => {
8955
+ const r = redactJsonlLine(line, patterns, memo);
8956
+ count += r.count;
8957
+ return r.count > 0 ? r.value : line;
8604
8958
  });
8605
8959
  totalCount = count;
8606
- output = processed.join("\n");
8960
+ output2 = processed.join("\n");
8607
8961
  } else {
8608
8962
  const r = redactString(content, patterns);
8609
8963
  totalCount = r.count;
8610
- output = r.value;
8964
+ output2 = r.value;
8611
8965
  }
8612
- results2.push({ index, content: output, count: totalCount });
8966
+ results.push({ index, content: output2, count: totalCount });
8613
8967
  }
8614
- return results2;
8968
+ return results;
8969
+ }
8970
+ function processRanges(ranges) {
8971
+ const patterns = compilePatterns();
8972
+ return ranges.map(({ index, bytes, start, end }) => {
8973
+ const memo = /* @__PURE__ */ new Map();
8974
+ const buffer = Buffer.from(
8975
+ bytes.buffer,
8976
+ bytes.byteOffset,
8977
+ bytes.byteLength
8978
+ );
8979
+ const scanned = scanBufferLines(
8980
+ buffer,
8981
+ (line) => redactJsonlLine(line, patterns, memo),
8982
+ { start, end }
8983
+ );
8984
+ return { index, ...scanned };
8985
+ });
8615
8986
  }
8616
8987
 
8617
8988
  // src/middleware/pattern-worker.ts
8618
- var files = workerData;
8619
- var results = processFiles(files);
8620
- parentPort?.postMessage(results);
8989
+ var job = workerData;
8990
+ var output = {
8991
+ files: processFiles(job.files),
8992
+ ranges: processRanges(job.ranges)
8993
+ };
8994
+ parentPort?.postMessage(output);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hillclimb",
3
- "version": "0.9.2",
3
+ "version": "0.9.4",
4
4
  "description": "Extract and export AI coding tool logs grouped by repo",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -44,6 +44,7 @@
44
44
  "@types/archiver": "^6.0.3",
45
45
  "@types/node": "^22.0.0",
46
46
  "@typescript/native-preview": "^7.0.0-dev.20260330.1",
47
+ "randexp": "^0.5.3",
47
48
  "tsup": "^8.5.1",
48
49
  "typescript": "^5.9.3",
49
50
  "yaml": "^2.8.3"