@dev-anywhere/proxy 0.9.12 → 0.9.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/THIRD_PARTY_NOTICES.md +8 -0
  2. package/dist/{autostart-57FQUWHF.js → autostart-VG7PVHTQ.js} +1 -1
  3. package/dist/{chunk-5KXGIGKU.js → chunk-6I5YPQPN.js} +7 -3
  4. package/dist/chunk-6I5YPQPN.js.map +1 -0
  5. package/dist/{chunk-NKYD7QX4.js → chunk-7UICNI4Q.js} +3 -3
  6. package/dist/{chunk-QZNAESON.js → chunk-J7XFB5AQ.js} +2 -2
  7. package/dist/{chunk-53N3SI24.js → chunk-KDISKSDP.js} +3 -3
  8. package/dist/chunk-KM62ELKK.js +2221 -0
  9. package/dist/chunk-KM62ELKK.js.map +1 -0
  10. package/dist/{chunk-3ZDUDCEI.js → chunk-U4CHGJJM.js} +2 -2
  11. package/dist/{chunk-ZHG3MO4C.js → chunk-WLLKRNXA.js} +5 -3
  12. package/dist/chunk-WLLKRNXA.js.map +1 -0
  13. package/dist/index.js +6 -6
  14. package/dist/preview-worker.js +2 -2
  15. package/dist/serve.js +27 -13
  16. package/dist/serve.js.map +1 -1
  17. package/dist/session-worker.js +2 -2
  18. package/dist/{terminal-OOQQSN3D.js → terminal-WZJO6TAN.js} +5 -5
  19. package/dist/terminal-worker.js +5 -5
  20. package/licenses/xterm-unicode-graphemes-MIT.txt +19 -0
  21. package/package.json +4 -4
  22. package/dist/chunk-5KXGIGKU.js.map +0 -1
  23. package/dist/chunk-UXNSX5GO.js +0 -859
  24. package/dist/chunk-UXNSX5GO.js.map +0 -1
  25. package/dist/chunk-ZHG3MO4C.js.map +0 -1
  26. /package/dist/{autostart-57FQUWHF.js.map → autostart-VG7PVHTQ.js.map} +0 -0
  27. /package/dist/{chunk-NKYD7QX4.js.map → chunk-7UICNI4Q.js.map} +0 -0
  28. /package/dist/{chunk-QZNAESON.js.map → chunk-J7XFB5AQ.js.map} +0 -0
  29. /package/dist/{chunk-53N3SI24.js.map → chunk-KDISKSDP.js.map} +0 -0
  30. /package/dist/{chunk-3ZDUDCEI.js.map → chunk-U4CHGJJM.js.map} +0 -0
  31. /package/dist/{terminal-OOQQSN3D.js.map → terminal-WZJO6TAN.js.map} +0 -0
@@ -1,859 +0,0 @@
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
- import { UnicodeGraphemesAddon } from "@xterm/addon-unicode-graphemes";
256
- var { Terminal: HeadlessTerminal } = pkg;
257
- var PtyRenderSequencer = class {
258
- terminal;
259
- serializeAddon = new SerializeAddon();
260
- outputSeq = 0;
261
- disposed = false;
262
- constructor(options) {
263
- this.terminal = new HeadlessTerminal({
264
- cols: options.cols,
265
- rows: options.rows,
266
- scrollback: options.scrollback ?? 5e3,
267
- allowProposedApi: true
268
- });
269
- this.terminal.loadAddon(this.serializeAddon);
270
- this.terminal.loadAddon(new UnicodeGraphemesAddon());
271
- }
272
- get cols() {
273
- return this.terminal.cols;
274
- }
275
- get rows() {
276
- return this.terminal.rows;
277
- }
278
- /** Queues non-empty render output and returns its allocated remote event sequence. */
279
- write(data) {
280
- if (this.disposed || data.length === 0) return null;
281
- const outputSeq = ++this.outputSeq;
282
- this.terminal.write(data);
283
- return outputSeq;
284
- }
285
- /**
286
- * Allocates a resize event and queues the geometry change at its exact place in xterm's write
287
- * stream. Output queued after this call cannot be parsed using the old geometry.
288
- */
289
- resize(cols, rows) {
290
- if (this.disposed) return null;
291
- const outputSeq = ++this.outputSeq;
292
- this.terminal.write("", () => {
293
- if (this.disposed) return;
294
- this.terminal.resize(cols, rows);
295
- });
296
- return outputSeq;
297
- }
298
- /** Captures the sequence watermark now and the matching terminal state at the FIFO barrier. */
299
- captureSnapshot(onSnapshot) {
300
- if (this.disposed) return false;
301
- const outputSeq = this.outputSeq;
302
- this.terminal.write("", () => {
303
- if (this.disposed) return;
304
- onSnapshot({
305
- cols: this.terminal.cols,
306
- rows: this.terminal.rows,
307
- data: this.serializeAddon.serialize(),
308
- outputSeq
309
- });
310
- });
311
- return true;
312
- }
313
- dispose() {
314
- if (this.disposed) return;
315
- this.disposed = true;
316
- this.terminal.dispose();
317
- }
318
- };
319
-
320
- // src/common/codex-xterm-history-compat.ts
321
- var SYNC_OUTPUT_START = "\x1B[?2026h";
322
- var SYNC_OUTPUT_END = "\x1B[?2026l";
323
- var MAX_SYNC_BLOCK_CHARS = 1024 * 1024;
324
- var ALT_SCREEN_SEQUENCE_RE = /\x1b\[\?(?:47|1047|1049)([hl])/g;
325
- var HISTORY_INSERT_RE = /\x1b\[1;([1-9]\d*)r\x1b\[(\d*)S\x1b\[r\x1b\[([1-9]\d*);1H\x1b\[J/g;
326
- var CODEX_XTERM_HISTORY_COMPAT_ENV = "DEV_ANYWHERE_CODEX_XTERM_HISTORY_COMPAT";
327
- var CodexXtermHistoryCompat = class {
328
- pending = "";
329
- state = "outside";
330
- alternateScreen = false;
331
- altScanCarry = "";
332
- terminalRows;
333
- rewrittenTransactions = 0;
334
- preservedRows = 0;
335
- constructor(rows) {
336
- this.terminalRows = rows;
337
- }
338
- get stats() {
339
- return {
340
- rewrittenTransactions: this.rewrittenTransactions,
341
- preservedRows: this.preservedRows
342
- };
343
- }
344
- push(data) {
345
- if (!data) return "";
346
- this.pending += data;
347
- let output = "";
348
- while (this.pending.length > 0) {
349
- if (this.state === "buffering-sync") {
350
- const endIndex = this.pending.indexOf(SYNC_OUTPUT_END, SYNC_OUTPUT_START.length);
351
- if (endIndex === -1) {
352
- if (this.pending.length <= MAX_SYNC_BLOCK_CHARS) break;
353
- const keep2 = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);
354
- const passthrough2 = this.pending.slice(0, this.pending.length - keep2);
355
- output += passthrough2;
356
- this.scanAlternateScreen(passthrough2);
357
- this.pending = this.pending.slice(this.pending.length - keep2);
358
- this.state = "passthrough-sync";
359
- continue;
360
- }
361
- const blockEnd = endIndex + SYNC_OUTPUT_END.length;
362
- const block = this.pending.slice(0, blockEnd);
363
- this.pending = this.pending.slice(blockEnd);
364
- output += this.rewriteSynchronizedBlock(block);
365
- this.state = "outside";
366
- continue;
367
- }
368
- if (this.state === "passthrough-sync") {
369
- const endIndex = this.pending.indexOf(SYNC_OUTPUT_END);
370
- if (endIndex === -1) {
371
- const keep2 = longestSuffixPrefix(this.pending, SYNC_OUTPUT_END);
372
- const passthrough3 = this.pending.slice(0, this.pending.length - keep2);
373
- output += passthrough3;
374
- this.scanAlternateScreen(passthrough3);
375
- this.pending = this.pending.slice(this.pending.length - keep2);
376
- break;
377
- }
378
- const blockEnd = endIndex + SYNC_OUTPUT_END.length;
379
- const passthrough2 = this.pending.slice(0, blockEnd);
380
- output += passthrough2;
381
- this.scanAlternateScreen(passthrough2);
382
- this.pending = this.pending.slice(blockEnd);
383
- this.state = "outside";
384
- continue;
385
- }
386
- const startIndex = this.pending.indexOf(SYNC_OUTPUT_START);
387
- if (startIndex !== -1) {
388
- const passthrough2 = this.pending.slice(0, startIndex);
389
- output += passthrough2;
390
- this.scanAlternateScreen(passthrough2);
391
- this.pending = this.pending.slice(startIndex);
392
- this.state = "buffering-sync";
393
- continue;
394
- }
395
- const keep = longestSuffixPrefix(this.pending, SYNC_OUTPUT_START);
396
- const passthrough = this.pending.slice(0, this.pending.length - keep);
397
- output += passthrough;
398
- this.scanAlternateScreen(passthrough);
399
- this.pending = this.pending.slice(this.pending.length - keep);
400
- break;
401
- }
402
- return output;
403
- }
404
- /** Flushes an incomplete candidate byte-for-byte, for resize/exit boundaries. */
405
- flush() {
406
- const pending = this.pending;
407
- this.pending = "";
408
- this.state = "outside";
409
- this.scanAlternateScreen(pending);
410
- return pending;
411
- }
412
- setTerminalRows(rows) {
413
- this.terminalRows = rows;
414
- }
415
- rewriteSynchronizedBlock(block) {
416
- const startsInAlternateScreen = this.alternateScreen;
417
- ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
418
- const switchesScreenBuffer = ALT_SCREEN_SEQUENCE_RE.test(block);
419
- ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
420
- let rewritten = block;
421
- if (!startsInAlternateScreen && !switchesScreenBuffer) {
422
- rewritten = block.replace(
423
- HISTORY_INSERT_RE,
424
- (original, bottomRaw, countRaw, repaintRowRaw) => {
425
- const bottom = Number.parseInt(bottomRaw, 10);
426
- const parsedCount = countRaw === "" ? 1 : Number.parseInt(countRaw, 10);
427
- const count = parsedCount === 0 ? 1 : parsedCount;
428
- const repaintRow = Number.parseInt(repaintRowRaw, 10);
429
- const expectedRepaintRow = bottom - count + 1;
430
- if (!Number.isSafeInteger(bottom) || !Number.isSafeInteger(count) || !Number.isSafeInteger(repaintRow) || bottom >= this.terminalRows || count < 1 || count > bottom || repaintRow !== expectedRepaintRow) {
431
- return original;
432
- }
433
- this.rewrittenTransactions += 1;
434
- this.preservedRows += count;
435
- return `\x1B[r\x1B[999;1H${"\n".repeat(count)}\x1B[H\x1B[${repaintRow};1H\x1B[J`;
436
- }
437
- );
438
- }
439
- this.scanAlternateScreen(block);
440
- return rewritten;
441
- }
442
- scanAlternateScreen(data) {
443
- if (!data) return;
444
- const scan = this.altScanCarry + data;
445
- ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
446
- for (const match of scan.matchAll(ALT_SCREEN_SEQUENCE_RE)) {
447
- this.alternateScreen = match[1] === "h";
448
- }
449
- ALT_SCREEN_SEQUENCE_RE.lastIndex = 0;
450
- this.altScanCarry = scan.slice(-(SYNC_OUTPUT_START.length - 1));
451
- }
452
- };
453
- function createCodexXtermHistoryCompat(provider, rows, env) {
454
- if (provider !== "codex") return null;
455
- const configured = env[CODEX_XTERM_HISTORY_COMPAT_ENV]?.trim().toLowerCase();
456
- if (configured === "0" || configured === "false" || configured === "off") return null;
457
- return new CodexXtermHistoryCompat(rows);
458
- }
459
- function longestSuffixPrefix(value, marker) {
460
- const max = Math.min(value.length, marker.length - 1);
461
- for (let length = max; length > 0; length -= 1) {
462
- if (value.endsWith(marker.slice(0, length))) return length;
463
- }
464
- return 0;
465
- }
466
-
467
- // src/common/pty-synchronized-output-coalescer.ts
468
- var SYNC_OUTPUT_START2 = "\x1B[?2026h";
469
- var SYNC_OUTPUT_END2 = "\x1B[?2026l";
470
- var DEFAULT_SYNC_OUTPUT_MAX_BUFFERED_BYTES = 8 * 1024 * 1024;
471
- var DEFAULT_SYNC_OUTPUT_IDLE_TIMEOUT_MS = 2e3;
472
- var PtySynchronizedOutputCoalescer = class {
473
- emitData;
474
- maxBufferedBytes;
475
- idleTimeoutMs;
476
- setTimer;
477
- clearTimer;
478
- onOverflow;
479
- mode = "outside";
480
- parserState = "ground";
481
- stringState = null;
482
- controlSequence = "";
483
- markerEligible = false;
484
- outsidePending = "";
485
- transactionParts = [];
486
- transactionBytes = 0;
487
- idleTimer = null;
488
- disposed = false;
489
- constructor(options) {
490
- this.emitData = options.emit;
491
- this.maxBufferedBytes = options.maxBufferedBytes ?? DEFAULT_SYNC_OUTPUT_MAX_BUFFERED_BYTES;
492
- this.idleTimeoutMs = options.idleTimeoutMs ?? DEFAULT_SYNC_OUTPUT_IDLE_TIMEOUT_MS;
493
- this.setTimer = options.setTimer ?? ((callback, delayMs) => setTimeout(callback, delayMs));
494
- this.clearTimer = options.clearTimer ?? ((handle) => clearTimeout(handle));
495
- this.onOverflow = options.onOverflow;
496
- if (!Number.isSafeInteger(this.maxBufferedBytes) || this.maxBufferedBytes < 1) {
497
- throw new RangeError("maxBufferedBytes must be a positive safe integer");
498
- }
499
- if (!Number.isFinite(this.idleTimeoutMs) || this.idleTimeoutMs < 0) {
500
- throw new RangeError("idleTimeoutMs must be a non-negative finite number");
501
- }
502
- }
503
- push(data) {
504
- if (this.disposed || data.length === 0) return;
505
- let offset = 0;
506
- for (let index = 0; index < data.length; index += 1) {
507
- const marker = this.scan(data[index]);
508
- if (marker === null) continue;
509
- const segment = data.slice(offset, index + 1);
510
- if (this.mode === "outside") {
511
- if (marker !== "start") continue;
512
- const combined = this.outsidePending + segment;
513
- const markerStart = combined.length - SYNC_OUTPUT_START2.length;
514
- this.emit(combined.slice(0, markerStart));
515
- this.outsidePending = "";
516
- this.mode = "buffering";
517
- this.appendTransaction(combined.slice(markerStart));
518
- } else if (this.mode === "buffering") {
519
- this.appendTransaction(segment);
520
- if (marker === "end" && this.mode === "buffering") {
521
- this.commitTransaction();
522
- } else if (marker === "end") {
523
- this.mode = "outside";
524
- }
525
- } else {
526
- this.emit(segment);
527
- if (marker === "end") this.mode = "outside";
528
- }
529
- offset = index + 1;
530
- }
531
- const remainder = data.slice(offset);
532
- if (this.mode === "buffering") {
533
- this.appendTransaction(remainder);
534
- if (this.mode === "buffering") this.armIdleTimer();
535
- return;
536
- }
537
- if (this.mode === "passthrough") {
538
- this.emit(remainder);
539
- return;
540
- }
541
- this.outsidePending += remainder;
542
- const candidateLength = this.startCandidateLength();
543
- const emitLength = this.outsidePending.length - candidateLength;
544
- if (emitLength > 0) {
545
- this.emit(this.outsidePending.slice(0, emitLength));
546
- this.outsidePending = this.outsidePending.slice(emitLength);
547
- }
548
- if (this.outsidePending.length > 0) this.armIdleTimer();
549
- else this.clearIdleTimer();
550
- }
551
- flush() {
552
- if (this.disposed) return;
553
- this.clearIdleTimer();
554
- const wasBuffering = this.mode === "buffering";
555
- this.emit(this.outsidePending);
556
- this.outsidePending = "";
557
- this.emitTransactionParts();
558
- if (wasBuffering) {
559
- this.mode = "passthrough";
560
- } else if (this.mode === "outside") {
561
- this.disarmCurrentMarkerCandidate();
562
- }
563
- }
564
- dispose() {
565
- if (this.disposed) return;
566
- this.flush();
567
- this.disposed = true;
568
- }
569
- appendTransaction(data) {
570
- if (!data) return;
571
- const incomingBytes = Buffer.byteLength(data, "utf8");
572
- const nextBytes = this.transactionBytes + incomingBytes;
573
- if (nextBytes <= this.maxBufferedBytes) {
574
- this.transactionParts.push(data);
575
- this.transactionBytes = nextBytes;
576
- return;
577
- }
578
- this.onOverflow?.({
579
- reason: "byte-cap",
580
- maxBufferedBytes: this.maxBufferedBytes,
581
- bufferedBytes: this.transactionBytes,
582
- incomingBytes,
583
- transactionBytes: nextBytes
584
- });
585
- this.clearIdleTimer();
586
- this.emitTransactionParts();
587
- this.emit(data);
588
- this.mode = "passthrough";
589
- }
590
- commitTransaction() {
591
- this.clearIdleTimer();
592
- const transaction = this.transactionParts.join("");
593
- this.transactionParts = [];
594
- this.transactionBytes = 0;
595
- this.mode = "outside";
596
- this.emit(transaction);
597
- }
598
- emitTransactionParts() {
599
- if (this.transactionParts.length === 0) return;
600
- this.emit(this.transactionParts.join(""));
601
- this.transactionParts = [];
602
- this.transactionBytes = 0;
603
- }
604
- emit(data) {
605
- if (data) this.emitData(data);
606
- }
607
- armIdleTimer() {
608
- this.clearIdleTimer();
609
- this.idleTimer = this.setTimer(() => {
610
- this.idleTimer = null;
611
- if (this.mode === "buffering") {
612
- this.emitTransactionParts();
613
- this.mode = "passthrough";
614
- return;
615
- }
616
- if (this.mode === "outside" && this.outsidePending) {
617
- this.emit(this.outsidePending);
618
- this.outsidePending = "";
619
- this.disarmCurrentMarkerCandidate();
620
- }
621
- }, this.idleTimeoutMs);
622
- }
623
- clearIdleTimer() {
624
- if (this.idleTimer === null) return;
625
- this.clearTimer(this.idleTimer);
626
- this.idleTimer = null;
627
- }
628
- startCandidateLength() {
629
- if ((this.parserState === "escape" || this.parserState === "csi") && this.markerEligible && SYNC_OUTPUT_START2.startsWith(this.controlSequence)) {
630
- return this.controlSequence.length;
631
- }
632
- return 0;
633
- }
634
- scan(char) {
635
- if (this.parserState === "ground") {
636
- if (char === "\x1B") {
637
- this.parserState = "escape";
638
- this.controlSequence = char;
639
- this.markerEligible = true;
640
- }
641
- return null;
642
- }
643
- if (this.parserState === "escape") {
644
- if (char === "[") {
645
- this.parserState = "csi";
646
- this.controlSequence += char;
647
- } else if (char === "]") {
648
- this.enterString("osc");
649
- } else if (char === "P") {
650
- this.enterString("dcs");
651
- } else if (char === "_") {
652
- this.enterString("apc");
653
- } else if (char === "^") {
654
- this.enterString("pm");
655
- } else if (char === "X") {
656
- this.enterString("sos");
657
- } else if (char === "\x1B") {
658
- this.controlSequence = char;
659
- this.markerEligible = true;
660
- } else if (isEscapeIntermediate(char)) {
661
- this.parserState = "escape-other";
662
- this.controlSequence = "";
663
- this.markerEligible = false;
664
- } else {
665
- this.parserState = "ground";
666
- this.controlSequence = "";
667
- this.markerEligible = false;
668
- }
669
- return null;
670
- }
671
- if (this.parserState === "escape-other") {
672
- if (char === "\x1B") {
673
- this.parserState = "escape";
674
- this.controlSequence = char;
675
- this.markerEligible = true;
676
- } else if (isFinalByte(char)) {
677
- this.parserState = "ground";
678
- }
679
- return null;
680
- }
681
- if (this.parserState === "csi") {
682
- if (char === "\x1B") {
683
- this.parserState = "escape";
684
- this.controlSequence = char;
685
- this.markerEligible = true;
686
- return null;
687
- }
688
- this.controlSequence += char;
689
- if (!isFinalByte(char)) return null;
690
- const sequence = this.controlSequence;
691
- const markerEligible = this.markerEligible;
692
- this.parserState = "ground";
693
- this.controlSequence = "";
694
- this.markerEligible = false;
695
- if (markerEligible && sequence === SYNC_OUTPUT_START2) return "start";
696
- if (markerEligible && sequence === SYNC_OUTPUT_END2) return "end";
697
- return null;
698
- }
699
- if (this.parserState === "string-escape") {
700
- if (char === "\\") {
701
- this.parserState = "ground";
702
- this.stringState = null;
703
- } else if (char !== "\x1B") {
704
- this.parserState = this.stringState ?? "ground";
705
- }
706
- return null;
707
- }
708
- if (char === "\x1B") {
709
- this.stringState = this.parserState;
710
- this.parserState = "string-escape";
711
- } else if (char === "\x9C" || this.parserState === "osc" && char === "\x07") {
712
- this.parserState = "ground";
713
- this.stringState = null;
714
- }
715
- return null;
716
- }
717
- enterString(state) {
718
- this.parserState = state;
719
- this.stringState = state;
720
- this.controlSequence = "";
721
- this.markerEligible = false;
722
- }
723
- disarmCurrentMarkerCandidate() {
724
- if (this.parserState === "escape" || this.parserState === "csi") {
725
- this.markerEligible = false;
726
- }
727
- }
728
- };
729
- function isFinalByte(char) {
730
- const code = char.charCodeAt(0);
731
- return code >= 64 && code <= 126;
732
- }
733
- function isEscapeIntermediate(char) {
734
- const code = char.charCodeAt(0);
735
- return code >= 32 && code <= 47;
736
- }
737
-
738
- // src/common/pty-input-compat.ts
739
- var WIN32_ESCAPE = "\x1B[27;1;27;1;0;1_\x1B[27;1;27;0;0;1_";
740
- var INPUT_TAIL_LIMIT = 80;
741
- function createPtyInputCompat(provider, platform = process.platform) {
742
- let inputTail = "";
743
- let sawWin32Input = false;
744
- let inBracketedPaste = false;
745
- const markers = /\x1b\[(?:200~|201~|(?:\d{0,10};){5}\d{0,10}_)/g;
746
- function observe(data) {
747
- if (platform !== "win32") return;
748
- const input = inputTail + data;
749
- markers.lastIndex = 0;
750
- let consumed = 0;
751
- for (let match = markers.exec(input); match; match = markers.exec(input)) {
752
- if (match[0] === "\x1B[200~") {
753
- inBracketedPaste = true;
754
- } else if (match[0] === "\x1B[201~") {
755
- inBracketedPaste = false;
756
- } else if (!inBracketedPaste) {
757
- sawWin32Input = true;
758
- }
759
- consumed = markers.lastIndex;
760
- }
761
- inputTail = input.slice(consumed).slice(-INPUT_TAIL_LIMIT);
762
- }
763
- function encodeRemote(data) {
764
- const wasInBracketedPaste = inBracketedPaste;
765
- observe(data);
766
- if (platform !== "win32" || wasInBracketedPaste) return data;
767
- if (provider === "codex" && data === "\n") return "\x1B\r";
768
- if (sawWin32Input && data === "\x1B") return WIN32_ESCAPE;
769
- return data;
770
- }
771
- return { observe, encodeRemote };
772
- }
773
-
774
- // src/ipc/terminal-admission.ts
775
- var TERMINAL_ADMISSION_VERSION = 1;
776
- var TERMINAL_ADMISSION_FRAME_MAX_BYTES = 16 * 1024;
777
- var ADMISSION_TEXT_MAX_LENGTH = 1024;
778
- function isRecord(value) {
779
- return value !== null && typeof value === "object" && !Array.isArray(value);
780
- }
781
- function isProtocolVersion(value) {
782
- return typeof value === "number" && Number.isSafeInteger(value) && value >= 0;
783
- }
784
- function isBoundedText(value, allowEmpty = false) {
785
- return typeof value === "string" && value.length <= ADMISSION_TEXT_MAX_LENGTH && (allowEmpty || value.length > 0);
786
- }
787
- function isTerminalAdmissionRequestCandidate(value) {
788
- return isRecord(value) && value.type === "terminal_admission_request";
789
- }
790
- function parseTerminalAdmissionRequest(value) {
791
- if (!isRecord(value) || value.type !== "terminal_admission_request") return null;
792
- if (value.admissionVersion !== TERMINAL_ADMISSION_VERSION) return null;
793
- if (!isProtocolVersion(value.terminalProtocolVersion)) return null;
794
- if (value.clientKind !== "local-terminal" && value.clientKind !== "terminal-worker") {
795
- return null;
796
- }
797
- if (value.sessionId !== void 0 && !isBoundedText(value.sessionId)) return null;
798
- if (value.clientKind === "terminal-worker" && value.sessionId === void 0) return null;
799
- return {
800
- type: "terminal_admission_request",
801
- admissionVersion: TERMINAL_ADMISSION_VERSION,
802
- terminalProtocolVersion: value.terminalProtocolVersion,
803
- clientKind: value.clientKind,
804
- ...value.sessionId !== void 0 ? { sessionId: value.sessionId } : {}
805
- };
806
- }
807
- function parseTerminalAdmissionResponse(value) {
808
- if (!isRecord(value) || value.type !== "terminal_admission_response") return null;
809
- if (value.admissionVersion !== TERMINAL_ADMISSION_VERSION) return null;
810
- if (!isProtocolVersion(value.terminalProtocolVersion)) return null;
811
- if (value.status === "accepted") {
812
- return {
813
- type: "terminal_admission_response",
814
- admissionVersion: TERMINAL_ADMISSION_VERSION,
815
- status: "accepted",
816
- terminalProtocolVersion: value.terminalProtocolVersion
817
- };
818
- }
819
- 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)) {
820
- return null;
821
- }
822
- return {
823
- type: "terminal_admission_response",
824
- admissionVersion: TERMINAL_ADMISSION_VERSION,
825
- status: "retired",
826
- terminalProtocolVersion: value.terminalProtocolVersion,
827
- code: value.code,
828
- action: value.action,
829
- message: value.message
830
- };
831
- }
832
- function serializeTerminalAdmissionMessage(message) {
833
- return `${JSON.stringify(message)}
834
- `;
835
- }
836
-
837
- export {
838
- createPtyInputCompat,
839
- createIdleChecker,
840
- ReconnectSupervisor,
841
- TERMINAL_ADMISSION_VERSION,
842
- TERMINAL_ADMISSION_FRAME_MAX_BYTES,
843
- isTerminalAdmissionRequestCandidate,
844
- parseTerminalAdmissionRequest,
845
- parseTerminalAdmissionResponse,
846
- serializeTerminalAdmissionMessage,
847
- extractOscSequences,
848
- OscWorkingDirectoryTracker,
849
- appendPtySemanticTextTail,
850
- extractTextSignals,
851
- extractOscSignals,
852
- shouldReleaseTextApprovalOnInput,
853
- decidePtySemanticTransition,
854
- shouldStartPtyTurnOnInput,
855
- PtyRenderSequencer,
856
- createCodexXtermHistoryCompat,
857
- PtySynchronizedOutputCoalescer
858
- };
859
- //# sourceMappingURL=chunk-UXNSX5GO.js.map