@tacuchi/updater 2.0.4 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/cli.js +542 -126
  2. package/package.json +8 -3
package/dist/cli.js CHANGED
@@ -5,10 +5,11 @@ import { render } from "ink";
5
5
  import { execaSync } from "execa";
6
6
 
7
7
  // src/app.tsx
8
- import { Box as Box8, Text as Text9, useInput as useInput6, useApp as useInkApp } from "ink";
8
+ import { Box as Box8, Text as Text9, useApp as useInkApp } from "ink";
9
9
 
10
10
  // src/hooks/use-app-machine.tsx
11
11
  import { createContext, useContext, useReducer, useEffect, useRef, useCallback } from "react";
12
+ import { useApp } from "ink";
12
13
 
13
14
  // src/state/types.ts
14
15
  var SELECTION_SEP = "\0";
@@ -161,6 +162,80 @@ import { execa as execa2, ExecaError } from "execa";
161
162
 
162
163
  // src/lib/exec/run.ts
163
164
  import { execa } from "execa";
165
+
166
+ // src/lib/exec/decode.ts
167
+ import iconv from "iconv-lite";
168
+ var DEFAULT_OEM = 437;
169
+ function looksLikeUtf16LE(buf) {
170
+ const n = Math.min(buf.length, 4096);
171
+ if (n < 4) return false;
172
+ let oddZeros = 0;
173
+ let oddTotal = 0;
174
+ for (let i = 1; i < n; i += 2) {
175
+ oddTotal++;
176
+ if (buf[i] === 0) oddZeros++;
177
+ }
178
+ return oddTotal > 0 && oddZeros / oddTotal > 0.6;
179
+ }
180
+ function isValidUtf8(buf) {
181
+ try {
182
+ new TextDecoder("utf-8", { fatal: true }).decode(buf);
183
+ return true;
184
+ } catch {
185
+ return false;
186
+ }
187
+ }
188
+ function oemEncoding(oem) {
189
+ const name = `cp${oem}`;
190
+ return iconv.encodingExists(name) ? name : "utf8";
191
+ }
192
+ function sniff(buf, oem = DEFAULT_OEM) {
193
+ if (buf.length >= 3 && buf[0] === 239 && buf[1] === 187 && buf[2] === 191) return { enc: "utf8", bomLen: 3 };
194
+ if (buf.length >= 2 && buf[0] === 255 && buf[1] === 254) return { enc: "utf16-le", bomLen: 2 };
195
+ if (buf.length >= 2 && buf[0] === 254 && buf[1] === 255) return { enc: "utf16-be", bomLen: 2 };
196
+ if (looksLikeUtf16LE(buf)) return { enc: "utf16-le", bomLen: 0 };
197
+ if (isValidUtf8(buf)) return { enc: "utf8", bomLen: 0 };
198
+ return { enc: oemEncoding(oem), bomLen: 0 };
199
+ }
200
+ function decodeSmart(buf, oem = DEFAULT_OEM) {
201
+ if (!buf || buf.length === 0) return "";
202
+ const { enc, bomLen } = sniff(buf, oem);
203
+ return iconv.decode(bomLen ? buf.subarray(bomLen) : buf, enc);
204
+ }
205
+ var StreamDecoder = class {
206
+ constructor(oem = DEFAULT_OEM) {
207
+ this.oem = oem;
208
+ }
209
+ dec = null;
210
+ write(chunk) {
211
+ if (!chunk || chunk.length === 0) return "";
212
+ let b = chunk;
213
+ let dec = this.dec;
214
+ if (!dec) {
215
+ const { enc, bomLen } = sniff(b, this.oem);
216
+ dec = iconv.getDecoder(enc);
217
+ this.dec = dec;
218
+ if (bomLen) b = b.subarray(bomLen);
219
+ }
220
+ return dec.write(b);
221
+ }
222
+ end() {
223
+ return this.dec ? this.dec.end() ?? "" : "";
224
+ }
225
+ };
226
+
227
+ // src/lib/exec/kill-tree.ts
228
+ import treeKill from "tree-kill";
229
+ function killTree(pid, signal = "SIGTERM") {
230
+ if (!pid) return;
231
+ try {
232
+ treeKill(pid, signal, () => {
233
+ });
234
+ } catch {
235
+ }
236
+ }
237
+
238
+ // src/lib/exec/run.ts
164
239
  var DEFAULT_TAIL_BYTES = 16384;
165
240
  function withSudo(cmd, args2, sudo) {
166
241
  if (process.platform === "win32") return [cmd, args2];
@@ -186,27 +261,48 @@ function execaOptions(opts, all) {
186
261
  cwd: opts.cwd,
187
262
  env: opts.env,
188
263
  cancelSignal: opts.signal,
189
- all
264
+ all,
265
+ // Capture raw bytes; we sniff-decode (UTF-8 / UTF-16LE / OEM) ourselves.
266
+ encoding: "buffer"
190
267
  };
191
268
  }
269
+ function attachTreeKill(signal, child) {
270
+ if (!signal) return;
271
+ const onAbort = () => killTree(child.pid);
272
+ if (signal.aborted) onAbort();
273
+ else signal.addEventListener("abort", onAbort, { once: true });
274
+ }
192
275
  var WARN_RE = /error|fail|denied|errno|cannot|unable/i;
193
276
  async function* runStream(cmd, args2, opts, percentParser) {
194
277
  const [finalCmd, finalArgs] = withSudo(cmd, args2, opts.sudo);
195
278
  const tailBytes = opts.tailBytes ?? DEFAULT_TAIL_BYTES;
196
279
  const started = Date.now();
197
280
  const child = execa(finalCmd, finalArgs, { ...execaOptions(opts, true), stdout: "pipe", stderr: "pipe" });
281
+ attachTreeKill(opts.signal, child);
198
282
  if (child.all) {
283
+ const decoder = new StreamDecoder();
284
+ let lineBuf = "";
285
+ const emit = function* (raw) {
286
+ const line = raw.replace(/\r$/, "");
287
+ if (!line) return;
288
+ const percent = percentParser?.(line);
289
+ if (percent !== void 0) {
290
+ yield { type: "progress", message: line, percent };
291
+ } else {
292
+ yield { type: "log", message: line, severity: WARN_RE.test(line) ? "warn" : "info" };
293
+ }
294
+ };
199
295
  for await (const chunk of child.all) {
200
- const lines = String(chunk).split("\n").filter(Boolean);
201
- for (const line of lines) {
202
- const percent = percentParser?.(line);
203
- if (percent !== void 0) {
204
- yield { type: "progress", message: line, percent };
205
- } else {
206
- yield { type: "log", message: line, severity: WARN_RE.test(line) ? "warn" : "info" };
207
- }
296
+ lineBuf += decoder.write(chunk);
297
+ let nl;
298
+ while ((nl = lineBuf.indexOf("\n")) >= 0) {
299
+ const raw = lineBuf.slice(0, nl);
300
+ lineBuf = lineBuf.slice(nl + 1);
301
+ yield* emit(raw);
208
302
  }
209
303
  }
304
+ lineBuf += decoder.end();
305
+ if (lineBuf) yield* emit(lineBuf);
210
306
  }
211
307
  const result = await child;
212
308
  return {
@@ -214,8 +310,8 @@ async function* runStream(cmd, args2, opts, percentParser) {
214
310
  exitCode: result.exitCode ?? null,
215
311
  durationMs: Date.now() - started,
216
312
  timedOut: result.timedOut ?? false,
217
- stdoutTail: tail(String(result.stdout ?? ""), tailBytes),
218
- stderrTail: tail(String(result.stderr ?? ""), tailBytes)
313
+ stdoutTail: tail(decodeSmart(result.stdout), tailBytes),
314
+ stderrTail: tail(decodeSmart(result.stderr), tailBytes)
219
315
  };
220
316
  }
221
317
 
@@ -226,18 +322,19 @@ async function execCommand(cmd, args2, timeout = 5e3, sudo = false) {
226
322
  const result = await execa2(finalCmd, finalArgs, {
227
323
  timeout,
228
324
  reject: false,
229
- all: false
325
+ all: false,
326
+ encoding: "buffer"
230
327
  });
231
328
  return {
232
- stdout: result.stdout,
233
- stderr: result.stderr,
329
+ stdout: decodeSmart(result.stdout),
330
+ stderr: decodeSmart(result.stderr),
234
331
  exitCode: result.exitCode ?? (result.failed ? 127 : 0)
235
332
  };
236
333
  } catch (err) {
237
334
  if (err instanceof ExecaError) {
238
335
  return {
239
- stdout: err.stdout ?? "",
240
- stderr: err.stderr ?? String(err.message),
336
+ stdout: decodeSmart(err.stdout),
337
+ stderr: decodeSmart(err.stderr) || String(err.message),
241
338
  exitCode: err.exitCode ?? 1
242
339
  };
243
340
  }
@@ -260,19 +357,26 @@ function classifyCommand(rec, successExitCodes) {
260
357
 
261
358
  // src/lib/result/verify.ts
262
359
  var KIND_PRIORITY = ["NO_PASSWORDLESS_SUDO", "TIMEOUT", "NETWORK", "COMMAND_FAILED"];
263
- function dominantFailureKind(commands) {
264
- const kinds = commands.map((c) => classifyCommand(c)).filter((k) => k !== null);
360
+ function rebootFrom(commands) {
361
+ const codes = new Set(commands.map((c) => c.exitCode));
362
+ if (codes.has(1641)) return "initiated";
363
+ if (codes.has(3010)) return "required";
364
+ if (codes.has(350) || codes.has(1604)) return "deferred";
365
+ return void 0;
366
+ }
367
+ function dominantFailureKind(commands, successExitCodes) {
368
+ const kinds = commands.map((c) => classifyCommand(c, successExitCodes)).filter((k) => k !== null);
265
369
  for (const k of KIND_PRIORITY) {
266
370
  if (kinds.includes(k)) return k;
267
371
  }
268
372
  return kinds[0] ?? null;
269
373
  }
270
- function reconcile(requested, before, after, commands) {
374
+ function reconcile(requested, before, after, commands, successExitCodes) {
271
375
  const beforeByName = new Map(before.map((p) => [p.name, p]));
272
376
  const targetNames = requested ?? before.map((p) => p.name);
273
377
  const targets = [...new Set(targetNames)];
274
378
  const stillOutdated = new Set(after.stillOutdated.map((p) => p.name));
275
- const cmdKind = dominantFailureKind(commands);
379
+ const cmdKind = dominantFailureKind(commands, successExitCodes);
276
380
  const packages = targets.map((name) => {
277
381
  const b = beforeByName.get(name);
278
382
  if (stillOutdated.has(name)) {
@@ -315,6 +419,7 @@ function reconcile(requested, before, after, commands) {
315
419
  status,
316
420
  skipped: 0,
317
421
  reason,
422
+ reboot: rebootFrom(commands),
318
423
  packages,
319
424
  commands
320
425
  };
@@ -328,6 +433,7 @@ import path2 from "path";
328
433
  import fs from "fs";
329
434
  import path from "path";
330
435
  import os from "os";
436
+ import envPaths from "env-paths";
331
437
  var DEFAULTS = {
332
438
  enabledManagers: {},
333
439
  verbosity: "info",
@@ -354,13 +460,33 @@ function normalizeConfig(parsed) {
354
460
  logTailBytes: typeof parsed.logTailBytes === "number" && parsed.logTailBytes > 0 ? Math.round(parsed.logTailBytes) : DEFAULTS.logTailBytes
355
461
  };
356
462
  }
463
+ var APP = "tacuchi-updater";
357
464
  function getConfigDir() {
465
+ if (process.platform === "win32") return envPaths(APP, { suffix: "" }).config;
358
466
  return path.join(os.homedir(), ".tacuchi-updater");
359
467
  }
468
+ function getLogDir() {
469
+ if (process.platform === "win32") return envPaths(APP, { suffix: "" }).log;
470
+ return path.join(getConfigDir(), "logs");
471
+ }
360
472
  function getConfigPath() {
361
473
  return path.join(getConfigDir(), "config.json");
362
474
  }
475
+ function migrateLegacyConfig() {
476
+ if (process.platform !== "win32") return;
477
+ try {
478
+ const target = getConfigPath();
479
+ if (fs.existsSync(target)) return;
480
+ const legacy = path.join(os.homedir(), ".tacuchi-updater", "config.json");
481
+ if (!fs.existsSync(legacy)) return;
482
+ const dir = getConfigDir();
483
+ if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
484
+ fs.copyFileSync(legacy, target);
485
+ } catch {
486
+ }
487
+ }
363
488
  function loadConfig() {
489
+ migrateLegacyConfig();
364
490
  const configPath = getConfigPath();
365
491
  try {
366
492
  if (!fs.existsSync(configPath)) return { ...DEFAULTS };
@@ -376,9 +502,24 @@ function saveConfig(config) {
376
502
  if (!fs.existsSync(dir)) {
377
503
  fs.mkdirSync(dir, { recursive: true });
378
504
  }
379
- const tmp = getConfigPath() + ".tmp";
380
- fs.writeFileSync(tmp, JSON.stringify(config, null, 2), "utf-8");
381
- fs.renameSync(tmp, getConfigPath());
505
+ const target = getConfigPath();
506
+ const tmp = target + ".tmp";
507
+ const data = JSON.stringify(config, null, 2);
508
+ try {
509
+ fs.writeFileSync(tmp, data, "utf-8");
510
+ fs.renameSync(tmp, target);
511
+ } catch (err) {
512
+ const code = err.code;
513
+ if (code === "EPERM" || code === "EBUSY" || code === "EEXIST") {
514
+ fs.writeFileSync(target, data, "utf-8");
515
+ try {
516
+ fs.unlinkSync(tmp);
517
+ } catch {
518
+ }
519
+ } else {
520
+ throw err;
521
+ }
522
+ }
382
523
  }
383
524
  function isManagerEnabled(config, managerId) {
384
525
  if (Object.prototype.hasOwnProperty.call(config.enabledManagers, managerId)) {
@@ -388,10 +529,8 @@ function isManagerEnabled(config, managerId) {
388
529
  }
389
530
 
390
531
  // src/lib/logger.ts
391
- var configLogPath = null;
392
- var localLogPath = null;
393
- var configStream = null;
394
- var localStream = null;
532
+ var logFilePath = null;
533
+ var logStream = null;
395
534
  var inMemoryLog = [];
396
535
  var entryCounter = 0;
397
536
  function createStream(dir, filename) {
@@ -404,35 +543,32 @@ function initLogger() {
404
543
  const now = /* @__PURE__ */ new Date();
405
544
  const stamp = now.toISOString().replace(/[T:]/g, "_").split(".")[0]?.replace(/-/g, "");
406
545
  const filename = `system_updater_${stamp}.log`;
407
- const configLogsDir = path2.join(getConfigDir(), "logs");
408
- const config = createStream(configLogsDir, filename);
409
- configStream = config.stream;
410
- configLogPath = config.filePath;
411
- const localLogsDir = path2.join(process.cwd(), "logs");
412
546
  try {
413
- const local = createStream(localLogsDir, filename);
414
- localStream = local.stream;
415
- localLogPath = local.filePath;
416
- localStream.on("error", () => {
417
- localStream = null;
418
- localLogPath = null;
547
+ const { stream, filePath } = createStream(getLogDir(), filename);
548
+ logStream = stream;
549
+ logFilePath = filePath;
550
+ logStream.on("error", () => {
551
+ logStream = null;
419
552
  });
420
553
  } catch {
554
+ logStream = null;
555
+ logFilePath = null;
421
556
  }
422
557
  writeRaw("INFO", "Logger iniciado \u2014 @tacuchi/updater");
423
- writeRaw("INFO", `Log config: ${configLogPath}`);
424
- if (localLogPath) writeRaw("INFO", `Log local: ${localLogPath}`);
425
- writeRaw("INFO", `PID: ${process.pid} | UID: ${process.getuid?.() ?? "N/A"} | SUDO_USER: ${process.env["SUDO_USER"] ?? "N/A"}`);
558
+ writeRaw("INFO", `Log: ${logFilePath ?? "(no disponible)"}`);
559
+ writeRaw(
560
+ "INFO",
561
+ `PID: ${process.pid} | UID: ${process.getuid?.() ?? "N/A"} | SUDO_USER: ${process.env["SUDO_USER"] ?? "N/A"}`
562
+ );
426
563
  writeRaw("INFO", `Platform: ${process.platform} | Node: ${process.version}`);
427
- return localLogPath ?? configLogPath;
564
+ return logFilePath ?? "";
428
565
  }
429
566
  function writeRaw(level, message) {
430
567
  const now = /* @__PURE__ */ new Date();
431
568
  const timestamp = now.toISOString().replace("T", " ").split(".")[0];
432
569
  const line = `${timestamp} [${level.padEnd(5)}] SystemUpdater - ${message}
433
570
  `;
434
- configStream?.write(line);
435
- localStream?.write(line);
571
+ logStream?.write(line);
436
572
  }
437
573
  function addToMemory(level, message) {
438
574
  const id = String(++entryCounter);
@@ -458,13 +594,14 @@ function logResult(r) {
458
594
  const ok = r.status === "success" || r.status === "noop";
459
595
  const level = ok ? "INFO" : r.status === "partial" ? "WARN" : "ERROR";
460
596
  const reason = r.reason ? ` reason=${r.reason}` : "";
461
- writeRaw(level, `${id}: status=${r.status} upgraded=${r.upgraded} failed=${r.failed}${reason}`);
597
+ const reboot = r.reboot ? ` reboot=${r.reboot}` : "";
598
+ writeRaw(level, `${id}: status=${r.status} upgraded=${r.upgraded} failed=${r.failed}${reason}${reboot}`);
462
599
  for (const e of r.errors) writeRaw(level, ` ${id}: ${e}`);
463
600
  const memLevel = ok ? "info" : r.status === "partial" ? "warn" : "error";
464
601
  addToMemory(memLevel, `${id}: ${r.status} (${r.upgraded} ok, ${r.failed} fail)`);
465
602
  }
466
603
  function getLogFilePath() {
467
- return localLogPath ?? configLogPath;
604
+ return logFilePath;
468
605
  }
469
606
 
470
607
  // src/managers/engine.ts
@@ -578,7 +715,7 @@ function fromDescriptor(d, cfg, deps = defaultDeps) {
578
715
  managerId: d.id,
579
716
  startedAt,
580
717
  finishedAt: Date.now(),
581
- ...reconcile(packages, before, after, commands)
718
+ ...reconcile(packages, before, after, commands, d.successExitCodes)
582
719
  };
583
720
  logResult(result);
584
721
  return result;
@@ -874,6 +1011,8 @@ var softwareupdate = {
874
1011
 
875
1012
  // src/managers/descriptors/winget.ts
876
1013
  var ACCEPT = ["--accept-source-agreements", "--accept-package-agreements"];
1014
+ var UPGRADE_FLAGS = ["--silent", "--disable-interactivity", "--source", "winget", ...ACCEPT];
1015
+ var WINGET_OK_CODES = [0, 2316632107, 2316632143, 2316632107 - 4294967296, 2316632143 - 4294967296];
877
1016
  function parseWingetOutdated(stdout) {
878
1017
  const lines = stdout.split("\n").map((l) => (l.split("\r").pop() ?? l).replace(/[⠀-⣿]/g, "").replace(/\s+$/, ""));
879
1018
  const dashIdx = lines.findIndex((l) => l.trim().length >= 3 && /^-+$/.test(l.trim()));
@@ -896,7 +1035,11 @@ function parseWingetOutdated(stdout) {
896
1035
  return out;
897
1036
  }
898
1037
  async function listWinget() {
899
- const res = await execCommand("winget", ["list", "--upgrade-available", "--accept-source-agreements"], 6e4);
1038
+ const res = await execCommand(
1039
+ "winget",
1040
+ ["list", "--upgrade-available", "--include-unknown", "--accept-source-agreements"],
1041
+ 6e4
1042
+ );
900
1043
  return parseWingetOutdated(res.stdout);
901
1044
  }
902
1045
  var winget = {
@@ -907,7 +1050,10 @@ var winget = {
907
1050
  kind: "direct",
908
1051
  detectCmd: { cmd: "winget", args: ["--version"], timeout: 3e3 },
909
1052
  parseVersion: (stdout) => stdout.trim() || void 0,
910
- listOutdatedCmd: () => ({ cmd: "winget", args: ["list", "--upgrade-available", "--accept-source-agreements"] }),
1053
+ listOutdatedCmd: () => ({
1054
+ cmd: "winget",
1055
+ args: ["list", "--upgrade-available", "--include-unknown", "--accept-source-agreements"]
1056
+ }),
911
1057
  parseOutdated: (stdout) => parseWingetOutdated(stdout),
912
1058
  // Escape hatch: winget upgrades ONE package per invocation (no multi-target),
913
1059
  // so a single bulk `--id A --id B` silently fails. Loop one `winget upgrade
@@ -926,13 +1072,13 @@ var winget = {
926
1072
  logCommand(rec);
927
1073
  };
928
1074
  if (!targets.length) {
929
- yield* run(["upgrade", "--all", ...ACCEPT]);
1075
+ yield* run(["upgrade", "--all", "--include-unknown", "--include-pinned", ...UPGRADE_FLAGS]);
930
1076
  } else {
931
- for (const id of targets) yield* run(["upgrade", "--exact", "--id", id, ...ACCEPT]);
1077
+ for (const id of targets) yield* run(["upgrade", "--exact", "--id", id, "--include-unknown", ...UPGRADE_FLAGS]);
932
1078
  }
933
1079
  yield { type: "phase", phase: "verifying", message: "Verificando resultado..." };
934
1080
  const after = await listWinget();
935
- return reconcile(packages, before, { stillOutdated: after.map((p) => ({ name: p.name })) }, commands);
1081
+ return reconcile(packages, before, { stillOutdated: after.map((p) => ({ name: p.name })) }, commands, WINGET_OK_CODES);
936
1082
  }
937
1083
  }
938
1084
  };
@@ -1415,6 +1561,10 @@ var choco = {
1415
1561
  platforms: ["win32"],
1416
1562
  requiresAdmin: true,
1417
1563
  kind: "direct",
1564
+ // Chocolatey "success" is not just 0: 1641 = reboot initiated, 3010 = reboot
1565
+ // required, 1605/1614 = already-(un)installed. Without these, a reboot-pending
1566
+ // upgrade would be misclassified as COMMAND_FAILED.
1567
+ successExitCodes: [0, 1605, 1614, 1641, 3010],
1418
1568
  detectCmd: { cmd: "choco", args: ["--version"], timeout: 3e3 },
1419
1569
  parseVersion: (stdout) => stdout.trim() || void 0,
1420
1570
  listOutdatedCmd: () => ({ cmd: "choco", args: ["outdated", "--limit-output"] }),
@@ -1901,20 +2051,20 @@ var scoop = {
1901
2051
  platforms: ["win32"],
1902
2052
  requiresAdmin: false,
1903
2053
  kind: "direct",
1904
- detectCmd: { cmd: "scoop", args: ["--version"], timeout: 3e3 },
2054
+ detectCmd: { cmd: "scoop.cmd", args: ["--version"], timeout: 3e3 },
1905
2055
  parseVersion: (stdout) => {
1906
2056
  const m = stdout.match(/v?\d+\.\d+(?:\.\d+)?/);
1907
2057
  return m?.[0];
1908
2058
  },
1909
- listOutdatedCmd: () => ({ cmd: "scoop", args: ["status"] }),
2059
+ listOutdatedCmd: () => ({ cmd: "scoop.cmd", args: ["status"] }),
1910
2060
  parseOutdated: (stdout) => parseScoopOutdated(stdout),
1911
2061
  // `scoop update` (no app) refreshes scoop itself + all buckets so the
1912
2062
  // following `scoop update *` / `scoop update <names>` sees the latest
1913
2063
  // manifests.
1914
- preUpgradeCmds: () => [{ cmd: "scoop", args: ["update"] }],
2064
+ preUpgradeCmds: () => [{ cmd: "scoop.cmd", args: ["update"] }],
1915
2065
  // Single bulk command: `scoop update *` upgrades every app, otherwise one
1916
2066
  // invocation carrying every selected app name.
1917
- upgradeCmd: (pkgs) => pkgs && pkgs.length ? { cmd: "scoop", args: ["update", ...pkgs] } : { cmd: "scoop", args: ["update", "*"] },
2067
+ upgradeCmd: (pkgs) => pkgs && pkgs.length ? { cmd: "scoop.cmd", args: ["update", ...pkgs] } : { cmd: "scoop.cmd", args: ["update", "*"] },
1918
2068
  manualCommand: () => "scoop update *"
1919
2069
  };
1920
2070
 
@@ -2533,8 +2683,9 @@ var en = {
2533
2683
  // src/i18n/index.ts
2534
2684
  var currentLang = detectLanguage();
2535
2685
  function detectLanguage() {
2536
- const lang = process.env["LANG"] ?? process.env["LANGUAGE"] ?? "";
2537
- return lang.startsWith("es") ? "es" : "es";
2686
+ const lang = (process.env["LANG"] ?? process.env["LANGUAGE"] ?? "").toLowerCase();
2687
+ if (lang.startsWith("en")) return "en";
2688
+ return "es";
2538
2689
  }
2539
2690
  function setLanguage(lang) {
2540
2691
  currentLang = lang;
@@ -2552,6 +2703,61 @@ function managerName(id) {
2552
2703
  return names[id] ?? id;
2553
2704
  }
2554
2705
 
2706
+ // src/hooks/use-app-machine.tsx
2707
+ import { writeFileSync, mkdirSync } from "fs";
2708
+ import { dirname } from "path";
2709
+
2710
+ // src/lib/elevation.ts
2711
+ import path3 from "path";
2712
+ import { execa as execa3 } from "execa";
2713
+ import isAdmin from "is-admin";
2714
+ async function isElevated() {
2715
+ if (process.platform === "win32") {
2716
+ try {
2717
+ return await isAdmin();
2718
+ } catch {
2719
+ return false;
2720
+ }
2721
+ }
2722
+ return process.getuid?.() === 0;
2723
+ }
2724
+ function elevatedSummaryPath() {
2725
+ const base = process.env["LOCALAPPDATA"] ?? process.env["TEMP"] ?? process.cwd();
2726
+ return path3.join(base, "tacuchi-updater", "last-run-summary.json");
2727
+ }
2728
+ var psQuote = (s) => `'${s.replace(/'/g, "''")}'`;
2729
+ async function relaunchElevated(extraArgs = []) {
2730
+ if (process.platform !== "win32") return false;
2731
+ const node = process.execPath;
2732
+ const script = process.argv[1] ?? "";
2733
+ const args2 = [script, ...process.argv.slice(2), ...extraArgs];
2734
+ const argList = args2.map(psQuote).join(",");
2735
+ const command = `Start-Process -FilePath ${psQuote(node)} -ArgumentList @(${argList}) -Verb RunAs`;
2736
+ try {
2737
+ const res = await execa3("powershell.exe", ["-NoProfile", "-ExecutionPolicy", "Bypass", "-Command", command], {
2738
+ reject: false
2739
+ });
2740
+ return (res.exitCode ?? 1) === 0;
2741
+ } catch {
2742
+ return false;
2743
+ }
2744
+ }
2745
+
2746
+ // src/lib/cancellation.ts
2747
+ var handlers = /* @__PURE__ */ new Set();
2748
+ function onProcessCancel(handler) {
2749
+ handlers.add(handler);
2750
+ return () => handlers.delete(handler);
2751
+ }
2752
+ function fireProcessCancel() {
2753
+ for (const handler of handlers) {
2754
+ try {
2755
+ handler();
2756
+ } catch {
2757
+ }
2758
+ }
2759
+ }
2760
+
2555
2761
  // src/hooks/use-app-machine.tsx
2556
2762
  import { jsx } from "react/jsx-runtime";
2557
2763
  function toManagerResult(r, logRef) {
@@ -2565,16 +2771,38 @@ function toManagerResult(r, logRef) {
2565
2771
  failed: r.failed,
2566
2772
  skipped: r.skipped ?? 0,
2567
2773
  failures,
2568
- manualCommand: r.manualCommand
2774
+ manualCommand: r.manualCommand,
2775
+ reboot: r.reboot
2569
2776
  };
2570
2777
  }
2778
+ function summarizeRun(state) {
2779
+ let upgraded = 0;
2780
+ let failed = 0;
2781
+ let skipped = 0;
2782
+ const managers = [];
2783
+ for (const id of state.run.queue) {
2784
+ const e = state.managers[id];
2785
+ if (!e) continue;
2786
+ if (e.status === "skipped") {
2787
+ skipped++;
2788
+ managers.push({ id, status: "skipped", upgraded: 0, failed: 0 });
2789
+ continue;
2790
+ }
2791
+ const u = e.result?.upgraded ?? 0;
2792
+ const f = e.result?.failed ?? 0;
2793
+ upgraded += u;
2794
+ failed += f;
2795
+ managers.push({ id, status: e.status, upgraded: u, failed: f });
2796
+ }
2797
+ return { upgraded, failed, skipped, managers };
2798
+ }
2571
2799
  var MachineContext = createContext(null);
2572
2800
  function useMachine() {
2573
2801
  const ctx = useContext(MachineContext);
2574
2802
  if (!ctx) throw new Error("useMachine must be used inside <MachineProvider>");
2575
2803
  return ctx;
2576
2804
  }
2577
- function useAppMachine(sudoMode2) {
2805
+ function useAppMachine(sudoMode2, nonInteractive2 = false) {
2578
2806
  const configRef = useRef(loadConfig());
2579
2807
  const [state, dispatch] = useReducer(
2580
2808
  appReducer,
@@ -2624,6 +2852,7 @@ function useAppMachine(sudoMode2) {
2624
2852
  setLanguage(configRef.current.language);
2625
2853
  void boot();
2626
2854
  }, [boot]);
2855
+ useEffect(() => onProcessCancel(() => abortRef.current?.abort()), []);
2627
2856
  const startRun = useCallback(() => {
2628
2857
  const config = configRef.current;
2629
2858
  const packagesByManager = /* @__PURE__ */ new Map();
@@ -2696,6 +2925,65 @@ function useAppMachine(sudoMode2) {
2696
2925
  dispatch({ type: "RESCAN" });
2697
2926
  void boot();
2698
2927
  }, [boot]);
2928
+ const { exit } = useApp();
2929
+ const exitedRef = useRef(false);
2930
+ const finishNonInteractive = useCallback(
2931
+ (code) => {
2932
+ if (exitedRef.current) return;
2933
+ exitedRef.current = true;
2934
+ process.exitCode = code;
2935
+ exit();
2936
+ if (!process.env["VITEST"]) {
2937
+ const t3 = setTimeout(() => process.exit(code), 100);
2938
+ t3.unref?.();
2939
+ }
2940
+ },
2941
+ [exit]
2942
+ );
2943
+ useEffect(() => {
2944
+ if (!nonInteractive2) return;
2945
+ if (state.phase === "select") {
2946
+ const hasOutdated = state.order.some((id) => (state.managers[id]?.outdated.length ?? 0) > 0);
2947
+ if (!hasOutdated) finishNonInteractive(0);
2948
+ else if (state.selection.size === 0) dispatch({ type: "SELECT_ALL" });
2949
+ else dispatch({ type: "GOTO_CONFIRM" });
2950
+ } else if (state.phase === "confirm") {
2951
+ startRun();
2952
+ } else if (state.phase === "summary") {
2953
+ finishNonInteractive(state.run.failedCount > 0 ? 1 : 0);
2954
+ }
2955
+ }, [
2956
+ nonInteractive2,
2957
+ state.phase,
2958
+ state.selection.size,
2959
+ state.run.failedCount,
2960
+ state.order,
2961
+ state.managers,
2962
+ startRun,
2963
+ finishNonInteractive
2964
+ ]);
2965
+ useEffect(() => {
2966
+ if (state.phase !== "summary" || process.platform !== "win32") return;
2967
+ try {
2968
+ const p = elevatedSummaryPath();
2969
+ mkdirSync(dirname(p), { recursive: true });
2970
+ writeFileSync(p, JSON.stringify({ ...summarizeRun(state), at: Date.now() }, null, 2), "utf-8");
2971
+ } catch {
2972
+ }
2973
+ }, [state.phase]);
2974
+ const relaunch = useCallback(() => {
2975
+ void (async () => {
2976
+ const ok = await relaunchElevated();
2977
+ if (ok) {
2978
+ process.exitCode = 0;
2979
+ exit();
2980
+ if (!process.env["VITEST"]) {
2981
+ const t3 = setTimeout(() => process.exit(0), 100);
2982
+ t3.unref?.();
2983
+ }
2984
+ }
2985
+ })();
2986
+ }, [exit]);
2699
2987
  const persist = useCallback((next) => {
2700
2988
  dispatch(next);
2701
2989
  }, []);
@@ -2722,6 +3010,7 @@ function useAppMachine(sudoMode2) {
2722
3010
  goSelect: useCallback(() => persist({ type: "GOTO_SELECT" }), [persist]),
2723
3011
  startRun,
2724
3012
  cancelRun,
3013
+ relaunch,
2725
3014
  rescan,
2726
3015
  openSettings: useCallback(() => persist({ type: "OPEN_SETTINGS" }), [persist]),
2727
3016
  closeSettings: useCallback(() => persist({ type: "CLOSE_SETTINGS" }), [persist]),
@@ -2733,6 +3022,14 @@ function MachineProvider({ value, children }) {
2733
3022
  return /* @__PURE__ */ jsx(MachineContext.Provider, { value, children });
2734
3023
  }
2735
3024
 
3025
+ // src/hooks/use-safe-input.ts
3026
+ import { useInput, useStdin } from "ink";
3027
+ function useSafeInput(handler, options) {
3028
+ const { isRawModeSupported } = useStdin();
3029
+ const active = (options?.isActive ?? true) && isRawModeSupported;
3030
+ useInput(handler, { ...options, isActive: active });
3031
+ }
3032
+
2736
3033
  // src/screens/detect.tsx
2737
3034
  import { Box as Box2, Text as Text3 } from "ink";
2738
3035
 
@@ -2788,6 +3085,61 @@ var semantic = {
2788
3085
  muted: colors.onSurfaceVariant
2789
3086
  };
2790
3087
 
3088
+ // src/lib/glyphs.ts
3089
+ function shouldUseAscii(env, platform) {
3090
+ if (env["TACUCHI_ASCII"] === "1") return true;
3091
+ if (env["TACUCHI_ASCII"] === "0") return false;
3092
+ if (env["TERM"] === "dumb") return true;
3093
+ if (platform === "win32" && !env["WT_SESSION"]) return true;
3094
+ return false;
3095
+ }
3096
+ var UNICODE = {
3097
+ pending: "\xB7",
3098
+ scanning: "\u25CC",
3099
+ outdated: "\u203A",
3100
+ uptodate: "\u2713",
3101
+ running: "\u25B8",
3102
+ done: "\u2713",
3103
+ failed: "\u2717",
3104
+ skipped: "\u2298",
3105
+ cursor: "\u276F",
3106
+ checkOn: "[\u2713]",
3107
+ checkOff: "[ ]",
3108
+ arrow: "\u2192",
3109
+ scrollUp: "\u25B2",
3110
+ scrollDown: "\u25BC",
3111
+ stepOn: "\u2586",
3112
+ stepOff: "\u2581",
3113
+ info: "\u24D8",
3114
+ ellipsis: "\u2026",
3115
+ bullet: "\u25B8",
3116
+ reboot: "\u27F3"
3117
+ };
3118
+ var ASCII_GLYPHS = {
3119
+ pending: ".",
3120
+ scanning: "o",
3121
+ outdated: ">",
3122
+ uptodate: "+",
3123
+ running: ">",
3124
+ done: "+",
3125
+ failed: "x",
3126
+ skipped: "-",
3127
+ cursor: ">",
3128
+ checkOn: "[x]",
3129
+ checkOff: "[ ]",
3130
+ arrow: "->",
3131
+ scrollUp: "^",
3132
+ scrollDown: "v",
3133
+ stepOn: "#",
3134
+ stepOff: "_",
3135
+ info: "i",
3136
+ ellipsis: "...",
3137
+ bullet: ">",
3138
+ reboot: "*"
3139
+ };
3140
+ var ASCII = shouldUseAscii(process.env, process.platform);
3141
+ var g = ASCII ? ASCII_GLYPHS : UNICODE;
3142
+
2791
3143
  // src/components/step-header.tsx
2792
3144
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2793
3145
  var STEP = {
@@ -2800,13 +3152,15 @@ var STEP = {
2800
3152
  function StepHeader({ phase }) {
2801
3153
  if (phase === "summary") {
2802
3154
  return /* @__PURE__ */ jsx2(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: semantic.success, bold: true, children: [
2803
- "\u2586 ",
3155
+ g.stepOn,
3156
+ " ",
2804
3157
  t("flow", "summary")
2805
3158
  ] }) });
2806
3159
  }
2807
3160
  if (phase === "settings") {
2808
3161
  return /* @__PURE__ */ jsx2(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: semantic.action, bold: true, children: [
2809
- "\u2586 ",
3162
+ g.stepOn,
3163
+ " ",
2810
3164
  t("flow", "settings")
2811
3165
  ] }) });
2812
3166
  }
@@ -2814,7 +3168,7 @@ function StepHeader({ phase }) {
2814
3168
  if (!step) return null;
2815
3169
  return /* @__PURE__ */ jsxs(Box, { marginBottom: 1, children: [
2816
3170
  [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsxs(Text, { color: i === step.n ? semantic.action : semantic.muted, bold: i === step.n, children: [
2817
- i === step.n ? "\u2586" : "\u2581",
3171
+ i === step.n ? g.stepOn : g.stepOff,
2818
3172
  " "
2819
3173
  ] }, i)),
2820
3174
  /* @__PURE__ */ jsxs(Text, { color: semantic.muted, children: [
@@ -2833,15 +3187,15 @@ function StepHeader({ phase }) {
2833
3187
  import { Text as Text2 } from "ink";
2834
3188
  import { jsx as jsx3 } from "react/jsx-runtime";
2835
3189
  var SPECS = {
2836
- pending: { glyph: "\xB7", color: semantic.muted },
2837
- scanning: { glyph: "\u25CC", color: semantic.action },
2838
- outdated: { glyph: "\u203A", color: semantic.warning },
2839
- uptodate: { glyph: "\u2713", color: semantic.muted },
2840
- queued: { glyph: "\xB7", color: semantic.muted },
2841
- running: { glyph: "\u25B8", color: semantic.action },
2842
- done: { glyph: "\u2713", color: semantic.success },
2843
- failed: { glyph: "\u2717", color: semantic.error },
2844
- skipped: { glyph: "\u2298", color: semantic.warning }
3190
+ pending: { glyph: g.pending, color: semantic.muted },
3191
+ scanning: { glyph: g.scanning, color: semantic.action },
3192
+ outdated: { glyph: g.outdated, color: semantic.warning },
3193
+ uptodate: { glyph: g.uptodate, color: semantic.muted },
3194
+ queued: { glyph: g.pending, color: semantic.muted },
3195
+ running: { glyph: g.running, color: semantic.action },
3196
+ done: { glyph: g.done, color: semantic.success },
3197
+ failed: { glyph: g.failed, color: semantic.error },
3198
+ skipped: { glyph: g.skipped, color: semantic.warning }
2845
3199
  };
2846
3200
  function statusColor(status) {
2847
3201
  return SPECS[status].color;
@@ -2881,8 +3235,9 @@ function DetectScreen() {
2881
3235
  /* @__PURE__ */ jsx4(Box2, { width: 18, children: /* @__PURE__ */ jsx4(Text3, { color: e.status === "outdated" ? semantic.text : semantic.muted, children: managerName(id) }) }),
2882
3236
  e.status === "outdated" ? /* @__PURE__ */ jsxs2(Text3, { color: semantic.warning, children: [
2883
3237
  e.outdated.length,
2884
- " \u203A"
2885
- ] }) : e.status === "uptodate" ? /* @__PURE__ */ jsx4(Text3, { color: colors.outline, children: "\u2014" }) : /* @__PURE__ */ jsx4(Text3, { color: semantic.muted, children: "\u2026" })
3238
+ " ",
3239
+ g.outdated
3240
+ ] }) : e.status === "uptodate" ? /* @__PURE__ */ jsx4(Text3, { color: colors.outline, children: "-" }) : /* @__PURE__ */ jsx4(Text3, { color: semantic.muted, children: g.ellipsis })
2886
3241
  ] }, id);
2887
3242
  })
2888
3243
  ] });
@@ -2890,10 +3245,10 @@ function DetectScreen() {
2890
3245
 
2891
3246
  // src/screens/select.tsx
2892
3247
  import { useState } from "react";
2893
- import { Box as Box3, Text as Text4, useInput } from "ink";
3248
+ import { Box as Box3, Text as Text4 } from "ink";
2894
3249
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
2895
3250
  function clip(s, n) {
2896
- return s.length > n ? s.slice(0, n - 1) + "\u2026" : s;
3251
+ return s.length > n ? s.slice(0, Math.max(0, n - g.ellipsis.length)) + g.ellipsis : s;
2897
3252
  }
2898
3253
  function SelectScreen() {
2899
3254
  const { state, toggleItem, selectAll, selectNone, goConfirm, openSettings } = useMachine();
@@ -2904,7 +3259,7 @@ function SelectScreen() {
2904
3259
  if (m && m.status === "outdated") for (const pkg of m.outdated) rows.push({ managerId: id, pkg });
2905
3260
  }
2906
3261
  const clamped = Math.min(cursor, Math.max(0, rows.length - 1));
2907
- useInput((input, key) => {
3262
+ useSafeInput((input, key) => {
2908
3263
  if (key.downArrow || input === "j") setCursor((c) => Math.min(rows.length - 1, c + 1));
2909
3264
  else if (key.upArrow || input === "k") setCursor((c) => Math.max(0, c - 1));
2910
3265
  else if (input === " ") {
@@ -2949,9 +3304,9 @@ function SelectScreen() {
2949
3304
  ] })
2950
3305
  ] }),
2951
3306
  start > 0 && /* @__PURE__ */ jsxs3(Text4, { color: colors.outline, children: [
2952
- "\u25B2 ",
2953
- start,
2954
- " \u2191"
3307
+ g.scrollUp,
3308
+ " ",
3309
+ start
2955
3310
  ] }),
2956
3311
  visible.map((r) => {
2957
3312
  const header = r.managerId !== prevManager ? managerName(r.managerId) : null;
@@ -2961,13 +3316,13 @@ function SelectScreen() {
2961
3316
  return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", children: [
2962
3317
  header && /* @__PURE__ */ jsx5(Text4, { color: semantic.muted, bold: true, children: header }),
2963
3318
  /* @__PURE__ */ jsxs3(Box3, { children: [
2964
- /* @__PURE__ */ jsx5(Text4, { color: isCursor ? semantic.action : colors.outline, children: isCursor ? "\u276F " : " " }),
2965
- /* @__PURE__ */ jsx5(Text4, { color: selected ? semantic.success : colors.outline, children: selected ? "[\u2713] " : "[ ] " }),
3319
+ /* @__PURE__ */ jsx5(Text4, { color: isCursor ? semantic.action : colors.outline, children: isCursor ? `${g.cursor} ` : " " }),
3320
+ /* @__PURE__ */ jsx5(Text4, { color: selected ? semantic.success : colors.outline, children: selected ? `${g.checkOn} ` : `${g.checkOff} ` }),
2966
3321
  /* @__PURE__ */ jsx5(Box3, { width: 22, children: /* @__PURE__ */ jsx5(Text4, { color: semantic.text, bold: isCursor, children: clip(r.pkg.name, 21) }) }),
2967
3322
  /* @__PURE__ */ jsxs3(Text4, { color: semantic.muted, wrap: "truncate-end", children: [
2968
3323
  clip(r.pkg.currentVersion, 14),
2969
3324
  " ",
2970
- /* @__PURE__ */ jsx5(Text4, { color: semantic.action, children: "\u2192" }),
3325
+ /* @__PURE__ */ jsx5(Text4, { color: semantic.action, children: g.arrow }),
2971
3326
  " ",
2972
3327
  clip(r.pkg.newVersion, 14)
2973
3328
  ] })
@@ -2975,26 +3330,28 @@ function SelectScreen() {
2975
3330
  ] }, `${r.managerId}:${r.pkg.name}`);
2976
3331
  }),
2977
3332
  end < rows.length && /* @__PURE__ */ jsxs3(Text4, { color: colors.outline, children: [
2978
- "\u25BC ",
2979
- rows.length - end,
2980
- " \u2193"
3333
+ g.scrollDown,
3334
+ " ",
3335
+ rows.length - end
2981
3336
  ] }),
2982
3337
  /* @__PURE__ */ jsx5(Box3, { marginTop: 1, children: /* @__PURE__ */ jsx5(Text4, { color: semantic.muted, children: clip(t("ui", "selectHint"), width) }) })
2983
3338
  ] });
2984
3339
  }
2985
3340
 
2986
3341
  // src/screens/confirm.tsx
2987
- import { Box as Box4, Text as Text5, useInput as useInput2 } from "ink";
3342
+ import { Box as Box4, Text as Text5 } from "ink";
2988
3343
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
2989
3344
  function ConfirmScreen() {
2990
- const { state, startRun, goSelect, sudoMode: sudoMode2 } = useMachine();
3345
+ const { state, startRun, goSelect, sudoMode: sudoMode2, relaunch } = useMachine();
2991
3346
  const byManager = /* @__PURE__ */ new Map();
2992
3347
  for (const key of state.selection) {
2993
3348
  const [id] = parseSelectionKey(key);
2994
3349
  byManager.set(id, (byManager.get(id) ?? 0) + 1);
2995
3350
  }
2996
- useInput2((input, key) => {
2997
- if (key.return || input === "y" || input === "Y") startRun();
3351
+ const needsElevation = process.platform === "win32" && !sudoMode2 && [...byManager.keys()].some((id) => state.managers[id]?.requiresAdmin);
3352
+ useSafeInput((input, key) => {
3353
+ if ((input === "e" || input === "E") && needsElevation) relaunch();
3354
+ else if (key.return || input === "y" || input === "Y") startRun();
2998
3355
  else if (key.escape) goSelect();
2999
3356
  });
3000
3357
  return /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", children: [
@@ -3004,24 +3361,28 @@ function ConfirmScreen() {
3004
3361
  const m = state.managers[id];
3005
3362
  const willSkip = m?.requiresAdmin && !sudoMode2;
3006
3363
  return /* @__PURE__ */ jsxs4(Box4, { children: [
3007
- /* @__PURE__ */ jsx6(Text5, { color: semantic.action, children: "\u25B8 " }),
3364
+ /* @__PURE__ */ jsxs4(Text5, { color: semantic.action, children: [
3365
+ g.bullet,
3366
+ " "
3367
+ ] }),
3008
3368
  /* @__PURE__ */ jsx6(Box4, { width: 20, children: /* @__PURE__ */ jsx6(Text5, { color: semantic.text, bold: true, children: managerName(id) }) }),
3009
3369
  /* @__PURE__ */ jsxs4(Text5, { color: semantic.muted, children: [
3010
3370
  count,
3011
3371
  " paquete(s)"
3012
3372
  ] }),
3013
- willSkip && /* @__PURE__ */ jsx6(Text5, { color: semantic.warning, children: " \xB7 requiere sudo \u2192 manual" })
3373
+ willSkip && /* @__PURE__ */ jsx6(Text5, { color: semantic.warning, children: process.platform === "win32" ? " \xB7 requiere admin \u2192 manual" : " \xB7 requiere sudo \u2192 manual" })
3014
3374
  ] }, id);
3015
3375
  }) }),
3016
- /* @__PURE__ */ jsx6(Text5, { color: semantic.muted, children: t("ui", "confirmHint") })
3376
+ /* @__PURE__ */ jsx6(Text5, { color: semantic.muted, children: t("ui", "confirmHint") }),
3377
+ needsElevation && /* @__PURE__ */ jsx6(Text5, { color: semantic.warning, children: "E \xB7 relanzar como Administrador (1 UAC) para los gestores que lo requieren" })
3017
3378
  ] });
3018
3379
  }
3019
3380
 
3020
3381
  // src/screens/update.tsx
3021
- import { Box as Box5, Text as Text6, useInput as useInput3 } from "ink";
3382
+ import { Box as Box5, Text as Text6 } from "ink";
3022
3383
  import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
3023
3384
  function clip2(s, n) {
3024
- return s.length > n ? s.slice(0, Math.max(0, n - 1)) + "\u2026" : s;
3385
+ return s.length > n ? s.slice(0, Math.max(0, n - g.ellipsis.length)) + g.ellipsis : s;
3025
3386
  }
3026
3387
  function Row({ e, width }) {
3027
3388
  let detail = "";
@@ -3037,7 +3398,7 @@ function Row({ e, width }) {
3037
3398
  }
3038
3399
  function UpdateScreen() {
3039
3400
  const { state, cancelRun } = useMachine();
3040
- useInput3((_input, key) => {
3401
+ useSafeInput((_input, key) => {
3041
3402
  if (key.escape) cancelRun();
3042
3403
  });
3043
3404
  const total = state.run.queue.length;
@@ -3053,17 +3414,20 @@ function UpdateScreen() {
3053
3414
  " "
3054
3415
  ] }),
3055
3416
  /* @__PURE__ */ jsxs5(Text6, { color: semantic.success, children: [
3056
- "\u2713 ",
3417
+ g.done,
3418
+ " ",
3057
3419
  state.run.doneCount,
3058
3420
  " "
3059
3421
  ] }),
3060
3422
  /* @__PURE__ */ jsxs5(Text6, { color: semantic.error, children: [
3061
- "\u2717 ",
3423
+ g.failed,
3424
+ " ",
3062
3425
  state.run.failedCount,
3063
3426
  " "
3064
3427
  ] }),
3065
3428
  /* @__PURE__ */ jsxs5(Text6, { color: semantic.warning, children: [
3066
- "\u2298 ",
3429
+ g.skipped,
3430
+ " ",
3067
3431
  state.run.skippedCount
3068
3432
  ] })
3069
3433
  ] }),
@@ -3079,11 +3443,11 @@ function UpdateScreen() {
3079
3443
  }
3080
3444
 
3081
3445
  // src/screens/summary.tsx
3082
- import { Box as Box6, Text as Text7, useInput as useInput4 } from "ink";
3446
+ import { Box as Box6, Text as Text7 } from "ink";
3083
3447
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
3084
3448
  function SummaryScreen() {
3085
3449
  const { state, rescan } = useMachine();
3086
- useInput4((input) => {
3450
+ useSafeInput((input) => {
3087
3451
  if (input === "r" || input === "R") rescan();
3088
3452
  });
3089
3453
  let upgraded = 0;
@@ -3091,6 +3455,7 @@ function SummaryScreen() {
3091
3455
  let skipped = 0;
3092
3456
  const failures = [];
3093
3457
  const manuals = [];
3458
+ const reboots = [];
3094
3459
  for (const id of state.run.queue) {
3095
3460
  const e = state.managers[id];
3096
3461
  if (!e) continue;
@@ -3104,12 +3469,13 @@ function SummaryScreen() {
3104
3469
  upgraded += r.upgraded;
3105
3470
  failed += r.failed;
3106
3471
  for (const f of r.failures) failures.push({ manager: id, package: f.package, message: f.message, kind: f.kind });
3472
+ if (r.reboot) reboots.push({ manager: id, state: r.reboot });
3107
3473
  }
3108
3474
  }
3109
3475
  const hasErrors = failed > 0;
3110
3476
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
3111
3477
  /* @__PURE__ */ jsx8(StepHeader, { phase: state.phase }),
3112
- /* @__PURE__ */ jsx8(Box6, { marginBottom: 1, children: /* @__PURE__ */ jsx8(Text7, { color: hasErrors ? semantic.error : semantic.success, bold: true, children: hasErrors ? `\u2717 ${t("ui", "withErrors")}` : `\u2713 ${t("ui", "allDone")}` }) }),
3478
+ /* @__PURE__ */ jsx8(Box6, { marginBottom: 1, children: /* @__PURE__ */ jsx8(Text7, { color: hasErrors ? semantic.error : semantic.success, bold: true, children: hasErrors ? `${g.failed} ${t("ui", "withErrors")}` : `${g.done} ${t("ui", "allDone")}` }) }),
3113
3479
  /* @__PURE__ */ jsxs6(Box6, { marginBottom: 1, children: [
3114
3480
  /* @__PURE__ */ jsxs6(Text7, { color: semantic.success, children: [
3115
3481
  upgraded,
@@ -3131,7 +3497,8 @@ function SummaryScreen() {
3131
3497
  ] }),
3132
3498
  failures.length > 0 && /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginBottom: 1, children: [
3133
3499
  failures.slice(0, 8).map((f, i) => /* @__PURE__ */ jsxs6(Text7, { color: semantic.error, wrap: "truncate-end", children: [
3134
- "\u2717 ",
3500
+ g.failed,
3501
+ " ",
3135
3502
  managerName(f.manager),
3136
3503
  f.package ? /* @__PURE__ */ jsxs6(Text7, { color: semantic.text, children: [
3137
3504
  " ",
@@ -3142,7 +3509,10 @@ function SummaryScreen() {
3142
3509
  f.kind
3143
3510
  ] }) : null
3144
3511
  ] }, i)),
3145
- failures.some((f) => f.kind === "TIMEOUT") && /* @__PURE__ */ jsx8(Text7, { color: semantic.warning, children: "\u24D8 Un TIMEOUT suele indicar un paquete que pide interacci\xF3n (ej. un cask que requiere cerrar la app o sudo). Actual\xEDzalo manualmente en una terminal." })
3512
+ failures.some((f) => f.kind === "TIMEOUT") && /* @__PURE__ */ jsxs6(Text7, { color: semantic.warning, children: [
3513
+ g.info,
3514
+ " Un TIMEOUT suele indicar un paquete que pide interacci\xF3n (ej. un cask que requiere cerrar la app o sudo). Actual\xEDzalo manualmente en una terminal."
3515
+ ] })
3146
3516
  ] }),
3147
3517
  manuals.length > 0 && /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginBottom: 1, children: [
3148
3518
  /* @__PURE__ */ jsx8(Text7, { color: semantic.warning, children: t("ui", "manualNeeded") }),
@@ -3153,6 +3523,11 @@ function SummaryScreen() {
3153
3523
  /* @__PURE__ */ jsx8(Text7, { color: semantic.text, children: m.command })
3154
3524
  ] }, i))
3155
3525
  ] }),
3526
+ reboots.length > 0 && /* @__PURE__ */ jsx8(Box6, { marginBottom: 1, children: /* @__PURE__ */ jsxs6(Text7, { color: semantic.warning, children: [
3527
+ g.reboot,
3528
+ " Reinicio pendiente: ",
3529
+ reboots.map((r) => `${managerName(r.manager)} (${r.state})`).join(", ")
3530
+ ] }) }),
3156
3531
  hasErrors && /* @__PURE__ */ jsxs6(Text7, { color: semantic.muted, children: [
3157
3532
  t("ui", "logAt"),
3158
3533
  " ",
@@ -3164,14 +3539,14 @@ function SummaryScreen() {
3164
3539
 
3165
3540
  // src/screens/settings-screen.tsx
3166
3541
  import { useState as useState2 } from "react";
3167
- import { Box as Box7, Text as Text8, useInput as useInput5 } from "ink";
3542
+ import { Box as Box7, Text as Text8 } from "ink";
3168
3543
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
3169
3544
  function SettingsScreen() {
3170
3545
  const { state, toggleEnabled, setLang, closeSettings } = useMachine();
3171
3546
  const ids = state.order;
3172
3547
  const [cursor, setCursor] = useState2(0);
3173
3548
  const clamped = Math.min(cursor, Math.max(0, ids.length - 1));
3174
- useInput5((input, key) => {
3549
+ useSafeInput((input, key) => {
3175
3550
  if (key.escape) closeSettings();
3176
3551
  else if (key.downArrow || input === "j") setCursor((c) => Math.min(ids.length - 1, c + 1));
3177
3552
  else if (key.upArrow || input === "k") setCursor((c) => Math.max(0, c - 1));
@@ -3193,7 +3568,7 @@ function SettingsScreen() {
3193
3568
  const enabled = isManagerEnabled(state.config, id);
3194
3569
  const isCursor = i === clamped;
3195
3570
  return /* @__PURE__ */ jsxs7(Box7, { children: [
3196
- /* @__PURE__ */ jsx9(Text8, { color: isCursor ? semantic.action : colors.outline, children: isCursor ? "\u276F " : " " }),
3571
+ /* @__PURE__ */ jsx9(Text8, { color: isCursor ? semantic.action : colors.outline, children: isCursor ? `${g.cursor} ` : " " }),
3197
3572
  /* @__PURE__ */ jsxs7(Text8, { color: enabled ? semantic.success : colors.outline, children: [
3198
3573
  enabled ? "[on ]" : "[off]",
3199
3574
  " "
@@ -3205,11 +3580,39 @@ function SettingsScreen() {
3205
3580
  ] });
3206
3581
  }
3207
3582
 
3583
+ // src/lib/version.ts
3584
+ import { readFileSync } from "fs";
3585
+ import { fileURLToPath } from "url";
3586
+ import path4 from "path";
3587
+ var cached = null;
3588
+ function getVersion() {
3589
+ if (cached !== null) return cached;
3590
+ const here = path4.dirname(fileURLToPath(import.meta.url));
3591
+ for (const rel of ["../package.json", "../../package.json"]) {
3592
+ try {
3593
+ const pkg = JSON.parse(readFileSync(path4.join(here, rel), "utf-8"));
3594
+ if (pkg.version) {
3595
+ cached = pkg.version;
3596
+ return cached;
3597
+ }
3598
+ } catch {
3599
+ }
3600
+ }
3601
+ cached = "0.0.0";
3602
+ return cached;
3603
+ }
3604
+
3208
3605
  // src/app.tsx
3209
3606
  import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
3210
3607
  function Header({ sudoMode: sudoMode2 }) {
3211
3608
  return /* @__PURE__ */ jsxs8(Box8, { justifyContent: "space-between", marginBottom: 1, children: [
3212
- /* @__PURE__ */ jsx10(Text9, { color: semantic.action, bold: true, children: "@tacuchi/updater" }),
3609
+ /* @__PURE__ */ jsxs8(Box8, { children: [
3610
+ /* @__PURE__ */ jsx10(Text9, { color: semantic.action, bold: true, children: "@tacuchi/updater" }),
3611
+ /* @__PURE__ */ jsxs8(Text9, { color: colors.outline, children: [
3612
+ " v",
3613
+ getVersion()
3614
+ ] })
3615
+ ] }),
3213
3616
  /* @__PURE__ */ jsx10(Text9, { color: sudoMode2 ? semantic.warning : colors.outline, children: sudoMode2 ? "SUDO" : `${process.platform}` })
3214
3617
  ] });
3215
3618
  }
@@ -3236,7 +3639,7 @@ function PhaseRouter() {
3236
3639
  }
3237
3640
  function Shell({ sudoMode: sudoMode2 }) {
3238
3641
  const { exit } = useInkApp();
3239
- useInput6((input) => {
3642
+ useSafeInput((input) => {
3240
3643
  if (input === "q" || input === "Q") {
3241
3644
  exit();
3242
3645
  process.exit(0);
@@ -3247,8 +3650,11 @@ function Shell({ sudoMode: sudoMode2 }) {
3247
3650
  /* @__PURE__ */ jsx10(PhaseRouter, {})
3248
3651
  ] });
3249
3652
  }
3250
- function App({ sudoMode: sudoMode2 = false }) {
3251
- const machine = useAppMachine(sudoMode2);
3653
+ function App({
3654
+ sudoMode: sudoMode2 = false,
3655
+ nonInteractive: nonInteractive2 = false
3656
+ }) {
3657
+ const machine = useAppMachine(sudoMode2, nonInteractive2);
3252
3658
  return /* @__PURE__ */ jsx10(MachineProvider, { value: machine, children: /* @__PURE__ */ jsx10(Shell, { sudoMode: sudoMode2 }) });
3253
3659
  }
3254
3660
 
@@ -3269,18 +3675,19 @@ if (args.includes("--help") || args.includes("-h")) {
3269
3675
  Flags:
3270
3676
  -s, --sudo Permite actualizar gestores que requieren admin
3271
3677
  (softwareupdate, apt, dnf, pacman, snap)
3678
+ -y, --yes, --all Modo no-interactivo: actualiza todo sin teclado
3679
+ (autom\xE1tico cuando stdin no es un TTY / CI / pipe)
3272
3680
  -h, --help Mostrar ayuda
3273
3681
  -v, --version Mostrar versi\xF3n
3682
+
3683
+ Tip: ejecuta siempre la \xFAltima versi\xF3n con npx @tacuchi/updater@latest
3274
3684
  `);
3275
3685
  process.exit(0);
3276
3686
  }
3277
3687
  if (args.includes("--version") || args.includes("-v")) {
3278
- console.log("1.0.0");
3688
+ console.log(getVersion());
3279
3689
  process.exit(0);
3280
3690
  }
3281
- if (sudoRequested && process.platform === "win32") {
3282
- console.log("\x1B[33m\xBB En Windows, ejecuta la terminal como Administrador en vez de usar --sudo\x1B[0m");
3283
- }
3284
3691
  if (sudoRequested && !isRoot && process.platform !== "win32") {
3285
3692
  console.log("\x1B[35m\xBB Modo SUDO: ingresa tu contrase\xF1a para continuar...\x1B[0m");
3286
3693
  try {
@@ -3297,13 +3704,22 @@ if (sudoRequested && !isRoot && process.platform !== "win32") {
3297
3704
  console.error("\x1B[31m\u2717 No se pudo autenticar sudo. Continuando sin permisos elevados.\x1B[0m");
3298
3705
  }
3299
3706
  }
3300
- var sudoMode = isRoot || sudoRequested;
3301
- var { unmount } = render(/* @__PURE__ */ jsx11(App, { sudoMode }));
3302
- process.on("SIGINT", () => {
3303
- unmount();
3304
- process.exit(0);
3305
- });
3306
- process.on("SIGTERM", () => {
3307
- unmount();
3308
- process.exit(0);
3309
- });
3707
+ var elevated = await isElevated();
3708
+ if (process.platform === "win32" && sudoRequested && !elevated) {
3709
+ console.log(
3710
+ "\x1B[33m\xBB En Windows --sudo no eleva. Abr\xED la terminal como Administrador (se detecta autom\xE1ticamente).\x1B[0m"
3711
+ );
3712
+ }
3713
+ var sudoMode = process.platform === "win32" ? elevated : isRoot || sudoRequested;
3714
+ var nonInteractive = !process.stdin.isTTY || args.includes("--yes") || args.includes("-y") || args.includes("--all");
3715
+ var { unmount } = render(/* @__PURE__ */ jsx11(App, { sudoMode, nonInteractive }));
3716
+ var onSignal = (code) => () => {
3717
+ fireProcessCancel();
3718
+ setTimeout(() => {
3719
+ unmount();
3720
+ process.exit(code);
3721
+ }, 200);
3722
+ };
3723
+ process.on("SIGINT", onSignal(130));
3724
+ process.on("SIGTERM", onSignal(143));
3725
+ process.on("SIGBREAK", onSignal(130));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tacuchi/updater",
3
- "version": "2.0.4",
3
+ "version": "2.1.0",
4
4
  "description": "CLI multiplataforma para actualizar gestores de paquetes del sistema",
5
5
  "type": "module",
6
6
  "bin": {
@@ -15,10 +15,11 @@
15
15
  "scripts": {
16
16
  "dev": "tsx src/cli.tsx",
17
17
  "build": "tsup",
18
+ "postbuild": "node scripts/assert-shebang.mjs",
18
19
  "test": "vitest run",
19
20
  "test:watch": "vitest",
20
21
  "typecheck": "tsc --noEmit",
21
- "prepublishOnly": "tsup"
22
+ "prepublishOnly": "npm run build"
22
23
  },
23
24
  "keywords": [
24
25
  "cli",
@@ -36,14 +37,18 @@
36
37
  "dependencies": {
37
38
  "@inkjs/ui": "^2.0.0",
38
39
  "chalk": "^5.4.1",
40
+ "env-paths": "^4.0.0",
39
41
  "execa": "^9.6.0",
42
+ "iconv-lite": "^0.7.2",
40
43
  "ink": "^6.8.0",
44
+ "is-admin": "^4.0.0",
41
45
  "react": "^19.2.0",
42
- "react-devtools-core": "^6.1.2"
46
+ "tree-kill": "^1.2.2"
43
47
  },
44
48
  "devDependencies": {
45
49
  "@types/react": "^19.0.0",
46
50
  "ink-testing-library": "^4.0.0",
51
+ "react-devtools-core": "^7.0.1",
47
52
  "tsup": "^8.4.0",
48
53
  "tsx": "^4.19.3",
49
54
  "typescript": "^5.7.3",