@structured-world/gitlab-mcp 13.3.1 → 13.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -5
- package/README.md.in +3 -2
- package/dist/src/configuration/call-scope.d.ts +3 -0
- package/dist/src/configuration/call-scope.js +27 -0
- package/dist/src/configuration/call-scope.js.map +1 -0
- package/dist/src/configuration/operator-projects.js +1 -0
- package/dist/src/configuration/operator-projects.js.map +1 -1
- package/dist/src/configuration/policy.d.ts +1 -0
- package/dist/src/configuration/policy.js.map +1 -1
- package/dist/src/entities/pipelines/job-log-sections.d.ts +36 -0
- package/dist/src/entities/pipelines/job-log-sections.js +79 -0
- package/dist/src/entities/pipelines/job-log-sections.js.map +1 -0
- package/dist/src/entities/pipelines/line-grep-worker.d.ts +18 -0
- package/dist/src/entities/pipelines/line-grep-worker.js +296 -0
- package/dist/src/entities/pipelines/line-grep-worker.js.map +1 -0
- package/dist/src/entities/pipelines/line-grep.d.ts +165 -0
- package/dist/src/entities/pipelines/line-grep.js +785 -0
- package/dist/src/entities/pipelines/line-grep.js.map +1 -0
- package/dist/src/entities/pipelines/log-sections.d.ts +57 -0
- package/dist/src/entities/pipelines/log-sections.js +156 -0
- package/dist/src/entities/pipelines/log-sections.js.map +1 -0
- package/dist/src/entities/pipelines/pipeline-grep.d.ts +49 -0
- package/dist/src/entities/pipelines/pipeline-grep.js +327 -0
- package/dist/src/entities/pipelines/pipeline-grep.js.map +1 -0
- package/dist/src/entities/pipelines/registry.js +31 -15
- package/dist/src/entities/pipelines/registry.js.map +1 -1
- package/dist/src/entities/pipelines/schema-readonly.d.ts +55 -0
- package/dist/src/entities/pipelines/schema-readonly.js +152 -5
- package/dist/src/entities/pipelines/schema-readonly.js.map +1 -1
- package/dist/src/entities/pipelines/section-markers.d.ts +89 -0
- package/dist/src/entities/pipelines/section-markers.js +491 -0
- package/dist/src/entities/pipelines/section-markers.js.map +1 -0
- package/dist/src/entities/pipelines/trace-open.d.ts +1 -0
- package/dist/src/entities/pipelines/trace-open.js +23 -0
- package/dist/src/entities/pipelines/trace-open.js.map +1 -0
- package/dist/src/entities/pipelines/trace.d.ts +6 -1
- package/dist/src/entities/pipelines/trace.js +14 -11
- package/dist/src/entities/pipelines/trace.js.map +1 -1
- package/dist/src/handlers.js +3 -1
- package/dist/src/handlers.js.map +1 -1
- package/dist/src/server.js +7 -0
- package/dist/src/server.js.map +1 -1
- package/dist/src/utils/re2-compile.d.ts +4 -0
- package/dist/src/utils/re2-compile.js +58 -0
- package/dist/src/utils/re2-compile.js.map +1 -0
- package/dist/src/utils/re2-pattern.d.ts +7 -0
- package/dist/src/utils/re2-pattern.js +16 -0
- package/dist/src/utils/re2-pattern.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +13 -13
- package/skills/gitlab-ci/SKILL.md +2 -2
|
@@ -0,0 +1,785 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LineGrepScanner = void 0;
|
|
4
|
+
exports.serveLineGrep = serveLineGrep;
|
|
5
|
+
const node_perf_hooks_1 = require("node:perf_hooks");
|
|
6
|
+
const re2_compile_1 = require("../../utils/re2-compile");
|
|
7
|
+
const re2_pattern_1 = require("../../utils/re2-pattern");
|
|
8
|
+
const trace_1 = require("./trace");
|
|
9
|
+
const log_sections_1 = require("./log-sections");
|
|
10
|
+
const section_markers_1 = require("./section-markers");
|
|
11
|
+
const FAILURE_PRESET = [
|
|
12
|
+
String.raw `\b(?:ERROR|FATAL|CRITICAL|FAIL|FAILED|FAILURE)\b`,
|
|
13
|
+
String.raw `(?i:\berror)(?:\[[A-Z]*[0-9]+\])?:`,
|
|
14
|
+
String.raw `\berror (?:TS|CS|C)[0-9]+\b`,
|
|
15
|
+
String.raw `\bERR!`,
|
|
16
|
+
String.raw `\b(?:panic|Panic|PANIC)(?:ked)?\b`,
|
|
17
|
+
String.raw `^Traceback \(most recent call last\)`,
|
|
18
|
+
String.raw `\b[A-Z][A-Za-z0-9]*(?:Exception|Error)\b`,
|
|
19
|
+
String.raw `\b(?:exit|Exit|EXIT)(?:ed)?(?: with)? (?:code|status):? [1-9][0-9]*`,
|
|
20
|
+
String.raw `\b(?:[Aa]ssertion|[Aa]ssert) failed\b`,
|
|
21
|
+
'(?:[Ss]egmentation fault|core dumped|[Oo]ut of memory|OUT OF MEMORY|OOMKilled)',
|
|
22
|
+
String.raw `\bundefined reference to\b`,
|
|
23
|
+
String.raw `\bmake(?:\[[0-9]+\])?: \*\*\*`,
|
|
24
|
+
];
|
|
25
|
+
const FAILURE_PATTERN = FAILURE_PRESET.map((part) => `(?:${part})`).join('|');
|
|
26
|
+
const MAX_GROUP_LINES = 32;
|
|
27
|
+
const BUDGET_CHECK_LINES = 256;
|
|
28
|
+
const NO_PATTERNS = Object.freeze([]);
|
|
29
|
+
const CR = 0x0d;
|
|
30
|
+
function skipEscape(src, start, end) {
|
|
31
|
+
let at = start + 1;
|
|
32
|
+
if (at >= end)
|
|
33
|
+
return end;
|
|
34
|
+
if (src[at] < 0x40 || src[at] > 0x5f)
|
|
35
|
+
return start;
|
|
36
|
+
at++;
|
|
37
|
+
while (at < end && (src[at] < 0x40 || src[at] > 0x7e))
|
|
38
|
+
at++;
|
|
39
|
+
return at >= end ? end : at + 1;
|
|
40
|
+
}
|
|
41
|
+
const hiddenFrom = [];
|
|
42
|
+
const hiddenTo = [];
|
|
43
|
+
const fragmentStarts = new Int32Array(MAX_GROUP_LINES);
|
|
44
|
+
let startCount = 0;
|
|
45
|
+
let startsMapped = 0;
|
|
46
|
+
let clearedFragments = 0;
|
|
47
|
+
const gapBefore = new Uint8Array(MAX_GROUP_LINES);
|
|
48
|
+
let gapCount = 0;
|
|
49
|
+
function tokenEnd(next, size) {
|
|
50
|
+
if (gapCount === 0)
|
|
51
|
+
return size;
|
|
52
|
+
for (let index = startsMapped; index < startCount; index++)
|
|
53
|
+
if (gapBefore[index] && fragmentStarts[index] > next)
|
|
54
|
+
return fragmentStarts[index];
|
|
55
|
+
return size;
|
|
56
|
+
}
|
|
57
|
+
function unionSorted(left, right) {
|
|
58
|
+
if (right.length === 0)
|
|
59
|
+
return left;
|
|
60
|
+
if (left.length === 0)
|
|
61
|
+
return right;
|
|
62
|
+
return [...new Set([...left, ...right])].sort((a, b) => a - b);
|
|
63
|
+
}
|
|
64
|
+
function mapCopied(from, to, out) {
|
|
65
|
+
while (startsMapped < startCount && fragmentStarts[startsMapped] < to) {
|
|
66
|
+
fragmentStarts[startsMapped] = out + fragmentStarts[startsMapped] - from;
|
|
67
|
+
startsMapped++;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function mapRemoved(to, out) {
|
|
71
|
+
while (startsMapped < startCount && fragmentStarts[startsMapped] < to)
|
|
72
|
+
fragmentStarts[startsMapped++] = out;
|
|
73
|
+
}
|
|
74
|
+
const SLOT_BYTES = trace_1.TRACE_LINE_BYTES + 3;
|
|
75
|
+
const isContinuationByte = (byte) => (byte & 0xc0) === 0x80;
|
|
76
|
+
function characterBoundary(text, at, floor, end) {
|
|
77
|
+
if (at <= floor || at >= end || !isContinuationByte(text[at]))
|
|
78
|
+
return at;
|
|
79
|
+
let lead = at - 1;
|
|
80
|
+
while (lead > floor && at - lead < 3 && isContinuationByte(text[lead]))
|
|
81
|
+
lead--;
|
|
82
|
+
const byte = text[lead];
|
|
83
|
+
let width = 0;
|
|
84
|
+
if (byte >= 0xf0)
|
|
85
|
+
width = 4;
|
|
86
|
+
else if (byte >= 0xe0)
|
|
87
|
+
width = 3;
|
|
88
|
+
else if (byte >= 0xc0)
|
|
89
|
+
width = 2;
|
|
90
|
+
const close = lead + width;
|
|
91
|
+
if (close <= at || close > end)
|
|
92
|
+
return at;
|
|
93
|
+
for (let next = at + 1; next < close; next++)
|
|
94
|
+
if (!isContinuationByte(text[next]))
|
|
95
|
+
return at;
|
|
96
|
+
return lead;
|
|
97
|
+
}
|
|
98
|
+
function crRunEnd(line, at, size) {
|
|
99
|
+
while (at < size && line[at] === CR)
|
|
100
|
+
at++;
|
|
101
|
+
return at;
|
|
102
|
+
}
|
|
103
|
+
let renderLength = 0;
|
|
104
|
+
function applyToken(line, next, size, isCr, isEscape) {
|
|
105
|
+
if (isCr) {
|
|
106
|
+
const at = crRunEnd(line, next, size);
|
|
107
|
+
if (at === size)
|
|
108
|
+
return -1;
|
|
109
|
+
renderLength = 0;
|
|
110
|
+
fragmentStarts.fill(0, 0, startsMapped);
|
|
111
|
+
mapRemoved(at + 1, 0);
|
|
112
|
+
clearedFragments = startsMapped;
|
|
113
|
+
return at;
|
|
114
|
+
}
|
|
115
|
+
const end = tokenEnd(next, size);
|
|
116
|
+
const at = isEscape ? skipEscape(line, next, end) : (0, section_markers_1.sectionMarkerEnd)(line, next, end);
|
|
117
|
+
if (at > next) {
|
|
118
|
+
mapRemoved(at, renderLength);
|
|
119
|
+
return at;
|
|
120
|
+
}
|
|
121
|
+
line[renderLength] = line[next];
|
|
122
|
+
mapCopied(next, next + 1, renderLength);
|
|
123
|
+
renderLength++;
|
|
124
|
+
return next + 1;
|
|
125
|
+
}
|
|
126
|
+
function nextOf(line, needle, known, at) {
|
|
127
|
+
return known !== -1 && known < at ? line.indexOf(needle, at) : known;
|
|
128
|
+
}
|
|
129
|
+
function earliest(limit, position) {
|
|
130
|
+
return position !== -1 && position < limit ? position : limit;
|
|
131
|
+
}
|
|
132
|
+
function renderTraceLine(buffer, size) {
|
|
133
|
+
const line = buffer.subarray(0, size);
|
|
134
|
+
startsMapped = 0;
|
|
135
|
+
clearedFragments = 0;
|
|
136
|
+
renderLength = 0;
|
|
137
|
+
let esc = line.indexOf(section_markers_1.ESC);
|
|
138
|
+
let cr = line.indexOf(CR);
|
|
139
|
+
let section = line.indexOf(section_markers_1.SECTION_PREFIX);
|
|
140
|
+
let at = 0;
|
|
141
|
+
let hidden = 0;
|
|
142
|
+
for (;;) {
|
|
143
|
+
esc = nextOf(line, section_markers_1.ESC, esc, at);
|
|
144
|
+
cr = nextOf(line, CR, cr, at);
|
|
145
|
+
section = nextOf(line, section_markers_1.SECTION_PREFIX, section, at);
|
|
146
|
+
let next = earliest(earliest(earliest(size, esc), cr), section);
|
|
147
|
+
const atHidden = hidden < hiddenFrom.length && hiddenFrom[hidden] <= next;
|
|
148
|
+
if (atHidden)
|
|
149
|
+
next = Math.max(at, hiddenFrom[hidden]);
|
|
150
|
+
if (next > at) {
|
|
151
|
+
if (renderLength !== at)
|
|
152
|
+
line.copy(line, renderLength, at, next);
|
|
153
|
+
mapCopied(at, next, renderLength);
|
|
154
|
+
renderLength += next - at;
|
|
155
|
+
}
|
|
156
|
+
if (atHidden) {
|
|
157
|
+
at = Math.max(next, hiddenTo[hidden++]);
|
|
158
|
+
mapRemoved(at, renderLength);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (next === size)
|
|
162
|
+
break;
|
|
163
|
+
at = applyToken(line, next, size, next === cr, next === esc);
|
|
164
|
+
if (at === -1)
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
167
|
+
mapRemoved(Infinity, renderLength);
|
|
168
|
+
return renderLength;
|
|
169
|
+
}
|
|
170
|
+
class LineGrepScanner {
|
|
171
|
+
matcher;
|
|
172
|
+
sections;
|
|
173
|
+
searchesSection;
|
|
174
|
+
listsSections;
|
|
175
|
+
stream;
|
|
176
|
+
presetIndex;
|
|
177
|
+
before;
|
|
178
|
+
after;
|
|
179
|
+
maxMatches;
|
|
180
|
+
invert;
|
|
181
|
+
startLine;
|
|
182
|
+
firstKept;
|
|
183
|
+
firstStored;
|
|
184
|
+
normalize;
|
|
185
|
+
budgetMs;
|
|
186
|
+
outputLimit;
|
|
187
|
+
ringSize;
|
|
188
|
+
ring;
|
|
189
|
+
ringLength;
|
|
190
|
+
ringOmitted;
|
|
191
|
+
ringStamp;
|
|
192
|
+
ringHasStamp;
|
|
193
|
+
carry = Buffer.allocUnsafe(trace_1.TRACE_LINE_BYTES);
|
|
194
|
+
decoder = new TextDecoder('utf-8', { ignoreBOM: true });
|
|
195
|
+
carryLength = 0;
|
|
196
|
+
lineBytes = 0;
|
|
197
|
+
line = 0;
|
|
198
|
+
chainLength = 0;
|
|
199
|
+
groupOpen = false;
|
|
200
|
+
groupFirst = 0;
|
|
201
|
+
groupEnd = 0;
|
|
202
|
+
groupMatchable = false;
|
|
203
|
+
logical;
|
|
204
|
+
outbox = [];
|
|
205
|
+
pending = null;
|
|
206
|
+
closedHunks = 0;
|
|
207
|
+
outputBytes = 0;
|
|
208
|
+
lastEmitted = -1;
|
|
209
|
+
afterRemaining = 0;
|
|
210
|
+
recorded = 0;
|
|
211
|
+
lastRecorded = -1;
|
|
212
|
+
matchCount = 0;
|
|
213
|
+
draining = false;
|
|
214
|
+
stop = null;
|
|
215
|
+
stopLine = 0;
|
|
216
|
+
outputResume = 0;
|
|
217
|
+
spent;
|
|
218
|
+
charged = 0;
|
|
219
|
+
sinceCheck = 0;
|
|
220
|
+
constructor(options) {
|
|
221
|
+
this.searchesSection = options.section !== undefined;
|
|
222
|
+
this.listsSections = options.listSections ?? false;
|
|
223
|
+
const onlySections = options.patterns.length === 0 &&
|
|
224
|
+
!options.preset &&
|
|
225
|
+
(this.searchesSection || this.listsSections);
|
|
226
|
+
const presetPatterns = options.preset ? [FAILURE_PATTERN] : [];
|
|
227
|
+
this.matcher = onlySections ? null : (0, re2_compile_1.compilePatterns)(options.patterns, presetPatterns);
|
|
228
|
+
this.presetIndex = options.preset ? options.patterns.length : undefined;
|
|
229
|
+
this.sections =
|
|
230
|
+
this.searchesSection || this.listsSections ? new log_sections_1.SectionTracker(options.section) : null;
|
|
231
|
+
this.stream = this.sections ? new section_markers_1.MarkerStream(options.normalize) : null;
|
|
232
|
+
this.before = options.before;
|
|
233
|
+
this.after = options.after;
|
|
234
|
+
this.maxMatches = options.maxMatches;
|
|
235
|
+
this.invert = options.invert;
|
|
236
|
+
this.startLine = options.startLine;
|
|
237
|
+
this.firstKept = Math.max(0, options.startLine - options.before);
|
|
238
|
+
if (this.sections)
|
|
239
|
+
this.firstStored = 0;
|
|
240
|
+
else
|
|
241
|
+
this.firstStored = options.normalize
|
|
242
|
+
? Math.max(0, this.firstKept - (MAX_GROUP_LINES - 1))
|
|
243
|
+
: this.firstKept;
|
|
244
|
+
this.normalize = options.normalize;
|
|
245
|
+
this.budgetMs = options.budgetMs;
|
|
246
|
+
this.spent = options.spent ?? new Int32Array(1);
|
|
247
|
+
this.outputLimit = options.outputBytes;
|
|
248
|
+
this.ringSize = options.before + 2;
|
|
249
|
+
this.ring = new Array(this.ringSize);
|
|
250
|
+
this.ringLength = new Int32Array(this.ringSize);
|
|
251
|
+
this.ringOmitted = new Float64Array(this.ringSize);
|
|
252
|
+
this.ringStamp = Buffer.allocUnsafe(this.ringSize * section_markers_1.TIMESTAMP_BYTES);
|
|
253
|
+
this.ringHasStamp = new Uint8Array(this.ringSize);
|
|
254
|
+
}
|
|
255
|
+
growRing(number) {
|
|
256
|
+
const size = this.before + 2 + MAX_GROUP_LINES;
|
|
257
|
+
const ring = new Array(size);
|
|
258
|
+
const length = new Int32Array(size);
|
|
259
|
+
const omitted = new Float64Array(size);
|
|
260
|
+
const stamp = Buffer.allocUnsafe(size * section_markers_1.TIMESTAMP_BYTES);
|
|
261
|
+
const hasStamp = new Uint8Array(size);
|
|
262
|
+
for (let line = Math.max(this.firstStored, number - this.ringSize + 1); line < number; line++) {
|
|
263
|
+
const from = line % this.ringSize;
|
|
264
|
+
const to = line % size;
|
|
265
|
+
ring[to] = this.ring[from];
|
|
266
|
+
length[to] = this.ringLength[from];
|
|
267
|
+
omitted[to] = this.ringOmitted[from];
|
|
268
|
+
this.ringStamp.copy(stamp, to * section_markers_1.TIMESTAMP_BYTES, from * section_markers_1.TIMESTAMP_BYTES, (from + 1) * section_markers_1.TIMESTAMP_BYTES);
|
|
269
|
+
hasStamp[to] = this.ringHasStamp[from];
|
|
270
|
+
}
|
|
271
|
+
this.ringSize = size;
|
|
272
|
+
this.ring = ring;
|
|
273
|
+
this.ringLength = length;
|
|
274
|
+
this.ringOmitted = omitted;
|
|
275
|
+
this.ringStamp = stamp;
|
|
276
|
+
this.ringHasStamp = hasStamp;
|
|
277
|
+
}
|
|
278
|
+
get exhausted() {
|
|
279
|
+
return this.stop !== null;
|
|
280
|
+
}
|
|
281
|
+
push(chunk) {
|
|
282
|
+
if (this.stop !== null)
|
|
283
|
+
return;
|
|
284
|
+
this.charged = node_perf_hooks_1.performance.now();
|
|
285
|
+
const bytes = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength);
|
|
286
|
+
this.stream?.push(bytes);
|
|
287
|
+
let offset = 0;
|
|
288
|
+
while (offset < bytes.length) {
|
|
289
|
+
const newline = bytes.indexOf(10, offset);
|
|
290
|
+
if (newline === -1) {
|
|
291
|
+
this.collect(bytes, offset, bytes.length - offset);
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
if (!this.endLine(bytes, offset, newline - offset))
|
|
295
|
+
break;
|
|
296
|
+
offset = newline + 1;
|
|
297
|
+
}
|
|
298
|
+
this.charge();
|
|
299
|
+
}
|
|
300
|
+
charge() {
|
|
301
|
+
const now = node_perf_hooks_1.performance.now();
|
|
302
|
+
Atomics.add(this.spent, 0, Math.round((now - this.charged) * 1000));
|
|
303
|
+
this.charged = now;
|
|
304
|
+
}
|
|
305
|
+
collect(bytes, offset, length) {
|
|
306
|
+
let limit = 0;
|
|
307
|
+
if (this.line >= this.firstStored)
|
|
308
|
+
limit = trace_1.TRACE_LINE_BYTES;
|
|
309
|
+
else if (this.normalize)
|
|
310
|
+
limit = section_markers_1.TIMESTAMP_HEADER_BYTES;
|
|
311
|
+
const keep = Math.min(length, limit - this.carryLength);
|
|
312
|
+
if (keep > 0) {
|
|
313
|
+
bytes.copy(this.carry, this.carryLength, offset, offset + keep);
|
|
314
|
+
this.carryLength += keep;
|
|
315
|
+
}
|
|
316
|
+
this.lineBytes += length;
|
|
317
|
+
}
|
|
318
|
+
endLine(bytes, offset, length) {
|
|
319
|
+
if (this.lineBytes === 0 && this.line >= this.firstStored) {
|
|
320
|
+
return this.finishLine(bytes, offset, offset + Math.min(length, trace_1.TRACE_LINE_BYTES), length);
|
|
321
|
+
}
|
|
322
|
+
this.collect(bytes, offset, length);
|
|
323
|
+
return this.finishLine(this.carry, 0, this.carryLength, this.lineBytes);
|
|
324
|
+
}
|
|
325
|
+
progress() {
|
|
326
|
+
const hunks = this.outbox;
|
|
327
|
+
this.outbox = [];
|
|
328
|
+
return {
|
|
329
|
+
hunks,
|
|
330
|
+
match_count: this.matchCount,
|
|
331
|
+
scanned_lines: this.line,
|
|
332
|
+
safe_resume: this.resumePoint(true),
|
|
333
|
+
exhausted: this.stop !== null,
|
|
334
|
+
...(this.searchesSection ? { section: this.sections.bounds() } : {}),
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
finish() {
|
|
338
|
+
this.charged = node_perf_hooks_1.performance.now();
|
|
339
|
+
this.stream?.end();
|
|
340
|
+
if (this.stop === null)
|
|
341
|
+
this.finishLine(this.carry, 0, this.carryLength, this.lineBytes);
|
|
342
|
+
if (this.stop === null)
|
|
343
|
+
this.closeGroup();
|
|
344
|
+
this.closePending();
|
|
345
|
+
this.charge();
|
|
346
|
+
const cut = this.stop === 'budget' || this.stop === 'output';
|
|
347
|
+
this.sections?.finish(this.stop === null ? this.line - 1 : null);
|
|
348
|
+
let truncated = null;
|
|
349
|
+
if (this.stop === 'output')
|
|
350
|
+
truncated = 'output_limit';
|
|
351
|
+
else if (this.stop === 'budget')
|
|
352
|
+
truncated = 'budget';
|
|
353
|
+
else if (this.matchCount > this.recorded)
|
|
354
|
+
truncated = this.draining ? 'budget' : 'max_matches';
|
|
355
|
+
const hunks = this.outbox;
|
|
356
|
+
this.outbox = [];
|
|
357
|
+
return {
|
|
358
|
+
hunks,
|
|
359
|
+
match_count: this.matchCount,
|
|
360
|
+
match_count_complete: !cut,
|
|
361
|
+
scanned_lines: this.line,
|
|
362
|
+
total_lines: this.stop === null ? this.line : null,
|
|
363
|
+
truncated,
|
|
364
|
+
resume_from: truncated === null ? null : this.resumePoint(false),
|
|
365
|
+
...(this.presetIndex !== undefined ? { preset_index: this.presetIndex } : {}),
|
|
366
|
+
...(this.searchesSection ? { section: this.sections.bounds() } : {}),
|
|
367
|
+
...(this.listsSections ? { sections: this.sections.listing() } : {}),
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
applyMarkers(line) {
|
|
371
|
+
const events = this.stream.events;
|
|
372
|
+
const tracker = this.sections;
|
|
373
|
+
let read = 0;
|
|
374
|
+
while (read < events.length && events[read].line <= line) {
|
|
375
|
+
const event = events[read++];
|
|
376
|
+
if (event.kind === 'start')
|
|
377
|
+
tracker.start(event.line, event.stamp, event.name, event.options);
|
|
378
|
+
else if (event.kind === 'end')
|
|
379
|
+
tracker.end(event.line, event.stamp, event.name);
|
|
380
|
+
else
|
|
381
|
+
tracker.unread(event.line);
|
|
382
|
+
}
|
|
383
|
+
if (read > 0)
|
|
384
|
+
events.splice(0, read);
|
|
385
|
+
}
|
|
386
|
+
takeHidden(first, starts) {
|
|
387
|
+
hiddenFrom.length = 0;
|
|
388
|
+
hiddenTo.length = 0;
|
|
389
|
+
const hidden = this.stream.hidden;
|
|
390
|
+
if (hidden.length === 0)
|
|
391
|
+
return;
|
|
392
|
+
const taken = [];
|
|
393
|
+
let kept = 0;
|
|
394
|
+
for (const span of hidden) {
|
|
395
|
+
if (span.line <= this.groupEnd) {
|
|
396
|
+
if (span.line >= first)
|
|
397
|
+
taken.push(span);
|
|
398
|
+
}
|
|
399
|
+
else
|
|
400
|
+
hidden[kept++] = span;
|
|
401
|
+
}
|
|
402
|
+
hidden.length = kept;
|
|
403
|
+
taken.sort((a, b) => a.line - b.line || a.from - b.from);
|
|
404
|
+
for (const span of taken) {
|
|
405
|
+
const start = starts(span.line - first);
|
|
406
|
+
hiddenFrom.push(start + span.from);
|
|
407
|
+
hiddenTo.push(start + span.to);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
resumePoint(undelivered) {
|
|
411
|
+
let resume;
|
|
412
|
+
if (this.stop === 'output')
|
|
413
|
+
resume = this.outputResume;
|
|
414
|
+
else if (undelivered && this.pending !== null)
|
|
415
|
+
resume = this.pending.matches[0].line;
|
|
416
|
+
else if (this.matchCount > this.recorded)
|
|
417
|
+
resume = this.lastRecorded + 1;
|
|
418
|
+
else
|
|
419
|
+
resume = this.stop === null ? this.line : this.stopLine;
|
|
420
|
+
if (!this.groupOpen || !this.groupMatchable)
|
|
421
|
+
return resume;
|
|
422
|
+
return Math.min(resume, Math.max(this.groupFirst, this.startLine));
|
|
423
|
+
}
|
|
424
|
+
halt(reason) {
|
|
425
|
+
this.stop ??= reason;
|
|
426
|
+
this.stopLine = this.line;
|
|
427
|
+
}
|
|
428
|
+
overBudget() {
|
|
429
|
+
if (this.draining || this.line <= this.startLine || ++this.sinceCheck < BUDGET_CHECK_LINES)
|
|
430
|
+
return false;
|
|
431
|
+
this.sinceCheck = 0;
|
|
432
|
+
this.charge();
|
|
433
|
+
if (Atomics.load(this.spent, 0) <= this.budgetMs * 1000)
|
|
434
|
+
return false;
|
|
435
|
+
if (this.pending !== null && this.afterRemaining > 0) {
|
|
436
|
+
this.draining = true;
|
|
437
|
+
return false;
|
|
438
|
+
}
|
|
439
|
+
this.halt('budget');
|
|
440
|
+
return true;
|
|
441
|
+
}
|
|
442
|
+
chain(src, begin, end) {
|
|
443
|
+
const chained = this.normalize &&
|
|
444
|
+
this.chainLength > 0 &&
|
|
445
|
+
this.chainLength < MAX_GROUP_LINES &&
|
|
446
|
+
(0, section_markers_1.continuesLine)(src, begin, end);
|
|
447
|
+
this.chainLength = chained ? this.chainLength + 1 : 1;
|
|
448
|
+
return chained;
|
|
449
|
+
}
|
|
450
|
+
finishLine(src, begin, end, sourceBytes) {
|
|
451
|
+
if (this.overBudget())
|
|
452
|
+
return false;
|
|
453
|
+
const number = this.line++;
|
|
454
|
+
this.carryLength = 0;
|
|
455
|
+
this.lineBytes = 0;
|
|
456
|
+
const chained = this.chain(src, begin, end);
|
|
457
|
+
if (number < this.firstStored)
|
|
458
|
+
return true;
|
|
459
|
+
if (chained && this.groupOpen && this.ringSize < this.before + 2 + MAX_GROUP_LINES)
|
|
460
|
+
this.growRing(number);
|
|
461
|
+
const slot = number % this.ringSize;
|
|
462
|
+
this.store(slot, number, src, begin, end, sourceBytes - (end - begin));
|
|
463
|
+
if (chained && this.groupOpen) {
|
|
464
|
+
this.groupEnd = number;
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
this.closeGroup();
|
|
468
|
+
if (this.stop !== null) {
|
|
469
|
+
this.stopLine = number;
|
|
470
|
+
return false;
|
|
471
|
+
}
|
|
472
|
+
this.openGroup(number, !chained);
|
|
473
|
+
}
|
|
474
|
+
if (!this.normalize)
|
|
475
|
+
this.closeGroup();
|
|
476
|
+
return this.stop === null;
|
|
477
|
+
}
|
|
478
|
+
store(slot, number, src, begin, end, omitted) {
|
|
479
|
+
const out = (this.ring[slot] ??= Buffer.allocUnsafe(SLOT_BYTES));
|
|
480
|
+
let from = begin;
|
|
481
|
+
this.ringHasStamp[slot] = 0;
|
|
482
|
+
if (this.normalize) {
|
|
483
|
+
if (number === 0 && end - from >= 3 && src[from] === 0xef) {
|
|
484
|
+
if (src[from + 1] === 0xbb && src[from + 2] === 0xbf)
|
|
485
|
+
from += 3;
|
|
486
|
+
}
|
|
487
|
+
if (end - from >= section_markers_1.TIMESTAMP_HEADER_BYTES && (0, section_markers_1.isTimestampHeader)(src, from)) {
|
|
488
|
+
src.copy(this.ringStamp, slot * section_markers_1.TIMESTAMP_BYTES, from, from + section_markers_1.TIMESTAMP_BYTES);
|
|
489
|
+
this.ringHasStamp[slot] = 1;
|
|
490
|
+
from += section_markers_1.TIMESTAMP_HEADER_BYTES;
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
this.ringLength[slot] = src.copy(out, 0, from, end);
|
|
494
|
+
this.ringOmitted[slot] = omitted;
|
|
495
|
+
}
|
|
496
|
+
openGroup(number, matchable) {
|
|
497
|
+
this.groupOpen = true;
|
|
498
|
+
this.groupFirst = number;
|
|
499
|
+
this.groupEnd = number;
|
|
500
|
+
this.groupMatchable =
|
|
501
|
+
matchable && this.matcher !== null && (this.searchesSection || number >= this.startLine);
|
|
502
|
+
}
|
|
503
|
+
renderGroup() {
|
|
504
|
+
const first = this.groupFirst;
|
|
505
|
+
const head = first % this.ringSize;
|
|
506
|
+
if (this.groupEnd === first) {
|
|
507
|
+
startCount = 0;
|
|
508
|
+
gapCount = 0;
|
|
509
|
+
if (this.stream)
|
|
510
|
+
this.takeHidden(first, () => 0);
|
|
511
|
+
const line = this.ring[head];
|
|
512
|
+
this.ringLength[head] = renderTraceLine(line, this.ringLength[head]);
|
|
513
|
+
this.clearHidden();
|
|
514
|
+
return line.subarray(0, this.ringLength[head]);
|
|
515
|
+
}
|
|
516
|
+
const logical = (this.logical ??= Buffer.allocUnsafe(MAX_GROUP_LINES * trace_1.TRACE_LINE_BYTES));
|
|
517
|
+
const size = this.joinGroup(logical, first);
|
|
518
|
+
if (this.stream)
|
|
519
|
+
this.takeHidden(first, (index) => (index === 0 ? 0 : fragmentStarts[index - 1]));
|
|
520
|
+
const length = renderTraceLine(logical, size);
|
|
521
|
+
this.clearHidden();
|
|
522
|
+
this.splitGroup(logical, first, length);
|
|
523
|
+
return logical.subarray(0, length);
|
|
524
|
+
}
|
|
525
|
+
clearHidden() {
|
|
526
|
+
if (!this.stream)
|
|
527
|
+
return;
|
|
528
|
+
hiddenFrom.length = 0;
|
|
529
|
+
hiddenTo.length = 0;
|
|
530
|
+
}
|
|
531
|
+
joinGroup(logical, first) {
|
|
532
|
+
let size = 0;
|
|
533
|
+
startCount = this.groupEnd - first;
|
|
534
|
+
gapCount = 0;
|
|
535
|
+
for (let line = first; line <= this.groupEnd; line++) {
|
|
536
|
+
const slot = line % this.ringSize;
|
|
537
|
+
if (line < this.groupEnd) {
|
|
538
|
+
const gap = this.ringOmitted[slot] > 0 ? 1 : 0;
|
|
539
|
+
gapBefore[line - first] = gap;
|
|
540
|
+
gapCount += gap;
|
|
541
|
+
}
|
|
542
|
+
if (line > first)
|
|
543
|
+
fragmentStarts[line - first - 1] = size;
|
|
544
|
+
size += this.ring[slot].copy(logical, size, 0, this.ringLength[slot]);
|
|
545
|
+
}
|
|
546
|
+
return size;
|
|
547
|
+
}
|
|
548
|
+
splitGroup(logical, first, length) {
|
|
549
|
+
let from = 0;
|
|
550
|
+
for (let index = 0; index <= startCount; index++) {
|
|
551
|
+
const slot = (first + index) % this.ringSize;
|
|
552
|
+
let to = length;
|
|
553
|
+
if (index < startCount) {
|
|
554
|
+
to = fragmentStarts[index];
|
|
555
|
+
if (this.ringOmitted[slot] === 0)
|
|
556
|
+
to = characterBoundary(logical, to, from, length);
|
|
557
|
+
}
|
|
558
|
+
this.ringLength[slot] = logical.copy(this.ring[slot], 0, from, to);
|
|
559
|
+
if (index < clearedFragments)
|
|
560
|
+
this.ringOmitted[slot] = 0;
|
|
561
|
+
if (index < startCount)
|
|
562
|
+
fragmentStarts[index] = to;
|
|
563
|
+
from = to;
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
static fragmentOffset(text, index) {
|
|
567
|
+
if (index === 0)
|
|
568
|
+
return 0;
|
|
569
|
+
return index > startCount ? text.length : fragmentStarts[index - 1];
|
|
570
|
+
}
|
|
571
|
+
matchFragments(text, lo, hi) {
|
|
572
|
+
const matcher = this.matcher;
|
|
573
|
+
const end = LineGrepScanner.fragmentOffset(text, hi + 1);
|
|
574
|
+
let from = LineGrepScanner.fragmentOffset(text, lo);
|
|
575
|
+
if (gapCount === 0)
|
|
576
|
+
return matcher.match(text.subarray(from, end));
|
|
577
|
+
let found = NO_PATTERNS;
|
|
578
|
+
for (let index = lo; index <= hi; index++) {
|
|
579
|
+
const last = index === hi;
|
|
580
|
+
if (!last && gapBefore[index] === 0)
|
|
581
|
+
continue;
|
|
582
|
+
const to = last ? end : fragmentStarts[index];
|
|
583
|
+
if (last || to > from)
|
|
584
|
+
found = unionSorted(found, matcher.match(text.subarray(from, to)));
|
|
585
|
+
from = to;
|
|
586
|
+
}
|
|
587
|
+
return found;
|
|
588
|
+
}
|
|
589
|
+
closeGroup() {
|
|
590
|
+
if (!this.groupOpen)
|
|
591
|
+
return;
|
|
592
|
+
this.groupOpen = false;
|
|
593
|
+
const first = this.groupFirst;
|
|
594
|
+
let isMatch = false;
|
|
595
|
+
let hits = NO_PATTERNS;
|
|
596
|
+
if (this.sections)
|
|
597
|
+
this.applyMarkers(this.groupEnd);
|
|
598
|
+
const text = this.normalize
|
|
599
|
+
? this.renderGroup()
|
|
600
|
+
: this.ring[first % this.ringSize].subarray(0, this.ringLength[first % this.ringSize]);
|
|
601
|
+
let from = first;
|
|
602
|
+
let last = this.groupEnd;
|
|
603
|
+
if (this.searchesSection) {
|
|
604
|
+
const tracker = this.sections;
|
|
605
|
+
const end = tracker.targetEnd;
|
|
606
|
+
if (tracker.unresolved || (end !== null && end < first)) {
|
|
607
|
+
this.halt('section');
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (end !== null)
|
|
611
|
+
last = Math.min(last, end);
|
|
612
|
+
const start = tracker.targetStart;
|
|
613
|
+
from = start === null ? last + 1 : Math.max(first, start);
|
|
614
|
+
}
|
|
615
|
+
if (from > last)
|
|
616
|
+
return;
|
|
617
|
+
if (this.groupMatchable && from >= this.startLine) {
|
|
618
|
+
const found = this.normalize
|
|
619
|
+
? this.matchFragments(text, from - first, last - first)
|
|
620
|
+
: this.matcher.match(text);
|
|
621
|
+
isMatch = this.invert ? found.length === 0 : found.length > 0;
|
|
622
|
+
if (!this.invert)
|
|
623
|
+
hits = found;
|
|
624
|
+
}
|
|
625
|
+
const recorded = this.place(from, isMatch, hits);
|
|
626
|
+
for (let line = from + 1; line <= last && this.stop === null; line++) {
|
|
627
|
+
if (recorded)
|
|
628
|
+
this.emit(this.pending, line, from);
|
|
629
|
+
else
|
|
630
|
+
this.place(line, false, NO_PATTERNS);
|
|
631
|
+
}
|
|
632
|
+
if (recorded && this.stop === null)
|
|
633
|
+
this.afterRemaining = this.after;
|
|
634
|
+
if (this.searchesSection && this.sections?.targetEnd !== null)
|
|
635
|
+
this.halt('section');
|
|
636
|
+
}
|
|
637
|
+
place(number, isMatch, hits) {
|
|
638
|
+
if (isMatch) {
|
|
639
|
+
this.matchCount++;
|
|
640
|
+
if (!this.draining && this.recorded < this.maxMatches)
|
|
641
|
+
return this.record(number, hits);
|
|
642
|
+
}
|
|
643
|
+
if (this.pending === null)
|
|
644
|
+
return false;
|
|
645
|
+
if (this.afterRemaining > 0) {
|
|
646
|
+
if (!this.emit(this.pending, number, number))
|
|
647
|
+
return false;
|
|
648
|
+
if (--this.afterRemaining === 0 && this.draining)
|
|
649
|
+
this.halt('budget');
|
|
650
|
+
}
|
|
651
|
+
else if (number - this.lastEmitted > this.before) {
|
|
652
|
+
this.closePending();
|
|
653
|
+
}
|
|
654
|
+
return false;
|
|
655
|
+
}
|
|
656
|
+
record(number, hits) {
|
|
657
|
+
const floor = this.sections?.targetStart ?? 0;
|
|
658
|
+
const hunk = (this.pending ??= {
|
|
659
|
+
start_line: Math.max(this.lastEmitted + 1, number - this.before, floor),
|
|
660
|
+
lines: [],
|
|
661
|
+
matches: [],
|
|
662
|
+
});
|
|
663
|
+
let line = Math.max(this.lastEmitted + 1, hunk.start_line);
|
|
664
|
+
while (line <= number) {
|
|
665
|
+
if (!this.emit(hunk, line, number))
|
|
666
|
+
return false;
|
|
667
|
+
line = hunk.start_line + hunk.lines.length;
|
|
668
|
+
}
|
|
669
|
+
this.recorded++;
|
|
670
|
+
this.lastRecorded = number;
|
|
671
|
+
hunk.matches.push({ line: number, patterns: hits });
|
|
672
|
+
this.afterRemaining = this.after;
|
|
673
|
+
return true;
|
|
674
|
+
}
|
|
675
|
+
emit(hunk, number, matchLine) {
|
|
676
|
+
const slot = number % this.ringSize;
|
|
677
|
+
const omitted = this.ringOmitted[slot];
|
|
678
|
+
const decoded = (0, trace_1.decodeFragment)(this.ring[slot].subarray(0, this.ringLength[slot]), false, omitted > 0, this.decoder);
|
|
679
|
+
const size = Buffer.byteLength(decoded.text);
|
|
680
|
+
if (this.outputBytes > 0 && this.outputBytes + size > this.outputLimit) {
|
|
681
|
+
if (this.closedHunks === 0 && hunk.matches.length === 0) {
|
|
682
|
+
this.restartAtMatch(hunk, matchLine);
|
|
683
|
+
return this.emit(hunk, matchLine, matchLine);
|
|
684
|
+
}
|
|
685
|
+
this.stopForOutput(matchLine);
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
this.outputBytes += size;
|
|
689
|
+
hunk.lines.push(decoded.text);
|
|
690
|
+
if (this.ringHasStamp[slot]) {
|
|
691
|
+
hunk.timestamps ??= new Array(hunk.lines.length - 1).fill(null);
|
|
692
|
+
const at = slot * section_markers_1.TIMESTAMP_BYTES;
|
|
693
|
+
hunk.timestamps.push(this.ringStamp.toString('latin1', at, at + section_markers_1.TIMESTAMP_BYTES));
|
|
694
|
+
}
|
|
695
|
+
else {
|
|
696
|
+
hunk.timestamps?.push(null);
|
|
697
|
+
}
|
|
698
|
+
const lost = omitted + decoded.skippedSuffix;
|
|
699
|
+
if (lost > 0) {
|
|
700
|
+
hunk.clipped ??= [];
|
|
701
|
+
hunk.clipped.push({ line: number, omitted_bytes: lost });
|
|
702
|
+
}
|
|
703
|
+
this.lastEmitted = number;
|
|
704
|
+
return true;
|
|
705
|
+
}
|
|
706
|
+
restartAtMatch(hunk, matchLine) {
|
|
707
|
+
this.outputBytes = 0;
|
|
708
|
+
hunk.start_line = matchLine;
|
|
709
|
+
hunk.lines.length = 0;
|
|
710
|
+
delete hunk.timestamps;
|
|
711
|
+
delete hunk.clipped;
|
|
712
|
+
this.lastEmitted = matchLine - 1;
|
|
713
|
+
}
|
|
714
|
+
stopForOutput(matchLine) {
|
|
715
|
+
const hunk = this.pending;
|
|
716
|
+
if (this.closedHunks > 0 || hunk.matches.length === 0) {
|
|
717
|
+
this.outputResume = hunk.matches.length > 0 ? hunk.matches[0].line : matchLine;
|
|
718
|
+
this.pending = null;
|
|
719
|
+
}
|
|
720
|
+
else {
|
|
721
|
+
this.outputResume =
|
|
722
|
+
this.matchCount > this.recorded ? this.lastRecorded + 1 : this.lastEmitted + 1;
|
|
723
|
+
this.closePending();
|
|
724
|
+
}
|
|
725
|
+
this.groupOpen = false;
|
|
726
|
+
this.halt('output');
|
|
727
|
+
}
|
|
728
|
+
closePending() {
|
|
729
|
+
if (this.pending === null)
|
|
730
|
+
return;
|
|
731
|
+
this.outbox.push(this.pending);
|
|
732
|
+
this.closedHunks++;
|
|
733
|
+
this.pending = null;
|
|
734
|
+
this.afterRemaining = 0;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
exports.LineGrepScanner = LineGrepScanner;
|
|
738
|
+
function serveLineGrep(port) {
|
|
739
|
+
let scanner = null;
|
|
740
|
+
const active = () => {
|
|
741
|
+
if (!scanner)
|
|
742
|
+
throw new Error('Log search received data before start');
|
|
743
|
+
return scanner;
|
|
744
|
+
};
|
|
745
|
+
port.on('message', (request) => {
|
|
746
|
+
try {
|
|
747
|
+
switch (request.type) {
|
|
748
|
+
case 'start':
|
|
749
|
+
scanner = null;
|
|
750
|
+
scanner = new LineGrepScanner(request.options);
|
|
751
|
+
port.postMessage({ type: 'ready' });
|
|
752
|
+
return;
|
|
753
|
+
case 'chunk': {
|
|
754
|
+
const current = active();
|
|
755
|
+
current.push(new Uint8Array(request.buffer, request.offset, request.length));
|
|
756
|
+
const reply = {
|
|
757
|
+
type: 'progress',
|
|
758
|
+
progress: current.progress(),
|
|
759
|
+
buffer: request.buffer,
|
|
760
|
+
};
|
|
761
|
+
port.postMessage(reply, [request.buffer]);
|
|
762
|
+
return;
|
|
763
|
+
}
|
|
764
|
+
case 'end': {
|
|
765
|
+
const current = active();
|
|
766
|
+
scanner = null;
|
|
767
|
+
port.postMessage({ type: 'done', result: current.finish() });
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
case 'reset':
|
|
771
|
+
scanner = null;
|
|
772
|
+
port.postMessage({ type: 'ready' });
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
catch (error) {
|
|
777
|
+
scanner = null;
|
|
778
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
779
|
+
port.postMessage((error instanceof re2_pattern_1.PatternError
|
|
780
|
+
? { type: 'invalid', message }
|
|
781
|
+
: { type: 'failed', message }));
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
//# sourceMappingURL=line-grep.js.map
|