billion-context 0.1.21 → 0.1.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -9,8 +9,8 @@ import { dirname } from "path";
9
9
  import { homedir } from "os";
10
10
  import path from "path";
11
11
  function xdg(envVar, fallback) {
12
- const v = process.env[envVar];
13
- if (v && v.length > 0) return path.resolve(v);
12
+ const v2 = process.env[envVar];
13
+ if (v2 && v2.length > 0) return path.resolve(v2);
14
14
  return path.join(homedir(), fallback);
15
15
  }
16
16
  function configDir() {
@@ -57,9 +57,9 @@ function open(pathStr) {
57
57
  }
58
58
  } catch {
59
59
  }
60
- const s = createWriteStream(pathStr, { flags: "a" });
60
+ const s3 = createWriteStream(pathStr, { flags: "a" });
61
61
  bytesWritten = existingSize;
62
- return s;
62
+ return s3;
63
63
  }
64
64
  function rotate(pathStr) {
65
65
  try {
@@ -78,8 +78,8 @@ function configureLogger(file) {
78
78
  return file;
79
79
  }
80
80
  var log = (level, msg2) => {
81
- const ts = (/* @__PURE__ */ new Date()).toISOString();
82
- const line = `${ts} [${level}] ${msg2}
81
+ const ts2 = (/* @__PURE__ */ new Date()).toISOString();
82
+ const line = `${ts2} [${level}] ${msg2}
83
83
  `;
84
84
  process.stderr.write(line);
85
85
  if (stream && logPath) {
@@ -139,8 +139,8 @@ function resolveContextLimit(routes, provider, model) {
139
139
  if (provider) {
140
140
  const route = routes[provider];
141
141
  if (route?.models) {
142
- const m = route.models[model];
143
- if (m?.context && m.context > 0) return m.context;
142
+ const m2 = route.models[model];
143
+ if (m2?.context && m2.context > 0) return m2.context;
144
144
  }
145
145
  }
146
146
  return lookupContextLimit(model);
@@ -155,16 +155,16 @@ function loadOptions(env = process.env) {
155
155
  if (routesPath) {
156
156
  const parsed = safeReadJson(routesPath);
157
157
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
158
- for (const [k, v] of Object.entries(parsed)) {
159
- const route = parseRouteEntry(v);
160
- if (route) routes[k] = route;
158
+ for (const [k2, v2] of Object.entries(parsed)) {
159
+ const route = parseRouteEntry(v2);
160
+ if (route) routes[k2] = route;
161
161
  }
162
162
  }
163
163
  }
164
164
  if (fileConfig.providers) {
165
- for (const [k, v] of Object.entries(fileConfig.providers)) {
166
- const route = parseRouteEntry(v);
167
- if (route && !routes[k]) routes[k] = route;
165
+ for (const [k2, v2] of Object.entries(fileConfig.providers)) {
166
+ const route = parseRouteEntry(v2);
167
+ if (route && !routes[k2]) routes[k2] = route;
168
168
  }
169
169
  }
170
170
  const modelContextLimit = parseInt(env.ACP_MODEL_CONTEXT_LIMIT ?? `${fileConfig.modelContextLimit ?? 2e5}`, 10);
@@ -200,23 +200,23 @@ var TEMPLATE_CONFIG = `{
200
200
  }
201
201
  }`;
202
202
  function ensureConfigTemplate() {
203
- const p = configFile();
204
- if (existsSync(p)) return false;
203
+ const p2 = configFile();
204
+ if (existsSync(p2)) return false;
205
205
  try {
206
- mkdirSync2(dirname(p), { recursive: true });
207
- writeFileSync(p, TEMPLATE_CONFIG + "\n", "utf8");
208
- log("info", `[acp-config] created empty config at ${p} \u2014 add your providers (see README Quickstart), then restart`);
206
+ mkdirSync2(dirname(p2), { recursive: true });
207
+ writeFileSync(p2, TEMPLATE_CONFIG + "\n", "utf8");
208
+ log("info", `[acp-config] created empty config at ${p2} \u2014 add your providers (see README Quickstart), then restart`);
209
209
  return true;
210
210
  } catch {
211
211
  return false;
212
212
  }
213
213
  }
214
- function parseRouteEntry(v) {
215
- if (typeof v === "string" && v.length > 0) {
216
- return { url: v.replace(/\/$/, "") };
214
+ function parseRouteEntry(v2) {
215
+ if (typeof v2 === "string" && v2.length > 0) {
216
+ return { url: v2.replace(/\/$/, "") };
217
217
  }
218
- if (v && typeof v === "object" && !Array.isArray(v) && typeof v.url === "string" && v.url.length > 0) {
219
- const obj = v;
218
+ if (v2 && typeof v2 === "object" && !Array.isArray(v2) && typeof v2.url === "string" && v2.url.length > 0) {
219
+ const obj = v2;
220
220
  return { url: obj.url.replace(/\/$/, ""), models: obj.models };
221
221
  }
222
222
  return void 0;
@@ -245,12 +245,12 @@ async function fetchWithTimeout(url, init, timeoutMs = UPSTREAM_TIMEOUT_MS) {
245
245
 
246
246
  // src/util.ts
247
247
  import { createHash } from "crypto";
248
- function hashId(s) {
249
- return createHash("sha256").update(s, "utf8").digest("hex").slice(0, 16);
248
+ function hashId(s3) {
249
+ return createHash("sha256").update(s3, "utf8").digest("hex").slice(0, 16);
250
250
  }
251
- function safeJsonParse(s) {
251
+ function safeJsonParse(s3) {
252
252
  try {
253
- return s ? JSON.parse(s) : {};
253
+ return s3 ? JSON.parse(s3) : {};
254
254
  } catch {
255
255
  return {};
256
256
  }
@@ -274,11 +274,11 @@ var ClusterCounter = class {
274
274
  function extractSystem(system) {
275
275
  if (!system) return "";
276
276
  if (typeof system === "string") return system;
277
- return system.map((b) => b.text).join("\n\n");
277
+ return system.map((b2) => b2.text).join("\n\n");
278
278
  }
279
279
  function buildSystem(text, original) {
280
280
  if (Array.isArray(original) && original.length > 0) {
281
- const ccBlock = original.find((b) => b.cache_control);
281
+ const ccBlock = original.find((b2) => b2.cache_control);
282
282
  return [{ type: "text", text, ...ccBlock ? { cache_control: ccBlock.cache_control } : {} }];
283
283
  }
284
284
  return text;
@@ -287,56 +287,56 @@ function anthropicToCore(body) {
287
287
  const msgs = [];
288
288
  const cacheControls = /* @__PURE__ */ new Map();
289
289
  const clusters = new ClusterCounter();
290
- for (const m of body.messages) {
291
- const blocks = typeof m.content === "string" ? [{ type: "text", text: m.content }] : m.content;
292
- for (const b of blocks) {
293
- switch (b.type) {
290
+ for (const m2 of body.messages) {
291
+ const blocks = typeof m2.content === "string" ? [{ type: "text", text: m2.content }] : m2.content;
292
+ for (const b2 of blocks) {
293
+ switch (b2.type) {
294
294
  case "text": {
295
- const base = deriveMessageId(m.role, "text", b.text);
295
+ const base = deriveMessageId(m2.role, "text", b2.text);
296
296
  const id = clusters.next(base);
297
- msgs.push({ id, role: m.role, contentType: "text", text: b.text });
298
- if (b.cache_control) cacheControls.set(id, b.cache_control);
297
+ msgs.push({ id, role: m2.role, contentType: "text", text: b2.text });
298
+ if (b2.cache_control) cacheControls.set(id, b2.cache_control);
299
299
  break;
300
300
  }
301
301
  case "tool_use": {
302
- const base = deriveMessageId("assistant", "tool-call", safeStringify(b.input), {
303
- toolCallId: b.id,
304
- toolName: b.name
302
+ const base = deriveMessageId("assistant", "tool-call", safeStringify(b2.input), {
303
+ toolCallId: b2.id,
304
+ toolName: b2.name
305
305
  });
306
306
  const id = clusters.next(base);
307
307
  msgs.push({
308
308
  id,
309
309
  role: "assistant",
310
310
  contentType: "tool-call",
311
- toolName: b.name,
312
- toolCallId: b.id,
313
- text: safeStringify(b.input)
311
+ toolName: b2.name,
312
+ toolCallId: b2.id,
313
+ text: safeStringify(b2.input)
314
314
  });
315
- if (b.cache_control) cacheControls.set(id, b.cache_control);
315
+ if (b2.cache_control) cacheControls.set(id, b2.cache_control);
316
316
  break;
317
317
  }
318
318
  case "tool_result": {
319
- const text = typeof b.content === "string" ? b.content : b.content.map((c) => c.text).join("\n");
320
- const base = deriveMessageId("tool", "tool-result", text, { toolCallId: b.tool_use_id });
319
+ const text = typeof b2.content === "string" ? b2.content : b2.content.map((c) => c.text).join("\n");
320
+ const base = deriveMessageId("tool", "tool-result", text, { toolCallId: b2.tool_use_id });
321
321
  const id = clusters.next(base);
322
322
  msgs.push({
323
323
  id,
324
324
  role: "tool",
325
325
  contentType: "tool-result",
326
- toolCallId: b.tool_use_id,
326
+ toolCallId: b2.tool_use_id,
327
327
  text
328
328
  });
329
- if (b.cache_control) cacheControls.set(id, b.cache_control);
329
+ if (b2.cache_control) cacheControls.set(id, b2.cache_control);
330
330
  break;
331
331
  }
332
332
  case "thinking": {
333
- const base = deriveMessageId("assistant", "reasoning", b.thinking);
334
- msgs.push({ id: clusters.next(base), role: "assistant", contentType: "reasoning", text: b.thinking });
333
+ const base = deriveMessageId("assistant", "reasoning", b2.thinking);
334
+ msgs.push({ id: clusters.next(base), role: "assistant", contentType: "reasoning", text: b2.thinking });
335
335
  break;
336
336
  }
337
337
  case "image": {
338
- const base = deriveMessageId(m.role, "text", "[image]");
339
- msgs.push({ id: clusters.next(base), role: m.role, contentType: "text", text: "[image]" });
338
+ const base = deriveMessageId(m2.role, "text", "[image]");
339
+ msgs.push({ id: clusters.next(base), role: m2.role, contentType: "text", text: "[image]" });
340
340
  break;
341
341
  }
342
342
  }
@@ -354,38 +354,38 @@ function coreToAnthropic(messages, cacheControls) {
354
354
  current = null;
355
355
  };
356
356
  const cc = (id) => {
357
- const v = cacheControls?.get(id);
358
- return v ? { cache_control: v } : {};
357
+ const v2 = cacheControls?.get(id);
358
+ return v2 ? { cache_control: v2 } : {};
359
359
  };
360
- for (const m of messages) {
361
- const target = m.role === "assistant" ? "assistant" : "user";
360
+ for (const m2 of messages) {
361
+ const target = m2.role === "assistant" ? "assistant" : "user";
362
362
  if (!current || current.role !== target) {
363
363
  flush();
364
364
  current = { role: target, blocks: [] };
365
365
  }
366
- switch (m.contentType) {
366
+ switch (m2.contentType) {
367
367
  case "text":
368
- current.blocks.push({ type: "text", text: m.text ?? "", ...cc(m.id) });
368
+ current.blocks.push({ type: "text", text: m2.text ?? "", ...cc(m2.id) });
369
369
  break;
370
370
  case "tool-call":
371
371
  current.blocks.push({
372
372
  type: "tool_use",
373
- id: m.toolCallId ?? `call_${m.id}`,
374
- name: m.toolName ?? "unknown",
375
- input: safeParse(m.text),
376
- ...cc(m.id)
373
+ id: m2.toolCallId ?? `call_${m2.id}`,
374
+ name: m2.toolName ?? "unknown",
375
+ input: safeParse(m2.text),
376
+ ...cc(m2.id)
377
377
  });
378
378
  break;
379
379
  case "tool-result":
380
380
  current.blocks.push({
381
381
  type: "tool_result",
382
- tool_use_id: m.toolCallId ?? "",
383
- content: m.text ?? "",
384
- ...cc(m.id)
382
+ tool_use_id: m2.toolCallId ?? "",
383
+ content: m2.text ?? "",
384
+ ...cc(m2.id)
385
385
  });
386
386
  break;
387
387
  case "reasoning":
388
- current.blocks.push({ type: "thinking", thinking: m.text ?? "" });
388
+ current.blocks.push({ type: "thinking", thinking: m2.text ?? "" });
389
389
  break;
390
390
  }
391
391
  }
@@ -394,21 +394,21 @@ function coreToAnthropic(messages, cacheControls) {
394
394
  }
395
395
  function conversationSignalAnthropic(body, headerValue2) {
396
396
  if (headerValue2 && headerValue2.trim()) return headerValue2.trim();
397
- const firstUser = body.messages.find((m) => m.role === "user");
397
+ const firstUser = body.messages.find((m2) => m2.role === "user");
398
398
  const seed = firstUser ? JSON.stringify(firstUser.content).slice(0, 200) : "default";
399
399
  return hashId(seed);
400
400
  }
401
- function safeStringify(v) {
401
+ function safeStringify(v2) {
402
402
  try {
403
- return JSON.stringify(v ?? {});
403
+ return JSON.stringify(v2 ?? {});
404
404
  } catch {
405
405
  return "{}";
406
406
  }
407
407
  }
408
- function safeParse(s) {
409
- if (!s) return {};
408
+ function safeParse(s3) {
409
+ if (!s3) return {};
410
410
  try {
411
- return JSON.parse(s);
411
+ return JSON.parse(s3);
412
412
  } catch {
413
413
  return {};
414
414
  }
@@ -418,27 +418,27 @@ function safeParse(s) {
418
418
  function openaiToCore(body) {
419
419
  const msgs = [];
420
420
  const clusters = new ClusterCounter();
421
- for (const m of body.messages) {
422
- switch (m.role) {
421
+ for (const m2 of body.messages) {
422
+ switch (m2.role) {
423
423
  case "system":
424
424
  case "developer": {
425
- const base = deriveMessageId(m.role, "text", stringContent(m.content));
426
- msgs.push({ id: clusters.next(base), role: "system", contentType: "text", text: stringContent(m.content) });
425
+ const base = deriveMessageId(m2.role, "text", stringContent(m2.content));
426
+ msgs.push({ id: clusters.next(base), role: "system", contentType: "text", text: stringContent(m2.content) });
427
427
  break;
428
428
  }
429
429
  case "user": {
430
- const base = deriveMessageId("user", "text", stringContent(m.content));
431
- msgs.push({ id: clusters.next(base), role: "user", contentType: "text", text: stringContent(m.content) });
430
+ const base = deriveMessageId("user", "text", stringContent(m2.content));
431
+ msgs.push({ id: clusters.next(base), role: "user", contentType: "text", text: stringContent(m2.content) });
432
432
  break;
433
433
  }
434
434
  case "assistant": {
435
- const text = stringContent(m.content);
435
+ const text = stringContent(m2.content);
436
436
  if (text) {
437
437
  const base = deriveMessageId("assistant", "text", text);
438
438
  msgs.push({ id: clusters.next(base), role: "assistant", contentType: "text", text });
439
439
  }
440
- if (Array.isArray(m.tool_calls)) {
441
- for (const tc of m.tool_calls) {
440
+ if (Array.isArray(m2.tool_calls)) {
441
+ for (const tc of m2.tool_calls) {
442
442
  const base = deriveMessageId("assistant", "tool-call", tc.function.arguments ?? "", {
443
443
  toolCallId: tc.id,
444
444
  toolName: tc.function.name
@@ -456,15 +456,15 @@ function openaiToCore(body) {
456
456
  break;
457
457
  }
458
458
  case "tool": {
459
- const base = deriveMessageId("tool", "tool-result", stringContent(m.content), {
460
- toolCallId: m.tool_call_id ?? ""
459
+ const base = deriveMessageId("tool", "tool-result", stringContent(m2.content), {
460
+ toolCallId: m2.tool_call_id ?? ""
461
461
  });
462
462
  msgs.push({
463
463
  id: clusters.next(base),
464
464
  role: "tool",
465
465
  contentType: "tool-result",
466
- toolCallId: m.tool_call_id ?? "",
467
- text: stringContent(m.content)
466
+ toolCallId: m2.tool_call_id ?? "",
467
+ text: stringContent(m2.content)
468
468
  });
469
469
  break;
470
470
  }
@@ -488,26 +488,26 @@ function coreToOpenai(messages) {
488
488
  }
489
489
  pending = null;
490
490
  };
491
- for (const m of messages) {
492
- if (m.role === "assistant") {
491
+ for (const m2 of messages) {
492
+ if (m2.role === "assistant") {
493
493
  if (!pending) pending = { text: null, toolCalls: [] };
494
- if (m.contentType === "text") {
495
- pending.text = (pending.text ?? "") + (m.text ?? "");
496
- } else if (m.contentType === "tool-call") {
494
+ if (m2.contentType === "text") {
495
+ pending.text = (pending.text ?? "") + (m2.text ?? "");
496
+ } else if (m2.contentType === "tool-call") {
497
497
  pending.toolCalls.push({
498
- id: m.toolCallId ?? `call_${m.id}`,
498
+ id: m2.toolCallId ?? `call_${m2.id}`,
499
499
  type: "function",
500
- function: { name: m.toolName ?? "unknown", arguments: m.text ?? "" }
500
+ function: { name: m2.toolName ?? "unknown", arguments: m2.text ?? "" }
501
501
  });
502
502
  }
503
503
  } else {
504
504
  flush();
505
- if (m.role === "system") {
506
- out.push({ role: "system", content: m.text ?? "" });
507
- } else if (m.role === "user") {
508
- out.push({ role: "user", content: m.text ?? "" });
509
- } else if (m.role === "tool") {
510
- out.push({ role: "tool", tool_call_id: m.toolCallId ?? "", content: m.text ?? "" });
505
+ if (m2.role === "system") {
506
+ out.push({ role: "system", content: m2.text ?? "" });
507
+ } else if (m2.role === "user") {
508
+ out.push({ role: "user", content: m2.text ?? "" });
509
+ } else if (m2.role === "tool") {
510
+ out.push({ role: "tool", tool_call_id: m2.toolCallId ?? "", content: m2.text ?? "" });
511
511
  }
512
512
  }
513
513
  }
@@ -531,7 +531,7 @@ ${extra}` : extra;
531
531
  }
532
532
  function conversationSignalOpenai(body, headerValue2) {
533
533
  if (headerValue2 && headerValue2.trim()) return headerValue2.trim();
534
- const firstUser = body.messages.find((m) => m.role === "user");
534
+ const firstUser = body.messages.find((m2) => m2.role === "user");
535
535
  const seed = firstUser ? stringContent(firstUser.content).slice(0, 200) : "default";
536
536
  return hashId(seed);
537
537
  }
@@ -539,7 +539,7 @@ function stringContent(content) {
539
539
  if (content == null) return "";
540
540
  if (typeof content === "string") return content;
541
541
  if (Array.isArray(content)) {
542
- return content.map((p) => typeof p === "string" ? p : p.type === "text" ? p.text ?? "" : "").join("\n");
542
+ return content.map((p2) => typeof p2 === "string" ? p2 : p2.type === "text" ? p2.text ?? "" : "").join("\n");
543
543
  }
544
544
  return "";
545
545
  }
@@ -557,12 +557,12 @@ var OPAQUE_ITEM_TYPES = /* @__PURE__ */ new Set([
557
557
  "mcp_list_tools",
558
558
  "mcp_call"
559
559
  ]);
560
- function isOpaqueItem(it) {
561
- return OPAQUE_ITEM_TYPES.has(it.type);
560
+ function isOpaqueItem(it2) {
561
+ return OPAQUE_ITEM_TYPES.has(it2.type);
562
562
  }
563
- function partText(p) {
564
- if (p.type === "input_text" || p.type === "output_text") {
565
- const t = p.text;
563
+ function partText(p2) {
564
+ if (p2.type === "input_text" || p2.type === "output_text") {
565
+ const t = p2.text;
566
566
  return typeof t === "string" ? t : "";
567
567
  }
568
568
  return "";
@@ -589,22 +589,22 @@ function responsesToCore(body) {
589
589
  idx++;
590
590
  return { msgs, systemParts, preamble, customToolCallIds };
591
591
  }
592
- for (const it of items) {
593
- if (isOpaqueItem(it)) {
594
- preamble.push(it);
592
+ for (const it2 of items) {
593
+ if (isOpaqueItem(it2)) {
594
+ preamble.push(it2);
595
595
  continue;
596
596
  }
597
- switch (it.type) {
597
+ switch (it2.type) {
598
598
  case "message": {
599
- const m = it;
600
- const text = messageContent(m.content);
601
- if (m.role === "system" || m.role === "developer") {
599
+ const m2 = it2;
600
+ const text = messageContent(m2.content);
601
+ if (m2.role === "system" || m2.role === "developer") {
602
602
  systemParts.push(text);
603
- } else if (m.role === "user") {
603
+ } else if (m2.role === "user") {
604
604
  const base = deriveMessageId("user", "text", text);
605
605
  msgs.push({ id: clusters.next(base), role: "user", contentType: "text", text });
606
606
  idx++;
607
- } else if (m.role === "assistant") {
607
+ } else if (m2.role === "assistant") {
608
608
  if (text) {
609
609
  const base = deriveMessageId("assistant", "text", text);
610
610
  msgs.push({ id: clusters.next(base), role: "assistant", contentType: "text", text });
@@ -614,7 +614,7 @@ function responsesToCore(body) {
614
614
  break;
615
615
  }
616
616
  case "function_call": {
617
- const fc = it;
617
+ const fc = it2;
618
618
  const base = deriveMessageId("assistant", "tool-call", fc.arguments ?? "", {
619
619
  toolCallId: fc.call_id,
620
620
  toolName: fc.name
@@ -631,7 +631,7 @@ function responsesToCore(body) {
631
631
  break;
632
632
  }
633
633
  case "function_call_output": {
634
- const fco = it;
634
+ const fco = it2;
635
635
  const outText = typeof fco.output === "string" ? fco.output : JSON.stringify(fco.output);
636
636
  const base = deriveMessageId("tool", "tool-result", outText, { toolCallId: fco.call_id });
637
637
  msgs.push({
@@ -645,7 +645,7 @@ function responsesToCore(body) {
645
645
  break;
646
646
  }
647
647
  case "custom_tool_call": {
648
- const ctc = it;
648
+ const ctc = it2;
649
649
  const callId = ctc.call_id ?? `call_${idx}`;
650
650
  customToolCallIds.add(callId);
651
651
  const argText = ctc.input ?? ctc.arguments ?? "";
@@ -665,7 +665,7 @@ function responsesToCore(body) {
665
665
  break;
666
666
  }
667
667
  case "custom_tool_call_output": {
668
- const ctco = it;
668
+ const ctco = it2;
669
669
  const callId = ctco.call_id ?? `call_${idx}`;
670
670
  customToolCallIds.add(callId);
671
671
  const outText = typeof ctco.output === "string" ? ctco.output : JSON.stringify(ctco.output ?? "");
@@ -681,7 +681,7 @@ function responsesToCore(body) {
681
681
  break;
682
682
  }
683
683
  default:
684
- preamble.push(it);
684
+ preamble.push(it2);
685
685
  break;
686
686
  }
687
687
  }
@@ -689,46 +689,46 @@ function responsesToCore(body) {
689
689
  }
690
690
  function coreToResponses(messages, customToolCallIds = /* @__PURE__ */ new Set()) {
691
691
  const out = [];
692
- for (const m of messages) {
693
- if (m.role === "system") {
694
- out.push({ type: "message", role: "developer", content: m.text ?? "" });
695
- } else if (m.role === "user") {
696
- out.push({ type: "message", role: "user", content: m.text ?? "" });
697
- } else if (m.role === "assistant") {
698
- if (m.contentType === "text") {
699
- out.push({ type: "message", role: "assistant", content: m.text ?? "" });
700
- } else if (m.contentType === "tool-call") {
701
- const callId = m.toolCallId ?? `call_${m.id}`;
692
+ for (const m2 of messages) {
693
+ if (m2.role === "system") {
694
+ out.push({ type: "message", role: "developer", content: m2.text ?? "" });
695
+ } else if (m2.role === "user") {
696
+ out.push({ type: "message", role: "user", content: m2.text ?? "" });
697
+ } else if (m2.role === "assistant") {
698
+ if (m2.contentType === "text") {
699
+ out.push({ type: "message", role: "assistant", content: m2.text ?? "" });
700
+ } else if (m2.contentType === "tool-call") {
701
+ const callId = m2.toolCallId ?? `call_${m2.id}`;
702
702
  if (customToolCallIds.has(callId)) {
703
703
  out.push({
704
704
  type: "custom_tool_call",
705
705
  call_id: callId,
706
- name: m.toolName ?? "unknown",
707
- input: m.text ?? "",
706
+ name: m2.toolName ?? "unknown",
707
+ input: m2.text ?? "",
708
708
  status: "completed"
709
709
  });
710
710
  } else {
711
711
  out.push({
712
712
  type: "function_call",
713
713
  call_id: callId,
714
- name: m.toolName ?? "unknown",
715
- arguments: m.text ?? ""
714
+ name: m2.toolName ?? "unknown",
715
+ arguments: m2.text ?? ""
716
716
  });
717
717
  }
718
718
  }
719
- } else if (m.role === "tool") {
720
- const callId = m.toolCallId ?? "";
719
+ } else if (m2.role === "tool") {
720
+ const callId = m2.toolCallId ?? "";
721
721
  if (customToolCallIds.has(callId)) {
722
722
  out.push({
723
723
  type: "custom_tool_call_output",
724
724
  call_id: callId,
725
- output: m.text ?? ""
725
+ output: m2.text ?? ""
726
726
  });
727
727
  } else {
728
728
  out.push({
729
729
  type: "function_call_output",
730
730
  call_id: callId,
731
- output: m.text ?? ""
731
+ output: m2.text ?? ""
732
732
  });
733
733
  }
734
734
  }
@@ -971,11 +971,11 @@ var SessionStore = class {
971
971
  for (const timer2 of this.timers.values()) clearTimeout(timer2);
972
972
  this.timers.clear();
973
973
  const pending = [];
974
- for (const s of sessions2) {
975
- if (!dirty.has(s.id)) continue;
974
+ for (const s3 of sessions2) {
975
+ if (!dirty.has(s3.id)) continue;
976
976
  pending.push(
977
- this.writeNow(s).catch((e) => {
978
- this.log("error", `[persist] shutdown flush failed for ${s.id}: ${msg(e)}`);
977
+ this.writeNow(s3).catch((e) => {
978
+ this.log("error", `[persist] shutdown flush failed for ${s3.id}: ${msg(e)}`);
979
979
  })
980
980
  );
981
981
  }
@@ -1061,8 +1061,8 @@ function persistEnabled() {
1061
1061
  if (env === "0" || env === "false") return false;
1062
1062
  return true;
1063
1063
  }
1064
- function defaultLogger(level, m) {
1065
- log(level, m);
1064
+ function defaultLogger(level, m2) {
1065
+ log(level, m2);
1066
1066
  }
1067
1067
  var _store = null;
1068
1068
  function getStore() {
@@ -1083,13 +1083,13 @@ async function initSessions() {
1083
1083
  if (!store.enabled) return;
1084
1084
  const loaded = await store.loadAll();
1085
1085
  if (loaded.size > MAX_SESSIONS) {
1086
- const entries = [...loaded.entries()].sort((a, b) => (b[1].createdAt ?? 0) - (a[1].createdAt ?? 0));
1087
- for (const [id, s] of entries) {
1086
+ const entries = [...loaded.entries()].sort((a, b2) => (b2[1].createdAt ?? 0) - (a[1].createdAt ?? 0));
1087
+ for (const [id, s3] of entries) {
1088
1088
  if (sessions.size >= MAX_SESSIONS) break;
1089
- sessions.set(id, s);
1089
+ sessions.set(id, s3);
1090
1090
  }
1091
1091
  } else {
1092
- for (const [id, s] of loaded) sessions.set(id, s);
1092
+ for (const [id, s3] of loaded) sessions.set(id, s3);
1093
1093
  }
1094
1094
  }
1095
1095
  function getSession(id, meta) {
@@ -1146,7 +1146,7 @@ async function withSessionLock(session, fn) {
1146
1146
  }
1147
1147
  }
1148
1148
  function listSessions() {
1149
- return [...sessions.values()].sort((a, b) => b.lastSeen - a.lastSeen);
1149
+ return [...sessions.values()].sort((a, b2) => b2.lastSeen - a.lastSeen);
1150
1150
  }
1151
1151
  function markDirty(session) {
1152
1152
  getStore().scheduleSave(session);
@@ -1157,17 +1157,17 @@ function cacheBlockContent(session, blockId, content) {
1157
1157
  function evictOldest() {
1158
1158
  let oldestId;
1159
1159
  let oldestSeen = Infinity;
1160
- for (const [id, s2] of sessions) {
1161
- if (s2.inFlight > 0) continue;
1162
- if (s2.lastSeen < oldestSeen) {
1163
- oldestSeen = s2.lastSeen;
1160
+ for (const [id, s4] of sessions) {
1161
+ if (s4.inFlight > 0) continue;
1162
+ if (s4.lastSeen < oldestSeen) {
1163
+ oldestSeen = s4.lastSeen;
1164
1164
  oldestId = id;
1165
1165
  }
1166
1166
  }
1167
1167
  if (!oldestId) return;
1168
- const s = sessions.get(oldestId);
1169
- const ok = getStore().flushSync(s);
1170
- if (!ok && !s.persisted) {
1168
+ const s3 = sessions.get(oldestId);
1169
+ const ok = getStore().flushSync(s3);
1170
+ if (!ok && !s3.persisted) {
1171
1171
  return;
1172
1172
  }
1173
1173
  sessions.delete(oldestId);
@@ -1231,8 +1231,8 @@ function toRange(r) {
1231
1231
  return { startRef, endRef, summary, ...topic ? { topic } : {} };
1232
1232
  }
1233
1233
  function pick(r, ...keys) {
1234
- for (const k of keys) {
1235
- if (r[k] !== void 0) return r[k];
1234
+ for (const k2 of keys) {
1235
+ if (r[k2] !== void 0) return r[k2];
1236
1236
  }
1237
1237
  return void 0;
1238
1238
  }
@@ -1449,46 +1449,46 @@ function routeEvent(ev, blocks, ctx, markConverted, markRealToolUse, getConverte
1449
1449
  }
1450
1450
  if (t === "content_block_delta") {
1451
1451
  const index = d.index ?? 0;
1452
- const st = blocks.get(index);
1453
- if (st && st.isCompress) {
1452
+ const st2 = blocks.get(index);
1453
+ if (st2 && st2.isCompress) {
1454
1454
  const partial = d.delta?.partial_json;
1455
- if (typeof partial === "string") st.json += partial;
1455
+ if (typeof partial === "string") st2.json += partial;
1456
1456
  return NOOP;
1457
1457
  }
1458
- const dt = d.delta;
1459
- if (dt?.text && (dt.text.includes("<acp ") || dt.text.includes("</acp"))) {
1460
- ctx.log(`[warn: tag echo] model emitted <acp tag in text delta: ${dt.text.slice(0, 120).replace(/\n/g, " ")}`);
1458
+ const dt2 = d.delta;
1459
+ if (dt2?.text && (dt2.text.includes("<acp ") || dt2.text.includes("</acp"))) {
1460
+ ctx.log(`[warn: tag echo] model emitted <acp tag in text delta: ${dt2.text.slice(0, 120).replace(/\n/g, " ")}`);
1461
1461
  }
1462
1462
  return emitEvent(ev);
1463
1463
  }
1464
1464
  if (t === "content_block_stop") {
1465
1465
  const index = d.index ?? 0;
1466
- const st = blocks.get(index);
1467
- if (st && st.isCompress) {
1466
+ const st2 = blocks.get(index);
1467
+ if (st2 && st2.isCompress) {
1468
1468
  blocks.delete(index);
1469
- return emitReplacementText(st.json, ctx, index);
1469
+ return emitReplacementText(st2.json, ctx, index);
1470
1470
  }
1471
1471
  return emitEvent(ev);
1472
1472
  }
1473
1473
  if (t === "message_delta") {
1474
1474
  if (!getConverted()) {
1475
- const u = d.usage;
1476
- if (u) {
1477
- const out = u.output_tokens;
1475
+ const u2 = d.usage;
1476
+ if (u2) {
1477
+ const out = u2.output_tokens;
1478
1478
  if (typeof out === "number") ctx.session.stats.outputTokens += out;
1479
1479
  }
1480
1480
  }
1481
1481
  return getConverted() ? NOOP : emitEvent(ev);
1482
1482
  }
1483
1483
  if (t === "message_start" && !getConverted()) {
1484
- const u = d.message?.usage;
1485
- if (u) {
1486
- const inp = u.input_tokens;
1487
- const cc = u.cache_creation_input_tokens;
1488
- const cr = u.cache_read_input_tokens;
1484
+ const u2 = d.message?.usage;
1485
+ if (u2) {
1486
+ const inp = u2.input_tokens;
1487
+ const cc = u2.cache_creation_input_tokens;
1488
+ const cr2 = u2.cache_read_input_tokens;
1489
1489
  if (typeof inp === "number") ctx.session.stats.inputTokens += inp;
1490
- if (typeof cr === "number") {
1491
- ctx.session.stats.cachedTokens += cr;
1490
+ if (typeof cr2 === "number") {
1491
+ ctx.session.stats.cachedTokens += cr2;
1492
1492
  ctx.session.stats.cacheSamples += 1;
1493
1493
  } else if (typeof inp === "number") {
1494
1494
  ctx.session.stats.cacheSamples += 1;
@@ -1529,7 +1529,7 @@ function applyRanges(ranges, ctx) {
1529
1529
  ctx.log(`[acp-proxy: compress requested ${ranges.length} range(s): ${ranges.map((r) => `${r.startRef}\u2013${r.endRef}`).join(", ")}]`);
1530
1530
  ctx.log(`[acp-proxy: ctx has ${ctx.messages.length} message(s), state has ${ctx.session.state.messageRefs?.byRef?.size ?? "?"} ref(s) mapped]`);
1531
1531
  if (ctx.messages.length > 0) {
1532
- const ids = ctx.messages.slice(0, 10).map((m) => `${m.id}(${(m.text ?? "").length}c)`).join(", ");
1532
+ const ids = ctx.messages.slice(0, 10).map((m2) => `${m2.id}(${(m2.text ?? "").length}c)`).join(", ");
1533
1533
  ctx.log(`[acp-proxy: first msg ids: ${ids}]`);
1534
1534
  }
1535
1535
  try {
@@ -1539,14 +1539,14 @@ function applyRanges(ranges, ctx) {
1539
1539
  state: ctx.session.state,
1540
1540
  config: ctx.config
1541
1541
  });
1542
- const beforeIds = new Set(ctx.session.state.blocks.map((b) => b.blockId));
1542
+ const beforeIds = new Set(ctx.session.state.blocks.map((b2) => b2.blockId));
1543
1543
  ctx.session.state = res.state;
1544
- for (const b of res.state.blocks) {
1545
- if (beforeIds.has(b.blockId)) continue;
1546
- const full = collectBlockContent(res.state, b, ctx.messages, { full: true });
1547
- const one = collectBlockContent(res.state, b, ctx.messages, { full: false });
1544
+ for (const b2 of res.state.blocks) {
1545
+ if (beforeIds.has(b2.blockId)) continue;
1546
+ const full = collectBlockContent(res.state, b2, ctx.messages, { full: true });
1547
+ const one = collectBlockContent(res.state, b2, ctx.messages, { full: false });
1548
1548
  if (full.count > 0 || one.count > 0) {
1549
- cacheBlockContent(ctx.session, b.blockId, {
1549
+ cacheBlockContent(ctx.session, b2.blockId, {
1550
1550
  one: { text: one.text, count: one.count },
1551
1551
  full: { text: full.text, count: full.count }
1552
1552
  });
@@ -1598,12 +1598,12 @@ function emitEvent(ev) {
1598
1598
  }
1599
1599
  function rewriteJsonResponse(body, ctx) {
1600
1600
  if (!body || typeof body !== "object") return body;
1601
- const b = body;
1602
- if (!Array.isArray(b.content)) return body;
1601
+ const b2 = body;
1602
+ if (!Array.isArray(b2.content)) return body;
1603
1603
  let converted = false;
1604
1604
  let sawRealToolUse = false;
1605
1605
  const newContent = [];
1606
- for (const block of b.content) {
1606
+ for (const block of b2.content) {
1607
1607
  const blk = block;
1608
1608
  if (blk.type === "tool_use" && blk.name === COMPRESS_TOOL_NAME) {
1609
1609
  converted = true;
@@ -1614,8 +1614,8 @@ function rewriteJsonResponse(body, ctx) {
1614
1614
  newContent.push(block);
1615
1615
  }
1616
1616
  }
1617
- b.content = newContent;
1618
- if (converted && !sawRealToolUse) b.stop_reason = "end_turn";
1617
+ b2.content = newContent;
1618
+ if (converted && !sawRealToolUse) b2.stop_reason = "end_turn";
1619
1619
  for (const blk of newContent) {
1620
1620
  const t = blk.text;
1621
1621
  if (typeof t === "string" && (t.includes("<acp ") || t.includes("</acp"))) {
@@ -1644,9 +1644,9 @@ function readProviders() {
1644
1644
  if (parsed && typeof parsed === "object" && !Array.isArray(parsed)) {
1645
1645
  const providers = parsed.providers;
1646
1646
  if (providers) {
1647
- for (const [k, v] of Object.entries(providers)) {
1648
- const route = parseRouteEntry(v);
1649
- if (route) routes[k] = route;
1647
+ for (const [k2, v2] of Object.entries(providers)) {
1648
+ const route = parseRouteEntry(v2);
1649
+ if (route) routes[k2] = route;
1650
1650
  }
1651
1651
  }
1652
1652
  }
@@ -2071,7 +2071,7 @@ var ORPHAN_THRESHOLD = 3;
2071
2071
  var orphanStreaks = /* @__PURE__ */ new WeakMap();
2072
2072
  function reapOrphanBlocks(session, visible, deactivate) {
2073
2073
  if (session.state.blocks.length === 0) return { reaped: [] };
2074
- const presentIds = new Set(visible.map((m) => m.id));
2074
+ const presentIds = new Set(visible.map((m2) => m2.id));
2075
2075
  const reaped = [];
2076
2076
  for (const block of session.state.blocks) {
2077
2077
  if (!block.active) continue;
@@ -2165,10 +2165,10 @@ function executeProxyTool(toolName, args, ctx) {
2165
2165
  const limit = typeof args.limit === "number" && args.limit > 0 ? Math.floor(args.limit) : 5;
2166
2166
  const blocks = ctx.core.search(query, ctx.session.state).slice(0, limit);
2167
2167
  if (blocks.length === 0) return `[No blocks matched "${query}"]`;
2168
- const lines = blocks.map((b) => {
2169
- const topic = b.topic ?? "(no topic)";
2170
- const preview = b.summary.length > 200 ? b.summary.slice(0, 200) + "..." : b.summary;
2171
- return `${b.blockId} (T${b.tier}) "${topic}"
2168
+ const lines = blocks.map((b2) => {
2169
+ const topic = b2.topic ?? "(no topic)";
2170
+ const preview = b2.summary.length > 200 ? b2.summary.slice(0, 200) + "..." : b2.summary;
2171
+ return `${b2.blockId} (T${b2.tier}) "${topic}"
2172
2172
  ${preview}`;
2173
2173
  });
2174
2174
  return `Found ${blocks.length} block(s) for "${query}":
@@ -2341,8 +2341,8 @@ async function* compressLoopStream(initialUpstream, ctx, requestBody, requestOpt
2341
2341
  const dataLine = eventStr.split("\n").find((l) => l.startsWith("data:"));
2342
2342
  if (dataLine) {
2343
2343
  try {
2344
- const p = JSON.parse(dataLine.slice(5).trim());
2345
- if (typeof p.id === "string") responseId = p.id;
2344
+ const p2 = JSON.parse(dataLine.slice(5).trim());
2345
+ if (typeof p2.id === "string") responseId = p2.id;
2346
2346
  } catch {
2347
2347
  }
2348
2348
  }
@@ -2404,7 +2404,7 @@ async function* compressLoopStream(initialUpstream, ctx, requestBody, requestOpt
2404
2404
  } finally {
2405
2405
  reader.releaseLock();
2406
2406
  }
2407
- const sortedIndices = [...toolCallByIndex.keys()].sort((a, b) => a - b);
2407
+ const sortedIndices = [...toolCallByIndex.keys()].sort((a, b2) => a - b2);
2408
2408
  const toolCalls = sortedIndices.map((i) => {
2409
2409
  const tc = toolCallByIndex.get(i);
2410
2410
  return { ...tc, id: tc.id || `call_${tc.index}` };
@@ -2430,8 +2430,8 @@ async function* compressLoopStream(initialUpstream, ctx, requestBody, requestOpt
2430
2430
  for (const tc of realCalls) {
2431
2431
  yield Buffer.from(buildToolCallSse(makeBase(), tc), "utf8");
2432
2432
  }
2433
- const fr = realCalls.length > 0 ? "tool_calls" : finishReason ?? "stop";
2434
- yield Buffer.from(buildFinishSse(makeBase(), fr, usage), "utf8");
2433
+ const fr2 = realCalls.length > 0 ? "tool_calls" : finishReason ?? "stop";
2434
+ yield Buffer.from(buildFinishSse(makeBase(), fr2, usage), "utf8");
2435
2435
  yield Buffer.from("data: [DONE]\n\n", "utf8");
2436
2436
  return;
2437
2437
  }
@@ -2558,10 +2558,10 @@ function executeProxyTool2(toolName, args, ctx) {
2558
2558
  const limit = typeof args.limit === "number" && args.limit > 0 ? Math.floor(args.limit) : 5;
2559
2559
  const blocks = ctx.core.search(query, ctx.session.state).slice(0, limit);
2560
2560
  if (blocks.length === 0) return `[No blocks matched "${query}"]`;
2561
- const lines = blocks.map((b) => {
2562
- const topic = b.topic ?? "(no topic)";
2563
- const preview = b.summary.length > 200 ? b.summary.slice(0, 200) + "..." : b.summary;
2564
- return `${b.blockId} (T${b.tier}) "${topic}"
2561
+ const lines = blocks.map((b2) => {
2562
+ const topic = b2.topic ?? "(no topic)";
2563
+ const preview = b2.summary.length > 200 ? b2.summary.slice(0, 200) + "..." : b2.summary;
2564
+ return `${b2.blockId} (T${b2.tier}) "${topic}"
2565
2565
  ${preview}`;
2566
2566
  });
2567
2567
  return `Found ${blocks.length} block(s) for "${query}":
@@ -2583,9 +2583,9 @@ function extractDataLine(rawEvent) {
2583
2583
  const parts = [];
2584
2584
  for (const l of rawEvent.split("\n")) {
2585
2585
  if (l.startsWith("data:")) {
2586
- let v = l.slice(5);
2587
- if (v.startsWith(" ")) v = v.slice(1);
2588
- parts.push(v);
2586
+ let v2 = l.slice(5);
2587
+ if (v2.startsWith(" ")) v2 = v2.slice(1);
2588
+ parts.push(v2);
2589
2589
  }
2590
2590
  }
2591
2591
  return parts.length ? parts.join("\n") : null;
@@ -2858,12 +2858,12 @@ async function* compressLoopResponsesStream(initialUpstream, ctx, requestBody, r
2858
2858
  log("debug", `[acp-diag] round ${loopCount} allCalls=[${allCalls.map((c) => c.name).join(",")}] realCalls=[${realCalls.map((c) => c.name).join(",")}] text=${JSON.stringify(contentText.slice(0, 120))}`);
2859
2859
  const hasOnlyProxy = proxyCalls.length > 0 && realCalls.length === 0;
2860
2860
  if (!hasOnlyProxy) {
2861
- let oi = nextOutputIndex;
2861
+ let oi2 = nextOutputIndex;
2862
2862
  for (const fc of realCalls) {
2863
- yield Buffer.from(buildFunctionCallEvents(fc, oi), "utf8");
2864
- oi++;
2863
+ yield Buffer.from(buildFunctionCallEvents(fc, oi2), "utf8");
2864
+ oi2++;
2865
2865
  }
2866
- nextOutputIndex = oi;
2866
+ nextOutputIndex = oi2;
2867
2867
  if (terminalKind && terminalKind !== "completed" && terminalRaw) {
2868
2868
  yield Buffer.from(terminalRaw + "\n\n", "utf8");
2869
2869
  return;
@@ -2948,8 +2948,8 @@ async function* compressLoopResponsesStream(initialUpstream, ctx, requestBody, r
2948
2948
  // src/stream-openai.ts
2949
2949
  function rewriteOpenaiJsonResponse(body, ctx) {
2950
2950
  if (!body || typeof body !== "object") return body;
2951
- const b = body;
2952
- const choice = b.choices?.[0];
2951
+ const b2 = body;
2952
+ const choice = b2.choices?.[0];
2953
2953
  const msg2 = choice?.message;
2954
2954
  if (!choice || !msg2) return body;
2955
2955
  let converted = false;
@@ -2991,13 +2991,13 @@ ${note}` : note;
2991
2991
  var TEXT_PROTOCOL2 = process.env.ACP_COMPRESS_PROTOCOL === "text";
2992
2992
  function rewriteResponsesJsonResponse(body, ctx) {
2993
2993
  if (!body || typeof body !== "object") return body;
2994
- const b = body;
2995
- if (!Array.isArray(b.output)) return body;
2994
+ const b2 = body;
2995
+ if (!Array.isArray(b2.output)) return body;
2996
2996
  let converted = false;
2997
2997
  let sawReal = false;
2998
2998
  const noteParts = [];
2999
2999
  const keep = [];
3000
- for (const item of b.output) {
3000
+ for (const item of b2.output) {
3001
3001
  if (item.type === "function_call" && item.name === COMPRESS_TOOL_NAME) {
3002
3002
  converted = true;
3003
3003
  noteParts.push(applyRanges(parseCompressInput(safeJsonParse(String(item.arguments ?? ""))), ctx));
@@ -3015,8 +3015,8 @@ function rewriteResponsesJsonResponse(body, ctx) {
3015
3015
  content: [{ type: "output_text", text: note }]
3016
3016
  });
3017
3017
  }
3018
- b.output = keep;
3019
- if (!sawReal) b.status = "completed";
3018
+ b2.output = keep;
3019
+ if (!sawReal) b2.status = "completed";
3020
3020
  return body;
3021
3021
  }
3022
3022
 
@@ -3083,8 +3083,8 @@ function extractKey(headers) {
3083
3083
  function clientConversationHeader(headers) {
3084
3084
  const names = ["x-session-affinity", "x-acp-session", "x-session-id", "x-opencode-session"];
3085
3085
  for (const name of names) {
3086
- const v = headers[name];
3087
- if (typeof v === "string" && v.trim().length > 0) return v.trim();
3086
+ const v2 = headers[name];
3087
+ if (typeof v2 === "string" && v2.trim().length > 0) return v2.trim();
3088
3088
  }
3089
3089
  return void 0;
3090
3090
  }
@@ -3115,7 +3115,7 @@ function resolveUpstream(opts, reqUrl) {
3115
3115
  const names = Object.keys(opts.routes);
3116
3116
  if (names.length === 0) return void 0;
3117
3117
  const RESERVED = /* @__PURE__ */ new Set(["v1", "v2", "v4", "chat", "completions", "messages", "models", "api"]);
3118
- const sorted = [...names].sort((a, b) => b.length - a.length);
3118
+ const sorted = [...names].sort((a, b2) => b2.length - a.length);
3119
3119
  const segments = reqUrl.split("/");
3120
3120
  for (const name of sorted) {
3121
3121
  if (!/^[A-Za-z][A-Za-z0-9_-]*$/.test(name)) continue;
@@ -3158,7 +3158,7 @@ async function startServer(opts) {
3158
3158
  const displayHost = opts.host === "0.0.0.0" ? "localhost" : opts.host;
3159
3159
  log2(
3160
3160
  "info",
3161
- `acp-proxy listening on http://${displayHost}:${opts.port}` + (Object.keys(opts.routes).length ? ` \u2014 routes: ${Object.entries(opts.routes).map(([n, u]) => `${n}=${typeof u === "string" ? u : u.url}`).join(", ")}` : ` \u2192 ${opts.upstream}`) + ` \u2014 web UI: http://${displayHost}:${opts.port}/__acp/`
3161
+ `acp-proxy listening on http://${displayHost}:${opts.port}` + (Object.keys(opts.routes).length ? ` \u2014 routes: ${Object.entries(opts.routes).map(([n, u2]) => `${n}=${typeof u2 === "string" ? u2 : u2.url}`).join(", ")}` : ` \u2192 ${opts.upstream}`) + ` \u2014 web UI: http://${displayHost}:${opts.port}/__acp/`
3162
3162
  );
3163
3163
  });
3164
3164
  server.on("error", (err) => {
@@ -3285,10 +3285,10 @@ var ACP_TAG_MARK = "<acp ";
3285
3285
  function diagTagSummary(messages, sessionId, strategy) {
3286
3286
  let textTagged = 0;
3287
3287
  let toolTagged = 0;
3288
- for (const m of messages) {
3289
- const hasTag = (m.text ?? "").includes(ACP_TAG_MARK);
3288
+ for (const m2 of messages) {
3289
+ const hasTag = (m2.text ?? "").includes(ACP_TAG_MARK);
3290
3290
  if (!hasTag) continue;
3291
- if (m.contentType === "tool-call" || m.contentType === "tool-result") toolTagged++;
3291
+ if (m2.contentType === "tool-call" || m2.contentType === "tool-result") toolTagged++;
3292
3292
  else textTagged++;
3293
3293
  }
3294
3294
  return `[${sessionId}] processTurn: ${messages.length} msgs, renderTags=${strategy}, ${textTagged} text tagged, ${toolTagged} tool tagged (should be 0 with text-only)`;
@@ -3296,13 +3296,13 @@ function diagTagSummary(messages, sessionId, strategy) {
3296
3296
  function diagNudge(turn, sessionId, tokenCount, limit) {
3297
3297
  const n = turn.nudge;
3298
3298
  if (!n) return `[${sessionId}] nudge: unavailable`;
3299
- const b = n.breakdown ?? {};
3299
+ const b2 = n.breakdown ?? {};
3300
3300
  const pct = limit > 0 ? `${Math.round(tokenCount / limit * 100)}%` : "?";
3301
- const growth = b["growth"] ?? 0;
3302
- const floor = b["growthFloor"] ?? 0;
3303
- const interval = b["nudgeGrowthTokens"] ?? 0;
3304
- const pendingT1 = b["pendingT1"] ?? 0;
3305
- const ref = b["growthReference"] ?? 0;
3301
+ const growth = b2["growth"] ?? 0;
3302
+ const floor = b2["growthFloor"] ?? 0;
3303
+ const interval = b2["nudgeGrowthTokens"] ?? 0;
3304
+ const pendingT1 = b2["pendingT1"] ?? 0;
3305
+ const ref = b2["growthReference"] ?? 0;
3306
3306
  const inject = n.shouldInject ? `INJECT T${n.tier ?? "?"}` : "idle";
3307
3307
  return `[${sessionId}] nudge ${inject}: usage=${pct} (${tokenCount}/${limit}), growth=${growth}/${floor} (ref=${ref}, interval=${interval}), pendingT1=${pendingT1}/${interval}, reason="${n.reason.slice(0, 120)}"`;
3308
3308
  }
@@ -3316,7 +3316,7 @@ function prepareAnthropic(parsed, req, opts, core, config, log2, session) {
3316
3316
  let toolsOut = parsed.tools;
3317
3317
  try {
3318
3318
  const { msgs, cacheControls } = anthropicToCore(parsed);
3319
- const tokenCount = estimateTokensFast3(msgs.map((m) => m.text ?? "").join("\n"));
3319
+ const tokenCount = estimateTokensFast3(msgs.map((m2) => m2.text ?? "").join("\n"));
3320
3320
  const turn = core.processTurn({ messages: msgs, state: session.state, config, tokenCount, renderTags: "text-only" });
3321
3321
  session.state = turn.state;
3322
3322
  session.stats.contextTokens = tokenCount;
@@ -3362,7 +3362,7 @@ function prepareOpenai(parsed, req, opts, core, config, log2, session) {
3362
3362
  const shouldInject = opts.compress.injectTool && !isTitleGen;
3363
3363
  try {
3364
3364
  const { msgs } = openaiToCore(parsed);
3365
- const tokenCount = estimateTokensFast3(msgs.map((m) => m.text ?? "").join("\n"));
3365
+ const tokenCount = estimateTokensFast3(msgs.map((m2) => m2.text ?? "").join("\n"));
3366
3366
  const turn = core.processTurn({ messages: msgs, state: session.state, config, tokenCount, renderTags: "text-only" });
3367
3367
  session.state = turn.state;
3368
3368
  session.stats.contextTokens = tokenCount;
@@ -3411,7 +3411,7 @@ function prepareResponses(parsed, req, opts, core, config, log2, session) {
3411
3411
  if (process.env.ACP_DEBUG) {
3412
3412
  log2("info", `[${sessionId}] input items: ${Array.isArray(parsed.input) ? parsed.input.map((i) => i.type).join(",") : "(string)"}`);
3413
3413
  }
3414
- const tokenCount = estimateTokensFast3(msgs.map((m) => m.text ?? "").join("\n"));
3414
+ const tokenCount = estimateTokensFast3(msgs.map((m2) => m2.text ?? "").join("\n"));
3415
3415
  const turn = core.processTurn({ messages: msgs, state: session.state, config, tokenCount, renderTags: process.env.ACP_RENDER_NONE ? "none" : "text-only" });
3416
3416
  session.state = turn.state;
3417
3417
  session.stats.contextTokens = tokenCount;
@@ -3425,7 +3425,7 @@ function prepareResponses(parsed, req, opts, core, config, log2, session) {
3425
3425
  reapOrphanBlocks(session, msgs, deactivateBlock4);
3426
3426
  const conversationItems = coreToResponses(processedMessages, customToolCallIds);
3427
3427
  if (preamble.length > 0) {
3428
- log2("info", `[${sessionId}] preserved ${preamble.length} opaque preamble item(s): ${preamble.map((p) => p.type).join(",")}`);
3428
+ log2("info", `[${sessionId}] preserved ${preamble.length} opaque preamble item(s): ${preamble.map((p2) => p2.type).join(",")}`);
3429
3429
  }
3430
3430
  const inputItems = [...preamble];
3431
3431
  if (shouldInject && !process.env.ACP_NO_COMPRESS_PROMPT) {
@@ -3510,12 +3510,12 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3510
3510
  const sid = prepared.session.id;
3511
3511
  const hdrKeys = Object.keys(req.headers);
3512
3512
  log2("info", `[${sid}] client headers: ${hdrKeys.join(",")}`);
3513
- for (const k of ["authorization", "x-api-key", "x-session-id", "x-session-affinity", "x-acp-session", "x-opencode-session", "prompt-cache-key", "anthropic-beta"]) {
3514
- const v = req.headers[k] ?? req.headers[k.toLowerCase()];
3515
- if (v) {
3516
- const s = Array.isArray(v) ? v.join(",") : String(v);
3517
- const masked = /key|auth|token/i.test(k) ? s.slice(0, 8) + "..." + s.slice(-4) + ` (${s.length} chars)` : s.slice(0, 60);
3518
- log2("info", `[${sid}] client hdr ${k}=${masked}`);
3513
+ for (const k2 of ["authorization", "x-api-key", "x-session-id", "x-session-affinity", "x-acp-session", "x-opencode-session", "prompt-cache-key", "anthropic-beta"]) {
3514
+ const v2 = req.headers[k2] ?? req.headers[k2.toLowerCase()];
3515
+ if (v2) {
3516
+ const s3 = Array.isArray(v2) ? v2.join(",") : String(v2);
3517
+ const masked = /key|auth|token/i.test(k2) ? s3.slice(0, 8) + "..." + s3.slice(-4) + ` (${s3.length} chars)` : s3.slice(0, 60);
3518
+ log2("info", `[${sid}] client hdr ${k2}=${masked}`);
3519
3519
  }
3520
3520
  }
3521
3521
  }
@@ -3526,7 +3526,7 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3526
3526
  const fn = t.function;
3527
3527
  return fn?.name ?? t.name ?? "?";
3528
3528
  });
3529
- log2("info", `[debug] tools=[${toolNames.join(",")}] msgs=${parsed.messages?.length ?? 0} stream=${parsed.stream ?? false} system_len=${JSON.stringify(parsed.messages?.find((m) => m.role === "system")?.content ?? "").length}`);
3529
+ log2("info", `[debug] tools=[${toolNames.join(",")}] msgs=${parsed.messages?.length ?? 0} stream=${parsed.stream ?? false} system_len=${JSON.stringify(parsed.messages?.find((m2) => m2.role === "system")?.content ?? "").length}`);
3530
3530
  if (process.env.ACP_DUMP_REQ === "1") {
3531
3531
  const out = `${tmpdir2()}/acp-proxy-debug-req-${Date.now()}.json`;
3532
3532
  fs2.writeFileSync(out, body.slice(0, 5e4));
@@ -3536,9 +3536,9 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3536
3536
  }
3537
3537
  }
3538
3538
  const headers = {};
3539
- for (const [k, v] of Object.entries(req.headers)) {
3540
- if (UPSTREAM_HOP_HEADERS.has(k.toLowerCase()) || v === void 0) continue;
3541
- headers[k] = Array.isArray(v) ? v.join(", ") : v;
3539
+ for (const [k2, v2] of Object.entries(req.headers)) {
3540
+ if (UPSTREAM_HOP_HEADERS.has(k2.toLowerCase()) || v2 === void 0) continue;
3541
+ headers[k2] = Array.isArray(v2) ? v2.join(", ") : v2;
3542
3542
  }
3543
3543
  headers["host"] = new URL(route ? route.upstream : opts.upstream).host;
3544
3544
  if (affinity && !clientConversationHeader(req.headers)) {
@@ -3551,9 +3551,9 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3551
3551
  };
3552
3552
  const { response: upstream, clearTimer: clearUpstreamTimer } = await fetchWithTimeout(upstreamUrl, init);
3553
3553
  const respHeaders = {};
3554
- upstream.headers.forEach((v, k) => {
3555
- if (UPSTREAM_HOP_HEADERS.has(k.toLowerCase())) return;
3556
- respHeaders[k] = v;
3554
+ upstream.headers.forEach((v2, k2) => {
3555
+ if (UPSTREAM_HOP_HEADERS.has(k2.toLowerCase())) return;
3556
+ respHeaders[k2] = v2;
3557
3557
  });
3558
3558
  if (!upstream.ok) {
3559
3559
  res.writeHead(upstream.status, respHeaders);
@@ -3585,17 +3585,17 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3585
3585
  let streamToRead = upstream.body;
3586
3586
  let dumpRaw;
3587
3587
  if (opts.dumpSse) {
3588
- const [a, b] = upstream.body.tee();
3588
+ const [a, b2] = upstream.body.tee();
3589
3589
  streamToRead = a;
3590
- dumpRaw = dumpStreamToFile(b, opts.dumpSse, `${Date.now()}-${prepared.session.id}-raw.sse`);
3590
+ dumpRaw = dumpStreamToFile(b2, opts.dumpSse, `${Date.now()}-${prepared.session.id}-raw.sse`);
3591
3591
  }
3592
3592
  try {
3593
3593
  if (prepared.protocol === "openai") {
3594
3594
  const parsedReq = JSON.parse(typeof body === "string" ? body : body.toString("utf8"));
3595
3595
  const reqHeaders = {};
3596
- for (const [k, v] of Object.entries(headers)) {
3597
- if (k.toLowerCase() === "content-length" || k.toLowerCase() === "host") continue;
3598
- reqHeaders[k] = v;
3596
+ for (const [k2, v2] of Object.entries(headers)) {
3597
+ if (k2.toLowerCase() === "content-length" || k2.toLowerCase() === "host") continue;
3598
+ reqHeaders[k2] = v2;
3599
3599
  }
3600
3600
  reqHeaders["content-type"] = "application/json";
3601
3601
  const loop = compressLoopStream(
@@ -3606,8 +3606,8 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3606
3606
  );
3607
3607
  for await (const chunk of loop) {
3608
3608
  {
3609
- const s = chunk.toString("utf8");
3610
- if (s.includes("<acp ") || s.includes("</acp")) {
3609
+ const s3 = chunk.toString("utf8");
3610
+ if (s3.includes("<acp ") || s3.includes("</acp")) {
3611
3611
  log2("warn", `[${prepared.session.id}] tag echo: openai response stream contains <acp tag`);
3612
3612
  }
3613
3613
  }
@@ -3616,9 +3616,9 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3616
3616
  } else if (prepared.protocol === "responses") {
3617
3617
  const parsedReq = JSON.parse(typeof body === "string" ? body : body.toString("utf8"));
3618
3618
  const reqHeaders = {};
3619
- for (const [k, v] of Object.entries(headers)) {
3620
- if (k.toLowerCase() === "content-length" || k.toLowerCase() === "host") continue;
3621
- reqHeaders[k] = v;
3619
+ for (const [k2, v2] of Object.entries(headers)) {
3620
+ if (k2.toLowerCase() === "content-length" || k2.toLowerCase() === "host") continue;
3621
+ reqHeaders[k2] = v2;
3622
3622
  }
3623
3623
  reqHeaders["content-type"] = "application/json";
3624
3624
  const loop = compressLoopResponsesStream(
@@ -3629,8 +3629,8 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3629
3629
  );
3630
3630
  for await (const chunk of loop) {
3631
3631
  {
3632
- const s = chunk.toString("utf8");
3633
- if (s.includes("<acp ") || s.includes("</acp")) {
3632
+ const s3 = chunk.toString("utf8");
3633
+ if (s3.includes("<acp ") || s3.includes("</acp")) {
3634
3634
  log2("warn", `[${prepared.session.id}] tag echo: responses response stream contains <acp tag`);
3635
3635
  }
3636
3636
  }
@@ -3640,8 +3640,8 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3640
3640
  const rewriter = rewriteSseStream(streamToRead, ctx);
3641
3641
  for await (const chunk of rewriter) {
3642
3642
  {
3643
- const s = chunk.toString("utf8");
3644
- if (s.includes("<acp ") || s.includes("</acp")) {
3643
+ const s3 = chunk.toString("utf8");
3644
+ if (s3.includes("<acp ") || s3.includes("</acp")) {
3645
3645
  log2("warn", `[${prepared.session.id}] tag echo: anthropic response stream contains <acp tag`);
3646
3646
  }
3647
3647
  }
@@ -3650,7 +3650,7 @@ async function forward(req, res, opts, body, prepared, core, config, log2, route
3650
3650
  }
3651
3651
  res.end();
3652
3652
  } catch (e) {
3653
- emitStreamError(res, prepared.protocol, e?.message ?? String(e), (m) => log2("error", `[${prepared.session.id}] ${m}`));
3653
+ emitStreamError(res, prepared.protocol, e?.message ?? String(e), (m2) => log2("error", `[${prepared.session.id}] ${m2}`));
3654
3654
  } finally {
3655
3655
  clearUpstreamTimer();
3656
3656
  if (dumpRaw) await dumpRaw;
@@ -3695,52 +3695,52 @@ async function dumpStreamToFile(stream2, dir, name) {
3695
3695
  const { join: join4 } = await import("path");
3696
3696
  try {
3697
3697
  mkdirSync6(dir, { recursive: true });
3698
- const ws = createWriteStream2(join4(dir, name));
3698
+ const ws2 = createWriteStream2(join4(dir, name));
3699
3699
  const reader = stream2.getReader();
3700
3700
  try {
3701
3701
  for (; ; ) {
3702
3702
  const { done, value } = await reader.read();
3703
3703
  if (done) break;
3704
- ws.write(Buffer.from(value));
3704
+ ws2.write(Buffer.from(value));
3705
3705
  }
3706
3706
  } finally {
3707
3707
  reader.releaseLock();
3708
- ws.end();
3708
+ ws2.end();
3709
3709
  }
3710
3710
  } catch {
3711
3711
  }
3712
3712
  }
3713
3713
  function deriveTitle(messages) {
3714
- for (const m of messages) {
3715
- if (m.role !== "user" || m.contentType !== "text") continue;
3716
- const clean = (m.text ?? "").replace(/\s+/g, " ").trim();
3714
+ for (const m2 of messages) {
3715
+ if (m2.role !== "user" || m2.contentType !== "text") continue;
3716
+ const clean = (m2.text ?? "").replace(/\s+/g, " ").trim();
3717
3717
  if (clean) return clean.length > 60 ? clean.slice(0, 57) + "\u2026" : clean;
3718
3718
  }
3719
3719
  return void 0;
3720
3720
  }
3721
3721
  function sendStats(res) {
3722
- const sessions2 = listSessions().map((s) => ({
3723
- id: s.id,
3724
- protocol: s.meta.protocol,
3725
- upstream: s.meta.upstreamOrigin,
3726
- label: s.meta.label,
3727
- title: s.meta.title,
3728
- requests: s.stats.requests,
3729
- contextTokens: s.stats.contextTokens,
3730
- inputTokens: s.stats.inputTokens,
3731
- cachedTokens: s.stats.cachedTokens,
3732
- outputTokens: s.stats.outputTokens,
3733
- cacheSamples: s.stats.cacheSamples,
3734
- cacheHitPct: s.stats.cacheSamples > 0 ? Math.round(s.stats.cachedTokens / s.stats.inputTokens * 100) : null,
3735
- lastSeen: new Date(s.lastSeen).toISOString()
3722
+ const sessions2 = listSessions().map((s3) => ({
3723
+ id: s3.id,
3724
+ protocol: s3.meta.protocol,
3725
+ upstream: s3.meta.upstreamOrigin,
3726
+ label: s3.meta.label,
3727
+ title: s3.meta.title,
3728
+ requests: s3.stats.requests,
3729
+ contextTokens: s3.stats.contextTokens,
3730
+ inputTokens: s3.stats.inputTokens,
3731
+ cachedTokens: s3.stats.cachedTokens,
3732
+ outputTokens: s3.stats.outputTokens,
3733
+ cacheSamples: s3.stats.cacheSamples,
3734
+ cacheHitPct: s3.stats.cacheSamples > 0 ? Math.round(s3.stats.cachedTokens / s3.stats.inputTokens * 100) : null,
3735
+ lastSeen: new Date(s3.lastSeen).toISOString()
3736
3736
  }));
3737
3737
  res.writeHead(200, { "content-type": "application/json" });
3738
3738
  res.end(JSON.stringify({ sessions: sessions2 }, null, 2));
3739
3739
  }
3740
3740
  function headerValue(req, name) {
3741
3741
  const lower = name.toLowerCase();
3742
- for (const [k, v] of Object.entries(req.headers)) {
3743
- if (k.toLowerCase() === lower) return Array.isArray(v) ? v[0] : v;
3742
+ for (const [k2, v2] of Object.entries(req.headers)) {
3743
+ if (k2.toLowerCase() === lower) return Array.isArray(v2) ? v2[0] : v2;
3744
3744
  }
3745
3745
  return void 0;
3746
3746
  }
@@ -3781,8 +3781,2978 @@ function logMsg(opts, level, msg2) {
3781
3781
  }
3782
3782
 
3783
3783
  // src/update.ts
3784
- import { readFile, writeFile, mkdir, access, constants, rm } from "fs/promises";
3785
- import { execFile } from "child_process";
3784
+ import { readFile, writeFile, mkdir, access, constants, rm, cp } from "fs/promises";
3785
+
3786
+ // node_modules/tar/dist/esm/index.min.js
3787
+ import Qr from "events";
3788
+ import I from "fs";
3789
+ import { EventEmitter as Di } from "events";
3790
+ import Cs from "stream";
3791
+ import { StringDecoder as Hr } from "string_decoder";
3792
+ import cr from "path";
3793
+ import Kt from "fs";
3794
+ import { dirname as Fn, parse as kn } from "path";
3795
+ import { EventEmitter as Dn } from "events";
3796
+ import zi from "assert";
3797
+ import { Buffer as Ot } from "buffer";
3798
+ import * as Ps from "zlib";
3799
+ import en from "zlib";
3800
+ import { posix as Zt } from "path";
3801
+ import { basename as _n } from "path";
3802
+ import mi from "fs";
3803
+ import X from "fs";
3804
+ import js from "path";
3805
+ import { win32 as Pn } from "path";
3806
+ import ar from "path";
3807
+ import Br from "fs";
3808
+ import co from "assert";
3809
+ import { randomBytes as Mr } from "crypto";
3810
+ import u from "fs";
3811
+ import R from "path";
3812
+ import pr from "fs";
3813
+ import wi from "fs";
3814
+ import we from "path";
3815
+ import k from "fs";
3816
+ import ro from "fs/promises";
3817
+ import Si from "path";
3818
+ import { join as xr } from "path";
3819
+ import v from "fs";
3820
+ import Pr from "path";
3821
+ var zr = Object.defineProperty;
3822
+ var Ur = (s3, t) => {
3823
+ for (var e in t) zr(s3, e, { get: t[e], enumerable: true });
3824
+ };
3825
+ var Ds = typeof process == "object" && process ? process : { stdout: null, stderr: null };
3826
+ var Wr = (s3) => !!s3 && typeof s3 == "object" && (s3 instanceof A || s3 instanceof Cs || Gr(s3) || Zr(s3));
3827
+ var Gr = (s3) => !!s3 && typeof s3 == "object" && s3 instanceof Di && typeof s3.pipe == "function" && s3.pipe !== Cs.Writable.prototype.pipe;
3828
+ var Zr = (s3) => !!s3 && typeof s3 == "object" && s3 instanceof Di && typeof s3.write == "function" && typeof s3.end == "function";
3829
+ var Q = /* @__PURE__ */ Symbol("EOF");
3830
+ var J = /* @__PURE__ */ Symbol("maybeEmitEnd");
3831
+ var nt = /* @__PURE__ */ Symbol("emittedEnd");
3832
+ var De = /* @__PURE__ */ Symbol("emittingEnd");
3833
+ var qt = /* @__PURE__ */ Symbol("emittedError");
3834
+ var Ne = /* @__PURE__ */ Symbol("closed");
3835
+ var Ns = /* @__PURE__ */ Symbol("read");
3836
+ var Ae = /* @__PURE__ */ Symbol("flush");
3837
+ var As = /* @__PURE__ */ Symbol("flushChunk");
3838
+ var z = /* @__PURE__ */ Symbol("encoding");
3839
+ var Mt = /* @__PURE__ */ Symbol("decoder");
3840
+ var g = /* @__PURE__ */ Symbol("flowing");
3841
+ var Qt = /* @__PURE__ */ Symbol("paused");
3842
+ var Bt = /* @__PURE__ */ Symbol("resume");
3843
+ var b = /* @__PURE__ */ Symbol("buffer");
3844
+ var N = /* @__PURE__ */ Symbol("pipes");
3845
+ var _ = /* @__PURE__ */ Symbol("bufferLength");
3846
+ var bi = /* @__PURE__ */ Symbol("bufferPush");
3847
+ var Ie = /* @__PURE__ */ Symbol("bufferShift");
3848
+ var L = /* @__PURE__ */ Symbol("objectMode");
3849
+ var S = /* @__PURE__ */ Symbol("destroyed");
3850
+ var _i = /* @__PURE__ */ Symbol("error");
3851
+ var Oi = /* @__PURE__ */ Symbol("emitData");
3852
+ var Is = /* @__PURE__ */ Symbol("emitEnd");
3853
+ var Ti = /* @__PURE__ */ Symbol("emitEnd2");
3854
+ var Z = /* @__PURE__ */ Symbol("async");
3855
+ var xi = /* @__PURE__ */ Symbol("abort");
3856
+ var Ce = /* @__PURE__ */ Symbol("aborted");
3857
+ var Jt = /* @__PURE__ */ Symbol("signal");
3858
+ var Rt = /* @__PURE__ */ Symbol("dataListeners");
3859
+ var C = /* @__PURE__ */ Symbol("discarded");
3860
+ var jt = (s3) => Promise.resolve().then(s3);
3861
+ var Yr = (s3) => s3();
3862
+ var Kr = (s3) => s3 === "end" || s3 === "finish" || s3 === "prefinish";
3863
+ var Vr = (s3) => s3 instanceof ArrayBuffer || !!s3 && typeof s3 == "object" && s3.constructor && s3.constructor.name === "ArrayBuffer" && s3.byteLength >= 0;
3864
+ var $r = (s3) => !Buffer.isBuffer(s3) && ArrayBuffer.isView(s3);
3865
+ var Fe = class {
3866
+ src;
3867
+ dest;
3868
+ opts;
3869
+ ondrain;
3870
+ constructor(t, e, i) {
3871
+ this.src = t, this.dest = e, this.opts = i, this.ondrain = () => t[Bt](), this.dest.on("drain", this.ondrain);
3872
+ }
3873
+ unpipe() {
3874
+ this.dest.removeListener("drain", this.ondrain);
3875
+ }
3876
+ proxyErrors(t) {
3877
+ }
3878
+ end() {
3879
+ this.unpipe(), this.opts.end && this.dest.end();
3880
+ }
3881
+ };
3882
+ var Li = class extends Fe {
3883
+ unpipe() {
3884
+ this.src.removeListener("error", this.proxyErrors), super.unpipe();
3885
+ }
3886
+ constructor(t, e, i) {
3887
+ super(t, e, i), this.proxyErrors = (r) => this.dest.emit("error", r), t.on("error", this.proxyErrors);
3888
+ }
3889
+ };
3890
+ var Xr = (s3) => !!s3.objectMode;
3891
+ var qr = (s3) => !s3.objectMode && !!s3.encoding && s3.encoding !== "buffer";
3892
+ var A = class extends Di {
3893
+ [g] = false;
3894
+ [Qt] = false;
3895
+ [N] = [];
3896
+ [b] = [];
3897
+ [L];
3898
+ [z];
3899
+ [Z];
3900
+ [Mt];
3901
+ [Q] = false;
3902
+ [nt] = false;
3903
+ [De] = false;
3904
+ [Ne] = false;
3905
+ [qt] = null;
3906
+ [_] = 0;
3907
+ [S] = false;
3908
+ [Jt];
3909
+ [Ce] = false;
3910
+ [Rt] = 0;
3911
+ [C] = false;
3912
+ writable = true;
3913
+ readable = true;
3914
+ constructor(...t) {
3915
+ let e = t[0] || {};
3916
+ if (super(), e.objectMode && typeof e.encoding == "string") throw new TypeError("Encoding and objectMode may not be used together");
3917
+ Xr(e) ? (this[L] = true, this[z] = null) : qr(e) ? (this[z] = e.encoding, this[L] = false) : (this[L] = false, this[z] = null), this[Z] = !!e.async, this[Mt] = this[z] ? new Hr(this[z]) : null, e && e.debugExposeBuffer === true && Object.defineProperty(this, "buffer", { get: () => this[b] }), e && e.debugExposePipes === true && Object.defineProperty(this, "pipes", { get: () => this[N] });
3918
+ let { signal: i } = e;
3919
+ i && (this[Jt] = i, i.aborted ? this[xi]() : i.addEventListener("abort", () => this[xi]()));
3920
+ }
3921
+ get bufferLength() {
3922
+ return this[_];
3923
+ }
3924
+ get encoding() {
3925
+ return this[z];
3926
+ }
3927
+ set encoding(t) {
3928
+ throw new Error("Encoding must be set at instantiation time");
3929
+ }
3930
+ setEncoding(t) {
3931
+ throw new Error("Encoding must be set at instantiation time");
3932
+ }
3933
+ get objectMode() {
3934
+ return this[L];
3935
+ }
3936
+ set objectMode(t) {
3937
+ throw new Error("objectMode must be set at instantiation time");
3938
+ }
3939
+ get async() {
3940
+ return this[Z];
3941
+ }
3942
+ set async(t) {
3943
+ this[Z] = this[Z] || !!t;
3944
+ }
3945
+ [xi]() {
3946
+ this[Ce] = true, this.emit("abort", this[Jt]?.reason), this.destroy(this[Jt]?.reason);
3947
+ }
3948
+ get aborted() {
3949
+ return this[Ce];
3950
+ }
3951
+ set aborted(t) {
3952
+ }
3953
+ write(t, e, i) {
3954
+ if (this[Ce]) return false;
3955
+ if (this[Q]) throw new Error("write after end");
3956
+ if (this[S]) return this.emit("error", Object.assign(new Error("Cannot call write after a stream was destroyed"), { code: "ERR_STREAM_DESTROYED" })), true;
3957
+ typeof e == "function" && (i = e, e = "utf8"), e || (e = "utf8");
3958
+ let r = this[Z] ? jt : Yr;
3959
+ if (!this[L] && !Buffer.isBuffer(t)) {
3960
+ if ($r(t)) t = Buffer.from(t.buffer, t.byteOffset, t.byteLength);
3961
+ else if (Vr(t)) t = Buffer.from(t);
3962
+ else if (typeof t != "string") throw new Error("Non-contiguous data written to non-objectMode stream");
3963
+ }
3964
+ return this[L] ? (this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : t.length ? (typeof t == "string" && !(e === this[z] && !this[Mt]?.lastNeed) && (t = Buffer.from(t, e)), Buffer.isBuffer(t) && this[z] && (t = this[Mt].write(t)), this[g] && this[_] !== 0 && this[Ae](true), this[g] ? this.emit("data", t) : this[bi](t), this[_] !== 0 && this.emit("readable"), i && r(i), this[g]) : (this[_] !== 0 && this.emit("readable"), i && r(i), this[g]);
3965
+ }
3966
+ read(t) {
3967
+ if (this[S]) return null;
3968
+ if (this[C] = false, this[_] === 0 || t === 0 || t && t > this[_]) return this[J](), null;
3969
+ this[L] && (t = null), this[b].length > 1 && !this[L] && (this[b] = [this[z] ? this[b].join("") : Buffer.concat(this[b], this[_])]);
3970
+ let e = this[Ns](t || null, this[b][0]);
3971
+ return this[J](), e;
3972
+ }
3973
+ [Ns](t, e) {
3974
+ if (this[L]) this[Ie]();
3975
+ else {
3976
+ let i = e;
3977
+ t === i.length || t === null ? this[Ie]() : typeof i == "string" ? (this[b][0] = i.slice(t), e = i.slice(0, t), this[_] -= t) : (this[b][0] = i.subarray(t), e = i.subarray(0, t), this[_] -= t);
3978
+ }
3979
+ return this.emit("data", e), !this[b].length && !this[Q] && this.emit("drain"), e;
3980
+ }
3981
+ end(t, e, i) {
3982
+ return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = "utf8"), t !== void 0 && this.write(t, e), i && this.once("end", i), this[Q] = true, this.writable = false, (this[g] || !this[Qt]) && this[J](), this;
3983
+ }
3984
+ [Bt]() {
3985
+ this[S] || (!this[Rt] && !this[N].length && (this[C] = true), this[Qt] = false, this[g] = true, this.emit("resume"), this[b].length ? this[Ae]() : this[Q] ? this[J]() : this.emit("drain"));
3986
+ }
3987
+ resume() {
3988
+ return this[Bt]();
3989
+ }
3990
+ pause() {
3991
+ this[g] = false, this[Qt] = true, this[C] = false;
3992
+ }
3993
+ get destroyed() {
3994
+ return this[S];
3995
+ }
3996
+ get flowing() {
3997
+ return this[g];
3998
+ }
3999
+ get paused() {
4000
+ return this[Qt];
4001
+ }
4002
+ [bi](t) {
4003
+ this[L] ? this[_] += 1 : this[_] += t.length, this[b].push(t);
4004
+ }
4005
+ [Ie]() {
4006
+ return this[L] ? this[_] -= 1 : this[_] -= this[b][0].length, this[b].shift();
4007
+ }
4008
+ [Ae](t = false) {
4009
+ do
4010
+ ;
4011
+ while (this[As](this[Ie]()) && this[b].length);
4012
+ !t && !this[b].length && !this[Q] && this.emit("drain");
4013
+ }
4014
+ [As](t) {
4015
+ return this.emit("data", t), this[g];
4016
+ }
4017
+ pipe(t, e) {
4018
+ if (this[S]) return t;
4019
+ this[C] = false;
4020
+ let i = this[nt];
4021
+ return e = e || {}, t === Ds.stdout || t === Ds.stderr ? e.end = false : e.end = e.end !== false, e.proxyErrors = !!e.proxyErrors, i ? e.end && t.end() : (this[N].push(e.proxyErrors ? new Li(this, t, e) : new Fe(this, t, e)), this[Z] ? jt(() => this[Bt]()) : this[Bt]()), t;
4022
+ }
4023
+ unpipe(t) {
4024
+ let e = this[N].find((i) => i.dest === t);
4025
+ e && (this[N].length === 1 ? (this[g] && this[Rt] === 0 && (this[g] = false), this[N] = []) : this[N].splice(this[N].indexOf(e), 1), e.unpipe());
4026
+ }
4027
+ addListener(t, e) {
4028
+ return this.on(t, e);
4029
+ }
4030
+ on(t, e) {
4031
+ let i = super.on(t, e);
4032
+ if (t === "data") this[C] = false, this[Rt]++, !this[N].length && !this[g] && this[Bt]();
4033
+ else if (t === "readable" && this[_] !== 0) super.emit("readable");
4034
+ else if (Kr(t) && this[nt]) super.emit(t), this.removeAllListeners(t);
4035
+ else if (t === "error" && this[qt]) {
4036
+ let r = e;
4037
+ this[Z] ? jt(() => r.call(this, this[qt])) : r.call(this, this[qt]);
4038
+ }
4039
+ return i;
4040
+ }
4041
+ removeListener(t, e) {
4042
+ return this.off(t, e);
4043
+ }
4044
+ off(t, e) {
4045
+ let i = super.off(t, e);
4046
+ return t === "data" && (this[Rt] = this.listeners("data").length, this[Rt] === 0 && !this[C] && !this[N].length && (this[g] = false)), i;
4047
+ }
4048
+ removeAllListeners(t) {
4049
+ let e = super.removeAllListeners(t);
4050
+ return (t === "data" || t === void 0) && (this[Rt] = 0, !this[C] && !this[N].length && (this[g] = false)), e;
4051
+ }
4052
+ get emittedEnd() {
4053
+ return this[nt];
4054
+ }
4055
+ [J]() {
4056
+ !this[De] && !this[nt] && !this[S] && this[b].length === 0 && this[Q] && (this[De] = true, this.emit("end"), this.emit("prefinish"), this.emit("finish"), this[Ne] && this.emit("close"), this[De] = false);
4057
+ }
4058
+ emit(t, ...e) {
4059
+ let i = e[0];
4060
+ if (t !== "error" && t !== "close" && t !== S && this[S]) return false;
4061
+ if (t === "data") return !this[L] && !i ? false : this[Z] ? (jt(() => this[Oi](i)), true) : this[Oi](i);
4062
+ if (t === "end") return this[Is]();
4063
+ if (t === "close") {
4064
+ if (this[Ne] = true, !this[nt] && !this[S]) return false;
4065
+ let n = super.emit("close");
4066
+ return this.removeAllListeners("close"), n;
4067
+ } else if (t === "error") {
4068
+ this[qt] = i, super.emit(_i, i);
4069
+ let n = !this[Jt] || this.listeners("error").length ? super.emit("error", i) : false;
4070
+ return this[J](), n;
4071
+ } else if (t === "resume") {
4072
+ let n = super.emit("resume");
4073
+ return this[J](), n;
4074
+ } else if (t === "finish" || t === "prefinish") {
4075
+ let n = super.emit(t);
4076
+ return this.removeAllListeners(t), n;
4077
+ }
4078
+ let r = super.emit(t, ...e);
4079
+ return this[J](), r;
4080
+ }
4081
+ [Oi](t) {
4082
+ for (let i of this[N]) i.dest.write(t) === false && this.pause();
4083
+ let e = this[C] ? false : super.emit("data", t);
4084
+ return this[J](), e;
4085
+ }
4086
+ [Is]() {
4087
+ return this[nt] ? false : (this[nt] = true, this.readable = false, this[Z] ? (jt(() => this[Ti]()), true) : this[Ti]());
4088
+ }
4089
+ [Ti]() {
4090
+ if (this[Mt]) {
4091
+ let e = this[Mt].end();
4092
+ if (e) {
4093
+ for (let i of this[N]) i.dest.write(e);
4094
+ this[C] || super.emit("data", e);
4095
+ }
4096
+ }
4097
+ for (let e of this[N]) e.end();
4098
+ let t = super.emit("end");
4099
+ return this.removeAllListeners("end"), t;
4100
+ }
4101
+ async collect() {
4102
+ let t = Object.assign([], { dataLength: 0 });
4103
+ this[L] || (t.dataLength = 0);
4104
+ let e = this.promise();
4105
+ return this.on("data", (i) => {
4106
+ t.push(i), this[L] || (t.dataLength += i.length);
4107
+ }), await e, t;
4108
+ }
4109
+ async concat() {
4110
+ if (this[L]) throw new Error("cannot concat in objectMode");
4111
+ let t = await this.collect();
4112
+ return this[z] ? t.join("") : Buffer.concat(t, t.dataLength);
4113
+ }
4114
+ async promise() {
4115
+ return new Promise((t, e) => {
4116
+ this.on(S, () => e(new Error("stream destroyed"))), this.on("error", (i) => e(i)), this.on("end", () => t());
4117
+ });
4118
+ }
4119
+ [Symbol.asyncIterator]() {
4120
+ this[C] = false;
4121
+ let t = false, e = async () => (this.pause(), t = true, { value: void 0, done: true });
4122
+ return { next: () => {
4123
+ if (t) return e();
4124
+ let r = this.read();
4125
+ if (r !== null) return Promise.resolve({ done: false, value: r });
4126
+ if (this[Q]) return e();
4127
+ let n, o, h = (d) => {
4128
+ this.off("data", a), this.off("end", l), this.off(S, c), e(), o(d);
4129
+ }, a = (d) => {
4130
+ this.off("error", h), this.off("end", l), this.off(S, c), this.pause(), n({ value: d, done: !!this[Q] });
4131
+ }, l = () => {
4132
+ this.off("error", h), this.off("data", a), this.off(S, c), e(), n({ done: true, value: void 0 });
4133
+ }, c = () => h(new Error("stream destroyed"));
4134
+ return new Promise((d, y) => {
4135
+ o = y, n = d, this.once(S, c), this.once("error", h), this.once("end", l), this.once("data", a);
4136
+ });
4137
+ }, throw: e, return: e, [Symbol.asyncIterator]() {
4138
+ return this;
4139
+ }, [Symbol.asyncDispose]: async () => {
4140
+ } };
4141
+ }
4142
+ [Symbol.iterator]() {
4143
+ this[C] = false;
4144
+ let t = false, e = () => (this.pause(), this.off(_i, e), this.off(S, e), this.off("end", e), t = true, { done: true, value: void 0 }), i = () => {
4145
+ if (t) return e();
4146
+ let r = this.read();
4147
+ return r === null ? e() : { done: false, value: r };
4148
+ };
4149
+ return this.once("end", e), this.once(_i, e), this.once(S, e), { next: i, throw: e, return: e, [Symbol.iterator]() {
4150
+ return this;
4151
+ }, [Symbol.dispose]: () => {
4152
+ } };
4153
+ }
4154
+ destroy(t) {
4155
+ if (this[S]) return t ? this.emit("error", t) : this.emit(S), this;
4156
+ this[S] = true, this[C] = true, this[b].length = 0, this[_] = 0;
4157
+ let e = this;
4158
+ return typeof e.close == "function" && !this[Ne] && e.close(), t ? this.emit("error", t) : this.emit(S), this;
4159
+ }
4160
+ static get isStream() {
4161
+ return Wr;
4162
+ }
4163
+ };
4164
+ var Jr = I.writev;
4165
+ var ht = /* @__PURE__ */ Symbol("_autoClose");
4166
+ var H = /* @__PURE__ */ Symbol("_close");
4167
+ var te = /* @__PURE__ */ Symbol("_ended");
4168
+ var m = /* @__PURE__ */ Symbol("_fd");
4169
+ var Ni = /* @__PURE__ */ Symbol("_finished");
4170
+ var tt = /* @__PURE__ */ Symbol("_flags");
4171
+ var Ai = /* @__PURE__ */ Symbol("_flush");
4172
+ var ki = /* @__PURE__ */ Symbol("_handleChunk");
4173
+ var vi = /* @__PURE__ */ Symbol("_makeBuf");
4174
+ var ie = /* @__PURE__ */ Symbol("_mode");
4175
+ var ke = /* @__PURE__ */ Symbol("_needDrain");
4176
+ var Ut = /* @__PURE__ */ Symbol("_onerror");
4177
+ var Ht = /* @__PURE__ */ Symbol("_onopen");
4178
+ var Ii = /* @__PURE__ */ Symbol("_onread");
4179
+ var Pt = /* @__PURE__ */ Symbol("_onwrite");
4180
+ var at = /* @__PURE__ */ Symbol("_open");
4181
+ var U = /* @__PURE__ */ Symbol("_path");
4182
+ var ot = /* @__PURE__ */ Symbol("_pos");
4183
+ var Y = /* @__PURE__ */ Symbol("_queue");
4184
+ var zt = /* @__PURE__ */ Symbol("_read");
4185
+ var Ci = /* @__PURE__ */ Symbol("_readSize");
4186
+ var j = /* @__PURE__ */ Symbol("_reading");
4187
+ var ee = /* @__PURE__ */ Symbol("_remain");
4188
+ var Fi = /* @__PURE__ */ Symbol("_size");
4189
+ var ve = /* @__PURE__ */ Symbol("_write");
4190
+ var gt = /* @__PURE__ */ Symbol("_writing");
4191
+ var Me = /* @__PURE__ */ Symbol("_defaultFlag");
4192
+ var bt = /* @__PURE__ */ Symbol("_errored");
4193
+ var _t = class extends A {
4194
+ [bt] = false;
4195
+ [m];
4196
+ [U];
4197
+ [Ci];
4198
+ [j] = false;
4199
+ [Fi];
4200
+ [ee];
4201
+ [ht];
4202
+ constructor(t, e) {
4203
+ if (e = e || {}, super(e), this.readable = true, this.writable = false, typeof t != "string") throw new TypeError("path must be a string");
4204
+ this[bt] = false, this[m] = typeof e.fd == "number" ? e.fd : void 0, this[U] = t, this[Ci] = e.readSize || 16 * 1024 * 1024, this[j] = false, this[Fi] = typeof e.size == "number" ? e.size : 1 / 0, this[ee] = this[Fi], this[ht] = typeof e.autoClose == "boolean" ? e.autoClose : true, typeof this[m] == "number" ? this[zt]() : this[at]();
4205
+ }
4206
+ get fd() {
4207
+ return this[m];
4208
+ }
4209
+ get path() {
4210
+ return this[U];
4211
+ }
4212
+ write() {
4213
+ throw new TypeError("this is a readable stream");
4214
+ }
4215
+ end() {
4216
+ throw new TypeError("this is a readable stream");
4217
+ }
4218
+ [at]() {
4219
+ I.open(this[U], "r", (t, e) => this[Ht](t, e));
4220
+ }
4221
+ [Ht](t, e) {
4222
+ t ? this[Ut](t) : (this[m] = e, this.emit("open", e), this[zt]());
4223
+ }
4224
+ [vi]() {
4225
+ return Buffer.allocUnsafe(Math.min(this[Ci], this[ee]));
4226
+ }
4227
+ [zt]() {
4228
+ if (!this[j]) {
4229
+ this[j] = true;
4230
+ let t = this[vi]();
4231
+ if (t.length === 0) return process.nextTick(() => this[Ii](null, 0, t));
4232
+ I.read(this[m], t, 0, t.length, null, (e, i, r) => this[Ii](e, i, r));
4233
+ }
4234
+ }
4235
+ [Ii](t, e, i) {
4236
+ this[j] = false, t ? this[Ut](t) : this[ki](e, i) && this[zt]();
4237
+ }
4238
+ [H]() {
4239
+ if (this[ht] && typeof this[m] == "number") {
4240
+ let t = this[m];
4241
+ this[m] = void 0, I.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
4242
+ }
4243
+ }
4244
+ [Ut](t) {
4245
+ this[j] = true, this[H](), this.emit("error", t);
4246
+ }
4247
+ [ki](t, e) {
4248
+ let i = false;
4249
+ return this[ee] -= t, t > 0 && (i = super.write(t < e.length ? e.subarray(0, t) : e)), (t === 0 || this[ee] <= 0) && (i = false, this[H](), super.end()), i;
4250
+ }
4251
+ emit(t, ...e) {
4252
+ switch (t) {
4253
+ case "prefinish":
4254
+ case "finish":
4255
+ return false;
4256
+ case "drain":
4257
+ return typeof this[m] == "number" && this[zt](), false;
4258
+ case "error":
4259
+ return this[bt] ? false : (this[bt] = true, super.emit(t, ...e));
4260
+ default:
4261
+ return super.emit(t, ...e);
4262
+ }
4263
+ }
4264
+ };
4265
+ var Be = class extends _t {
4266
+ [at]() {
4267
+ let t = true;
4268
+ try {
4269
+ this[Ht](null, I.openSync(this[U], "r")), t = false;
4270
+ } finally {
4271
+ t && this[H]();
4272
+ }
4273
+ }
4274
+ [zt]() {
4275
+ let t = true;
4276
+ try {
4277
+ if (!this[j]) {
4278
+ this[j] = true;
4279
+ do {
4280
+ let e = this[vi](), i = e.length === 0 ? 0 : I.readSync(this[m], e, 0, e.length, null);
4281
+ if (!this[ki](i, e)) break;
4282
+ } while (true);
4283
+ this[j] = false;
4284
+ }
4285
+ t = false;
4286
+ } finally {
4287
+ t && this[H]();
4288
+ }
4289
+ }
4290
+ [H]() {
4291
+ if (this[ht] && typeof this[m] == "number") {
4292
+ let t = this[m];
4293
+ this[m] = void 0, I.closeSync(t), this.emit("close");
4294
+ }
4295
+ }
4296
+ };
4297
+ var et = class extends Qr {
4298
+ readable = false;
4299
+ writable = true;
4300
+ [bt] = false;
4301
+ [gt] = false;
4302
+ [te] = false;
4303
+ [Y] = [];
4304
+ [ke] = false;
4305
+ [U];
4306
+ [ie];
4307
+ [ht];
4308
+ [m];
4309
+ [Me];
4310
+ [tt];
4311
+ [Ni] = false;
4312
+ [ot];
4313
+ constructor(t, e) {
4314
+ e = e || {}, super(e), this[U] = t, this[m] = typeof e.fd == "number" ? e.fd : void 0, this[ie] = e.mode === void 0 ? 438 : e.mode, this[ot] = typeof e.start == "number" ? e.start : void 0, this[ht] = typeof e.autoClose == "boolean" ? e.autoClose : true;
4315
+ let i = this[ot] !== void 0 ? "r+" : "w";
4316
+ this[Me] = e.flags === void 0, this[tt] = e.flags === void 0 ? i : e.flags, this[m] === void 0 && this[at]();
4317
+ }
4318
+ emit(t, ...e) {
4319
+ if (t === "error") {
4320
+ if (this[bt]) return false;
4321
+ this[bt] = true;
4322
+ }
4323
+ return super.emit(t, ...e);
4324
+ }
4325
+ get fd() {
4326
+ return this[m];
4327
+ }
4328
+ get path() {
4329
+ return this[U];
4330
+ }
4331
+ [Ut](t) {
4332
+ this[H](), this[gt] = true, this.emit("error", t);
4333
+ }
4334
+ [at]() {
4335
+ I.open(this[U], this[tt], this[ie], (t, e) => this[Ht](t, e));
4336
+ }
4337
+ [Ht](t, e) {
4338
+ this[Me] && this[tt] === "r+" && t && t.code === "ENOENT" ? (this[tt] = "w", this[at]()) : t ? this[Ut](t) : (this[m] = e, this.emit("open", e), this[gt] || this[Ai]());
4339
+ }
4340
+ end(t, e) {
4341
+ return t && this.write(t, e), this[te] = true, !this[gt] && !this[Y].length && typeof this[m] == "number" && this[Pt](null, 0), this;
4342
+ }
4343
+ write(t, e) {
4344
+ return typeof t == "string" && (t = Buffer.from(t, e)), this[te] ? (this.emit("error", new Error("write() after end()")), false) : this[m] === void 0 || this[gt] || this[Y].length ? (this[Y].push(t), this[ke] = true, false) : (this[gt] = true, this[ve](t), true);
4345
+ }
4346
+ [ve](t) {
4347
+ I.write(this[m], t, 0, t.length, this[ot], (e, i) => this[Pt](e, i));
4348
+ }
4349
+ [Pt](t, e) {
4350
+ t ? this[Ut](t) : (this[ot] !== void 0 && typeof e == "number" && (this[ot] += e), this[Y].length ? this[Ai]() : (this[gt] = false, this[te] && !this[Ni] ? (this[Ni] = true, this[H](), this.emit("finish")) : this[ke] && (this[ke] = false, this.emit("drain"))));
4351
+ }
4352
+ [Ai]() {
4353
+ if (this[Y].length === 0) this[te] && this[Pt](null, 0);
4354
+ else if (this[Y].length === 1) this[ve](this[Y].pop());
4355
+ else {
4356
+ let t = this[Y];
4357
+ this[Y] = [], Jr(this[m], t, this[ot], (e, i) => this[Pt](e, i));
4358
+ }
4359
+ }
4360
+ [H]() {
4361
+ if (this[ht] && typeof this[m] == "number") {
4362
+ let t = this[m];
4363
+ this[m] = void 0, I.close(t, (e) => e ? this.emit("error", e) : this.emit("close"));
4364
+ }
4365
+ }
4366
+ };
4367
+ var Wt = class extends et {
4368
+ [at]() {
4369
+ let t;
4370
+ if (this[Me] && this[tt] === "r+") try {
4371
+ t = I.openSync(this[U], this[tt], this[ie]);
4372
+ } catch (e) {
4373
+ if (e?.code === "ENOENT") return this[tt] = "w", this[at]();
4374
+ throw e;
4375
+ }
4376
+ else t = I.openSync(this[U], this[tt], this[ie]);
4377
+ this[Ht](null, t);
4378
+ }
4379
+ [H]() {
4380
+ if (this[ht] && typeof this[m] == "number") {
4381
+ let t = this[m];
4382
+ this[m] = void 0, I.closeSync(t), this.emit("close");
4383
+ }
4384
+ }
4385
+ [ve](t) {
4386
+ let e = true;
4387
+ try {
4388
+ this[Pt](null, I.writeSync(this[m], t, 0, t.length, this[ot])), e = false;
4389
+ } finally {
4390
+ if (e) try {
4391
+ this[H]();
4392
+ } catch {
4393
+ }
4394
+ }
4395
+ }
4396
+ };
4397
+ var jr = /* @__PURE__ */ new Map([["C", "cwd"], ["f", "file"], ["z", "gzip"], ["P", "preservePaths"], ["U", "unlink"], ["strip-components", "strip"], ["stripComponents", "strip"], ["keep-newer", "newer"], ["keepNewer", "newer"], ["keep-newer-files", "newer"], ["keepNewerFiles", "newer"], ["k", "keep"], ["keep-existing", "keep"], ["keepExisting", "keep"], ["m", "noMtime"], ["no-mtime", "noMtime"], ["p", "preserveOwner"], ["L", "follow"], ["h", "follow"], ["onentry", "onReadEntry"]]);
4398
+ var Fs = (s3) => !!s3.sync && !!s3.file;
4399
+ var ks = (s3) => !s3.sync && !!s3.file;
4400
+ var vs = (s3) => !!s3.sync && !s3.file;
4401
+ var Ms = (s3) => !s3.sync && !s3.file;
4402
+ var Bs = (s3) => !!s3.file;
4403
+ var tn = (s3) => {
4404
+ let t = jr.get(s3);
4405
+ return t || s3;
4406
+ };
4407
+ var se = (s3 = {}) => {
4408
+ if (!s3) return {};
4409
+ let t = {};
4410
+ for (let [e, i] of Object.entries(s3)) {
4411
+ let r = tn(e);
4412
+ t[r] = i;
4413
+ }
4414
+ return t.chmod === void 0 && t.noChmod === false && (t.chmod = true), delete t.noChmod, t;
4415
+ };
4416
+ var K = (s3, t, e, i, r) => Object.assign((n = [], o, h) => {
4417
+ Array.isArray(n) && (o = n, n = {}), typeof o == "function" && (h = o, o = void 0), o = o ? Array.from(o) : [];
4418
+ let a = se(n);
4419
+ if (r?.(a, o), Fs(a)) {
4420
+ if (typeof h == "function") throw new TypeError("callback not supported for sync tar functions");
4421
+ return s3(a, o);
4422
+ } else if (ks(a)) {
4423
+ let l = t(a, o);
4424
+ return h ? l.then(() => h(), h) : l;
4425
+ } else if (vs(a)) {
4426
+ if (typeof h == "function") throw new TypeError("callback not supported for sync tar functions");
4427
+ return e(a, o);
4428
+ } else if (Ms(a)) {
4429
+ if (typeof h == "function") throw new TypeError("callback only supported with file option");
4430
+ return i(a, o);
4431
+ }
4432
+ throw new Error("impossible options??");
4433
+ }, { syncFile: s3, asyncFile: t, syncNoFile: e, asyncNoFile: i, validate: r });
4434
+ var sn = en.constants || { ZLIB_VERNUM: 4736 };
4435
+ var M = Object.freeze(Object.assign(/* @__PURE__ */ Object.create(null), { Z_NO_FLUSH: 0, Z_PARTIAL_FLUSH: 1, Z_SYNC_FLUSH: 2, Z_FULL_FLUSH: 3, Z_FINISH: 4, Z_BLOCK: 5, Z_OK: 0, Z_STREAM_END: 1, Z_NEED_DICT: 2, Z_ERRNO: -1, Z_STREAM_ERROR: -2, Z_DATA_ERROR: -3, Z_MEM_ERROR: -4, Z_BUF_ERROR: -5, Z_VERSION_ERROR: -6, Z_NO_COMPRESSION: 0, Z_BEST_SPEED: 1, Z_BEST_COMPRESSION: 9, Z_DEFAULT_COMPRESSION: -1, Z_FILTERED: 1, Z_HUFFMAN_ONLY: 2, Z_RLE: 3, Z_FIXED: 4, Z_DEFAULT_STRATEGY: 0, DEFLATE: 1, INFLATE: 2, GZIP: 3, GUNZIP: 4, DEFLATERAW: 5, INFLATERAW: 6, UNZIP: 7, BROTLI_DECODE: 8, BROTLI_ENCODE: 9, Z_MIN_WINDOWBITS: 8, Z_MAX_WINDOWBITS: 15, Z_DEFAULT_WINDOWBITS: 15, Z_MIN_CHUNK: 64, Z_MAX_CHUNK: 1 / 0, Z_DEFAULT_CHUNK: 16384, Z_MIN_MEMLEVEL: 1, Z_MAX_MEMLEVEL: 9, Z_DEFAULT_MEMLEVEL: 8, Z_MIN_LEVEL: -1, Z_MAX_LEVEL: 9, Z_DEFAULT_LEVEL: -1, BROTLI_OPERATION_PROCESS: 0, BROTLI_OPERATION_FLUSH: 1, BROTLI_OPERATION_FINISH: 2, BROTLI_OPERATION_EMIT_METADATA: 3, BROTLI_MODE_GENERIC: 0, BROTLI_MODE_TEXT: 1, BROTLI_MODE_FONT: 2, BROTLI_DEFAULT_MODE: 0, BROTLI_MIN_QUALITY: 0, BROTLI_MAX_QUALITY: 11, BROTLI_DEFAULT_QUALITY: 11, BROTLI_MIN_WINDOW_BITS: 10, BROTLI_MAX_WINDOW_BITS: 24, BROTLI_LARGE_MAX_WINDOW_BITS: 30, BROTLI_DEFAULT_WINDOW: 22, BROTLI_MIN_INPUT_BLOCK_BITS: 16, BROTLI_MAX_INPUT_BLOCK_BITS: 24, BROTLI_PARAM_MODE: 0, BROTLI_PARAM_QUALITY: 1, BROTLI_PARAM_LGWIN: 2, BROTLI_PARAM_LGBLOCK: 3, BROTLI_PARAM_DISABLE_LITERAL_CONTEXT_MODELING: 4, BROTLI_PARAM_SIZE_HINT: 5, BROTLI_PARAM_LARGE_WINDOW: 6, BROTLI_PARAM_NPOSTFIX: 7, BROTLI_PARAM_NDIRECT: 8, BROTLI_DECODER_RESULT_ERROR: 0, BROTLI_DECODER_RESULT_SUCCESS: 1, BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_RESULT_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_PARAM_DISABLE_RING_BUFFER_REALLOCATION: 0, BROTLI_DECODER_PARAM_LARGE_WINDOW: 1, BROTLI_DECODER_NO_ERROR: 0, BROTLI_DECODER_SUCCESS: 1, BROTLI_DECODER_NEEDS_MORE_INPUT: 2, BROTLI_DECODER_NEEDS_MORE_OUTPUT: 3, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_NIBBLE: -1, BROTLI_DECODER_ERROR_FORMAT_RESERVED: -2, BROTLI_DECODER_ERROR_FORMAT_EXUBERANT_META_NIBBLE: -3, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_ALPHABET: -4, BROTLI_DECODER_ERROR_FORMAT_SIMPLE_HUFFMAN_SAME: -5, BROTLI_DECODER_ERROR_FORMAT_CL_SPACE: -6, BROTLI_DECODER_ERROR_FORMAT_HUFFMAN_SPACE: -7, BROTLI_DECODER_ERROR_FORMAT_CONTEXT_MAP_REPEAT: -8, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_1: -9, BROTLI_DECODER_ERROR_FORMAT_BLOCK_LENGTH_2: -10, BROTLI_DECODER_ERROR_FORMAT_TRANSFORM: -11, BROTLI_DECODER_ERROR_FORMAT_DICTIONARY: -12, BROTLI_DECODER_ERROR_FORMAT_WINDOW_BITS: -13, BROTLI_DECODER_ERROR_FORMAT_PADDING_1: -14, BROTLI_DECODER_ERROR_FORMAT_PADDING_2: -15, BROTLI_DECODER_ERROR_FORMAT_DISTANCE: -16, BROTLI_DECODER_ERROR_DICTIONARY_NOT_SET: -19, BROTLI_DECODER_ERROR_INVALID_ARGUMENTS: -20, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MODES: -21, BROTLI_DECODER_ERROR_ALLOC_TREE_GROUPS: -22, BROTLI_DECODER_ERROR_ALLOC_CONTEXT_MAP: -25, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_1: -26, BROTLI_DECODER_ERROR_ALLOC_RING_BUFFER_2: -27, BROTLI_DECODER_ERROR_ALLOC_BLOCK_TYPE_TREES: -30, BROTLI_DECODER_ERROR_UNREACHABLE: -31 }, sn));
4436
+ var rn = Ot.concat;
4437
+ var zs = Object.getOwnPropertyDescriptor(Ot, "concat");
4438
+ var nn = (s3) => s3;
4439
+ var Bi = zs?.writable === true || zs?.set !== void 0 ? (s3) => {
4440
+ Ot.concat = s3 ? nn : rn;
4441
+ } : (s3) => {
4442
+ };
4443
+ var Tt = /* @__PURE__ */ Symbol("_superWrite");
4444
+ var Gt = class extends Error {
4445
+ code;
4446
+ errno;
4447
+ constructor(t, e) {
4448
+ super("zlib: " + t.message, { cause: t }), this.code = t.code, this.errno = t.errno, this.code || (this.code = "ZLIB_ERROR"), this.message = "zlib: " + t.message, Error.captureStackTrace(this, e ?? this.constructor);
4449
+ }
4450
+ get name() {
4451
+ return "ZlibError";
4452
+ }
4453
+ };
4454
+ var Pi = /* @__PURE__ */ Symbol("flushFlag");
4455
+ var re = class extends A {
4456
+ #t = false;
4457
+ #i = false;
4458
+ #s;
4459
+ #n;
4460
+ #r;
4461
+ #e;
4462
+ #o;
4463
+ get sawError() {
4464
+ return this.#t;
4465
+ }
4466
+ get handle() {
4467
+ return this.#e;
4468
+ }
4469
+ get flushFlag() {
4470
+ return this.#s;
4471
+ }
4472
+ constructor(t, e) {
4473
+ if (!t || typeof t != "object") throw new TypeError("invalid options for ZlibBase constructor");
4474
+ if (super(t), this.#s = t.flush ?? 0, this.#n = t.finishFlush ?? 0, this.#r = t.fullFlushFlag ?? 0, typeof Ps[e] != "function") throw new TypeError("Compression method not supported: " + e);
4475
+ try {
4476
+ this.#e = new Ps[e](t);
4477
+ } catch (i) {
4478
+ throw new Gt(i, this.constructor);
4479
+ }
4480
+ this.#o = (i) => {
4481
+ this.#t || (this.#t = true, this.close(), this.emit("error", i));
4482
+ }, this.#e?.on("error", (i) => this.#o(new Gt(i))), this.once("end", () => this.close);
4483
+ }
4484
+ close() {
4485
+ this.#e && (this.#e.close(), this.#e = void 0, this.emit("close"));
4486
+ }
4487
+ reset() {
4488
+ if (!this.#t) return zi(this.#e, "zlib binding closed"), this.#e.reset?.();
4489
+ }
4490
+ flush(t) {
4491
+ this.ended || (typeof t != "number" && (t = this.#r), this.write(Object.assign(Ot.alloc(0), { [Pi]: t })));
4492
+ }
4493
+ end(t, e, i) {
4494
+ return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), t && (e ? this.write(t, e) : this.write(t)), this.flush(this.#n), this.#i = true, super.end(i);
4495
+ }
4496
+ get ended() {
4497
+ return this.#i;
4498
+ }
4499
+ [Tt](t) {
4500
+ return super.write(t);
4501
+ }
4502
+ write(t, e, i) {
4503
+ if (typeof e == "function" && (i = e, e = "utf8"), typeof t == "string" && (t = Ot.from(t, e)), this.#t) return;
4504
+ zi(this.#e, "zlib binding closed");
4505
+ let r = this.#e._handle, n = r.close;
4506
+ r.close = () => {
4507
+ };
4508
+ let o = this.#e.close;
4509
+ this.#e.close = () => {
4510
+ }, Bi(true);
4511
+ let h;
4512
+ try {
4513
+ let l = typeof t[Pi] == "number" ? t[Pi] : this.#s;
4514
+ h = this.#e._processChunk(t, l), Bi(false);
4515
+ } catch (l) {
4516
+ Bi(false), this.#o(new Gt(l, this.write));
4517
+ } finally {
4518
+ this.#e && (this.#e._handle = r, r.close = n, this.#e.close = o, this.#e.removeAllListeners("error"));
4519
+ }
4520
+ this.#e && this.#e.on("error", (l) => this.#o(new Gt(l, this.write)));
4521
+ let a;
4522
+ if (h) if (Array.isArray(h) && h.length > 0) {
4523
+ let l = h[0];
4524
+ a = this[Tt](Ot.from(l));
4525
+ for (let c = 1; c < h.length; c++) a = this[Tt](h[c]);
4526
+ } else a = this[Tt](Ot.from(h));
4527
+ return i && i(), a;
4528
+ }
4529
+ };
4530
+ var Pe = class extends re {
4531
+ #t;
4532
+ #i;
4533
+ constructor(t, e) {
4534
+ t = t || {}, t.flush = t.flush || M.Z_NO_FLUSH, t.finishFlush = t.finishFlush || M.Z_FINISH, t.fullFlushFlag = M.Z_FULL_FLUSH, super(t, e), this.#t = t.level, this.#i = t.strategy;
4535
+ }
4536
+ params(t, e) {
4537
+ if (!this.sawError) {
4538
+ if (!this.handle) throw new Error("cannot switch params when binding is closed");
4539
+ if (!this.handle.params) throw new Error("not supported in this implementation");
4540
+ if (this.#t !== t || this.#i !== e) {
4541
+ this.flush(M.Z_SYNC_FLUSH), zi(this.handle, "zlib binding closed");
4542
+ let i = this.handle.flush;
4543
+ this.handle.flush = (r, n) => {
4544
+ typeof r == "function" && (n = r, r = this.flushFlag), this.flush(r), n?.();
4545
+ };
4546
+ try {
4547
+ this.handle.params(t, e);
4548
+ } finally {
4549
+ this.handle.flush = i;
4550
+ }
4551
+ this.handle && (this.#t = t, this.#i = e);
4552
+ }
4553
+ }
4554
+ }
4555
+ };
4556
+ var ze = class extends Pe {
4557
+ #t;
4558
+ constructor(t) {
4559
+ super(t, "Gzip"), this.#t = t && !!t.portable;
4560
+ }
4561
+ [Tt](t) {
4562
+ return this.#t ? (this.#t = false, t[9] = 255, super[Tt](t)) : super[Tt](t);
4563
+ }
4564
+ };
4565
+ var Ue = class extends Pe {
4566
+ constructor(t) {
4567
+ super(t, "Unzip");
4568
+ }
4569
+ };
4570
+ var He = class extends re {
4571
+ constructor(t, e) {
4572
+ t = t || {}, t.flush = t.flush || M.BROTLI_OPERATION_PROCESS, t.finishFlush = t.finishFlush || M.BROTLI_OPERATION_FINISH, t.fullFlushFlag = M.BROTLI_OPERATION_FLUSH, super(t, e);
4573
+ }
4574
+ };
4575
+ var We = class extends He {
4576
+ constructor(t) {
4577
+ super(t, "BrotliCompress");
4578
+ }
4579
+ };
4580
+ var Ge = class extends He {
4581
+ constructor(t) {
4582
+ super(t, "BrotliDecompress");
4583
+ }
4584
+ };
4585
+ var Ze = class extends re {
4586
+ constructor(t, e) {
4587
+ t = t || {}, t.flush = t.flush || M.ZSTD_e_continue, t.finishFlush = t.finishFlush || M.ZSTD_e_end, t.fullFlushFlag = M.ZSTD_e_flush, super(t, e);
4588
+ }
4589
+ };
4590
+ var Ye = class extends Ze {
4591
+ constructor(t) {
4592
+ super(t, "ZstdCompress");
4593
+ }
4594
+ };
4595
+ var Ke = class extends Ze {
4596
+ constructor(t) {
4597
+ super(t, "ZstdDecompress");
4598
+ }
4599
+ };
4600
+ var Us = (s3, t) => {
4601
+ if (Number.isSafeInteger(s3)) s3 < 0 ? an(s3, t) : hn(s3, t);
4602
+ else throw Error("cannot encode number outside of javascript safe integer range");
4603
+ return t;
4604
+ };
4605
+ var hn = (s3, t) => {
4606
+ t[0] = 128;
4607
+ for (var e = t.length; e > 1; e--) t[e - 1] = s3 & 255, s3 = Math.floor(s3 / 256);
4608
+ };
4609
+ var an = (s3, t) => {
4610
+ t[0] = 255;
4611
+ var e = false;
4612
+ s3 = s3 * -1;
4613
+ for (var i = t.length; i > 1; i--) {
4614
+ var r = s3 & 255;
4615
+ s3 = Math.floor(s3 / 256), e ? t[i - 1] = Ws(r) : r === 0 ? t[i - 1] = 0 : (e = true, t[i - 1] = Gs(r));
4616
+ }
4617
+ };
4618
+ var Hs = (s3) => {
4619
+ let t = s3[0], e = t === 128 ? cn(s3.subarray(1, s3.length)) : t === 255 ? ln(s3) : null;
4620
+ if (e === null) throw Error("invalid base256 encoding");
4621
+ if (!Number.isSafeInteger(e)) throw Error("parsed number outside of javascript safe integer range");
4622
+ return e;
4623
+ };
4624
+ var ln = (s3) => {
4625
+ for (var t = s3.length, e = 0, i = false, r = t - 1; r > -1; r--) {
4626
+ var n = Number(s3[r]), o;
4627
+ i ? o = Ws(n) : n === 0 ? o = n : (i = true, o = Gs(n)), o !== 0 && (e -= o * Math.pow(256, t - r - 1));
4628
+ }
4629
+ return e;
4630
+ };
4631
+ var cn = (s3) => {
4632
+ for (var t = s3.length, e = 0, i = t - 1; i > -1; i--) {
4633
+ var r = Number(s3[i]);
4634
+ r !== 0 && (e += r * Math.pow(256, t - i - 1));
4635
+ }
4636
+ return e;
4637
+ };
4638
+ var Ws = (s3) => (255 ^ s3) & 255;
4639
+ var Gs = (s3) => (255 ^ s3) + 1 & 255;
4640
+ var Hi = {};
4641
+ Ur(Hi, { code: () => Ve, isCode: () => ne, isName: () => dn, name: () => oe, normalFsTypes: () => Ui });
4642
+ var ne = (s3) => oe.has(s3);
4643
+ var dn = (s3) => Ve.has(s3);
4644
+ var Ui = /* @__PURE__ */ new Set(["0", "", "1", "2", "3", "4", "5", "6", "7", "D"]);
4645
+ var oe = /* @__PURE__ */ new Map([["0", "File"], ["", "OldFile"], ["1", "Link"], ["2", "SymbolicLink"], ["3", "CharacterDevice"], ["4", "BlockDevice"], ["5", "Directory"], ["6", "FIFO"], ["7", "ContiguousFile"], ["g", "GlobalExtendedHeader"], ["x", "ExtendedHeader"], ["A", "SolarisACL"], ["D", "GNUDumpDir"], ["I", "Inode"], ["K", "NextFileHasLongLinkpath"], ["L", "NextFileHasLongPath"], ["M", "ContinuationFile"], ["N", "OldGnuLongPath"], ["S", "SparseFile"], ["V", "TapeVolumeHeader"], ["X", "OldExtendedHeader"]]);
4646
+ var Ve = new Map(Array.from(oe).map((s3) => [s3[1], s3[0]]));
4647
+ var un = (s3) => s3 === void 0 || s3 < 0 ? void 0 : s3;
4648
+ var F = class {
4649
+ cksumValid = false;
4650
+ needPax = false;
4651
+ nullBlock = false;
4652
+ block;
4653
+ path;
4654
+ mode;
4655
+ uid;
4656
+ gid;
4657
+ size;
4658
+ cksum;
4659
+ #t = "Unsupported";
4660
+ linkpath;
4661
+ uname;
4662
+ gname;
4663
+ devmaj = 0;
4664
+ devmin = 0;
4665
+ atime;
4666
+ ctime;
4667
+ mtime;
4668
+ charset;
4669
+ comment;
4670
+ constructor(t, e = 0, i, r) {
4671
+ Buffer.isBuffer(t) ? this.decode(t, e || 0, i, r) : t && this.#i(t);
4672
+ }
4673
+ decode(t, e, i, r) {
4674
+ if (e || (e = 0), !t || !(t.length >= e + 512)) throw new Error("need 512 bytes for header");
4675
+ let n = xt(t, e + 156, 1), o = Ui.has(n), h = o ? i : void 0, a = o ? r : void 0;
4676
+ if (this.path = h?.path ?? xt(t, e, 100), this.mode = h?.mode ?? a?.mode ?? lt(t, e + 100, 8), this.uid = h?.uid ?? a?.uid ?? lt(t, e + 108, 8), this.gid = h?.gid ?? a?.gid ?? lt(t, e + 116, 8), this.size = un(h?.size ?? a?.size ?? lt(t, e + 124, 12)), this.mtime = h?.mtime ?? a?.mtime ?? Wi(t, e + 136, 12), this.cksum = lt(t, e + 148, 12), a && this.#i(a, true), h && this.#i(h), ne(n) && (this.#t = n || "0"), this.#t === "0" && this.path.slice(-1) === "/" && (this.#t = "5"), this.#t === "5" && (this.size = 0), this.linkpath = xt(t, e + 157, 100), t.subarray(e + 257, e + 265).toString() === "ustar\x0000") if (this.uname = h?.uname ?? a?.uname ?? xt(t, e + 265, 32), this.gname = h?.gname ?? a?.gname ?? xt(t, e + 297, 32), this.devmaj = h?.devmaj ?? a?.devmaj ?? lt(t, e + 329, 8) ?? 0, this.devmin = h?.devmin ?? a?.devmin ?? lt(t, e + 337, 8) ?? 0, t[e + 475] !== 0) {
4677
+ let c = xt(t, e + 345, 155);
4678
+ this.path = c + "/" + this.path;
4679
+ } else {
4680
+ let c = xt(t, e + 345, 130);
4681
+ c && (this.path = c + "/" + this.path), this.atime = i?.atime ?? r?.atime ?? Wi(t, e + 476, 12), this.ctime = i?.ctime ?? r?.ctime ?? Wi(t, e + 488, 12);
4682
+ }
4683
+ let l = 256;
4684
+ for (let c = e; c < e + 148; c++) l += t[c];
4685
+ for (let c = e + 156; c < e + 512; c++) l += t[c];
4686
+ this.cksumValid = l === this.cksum, this.cksum === void 0 && l === 256 && (this.nullBlock = true);
4687
+ }
4688
+ #i(t, e = false) {
4689
+ Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "size" && Number(r) < 0 || i === "path" && e || i === "linkpath" && e || i === "global"))));
4690
+ }
4691
+ encode(t, e = 0) {
4692
+ if (t || (t = this.block = Buffer.alloc(512)), this.#t === "Unsupported" && (this.#t = "0"), !(t.length >= e + 512)) throw new Error("need 512 bytes for header");
4693
+ let i = this.ctime || this.atime ? 130 : 155, r = mn(this.path || "", i), n = r[0], o = r[1];
4694
+ this.needPax = !!r[2], this.needPax = Lt(t, e, 100, n) || this.needPax, this.needPax = ct(t, e + 100, 8, this.mode) || this.needPax, this.needPax = ct(t, e + 108, 8, this.uid) || this.needPax, this.needPax = ct(t, e + 116, 8, this.gid) || this.needPax, this.needPax = ct(t, e + 124, 12, this.size) || this.needPax, this.needPax = Gi(t, e + 136, 12, this.mtime) || this.needPax, t[e + 156] = Number(this.#t.codePointAt(0)), this.needPax = Lt(t, e + 157, 100, this.linkpath) || this.needPax, t.write("ustar\x0000", e + 257, 8), this.needPax = Lt(t, e + 265, 32, this.uname) || this.needPax, this.needPax = Lt(t, e + 297, 32, this.gname) || this.needPax, this.needPax = ct(t, e + 329, 8, this.devmaj) || this.needPax, this.needPax = ct(t, e + 337, 8, this.devmin) || this.needPax, this.needPax = Lt(t, e + 345, i, o) || this.needPax, t[e + 475] !== 0 ? this.needPax = Lt(t, e + 345, 155, o) || this.needPax : (this.needPax = Lt(t, e + 345, 130, o) || this.needPax, this.needPax = Gi(t, e + 476, 12, this.atime) || this.needPax, this.needPax = Gi(t, e + 488, 12, this.ctime) || this.needPax);
4695
+ let h = 256;
4696
+ for (let a = e; a < e + 148; a++) h += t[a];
4697
+ for (let a = e + 156; a < e + 512; a++) h += t[a];
4698
+ return this.cksum = h, ct(t, e + 148, 8, this.cksum), this.cksumValid = true, this.needPax;
4699
+ }
4700
+ get type() {
4701
+ return this.#t === "Unsupported" ? this.#t : oe.get(this.#t);
4702
+ }
4703
+ get typeKey() {
4704
+ return this.#t;
4705
+ }
4706
+ set type(t) {
4707
+ let e = String(Ve.get(t));
4708
+ if (ne(e) || e === "Unsupported") this.#t = e;
4709
+ else if (ne(t)) this.#t = t;
4710
+ else throw new TypeError("invalid entry type: " + t);
4711
+ }
4712
+ };
4713
+ var mn = (s3, t) => {
4714
+ let i = s3, r = "", n, o = Zt.parse(s3).root || ".";
4715
+ if (Buffer.byteLength(i) < 100) n = [i, r, false];
4716
+ else {
4717
+ r = Zt.dirname(i), i = Zt.basename(i);
4718
+ do
4719
+ Buffer.byteLength(i) <= 100 && Buffer.byteLength(r) <= t ? n = [i, r, false] : Buffer.byteLength(i) > 100 && Buffer.byteLength(r) <= t ? n = [i.slice(0, 99), r, true] : (i = Zt.join(Zt.basename(r), i), r = Zt.dirname(r));
4720
+ while (r !== o && n === void 0);
4721
+ n || (n = [s3.slice(0, 99), "", true]);
4722
+ }
4723
+ return n;
4724
+ };
4725
+ var xt = (s3, t, e) => s3.subarray(t, t + e).toString("utf8").replace(/\0.*/, "");
4726
+ var Wi = (s3, t, e) => pn(lt(s3, t, e));
4727
+ var pn = (s3) => s3 === void 0 ? void 0 : new Date(s3 * 1e3);
4728
+ var lt = (s3, t, e) => Number(s3[t]) & 128 ? Hs(s3.subarray(t, t + e)) : wn(s3, t, e);
4729
+ var En = (s3) => isNaN(s3) ? void 0 : s3;
4730
+ var wn = (s3, t, e) => En(parseInt(s3.subarray(t, t + e).toString("utf8").replace(/\0.*$/, "").trim(), 8));
4731
+ var Sn = { 12: 8589934591, 8: 2097151 };
4732
+ var ct = (s3, t, e, i) => i === void 0 ? false : i > Sn[e] || i < 0 ? (Us(i, s3.subarray(t, t + e)), true) : (yn(s3, t, e, i), false);
4733
+ var yn = (s3, t, e, i) => s3.write(Rn(i, e), t, e, "ascii");
4734
+ var Rn = (s3, t) => gn(Math.floor(s3).toString(8), t);
4735
+ var gn = (s3, t) => (s3.length === t - 1 ? s3 : new Array(t - s3.length - 1).join("0") + s3 + " ") + "\0";
4736
+ var Gi = (s3, t, e, i) => i === void 0 ? false : ct(s3, t, e, i.getTime() / 1e3);
4737
+ var bn = new Array(156).join("\0");
4738
+ var Lt = (s3, t, e, i) => i === void 0 ? false : (s3.write(i + bn, t, e, "utf8"), i.length !== Buffer.byteLength(i) || i.length > e);
4739
+ var ft = class s {
4740
+ atime;
4741
+ mtime;
4742
+ ctime;
4743
+ charset;
4744
+ comment;
4745
+ gid;
4746
+ uid;
4747
+ gname;
4748
+ uname;
4749
+ linkpath;
4750
+ dev;
4751
+ ino;
4752
+ nlink;
4753
+ path;
4754
+ size;
4755
+ mode;
4756
+ global;
4757
+ constructor(t, e = false) {
4758
+ this.atime = t.atime, this.charset = t.charset, this.comment = t.comment, this.ctime = t.ctime, this.dev = t.dev, this.gid = t.gid, this.global = e, this.gname = t.gname, this.ino = t.ino, this.linkpath = t.linkpath, this.mtime = t.mtime, this.nlink = t.nlink, this.path = t.path, this.size = t.size, this.uid = t.uid, this.uname = t.uname;
4759
+ }
4760
+ encode() {
4761
+ let t = this.encodeBody();
4762
+ if (t === "") return Buffer.allocUnsafe(0);
4763
+ let e = Buffer.byteLength(t), i = 512 * Math.ceil(1 + e / 512), r = Buffer.allocUnsafe(i);
4764
+ for (let n = 0; n < 512; n++) r[n] = 0;
4765
+ new F({ path: ("PaxHeader/" + _n(this.path ?? "")).slice(0, 99), mode: this.mode || 420, uid: this.uid, gid: this.gid, size: e, mtime: this.mtime, type: this.global ? "GlobalExtendedHeader" : "ExtendedHeader", linkpath: "", uname: this.uname || "", gname: this.gname || "", devmaj: 0, devmin: 0, atime: this.atime, ctime: this.ctime }).encode(r), r.write(t, 512, e, "utf8");
4766
+ for (let n = e + 512; n < r.length; n++) r[n] = 0;
4767
+ return r;
4768
+ }
4769
+ encodeBody() {
4770
+ return this.encodeField("path") + this.encodeField("ctime") + this.encodeField("atime") + this.encodeField("dev") + this.encodeField("ino") + this.encodeField("nlink") + this.encodeField("charset") + this.encodeField("comment") + this.encodeField("gid") + this.encodeField("gname") + this.encodeField("linkpath") + this.encodeField("mtime") + this.encodeField("size") + this.encodeField("uid") + this.encodeField("uname");
4771
+ }
4772
+ encodeField(t) {
4773
+ if (this[t] === void 0) return "";
4774
+ let e = this[t], i = e instanceof Date ? e.getTime() / 1e3 : e, r = " " + (t === "dev" || t === "ino" || t === "nlink" ? "SCHILY." : "") + t + "=" + i + `
4775
+ `, n = Buffer.byteLength(r), o = Math.floor(Math.log(n) / Math.log(10)) + 1;
4776
+ return n + o >= Math.pow(10, o) && (o += 1), o + n + r;
4777
+ }
4778
+ static parse(t, e, i = false) {
4779
+ return new s(On(Tn(t), e), i);
4780
+ }
4781
+ };
4782
+ var On = (s3, t) => t ? Object.assign({}, t, s3) : s3;
4783
+ var Tn = (s3) => s3.replace(/\n$/, "").split(`
4784
+ `).reduce(xn, /* @__PURE__ */ Object.create(null));
4785
+ var xn = (s3, t) => {
4786
+ let e = parseInt(t, 10);
4787
+ if (e !== Buffer.byteLength(t) + 1) return s3;
4788
+ t = t.slice((e + " ").length);
4789
+ let i = t.split("="), r = i.shift();
4790
+ if (!r) return s3;
4791
+ let n = r.replace(/^SCHILY\.(dev|ino|nlink)/, "$1"), o = i.join("=").replace(/\0.*/, "");
4792
+ switch (n) {
4793
+ case "path":
4794
+ case "linkpath":
4795
+ case "type":
4796
+ case "charset":
4797
+ case "comment":
4798
+ case "gname":
4799
+ case "uname":
4800
+ s3[n] = o;
4801
+ break;
4802
+ case "ctime":
4803
+ case "atime":
4804
+ case "mtime":
4805
+ s3[n] = new Date(Number(o) * 1e3);
4806
+ break;
4807
+ case "size":
4808
+ let h = +o;
4809
+ h >= 0 && (s3[n] = h);
4810
+ break;
4811
+ case "gid":
4812
+ case "uid":
4813
+ case "dev":
4814
+ case "ino":
4815
+ case "nlink":
4816
+ case "mode":
4817
+ s3[n] = +o;
4818
+ break;
4819
+ }
4820
+ return s3;
4821
+ };
4822
+ var Ln = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
4823
+ var f = Ln !== "win32" ? (s3) => String(s3) : (s3) => String(s3).replaceAll(/\\/g, "/");
4824
+ var $e = class extends A {
4825
+ extended;
4826
+ globalExtended;
4827
+ header;
4828
+ startBlockSize;
4829
+ blockRemain;
4830
+ remain;
4831
+ type;
4832
+ meta = false;
4833
+ ignore = false;
4834
+ path;
4835
+ mode;
4836
+ uid;
4837
+ gid;
4838
+ uname;
4839
+ gname;
4840
+ size = 0;
4841
+ mtime;
4842
+ atime;
4843
+ ctime;
4844
+ linkpath;
4845
+ dev;
4846
+ ino;
4847
+ nlink;
4848
+ invalid = false;
4849
+ absolute;
4850
+ unsupported = false;
4851
+ constructor(t, e, i) {
4852
+ switch (super({}), this.pause(), this.extended = e, this.globalExtended = i, this.header = t, this.remain = t.size ?? 0, this.startBlockSize = 512 * Math.ceil(this.remain / 512), this.blockRemain = this.startBlockSize, this.type = t.type, this.type) {
4853
+ case "File":
4854
+ case "OldFile":
4855
+ case "Link":
4856
+ case "SymbolicLink":
4857
+ case "CharacterDevice":
4858
+ case "BlockDevice":
4859
+ case "Directory":
4860
+ case "FIFO":
4861
+ case "ContiguousFile":
4862
+ case "GNUDumpDir":
4863
+ break;
4864
+ case "NextFileHasLongLinkpath":
4865
+ case "NextFileHasLongPath":
4866
+ case "OldGnuLongPath":
4867
+ case "GlobalExtendedHeader":
4868
+ case "ExtendedHeader":
4869
+ case "OldExtendedHeader":
4870
+ this.meta = true;
4871
+ break;
4872
+ default:
4873
+ this.ignore = true;
4874
+ }
4875
+ if (!t.path) throw new Error("no path provided for tar.ReadEntry");
4876
+ this.path = f(t.path), this.mode = t.mode, this.mode && (this.mode = this.mode & 4095), this.uid = t.uid, this.gid = t.gid, this.uname = t.uname, this.gname = t.gname, this.size = this.remain, this.mtime = t.mtime, this.atime = t.atime, this.ctime = t.ctime, this.linkpath = t.linkpath ? f(t.linkpath) : void 0, this.uname = t.uname, this.gname = t.gname, e && this.#t(e), i && this.#t(i, true);
4877
+ }
4878
+ write(t) {
4879
+ let e = t.length;
4880
+ if (e > this.blockRemain) throw new Error("writing more to entry than is appropriate");
4881
+ let i = this.remain, r = this.blockRemain;
4882
+ return this.remain = Math.max(0, i - e), this.blockRemain = Math.max(0, r - e), this.ignore ? true : i >= e ? super.write(t) : super.write(t.subarray(0, i));
4883
+ }
4884
+ #t(t, e = false) {
4885
+ t.path && (t.path = f(t.path)), t.linkpath && (t.linkpath = f(t.linkpath)), Object.assign(this, Object.fromEntries(Object.entries(t).filter(([i, r]) => !(r == null || i === "path" && e))));
4886
+ }
4887
+ };
4888
+ var Dt = (s3, t, e, i = {}) => {
4889
+ s3.file && (i.file = s3.file), s3.cwd && (i.cwd = s3.cwd), i.code = e instanceof Error && e.code || t, i.tarCode = t, !s3.strict && i.recoverable !== false ? (e instanceof Error && (i = Object.assign(e, i), e = e.message), s3.emit("warn", t, e, i)) : e instanceof Error ? s3.emit("error", Object.assign(e, i)) : s3.emit("error", Object.assign(new Error(`${t}: ${e}`), i));
4890
+ };
4891
+ var Nn = 1024 * 1024;
4892
+ var Xi = Buffer.from([31, 139]);
4893
+ var qi = Buffer.from([40, 181, 47, 253]);
4894
+ var An = Math.max(Xi.length, qi.length);
4895
+ var B = /* @__PURE__ */ Symbol("state");
4896
+ var Nt = /* @__PURE__ */ Symbol("writeEntry");
4897
+ var it = /* @__PURE__ */ Symbol("readEntry");
4898
+ var Zi = /* @__PURE__ */ Symbol("nextEntry");
4899
+ var Zs = /* @__PURE__ */ Symbol("processEntry");
4900
+ var V = /* @__PURE__ */ Symbol("extendedHeader");
4901
+ var he = /* @__PURE__ */ Symbol("globalExtendedHeader");
4902
+ var dt = /* @__PURE__ */ Symbol("meta");
4903
+ var Ys = /* @__PURE__ */ Symbol("emitMeta");
4904
+ var p = /* @__PURE__ */ Symbol("buffer");
4905
+ var st = /* @__PURE__ */ Symbol("queue");
4906
+ var ut = /* @__PURE__ */ Symbol("ended");
4907
+ var Yi = /* @__PURE__ */ Symbol("emittedEnd");
4908
+ var At = /* @__PURE__ */ Symbol("emit");
4909
+ var w = /* @__PURE__ */ Symbol("unzip");
4910
+ var Xe = /* @__PURE__ */ Symbol("consumeChunk");
4911
+ var qe = /* @__PURE__ */ Symbol("consumeChunkSub");
4912
+ var Ki = /* @__PURE__ */ Symbol("consumeBody");
4913
+ var Ks = /* @__PURE__ */ Symbol("consumeMeta");
4914
+ var Vs = /* @__PURE__ */ Symbol("consumeHeader");
4915
+ var ae = /* @__PURE__ */ Symbol("consuming");
4916
+ var Vi = /* @__PURE__ */ Symbol("bufferConcat");
4917
+ var Qe = /* @__PURE__ */ Symbol("maybeEnd");
4918
+ var Yt = /* @__PURE__ */ Symbol("writing");
4919
+ var $ = /* @__PURE__ */ Symbol("aborted");
4920
+ var Je = /* @__PURE__ */ Symbol("onDone");
4921
+ var It = /* @__PURE__ */ Symbol("sawValidEntry");
4922
+ var je = /* @__PURE__ */ Symbol("sawNullBlock");
4923
+ var ti = /* @__PURE__ */ Symbol("sawEOF");
4924
+ var $s = /* @__PURE__ */ Symbol("closeStream");
4925
+ var In = 1e3;
4926
+ var le = /* @__PURE__ */ Symbol("compressedBytesRead");
4927
+ var $i = /* @__PURE__ */ Symbol("decompressedBytesRead");
4928
+ var Xs = /* @__PURE__ */ Symbol("checkDecompressionRatio");
4929
+ var Cn = () => true;
4930
+ var rt = class extends Dn {
4931
+ file;
4932
+ strict;
4933
+ maxMetaEntrySize;
4934
+ filter;
4935
+ brotli;
4936
+ zstd;
4937
+ maxDecompressionRatio;
4938
+ writable = true;
4939
+ readable = false;
4940
+ [st] = [];
4941
+ [p];
4942
+ [it];
4943
+ [Nt];
4944
+ [B] = "begin";
4945
+ [dt] = "";
4946
+ [V];
4947
+ [he];
4948
+ [ut] = false;
4949
+ [w];
4950
+ [$] = false;
4951
+ [It];
4952
+ [je] = false;
4953
+ [ti] = false;
4954
+ [Yt] = false;
4955
+ [ae] = false;
4956
+ [Yi] = false;
4957
+ [le] = 0;
4958
+ [$i] = 0;
4959
+ constructor(t = {}) {
4960
+ super(), this.file = t.file || "", this.on(Je, () => {
4961
+ (this[B] === "begin" || this[It] === false) && this.warn("TAR_BAD_ARCHIVE", "Unrecognized archive format");
4962
+ }), t.ondone ? this.on(Je, t.ondone) : this.on(Je, () => {
4963
+ this.emit("prefinish"), this.emit("finish"), this.emit("end");
4964
+ }), this.strict = !!t.strict, this.maxDecompressionRatio = typeof t.maxDecompressionRatio == "number" ? t.maxDecompressionRatio : In, this.maxMetaEntrySize = t.maxMetaEntrySize || Nn, this.filter = typeof t.filter == "function" ? t.filter : Cn;
4965
+ let e = t.file && (t.file.endsWith(".tar.br") || t.file.endsWith(".tbr"));
4966
+ this.brotli = !(t.gzip || t.zstd) && t.brotli !== void 0 ? t.brotli : e ? void 0 : false;
4967
+ let i = t.file && (t.file.endsWith(".tar.zst") || t.file.endsWith(".tzst"));
4968
+ this.zstd = !(t.gzip || t.brotli) && t.zstd !== void 0 ? t.zstd : i ? true : void 0, this.on("end", () => this[$s]()), typeof t.onwarn == "function" && this.on("warn", t.onwarn), typeof t.onReadEntry == "function" && this.on("entry", t.onReadEntry);
4969
+ }
4970
+ warn(t, e, i = {}) {
4971
+ Dt(this, t, e, i);
4972
+ }
4973
+ [Vs](t, e) {
4974
+ this[It] === void 0 && (this[It] = false);
4975
+ let i;
4976
+ try {
4977
+ i = new F(t, e, this[V], this[he]);
4978
+ } catch (r) {
4979
+ return this.warn("TAR_ENTRY_INVALID", r);
4980
+ }
4981
+ if (i.nullBlock) this[je] ? (this[ti] = true, this[B] === "begin" && (this[B] = "header"), this[At]("eof")) : (this[je] = true, this[At]("nullBlock"));
4982
+ else if (this[je] = false, !i.cksumValid) this.warn("TAR_ENTRY_INVALID", "checksum failure", { header: i });
4983
+ else if (!i.path) this.warn("TAR_ENTRY_INVALID", "path is required", { header: i });
4984
+ else {
4985
+ let r = i.type;
4986
+ if (/^(Symbolic)?Link$/.test(r) && !i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath required", { header: i });
4987
+ else if (!/^(Symbolic)?Link$/.test(r) && !/^(Global)?ExtendedHeader$/.test(r) && i.linkpath) this.warn("TAR_ENTRY_INVALID", "linkpath forbidden", { header: i });
4988
+ else {
4989
+ let n = this[Nt] = new $e(i, this[V], this[he]);
4990
+ if (!this[It]) if (n.remain) {
4991
+ let o = () => {
4992
+ n.invalid || (this[It] = true);
4993
+ };
4994
+ n.on("end", o);
4995
+ } else this[It] = true;
4996
+ n.meta ? n.size > this.maxMetaEntrySize ? (n.ignore = true, this[At]("ignoredEntry", n), this[B] = "ignore", n.resume()) : n.size > 0 && (this[dt] = "", n.on("data", (o) => this[dt] += o), this[B] = "meta") : (this[V] = void 0, n.ignore = n.ignore || !this.filter(n.path, n), n.ignore ? (this[At]("ignoredEntry", n), this[B] = n.remain ? "ignore" : "header", n.resume()) : (n.remain ? this[B] = "body" : (this[B] = "header", n.end()), this[it] ? this[st].push(n) : (this[st].push(n), this[Zi]())));
4997
+ }
4998
+ }
4999
+ }
5000
+ [$s]() {
5001
+ queueMicrotask(() => this.emit("close"));
5002
+ }
5003
+ [Zs](t) {
5004
+ let e = true;
5005
+ if (!t) this[it] = void 0, e = false;
5006
+ else if (Array.isArray(t)) {
5007
+ let [i, ...r] = t;
5008
+ this.emit(i, ...r);
5009
+ } else this[it] = t, this.emit("entry", t), t.emittedEnd || (t.on("end", () => this[Zi]()), e = false);
5010
+ return e;
5011
+ }
5012
+ [Zi]() {
5013
+ do
5014
+ ;
5015
+ while (this[Zs](this[st].shift()));
5016
+ if (this[st].length === 0) {
5017
+ let t = this[it];
5018
+ !t || t.flowing || t.size === t.remain ? this[Yt] || this.emit("drain") : t.once("drain", () => this.emit("drain"));
5019
+ }
5020
+ }
5021
+ [Ki](t, e) {
5022
+ let i = this[Nt];
5023
+ if (!i) throw new Error("attempt to consume body without entry??");
5024
+ let r = i.blockRemain ?? 0, n = r >= t.length && e === 0 ? t : t.subarray(e, e + r);
5025
+ return i.write(n), i.blockRemain || (this[B] = "header", this[Nt] = void 0, i.end()), n.length;
5026
+ }
5027
+ [Ks](t, e) {
5028
+ let i = this[Nt], r = this[Ki](t, e);
5029
+ return !this[Nt] && i && this[Ys](i), r;
5030
+ }
5031
+ [At](t, e, i) {
5032
+ this[st].length === 0 && !this[it] ? this.emit(t, e, i) : this[st].push([t, e, i]);
5033
+ }
5034
+ [Ys](t) {
5035
+ switch (this[At]("meta", this[dt]), t.type) {
5036
+ case "ExtendedHeader":
5037
+ case "OldExtendedHeader":
5038
+ this[V] = ft.parse(this[dt], this[V], false);
5039
+ break;
5040
+ case "GlobalExtendedHeader":
5041
+ this[he] = ft.parse(this[dt], this[he], true);
5042
+ break;
5043
+ case "NextFileHasLongPath":
5044
+ case "OldGnuLongPath": {
5045
+ let e = this[V] ?? /* @__PURE__ */ Object.create(null);
5046
+ this[V] = e, e.path = this[dt].replace(/\0.*/, "");
5047
+ break;
5048
+ }
5049
+ case "NextFileHasLongLinkpath": {
5050
+ let e = this[V] || /* @__PURE__ */ Object.create(null);
5051
+ this[V] = e, e.linkpath = this[dt].replace(/\0.*/, "");
5052
+ break;
5053
+ }
5054
+ default:
5055
+ throw new Error("unknown meta: " + t.type);
5056
+ }
5057
+ }
5058
+ abort(t) {
5059
+ if (!this[$]) {
5060
+ if (this[w]) {
5061
+ let e = this[w];
5062
+ e.write = () => true, e.end = () => e, e.emit = () => false, e.destroy?.();
5063
+ }
5064
+ this[$] = true, this.emit("abort", t), this.warn("TAR_ABORT", t, { recoverable: false });
5065
+ }
5066
+ }
5067
+ [Xs](t) {
5068
+ this[$i] += t.length;
5069
+ let e = this[$i] / this[le];
5070
+ return e > this.maxDecompressionRatio ? (this.abort(new Error(`max decompression ratio exceeded: ${e.toFixed(2)} > ${this.maxDecompressionRatio}`)), false) : true;
5071
+ }
5072
+ write(t, e, i) {
5073
+ if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this[$]) return i?.(), false;
5074
+ if ((this[w] === void 0 || this.brotli === void 0 && this[w] === false) && t) {
5075
+ if (this[p] && (t = Buffer.concat([this[p], t]), this[p] = void 0), t.length < An) return this[p] = t, i?.(), true;
5076
+ for (let a = 0; this[w] === void 0 && a < Xi.length; a++) t[a] !== Xi[a] && (this[w] = false);
5077
+ let o = false;
5078
+ if (this[w] === false && this.zstd !== false) {
5079
+ o = true;
5080
+ for (let a = 0; a < qi.length; a++) if (t[a] !== qi[a]) {
5081
+ o = false;
5082
+ break;
5083
+ }
5084
+ }
5085
+ let h = this.brotli === void 0 && !o;
5086
+ if (this[w] === false && h) if (t.length < 512) if (this[ut]) this.brotli = true;
5087
+ else return this[p] = t, i?.(), true;
5088
+ else try {
5089
+ new F(t.subarray(0, 512)), this.brotli = false;
5090
+ } catch {
5091
+ this.brotli = true;
5092
+ }
5093
+ if (this[w] === void 0 || this[w] === false && (this.brotli || o)) {
5094
+ let a = this[ut];
5095
+ this[ut] = false, this[w] = this[w] === void 0 ? new Ue({}) : o ? new Ke({}) : new Ge({}), this[w].on("data", (c) => {
5096
+ this[Xs](c) && this[Xe](c);
5097
+ }), this[w].on("error", (c) => {
5098
+ this[$] || this.abort(c);
5099
+ }), this[w].on("end", () => {
5100
+ this[ut] = true, this[Xe]();
5101
+ }), this[Yt] = true, this[le] += t.length;
5102
+ let l = !!this[w][a ? "end" : "write"](t);
5103
+ return this[Yt] = false, i?.(), l;
5104
+ }
5105
+ }
5106
+ this[Yt] = true, this[w] ? (this[le] += t.length, this[w].write(t)) : this[Xe](t), this[Yt] = false;
5107
+ let n = this[st].length > 0 ? false : this[it] ? this[it].flowing : true;
5108
+ return !n && this[st].length === 0 && this[it]?.once("drain", () => this.emit("drain")), i?.(), n;
5109
+ }
5110
+ [Vi](t) {
5111
+ t && !this[$] && (this[p] = this[p] ? Buffer.concat([this[p], t]) : t);
5112
+ }
5113
+ [Qe]() {
5114
+ if (this[ut] && !this[Yi] && !this[$] && !this[ae]) {
5115
+ this[Yi] = true;
5116
+ let t = this[Nt];
5117
+ if (t?.blockRemain) {
5118
+ let e = this[p] ? this[p].length : 0;
5119
+ this.warn("TAR_BAD_ARCHIVE", `Truncated input (needed ${t.blockRemain} more bytes, only ${e} available)`, { entry: t }), this[p] && t.write(this[p]), t.end();
5120
+ }
5121
+ this[At](Je);
5122
+ }
5123
+ }
5124
+ [Xe](t) {
5125
+ if (this[ae] && t) this[Vi](t);
5126
+ else if (!t && !this[p]) this[Qe]();
5127
+ else if (t) {
5128
+ if (this[ae] = true, this[p]) {
5129
+ this[Vi](t);
5130
+ let e = this[p];
5131
+ this[p] = void 0, this[qe](e);
5132
+ } else this[qe](t);
5133
+ for (; this[p] && this[p]?.length >= 512 && !this[$] && !this[ti]; ) {
5134
+ let e = this[p];
5135
+ this[p] = void 0, this[qe](e);
5136
+ }
5137
+ this[ae] = false;
5138
+ }
5139
+ (!this[p] || this[ut]) && this[Qe]();
5140
+ }
5141
+ [qe](t) {
5142
+ let e = 0, i = t.length;
5143
+ for (; e + 512 <= i && !this[$] && !this[ti]; ) switch (this[B]) {
5144
+ case "begin":
5145
+ case "header":
5146
+ this[Vs](t, e), e += 512;
5147
+ break;
5148
+ case "ignore":
5149
+ case "body":
5150
+ e += this[Ki](t, e);
5151
+ break;
5152
+ case "meta":
5153
+ e += this[Ks](t, e);
5154
+ break;
5155
+ default:
5156
+ throw new Error("invalid state: " + this[B]);
5157
+ }
5158
+ e < i && (this[p] = this[p] ? Buffer.concat([t.subarray(e), this[p]]) : t.subarray(e));
5159
+ }
5160
+ end(t, e, i) {
5161
+ return typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e)), i && this.once("finish", i), this[$] || (this[w] ? (t && (this[le] += t.length, this[w].write(t)), this[w].end()) : (this[ut] = true, (this.brotli === void 0 || this.zstd === void 0) && (t = t || Buffer.alloc(0)), t && this.write(t), this[Qe]())), this;
5162
+ }
5163
+ };
5164
+ var mt = (s3) => {
5165
+ let t = s3.length - 1, e = -1;
5166
+ for (; t > -1 && s3.charAt(t) === "/"; ) e = t, t--;
5167
+ return e === -1 ? s3 : s3.slice(0, e);
5168
+ };
5169
+ var vn = (s3) => {
5170
+ let t = s3.onReadEntry;
5171
+ s3.onReadEntry = t ? (e) => {
5172
+ t(e), e.resume();
5173
+ } : (e) => e.resume();
5174
+ };
5175
+ var Qi = (s3, t) => {
5176
+ let e = new Map(t.map((o) => [mt(o), true])), i = s3.filter, r = 100, n = (o, h = "", a = 0) => {
5177
+ if (a >= r) return e.set(o, false), false;
5178
+ let l = h || kn(o).root || ".", c;
5179
+ if (o === l) c = false;
5180
+ else {
5181
+ let d = e.get(o);
5182
+ c = d !== void 0 ? d : n(Fn(o), l, a + 1);
5183
+ }
5184
+ return e.set(o, c), c;
5185
+ };
5186
+ s3.filter = i ? (o, h) => i(o, h) && n(mt(o)) : (o) => n(mt(o));
5187
+ };
5188
+ var Mn = (s3) => {
5189
+ let t = new rt(s3), e = s3.file, i;
5190
+ try {
5191
+ i = Kt.openSync(e, "r");
5192
+ let r = Kt.fstatSync(i), n = s3.maxReadSize || 16 * 1024 * 1024;
5193
+ if (r.size < n) {
5194
+ let o = Buffer.allocUnsafe(r.size), h = Kt.readSync(i, o, 0, r.size, 0);
5195
+ t.end(h === o.byteLength ? o : o.subarray(0, h));
5196
+ } else {
5197
+ let o = 0, h = Buffer.allocUnsafe(n);
5198
+ for (; o < r.size; ) {
5199
+ let a = Kt.readSync(i, h, 0, n, o);
5200
+ if (a === 0) break;
5201
+ o += a, t.write(h.subarray(0, a));
5202
+ }
5203
+ t.end();
5204
+ }
5205
+ } finally {
5206
+ if (typeof i == "number") try {
5207
+ Kt.closeSync(i);
5208
+ } catch {
5209
+ }
5210
+ }
5211
+ };
5212
+ var Bn = (s3, t) => {
5213
+ let e = new rt(s3), i = s3.maxReadSize || 16 * 1024 * 1024, r = s3.file;
5214
+ return new Promise((o, h) => {
5215
+ e.on("error", h), e.on("end", o), Kt.stat(r, (a, l) => {
5216
+ if (a) h(a);
5217
+ else {
5218
+ let c = new _t(r, { readSize: i, size: l.size });
5219
+ c.on("error", h), c.pipe(e);
5220
+ }
5221
+ });
5222
+ });
5223
+ };
5224
+ var Ct = K(Mn, Bn, (s3) => new rt(s3), (s3) => new rt(s3), (s3, t) => {
5225
+ t?.length && Qi(s3, t), s3.noResume || vn(s3);
5226
+ });
5227
+ var Ji = (s3, t, e) => (s3 &= 4095, e && (s3 = (s3 | 384) & -19), t && (s3 & 256 && (s3 |= 64), s3 & 32 && (s3 |= 8), s3 & 4 && (s3 |= 1)), s3);
5228
+ var { isAbsolute: zn, parse: qs } = Pn;
5229
+ var ce = (s3) => {
5230
+ let t = "", e = qs(s3);
5231
+ for (; zn(s3) || e.root; ) {
5232
+ let i = s3.charAt(0) === "/" && s3.slice(0, 4) !== "//?/" ? "/" : e.root;
5233
+ s3 = s3.slice(i.length), t += i, e = qs(s3);
5234
+ }
5235
+ return [t, s3];
5236
+ };
5237
+ var ei = ["|", "<", ">", "?", ":"];
5238
+ var ji = ei.map((s3) => String.fromCodePoint(61440 + Number(s3.codePointAt(0))));
5239
+ var Un = new Map(ei.map((s3, t) => [s3, ji[t]]));
5240
+ var Hn = new Map(ji.map((s3, t) => [s3, ei[t]]));
5241
+ var ts = (s3) => ei.reduce((t, e) => t.split(e).join(Un.get(e)), s3);
5242
+ var Qs = (s3) => ji.reduce((t, e) => t.split(e).join(Hn.get(e)), s3);
5243
+ var rr = (s3, t) => t ? (s3 = f(s3).replace(/^\.(\/|$)/, ""), mt(t) + "/" + s3) : f(s3);
5244
+ var Wn = 16 * 1024 * 1024;
5245
+ var tr = /* @__PURE__ */ Symbol("process");
5246
+ var er = /* @__PURE__ */ Symbol("file");
5247
+ var ir = /* @__PURE__ */ Symbol("directory");
5248
+ var is = /* @__PURE__ */ Symbol("symlink");
5249
+ var sr = /* @__PURE__ */ Symbol("hardlink");
5250
+ var fe = /* @__PURE__ */ Symbol("header");
5251
+ var ii = /* @__PURE__ */ Symbol("read");
5252
+ var ss = /* @__PURE__ */ Symbol("lstat");
5253
+ var si = /* @__PURE__ */ Symbol("onlstat");
5254
+ var rs = /* @__PURE__ */ Symbol("onread");
5255
+ var ns = /* @__PURE__ */ Symbol("onreadlink");
5256
+ var os = /* @__PURE__ */ Symbol("openfile");
5257
+ var hs = /* @__PURE__ */ Symbol("onopenfile");
5258
+ var pt = /* @__PURE__ */ Symbol("close");
5259
+ var ri = /* @__PURE__ */ Symbol("mode");
5260
+ var as = /* @__PURE__ */ Symbol("awaitDrain");
5261
+ var es = /* @__PURE__ */ Symbol("ondrain");
5262
+ var q = /* @__PURE__ */ Symbol("prefix");
5263
+ var de = class extends A {
5264
+ path;
5265
+ portable;
5266
+ myuid = process.getuid && process.getuid() || 0;
5267
+ myuser = process.env.USER || "";
5268
+ maxReadSize;
5269
+ linkCache;
5270
+ statCache;
5271
+ preservePaths;
5272
+ cwd;
5273
+ strict;
5274
+ mtime;
5275
+ noPax;
5276
+ noMtime;
5277
+ prefix;
5278
+ fd;
5279
+ blockLen = 0;
5280
+ blockRemain = 0;
5281
+ buf;
5282
+ pos = 0;
5283
+ remain = 0;
5284
+ length = 0;
5285
+ offset = 0;
5286
+ win32;
5287
+ absolute;
5288
+ header;
5289
+ type;
5290
+ linkpath;
5291
+ stat;
5292
+ onWriteEntry;
5293
+ #t = false;
5294
+ constructor(t, e = {}) {
5295
+ let i = se(e);
5296
+ super(), this.path = f(t), this.portable = !!i.portable, this.maxReadSize = i.maxReadSize || Wn, this.linkCache = i.linkCache || /* @__PURE__ */ new Map(), this.statCache = i.statCache || /* @__PURE__ */ new Map(), this.preservePaths = !!i.preservePaths, this.cwd = f(i.cwd || process.cwd()), this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.mtime = i.mtime, this.prefix = i.prefix ? f(i.prefix) : void 0, this.onWriteEntry = i.onWriteEntry, typeof i.onwarn == "function" && this.on("warn", i.onwarn);
5297
+ let r = false;
5298
+ if (!this.preservePaths) {
5299
+ let [o, h] = ce(this.path);
5300
+ o && typeof h == "string" && (this.path = h, r = o);
5301
+ }
5302
+ this.win32 = !!i.win32 || process.platform === "win32", this.win32 && (this.path = Qs(this.path.replaceAll(/\\/g, "/")), t = t.replaceAll(/\\/g, "/")), this.absolute = f(i.absolute || js.resolve(this.cwd, t)), this.path === "" && (this.path = "./"), r && this.warn("TAR_ENTRY_INFO", `stripping ${r} from absolute path`, { entry: this, path: r + this.path });
5303
+ let n = this.statCache.get(this.absolute);
5304
+ n ? this[si](n) : this[ss]();
5305
+ }
5306
+ warn(t, e, i = {}) {
5307
+ return Dt(this, t, e, i);
5308
+ }
5309
+ emit(t, ...e) {
5310
+ return t === "error" && (this.#t = true), super.emit(t, ...e);
5311
+ }
5312
+ [ss]() {
5313
+ X.lstat(this.absolute, (t, e) => {
5314
+ if (t) return this.emit("error", t);
5315
+ this[si](e);
5316
+ });
5317
+ }
5318
+ [si](t) {
5319
+ this.statCache.set(this.absolute, t), this.stat = t, t.isFile() || (t.size = 0), this.type = Gn(t), this.emit("stat", t), this[tr]();
5320
+ }
5321
+ [tr]() {
5322
+ switch (this.type) {
5323
+ case "File":
5324
+ return this[er]();
5325
+ case "Directory":
5326
+ return this[ir]();
5327
+ case "SymbolicLink":
5328
+ return this[is]();
5329
+ default:
5330
+ return this.end();
5331
+ }
5332
+ }
5333
+ [ri](t) {
5334
+ return Ji(t, this.type === "Directory", this.portable);
5335
+ }
5336
+ [q](t) {
5337
+ return rr(t, this.prefix);
5338
+ }
5339
+ [fe]() {
5340
+ if (!this.stat) throw new Error("cannot write header before stat");
5341
+ this.type === "Directory" && this.portable && (this.noMtime = true), this.onWriteEntry?.(this), this.header = new F({ path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, mode: this[ri](this.stat.mode), uid: this.portable ? void 0 : this.stat.uid, gid: this.portable ? void 0 : this.stat.gid, size: this.stat.size, mtime: this.noMtime ? void 0 : this.mtime || this.stat.mtime, type: this.type === "Unsupported" ? void 0 : this.type, uname: this.portable ? void 0 : this.stat.uid === this.myuid ? this.myuser : "", atime: this.portable ? void 0 : this.stat.atime, ctime: this.portable ? void 0 : this.stat.ctime }), this.header.encode() && !this.noPax && super.write(new ft({ atime: this.portable ? void 0 : this.header.atime, ctime: this.portable ? void 0 : this.header.ctime, gid: this.portable ? void 0 : this.header.gid, mtime: this.noMtime ? void 0 : this.mtime || this.header.mtime, path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, size: this.header.size, uid: this.portable ? void 0 : this.header.uid, uname: this.portable ? void 0 : this.header.uname, dev: this.portable ? void 0 : this.stat.dev, ino: this.portable ? void 0 : this.stat.ino, nlink: this.portable ? void 0 : this.stat.nlink }).encode());
5342
+ let t = this.header?.block;
5343
+ if (!t) throw new Error("failed to encode header");
5344
+ super.write(t);
5345
+ }
5346
+ [ir]() {
5347
+ if (!this.stat) throw new Error("cannot create directory entry without stat");
5348
+ this.path.slice(-1) !== "/" && (this.path += "/"), this.stat.size = 0, this[fe](), this.end();
5349
+ }
5350
+ [is]() {
5351
+ X.readlink(this.absolute, (t, e) => {
5352
+ if (t) return this.emit("error", t);
5353
+ this[ns](e);
5354
+ });
5355
+ }
5356
+ [ns](t) {
5357
+ this.linkpath = f(t), this[fe](), this.end();
5358
+ }
5359
+ [sr](t) {
5360
+ if (!this.stat) throw new Error("cannot create link entry without stat");
5361
+ this.type = "Link", this.linkpath = f(js.relative(this.cwd, t)), this.stat.size = 0, this[fe](), this.end();
5362
+ }
5363
+ [er]() {
5364
+ if (!this.stat) throw new Error("cannot create file entry without stat");
5365
+ if (this.stat.nlink > 1) {
5366
+ let t = `${this.stat.dev}:${this.stat.ino}`, e = this.linkCache.get(t);
5367
+ if (e?.indexOf(this.cwd) === 0) return this[sr](e);
5368
+ this.linkCache.set(t, this.absolute);
5369
+ }
5370
+ if (this[fe](), this.stat.size === 0) return this.end();
5371
+ this[os]();
5372
+ }
5373
+ [os]() {
5374
+ X.open(this.absolute, "r", (t, e) => {
5375
+ if (t) return this.emit("error", t);
5376
+ this[hs](e);
5377
+ });
5378
+ }
5379
+ [hs](t) {
5380
+ if (this.fd = t, this.#t) return this[pt]();
5381
+ if (!this.stat) throw new Error("should stat before calling onopenfile");
5382
+ this.blockLen = 512 * Math.ceil(this.stat.size / 512), this.blockRemain = this.blockLen;
5383
+ let e = Math.min(this.blockLen, this.maxReadSize);
5384
+ this.buf = Buffer.allocUnsafe(e), this.offset = 0, this.pos = 0, this.remain = this.stat.size, this.length = this.buf.length, this[ii]();
5385
+ }
5386
+ [ii]() {
5387
+ let { fd: t, buf: e, offset: i, length: r, pos: n } = this;
5388
+ if (t === void 0 || e === void 0) throw new Error("cannot read file without first opening");
5389
+ X.read(t, e, i, r, n, (o, h) => {
5390
+ if (o) return this[pt](() => this.emit("error", o));
5391
+ this[rs](h);
5392
+ });
5393
+ }
5394
+ [pt](t = () => {
5395
+ }) {
5396
+ this.fd !== void 0 && X.close(this.fd, t);
5397
+ }
5398
+ [rs](t) {
5399
+ if (t <= 0 && this.remain > 0) {
5400
+ let r = Object.assign(new Error("encountered unexpected EOF"), { path: this.absolute, syscall: "read", code: "EOF" });
5401
+ return this[pt](() => this.emit("error", r));
5402
+ }
5403
+ if (t > this.remain) {
5404
+ let r = Object.assign(new Error("did not encounter expected EOF"), { path: this.absolute, syscall: "read", code: "EOF" });
5405
+ return this[pt](() => this.emit("error", r));
5406
+ }
5407
+ if (!this.buf) throw new Error("should have created buffer prior to reading");
5408
+ if (t === this.remain) for (let r = t; r < this.length && t < this.blockRemain; r++) this.buf[r + this.offset] = 0, t++, this.remain++;
5409
+ let e = this.offset === 0 && t === this.buf.length ? this.buf : this.buf.subarray(this.offset, this.offset + t);
5410
+ this.write(e) ? this[es]() : this[as](() => this[es]());
5411
+ }
5412
+ [as](t) {
5413
+ this.once("drain", t);
5414
+ }
5415
+ write(t, e, i) {
5416
+ if (typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8")), this.blockRemain < t.length) {
5417
+ let r = Object.assign(new Error("writing more data than expected"), { path: this.absolute });
5418
+ return this.emit("error", r);
5419
+ }
5420
+ return this.remain -= t.length, this.blockRemain -= t.length, this.pos += t.length, this.offset += t.length, super.write(t, null, i);
5421
+ }
5422
+ [es]() {
5423
+ if (!this.remain) return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), this[pt]((t) => t ? this.emit("error", t) : this.end());
5424
+ if (!this.buf) throw new Error("buffer lost somehow in ONDRAIN");
5425
+ this.offset >= this.length && (this.buf = Buffer.allocUnsafe(Math.min(this.blockRemain, this.buf.length)), this.offset = 0), this.length = this.buf.length - this.offset, this[ii]();
5426
+ }
5427
+ };
5428
+ var ni = class extends de {
5429
+ sync = true;
5430
+ [ss]() {
5431
+ this[si](X.lstatSync(this.absolute));
5432
+ }
5433
+ [is]() {
5434
+ this[ns](X.readlinkSync(this.absolute));
5435
+ }
5436
+ [os]() {
5437
+ this[hs](X.openSync(this.absolute, "r"));
5438
+ }
5439
+ [ii]() {
5440
+ let t = true;
5441
+ try {
5442
+ let { fd: e, buf: i, offset: r, length: n, pos: o } = this;
5443
+ if (e === void 0 || i === void 0) throw new Error("fd and buf must be set in READ method");
5444
+ let h = X.readSync(e, i, r, n, o);
5445
+ this[rs](h), t = false;
5446
+ } finally {
5447
+ if (t) try {
5448
+ this[pt](() => {
5449
+ });
5450
+ } catch {
5451
+ }
5452
+ }
5453
+ }
5454
+ [as](t) {
5455
+ t();
5456
+ }
5457
+ [pt](t = () => {
5458
+ }) {
5459
+ this.fd !== void 0 && X.closeSync(this.fd), t();
5460
+ }
5461
+ };
5462
+ var oi = class extends A {
5463
+ blockLen = 0;
5464
+ blockRemain = 0;
5465
+ buf = 0;
5466
+ pos = 0;
5467
+ remain = 0;
5468
+ length = 0;
5469
+ preservePaths;
5470
+ portable;
5471
+ strict;
5472
+ noPax;
5473
+ noMtime;
5474
+ readEntry;
5475
+ type;
5476
+ prefix;
5477
+ path;
5478
+ mode;
5479
+ uid;
5480
+ gid;
5481
+ uname;
5482
+ gname;
5483
+ header;
5484
+ mtime;
5485
+ atime;
5486
+ ctime;
5487
+ linkpath;
5488
+ size;
5489
+ onWriteEntry;
5490
+ warn(t, e, i = {}) {
5491
+ return Dt(this, t, e, i);
5492
+ }
5493
+ constructor(t, e = {}) {
5494
+ let i = se(e);
5495
+ super(), this.preservePaths = !!i.preservePaths, this.portable = !!i.portable, this.strict = !!i.strict, this.noPax = !!i.noPax, this.noMtime = !!i.noMtime, this.onWriteEntry = i.onWriteEntry, this.readEntry = t;
5496
+ let { type: r } = t;
5497
+ if (r === "Unsupported") throw new Error("writing entry that should be ignored");
5498
+ this.type = r, this.type === "Directory" && this.portable && (this.noMtime = true), this.prefix = i.prefix, this.path = f(t.path), this.mode = t.mode !== void 0 ? this[ri](t.mode) : void 0, this.uid = this.portable ? void 0 : t.uid, this.gid = this.portable ? void 0 : t.gid, this.uname = this.portable ? void 0 : t.uname, this.gname = this.portable ? void 0 : t.gname, this.size = t.size, this.mtime = this.noMtime ? void 0 : i.mtime || t.mtime, this.atime = this.portable ? void 0 : t.atime, this.ctime = this.portable ? void 0 : t.ctime, this.linkpath = t.linkpath !== void 0 ? f(t.linkpath) : void 0, typeof i.onwarn == "function" && this.on("warn", i.onwarn);
5499
+ let n = false;
5500
+ if (!this.preservePaths) {
5501
+ let [h, a] = ce(this.path);
5502
+ h && typeof a == "string" && (this.path = a, n = h);
5503
+ }
5504
+ this.remain = t.size, this.blockRemain = t.startBlockSize, this.onWriteEntry?.(this), this.header = new F({ path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, mode: this.mode, uid: this.portable ? void 0 : this.uid, gid: this.portable ? void 0 : this.gid, size: this.size, mtime: this.noMtime ? void 0 : this.mtime, type: this.type, uname: this.portable ? void 0 : this.uname, atime: this.portable ? void 0 : this.atime, ctime: this.portable ? void 0 : this.ctime }), n && this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute path`, { entry: this, path: n + this.path }), this.header.encode() && !this.noPax && super.write(new ft({ atime: this.portable ? void 0 : this.atime, ctime: this.portable ? void 0 : this.ctime, gid: this.portable ? void 0 : this.gid, mtime: this.noMtime ? void 0 : this.mtime, path: this[q](this.path), linkpath: this.type === "Link" && this.linkpath !== void 0 ? this[q](this.linkpath) : this.linkpath, size: this.size, uid: this.portable ? void 0 : this.uid, uname: this.portable ? void 0 : this.uname, dev: this.portable ? void 0 : this.readEntry.dev, ino: this.portable ? void 0 : this.readEntry.ino, nlink: this.portable ? void 0 : this.readEntry.nlink }).encode());
5505
+ let o = this.header?.block;
5506
+ if (!o) throw new Error("failed to encode header");
5507
+ super.write(o), t.pipe(this);
5508
+ }
5509
+ [q](t) {
5510
+ return rr(t, this.prefix);
5511
+ }
5512
+ [ri](t) {
5513
+ return Ji(t, this.type === "Directory", this.portable);
5514
+ }
5515
+ write(t, e, i) {
5516
+ typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, typeof e == "string" ? e : "utf8"));
5517
+ let r = t.length;
5518
+ if (r > this.blockRemain) throw new Error("writing more to entry than is appropriate");
5519
+ return this.blockRemain -= r, super.write(t, i);
5520
+ }
5521
+ end(t, e, i) {
5522
+ return this.blockRemain && super.write(Buffer.alloc(this.blockRemain)), typeof t == "function" && (i = t, e = void 0, t = void 0), typeof e == "function" && (i = e, e = void 0), typeof t == "string" && (t = Buffer.from(t, e ?? "utf8")), i && this.once("finish", i), t ? super.end(t, i) : super.end(i), this;
5523
+ }
5524
+ };
5525
+ var Gn = (s3) => s3.isFile() ? "File" : s3.isDirectory() ? "Directory" : s3.isSymbolicLink() ? "SymbolicLink" : "Unsupported";
5526
+ var hi = class s2 {
5527
+ tail;
5528
+ head;
5529
+ length = 0;
5530
+ static create(t = []) {
5531
+ return new s2(t);
5532
+ }
5533
+ constructor(t = []) {
5534
+ for (let e of t) this.push(e);
5535
+ }
5536
+ *[Symbol.iterator]() {
5537
+ for (let t = this.head; t; t = t.next) yield t.value;
5538
+ }
5539
+ removeNode(t) {
5540
+ if (t.list !== this) throw new Error("removing node which does not belong to this list");
5541
+ let e = t.next, i = t.prev;
5542
+ return e && (e.prev = i), i && (i.next = e), t === this.head && (this.head = e), t === this.tail && (this.tail = i), this.length--, t.next = void 0, t.prev = void 0, t.list = void 0, e;
5543
+ }
5544
+ unshiftNode(t) {
5545
+ if (t === this.head) return;
5546
+ t.list && t.list.removeNode(t);
5547
+ let e = this.head;
5548
+ t.list = this, t.next = e, e && (e.prev = t), this.head = t, this.tail || (this.tail = t), this.length++;
5549
+ }
5550
+ pushNode(t) {
5551
+ if (t === this.tail) return;
5552
+ t.list && t.list.removeNode(t);
5553
+ let e = this.tail;
5554
+ t.list = this, t.prev = e, e && (e.next = t), this.tail = t, this.head || (this.head = t), this.length++;
5555
+ }
5556
+ push(...t) {
5557
+ for (let e = 0, i = t.length; e < i; e++) Yn(this, t[e]);
5558
+ return this.length;
5559
+ }
5560
+ unshift(...t) {
5561
+ for (var e = 0, i = t.length; e < i; e++) Kn(this, t[e]);
5562
+ return this.length;
5563
+ }
5564
+ pop() {
5565
+ if (!this.tail) return;
5566
+ let t = this.tail.value, e = this.tail;
5567
+ return this.tail = this.tail.prev, this.tail ? this.tail.next = void 0 : this.head = void 0, e.list = void 0, this.length--, t;
5568
+ }
5569
+ shift() {
5570
+ if (!this.head) return;
5571
+ let t = this.head.value, e = this.head;
5572
+ return this.head = this.head.next, this.head ? this.head.prev = void 0 : this.tail = void 0, e.list = void 0, this.length--, t;
5573
+ }
5574
+ forEach(t, e) {
5575
+ e = e || this;
5576
+ for (let i = this.head, r = 0; i; r++) t.call(e, i.value, r, this), i = i.next;
5577
+ }
5578
+ forEachReverse(t, e) {
5579
+ e = e || this;
5580
+ for (let i = this.tail, r = this.length - 1; i; r--) t.call(e, i.value, r, this), i = i.prev;
5581
+ }
5582
+ get(t) {
5583
+ let e = 0, i = this.head;
5584
+ for (; i && e < t; e++) i = i.next;
5585
+ if (e === t && i) return i.value;
5586
+ }
5587
+ getReverse(t) {
5588
+ let e = 0, i = this.tail;
5589
+ for (; i && e < t; e++) i = i.prev;
5590
+ if (e === t && i) return i.value;
5591
+ }
5592
+ map(t, e) {
5593
+ e = e || this;
5594
+ let i = new s2();
5595
+ for (let r = this.head; r; ) i.push(t.call(e, r.value, this)), r = r.next;
5596
+ return i;
5597
+ }
5598
+ mapReverse(t, e) {
5599
+ e = e || this;
5600
+ var i = new s2();
5601
+ for (let r = this.tail; r; ) i.push(t.call(e, r.value, this)), r = r.prev;
5602
+ return i;
5603
+ }
5604
+ reduce(t, e) {
5605
+ let i, r = this.head;
5606
+ if (arguments.length > 1) i = e;
5607
+ else if (this.head) r = this.head.next, i = this.head.value;
5608
+ else throw new TypeError("Reduce of empty list with no initial value");
5609
+ for (var n = 0; r; n++) i = t(i, r.value, n), r = r.next;
5610
+ return i;
5611
+ }
5612
+ reduceReverse(t, e) {
5613
+ let i, r = this.tail;
5614
+ if (arguments.length > 1) i = e;
5615
+ else if (this.tail) r = this.tail.prev, i = this.tail.value;
5616
+ else throw new TypeError("Reduce of empty list with no initial value");
5617
+ for (let n = this.length - 1; r; n--) i = t(i, r.value, n), r = r.prev;
5618
+ return i;
5619
+ }
5620
+ toArray() {
5621
+ let t = new Array(this.length);
5622
+ for (let e = 0, i = this.head; i; e++) t[e] = i.value, i = i.next;
5623
+ return t;
5624
+ }
5625
+ toArrayReverse() {
5626
+ let t = new Array(this.length);
5627
+ for (let e = 0, i = this.tail; i; e++) t[e] = i.value, i = i.prev;
5628
+ return t;
5629
+ }
5630
+ slice(t = 0, e = this.length) {
5631
+ e < 0 && (e += this.length), t < 0 && (t += this.length);
5632
+ let i = new s2();
5633
+ if (e < t || e < 0) return i;
5634
+ t < 0 && (t = 0), e > this.length && (e = this.length);
5635
+ let r = this.head, n = 0;
5636
+ for (n = 0; r && n < t; n++) r = r.next;
5637
+ for (; r && n < e; n++, r = r.next) i.push(r.value);
5638
+ return i;
5639
+ }
5640
+ sliceReverse(t = 0, e = this.length) {
5641
+ e < 0 && (e += this.length), t < 0 && (t += this.length);
5642
+ let i = new s2();
5643
+ if (e < t || e < 0) return i;
5644
+ t < 0 && (t = 0), e > this.length && (e = this.length);
5645
+ let r = this.length, n = this.tail;
5646
+ for (; n && r > e; r--) n = n.prev;
5647
+ for (; n && r > t; r--, n = n.prev) i.push(n.value);
5648
+ return i;
5649
+ }
5650
+ splice(t, e = 0, ...i) {
5651
+ t > this.length && (t = this.length - 1), t < 0 && (t = this.length + t);
5652
+ let r = this.head;
5653
+ for (let o = 0; r && o < t; o++) r = r.next;
5654
+ let n = [];
5655
+ for (let o = 0; r && o < e; o++) n.push(r.value), r = this.removeNode(r);
5656
+ r ? r !== this.tail && (r = r.prev) : r = this.tail;
5657
+ for (let o of i) r = Zn(this, r, o);
5658
+ return n;
5659
+ }
5660
+ reverse() {
5661
+ let t = this.head, e = this.tail;
5662
+ for (let i = t; i; i = i.prev) {
5663
+ let r = i.prev;
5664
+ i.prev = i.next, i.next = r;
5665
+ }
5666
+ return this.head = e, this.tail = t, this;
5667
+ }
5668
+ };
5669
+ function Zn(s3, t, e) {
5670
+ let i = t, r = t ? t.next : s3.head, n = new ue(e, i, r, s3);
5671
+ return n.next === void 0 && (s3.tail = n), n.prev === void 0 && (s3.head = n), s3.length++, n;
5672
+ }
5673
+ function Yn(s3, t) {
5674
+ s3.tail = new ue(t, s3.tail, void 0, s3), s3.head || (s3.head = s3.tail), s3.length++;
5675
+ }
5676
+ function Kn(s3, t) {
5677
+ s3.head = new ue(t, void 0, s3.head, s3), s3.tail || (s3.tail = s3.head), s3.length++;
5678
+ }
5679
+ var ue = class {
5680
+ list;
5681
+ next;
5682
+ prev;
5683
+ value;
5684
+ constructor(t, e, i, r) {
5685
+ this.list = r, this.value = t, e ? (e.next = this, this.prev = e) : this.prev = void 0, i ? (i.prev = this, this.next = i) : this.next = void 0;
5686
+ }
5687
+ };
5688
+ var pi = class {
5689
+ path;
5690
+ absolute;
5691
+ entry;
5692
+ stat;
5693
+ readdir;
5694
+ pending = false;
5695
+ pendingLink = false;
5696
+ ignore = false;
5697
+ piped = false;
5698
+ constructor(t, e) {
5699
+ this.path = t || "./", this.absolute = e;
5700
+ }
5701
+ };
5702
+ var nr = Buffer.alloc(1024);
5703
+ var li = /* @__PURE__ */ Symbol("onStat");
5704
+ var me = /* @__PURE__ */ Symbol("ended");
5705
+ var W = /* @__PURE__ */ Symbol("queue");
5706
+ var pe = /* @__PURE__ */ Symbol("pendingLinks");
5707
+ var Et = /* @__PURE__ */ Symbol("current");
5708
+ var Ft = /* @__PURE__ */ Symbol("process");
5709
+ var Ee = /* @__PURE__ */ Symbol("processing");
5710
+ var ai = /* @__PURE__ */ Symbol("processJob");
5711
+ var G = /* @__PURE__ */ Symbol("jobs");
5712
+ var ls = /* @__PURE__ */ Symbol("jobDone");
5713
+ var ci = /* @__PURE__ */ Symbol("addFSEntry");
5714
+ var or = /* @__PURE__ */ Symbol("addTarEntry");
5715
+ var ds = /* @__PURE__ */ Symbol("stat");
5716
+ var us = /* @__PURE__ */ Symbol("readdir");
5717
+ var fi = /* @__PURE__ */ Symbol("onreaddir");
5718
+ var di = /* @__PURE__ */ Symbol("pipe");
5719
+ var hr = /* @__PURE__ */ Symbol("entry");
5720
+ var cs = /* @__PURE__ */ Symbol("entryOpt");
5721
+ var ui = /* @__PURE__ */ Symbol("writeEntryClass");
5722
+ var lr = /* @__PURE__ */ Symbol("write");
5723
+ var fs3 = /* @__PURE__ */ Symbol("ondrain");
5724
+ var wt = class extends A {
5725
+ sync = false;
5726
+ opt;
5727
+ cwd;
5728
+ maxReadSize;
5729
+ preservePaths;
5730
+ strict;
5731
+ noPax;
5732
+ prefix;
5733
+ linkCache;
5734
+ statCache;
5735
+ file;
5736
+ portable;
5737
+ zip;
5738
+ readdirCache;
5739
+ noDirRecurse;
5740
+ follow;
5741
+ noMtime;
5742
+ mtime;
5743
+ filter;
5744
+ jobs;
5745
+ [ui];
5746
+ onWriteEntry;
5747
+ [W];
5748
+ [pe] = /* @__PURE__ */ new Map();
5749
+ [G] = 0;
5750
+ [Ee] = false;
5751
+ [me] = false;
5752
+ constructor(t = {}) {
5753
+ if (super(), this.opt = t, this.file = t.file || "", this.cwd = t.cwd || process.cwd(), this.maxReadSize = t.maxReadSize, this.preservePaths = !!t.preservePaths, this.strict = !!t.strict, this.noPax = !!t.noPax, this.prefix = f(t.prefix || ""), this.linkCache = t.linkCache || /* @__PURE__ */ new Map(), this.statCache = t.statCache || /* @__PURE__ */ new Map(), this.readdirCache = t.readdirCache || /* @__PURE__ */ new Map(), this.onWriteEntry = t.onWriteEntry, this[ui] = de, typeof t.onwarn == "function" && this.on("warn", t.onwarn), this.portable = !!t.portable, t.gzip || t.brotli || t.zstd) {
5754
+ if ((t.gzip ? 1 : 0) + (t.brotli ? 1 : 0) + (t.zstd ? 1 : 0) > 1) throw new TypeError("gzip, brotli, zstd are mutually exclusive");
5755
+ if (t.gzip && (typeof t.gzip != "object" && (t.gzip = {}), this.portable && (t.gzip.portable = true), this.zip = new ze(t.gzip)), t.brotli && (typeof t.brotli != "object" && (t.brotli = {}), this.zip = new We(t.brotli)), t.zstd && (typeof t.zstd != "object" && (t.zstd = {}), this.zip = new Ye(t.zstd)), !this.zip) throw new Error("impossible");
5756
+ let e = this.zip;
5757
+ e.on("data", (i) => super.write(i)), e.on("end", () => super.end()), e.on("drain", () => this[fs3]()), this.on("resume", () => e.resume());
5758
+ } else this.on("drain", this[fs3]);
5759
+ this.noDirRecurse = !!t.noDirRecurse, this.follow = !!t.follow, this.noMtime = !!t.noMtime, t.mtime && (this.mtime = t.mtime), this.filter = typeof t.filter == "function" ? t.filter : () => true, this[W] = new hi(), this[G] = 0, this.jobs = Number(t.jobs) || 4, this[Ee] = false, this[me] = false;
5760
+ }
5761
+ [lr](t) {
5762
+ return super.write(t);
5763
+ }
5764
+ add(t) {
5765
+ return this.write(t), this;
5766
+ }
5767
+ end(t, e, i) {
5768
+ return typeof t == "function" && (i = t, t = void 0), typeof e == "function" && (i = e, e = void 0), t && this.add(t), this[me] = true, this[Ft](), i && i(), this;
5769
+ }
5770
+ write(t) {
5771
+ if (this[me]) throw new Error("write after end");
5772
+ return typeof t == "string" ? this[ci](t) : this[or](t), this.flowing;
5773
+ }
5774
+ [or](t) {
5775
+ let e = f(ar.resolve(this.cwd, t.path));
5776
+ if (!this.filter(t.path, t)) t.resume();
5777
+ else {
5778
+ let i = new pi(t.path, e);
5779
+ i.entry = new oi(t, this[cs](i)), i.entry.on("end", () => this[ls](i)), this[G] += 1, this[W].push(i);
5780
+ }
5781
+ this[Ft]();
5782
+ }
5783
+ [ci](t) {
5784
+ let e = f(ar.resolve(this.cwd, t));
5785
+ this[W].push(new pi(t, e)), this[Ft]();
5786
+ }
5787
+ [ds](t) {
5788
+ t.pending = true, this[G] += 1;
5789
+ let e = this.follow ? "stat" : "lstat";
5790
+ mi[e](t.absolute, (i, r) => {
5791
+ t.pending = false, this[G] -= 1, i ? this.emit("error", i) : this[li](t, r);
5792
+ });
5793
+ }
5794
+ [li](t, e) {
5795
+ if (this.statCache.set(t.absolute, e), t.stat = e, !this.filter(t.path, e)) t.ignore = true;
5796
+ else if (e.isFile() && e.nlink > 1 && !this.linkCache.get(`${e.dev}:${e.ino}`) && !this.sync) if (t === this[Et]) this[ai](t);
5797
+ else {
5798
+ let i = `${e.dev}:${e.ino}`, r = this[pe].get(i);
5799
+ r ? r.push(t) : this[pe].set(i, [t]), t.pendingLink = true, t.pending = true;
5800
+ }
5801
+ this[Ft]();
5802
+ }
5803
+ [us](t) {
5804
+ t.pending = true, this[G] += 1, mi.readdir(t.absolute, (e, i) => {
5805
+ if (t.pending = false, this[G] -= 1, e) return this.emit("error", e);
5806
+ this[fi](t, i);
5807
+ });
5808
+ }
5809
+ [fi](t, e) {
5810
+ this.readdirCache.set(t.absolute, e), t.readdir = e, this[Ft]();
5811
+ }
5812
+ [Ft]() {
5813
+ if (!this[Ee]) {
5814
+ this[Ee] = true;
5815
+ for (let t = this[W].head; t && this[G] < this.jobs; t = t.next) if (this[ai](t.value), t.value.ignore) {
5816
+ let e = t.next;
5817
+ this[W].removeNode(t), t.next = e;
5818
+ }
5819
+ this[Ee] = false, this[me] && this[W].length === 0 && this[G] === 0 && (this.zip ? this.zip.end(nr) : (super.write(nr), super.end()));
5820
+ }
5821
+ }
5822
+ get [Et]() {
5823
+ return this[W] && this[W].head && this[W].head.value;
5824
+ }
5825
+ [ls](t) {
5826
+ this[W].shift(), this[G] -= 1;
5827
+ let { stat: e } = t;
5828
+ if (e && e.isFile() && e.nlink > 1) {
5829
+ let i = `${e.dev}:${e.ino}`, r = this[pe].get(i);
5830
+ if (r) {
5831
+ this[pe].delete(i);
5832
+ for (let n of r) n.pending = false, this[ai](n);
5833
+ }
5834
+ }
5835
+ this[Ft]();
5836
+ }
5837
+ [ai](t) {
5838
+ if (t.pending && t.pendingLink && t === this[Et] && (t.pending = false, t.pendingLink = false), !t.pending) {
5839
+ if (t.entry) {
5840
+ t === this[Et] && !t.piped && this[di](t);
5841
+ return;
5842
+ }
5843
+ if (!t.stat) {
5844
+ let e = this.statCache.get(t.absolute);
5845
+ e ? this[li](t, e) : this[ds](t);
5846
+ }
5847
+ if (t.stat && !t.ignore) {
5848
+ if (!this.noDirRecurse && t.stat.isDirectory() && !t.readdir) {
5849
+ let e = this.readdirCache.get(t.absolute);
5850
+ if (e ? this[fi](t, e) : this[us](t), !t.readdir) return;
5851
+ }
5852
+ if (t.entry = this[hr](t), !t.entry) {
5853
+ t.ignore = true;
5854
+ return;
5855
+ }
5856
+ t === this[Et] && !t.piped && this[di](t);
5857
+ }
5858
+ }
5859
+ }
5860
+ [cs](t) {
5861
+ return { onwarn: (e, i, r) => this.warn(e, i, r), noPax: this.noPax, cwd: this.cwd, absolute: t.absolute, preservePaths: this.preservePaths, maxReadSize: this.maxReadSize, strict: this.strict, portable: this.portable, linkCache: this.linkCache, statCache: this.statCache, noMtime: this.noMtime, mtime: this.mtime, prefix: this.prefix, onWriteEntry: this.onWriteEntry };
5862
+ }
5863
+ [hr](t) {
5864
+ this[G] += 1;
5865
+ try {
5866
+ return new this[ui](t.path, this[cs](t)).on("end", () => this[ls](t)).on("error", (i) => this.emit("error", i));
5867
+ } catch (e) {
5868
+ this.emit("error", e);
5869
+ }
5870
+ }
5871
+ [fs3]() {
5872
+ this[Et] && this[Et].entry && this[Et].entry.resume();
5873
+ }
5874
+ [di](t) {
5875
+ t.piped = true, t.readdir && t.readdir.forEach((r) => {
5876
+ let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/");
5877
+ this[ci](o + r);
5878
+ });
5879
+ let e = t.entry, i = this.zip;
5880
+ if (!e) throw new Error("cannot pipe without source");
5881
+ i ? e.on("data", (r) => {
5882
+ i.write(r) || e.pause();
5883
+ }) : e.on("data", (r) => {
5884
+ super.write(r) || e.pause();
5885
+ });
5886
+ }
5887
+ pause() {
5888
+ return this.zip && this.zip.pause(), super.pause();
5889
+ }
5890
+ warn(t, e, i = {}) {
5891
+ Dt(this, t, e, i);
5892
+ }
5893
+ };
5894
+ var kt = class extends wt {
5895
+ sync = true;
5896
+ constructor(t) {
5897
+ super(t), this[ui] = ni;
5898
+ }
5899
+ pause() {
5900
+ }
5901
+ resume() {
5902
+ }
5903
+ [ds](t) {
5904
+ let e = this.follow ? "statSync" : "lstatSync";
5905
+ this[li](t, mi[e](t.absolute));
5906
+ }
5907
+ [us](t) {
5908
+ this[fi](t, mi.readdirSync(t.absolute));
5909
+ }
5910
+ [di](t) {
5911
+ let e = t.entry, i = this.zip;
5912
+ if (t.readdir && t.readdir.forEach((r) => {
5913
+ let n = t.path, o = n === "./" ? "" : n.replace(/\/*$/, "/");
5914
+ this[ci](o + r);
5915
+ }), !e) throw new Error("Cannot pipe without source");
5916
+ i ? e.on("data", (r) => {
5917
+ i.write(r);
5918
+ }) : e.on("data", (r) => {
5919
+ super[lr](r);
5920
+ });
5921
+ }
5922
+ };
5923
+ var Vn = (s3, t) => {
5924
+ let e = new kt(s3), i = new Wt(s3.file, { mode: s3.mode || 438 });
5925
+ e.pipe(i), fr(e, t);
5926
+ };
5927
+ var $n = (s3, t) => {
5928
+ let e = new wt(s3), i = new et(s3.file, { mode: s3.mode || 438 });
5929
+ e.pipe(i);
5930
+ let r = new Promise((n, o) => {
5931
+ i.on("error", o), i.on("close", n), e.on("error", o);
5932
+ });
5933
+ return dr(e, t).catch((n) => e.emit("error", n)), r;
5934
+ };
5935
+ var fr = (s3, t) => {
5936
+ t.forEach((e) => {
5937
+ e.charAt(0) === "@" ? Ct({ file: cr.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
5938
+ }), s3.end();
5939
+ };
5940
+ var dr = async (s3, t) => {
5941
+ for (let e of t) e.charAt(0) === "@" ? await Ct({ file: cr.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => {
5942
+ s3.add(i);
5943
+ } }) : s3.add(e);
5944
+ s3.end();
5945
+ };
5946
+ var Xn = (s3, t) => {
5947
+ let e = new kt(s3);
5948
+ return fr(e, t), e;
5949
+ };
5950
+ var qn = (s3, t) => {
5951
+ let e = new wt(s3);
5952
+ return dr(e, t).catch((i) => e.emit("error", i)), e;
5953
+ };
5954
+ var Qn = K(Vn, $n, Xn, qn, (s3, t) => {
5955
+ if (!t?.length) throw new TypeError("no paths specified to add to archive");
5956
+ });
5957
+ var Jn = process.env.__FAKE_PLATFORM__ || process.platform;
5958
+ var Er = Jn === "win32";
5959
+ var { O_CREAT: wr, O_NOFOLLOW: ur, O_TRUNC: Sr, O_WRONLY: yr } = pr.constants;
5960
+ var Rr = Number(process.env.__FAKE_FS_O_FILENAME__) || pr.constants.UV_FS_O_FILEMAP || 0;
5961
+ var jn = Er && !!Rr;
5962
+ var to = 512 * 1024;
5963
+ var eo = Rr | Sr | wr | yr;
5964
+ var mr = !Er && typeof ur == "number" ? ur | Sr | wr | yr : null;
5965
+ var ms = mr !== null ? () => mr : jn ? (s3) => s3 < to ? eo : "w" : () => "w";
5966
+ var ps = (s3, t, e) => {
5967
+ try {
5968
+ return wi.lchownSync(s3, t, e);
5969
+ } catch (i) {
5970
+ if (i?.code !== "ENOENT") throw i;
5971
+ }
5972
+ };
5973
+ var Ei = (s3, t, e, i) => {
5974
+ wi.lchown(s3, t, e, (r) => {
5975
+ i(r && r?.code !== "ENOENT" ? r : null);
5976
+ });
5977
+ };
5978
+ var io = (s3, t, e, i, r) => {
5979
+ if (t.isDirectory()) Es(we.resolve(s3, t.name), e, i, (n) => {
5980
+ if (n) return r(n);
5981
+ let o = we.resolve(s3, t.name);
5982
+ Ei(o, e, i, r);
5983
+ });
5984
+ else {
5985
+ let n = we.resolve(s3, t.name);
5986
+ Ei(n, e, i, r);
5987
+ }
5988
+ };
5989
+ var Es = (s3, t, e, i) => {
5990
+ wi.readdir(s3, { withFileTypes: true }, (r, n) => {
5991
+ if (r) {
5992
+ if (r.code === "ENOENT") return i();
5993
+ if (r.code !== "ENOTDIR" && r.code !== "ENOTSUP") return i(r);
5994
+ }
5995
+ if (r || !n.length) return Ei(s3, t, e, i);
5996
+ let o = n.length, h = null, a = (l) => {
5997
+ if (!h) {
5998
+ if (l) return i(h = l);
5999
+ if (--o === 0) return Ei(s3, t, e, i);
6000
+ }
6001
+ };
6002
+ for (let l of n) io(s3, l, t, e, a);
6003
+ });
6004
+ };
6005
+ var so = (s3, t, e, i) => {
6006
+ t.isDirectory() && ws(we.resolve(s3, t.name), e, i), ps(we.resolve(s3, t.name), e, i);
6007
+ };
6008
+ var ws = (s3, t, e) => {
6009
+ let i;
6010
+ try {
6011
+ i = wi.readdirSync(s3, { withFileTypes: true });
6012
+ } catch (r) {
6013
+ let n = r;
6014
+ if (n?.code === "ENOENT") return;
6015
+ if (n?.code === "ENOTDIR" || n?.code === "ENOTSUP") return ps(s3, t, e);
6016
+ throw n;
6017
+ }
6018
+ for (let r of i) so(s3, r, t, e);
6019
+ return ps(s3, t, e);
6020
+ };
6021
+ var Se = class extends Error {
6022
+ path;
6023
+ code;
6024
+ syscall = "chdir";
6025
+ constructor(t, e) {
6026
+ super(`${e}: Cannot cd into '${t}'`), this.path = t, this.code = e;
6027
+ }
6028
+ get name() {
6029
+ return "CwdError";
6030
+ }
6031
+ };
6032
+ var St = class extends Error {
6033
+ path;
6034
+ symlink;
6035
+ syscall = "symlink";
6036
+ code = "TAR_SYMLINK_ERROR";
6037
+ constructor(t, e) {
6038
+ super("TAR_SYMLINK_ERROR: Cannot extract through symbolic link"), this.symlink = t, this.path = e;
6039
+ }
6040
+ get name() {
6041
+ return "SymlinkError";
6042
+ }
6043
+ };
6044
+ var no = (s3, t) => {
6045
+ k.stat(s3, (e, i) => {
6046
+ (e || !i.isDirectory()) && (e = new Se(s3, e?.code || "ENOTDIR")), t(e);
6047
+ });
6048
+ };
6049
+ var gr = (s3, t, e) => {
6050
+ s3 = f(s3);
6051
+ let i = t.umask ?? 18, r = t.mode | 448, n = (r & i) !== 0, o = t.uid, h = t.gid, a = typeof o == "number" && typeof h == "number" && (o !== t.processUid || h !== t.processGid), l = t.preserve, c = t.unlink, d = f(t.cwd), y = (E, x) => {
6052
+ E ? e(E) : x && a ? Es(x, o, h, (Le) => y(Le)) : n ? k.chmod(s3, r, e) : e();
6053
+ };
6054
+ if (s3 === d) return no(s3, y);
6055
+ if (l) return ro.mkdir(s3, { mode: r, recursive: true }).then((E) => y(null, E ?? void 0), y);
6056
+ let D = f(Si.relative(d, s3)).split("/");
6057
+ Ss(d, D, r, c, d, void 0, y);
6058
+ };
6059
+ var Ss = (s3, t, e, i, r, n, o) => {
6060
+ if (t.length === 0) return o(null, n);
6061
+ let h = t.shift(), a = f(Si.resolve(s3 + "/" + h));
6062
+ k.mkdir(a, e, br(a, t, e, i, r, n, o));
6063
+ };
6064
+ var br = (s3, t, e, i, r, n, o) => (h) => {
6065
+ h ? k.lstat(s3, (a, l) => {
6066
+ if (a) a.path = a.path && f(a.path), o(a);
6067
+ else if (l.isDirectory()) Ss(s3, t, e, i, r, n, o);
6068
+ else if (i) k.unlink(s3, (c) => {
6069
+ if (c) return o(c);
6070
+ k.mkdir(s3, e, br(s3, t, e, i, r, n, o));
6071
+ });
6072
+ else {
6073
+ if (l.isSymbolicLink()) return o(new St(s3, s3 + "/" + t.join("/")));
6074
+ o(h);
6075
+ }
6076
+ }) : (n = n || s3, Ss(s3, t, e, i, r, n, o));
6077
+ };
6078
+ var oo = (s3) => {
6079
+ let t = false, e;
6080
+ try {
6081
+ t = k.statSync(s3).isDirectory();
6082
+ } catch (i) {
6083
+ e = i?.code;
6084
+ } finally {
6085
+ if (!t) throw new Se(s3, e ?? "ENOTDIR");
6086
+ }
6087
+ };
6088
+ var _r = (s3, t) => {
6089
+ s3 = f(s3);
6090
+ let e = t.umask ?? 18, i = t.mode | 448, r = (i & e) !== 0, n = t.uid, o = t.gid, h = typeof n == "number" && typeof o == "number" && (n !== t.processUid || o !== t.processGid), a = t.preserve, l = t.unlink, c = f(t.cwd), d = (E) => {
6091
+ E && h && ws(E, n, o), r && k.chmodSync(s3, i);
6092
+ };
6093
+ if (s3 === c) return oo(c), d();
6094
+ if (a) return d(k.mkdirSync(s3, { mode: i, recursive: true }) ?? void 0);
6095
+ let T = f(Si.relative(c, s3)).split("/"), D;
6096
+ for (let E = T.shift(), x = c; E && (x += "/" + E); E = T.shift()) {
6097
+ x = f(Si.resolve(x));
6098
+ try {
6099
+ k.mkdirSync(x, i), D = D || x;
6100
+ } catch {
6101
+ let Le = k.lstatSync(x);
6102
+ if (Le.isDirectory()) continue;
6103
+ if (l) {
6104
+ k.unlinkSync(x), k.mkdirSync(x, i), D = D || x;
6105
+ continue;
6106
+ } else if (Le.isSymbolicLink()) return new St(x, x + "/" + T.join("/"));
6107
+ }
6108
+ }
6109
+ return d(D);
6110
+ };
6111
+ var ys = /* @__PURE__ */ Object.create(null);
6112
+ var Or = 1e4;
6113
+ var Vt = /* @__PURE__ */ new Set();
6114
+ var Tr = (s3) => {
6115
+ Vt.has(s3) ? Vt.delete(s3) : ys[s3] = s3.normalize("NFD").toLocaleLowerCase("en").toLocaleUpperCase("en"), Vt.add(s3);
6116
+ let t = ys[s3], e = Vt.size - Or;
6117
+ if (e > Or / 10) {
6118
+ for (let i of Vt) if (Vt.delete(i), delete ys[i], --e <= 0) break;
6119
+ }
6120
+ return t;
6121
+ };
6122
+ var ho = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
6123
+ var ao = ho === "win32";
6124
+ var lo = (s3) => s3.split("/").slice(0, -1).reduce((e, i) => {
6125
+ let r = e.at(-1);
6126
+ return r !== void 0 && (i = xr(r, i)), e.push(i || "/"), e;
6127
+ }, []);
6128
+ var yi = class {
6129
+ #t = /* @__PURE__ */ new Map();
6130
+ #i = /* @__PURE__ */ new Map();
6131
+ #s = /* @__PURE__ */ new Set();
6132
+ reserve(t, e) {
6133
+ t = ao ? ["win32 parallelization disabled"] : t.map((r) => mt(xr(Tr(r))));
6134
+ let i = new Set(t.map((r) => lo(r)).reduce((r, n) => r.concat(n)));
6135
+ this.#i.set(e, { dirs: i, paths: t });
6136
+ for (let r of t) {
6137
+ let n = this.#t.get(r);
6138
+ n ? n.push(e) : this.#t.set(r, [e]);
6139
+ }
6140
+ for (let r of i) {
6141
+ let n = this.#t.get(r);
6142
+ if (!n) this.#t.set(r, [/* @__PURE__ */ new Set([e])]);
6143
+ else {
6144
+ let o = n.at(-1);
6145
+ o instanceof Set ? o.add(e) : n.push(/* @__PURE__ */ new Set([e]));
6146
+ }
6147
+ }
6148
+ return this.#r(e);
6149
+ }
6150
+ #n(t) {
6151
+ let e = this.#i.get(t);
6152
+ if (!e) throw new Error("function does not have any path reservations");
6153
+ return { paths: e.paths.map((i) => this.#t.get(i)), dirs: [...e.dirs].map((i) => this.#t.get(i)) };
6154
+ }
6155
+ check(t) {
6156
+ let { paths: e, dirs: i } = this.#n(t);
6157
+ return e.every((r) => r && r[0] === t) && i.every((r) => r && r[0] instanceof Set && r[0].has(t));
6158
+ }
6159
+ #r(t) {
6160
+ return this.#s.has(t) || !this.check(t) ? false : (this.#s.add(t), t(() => this.#e(t)), true);
6161
+ }
6162
+ #e(t) {
6163
+ if (!this.#s.has(t)) return false;
6164
+ let e = this.#i.get(t);
6165
+ if (!e) throw new Error("invalid reservation");
6166
+ let { paths: i, dirs: r } = e, n = /* @__PURE__ */ new Set();
6167
+ for (let o of i) {
6168
+ let h = this.#t.get(o);
6169
+ if (!h || h?.[0] !== t) continue;
6170
+ let a = h[1];
6171
+ if (!a) {
6172
+ this.#t.delete(o);
6173
+ continue;
6174
+ }
6175
+ if (h.shift(), typeof a == "function") n.add(a);
6176
+ else for (let l of a) n.add(l);
6177
+ }
6178
+ for (let o of r) {
6179
+ let h = this.#t.get(o), a = h?.[0];
6180
+ if (!(!h || !(a instanceof Set))) if (a.size === 1 && h.length === 1) {
6181
+ this.#t.delete(o);
6182
+ continue;
6183
+ } else if (a.size === 1) {
6184
+ h.shift();
6185
+ let l = h[0];
6186
+ typeof l == "function" && n.add(l);
6187
+ } else a.delete(t);
6188
+ }
6189
+ return this.#s.delete(t), n.forEach((o) => this.#r(o)), true;
6190
+ }
6191
+ };
6192
+ var Lr = () => process.umask();
6193
+ var Dr = /* @__PURE__ */ Symbol("onEntry");
6194
+ var _s = /* @__PURE__ */ Symbol("checkFs");
6195
+ var Nr = /* @__PURE__ */ Symbol("checkFs2");
6196
+ var Os = /* @__PURE__ */ Symbol("isReusable");
6197
+ var P = /* @__PURE__ */ Symbol("makeFs");
6198
+ var Ts = /* @__PURE__ */ Symbol("file");
6199
+ var xs = /* @__PURE__ */ Symbol("directory");
6200
+ var gi = /* @__PURE__ */ Symbol("link");
6201
+ var Ar = /* @__PURE__ */ Symbol("symlink");
6202
+ var Ir = /* @__PURE__ */ Symbol("hardlink");
6203
+ var Re = /* @__PURE__ */ Symbol("ensureNoSymlink");
6204
+ var Cr = /* @__PURE__ */ Symbol("unsupported");
6205
+ var Fr = /* @__PURE__ */ Symbol("checkPath");
6206
+ var Rs = /* @__PURE__ */ Symbol("stripAbsolutePath");
6207
+ var yt = /* @__PURE__ */ Symbol("mkdir");
6208
+ var O = /* @__PURE__ */ Symbol("onError");
6209
+ var Ri = /* @__PURE__ */ Symbol("pending");
6210
+ var kr = /* @__PURE__ */ Symbol("pend");
6211
+ var $t = /* @__PURE__ */ Symbol("unpend");
6212
+ var gs = /* @__PURE__ */ Symbol("ended");
6213
+ var bs = /* @__PURE__ */ Symbol("maybeClose");
6214
+ var Ls = /* @__PURE__ */ Symbol("skip");
6215
+ var ge = /* @__PURE__ */ Symbol("doChown");
6216
+ var be = /* @__PURE__ */ Symbol("uid");
6217
+ var _e = /* @__PURE__ */ Symbol("gid");
6218
+ var Oe = /* @__PURE__ */ Symbol("checkedCwd");
6219
+ var fo = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform;
6220
+ var Te = fo === "win32";
6221
+ var uo = 1024;
6222
+ var mo = (s3, t) => {
6223
+ if (!Te) return u.unlink(s3, t);
6224
+ let e = s3 + ".DELETE." + Mr(16).toString("hex");
6225
+ u.rename(s3, e, (i) => {
6226
+ if (i) return t(i);
6227
+ u.unlink(e, t);
6228
+ });
6229
+ };
6230
+ var po = (s3) => {
6231
+ if (!Te) return u.unlinkSync(s3);
6232
+ let t = s3 + ".DELETE." + Mr(16).toString("hex");
6233
+ u.renameSync(s3, t), u.unlinkSync(t);
6234
+ };
6235
+ var vr = (s3, t, e) => s3 !== void 0 && s3 === s3 >>> 0 ? s3 : t !== void 0 && t === t >>> 0 ? t : e;
6236
+ var Xt = class extends rt {
6237
+ [gs] = false;
6238
+ [Oe] = false;
6239
+ [Ri] = 0;
6240
+ reservations = new yi();
6241
+ transform;
6242
+ writable = true;
6243
+ readable = false;
6244
+ uid;
6245
+ gid;
6246
+ setOwner;
6247
+ preserveOwner;
6248
+ processGid;
6249
+ processUid;
6250
+ maxDepth;
6251
+ forceChown;
6252
+ win32;
6253
+ newer;
6254
+ keep;
6255
+ noMtime;
6256
+ preservePaths;
6257
+ unlink;
6258
+ cwd;
6259
+ strip;
6260
+ processUmask;
6261
+ umask;
6262
+ dmode;
6263
+ fmode;
6264
+ chmod;
6265
+ constructor(t = {}) {
6266
+ if (t.ondone = () => {
6267
+ this[gs] = true, this[bs]();
6268
+ }, super(t), this.transform = t.transform, this.chmod = !!t.chmod, typeof t.uid == "number" || typeof t.gid == "number") {
6269
+ if (typeof t.uid != "number" || typeof t.gid != "number") throw new TypeError("cannot set owner without number uid and gid");
6270
+ if (t.preserveOwner) throw new TypeError("cannot preserve owner in archive and also set owner explicitly");
6271
+ this.uid = t.uid, this.gid = t.gid, this.setOwner = true;
6272
+ } else this.uid = void 0, this.gid = void 0, this.setOwner = false;
6273
+ this.preserveOwner = t.preserveOwner === void 0 && typeof t.uid != "number" ? process.getuid?.() === 0 : !!t.preserveOwner, this.processUid = (this.preserveOwner || this.setOwner) && process.getuid ? process.getuid() : void 0, this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ? process.getgid() : void 0, this.maxDepth = typeof t.maxDepth == "number" ? t.maxDepth : uo, this.forceChown = t.forceChown === true, this.win32 = !!t.win32 || Te, this.newer = !!t.newer, this.keep = !!t.keep, this.noMtime = !!t.noMtime, this.preservePaths = !!t.preservePaths, this.unlink = !!t.unlink, this.cwd = f(R.resolve(t.cwd || process.cwd())), this.strip = Number(t.strip) || 0, this.processUmask = this.chmod ? typeof t.processUmask == "number" ? t.processUmask : Lr() : 0, this.umask = typeof t.umask == "number" ? t.umask : this.processUmask, this.dmode = t.dmode || 511 & ~this.umask, this.fmode = t.fmode || 438 & ~this.umask, this.on("entry", (e) => this[Dr](e));
6274
+ }
6275
+ warn(t, e, i = {}) {
6276
+ return (t === "TAR_BAD_ARCHIVE" || t === "TAR_ABORT") && (i.recoverable = false), super.warn(t, e, i);
6277
+ }
6278
+ [bs]() {
6279
+ this[gs] && this[Ri] === 0 && (this.emit("prefinish"), this.emit("finish"), this.emit("end"));
6280
+ }
6281
+ [Rs](t, e) {
6282
+ let i = t[e], { type: r } = t;
6283
+ if (!i || this.preservePaths) return true;
6284
+ let [n, o] = ce(i), h = o.replaceAll(/\\/g, "/").split("/");
6285
+ if (h.includes("..") || Te && /^[a-z]:\.\.$/i.test(h[0] ?? "")) {
6286
+ if (e === "path" || r === "Link") return this.warn("TAR_ENTRY_ERROR", `${e} contains '..'`, { entry: t, [e]: i }), false;
6287
+ let a = R.posix.dirname(t.path), l = R.posix.normalize(R.posix.join(a, h.join("/")));
6288
+ if (l.startsWith("../") || l === "..") return this.warn("TAR_ENTRY_ERROR", `${e} escapes extraction directory`, { entry: t, [e]: i }), false;
6289
+ }
6290
+ return n && (t[e] = String(o), this.warn("TAR_ENTRY_INFO", `stripping ${n} from absolute ${e}`, { entry: t, [e]: i })), true;
6291
+ }
6292
+ [Fr](t) {
6293
+ let e = f(t.path), i = e.split("/");
6294
+ if (this.strip) {
6295
+ if (i.length < this.strip) return false;
6296
+ if (t.type === "Link") {
6297
+ let r = f(String(t.linkpath)).split("/");
6298
+ if (r.length >= this.strip) t.linkpath = r.slice(this.strip).join("/");
6299
+ else return false;
6300
+ }
6301
+ i.splice(0, this.strip), t.path = i.join("/");
6302
+ }
6303
+ if (isFinite(this.maxDepth) && i.length > this.maxDepth) return this.warn("TAR_ENTRY_ERROR", "path excessively deep", { entry: t, path: e, depth: i.length, maxDepth: this.maxDepth }), false;
6304
+ if (!this[Rs](t, "path") || !this[Rs](t, "linkpath")) return false;
6305
+ if (t.absolute = R.isAbsolute(t.path) ? f(R.resolve(t.path)) : f(R.resolve(this.cwd, t.path)), !this.preservePaths && typeof t.absolute == "string" && t.absolute.indexOf(this.cwd + "/") !== 0 && t.absolute !== this.cwd) return this.warn("TAR_ENTRY_ERROR", "path escaped extraction target", { entry: t, path: f(t.path), resolvedPath: t.absolute, cwd: this.cwd }), false;
6306
+ if (t.absolute === this.cwd && t.type !== "Directory" && t.type !== "GNUDumpDir") return false;
6307
+ if (this.win32) {
6308
+ let { root: r } = R.win32.parse(String(t.absolute));
6309
+ t.absolute = r + ts(String(t.absolute).slice(r.length));
6310
+ let { root: n } = R.win32.parse(t.path);
6311
+ t.path = n + ts(t.path.slice(n.length));
6312
+ }
6313
+ return true;
6314
+ }
6315
+ [Dr](t) {
6316
+ if (!this[Fr](t)) return t.resume();
6317
+ switch (co.equal(typeof t.absolute, "string"), t.type) {
6318
+ case "Directory":
6319
+ case "GNUDumpDir":
6320
+ t.mode && (t.mode = t.mode | 448);
6321
+ case "File":
6322
+ case "OldFile":
6323
+ case "ContiguousFile":
6324
+ case "Link":
6325
+ case "SymbolicLink":
6326
+ return this[_s](t);
6327
+ default:
6328
+ return this[Cr](t);
6329
+ }
6330
+ }
6331
+ [O](t, e) {
6332
+ t.name === "CwdError" ? this.emit("error", t) : (this.warn("TAR_ENTRY_ERROR", t, { entry: e }), this[$t](), e.resume());
6333
+ }
6334
+ [yt](t, e, i) {
6335
+ gr(f(t), { uid: this.uid, gid: this.gid, processUid: this.processUid, processGid: this.processGid, umask: this.processUmask, preserve: this.preservePaths, unlink: this.unlink, cwd: this.cwd, mode: e }, i);
6336
+ }
6337
+ [ge](t) {
6338
+ return this.forceChown || this.preserveOwner && (typeof t.uid == "number" && t.uid !== this.processUid || typeof t.gid == "number" && t.gid !== this.processGid) || typeof this.uid == "number" && this.uid !== this.processUid || typeof this.gid == "number" && this.gid !== this.processGid;
6339
+ }
6340
+ [be](t) {
6341
+ return vr(this.uid, t.uid, this.processUid);
6342
+ }
6343
+ [_e](t) {
6344
+ return vr(this.gid, t.gid, this.processGid);
6345
+ }
6346
+ [Ts](t, e) {
6347
+ let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = new et(String(t.absolute), { flags: ms(t.size), mode: i, autoClose: false });
6348
+ r.on("error", (a) => {
6349
+ r.fd && u.close(r.fd, () => {
6350
+ }), r.write = () => true, this[O](a, t), e();
6351
+ });
6352
+ let n = 1, o = (a) => {
6353
+ if (a) {
6354
+ r.fd && u.close(r.fd, () => {
6355
+ }), this[O](a, t), e();
6356
+ return;
6357
+ }
6358
+ --n === 0 && r.fd !== void 0 && u.close(r.fd, (l) => {
6359
+ l ? this[O](l, t) : this[$t](), e();
6360
+ });
6361
+ };
6362
+ r.on("finish", () => {
6363
+ let a = String(t.absolute), l = r.fd;
6364
+ if (typeof l == "number" && t.mtime && !this.noMtime) {
6365
+ n++;
6366
+ let c = t.atime || /* @__PURE__ */ new Date(), d = t.mtime;
6367
+ u.futimes(l, c, d, (y) => y ? u.utimes(a, c, d, (T) => o(T && y)) : o());
6368
+ }
6369
+ if (typeof l == "number" && this[ge](t)) {
6370
+ n++;
6371
+ let c = this[be](t), d = this[_e](t);
6372
+ typeof c == "number" && typeof d == "number" && u.fchown(l, c, d, (y) => y ? u.chown(a, c, d, (T) => o(T && y)) : o());
6373
+ }
6374
+ o();
6375
+ });
6376
+ let h = this.transform && this.transform(t) || t;
6377
+ h !== t && (h.on("error", (a) => {
6378
+ this[O](a, t), e();
6379
+ }), t.pipe(h)), h.pipe(r);
6380
+ }
6381
+ [xs](t, e) {
6382
+ let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode;
6383
+ this[yt](String(t.absolute), i, (r) => {
6384
+ if (r) {
6385
+ this[O](r, t), e();
6386
+ return;
6387
+ }
6388
+ let n = 1, o = () => {
6389
+ --n === 0 && (e(), this[$t](), t.resume());
6390
+ };
6391
+ t.mtime && !this.noMtime && (n++, u.utimes(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime, o)), this[ge](t) && (n++, u.chown(String(t.absolute), Number(this[be](t)), Number(this[_e](t)), o)), o();
6392
+ });
6393
+ }
6394
+ [Cr](t) {
6395
+ t.unsupported = true, this.warn("TAR_ENTRY_UNSUPPORTED", `unsupported entry type: ${t.type}`, { entry: t }), t.resume();
6396
+ }
6397
+ [Ar](t, e) {
6398
+ let i = f(R.relative(this.cwd, R.resolve(R.dirname(String(t.absolute)), String(t.linkpath)))).split("/");
6399
+ this[Re](t, this.cwd, i, () => this[gi](t, String(t.linkpath), "symlink", e), (r) => {
6400
+ this[O](r, t), e();
6401
+ });
6402
+ }
6403
+ [Ir](t, e) {
6404
+ let i = f(R.resolve(this.cwd, String(t.linkpath))), r = f(String(t.linkpath)).split("/");
6405
+ this[Re](t, this.cwd, r, () => this[gi](t, i, "link", e), (n) => {
6406
+ this[O](n, t), e();
6407
+ });
6408
+ }
6409
+ [Re](t, e, i, r, n) {
6410
+ let o = i.shift();
6411
+ if (this.preservePaths || o === void 0) return r();
6412
+ let h = R.resolve(e, o);
6413
+ u.lstat(h, (a, l) => {
6414
+ if (a) return r();
6415
+ if (l?.isSymbolicLink()) return n(new St(h, R.resolve(h, i.join("/"))));
6416
+ this[Re](t, h, i, r, n);
6417
+ });
6418
+ }
6419
+ [kr]() {
6420
+ this[Ri]++;
6421
+ }
6422
+ [$t]() {
6423
+ this[Ri]--, this[bs]();
6424
+ }
6425
+ [Ls](t) {
6426
+ this[$t](), t.resume();
6427
+ }
6428
+ [Os](t, e) {
6429
+ return t.type === "File" && !this.unlink && e.isFile() && e.nlink <= 1 && !Te;
6430
+ }
6431
+ [_s](t) {
6432
+ this[kr]();
6433
+ let e = [t.path];
6434
+ t.linkpath && e.push(t.linkpath), this.reservations.reserve(e, (i) => this[Nr](t, i));
6435
+ }
6436
+ [Nr](t, e) {
6437
+ let i = (h) => {
6438
+ e(h);
6439
+ }, r = () => {
6440
+ this[yt](this.cwd, this.dmode, (h) => {
6441
+ if (h) {
6442
+ this[O](h, t), i();
6443
+ return;
6444
+ }
6445
+ this[Oe] = true, n();
6446
+ });
6447
+ }, n = () => {
6448
+ if (t.absolute !== this.cwd) {
6449
+ let h = f(R.dirname(String(t.absolute)));
6450
+ if (h !== this.cwd) return this[yt](h, this.dmode, (a) => {
6451
+ if (a) {
6452
+ this[O](a, t), i();
6453
+ return;
6454
+ }
6455
+ o();
6456
+ });
6457
+ }
6458
+ o();
6459
+ }, o = () => {
6460
+ u.lstat(String(t.absolute), (h, a) => {
6461
+ if (a && (this.keep || this.newer && a.mtime > (t.mtime ?? a.mtime))) {
6462
+ this[Ls](t), i();
6463
+ return;
6464
+ }
6465
+ if (h || this[Os](t, a)) return this[P](null, t, i);
6466
+ if (a.isDirectory()) {
6467
+ if (t.type === "Directory") {
6468
+ let l = this.chmod && t.mode && (a.mode & 4095) !== t.mode, c = (d) => this[P](d ?? null, t, i);
6469
+ return l ? u.chmod(String(t.absolute), Number(t.mode), c) : c();
6470
+ }
6471
+ if (t.absolute !== this.cwd) return u.rmdir(String(t.absolute), (l) => this[P](l ?? null, t, i));
6472
+ }
6473
+ if (t.absolute === this.cwd) return this[P](null, t, i);
6474
+ mo(String(t.absolute), (l) => this[P](l ?? null, t, i));
6475
+ });
6476
+ };
6477
+ this[Oe] ? n() : r();
6478
+ }
6479
+ [P](t, e, i) {
6480
+ if (t) {
6481
+ this[O](t, e), i();
6482
+ return;
6483
+ }
6484
+ switch (e.type) {
6485
+ case "File":
6486
+ case "OldFile":
6487
+ case "ContiguousFile":
6488
+ return this[Ts](e, i);
6489
+ case "Link":
6490
+ return this[Ir](e, i);
6491
+ case "SymbolicLink":
6492
+ return this[Ar](e, i);
6493
+ case "Directory":
6494
+ case "GNUDumpDir":
6495
+ return this[xs](e, i);
6496
+ }
6497
+ }
6498
+ [gi](t, e, i, r) {
6499
+ u[i](e, String(t.absolute), (n) => {
6500
+ n ? this[O](n, t) : (this[$t](), t.resume()), r();
6501
+ });
6502
+ }
6503
+ };
6504
+ var ye = (s3) => {
6505
+ try {
6506
+ return [null, s3()];
6507
+ } catch (t) {
6508
+ return [t, null];
6509
+ }
6510
+ };
6511
+ var xe = class extends Xt {
6512
+ sync = true;
6513
+ [P](t, e) {
6514
+ return super[P](t, e, () => {
6515
+ });
6516
+ }
6517
+ [_s](t) {
6518
+ if (!this[Oe]) {
6519
+ let n = this[yt](this.cwd, this.dmode);
6520
+ if (n) return this[O](n, t);
6521
+ this[Oe] = true;
6522
+ }
6523
+ if (t.absolute !== this.cwd) {
6524
+ let n = f(R.dirname(String(t.absolute)));
6525
+ if (n !== this.cwd) {
6526
+ let o = this[yt](n, this.dmode);
6527
+ if (o) return this[O](o, t);
6528
+ }
6529
+ }
6530
+ let [e, i] = ye(() => u.lstatSync(String(t.absolute)));
6531
+ if (i && (this.keep || this.newer && i.mtime > (t.mtime ?? i.mtime))) return this[Ls](t);
6532
+ if (e || this[Os](t, i)) return this[P](null, t);
6533
+ if (i.isDirectory()) {
6534
+ if (t.type === "Directory") {
6535
+ let o = this.chmod && t.mode && (i.mode & 4095) !== t.mode, [h] = o ? ye(() => {
6536
+ u.chmodSync(String(t.absolute), Number(t.mode));
6537
+ }) : [];
6538
+ return this[P](h, t);
6539
+ }
6540
+ let [n] = ye(() => u.rmdirSync(String(t.absolute)));
6541
+ this[P](n, t);
6542
+ }
6543
+ let [r] = t.absolute === this.cwd ? [] : ye(() => po(String(t.absolute)));
6544
+ this[P](r, t);
6545
+ }
6546
+ [Ts](t, e) {
6547
+ let i = typeof t.mode == "number" ? t.mode & 4095 : this.fmode, r = (h) => {
6548
+ let a;
6549
+ try {
6550
+ u.closeSync(n);
6551
+ } catch (l) {
6552
+ a = l;
6553
+ }
6554
+ (h || a) && this[O](h || a, t), e();
6555
+ }, n;
6556
+ try {
6557
+ n = u.openSync(String(t.absolute), ms(t.size), i);
6558
+ } catch (h) {
6559
+ return r(h);
6560
+ }
6561
+ let o = this.transform && this.transform(t) || t;
6562
+ o !== t && (o.on("error", (h) => this[O](h, t)), t.pipe(o)), o.on("data", (h) => {
6563
+ try {
6564
+ u.writeSync(n, h, 0, h.length);
6565
+ } catch (a) {
6566
+ r(a);
6567
+ }
6568
+ }), o.on("end", () => {
6569
+ let h = null;
6570
+ if (t.mtime && !this.noMtime) {
6571
+ let a = t.atime || /* @__PURE__ */ new Date(), l = t.mtime;
6572
+ try {
6573
+ u.futimesSync(n, a, l);
6574
+ } catch (c) {
6575
+ try {
6576
+ u.utimesSync(String(t.absolute), a, l);
6577
+ } catch {
6578
+ h = c;
6579
+ }
6580
+ }
6581
+ }
6582
+ if (this[ge](t)) {
6583
+ let a = this[be](t), l = this[_e](t);
6584
+ try {
6585
+ u.fchownSync(n, Number(a), Number(l));
6586
+ } catch (c) {
6587
+ try {
6588
+ u.chownSync(String(t.absolute), Number(a), Number(l));
6589
+ } catch {
6590
+ h = h || c;
6591
+ }
6592
+ }
6593
+ }
6594
+ r(h);
6595
+ });
6596
+ }
6597
+ [xs](t, e) {
6598
+ let i = typeof t.mode == "number" ? t.mode & 4095 : this.dmode, r = this[yt](String(t.absolute), i);
6599
+ if (r) {
6600
+ this[O](r, t), e();
6601
+ return;
6602
+ }
6603
+ if (t.mtime && !this.noMtime) try {
6604
+ u.utimesSync(String(t.absolute), t.atime || /* @__PURE__ */ new Date(), t.mtime);
6605
+ } catch {
6606
+ }
6607
+ if (this[ge](t)) try {
6608
+ u.chownSync(String(t.absolute), Number(this[be](t)), Number(this[_e](t)));
6609
+ } catch {
6610
+ }
6611
+ e(), t.resume();
6612
+ }
6613
+ [yt](t, e) {
6614
+ try {
6615
+ return _r(f(t), { uid: this.uid, gid: this.gid, processUid: this.processUid, processGid: this.processGid, umask: this.processUmask, preserve: this.preservePaths, unlink: this.unlink, cwd: this.cwd, mode: e });
6616
+ } catch (i) {
6617
+ return i;
6618
+ }
6619
+ }
6620
+ [Re](t, e, i, r, n) {
6621
+ if (this.preservePaths || i.length === 0) return r();
6622
+ let o = e;
6623
+ for (let h of i) {
6624
+ o = R.resolve(o, h);
6625
+ let [a, l] = ye(() => u.lstatSync(o));
6626
+ if (a) return r();
6627
+ if (l.isSymbolicLink()) return n(new St(o, R.resolve(e, i.join("/"))));
6628
+ }
6629
+ r();
6630
+ }
6631
+ [gi](t, e, i, r) {
6632
+ let n = `${i}Sync`;
6633
+ try {
6634
+ u[n](e, String(t.absolute)), r(), t.resume();
6635
+ } catch (o) {
6636
+ return this[O](o, t);
6637
+ }
6638
+ }
6639
+ };
6640
+ var Eo = (s3) => {
6641
+ let t = new xe(s3), e = s3.file, i = Br.statSync(e), r = s3.maxReadSize || 16 * 1024 * 1024;
6642
+ new Be(e, { readSize: r, size: i.size }).pipe(t);
6643
+ };
6644
+ var wo = (s3, t) => {
6645
+ let e = new Xt(s3), i = s3.maxReadSize || 16 * 1024 * 1024, r = s3.file;
6646
+ return new Promise((o, h) => {
6647
+ e.on("error", h), e.on("close", o), Br.stat(r, (a, l) => {
6648
+ if (a) h(a);
6649
+ else {
6650
+ let c = new _t(r, { readSize: i, size: l.size });
6651
+ c.on("error", h), c.pipe(e);
6652
+ }
6653
+ });
6654
+ });
6655
+ };
6656
+ var So = K(Eo, wo, (s3) => new xe(s3), (s3) => new Xt(s3), (s3, t) => {
6657
+ t?.length && Qi(s3, t);
6658
+ });
6659
+ var yo = (s3, t) => {
6660
+ let e = new kt(s3), i = true, r, n;
6661
+ try {
6662
+ try {
6663
+ r = v.openSync(s3.file, "r+");
6664
+ } catch (a) {
6665
+ if (a?.code === "ENOENT") r = v.openSync(s3.file, "w+");
6666
+ else throw a;
6667
+ }
6668
+ let o = v.fstatSync(r), h = Buffer.alloc(512);
6669
+ t: for (n = 0; n < o.size; n += 512) {
6670
+ for (let c = 0, d = 0; c < 512; c += d) {
6671
+ if (d = v.readSync(r, h, c, h.length - c, n + c), n === 0 && h[0] === 31 && h[1] === 139) throw new Error("cannot append to compressed archives");
6672
+ if (!d) break t;
6673
+ }
6674
+ let a = new F(h);
6675
+ if (!a.cksumValid) break;
6676
+ let l = 512 * Math.ceil((a.size || 0) / 512);
6677
+ if (n + l + 512 > o.size) break;
6678
+ n += l, s3.mtimeCache && a.mtime && s3.mtimeCache.set(String(a.path), a.mtime);
6679
+ }
6680
+ i = false, Ro(s3, e, n, r, t);
6681
+ } finally {
6682
+ if (i) try {
6683
+ v.closeSync(r);
6684
+ } catch {
6685
+ }
6686
+ }
6687
+ };
6688
+ var Ro = (s3, t, e, i, r) => {
6689
+ let n = new Wt(s3.file, { fd: i, start: e });
6690
+ t.pipe(n), bo(t, r);
6691
+ };
6692
+ var go = (s3, t) => {
6693
+ t = Array.from(t);
6694
+ let e = new wt(s3), i = (n, o, h) => {
6695
+ let a = (T, D) => {
6696
+ T ? v.close(n, (E) => h(T)) : h(null, D);
6697
+ }, l = 0;
6698
+ if (o === 0) return a(null, 0);
6699
+ let c = 0, d = Buffer.alloc(512), y = (T, D) => {
6700
+ if (T || D === void 0) return a(T);
6701
+ if (c += D, c < 512 && D) return v.read(n, d, c, d.length - c, l + c, y);
6702
+ if (l === 0 && d[0] === 31 && d[1] === 139) return a(new Error("cannot append to compressed archives"));
6703
+ if (c < 512) return a(null, l);
6704
+ let E = new F(d);
6705
+ if (!E.cksumValid) return a(null, l);
6706
+ let x = 512 * Math.ceil((E.size ?? 0) / 512);
6707
+ if (l + x + 512 > o || (l += x + 512, l >= o)) return a(null, l);
6708
+ s3.mtimeCache && E.mtime && s3.mtimeCache.set(String(E.path), E.mtime), c = 0, v.read(n, d, 0, 512, l, y);
6709
+ };
6710
+ v.read(n, d, 0, 512, l, y);
6711
+ };
6712
+ return new Promise((n, o) => {
6713
+ e.on("error", o);
6714
+ let h = "r+", a = (l, c) => {
6715
+ if (l && l.code === "ENOENT" && h === "r+") return h = "w+", v.open(s3.file, h, a);
6716
+ if (l || !c) return o(l);
6717
+ v.fstat(c, (d, y) => {
6718
+ if (d) return v.close(c, () => o(d));
6719
+ i(c, y.size, (T, D) => {
6720
+ if (T) return o(T);
6721
+ let E = new et(s3.file, { fd: c, start: D });
6722
+ e.pipe(E), E.on("error", o), E.on("close", n), _o(e, t);
6723
+ });
6724
+ });
6725
+ };
6726
+ v.open(s3.file, h, a);
6727
+ });
6728
+ };
6729
+ var bo = (s3, t) => {
6730
+ t.forEach((e) => {
6731
+ e.charAt(0) === "@" ? Ct({ file: Pr.resolve(s3.cwd, e.slice(1)), sync: true, noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
6732
+ }), s3.end();
6733
+ };
6734
+ var _o = async (s3, t) => {
6735
+ for (let e of t) e.charAt(0) === "@" ? await Ct({ file: Pr.resolve(String(s3.cwd), e.slice(1)), noResume: true, onReadEntry: (i) => s3.add(i) }) : s3.add(e);
6736
+ s3.end();
6737
+ };
6738
+ var vt = K(yo, go, () => {
6739
+ throw new TypeError("file is required");
6740
+ }, () => {
6741
+ throw new TypeError("file is required");
6742
+ }, (s3, t) => {
6743
+ if (!Bs(s3)) throw new TypeError("file is required");
6744
+ if (s3.gzip || s3.brotli || s3.zstd || s3.file.endsWith(".br") || s3.file.endsWith(".tbr")) throw new TypeError("cannot append to compressed archives");
6745
+ if (!t?.length) throw new TypeError("no paths specified to add/replace");
6746
+ });
6747
+ var Oo = K(vt.syncFile, vt.asyncFile, vt.syncNoFile, vt.asyncNoFile, (s3, t = []) => {
6748
+ vt.validate?.(s3, t), To(s3);
6749
+ });
6750
+ var To = (s3) => {
6751
+ let t = s3.filter;
6752
+ s3.mtimeCache || (s3.mtimeCache = /* @__PURE__ */ new Map()), s3.filter = t ? (e, i) => t(e, i) && !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0)) : (e, i) => !((s3.mtimeCache?.get(e) ?? i.mtime ?? 0) > (i.mtime ?? 0));
6753
+ };
6754
+
6755
+ // src/update.ts
3786
6756
  import path4 from "path";
3787
6757
  import { fileURLToPath as fileURLToPath2 } from "url";
3788
6758
  var REGISTRY_BASE = "https://registry.npmjs.org";
@@ -3793,8 +6763,8 @@ var LOCK_STALE_MS = 2 * 60 * 1e3;
3793
6763
  var timer;
3794
6764
  var inFlight = false;
3795
6765
  var firstCheckDone = false;
3796
- function parseVersion(v) {
3797
- return v.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
6766
+ function parseVersion(v2) {
6767
+ return v2.replace(/^v/, "").split(".").map((n) => parseInt(n, 10) || 0);
3798
6768
  }
3799
6769
  function isNewer(latest, current) {
3800
6770
  const l = parseVersion(latest);
@@ -3815,10 +6785,10 @@ async function readLastCheck() {
3815
6785
  return 0;
3816
6786
  }
3817
6787
  }
3818
- async function writeLastCheck(ts) {
6788
+ async function writeLastCheck(ts2) {
3819
6789
  try {
3820
6790
  await mkdir(path4.dirname(THROTTLE_FILE), { recursive: true });
3821
- await writeFile(THROTTLE_FILE, String(ts), "utf-8");
6791
+ await writeFile(THROTTLE_FILE, String(ts2), "utf-8");
3822
6792
  } catch {
3823
6793
  }
3824
6794
  }
@@ -3993,23 +6963,11 @@ async function installViaTarball(version, tarballUrl, installDir) {
3993
6963
  try {
3994
6964
  await rm(stagingDir, { recursive: true, force: true });
3995
6965
  await mkdir(stagingDir, { recursive: true });
3996
- const { code, stderr } = await new Promise((resolve) => {
3997
- execFile(
3998
- "tar",
3999
- ["xzf", tmpFile, "-C", stagingDir, "--strip-components=1"],
4000
- { timeout: 3e4 },
4001
- (err, _stdout, stderr2) => {
4002
- if (err) {
4003
- resolve({ code: 1, stderr: stderr2 || err.message });
4004
- } else {
4005
- resolve({ code: 0, stderr: stderr2 || "" });
4006
- }
4007
- }
4008
- );
6966
+ await So({
6967
+ file: tmpFile,
6968
+ cwd: stagingDir,
6969
+ strip: 1
4009
6970
  });
4010
- if (code !== 0) {
4011
- return { ok: false, error: `extraction failed (tar exit ${code})${stderr.trim() ? `: ${stderr.trim()}` : ""}` };
4012
- }
4013
6971
  const stagingVersion = await readDiskVersion(stagingDir);
4014
6972
  if (stagingVersion !== version) {
4015
6973
  return { ok: false, error: `staging verification failed: version is ${stagingVersion ?? "missing"}, expected ${version}` };
@@ -4020,23 +6978,7 @@ async function installViaTarball(version, tarballUrl, installDir) {
4020
6978
  await rm(tmpFile, { force: true });
4021
6979
  }
4022
6980
  try {
4023
- const { code, stderr } = await new Promise((resolve) => {
4024
- execFile(
4025
- "cp",
4026
- ["-r", stagingDir + "/.", installDir + "/"],
4027
- { timeout: 3e4 },
4028
- (err, _stdout, stderr2) => {
4029
- if (err) {
4030
- resolve({ code: 1, stderr: stderr2 || err.message });
4031
- } else {
4032
- resolve({ code: 0, stderr: stderr2 || "" });
4033
- }
4034
- }
4035
- );
4036
- });
4037
- if (code !== 0) {
4038
- return { ok: false, error: `failed to copy to install dir (cp exit ${code})${stderr.trim() ? `: ${stderr.trim()}` : ""}` };
4039
- }
6981
+ await cp(stagingDir, installDir, { recursive: true, force: true });
4040
6982
  } catch (e) {
4041
6983
  return { ok: false, error: `failed to copy to install dir: ${String(e)}` };
4042
6984
  } finally {
@@ -4185,8 +7127,8 @@ async function main() {
4185
7127
  await checkForUpdate({ packageName: PACKAGE_NAME, currentVersion: VERSION, autoUpdate: true }, true);
4186
7128
  return;
4187
7129
  }
4188
- for (const [k, v] of Object.entries(overrides)) {
4189
- if (v !== void 0) process.env[k] = v;
7130
+ for (const [k2, v2] of Object.entries(overrides)) {
7131
+ if (v2 !== void 0) process.env[k2] = v2;
4190
7132
  }
4191
7133
  ensureConfigTemplate();
4192
7134
  const opts = loadOptions();