@dev-anywhere/proxy 0.9.13 → 0.9.15

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.
@@ -0,0 +1,2221 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/common/pty-idle-checker.ts
4
+ function createIdleChecker(options) {
5
+ let timer = null;
6
+ const tick = () => {
7
+ const last = options.getLastOutputTime();
8
+ if (last <= 0) return;
9
+ if (Date.now() - last <= options.thresholdMs) return;
10
+ options.setLastOutputTime(0);
11
+ if (options.getCurrentState() !== "working") return;
12
+ options.onIdle();
13
+ };
14
+ return {
15
+ start() {
16
+ if (timer) clearInterval(timer);
17
+ timer = setInterval(tick, options.intervalMs);
18
+ },
19
+ stop() {
20
+ if (timer) {
21
+ clearInterval(timer);
22
+ timer = null;
23
+ }
24
+ }
25
+ };
26
+ }
27
+
28
+ // src/common/reconnect-supervisor.ts
29
+ import { setTimeout as sleep } from "timers/promises";
30
+ var ReconnectSupervisor = class {
31
+ constructor(options) {
32
+ this.options = options;
33
+ if (options.initialDelayMs <= 0 || options.maxDelayMs < options.initialDelayMs) {
34
+ throw new TypeError("Invalid reconnect backoff");
35
+ }
36
+ this.wait = options.wait ?? sleep;
37
+ }
38
+ options;
39
+ active = null;
40
+ wait;
41
+ request(request) {
42
+ if (this.active) {
43
+ return { started: false, completion: this.active };
44
+ }
45
+ const completion = this.run(request);
46
+ this.active = completion;
47
+ const clear = () => {
48
+ if (this.active === completion) this.active = null;
49
+ };
50
+ void completion.then(clear, clear);
51
+ return { started: true, completion };
52
+ }
53
+ async run(request) {
54
+ for (let attempt = 1; ; attempt += 1) {
55
+ if (request.shouldStop()) return;
56
+ const delayMs = Math.min(this.options.initialDelayMs * attempt, this.options.maxDelayMs);
57
+ await this.wait(delayMs);
58
+ if (request.shouldStop()) return;
59
+ const result = await request.attempt(attempt);
60
+ if (result !== "retry") return;
61
+ }
62
+ }
63
+ };
64
+
65
+ // src/common/osc-extractor.ts
66
+ import { posix, win32 } from "path";
67
+ import { fileURLToPath } from "url";
68
+ var OSC_PATTERN = /\x1b\](\d+);([^\x07\x1b]*?)(?:\x07|\x1b\\)/g;
69
+ var SEMANTIC_TEXT_TAIL_MAX = 4096;
70
+ var OSC_SEQUENCE_PATTERN = /\x1b\](?:\d+);[^\x07\x1b]*?(?:\x07|\x1b\\)/g;
71
+ var CSI_SEQUENCE_PATTERN = /\x1b\[[0-?]*[ -/]*[@-~]/g;
72
+ var SIMPLE_ESC_PATTERN = /\x1b[@-Z\\-_]/g;
73
+ function extractOscSequences(rawData) {
74
+ const regex = new RegExp(OSC_PATTERN.source, OSC_PATTERN.flags);
75
+ const matches = [];
76
+ let match;
77
+ while ((match = regex.exec(rawData)) !== null) {
78
+ matches.push({ code: parseInt(match[1], 10), text: match[2] });
79
+ }
80
+ return matches;
81
+ }
82
+ function lastSequence(matches, code) {
83
+ for (let i = matches.length - 1; i >= 0; i -= 1) {
84
+ if (matches[i].code === code) return matches[i];
85
+ }
86
+ return void 0;
87
+ }
88
+ function extractOscWorkingDirectory(rawData, platform = process.platform) {
89
+ const sequences = extractOscSequences(rawData);
90
+ for (let index = sequences.length - 1; index >= 0; index--) {
91
+ const sequence = sequences[index];
92
+ if (sequence.code === 9 && sequence.text.startsWith("9;")) {
93
+ const path = sequence.text.slice(2).replace(/^"(.*)"$/, "$1");
94
+ if (/[\0\r\n]/.test(path)) return null;
95
+ return (platform === "win32" ? win32 : posix).isAbsolute(path) ? path : null;
96
+ }
97
+ if (sequence.code !== 7) continue;
98
+ try {
99
+ const uri = new URL(sequence.text);
100
+ if (uri.protocol !== "file:") return null;
101
+ if (platform !== "win32" || /^\/[a-z]:\//i.test(uri.pathname)) uri.hostname = "";
102
+ const path = fileURLToPath(uri, { windows: platform === "win32" });
103
+ return /[\0\r\n]/.test(path) ? null : path;
104
+ } catch {
105
+ return null;
106
+ }
107
+ }
108
+ return null;
109
+ }
110
+ var OscWorkingDirectoryTracker = class {
111
+ constructor(platform = process.platform) {
112
+ this.platform = platform;
113
+ }
114
+ platform;
115
+ pending = "";
116
+ push(data) {
117
+ const combined = this.pending + data;
118
+ const cwd = extractOscWorkingDirectory(combined, this.platform);
119
+ const start = combined.lastIndexOf("\x1B]");
120
+ const tail = start < 0 ? "" : combined.slice(start);
121
+ this.pending = tail && !tail.includes("\x07") && !tail.includes("\x1B\\") && tail.length <= 64 * 1024 ? tail : combined.endsWith("\x1B") ? "\x1B" : "";
122
+ return cwd;
123
+ }
124
+ };
125
+ function normalizePtySemanticText(rawData) {
126
+ return rawData.replace(OSC_SEQUENCE_PATTERN, " ").replace(CSI_SEQUENCE_PATTERN, " ").replace(SIMPLE_ESC_PATTERN, " ").replace(/\r/g, "\n").replace(/[^\S\n]+/g, " ").replace(/\n+/g, "\n").trim();
127
+ }
128
+ function appendPtySemanticTextTail(previous, chunk) {
129
+ const next = `${previous}
130
+ ${normalizePtySemanticText(chunk)}`.slice(-SEMANTIC_TEXT_TAIL_MAX);
131
+ return next.trim();
132
+ }
133
+ function extractClaudeTextSignal(text) {
134
+ const toolMatch = text.match(/\bHook\s+PreToolUse:([A-Za-z0-9_.:-]+)/i);
135
+ if (toolMatch?.[1] && /\brequires confirmation for this (?:command|tool)\b/i.test(text) && /\bDo you want to proceed\?/i.test(text)) {
136
+ return {
137
+ state: "approval_wait",
138
+ tool: toolMatch[1],
139
+ title: `Hook confirmation: ${toolMatch[1]}`
140
+ };
141
+ }
142
+ const nativePermissionMatch = text.match(
143
+ /\bDo you want to (?<action>make this edit to|create|update|delete|run|execute)\b[^\n?]*\?/i
144
+ );
145
+ if (nativePermissionMatch?.groups?.action && /\b1\.\s*Yes\b/i.test(text) && /\b3\.\s*No\b/i.test(text)) {
146
+ const action = nativePermissionMatch.groups.action.toLowerCase();
147
+ const tool = action === "run" || action === "execute" ? "Bash" : "Edit";
148
+ return {
149
+ state: "approval_wait",
150
+ tool,
151
+ title: `Claude permission: ${tool}`
152
+ };
153
+ }
154
+ return null;
155
+ }
156
+ function extractTextSignals(semanticText, provider) {
157
+ if (provider === "claude") {
158
+ return extractClaudeTextSignal(semanticText);
159
+ }
160
+ return null;
161
+ }
162
+ function extractOscSignals(rawData, _provider) {
163
+ const matches = extractOscSequences(rawData);
164
+ if (matches.length === 0) return null;
165
+ const osc0 = lastSequence(matches, 0);
166
+ const osc9 = lastSequence(matches, 9);
167
+ if (osc9) {
168
+ if (osc9.text.includes("waiting for your input") || osc9.text.trim() === "4;0;") {
169
+ return { state: "turn_complete", ...osc0 ? { title: osc0.text } : {} };
170
+ }
171
+ if (osc9.text.includes("needs your permission")) {
172
+ const toolMatch = osc9.text.match(/permission.*?:\s*(\S+)/);
173
+ return {
174
+ state: "approval_wait",
175
+ ...osc0 ? { title: osc0.text } : {},
176
+ ...toolMatch?.[1] ? { tool: toolMatch[1] } : {}
177
+ };
178
+ }
179
+ }
180
+ if (osc0 && !osc9) {
181
+ return { state: null, title: osc0.text };
182
+ }
183
+ return null;
184
+ }
185
+
186
+ // src/common/pty-approval-state.ts
187
+ function shouldReleaseApprovalWait(options) {
188
+ if (options.currentState !== "approval_wait") return false;
189
+ if (options.signalState === void 0) return false;
190
+ if (options.signalState === null && options.allowTitleOnlyRelease === false) return false;
191
+ return options.signalState !== "approval_wait";
192
+ }
193
+ function stateAfterApprovalRelease(signalState) {
194
+ if (signalState === null) return "turn_complete";
195
+ return signalState !== "approval_wait" ? signalState : "working";
196
+ }
197
+ function shouldReleaseTextApprovalOnInput(data) {
198
+ if (data.includes("\r") || data.includes("\n")) return true;
199
+ return data === "1" || data === "2" || data === "y" || data === "Y" || data === "n" || data === "N" || data === "\x1B" || data === "";
200
+ }
201
+
202
+ // src/common/pty-semantic-machine.ts
203
+ function withMeta(signal) {
204
+ return {
205
+ ...signal?.title !== void 0 ? { title: signal.title } : {},
206
+ ...signal?.tool !== void 0 ? { tool: signal.tool } : {}
207
+ };
208
+ }
209
+ function decidePtySemanticTransition(input) {
210
+ const {
211
+ currentState,
212
+ signal,
213
+ sessionStateIsWaitingApproval,
214
+ allowTitleOnlyApprovalRelease = true
215
+ } = input;
216
+ if (signal?.state === "approval_wait") {
217
+ return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
218
+ }
219
+ if (shouldReleaseApprovalWait({
220
+ currentState,
221
+ signalState: signal === null ? void 0 : signal.state,
222
+ allowTitleOnlyRelease: allowTitleOnlyApprovalRelease
223
+ })) {
224
+ return {
225
+ nextState: stateAfterApprovalRelease(signal.state),
226
+ emit: true,
227
+ meta: withMeta(signal)
228
+ };
229
+ }
230
+ const inApprovalContext = currentState === "approval_wait" || sessionStateIsWaitingApproval === true;
231
+ if (inApprovalContext && signal?.state !== "turn_complete") {
232
+ if (currentState === "approval_wait") {
233
+ return { nextState: "approval_wait", emit: false };
234
+ }
235
+ return { nextState: "approval_wait", emit: true, meta: withMeta(signal) };
236
+ }
237
+ if (signal !== null && signal.state === null) {
238
+ return { nextState: currentState, emit: false };
239
+ }
240
+ if (signal && signal.state !== null && signal.state !== "working") {
241
+ return { nextState: signal.state, emit: true, meta: withMeta(signal) };
242
+ }
243
+ if (currentState !== "working" && signal?.state === "working") {
244
+ return { nextState: "working", emit: true };
245
+ }
246
+ return { nextState: currentState, emit: false };
247
+ }
248
+ function shouldStartPtyTurnOnInput(currentState, data) {
249
+ return currentState === "turn_complete" && (data.includes("\r") || data.includes("\n"));
250
+ }
251
+
252
+ // src/common/pty-render-sequencer.ts
253
+ import pkg from "@xterm/headless";
254
+ import { SerializeAddon } from "@xterm/addon-serialize";
255
+
256
+ // ../../node_modules/.pnpm/@xterm+addon-unicode-graphemes@0.4.0_patch_hash=ii5qcsnajlhye26zd4cjwwjuxu/node_modules/@xterm/addon-unicode-graphemes/lib/addon-unicode-graphemes.mjs
257
+ var be = [[768, 879], [1155, 1158], [1160, 1161], [1425, 1469], [1471, 1471], [1473, 1474], [1476, 1477], [1479, 1479], [1536, 1539], [1552, 1557], [1611, 1630], [1648, 1648], [1750, 1764], [1767, 1768], [1770, 1773], [1807, 1807], [1809, 1809], [1840, 1866], [1958, 1968], [2027, 2035], [2305, 2306], [2364, 2364], [2369, 2376], [2381, 2381], [2385, 2388], [2402, 2403], [2433, 2433], [2492, 2492], [2497, 2500], [2509, 2509], [2530, 2531], [2561, 2562], [2620, 2620], [2625, 2626], [2631, 2632], [2635, 2637], [2672, 2673], [2689, 2690], [2748, 2748], [2753, 2757], [2759, 2760], [2765, 2765], [2786, 2787], [2817, 2817], [2876, 2876], [2879, 2879], [2881, 2883], [2893, 2893], [2902, 2902], [2946, 2946], [3008, 3008], [3021, 3021], [3134, 3136], [3142, 3144], [3146, 3149], [3157, 3158], [3260, 3260], [3263, 3263], [3270, 3270], [3276, 3277], [3298, 3299], [3393, 3395], [3405, 3405], [3530, 3530], [3538, 3540], [3542, 3542], [3633, 3633], [3636, 3642], [3655, 3662], [3761, 3761], [3764, 3769], [3771, 3772], [3784, 3789], [3864, 3865], [3893, 3893], [3895, 3895], [3897, 3897], [3953, 3966], [3968, 3972], [3974, 3975], [3984, 3991], [3993, 4028], [4038, 4038], [4141, 4144], [4146, 4146], [4150, 4151], [4153, 4153], [4184, 4185], [4448, 4607], [4959, 4959], [5906, 5908], [5938, 5940], [5970, 5971], [6002, 6003], [6068, 6069], [6071, 6077], [6086, 6086], [6089, 6099], [6109, 6109], [6155, 6157], [6313, 6313], [6432, 6434], [6439, 6440], [6450, 6450], [6457, 6459], [6679, 6680], [6912, 6915], [6964, 6964], [6966, 6970], [6972, 6972], [6978, 6978], [7019, 7027], [7616, 7626], [7678, 7679], [8203, 8207], [8234, 8238], [8288, 8291], [8298, 8303], [8400, 8431], [12330, 12335], [12441, 12442], [43014, 43014], [43019, 43019], [43045, 43046], [64286, 64286], [65024, 65039], [65056, 65059], [65279, 65279], [65529, 65531]];
258
+ var Lt = [[68097, 68099], [68101, 68102], [68108, 68111], [68152, 68154], [68159, 68159], [119143, 119145], [119155, 119170], [119173, 119179], [119210, 119213], [119362, 119364], [917505, 917505], [917536, 917631], [917760, 917999]];
259
+ var y;
260
+ function Ft(n5, e) {
261
+ let t = 0, r = e.length - 1, i;
262
+ if (n5 < e[0][0] || n5 > e[r][1]) return false;
263
+ for (; r >= t; ) if (i = t + r >> 1, n5 > e[i][1]) t = i + 1;
264
+ else if (n5 < e[i][0]) r = i - 1;
265
+ else return true;
266
+ return false;
267
+ }
268
+ var J = class {
269
+ constructor() {
270
+ this.version = "6";
271
+ if (!y) {
272
+ y = new Uint8Array(65536), y.fill(1), y[0] = 0, y.fill(0, 1, 32), y.fill(0, 127, 160), y.fill(2, 4352, 4448), y[9001] = 2, y[9002] = 2, y.fill(2, 11904, 42192), y[12351] = 1, y.fill(2, 44032, 55204), y.fill(2, 63744, 64256), y.fill(2, 65040, 65050), y.fill(2, 65072, 65136), y.fill(2, 65280, 65377), y.fill(2, 65504, 65511);
273
+ for (let e = 0; e < be.length; ++e) y.fill(0, be[e][0], be[e][1] + 1);
274
+ }
275
+ }
276
+ wcwidth(e) {
277
+ return e < 32 ? 0 : e < 127 ? 1 : e < 65536 ? y[e] : Ft(e, Lt) ? 0 : e >= 131072 && e <= 196605 || e >= 196608 && e <= 262141 ? 2 : 1;
278
+ }
279
+ charProperties(e, t) {
280
+ let r = this.wcwidth(e), i = r === 0 && t !== 0;
281
+ if (i) {
282
+ let o = w.extractWidth(t);
283
+ o === 0 ? i = false : o > r && (r = o);
284
+ }
285
+ return w.createPropertyValue(0, r, i);
286
+ }
287
+ };
288
+ var ve = class {
289
+ constructor() {
290
+ this.listeners = [], this.unexpectedErrorHandler = function(e) {
291
+ setTimeout(() => {
292
+ throw e.stack ? ee.isErrorNoTelemetry(e) ? new ee(e.message + `
293
+
294
+ ` + e.stack) : new Error(e.message + `
295
+
296
+ ` + e.stack) : e;
297
+ }, 0);
298
+ };
299
+ }
300
+ addListener(e) {
301
+ return this.listeners.push(e), () => {
302
+ this._removeListener(e);
303
+ };
304
+ }
305
+ emit(e) {
306
+ this.listeners.forEach((t) => {
307
+ t(e);
308
+ });
309
+ }
310
+ _removeListener(e) {
311
+ this.listeners.splice(this.listeners.indexOf(e), 1);
312
+ }
313
+ setUnexpectedErrorHandler(e) {
314
+ this.unexpectedErrorHandler = e;
315
+ }
316
+ getUnexpectedErrorHandler() {
317
+ return this.unexpectedErrorHandler;
318
+ }
319
+ onUnexpectedError(e) {
320
+ this.unexpectedErrorHandler(e), this.emit(e);
321
+ }
322
+ onUnexpectedExternalError(e) {
323
+ this.unexpectedErrorHandler(e);
324
+ }
325
+ };
326
+ var St = new ve();
327
+ function te(n5) {
328
+ Ut(n5) || St.onUnexpectedError(n5);
329
+ }
330
+ var me = "Canceled";
331
+ function Ut(n5) {
332
+ return n5 instanceof $ ? true : n5 instanceof Error && n5.name === me && n5.message === me;
333
+ }
334
+ var $ = class extends Error {
335
+ constructor() {
336
+ super(me), this.name = this.message;
337
+ }
338
+ };
339
+ var ee = class n extends Error {
340
+ constructor(e) {
341
+ super(e), this.name = "CodeExpectedError";
342
+ }
343
+ static fromError(e) {
344
+ if (e instanceof n) return e;
345
+ let t = new n();
346
+ return t.message = e.message, t.stack = e.stack, t;
347
+ }
348
+ static isErrorNoTelemetry(e) {
349
+ return e.name === "CodeExpectedError";
350
+ }
351
+ };
352
+ function ge(n5, e) {
353
+ let t = this, r = false, i;
354
+ return function() {
355
+ if (r) return i;
356
+ if (r = true, e) try {
357
+ i = n5.apply(t, arguments);
358
+ } finally {
359
+ e();
360
+ }
361
+ else i = n5.apply(t, arguments);
362
+ return i;
363
+ };
364
+ }
365
+ function Ot(n5, e, t = 0, r = n5.length) {
366
+ let i = t, o = r;
367
+ for (; i < o; ) {
368
+ let f = Math.floor((i + o) / 2);
369
+ e(n5[f]) ? i = f + 1 : o = f;
370
+ }
371
+ return i - 1;
372
+ }
373
+ var ne = class ne2 {
374
+ constructor(e) {
375
+ this._array = e;
376
+ this._findLastMonotonousLastIdx = 0;
377
+ }
378
+ findLastMonotonous(e) {
379
+ if (ne2.assertInvariants) {
380
+ if (this._prevFindLastPredicate) {
381
+ for (let r of this._array) if (this._prevFindLastPredicate(r) && !e(r)) throw new Error("MonotonousArray: current predicate must be weaker than (or equal to) the previous predicate.");
382
+ }
383
+ this._prevFindLastPredicate = e;
384
+ }
385
+ let t = Ot(this._array, e, this._findLastMonotonousLastIdx);
386
+ return this._findLastMonotonousLastIdx = t + 1, t === -1 ? void 0 : this._array[t];
387
+ }
388
+ };
389
+ ne.assertInvariants = false;
390
+ var $e;
391
+ ((T) => {
392
+ function n5(p) {
393
+ return p < 0;
394
+ }
395
+ T.isLessThan = n5;
396
+ function e(p) {
397
+ return p <= 0;
398
+ }
399
+ T.isLessThanOrEqual = e;
400
+ function t(p) {
401
+ return p > 0;
402
+ }
403
+ T.isGreaterThan = t;
404
+ function r(p) {
405
+ return p === 0;
406
+ }
407
+ T.isNeitherLessOrGreaterThan = r, T.greaterThan = 1, T.lessThan = -1, T.neitherLessOrGreaterThan = 0;
408
+ })($e ||= {});
409
+ function et(n5, e) {
410
+ return (t, r) => e(n5(t), n5(r));
411
+ }
412
+ var tt = (n5, e) => n5 - e;
413
+ var M = class M2 {
414
+ constructor(e) {
415
+ this.iterate = e;
416
+ }
417
+ forEach(e) {
418
+ this.iterate((t) => (e(t), true));
419
+ }
420
+ toArray() {
421
+ let e = [];
422
+ return this.iterate((t) => (e.push(t), true)), e;
423
+ }
424
+ filter(e) {
425
+ return new M2((t) => this.iterate((r) => e(r) ? t(r) : true));
426
+ }
427
+ map(e) {
428
+ return new M2((t) => this.iterate((r) => t(e(r))));
429
+ }
430
+ some(e) {
431
+ let t = false;
432
+ return this.iterate((r) => (t = e(r), !t)), t;
433
+ }
434
+ findFirst(e) {
435
+ let t;
436
+ return this.iterate((r) => e(r) ? (t = r, false) : true), t;
437
+ }
438
+ findLast(e) {
439
+ let t;
440
+ return this.iterate((r) => (e(r) && (t = r), true)), t;
441
+ }
442
+ findLastMaxBy(e) {
443
+ let t, r = true;
444
+ return this.iterate((i) => ((r || $e.isGreaterThan(e(i, t))) && (r = false, t = i), true)), t;
445
+ }
446
+ };
447
+ M.empty = new M((e) => {
448
+ });
449
+ function st(n5, e) {
450
+ let t = /* @__PURE__ */ Object.create(null);
451
+ for (let r of n5) {
452
+ let i = e(r), o = t[i];
453
+ o || (o = t[i] = []), o.push(r);
454
+ }
455
+ return t;
456
+ }
457
+ var rt;
458
+ var it;
459
+ var nt = class {
460
+ constructor(e, t) {
461
+ this.toKey = t;
462
+ this._map = /* @__PURE__ */ new Map();
463
+ this[rt] = "SetWithKey";
464
+ for (let r of e) this.add(r);
465
+ }
466
+ get size() {
467
+ return this._map.size;
468
+ }
469
+ add(e) {
470
+ let t = this.toKey(e);
471
+ return this._map.set(t, e), this;
472
+ }
473
+ delete(e) {
474
+ return this._map.delete(this.toKey(e));
475
+ }
476
+ has(e) {
477
+ return this._map.has(this.toKey(e));
478
+ }
479
+ *entries() {
480
+ for (let e of this._map.values()) yield [e, e];
481
+ }
482
+ keys() {
483
+ return this.values();
484
+ }
485
+ *values() {
486
+ for (let e of this._map.values()) yield e;
487
+ }
488
+ clear() {
489
+ this._map.clear();
490
+ }
491
+ forEach(e, t) {
492
+ this._map.forEach((r) => e.call(t, r, r, this));
493
+ }
494
+ [(it = Symbol.iterator, rt = Symbol.toStringTag, it)]() {
495
+ return this.values();
496
+ }
497
+ };
498
+ var re = class {
499
+ constructor() {
500
+ this.map = /* @__PURE__ */ new Map();
501
+ }
502
+ add(e, t) {
503
+ let r = this.map.get(e);
504
+ r || (r = /* @__PURE__ */ new Set(), this.map.set(e, r)), r.add(t);
505
+ }
506
+ delete(e, t) {
507
+ let r = this.map.get(e);
508
+ r && (r.delete(t), r.size === 0 && this.map.delete(e));
509
+ }
510
+ forEach(e, t) {
511
+ let r = this.map.get(e);
512
+ r && r.forEach(t);
513
+ }
514
+ get(e) {
515
+ let t = this.map.get(e);
516
+ return t || /* @__PURE__ */ new Set();
517
+ }
518
+ };
519
+ var _e;
520
+ ((Te) => {
521
+ function n5(c) {
522
+ return c && typeof c == "object" && typeof c[Symbol.iterator] == "function";
523
+ }
524
+ Te.is = n5;
525
+ let e = Object.freeze([]);
526
+ function t() {
527
+ return e;
528
+ }
529
+ Te.empty = t;
530
+ function* r(c) {
531
+ yield c;
532
+ }
533
+ Te.single = r;
534
+ function i(c) {
535
+ return n5(c) ? c : r(c);
536
+ }
537
+ Te.wrap = i;
538
+ function o(c) {
539
+ return c || e;
540
+ }
541
+ Te.from = o;
542
+ function* f(c) {
543
+ for (let b = c.length - 1; b >= 0; b--) yield c[b];
544
+ }
545
+ Te.reverse = f;
546
+ function T(c) {
547
+ return !c || c[Symbol.iterator]().next().done === true;
548
+ }
549
+ Te.isEmpty = T;
550
+ function p(c) {
551
+ return c[Symbol.iterator]().next().value;
552
+ }
553
+ Te.first = p;
554
+ function m(c, b) {
555
+ let g = 0;
556
+ for (let D of c) if (b(D, g++)) return true;
557
+ return false;
558
+ }
559
+ Te.some = m;
560
+ function _(c, b) {
561
+ for (let g of c) if (b(g)) return g;
562
+ }
563
+ Te.find = _;
564
+ function* x(c, b) {
565
+ for (let g of c) b(g) && (yield g);
566
+ }
567
+ Te.filter = x;
568
+ function* L(c, b) {
569
+ let g = 0;
570
+ for (let D of c) yield b(D, g++);
571
+ }
572
+ Te.map = L;
573
+ function* O(c, b) {
574
+ let g = 0;
575
+ for (let D of c) yield* b(D, g++);
576
+ }
577
+ Te.flatMap = O;
578
+ function* pe(...c) {
579
+ for (let b of c) yield* b;
580
+ }
581
+ Te.concat = pe;
582
+ function X(c, b, g) {
583
+ let D = g;
584
+ for (let z of c) D = b(D, z);
585
+ return D;
586
+ }
587
+ Te.reduce = X;
588
+ function* F(c, b, g = c.length) {
589
+ for (b < 0 && (b += c.length), g < 0 ? g += c.length : g > c.length && (g = c.length); b < g; b++) yield c[b];
590
+ }
591
+ Te.slice = F;
592
+ function he(c, b = Number.POSITIVE_INFINITY) {
593
+ let g = [];
594
+ if (b === 0) return [g, c];
595
+ let D = c[Symbol.iterator]();
596
+ for (let z = 0; z < b; z++) {
597
+ let xe = D.next();
598
+ if (xe.done) return [g, Te.empty()];
599
+ g.push(xe.value);
600
+ }
601
+ return [g, { [Symbol.iterator]() {
602
+ return D;
603
+ } }];
604
+ }
605
+ Te.consume = he;
606
+ async function K(c) {
607
+ let b = [];
608
+ for await (let g of c) b.push(g);
609
+ return Promise.resolve(b);
610
+ }
611
+ Te.asyncToArray = K;
612
+ })(_e ||= {});
613
+ var Pt = false;
614
+ var B = null;
615
+ var ie = class ie2 {
616
+ constructor() {
617
+ this.livingDisposables = /* @__PURE__ */ new Map();
618
+ }
619
+ getDisposableData(e) {
620
+ let t = this.livingDisposables.get(e);
621
+ return t || (t = { parent: null, source: null, isSingleton: false, value: e, idx: ie2.idx++ }, this.livingDisposables.set(e, t)), t;
622
+ }
623
+ trackDisposable(e) {
624
+ let t = this.getDisposableData(e);
625
+ t.source || (t.source = new Error().stack);
626
+ }
627
+ setParent(e, t) {
628
+ let r = this.getDisposableData(e);
629
+ r.parent = t;
630
+ }
631
+ markAsDisposed(e) {
632
+ this.livingDisposables.delete(e);
633
+ }
634
+ markAsSingleton(e) {
635
+ this.getDisposableData(e).isSingleton = true;
636
+ }
637
+ getRootParent(e, t) {
638
+ let r = t.get(e);
639
+ if (r) return r;
640
+ let i = e.parent ? this.getRootParent(this.getDisposableData(e.parent), t) : e;
641
+ return t.set(e, i), i;
642
+ }
643
+ getTrackedDisposables() {
644
+ let e = /* @__PURE__ */ new Map();
645
+ return [...this.livingDisposables.entries()].filter(([, r]) => r.source !== null && !this.getRootParent(r, e).isSingleton).flatMap(([r]) => r);
646
+ }
647
+ computeLeakingDisposables(e = 10, t) {
648
+ let r;
649
+ if (t) r = t;
650
+ else {
651
+ let p = /* @__PURE__ */ new Map(), m = [...this.livingDisposables.values()].filter((x) => x.source !== null && !this.getRootParent(x, p).isSingleton);
652
+ if (m.length === 0) return;
653
+ let _ = new Set(m.map((x) => x.value));
654
+ if (r = m.filter((x) => !(x.parent && _.has(x.parent))), r.length === 0) throw new Error("There are cyclic diposable chains!");
655
+ }
656
+ if (!r) return;
657
+ function i(p) {
658
+ function m(x, L) {
659
+ for (; x.length > 0 && L.some((O) => typeof O == "string" ? O === x[0] : x[0].match(O)); ) x.shift();
660
+ }
661
+ let _ = p.source.split(`
662
+ `).map((x) => x.trim().replace("at ", "")).filter((x) => x !== "");
663
+ return m(_, ["Error", /^trackDisposable \(.*\)$/, /^DisposableTracker.trackDisposable \(.*\)$/]), _.reverse();
664
+ }
665
+ let o = new re();
666
+ for (let p of r) {
667
+ let m = i(p);
668
+ for (let _ = 0; _ <= m.length; _++) o.add(m.slice(0, _).join(`
669
+ `), p);
670
+ }
671
+ r.sort(et((p) => p.idx, tt));
672
+ let f = "", T = 0;
673
+ for (let p of r.slice(0, e)) {
674
+ T++;
675
+ let m = i(p), _ = [];
676
+ for (let x = 0; x < m.length; x++) {
677
+ let L = m[x];
678
+ L = `(shared with ${o.get(m.slice(0, x + 1).join(`
679
+ `)).size}/${r.length} leaks) at ${L}`;
680
+ let pe = o.get(m.slice(0, x).join(`
681
+ `)), X = st([...pe].map((F) => i(F)[x]), (F) => F);
682
+ delete X[m[x]];
683
+ for (let [F, he] of Object.entries(X)) _.unshift(` - stacktraces of ${he.length} other leaks continue with ${F}`);
684
+ _.unshift(L);
685
+ }
686
+ f += `
687
+
688
+
689
+ ==================== Leaking disposable ${T}/${r.length}: ${p.value.constructor.name} ====================
690
+ ${_.join(`
691
+ `)}
692
+ ============================================================
693
+
694
+ `;
695
+ }
696
+ return r.length > e && (f += `
697
+
698
+
699
+ ... and ${r.length - e} more leaking disposables
700
+
701
+ `), { leaks: r, details: f };
702
+ }
703
+ };
704
+ ie.idx = 0;
705
+ function Mt(n5) {
706
+ B = n5;
707
+ }
708
+ if (Pt) {
709
+ let n5 = "__is_disposable_tracked__";
710
+ Mt(new class {
711
+ trackDisposable(e) {
712
+ let t = new Error("Potentially leaked disposable").stack;
713
+ setTimeout(() => {
714
+ e[n5] || console.log(t);
715
+ }, 3e3);
716
+ }
717
+ setParent(e, t) {
718
+ if (e && e !== k.None) try {
719
+ e[n5] = true;
720
+ } catch {
721
+ }
722
+ }
723
+ markAsDisposed(e) {
724
+ if (e && e !== k.None) try {
725
+ e[n5] = true;
726
+ } catch {
727
+ }
728
+ }
729
+ markAsSingleton(e) {
730
+ }
731
+ }());
732
+ }
733
+ function Ee(n5) {
734
+ return B?.trackDisposable(n5), n5;
735
+ }
736
+ function Ie(n5) {
737
+ B?.markAsDisposed(n5);
738
+ }
739
+ function ye(n5, e) {
740
+ B?.setParent(n5, e);
741
+ }
742
+ function Bt(n5, e) {
743
+ if (B) for (let t of n5) B.setParent(t, e);
744
+ }
745
+ function at(n5) {
746
+ if (_e.is(n5)) {
747
+ let e = [];
748
+ for (let t of n5) if (t) try {
749
+ t.dispose();
750
+ } catch (r) {
751
+ e.push(r);
752
+ }
753
+ if (e.length === 1) throw e[0];
754
+ if (e.length > 1) throw new AggregateError(e, "Encountered errors while disposing of store");
755
+ return Array.isArray(n5) ? [] : n5;
756
+ } else if (n5) return n5.dispose(), n5;
757
+ }
758
+ function lt(...n5) {
759
+ let e = De(() => at(n5));
760
+ return Bt(n5, e), e;
761
+ }
762
+ function De(n5) {
763
+ let e = Ee({ dispose: ge(() => {
764
+ Ie(e), n5();
765
+ }) });
766
+ return e;
767
+ }
768
+ var se = class se2 {
769
+ constructor() {
770
+ this._toDispose = /* @__PURE__ */ new Set();
771
+ this._isDisposed = false;
772
+ Ee(this);
773
+ }
774
+ dispose() {
775
+ this._isDisposed || (Ie(this), this._isDisposed = true, this.clear());
776
+ }
777
+ get isDisposed() {
778
+ return this._isDisposed;
779
+ }
780
+ clear() {
781
+ if (this._toDispose.size !== 0) try {
782
+ at(this._toDispose);
783
+ } finally {
784
+ this._toDispose.clear();
785
+ }
786
+ }
787
+ add(e) {
788
+ if (!e) return e;
789
+ if (e === this) throw new Error("Cannot register a disposable on itself!");
790
+ return ye(e, this), this._isDisposed ? se2.DISABLE_DISPOSED_WARNING || console.warn(new Error("Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!").stack) : this._toDispose.add(e), e;
791
+ }
792
+ delete(e) {
793
+ if (e) {
794
+ if (e === this) throw new Error("Cannot dispose a disposable on itself!");
795
+ this._toDispose.delete(e), e.dispose();
796
+ }
797
+ }
798
+ deleteAndLeak(e) {
799
+ e && this._toDispose.has(e) && (this._toDispose.delete(e), ye(e, null));
800
+ }
801
+ };
802
+ se.DISABLE_DISPOSED_WARNING = false;
803
+ var N = se;
804
+ var k = class {
805
+ constructor() {
806
+ this._store = new N();
807
+ Ee(this), ye(this._store, this);
808
+ }
809
+ dispose() {
810
+ Ie(this), this._store.dispose();
811
+ }
812
+ _register(e) {
813
+ if (e === this) throw new Error("Cannot register a disposable on itself!");
814
+ return this._store.add(e);
815
+ }
816
+ };
817
+ k.None = Object.freeze({ dispose() {
818
+ } });
819
+ var W = class W2 {
820
+ constructor(e) {
821
+ this.element = e, this.next = W2.Undefined, this.prev = W2.Undefined;
822
+ }
823
+ };
824
+ W.Undefined = new W(void 0);
825
+ var Nt = globalThis.performance && typeof globalThis.performance.now == "function";
826
+ var oe = class n2 {
827
+ static create(e) {
828
+ return new n2(e);
829
+ }
830
+ constructor(e) {
831
+ this._now = Nt && e === false ? Date.now : globalThis.performance.now.bind(globalThis.performance), this._startTime = this._now(), this._stopTime = -1;
832
+ }
833
+ stop() {
834
+ this._stopTime = this._now();
835
+ }
836
+ reset() {
837
+ this._startTime = this._now(), this._stopTime = -1;
838
+ }
839
+ elapsed() {
840
+ return this._stopTime !== -1 ? this._stopTime - this._startTime : this._now() - this._startTime;
841
+ }
842
+ };
843
+ var Wt = false;
844
+ var dt = false;
845
+ var Vt = false;
846
+ var Ht;
847
+ ((q) => {
848
+ q.None = () => k.None;
849
+ function e(u) {
850
+ if (Vt) {
851
+ let { onDidAddListener: s } = u, l = j.create(), a = 0;
852
+ u.onDidAddListener = () => {
853
+ ++a === 2 && (console.warn("snapshotted emitter LIKELY used public and SHOULD HAVE BEEN created with DisposableStore. snapshotted here"), l.print()), s?.();
854
+ };
855
+ }
856
+ }
857
+ function t(u, s) {
858
+ return L(u, () => {
859
+ }, 0, void 0, true, void 0, s);
860
+ }
861
+ q.defer = t;
862
+ function r(u) {
863
+ return (s, l = null, a) => {
864
+ let d = false, h;
865
+ return h = u((v) => {
866
+ if (!d) return h ? h.dispose() : d = true, s.call(l, v);
867
+ }, null, a), d && h.dispose(), h;
868
+ };
869
+ }
870
+ q.once = r;
871
+ function i(u, s, l) {
872
+ return _((a, d = null, h) => u((v) => a.call(d, s(v)), null, h), l);
873
+ }
874
+ q.map = i;
875
+ function o(u, s, l) {
876
+ return _((a, d = null, h) => u((v) => {
877
+ s(v), a.call(d, v);
878
+ }, null, h), l);
879
+ }
880
+ q.forEach = o;
881
+ function f(u, s, l) {
882
+ return _((a, d = null, h) => u((v) => s(v) && a.call(d, v), null, h), l);
883
+ }
884
+ q.filter = f;
885
+ function T(u) {
886
+ return u;
887
+ }
888
+ q.signal = T;
889
+ function p(...u) {
890
+ return (s, l = null, a) => {
891
+ let d = lt(...u.map((h) => h((v) => s.call(l, v))));
892
+ return x(d, a);
893
+ };
894
+ }
895
+ q.any = p;
896
+ function m(u, s, l, a) {
897
+ let d = l;
898
+ return i(u, (h) => (d = s(d, h), d), a);
899
+ }
900
+ q.reduce = m;
901
+ function _(u, s) {
902
+ let l, a = { onWillAddFirstListener() {
903
+ l = u(d.fire, d);
904
+ }, onDidRemoveLastListener() {
905
+ l?.dispose();
906
+ } };
907
+ s || e(a);
908
+ let d = new A(a);
909
+ return s?.add(d), d.event;
910
+ }
911
+ function x(u, s) {
912
+ return s instanceof Array ? s.push(u) : s && s.add(u), u;
913
+ }
914
+ function L(u, s, l = 100, a = false, d = false, h, v) {
915
+ let E, I, P, Z = 0, G, Ze = { leakWarningThreshold: h, onWillAddFirstListener() {
916
+ E = u((Rt) => {
917
+ Z++, I = s(I, Rt), a && !P && (Y.fire(I), I = void 0), G = () => {
918
+ let kt = I;
919
+ I = void 0, P = void 0, (!a || Z > 1) && Y.fire(kt), Z = 0;
920
+ }, typeof l == "number" ? (clearTimeout(P), P = setTimeout(G, l)) : P === void 0 && (P = 0, queueMicrotask(G));
921
+ });
922
+ }, onWillRemoveListener() {
923
+ d && Z > 0 && G?.();
924
+ }, onDidRemoveLastListener() {
925
+ G = void 0, E.dispose();
926
+ } };
927
+ v || e(Ze);
928
+ let Y = new A(Ze);
929
+ return v?.add(Y), Y.event;
930
+ }
931
+ q.debounce = L;
932
+ function O(u, s = 0, l) {
933
+ return q.debounce(u, (a, d) => a ? (a.push(d), a) : [d], s, void 0, true, void 0, l);
934
+ }
935
+ q.accumulate = O;
936
+ function pe(u, s = (a, d) => a === d, l) {
937
+ let a = true, d;
938
+ return f(u, (h) => {
939
+ let v = a || !s(h, d);
940
+ return a = false, d = h, v;
941
+ }, l);
942
+ }
943
+ q.latch = pe;
944
+ function X(u, s, l) {
945
+ return [q.filter(u, s, l), q.filter(u, (a) => !s(a), l)];
946
+ }
947
+ q.split = X;
948
+ function F(u, s = false, l = [], a) {
949
+ let d = l.slice(), h = u((I) => {
950
+ d ? d.push(I) : E.fire(I);
951
+ });
952
+ a && a.add(h);
953
+ let v = () => {
954
+ d?.forEach((I) => E.fire(I)), d = null;
955
+ }, E = new A({ onWillAddFirstListener() {
956
+ h || (h = u((I) => E.fire(I)), a && a.add(h));
957
+ }, onDidAddFirstListener() {
958
+ d && (s ? setTimeout(v) : v());
959
+ }, onDidRemoveLastListener() {
960
+ h && h.dispose(), h = null;
961
+ } });
962
+ return a && a.add(E), E.event;
963
+ }
964
+ q.buffer = F;
965
+ function he(u, s) {
966
+ return (a, d, h) => {
967
+ let v = s(new Te());
968
+ return u(function(E) {
969
+ let I = v.evaluate(E);
970
+ I !== K && a.call(d, I);
971
+ }, void 0, h);
972
+ };
973
+ }
974
+ q.chain = he;
975
+ let K = /* @__PURE__ */ Symbol("HaltChainable");
976
+ class Te {
977
+ constructor() {
978
+ this.steps = [];
979
+ }
980
+ map(s) {
981
+ return this.steps.push(s), this;
982
+ }
983
+ forEach(s) {
984
+ return this.steps.push((l) => (s(l), l)), this;
985
+ }
986
+ filter(s) {
987
+ return this.steps.push((l) => s(l) ? l : K), this;
988
+ }
989
+ reduce(s, l) {
990
+ let a = l;
991
+ return this.steps.push((d) => (a = s(a, d), a)), this;
992
+ }
993
+ latch(s = (l, a) => l === a) {
994
+ let l = true, a;
995
+ return this.steps.push((d) => {
996
+ let h = l || !s(d, a);
997
+ return l = false, a = d, h ? d : K;
998
+ }), this;
999
+ }
1000
+ evaluate(s) {
1001
+ for (let l of this.steps) if (s = l(s), s === K) break;
1002
+ return s;
1003
+ }
1004
+ }
1005
+ function c(u, s, l = (a) => a) {
1006
+ let a = (...E) => v.fire(l(...E)), d = () => u.on(s, a), h = () => u.removeListener(s, a), v = new A({ onWillAddFirstListener: d, onDidRemoveLastListener: h });
1007
+ return v.event;
1008
+ }
1009
+ q.fromNodeEventEmitter = c;
1010
+ function b(u, s, l = (a) => a) {
1011
+ let a = (...E) => v.fire(l(...E)), d = () => u.addEventListener(s, a), h = () => u.removeEventListener(s, a), v = new A({ onWillAddFirstListener: d, onDidRemoveLastListener: h });
1012
+ return v.event;
1013
+ }
1014
+ q.fromDOMEventEmitter = b;
1015
+ function g(u) {
1016
+ return new Promise((s) => r(u)(s));
1017
+ }
1018
+ q.toPromise = g;
1019
+ function D(u) {
1020
+ let s = new A();
1021
+ return u.then((l) => {
1022
+ s.fire(l);
1023
+ }, () => {
1024
+ s.fire(void 0);
1025
+ }).finally(() => {
1026
+ s.dispose();
1027
+ }), s.event;
1028
+ }
1029
+ q.fromPromise = D;
1030
+ function z(u, s) {
1031
+ return u((l) => s.fire(l));
1032
+ }
1033
+ q.forward = z;
1034
+ function xe(u, s, l) {
1035
+ return s(l), u((a) => s(a));
1036
+ }
1037
+ q.runAndSubscribe = xe;
1038
+ class Ct {
1039
+ constructor(s, l) {
1040
+ this._observable = s;
1041
+ this._counter = 0;
1042
+ this._hasChanged = false;
1043
+ let a = { onWillAddFirstListener: () => {
1044
+ s.addObserver(this);
1045
+ }, onDidRemoveLastListener: () => {
1046
+ s.removeObserver(this);
1047
+ } };
1048
+ l || e(a), this.emitter = new A(a), l && l.add(this.emitter);
1049
+ }
1050
+ beginUpdate(s) {
1051
+ this._counter++;
1052
+ }
1053
+ handlePossibleChange(s) {
1054
+ }
1055
+ handleChange(s, l) {
1056
+ this._hasChanged = true;
1057
+ }
1058
+ endUpdate(s) {
1059
+ this._counter--, this._counter === 0 && (this._observable.reportChanges(), this._hasChanged && (this._hasChanged = false, this.emitter.fire(this._observable.get())));
1060
+ }
1061
+ }
1062
+ function _n(u, s) {
1063
+ return new Ct(u, s).emitter.event;
1064
+ }
1065
+ q.fromObservable = _n;
1066
+ function yn(u) {
1067
+ return (s, l, a) => {
1068
+ let d = 0, h = false, v = { beginUpdate() {
1069
+ d++;
1070
+ }, endUpdate() {
1071
+ d--, d === 0 && (u.reportChanges(), h && (h = false, s.call(l)));
1072
+ }, handlePossibleChange() {
1073
+ }, handleChange() {
1074
+ h = true;
1075
+ } };
1076
+ u.addObserver(v), u.reportChanges();
1077
+ let E = { dispose() {
1078
+ u.removeObserver(v);
1079
+ } };
1080
+ return a instanceof N ? a.add(E) : Array.isArray(a) && a.push(E), E;
1081
+ };
1082
+ }
1083
+ q.fromObservableLight = yn;
1084
+ })(Ht ||= {});
1085
+ var V = class V2 {
1086
+ constructor(e) {
1087
+ this.listenerCount = 0;
1088
+ this.invocationCount = 0;
1089
+ this.elapsedOverall = 0;
1090
+ this.durations = [];
1091
+ this.name = `${e}_${V2._idPool++}`, V2.all.add(this);
1092
+ }
1093
+ start(e) {
1094
+ this._stopWatch = new oe(), this.listenerCount = e;
1095
+ }
1096
+ stop() {
1097
+ if (this._stopWatch) {
1098
+ let e = this._stopWatch.elapsed();
1099
+ this.durations.push(e), this.elapsedOverall += e, this.invocationCount += 1, this._stopWatch = void 0;
1100
+ }
1101
+ }
1102
+ };
1103
+ V.all = /* @__PURE__ */ new Set(), V._idPool = 0;
1104
+ var Ae = V;
1105
+ var ct = -1;
1106
+ var le = class le2 {
1107
+ constructor(e, t, r = (le2._idPool++).toString(16).padStart(3, "0")) {
1108
+ this._errorHandler = e;
1109
+ this.threshold = t;
1110
+ this.name = r;
1111
+ this._warnCountdown = 0;
1112
+ }
1113
+ dispose() {
1114
+ this._stacks?.clear();
1115
+ }
1116
+ check(e, t) {
1117
+ let r = this.threshold;
1118
+ if (r <= 0 || t < r) return;
1119
+ this._stacks || (this._stacks = /* @__PURE__ */ new Map());
1120
+ let i = this._stacks.get(e.value) || 0;
1121
+ if (this._stacks.set(e.value, i + 1), this._warnCountdown -= 1, this._warnCountdown <= 0) {
1122
+ this._warnCountdown = r * 0.5;
1123
+ let [o, f] = this.getMostFrequentStack(), T = `[${this.name}] potential listener LEAK detected, having ${t} listeners already. MOST frequent listener (${f}):`;
1124
+ console.warn(T), console.warn(o);
1125
+ let p = new Ce(T, o);
1126
+ this._errorHandler(p);
1127
+ }
1128
+ return () => {
1129
+ let o = this._stacks.get(e.value) || 0;
1130
+ this._stacks.set(e.value, o - 1);
1131
+ };
1132
+ }
1133
+ getMostFrequentStack() {
1134
+ if (!this._stacks) return;
1135
+ let e, t = 0;
1136
+ for (let [r, i] of this._stacks) (!e || t < i) && (e = [r, i], t = i);
1137
+ return e;
1138
+ }
1139
+ };
1140
+ le._idPool = 1;
1141
+ var we = le;
1142
+ var j = class n3 {
1143
+ constructor(e) {
1144
+ this.value = e;
1145
+ }
1146
+ static create() {
1147
+ let e = new Error();
1148
+ return new n3(e.stack ?? "");
1149
+ }
1150
+ print() {
1151
+ console.warn(this.value.split(`
1152
+ `).slice(2).join(`
1153
+ `));
1154
+ }
1155
+ };
1156
+ var Ce = class extends Error {
1157
+ constructor(e, t) {
1158
+ super(e), this.name = "ListenerLeakError", this.stack = t;
1159
+ }
1160
+ };
1161
+ var Re = class extends Error {
1162
+ constructor(e, t) {
1163
+ super(e), this.name = "ListenerRefusalError", this.stack = t;
1164
+ }
1165
+ };
1166
+ var Kt = 0;
1167
+ var H = class {
1168
+ constructor(e) {
1169
+ this.value = e;
1170
+ this.id = Kt++;
1171
+ }
1172
+ };
1173
+ var zt = 2;
1174
+ var Gt = (n5, e) => {
1175
+ if (n5 instanceof H) e(n5);
1176
+ else for (let t = 0; t < n5.length; t++) {
1177
+ let r = n5[t];
1178
+ r && e(r);
1179
+ }
1180
+ };
1181
+ var ae;
1182
+ if (Wt) {
1183
+ let n5 = [];
1184
+ setInterval(() => {
1185
+ n5.length !== 0 && (console.warn("[LEAKING LISTENERS] GC'ed these listeners that were NOT yet disposed:"), console.warn(n5.join(`
1186
+ `)), n5.length = 0);
1187
+ }, 3e3), ae = new FinalizationRegistry((e) => {
1188
+ typeof e == "string" && n5.push(e);
1189
+ });
1190
+ }
1191
+ var A = class {
1192
+ constructor(e) {
1193
+ this._size = 0;
1194
+ this._options = e, this._leakageMon = ct > 0 || this._options?.leakWarningThreshold ? new we(e?.onListenerError ?? te, this._options?.leakWarningThreshold ?? ct) : void 0, this._perfMon = this._options?._profName ? new Ae(this._options._profName) : void 0, this._deliveryQueue = this._options?.deliveryQueue;
1195
+ }
1196
+ dispose() {
1197
+ if (!this._disposed) {
1198
+ if (this._disposed = true, this._deliveryQueue?.current === this && this._deliveryQueue.reset(), this._listeners) {
1199
+ if (dt) {
1200
+ let e = this._listeners;
1201
+ queueMicrotask(() => {
1202
+ Gt(e, (t) => t.stack?.print());
1203
+ });
1204
+ }
1205
+ this._listeners = void 0, this._size = 0;
1206
+ }
1207
+ this._options?.onDidRemoveLastListener?.(), this._leakageMon?.dispose();
1208
+ }
1209
+ }
1210
+ get event() {
1211
+ return this._event ??= (e, t, r) => {
1212
+ if (this._leakageMon && this._size > this._leakageMon.threshold ** 2) {
1213
+ let p = `[${this._leakageMon.name}] REFUSES to accept new listeners because it exceeded its threshold by far (${this._size} vs ${this._leakageMon.threshold})`;
1214
+ console.warn(p);
1215
+ let m = this._leakageMon.getMostFrequentStack() ?? ["UNKNOWN stack", -1], _ = new Re(`${p}. HINT: Stack shows most frequent listener (${m[1]}-times)`, m[0]);
1216
+ return (this._options?.onListenerError || te)(_), k.None;
1217
+ }
1218
+ if (this._disposed) return k.None;
1219
+ t && (e = e.bind(t));
1220
+ let i = new H(e), o, f;
1221
+ this._leakageMon && this._size >= Math.ceil(this._leakageMon.threshold * 0.2) && (i.stack = j.create(), o = this._leakageMon.check(i.stack, this._size + 1)), dt && (i.stack = f ?? j.create()), this._listeners ? this._listeners instanceof H ? (this._deliveryQueue ??= new ke(), this._listeners = [this._listeners, i]) : this._listeners.push(i) : (this._options?.onWillAddFirstListener?.(this), this._listeners = i, this._options?.onDidAddFirstListener?.(this)), this._size++;
1222
+ let T = De(() => {
1223
+ ae?.unregister(T), o?.(), this._removeListener(i);
1224
+ });
1225
+ if (r instanceof N ? r.add(T) : Array.isArray(r) && r.push(T), ae) {
1226
+ let p = new Error().stack.split(`
1227
+ `).slice(2, 3).join(`
1228
+ `).trim(), m = /(file:|vscode-file:\/\/vscode-app)?(\/[^:]*:\d+:\d+)/.exec(p);
1229
+ ae.register(T, m?.[2] ?? p, T);
1230
+ }
1231
+ return T;
1232
+ }, this._event;
1233
+ }
1234
+ _removeListener(e) {
1235
+ if (this._options?.onWillRemoveListener?.(this), !this._listeners) return;
1236
+ if (this._size === 1) {
1237
+ this._listeners = void 0, this._options?.onDidRemoveLastListener?.(this), this._size = 0;
1238
+ return;
1239
+ }
1240
+ let t = this._listeners, r = t.indexOf(e);
1241
+ if (r === -1) throw console.log("disposed?", this._disposed), console.log("size?", this._size), console.log("arr?", JSON.stringify(this._listeners)), new Error("Attempted to dispose unknown listener");
1242
+ this._size--, t[r] = void 0;
1243
+ let i = this._deliveryQueue.current === this;
1244
+ if (this._size * zt <= t.length) {
1245
+ let o = 0;
1246
+ for (let f = 0; f < t.length; f++) t[f] ? t[o++] = t[f] : i && (this._deliveryQueue.end--, o < this._deliveryQueue.i && this._deliveryQueue.i--);
1247
+ t.length = o;
1248
+ }
1249
+ }
1250
+ _deliver(e, t) {
1251
+ if (!e) return;
1252
+ let r = this._options?.onListenerError || te;
1253
+ if (!r) {
1254
+ e.value(t);
1255
+ return;
1256
+ }
1257
+ try {
1258
+ e.value(t);
1259
+ } catch (i) {
1260
+ r(i);
1261
+ }
1262
+ }
1263
+ _deliverQueue(e) {
1264
+ let t = e.current._listeners;
1265
+ for (; e.i < e.end; ) this._deliver(t[e.i++], e.value);
1266
+ e.reset();
1267
+ }
1268
+ fire(e) {
1269
+ if (this._deliveryQueue?.current && (this._deliverQueue(this._deliveryQueue), this._perfMon?.stop()), this._perfMon?.start(this._size), this._listeners) if (this._listeners instanceof H) this._deliver(this._listeners, e);
1270
+ else {
1271
+ let t = this._deliveryQueue;
1272
+ t.enqueue(this, e, this._listeners.length), this._deliverQueue(t);
1273
+ }
1274
+ this._perfMon?.stop();
1275
+ }
1276
+ hasListeners() {
1277
+ return this._size > 0;
1278
+ }
1279
+ };
1280
+ var ke = class {
1281
+ constructor() {
1282
+ this.i = -1;
1283
+ this.end = 0;
1284
+ }
1285
+ enqueue(e, t, r) {
1286
+ this.i = 0, this.end = r, this.current = e, this.value = t;
1287
+ }
1288
+ reset() {
1289
+ this.i = this.end, this.current = void 0, this.value = void 0;
1290
+ }
1291
+ };
1292
+ var w = class n4 {
1293
+ constructor() {
1294
+ this._providers = /* @__PURE__ */ Object.create(null);
1295
+ this._active = "";
1296
+ this._onChange = new A();
1297
+ this.onChange = this._onChange.event;
1298
+ let e = new J();
1299
+ this.register(e), this._active = e.version, this._activeProvider = e;
1300
+ }
1301
+ static extractShouldJoin(e) {
1302
+ return (e & 1) !== 0;
1303
+ }
1304
+ static extractWidth(e) {
1305
+ return e >> 1 & 3;
1306
+ }
1307
+ static extractCharKind(e) {
1308
+ return e >> 3;
1309
+ }
1310
+ static createPropertyValue(e, t, r = false) {
1311
+ return (e & 16777215) << 3 | (t & 3) << 1 | (r ? 1 : 0);
1312
+ }
1313
+ dispose() {
1314
+ this._onChange.dispose();
1315
+ }
1316
+ get versions() {
1317
+ return Object.keys(this._providers);
1318
+ }
1319
+ get activeVersion() {
1320
+ return this._active;
1321
+ }
1322
+ set activeVersion(e) {
1323
+ if (!this._providers[e]) throw new Error(`unknown Unicode version "${e}"`);
1324
+ this._active = e, this._activeProvider = this._providers[e], this._onChange.fire(e);
1325
+ }
1326
+ register(e) {
1327
+ this._providers[e.version] = e;
1328
+ }
1329
+ wcwidth(e) {
1330
+ return this._activeProvider.wcwidth(e);
1331
+ }
1332
+ getStringCellWidth(e) {
1333
+ let t = 0, r = 0, i = e.length;
1334
+ for (let o = 0; o < i; ++o) {
1335
+ let f = e.charCodeAt(o);
1336
+ if (55296 <= f && f <= 56319) {
1337
+ if (++o >= i) return t + this.wcwidth(f);
1338
+ let m = e.charCodeAt(o);
1339
+ 56320 <= m && m <= 57343 ? f = (f - 55296) * 1024 + m - 56320 + 65536 : t += this.wcwidth(m);
1340
+ }
1341
+ let T = this.charProperties(f, r), p = n4.extractWidth(T);
1342
+ n4.extractShouldJoin(T) && (p -= n4.extractWidth(r)), t += p, r = T;
1343
+ }
1344
+ return t;
1345
+ }
1346
+ charProperties(e, t) {
1347
+ return this._activeProvider.charProperties(e, t);
1348
+ }
1349
+ };
1350
+ var Ue = 0;
1351
+ var Tt = -3;
1352
+ var S = class {
1353
+ constructor() {
1354
+ this.table = new Uint16Array(16);
1355
+ this.trans = new Uint16Array(288);
1356
+ }
1357
+ };
1358
+ var Fe = class {
1359
+ constructor(e, t) {
1360
+ this.tag = 0;
1361
+ this.bitcount = 0;
1362
+ this.destLen = 0;
1363
+ this.sourceIndex = 0;
1364
+ this.source = e, this.dest = t, this.ltree = new S(), this.dtree = new S();
1365
+ }
1366
+ };
1367
+ var xt = new S();
1368
+ var bt = new S();
1369
+ var Oe = new Uint8Array(30);
1370
+ var Pe = new Uint16Array(30);
1371
+ var vt = new Uint8Array(30);
1372
+ var mt = new Uint16Array(30);
1373
+ var jt = new Uint8Array([16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15]);
1374
+ var ft = new S();
1375
+ var C = new Uint8Array(320);
1376
+ function gt(n5, e, t, r) {
1377
+ var i, o;
1378
+ for (i = 0; i < t; ++i) n5[i] = 0;
1379
+ for (i = 0; i < 30 - t; ++i) n5[i + t] = i / t | 0;
1380
+ for (o = r, i = 0; i < 30; ++i) e[i] = o, o += 1 << n5[i];
1381
+ }
1382
+ function Qt(n5, e) {
1383
+ var t;
1384
+ for (t = 0; t < 7; ++t) n5.table[t] = 0;
1385
+ for (n5.table[7] = 24, n5.table[8] = 152, n5.table[9] = 112, t = 0; t < 24; ++t) n5.trans[t] = 256 + t;
1386
+ for (t = 0; t < 144; ++t) n5.trans[24 + t] = t;
1387
+ for (t = 0; t < 8; ++t) n5.trans[168 + t] = 280 + t;
1388
+ for (t = 0; t < 112; ++t) n5.trans[176 + t] = 144 + t;
1389
+ for (t = 0; t < 5; ++t) e.table[t] = 0;
1390
+ for (e.table[5] = 32, t = 0; t < 32; ++t) e.trans[t] = t;
1391
+ }
1392
+ var pt = new Uint16Array(16);
1393
+ function Le(n5, e, t, r) {
1394
+ var i, o;
1395
+ for (i = 0; i < 16; ++i) n5.table[i] = 0;
1396
+ for (i = 0; i < r; ++i) n5.table[e[t + i]]++;
1397
+ for (n5.table[0] = 0, o = 0, i = 0; i < 16; ++i) pt[i] = o, o += n5.table[i];
1398
+ for (i = 0; i < r; ++i) e[t + i] && (n5.trans[pt[e[t + i]]++] = i);
1399
+ }
1400
+ function Xt(n5) {
1401
+ n5.bitcount-- || (n5.tag = n5.source[n5.sourceIndex++], n5.bitcount = 7);
1402
+ var e = n5.tag & 1;
1403
+ return n5.tag >>>= 1, e;
1404
+ }
1405
+ function R(n5, e, t) {
1406
+ if (!e) return t;
1407
+ for (; n5.bitcount < 24; ) n5.tag |= n5.source[n5.sourceIndex++] << n5.bitcount, n5.bitcount += 8;
1408
+ var r = n5.tag & 65535 >>> 16 - e;
1409
+ return n5.tag >>>= e, n5.bitcount -= e, r + t;
1410
+ }
1411
+ function Se(n5, e) {
1412
+ for (; n5.bitcount < 24; ) n5.tag |= n5.source[n5.sourceIndex++] << n5.bitcount, n5.bitcount += 8;
1413
+ var t = 0, r = 0, i = 0, o = n5.tag;
1414
+ do
1415
+ r = 2 * r + (o & 1), o >>>= 1, ++i, t += e.table[i], r -= e.table[i];
1416
+ while (r >= 0);
1417
+ return n5.tag = o, n5.bitcount -= i, e.trans[t + r];
1418
+ }
1419
+ function qt(n5, e, t) {
1420
+ var r, i, o, f, T, p;
1421
+ for (r = R(n5, 5, 257), i = R(n5, 5, 1), o = R(n5, 4, 4), f = 0; f < 19; ++f) C[f] = 0;
1422
+ for (f = 0; f < o; ++f) {
1423
+ var m = R(n5, 3, 0);
1424
+ C[jt[f]] = m;
1425
+ }
1426
+ for (Le(ft, C, 0, 19), T = 0; T < r + i; ) {
1427
+ var _ = Se(n5, ft);
1428
+ switch (_) {
1429
+ case 16:
1430
+ var x = C[T - 1];
1431
+ for (p = R(n5, 2, 3); p; --p) C[T++] = x;
1432
+ break;
1433
+ case 17:
1434
+ for (p = R(n5, 3, 3); p; --p) C[T++] = 0;
1435
+ break;
1436
+ case 18:
1437
+ for (p = R(n5, 7, 11); p; --p) C[T++] = 0;
1438
+ break;
1439
+ default:
1440
+ C[T++] = _;
1441
+ break;
1442
+ }
1443
+ }
1444
+ Le(e, C, 0, r), Le(t, C, r, i);
1445
+ }
1446
+ function ht(n5, e, t) {
1447
+ for (; ; ) {
1448
+ var r = Se(n5, e);
1449
+ if (r === 256) return Ue;
1450
+ if (r < 256) n5.dest[n5.destLen++] = r;
1451
+ else {
1452
+ var i, o, f, T;
1453
+ for (r -= 257, i = R(n5, Oe[r], Pe[r]), o = Se(n5, t), f = n5.destLen - R(n5, vt[o], mt[o]), T = f; T < f + i; ++T) n5.dest[n5.destLen++] = n5.dest[T];
1454
+ }
1455
+ }
1456
+ }
1457
+ function Zt(n5) {
1458
+ for (var e, t, r; n5.bitcount > 8; ) n5.sourceIndex--, n5.bitcount -= 8;
1459
+ if (e = n5.source[n5.sourceIndex + 1], e = 256 * e + n5.source[n5.sourceIndex], t = n5.source[n5.sourceIndex + 3], t = 256 * t + n5.source[n5.sourceIndex + 2], e !== (~t & 65535)) return Tt;
1460
+ for (n5.sourceIndex += 4, r = e; r; --r) n5.dest[n5.destLen++] = n5.source[n5.sourceIndex++];
1461
+ return n5.bitcount = 0, Ue;
1462
+ }
1463
+ function Yt(n5, e) {
1464
+ var t = new Fe(n5, e), r, i, o;
1465
+ do {
1466
+ switch (r = Xt(t), i = R(t, 2, 0), i) {
1467
+ case 0:
1468
+ o = Zt(t);
1469
+ break;
1470
+ case 1:
1471
+ o = ht(t, xt, bt);
1472
+ break;
1473
+ case 2:
1474
+ qt(t, t.ltree, t.dtree), o = ht(t, t.ltree, t.dtree);
1475
+ break;
1476
+ default:
1477
+ o = Tt;
1478
+ }
1479
+ if (o !== Ue) throw new Error("Data error");
1480
+ } while (!r);
1481
+ return t.destLen < t.dest.length ? typeof t.dest.slice == "function" ? t.dest.slice(0, t.destLen) : t.dest.subarray(0, t.destLen) : t.dest;
1482
+ }
1483
+ Qt(xt, bt);
1484
+ gt(Oe, Pe, 4, 3);
1485
+ gt(vt, mt, 2, 1);
1486
+ Oe[28] = 0;
1487
+ Pe[28] = 258;
1488
+ var Me = Yt;
1489
+ var We = 11;
1490
+ var U = 5;
1491
+ var Jt = We - U;
1492
+ var $t = 65536 >> We;
1493
+ var en = 1 << Jt;
1494
+ var tn = en - 1;
1495
+ var ue = 2;
1496
+ var nn = 1 << U;
1497
+ var Be = nn - 1;
1498
+ var _t = 65536 >> U;
1499
+ var rn = 1024 >> U;
1500
+ var sn = _t + rn;
1501
+ var on = sn;
1502
+ var an = 32;
1503
+ var ln = on + an;
1504
+ var un = 1 << ue;
1505
+ var dn = new Uint8Array(new Uint32Array([305419896]).buffer)[0] === 18;
1506
+ var Ne = class {
1507
+ constructor(e) {
1508
+ let t = new DataView(e.buffer, e.byteOffset, e.byteLength);
1509
+ this.highStart = t.getUint32(0, true), this.errorValue = t.getUint32(4, true);
1510
+ let r = t.getUint32(8, true);
1511
+ if (e = e.subarray(12), e = Me(e, new Uint8Array(r)), e = Me(e, new Uint8Array(r)), dn) {
1512
+ let i = e.length;
1513
+ for (let o = 0; o < i; o += 4) {
1514
+ let f = e[o];
1515
+ e[o] = e[o + 3], e[o + 3] = f;
1516
+ let T = e[o + 1];
1517
+ e[o + 1] = e[o + 2], e[o + 2] = T;
1518
+ }
1519
+ }
1520
+ this.data = new Uint32Array(e.buffer);
1521
+ }
1522
+ get(e) {
1523
+ let t;
1524
+ return e < 0 || e > 1114111 ? this.errorValue : e < 55296 || e > 56319 && e <= 65535 ? (t = (this.data[e >> U] << ue) + (e & Be), this.data[t]) : e <= 65535 ? (t = (this.data[_t + (e - 55296 >> U)] << ue) + (e & Be), this.data[t]) : e < this.highStart ? (t = this.data[ln - $t + (e >> We)], t = this.data[t + (e >> U & tn)], t = (t << ue) + (e & Be), this.data[t]) : this.data[this.data.length - un];
1525
+ }
1526
+ };
1527
+ var yt = Ne;
1528
+ var cn = "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";
1529
+ function fn(n5) {
1530
+ if (typeof Buffer < "u") return Buffer.from(n5, "base64");
1531
+ let e = atob(n5), t = new Uint8Array(e.length);
1532
+ for (let r = 0; r < t.length; ++r) t[r] = e.charCodeAt(r);
1533
+ return t;
1534
+ }
1535
+ var pn = new yt(fn(cn));
1536
+ var de = 15;
1537
+ var ce = 0;
1538
+ var hn = 48;
1539
+ var Tn = 4;
1540
+ var Dt = 0;
1541
+ var je = 1;
1542
+ var Qe = 2;
1543
+ var Ge = 3;
1544
+ var xn = 4;
1545
+ var Ve = 5;
1546
+ var He = 6;
1547
+ var Ke = 7;
1548
+ var Et = 8;
1549
+ var ze = 9;
1550
+ var It = 10;
1551
+ var bn = 11;
1552
+ var vn = 32;
1553
+ function Xe(n5) {
1554
+ return (n5 & hn) >> Tn;
1555
+ }
1556
+ function At(n5, e) {
1557
+ let t = (n5 & de) >> ce, r = (e & de) >> ce;
1558
+ return mn(t, r) ? r === Ge ? vn : r + 16 : r - 16;
1559
+ }
1560
+ function mn(n5, e) {
1561
+ return n5 >= Ve && n5 <= ze && (n5 == Ve && (e == Ve || e == He || e == Et || e == ze) || (n5 == Et || n5 == He) && (e == He || e == Ke) || (n5 == ze || n5 == Ke) && e == Ke) || e == Qe || e == It || n5 == je || e == xn || n5 == It && e == bn || e == Ge && n5 == Ge;
1562
+ }
1563
+ function qe(n5) {
1564
+ return pn.get(n5);
1565
+ }
1566
+ var fe = class fe2 {
1567
+ constructor(e = true) {
1568
+ this.ambiguousCharsAreWide = false;
1569
+ this.version = e ? "15-graphemes" : "15", this.handleGraphemes = e;
1570
+ }
1571
+ charProperties(e, t) {
1572
+ if (e >= 32 && e < 127 && t >> 3 === 0) return fe2._plainNarrowProperties;
1573
+ let r = qe(e), i = Xe(r), o = false;
1574
+ if (i >= 2 ? i = i === 3 || this.ambiguousCharsAreWide || e === 65039 ? 2 : 1 : i = 1, t !== 0) {
1575
+ let f = w.extractWidth(t);
1576
+ this.handleGraphemes ? r = At(w.extractCharKind(t), r) : r = i === 0 ? 1 : 0, o = r > 0, o && (f > i ? i = f : r === 32 && (i = 2));
1577
+ }
1578
+ return w.createPropertyValue(r, i, o);
1579
+ }
1580
+ wcwidth(e) {
1581
+ let t = qe(e), r = Xe(t), i = (t & de) >> ce;
1582
+ return i === Qe || i === je ? 0 : r >= 2 && (r === 3 || this.ambiguousCharsAreWide) ? 2 : 1;
1583
+ }
1584
+ };
1585
+ fe._plainNarrowProperties = w.createPropertyValue(Dt, 1, false);
1586
+ var Q = fe;
1587
+ var wt = class {
1588
+ constructor() {
1589
+ this._oldVersion = "";
1590
+ }
1591
+ activate(e) {
1592
+ this._provider15 || (this._provider15 = new Q(false)), this._provider15Graphemes || (this._provider15Graphemes = new Q(true));
1593
+ let t = e.unicode;
1594
+ this._unicode = t, t.register(this._provider15), t.register(this._provider15Graphemes), this._oldVersion = t.activeVersion, t.activeVersion = "15-graphemes";
1595
+ }
1596
+ dispose() {
1597
+ this._unicode && (this._unicode.activeVersion = this._oldVersion);
1598
+ }
1599
+ };
1600
+
1601
+ // src/common/pty-render-sequencer.ts
1602
+ var { Terminal: HeadlessTerminal } = pkg;
1603
+ var PtyRenderSequencer = class {
1604
+ terminal;
1605
+ serializeAddon = new SerializeAddon();
1606
+ outputSeq = 0;
1607
+ disposed = false;
1608
+ constructor(options) {
1609
+ this.terminal = new HeadlessTerminal({
1610
+ cols: options.cols,
1611
+ rows: options.rows,
1612
+ scrollback: options.scrollback ?? 5e3,
1613
+ allowProposedApi: true
1614
+ });
1615
+ this.terminal.loadAddon(this.serializeAddon);
1616
+ this.terminal.loadAddon(new wt());
1617
+ }
1618
+ get cols() {
1619
+ return this.terminal.cols;
1620
+ }
1621
+ get rows() {
1622
+ return this.terminal.rows;
1623
+ }
1624
+ /** Queues non-empty render output and returns its allocated remote event sequence. */
1625
+ write(data) {
1626
+ if (this.disposed || data.length === 0) return null;
1627
+ const outputSeq = ++this.outputSeq;
1628
+ this.terminal.write(data);
1629
+ return outputSeq;
1630
+ }
1631
+ /**
1632
+ * Allocates a resize event and queues the geometry change at its exact place in xterm's write
1633
+ * stream. Output queued after this call cannot be parsed using the old geometry.
1634
+ */
1635
+ resize(cols, rows) {
1636
+ if (this.disposed) return null;
1637
+ const outputSeq = ++this.outputSeq;
1638
+ this.terminal.write("", () => {
1639
+ if (this.disposed) return;
1640
+ this.terminal.resize(cols, rows);
1641
+ });
1642
+ return outputSeq;
1643
+ }
1644
+ /** Captures the sequence watermark now and the matching terminal state at the FIFO barrier. */
1645
+ captureSnapshot(onSnapshot) {
1646
+ if (this.disposed) return false;
1647
+ const outputSeq = this.outputSeq;
1648
+ this.terminal.write("", () => {
1649
+ if (this.disposed) return;
1650
+ onSnapshot({
1651
+ cols: this.terminal.cols,
1652
+ rows: this.terminal.rows,
1653
+ data: this.serializeAddon.serialize(),
1654
+ outputSeq
1655
+ });
1656
+ });
1657
+ return true;
1658
+ }
1659
+ dispose() {
1660
+ if (this.disposed) return;
1661
+ this.disposed = true;
1662
+ this.terminal.dispose();
1663
+ }
1664
+ };
1665
+
1666
+ // src/common/codex-xterm-history-compat.ts
1667
+ var SYNC_OUTPUT_START = "\x1B[?2026h";
1668
+ var SYNC_OUTPUT_END = "\x1B[?2026l";
1669
+ var MAX_SYNC_BLOCK_CHARS = 1024 * 1024;
1670
+ var ALT_SCREEN_SEQUENCE_RE = /\x1b\[\?(?:47|1047|1049)([hl])/g;
1671
+ var HISTORY_INSERT_RE = /\x1b\[1;([1-9]\d*)r\x1b\[(\d*)S\x1b\[r\x1b\[([1-9]\d*);1H\x1b\[J/g;
1672
+ var CODEX_XTERM_HISTORY_COMPAT_ENV = "DEV_ANYWHERE_CODEX_XTERM_HISTORY_COMPAT";
1673
+ var CodexXtermHistoryCompat = class {
1674
+ pending = "";
1675
+ state = "outside";
1676
+ alternateScreen = false;
1677
+ altScanCarry = "";
1678
+ terminalRows;
1679
+ rewrittenTransactions = 0;
1680
+ preservedRows = 0;
1681
+ constructor(rows) {
1682
+ this.terminalRows = rows;
1683
+ }
1684
+ get stats() {
1685
+ return {
1686
+ rewrittenTransactions: this.rewrittenTransactions,
1687
+ preservedRows: this.preservedRows
1688
+ };
1689
+ }
1690
+ push(data) {
1691
+ if (!data) return "";
1692
+ this.pending += data;
1693
+ let output = "";
1694
+ while (this.pending.length > 0) {
1695
+ if (this.state === "buffering-sync") {
1696
+ const endIndex = this.pending.indexOf(SYNC_OUTPUT_END, SYNC_OUTPUT_START.length);
1697
+ if (endIndex === -1) {
1698
+ if (this.pending.length <= MAX_SYNC_BLOCK_CHARS) break;
1699
+ const keep2 = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);
1700
+ const passthrough2 = this.pending.slice(0, this.pending.length - keep2);
1701
+ output += passthrough2;
1702
+ this.scanAlternateScreen(passthrough2);
1703
+ this.pending = this.pending.slice(this.pending.length - keep2);
1704
+ this.state = "passthrough-sync";
1705
+ continue;
1706
+ }
1707
+ const blockEnd = endIndex + SYNC_OUTPUT_END.length;
1708
+ const block = this.pending.slice(0, blockEnd);
1709
+ this.pending = this.pending.slice(blockEnd);
1710
+ output += this.rewriteSynchronizedBlock(block);
1711
+ this.state = "outside";
1712
+ continue;
1713
+ }
1714
+ if (this.state === "passthrough-sync") {
1715
+ const endIndex = this.pending.indexOf(SYNC_OUTPUT_END);
1716
+ if (endIndex === -1) {
1717
+ const keep2 = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);
1718
+ const passthrough3 = this.pending.slice(0, this.pending.length - keep2);
1719
+ output += passthrough3;
1720
+ this.scanAlternateScreen(passthrough3);
1721
+ this.pending = this.pending.slice(this.pending.length - keep2);
1722
+ break;
1723
+ }
1724
+ const blockEnd = endIndex + SYNC_OUTPUT_END.length;
1725
+ const passthrough2 = this.pending.slice(0, blockEnd);
1726
+ output += passthrough2;
1727
+ this.scanAlternateScreen(passthrough2);
1728
+ this.pending = this.pending.slice(blockEnd);
1729
+ this.state = "outside";
1730
+ continue;
1731
+ }
1732
+ const startIndex = this.pending.indexOf(SYNC_OUTPUT_START);
1733
+ if (startIndex !== -1) {
1734
+ const passthrough2 = this.pending.slice(0, startIndex);
1735
+ output += passthrough2;
1736
+ this.scanAlternateScreen(passthrough2);
1737
+ this.pending = this.pending.slice(startIndex);
1738
+ this.state = "buffering-sync";
1739
+ continue;
1740
+ }
1741
+ const keep = longestSuffixPrefix(this.pending, SYNC_OUTPUT_START);
1742
+ const passthrough = this.pending.slice(0, this.pending.length - keep);
1743
+ output += passthrough;
1744
+ this.scanAlternateScreen(passthrough);
1745
+ this.pending = this.pending.slice(this.pending.length - keep);
1746
+ break;
1747
+ }
1748
+ return output;
1749
+ }
1750
+ /** Flushes an incomplete candidate byte-for-byte, for resize/exit boundaries. */
1751
+ flush() {
1752
+ const pending = this.pending;
1753
+ this.pending = "";
1754
+ this.state = "outside";
1755
+ this.scanAlternateScreen(pending);
1756
+ return pending;
1757
+ }
1758
+ setTerminalRows(rows) {
1759
+ this.terminalRows = rows;
1760
+ }
1761
+ rewriteSynchronizedBlock(block) {
1762
+ const startsInAlternateScreen = this.alternateScreen;
1763
+ ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
1764
+ const switchesScreenBuffer = ALT_SCREEN_SEQUENCE_RE.test(block);
1765
+ ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
1766
+ let rewritten = block;
1767
+ if (!startsInAlternateScreen && !switchesScreenBuffer) {
1768
+ rewritten = block.replace(
1769
+ HISTORY_INSERT_RE,
1770
+ (original, bottomRaw, countRaw, repaintRowRaw) => {
1771
+ const bottom = Number.parseInt(bottomRaw, 10);
1772
+ const parsedCount = countRaw === "" ? 1 : Number.parseInt(countRaw, 10);
1773
+ const count = parsedCount === 0 ? 1 : parsedCount;
1774
+ const repaintRow = Number.parseInt(repaintRowRaw, 10);
1775
+ const expectedRepaintRow = bottom - count + 1;
1776
+ if (!Number.isSafeInteger(bottom) || !Number.isSafeInteger(count) || !Number.isSafeInteger(repaintRow) || bottom >= this.terminalRows || count < 1 || count > bottom || repaintRow !== expectedRepaintRow) {
1777
+ return original;
1778
+ }
1779
+ this.rewrittenTransactions += 1;
1780
+ this.preservedRows += count;
1781
+ return `\x1B[r\x1B[999;1H${"\n".repeat(count)}\x1B[H\x1B[${repaintRow};1H\x1B[J`;
1782
+ }
1783
+ );
1784
+ }
1785
+ this.scanAlternateScreen(block);
1786
+ return rewritten;
1787
+ }
1788
+ scanAlternateScreen(data) {
1789
+ if (!data) return;
1790
+ const scan = this.altScanCarry + data;
1791
+ ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
1792
+ for (const match of scan.matchAll(ALT_SCREEN_SEQUENCE_RE)) {
1793
+ this.alternateScreen = match[1] === "h";
1794
+ }
1795
+ ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
1796
+ this.altScanCarry = scan.slice(-(SYNC_OUTPUT_START.length - 1));
1797
+ }
1798
+ };
1799
+ function createCodexXtermHistoryCompat(provider, rows, env) {
1800
+ if (provider !== "codex") return null;
1801
+ const configured = env[CODEX_XTERM_HISTORY_COMPAT_ENV]?.trim().toLowerCase();
1802
+ if (configured === "0" || configured === "false" || configured === "off") return null;
1803
+ return new CodexXtermHistoryCompat(rows);
1804
+ }
1805
+ function longestSuffixPrefix(value, marker) {
1806
+ const max = Math.min(value.length, marker.length - 1);
1807
+ for (let length = max; length > 0; length -= 1) {
1808
+ if (value.endsWith(marker.slice(0, length))) return length;
1809
+ }
1810
+ return 0;
1811
+ }
1812
+
1813
+ // src/common/pty-synchronized-output-coalescer.ts
1814
+ var SYNC_OUTPUT_START2 = "\x1B[?2026h";
1815
+ var SYNC_OUTPUT_END2 = "\x1B[?2026l";
1816
+ var DEFAULT_SYNC_OUTPUT_MAX_BUFFERED_BYTES = 8 * 1024 * 1024;
1817
+ var DEFAULT_SYNC_OUTPUT_IDLE_TIMEOUT_MS = 2e3;
1818
+ var PtySynchronizedOutputCoalescer = class {
1819
+ emitData;
1820
+ maxBufferedBytes;
1821
+ idleTimeoutMs;
1822
+ setTimer;
1823
+ clearTimer;
1824
+ onOverflow;
1825
+ mode = "outside";
1826
+ parserState = "ground";
1827
+ stringState = null;
1828
+ controlSequence = "";
1829
+ markerEligible = false;
1830
+ outsidePending = "";
1831
+ transactionParts = [];
1832
+ transactionBytes = 0;
1833
+ idleTimer = null;
1834
+ disposed = false;
1835
+ constructor(options) {
1836
+ this.emitData = options.emit;
1837
+ this.maxBufferedBytes = options.maxBufferedBytes ?? DEFAULT_SYNC_OUTPUT_MAX_BUFFERED_BYTES;
1838
+ this.idleTimeoutMs = options.idleTimeoutMs ?? DEFAULT_SYNC_OUTPUT_IDLE_TIMEOUT_MS;
1839
+ this.setTimer = options.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
1840
+ this.clearTimer = options.clearTimer ?? ((handle) => clearTimeout(handle));
1841
+ this.onOverflow = options.onOverflow;
1842
+ if (!Number.isSafeInteger(this.maxBufferedBytes) || this.maxBufferedBytes < 1) {
1843
+ throw new RangeError("maxBufferedBytes must be a positive safe integer");
1844
+ }
1845
+ if (!Number.isFinite(this.idleTimeoutMs) || this.idleTimeoutMs < 0) {
1846
+ throw new RangeError("idleTimeoutMs must be a non-negative finite number");
1847
+ }
1848
+ }
1849
+ push(data) {
1850
+ if (this.disposed || data.length === 0) return;
1851
+ let offset = 0;
1852
+ for (let index = 0; index < data.length; index += 1) {
1853
+ const marker = this.scan(data[index]);
1854
+ if (marker === null) continue;
1855
+ const segment = data.slice(offset, index + 1);
1856
+ if (this.mode === "outside") {
1857
+ if (marker !== "start") continue;
1858
+ const combined = this.outsidePending + segment;
1859
+ const markerStart = combined.length - SYNC_OUTPUT_START2.length;
1860
+ this.emit(combined.slice(0, markerStart));
1861
+ this.outsidePending = "";
1862
+ this.mode = "buffering";
1863
+ this.appendTransaction(combined.slice(markerStart));
1864
+ } else if (this.mode === "buffering") {
1865
+ this.appendTransaction(segment);
1866
+ if (marker === "end" && this.mode === "buffering") {
1867
+ this.commitTransaction();
1868
+ } else if (marker === "end") {
1869
+ this.mode = "outside";
1870
+ }
1871
+ } else {
1872
+ this.emit(segment);
1873
+ if (marker === "end") this.mode = "outside";
1874
+ }
1875
+ offset = index + 1;
1876
+ }
1877
+ const remainder = data.slice(offset);
1878
+ if (this.mode === "buffering") {
1879
+ this.appendTransaction(remainder);
1880
+ if (this.mode === "buffering") this.armIdleTimer();
1881
+ return;
1882
+ }
1883
+ if (this.mode === "passthrough") {
1884
+ this.emit(remainder);
1885
+ return;
1886
+ }
1887
+ this.outsidePending += remainder;
1888
+ const candidateLength = this.startCandidateLength();
1889
+ const emitLength = this.outsidePending.length - candidateLength;
1890
+ if (emitLength > 0) {
1891
+ this.emit(this.outsidePending.slice(0, emitLength));
1892
+ this.outsidePending = this.outsidePending.slice(emitLength);
1893
+ }
1894
+ if (this.outsidePending.length > 0) this.armIdleTimer();
1895
+ else this.clearIdleTimer();
1896
+ }
1897
+ flush() {
1898
+ if (this.disposed) return;
1899
+ this.clearIdleTimer();
1900
+ const wasBuffering = this.mode === "buffering";
1901
+ this.emit(this.outsidePending);
1902
+ this.outsidePending = "";
1903
+ this.emitTransactionParts();
1904
+ if (wasBuffering) {
1905
+ this.mode = "passthrough";
1906
+ } else if (this.mode === "outside") {
1907
+ this.disarmCurrentMarkerCandidate();
1908
+ }
1909
+ }
1910
+ dispose() {
1911
+ if (this.disposed) return;
1912
+ this.flush();
1913
+ this.disposed = true;
1914
+ }
1915
+ appendTransaction(data) {
1916
+ if (!data) return;
1917
+ const incomingBytes = Buffer.byteLength(data, "utf8");
1918
+ const nextBytes = this.transactionBytes + incomingBytes;
1919
+ if (nextBytes <= this.maxBufferedBytes) {
1920
+ this.transactionParts.push(data);
1921
+ this.transactionBytes = nextBytes;
1922
+ return;
1923
+ }
1924
+ this.onOverflow?.({
1925
+ reason: "byte-cap",
1926
+ maxBufferedBytes: this.maxBufferedBytes,
1927
+ bufferedBytes: this.transactionBytes,
1928
+ incomingBytes,
1929
+ transactionBytes: nextBytes
1930
+ });
1931
+ this.clearIdleTimer();
1932
+ this.emitTransactionParts();
1933
+ this.emit(data);
1934
+ this.mode = "passthrough";
1935
+ }
1936
+ commitTransaction() {
1937
+ this.clearIdleTimer();
1938
+ const transaction = this.transactionParts.join("");
1939
+ this.transactionParts = [];
1940
+ this.transactionBytes = 0;
1941
+ this.mode = "outside";
1942
+ this.emit(transaction);
1943
+ }
1944
+ emitTransactionParts() {
1945
+ if (this.transactionParts.length === 0) return;
1946
+ this.emit(this.transactionParts.join(""));
1947
+ this.transactionParts = [];
1948
+ this.transactionBytes = 0;
1949
+ }
1950
+ emit(data) {
1951
+ if (data) this.emitData(data);
1952
+ }
1953
+ armIdleTimer() {
1954
+ this.clearIdleTimer();
1955
+ this.idleTimer = this.setTimer(() => {
1956
+ this.idleTimer = null;
1957
+ if (this.mode === "buffering") {
1958
+ this.emitTransactionParts();
1959
+ this.mode = "passthrough";
1960
+ return;
1961
+ }
1962
+ if (this.mode === "outside" && this.outsidePending) {
1963
+ this.emit(this.outsidePending);
1964
+ this.outsidePending = "";
1965
+ this.disarmCurrentMarkerCandidate();
1966
+ }
1967
+ }, this.idleTimeoutMs);
1968
+ }
1969
+ clearIdleTimer() {
1970
+ if (this.idleTimer === null) return;
1971
+ this.clearTimer(this.idleTimer);
1972
+ this.idleTimer = null;
1973
+ }
1974
+ startCandidateLength() {
1975
+ if ((this.parserState === "escape" || this.parserState === "csi") && this.markerEligible && SYNC_OUTPUT_START2.startsWith(this.controlSequence)) {
1976
+ return this.controlSequence.length;
1977
+ }
1978
+ return 0;
1979
+ }
1980
+ scan(char) {
1981
+ if (this.parserState === "ground") {
1982
+ if (char === "\x1B") {
1983
+ this.parserState = "escape";
1984
+ this.controlSequence = char;
1985
+ this.markerEligible = true;
1986
+ }
1987
+ return null;
1988
+ }
1989
+ if (this.parserState === "escape") {
1990
+ if (char === "[") {
1991
+ this.parserState = "csi";
1992
+ this.controlSequence += char;
1993
+ } else if (char === "]") {
1994
+ this.enterString("osc");
1995
+ } else if (char === "P") {
1996
+ this.enterString("dcs");
1997
+ } else if (char === "_") {
1998
+ this.enterString("apc");
1999
+ } else if (char === "^") {
2000
+ this.enterString("pm");
2001
+ } else if (char === "X") {
2002
+ this.enterString("sos");
2003
+ } else if (char === "\x1B") {
2004
+ this.controlSequence = char;
2005
+ this.markerEligible = true;
2006
+ } else if (isEscapeIntermediate(char)) {
2007
+ this.parserState = "escape-other";
2008
+ this.controlSequence = "";
2009
+ this.markerEligible = false;
2010
+ } else {
2011
+ this.parserState = "ground";
2012
+ this.controlSequence = "";
2013
+ this.markerEligible = false;
2014
+ }
2015
+ return null;
2016
+ }
2017
+ if (this.parserState === "escape-other") {
2018
+ if (char === "\x1B") {
2019
+ this.parserState = "escape";
2020
+ this.controlSequence = char;
2021
+ this.markerEligible = true;
2022
+ } else if (isFinalByte(char)) {
2023
+ this.parserState = "ground";
2024
+ }
2025
+ return null;
2026
+ }
2027
+ if (this.parserState === "csi") {
2028
+ if (char === "\x1B") {
2029
+ this.parserState = "escape";
2030
+ this.controlSequence = char;
2031
+ this.markerEligible = true;
2032
+ return null;
2033
+ }
2034
+ this.controlSequence += char;
2035
+ if (!isFinalByte(char)) return null;
2036
+ const sequence = this.controlSequence;
2037
+ const markerEligible = this.markerEligible;
2038
+ this.parserState = "ground";
2039
+ this.controlSequence = "";
2040
+ this.markerEligible = false;
2041
+ if (markerEligible && sequence === SYNC_OUTPUT_START2) return "start";
2042
+ if (markerEligible && sequence === SYNC_OUTPUT_END2) return "end";
2043
+ return null;
2044
+ }
2045
+ if (this.parserState === "string-escape") {
2046
+ if (char === "\\") {
2047
+ this.parserState = "ground";
2048
+ this.stringState = null;
2049
+ } else if (char !== "\x1B") {
2050
+ this.parserState = this.stringState ?? "ground";
2051
+ }
2052
+ return null;
2053
+ }
2054
+ if (char === "\x1B") {
2055
+ this.stringState = this.parserState;
2056
+ this.parserState = "string-escape";
2057
+ } else if (char === "\x9C" || this.parserState === "osc" && char === "\x07") {
2058
+ this.parserState = "ground";
2059
+ this.stringState = null;
2060
+ }
2061
+ return null;
2062
+ }
2063
+ enterString(state) {
2064
+ this.parserState = state;
2065
+ this.stringState = state;
2066
+ this.controlSequence = "";
2067
+ this.markerEligible = false;
2068
+ }
2069
+ disarmCurrentMarkerCandidate() {
2070
+ if (this.parserState === "escape" || this.parserState === "csi") {
2071
+ this.markerEligible = false;
2072
+ }
2073
+ }
2074
+ };
2075
+ function isFinalByte(char) {
2076
+ const code = char.charCodeAt(0);
2077
+ return code >= 64 && code <= 126;
2078
+ }
2079
+ function isEscapeIntermediate(char) {
2080
+ const code = char.charCodeAt(0);
2081
+ return code >= 32 && code <= 47;
2082
+ }
2083
+
2084
+ // src/common/pty-input-compat.ts
2085
+ var WIN32_ESCAPE = "\x1B[27;1;27;1;0;1_\x1B[27;1;27;0;0;1_";
2086
+ var INPUT_TAIL_LIMIT = 80;
2087
+ function createPtyInputCompat(provider, platform = process.platform) {
2088
+ let inputTail = "";
2089
+ let sawWin32Input = false;
2090
+ let inBracketedPaste = false;
2091
+ const markers = /\x1b\[(?:200~|201~|(?:\d{0,10};){5}\d{0,10}_)/g;
2092
+ function observe(data) {
2093
+ if (platform !== "win32") return;
2094
+ const input = inputTail + data;
2095
+ markers.lastIndex = 0;
2096
+ let consumed = 0;
2097
+ for (let match = markers.exec(input); match; match = markers.exec(input)) {
2098
+ if (match[0] === "\x1B[200~") {
2099
+ inBracketedPaste = true;
2100
+ } else if (match[0] === "\x1B[201~") {
2101
+ inBracketedPaste = false;
2102
+ } else if (!inBracketedPaste) {
2103
+ sawWin32Input = true;
2104
+ }
2105
+ consumed = markers.lastIndex;
2106
+ }
2107
+ inputTail = input.slice(consumed).slice(-INPUT_TAIL_LIMIT);
2108
+ }
2109
+ function encodeRemote(data) {
2110
+ const wasInBracketedPaste = inBracketedPaste;
2111
+ observe(data);
2112
+ if (platform !== "win32" || wasInBracketedPaste) return data;
2113
+ if (provider === "codex" && data === "\n") return "\x1B\r";
2114
+ if (sawWin32Input && data === "\x1B") return WIN32_ESCAPE;
2115
+ return data;
2116
+ }
2117
+ return { observe, encodeRemote };
2118
+ }
2119
+
2120
+ // src/ipc/terminal-admission.ts
2121
+ var TERMINAL_ADMISSION_VERSION = 1;
2122
+ var TERMINAL_ADMISSION_FRAME_MAX_BYTES = 16 * 1024;
2123
+ var ADMISSION_TEXT_MAX_LENGTH = 1024;
2124
+ function isRecord(value) {
2125
+ return value !== null && typeof value === "object" && !Array.isArray(value);
2126
+ }
2127
+ function isProtocolVersion(value) {
2128
+ return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
2129
+ }
2130
+ function isBoundedText(value, allowEmpty = false) {
2131
+ return typeof value === "string" && value.length <= ADMISSION_TEXT_MAX_LENGTH && (allowEmpty || value.length > 0);
2132
+ }
2133
+ function isTerminalAdmissionRequestCandidate(value) {
2134
+ return isRecord(value) && value.type === "terminal_admission_request";
2135
+ }
2136
+ function parseTerminalAdmissionRequest(value) {
2137
+ if (!isRecord(value) || value.type !== "terminal_admission_request") return null;
2138
+ if (value.admissionVersion !== TERMINAL_ADMISSION_VERSION) return null;
2139
+ if (!isProtocolVersion(value.terminalProtocolVersion)) return null;
2140
+ if (value.clientKind !== "local-terminal" && value.clientKind !== "terminal-worker") {
2141
+ return null;
2142
+ }
2143
+ if (value.sessionId !== void 0 && !isBoundedText(value.sessionId)) return null;
2144
+ if (value.clientKind === "terminal-worker" && value.sessionId === void 0) return null;
2145
+ return {
2146
+ type: "terminal_admission_request",
2147
+ admissionVersion: TERMINAL_ADMISSION_VERSION,
2148
+ terminalProtocolVersion: value.terminalProtocolVersion,
2149
+ clientKind: value.clientKind,
2150
+ ...value.sessionId !== void 0 ? { sessionId: value.sessionId } : {}
2151
+ };
2152
+ }
2153
+ function parseTerminalAdmissionResponse(value) {
2154
+ if (!isRecord(value) || value.type !== "terminal_admission_response") return null;
2155
+ if (value.admissionVersion !== TERMINAL_ADMISSION_VERSION) return null;
2156
+ if (!isProtocolVersion(value.terminalProtocolVersion)) return null;
2157
+ if (value.status === "accepted") {
2158
+ return {
2159
+ type: "terminal_admission_response",
2160
+ admissionVersion: TERMINAL_ADMISSION_VERSION,
2161
+ status: "accepted",
2162
+ terminalProtocolVersion: value.terminalProtocolVersion
2163
+ };
2164
+ }
2165
+ if (value.status !== "retired" || value.code !== "ADMISSION_REQUEST_INVALID" && value.code !== "ADMISSION_RESPONSE_INVALID" && value.code !== "TERMINAL_RUNTIME_OUTDATED" && value.code !== "TERMINAL_SERVICE_OUTDATED" || value.action !== "restart_terminal" && value.action !== "restart_service" || !isBoundedText(value.message)) {
2166
+ return null;
2167
+ }
2168
+ return {
2169
+ type: "terminal_admission_response",
2170
+ admissionVersion: TERMINAL_ADMISSION_VERSION,
2171
+ status: "retired",
2172
+ terminalProtocolVersion: value.terminalProtocolVersion,
2173
+ code: value.code,
2174
+ action: value.action,
2175
+ message: value.message
2176
+ };
2177
+ }
2178
+ function serializeTerminalAdmissionMessage(message) {
2179
+ return `${JSON.stringify(message)}
2180
+ `;
2181
+ }
2182
+
2183
+ export {
2184
+ createPtyInputCompat,
2185
+ createIdleChecker,
2186
+ ReconnectSupervisor,
2187
+ TERMINAL_ADMISSION_VERSION,
2188
+ TERMINAL_ADMISSION_FRAME_MAX_BYTES,
2189
+ isTerminalAdmissionRequestCandidate,
2190
+ parseTerminalAdmissionRequest,
2191
+ parseTerminalAdmissionResponse,
2192
+ serializeTerminalAdmissionMessage,
2193
+ extractOscSequences,
2194
+ OscWorkingDirectoryTracker,
2195
+ appendPtySemanticTextTail,
2196
+ extractTextSignals,
2197
+ extractOscSignals,
2198
+ shouldReleaseTextApprovalOnInput,
2199
+ decidePtySemanticTransition,
2200
+ shouldStartPtyTurnOnInput,
2201
+ PtyRenderSequencer,
2202
+ createCodexXtermHistoryCompat,
2203
+ PtySynchronizedOutputCoalescer
2204
+ };
2205
+ /*! Bundled license information:
2206
+
2207
+ @xterm/addon-unicode-graphemes/lib/addon-unicode-graphemes.mjs:
2208
+ (**
2209
+ * Copyright (c) 2014-2024 The xterm.js authors. All rights reserved.
2210
+ * @license MIT
2211
+ *
2212
+ * Copyright (c) 2012-2013, Christopher Jeffrey (MIT License)
2213
+ * @license MIT
2214
+ *
2215
+ * Originally forked from (with the author's permission):
2216
+ * Fabrice Bellard's javascript vt100 for jslinux:
2217
+ * http://bellard.org/jslinux/
2218
+ * Copyright (c) 2011 Fabrice Bellard
2219
+ *)
2220
+ */
2221
+ //# sourceMappingURL=chunk-KM62ELKK.js.map