@tacuchi/updater 2.0.3 → 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 +591 -160
  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;
@@ -873,31 +1010,38 @@ var softwareupdate = {
873
1010
  };
874
1011
 
875
1012
  // src/managers/descriptors/winget.ts
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];
876
1016
  function parseWingetOutdated(stdout) {
877
- const packages = [];
878
- const lines = stdout.split("\n");
879
- let inTable = false;
880
- for (const line of lines) {
881
- if (line.includes("------")) {
882
- inTable = true;
883
- continue;
884
- }
885
- if (!inTable) continue;
886
- const cols = line.trim().split(/\s{2,}/);
887
- if (cols.length >= 4) {
888
- packages.push({
889
- name: cols[1] ?? cols[0] ?? "Unknown",
890
- currentVersion: cols[2] ?? "?",
891
- newVersion: cols[3] ?? "?"
892
- });
893
- }
1017
+ const lines = stdout.split("\n").map((l) => (l.split("\r").pop() ?? l).replace(/[⠀-⣿]/g, "").replace(/\s+$/, ""));
1018
+ const dashIdx = lines.findIndex((l) => l.trim().length >= 3 && /^-+$/.test(l.trim()));
1019
+ if (dashIdx < 1) return [];
1020
+ const header = lines[dashIdx - 1] ?? "";
1021
+ const starts = [];
1022
+ for (const m of header.matchAll(/\S+/g)) starts.push(m.index ?? 0);
1023
+ if (starts.length < 4) return [];
1024
+ const cell = (line, i) => (i < starts.length - 1 ? line.slice(starts[i], starts[i + 1]) : line.slice(starts[i])).trim();
1025
+ const out = [];
1026
+ for (let i = dashIdx + 1; i < lines.length; i++) {
1027
+ const line = lines[i];
1028
+ if (line.trim().length === 0) continue;
1029
+ const id = cell(line, 1);
1030
+ const current = cell(line, 2);
1031
+ const available = cell(line, 3);
1032
+ if (!id || !available) continue;
1033
+ out.push({ name: id, currentVersion: current || "?", newVersion: available || "?" });
894
1034
  }
895
- return packages;
1035
+ return out;
1036
+ }
1037
+ async function listWinget() {
1038
+ const res = await execCommand(
1039
+ "winget",
1040
+ ["list", "--upgrade-available", "--include-unknown", "--accept-source-agreements"],
1041
+ 6e4
1042
+ );
1043
+ return parseWingetOutdated(res.stdout);
896
1044
  }
897
- var ACCEPT_AGREEMENTS = [
898
- "--accept-source-agreements",
899
- "--accept-package-agreements"
900
- ];
901
1045
  var winget = {
902
1046
  id: "winget",
903
1047
  group: "apps",
@@ -908,17 +1052,34 @@ var winget = {
908
1052
  parseVersion: (stdout) => stdout.trim() || void 0,
909
1053
  listOutdatedCmd: () => ({
910
1054
  cmd: "winget",
911
- args: ["list", "--upgrade-available", "--accept-source-agreements"]
1055
+ args: ["list", "--upgrade-available", "--include-unknown", "--accept-source-agreements"]
912
1056
  }),
913
1057
  parseOutdated: (stdout) => parseWingetOutdated(stdout),
914
- // Single bulk command: `winget upgrade --all` when nothing is selected,
915
- // otherwise one invocation carrying every selected id (`--id <id>` per pkg).
916
- upgradeCmd: (pkgs) => {
917
- if (pkgs && pkgs.length) {
918
- const idArgs = pkgs.flatMap((id) => ["--id", id]);
919
- return { cmd: "winget", args: ["upgrade", ...ACCEPT_AGREEMENTS, ...idArgs] };
1058
+ // Escape hatch: winget upgrades ONE package per invocation (no multi-target),
1059
+ // so a single bulk `--id A --id B` silently fails. Loop one `winget upgrade
1060
+ // --exact --id <id>` per selected package, then verify by re-listing.
1061
+ escapeHatch: {
1062
+ listOutdated: listWinget,
1063
+ async *upgrade(packages, ctx) {
1064
+ yield { type: "phase", phase: "upgrading", message: "Actualizando winget..." };
1065
+ const before = await listWinget();
1066
+ const targets = packages && packages.length ? packages : before.map((p) => p.name);
1067
+ const commands = [];
1068
+ const run = async function* (args2) {
1069
+ yield { type: "log", message: `winget ${args2.join(" ")}` };
1070
+ const rec = yield* runStream("winget", args2, { timeoutMs: 6e5, sudo: false, signal: ctx.signal });
1071
+ commands.push(rec);
1072
+ logCommand(rec);
1073
+ };
1074
+ if (!targets.length) {
1075
+ yield* run(["upgrade", "--all", "--include-unknown", "--include-pinned", ...UPGRADE_FLAGS]);
1076
+ } else {
1077
+ for (const id of targets) yield* run(["upgrade", "--exact", "--id", id, "--include-unknown", ...UPGRADE_FLAGS]);
1078
+ }
1079
+ yield { type: "phase", phase: "verifying", message: "Verificando resultado..." };
1080
+ const after = await listWinget();
1081
+ return reconcile(packages, before, { stillOutdated: after.map((p) => ({ name: p.name })) }, commands, WINGET_OK_CODES);
920
1082
  }
921
- return { cmd: "winget", args: ["upgrade", "--all", ...ACCEPT_AGREEMENTS] };
922
1083
  }
923
1084
  };
924
1085
 
@@ -1400,6 +1561,10 @@ var choco = {
1400
1561
  platforms: ["win32"],
1401
1562
  requiresAdmin: true,
1402
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],
1403
1568
  detectCmd: { cmd: "choco", args: ["--version"], timeout: 3e3 },
1404
1569
  parseVersion: (stdout) => stdout.trim() || void 0,
1405
1570
  listOutdatedCmd: () => ({ cmd: "choco", args: ["outdated", "--limit-output"] }),
@@ -1886,20 +2051,20 @@ var scoop = {
1886
2051
  platforms: ["win32"],
1887
2052
  requiresAdmin: false,
1888
2053
  kind: "direct",
1889
- detectCmd: { cmd: "scoop", args: ["--version"], timeout: 3e3 },
2054
+ detectCmd: { cmd: "scoop.cmd", args: ["--version"], timeout: 3e3 },
1890
2055
  parseVersion: (stdout) => {
1891
2056
  const m = stdout.match(/v?\d+\.\d+(?:\.\d+)?/);
1892
2057
  return m?.[0];
1893
2058
  },
1894
- listOutdatedCmd: () => ({ cmd: "scoop", args: ["status"] }),
2059
+ listOutdatedCmd: () => ({ cmd: "scoop.cmd", args: ["status"] }),
1895
2060
  parseOutdated: (stdout) => parseScoopOutdated(stdout),
1896
2061
  // `scoop update` (no app) refreshes scoop itself + all buckets so the
1897
2062
  // following `scoop update *` / `scoop update <names>` sees the latest
1898
2063
  // manifests.
1899
- preUpgradeCmds: () => [{ cmd: "scoop", args: ["update"] }],
2064
+ preUpgradeCmds: () => [{ cmd: "scoop.cmd", args: ["update"] }],
1900
2065
  // Single bulk command: `scoop update *` upgrades every app, otherwise one
1901
2066
  // invocation carrying every selected app name.
1902
- 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", "*"] },
1903
2068
  manualCommand: () => "scoop update *"
1904
2069
  };
1905
2070
 
@@ -2309,6 +2474,7 @@ var es = {
2309
2474
  selectHint: "Espacio marcar \xB7 A todos \xB7 N ninguno \xB7 Enter continuar \xB7 S ajustes \xB7 Q salir",
2310
2475
  confirmHint: "Enter actualizar \xB7 Esc volver \xB7 Q salir",
2311
2476
  updatingHint: "Esc cancelar",
2477
+ passwordNote: 'Si aparece "Password:" abajo, es un gestor (p.ej. un cask de brew): escr\xEDbela y Enter.',
2312
2478
  summaryHint: "R re-escanear \xB7 Q salir",
2313
2479
  elapsed: "transcurrido",
2314
2480
  cancel: "Cancelando..."
@@ -2507,6 +2673,7 @@ var en = {
2507
2673
  selectHint: "Space toggle \xB7 A all \xB7 N none \xB7 Enter continue \xB7 S settings \xB7 Q quit",
2508
2674
  confirmHint: "Enter update \xB7 Esc back \xB7 Q quit",
2509
2675
  updatingHint: "Esc cancel",
2676
+ passwordNote: 'If a "Password:" prompt appears below, it is a manager (e.g. a brew cask): type it and Enter.',
2510
2677
  summaryHint: "R rescan \xB7 Q quit",
2511
2678
  elapsed: "elapsed",
2512
2679
  cancel: "Cancelling..."
@@ -2516,8 +2683,9 @@ var en = {
2516
2683
  // src/i18n/index.ts
2517
2684
  var currentLang = detectLanguage();
2518
2685
  function detectLanguage() {
2519
- const lang = process.env["LANG"] ?? process.env["LANGUAGE"] ?? "";
2520
- 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";
2521
2689
  }
2522
2690
  function setLanguage(lang) {
2523
2691
  currentLang = lang;
@@ -2535,6 +2703,61 @@ function managerName(id) {
2535
2703
  return names[id] ?? id;
2536
2704
  }
2537
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
+
2538
2761
  // src/hooks/use-app-machine.tsx
2539
2762
  import { jsx } from "react/jsx-runtime";
2540
2763
  function toManagerResult(r, logRef) {
@@ -2548,16 +2771,38 @@ function toManagerResult(r, logRef) {
2548
2771
  failed: r.failed,
2549
2772
  skipped: r.skipped ?? 0,
2550
2773
  failures,
2551
- manualCommand: r.manualCommand
2774
+ manualCommand: r.manualCommand,
2775
+ reboot: r.reboot
2552
2776
  };
2553
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
+ }
2554
2799
  var MachineContext = createContext(null);
2555
2800
  function useMachine() {
2556
2801
  const ctx = useContext(MachineContext);
2557
2802
  if (!ctx) throw new Error("useMachine must be used inside <MachineProvider>");
2558
2803
  return ctx;
2559
2804
  }
2560
- function useAppMachine(sudoMode2) {
2805
+ function useAppMachine(sudoMode2, nonInteractive2 = false) {
2561
2806
  const configRef = useRef(loadConfig());
2562
2807
  const [state, dispatch] = useReducer(
2563
2808
  appReducer,
@@ -2607,6 +2852,7 @@ function useAppMachine(sudoMode2) {
2607
2852
  setLanguage(configRef.current.language);
2608
2853
  void boot();
2609
2854
  }, [boot]);
2855
+ useEffect(() => onProcessCancel(() => abortRef.current?.abort()), []);
2610
2856
  const startRun = useCallback(() => {
2611
2857
  const config = configRef.current;
2612
2858
  const packagesByManager = /* @__PURE__ */ new Map();
@@ -2643,13 +2889,8 @@ function useAppMachine(sudoMode2) {
2643
2889
  if (e.phase === "queued") {
2644
2890
  enqueue({ type: "MGR_QUEUED", id });
2645
2891
  } else if (e.phase === "upgrading") {
2646
- if (e.event && (e.event.percent !== void 0 || e.event.package || e.event.message)) {
2647
- enqueue({
2648
- type: "MGR_PROGRESS",
2649
- id,
2650
- percent: e.event.percent,
2651
- currentPackage: e.event.package ?? e.event.message
2652
- });
2892
+ if (e.event?.percent !== void 0) {
2893
+ enqueue({ type: "MGR_PROGRESS", id, percent: e.event.percent });
2653
2894
  } else if (!e.event) {
2654
2895
  enqueue({ type: "MGR_RUNNING", id });
2655
2896
  }
@@ -2684,6 +2925,65 @@ function useAppMachine(sudoMode2) {
2684
2925
  dispatch({ type: "RESCAN" });
2685
2926
  void boot();
2686
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]);
2687
2987
  const persist = useCallback((next) => {
2688
2988
  dispatch(next);
2689
2989
  }, []);
@@ -2710,6 +3010,7 @@ function useAppMachine(sudoMode2) {
2710
3010
  goSelect: useCallback(() => persist({ type: "GOTO_SELECT" }), [persist]),
2711
3011
  startRun,
2712
3012
  cancelRun,
3013
+ relaunch,
2713
3014
  rescan,
2714
3015
  openSettings: useCallback(() => persist({ type: "OPEN_SETTINGS" }), [persist]),
2715
3016
  closeSettings: useCallback(() => persist({ type: "CLOSE_SETTINGS" }), [persist]),
@@ -2721,6 +3022,14 @@ function MachineProvider({ value, children }) {
2721
3022
  return /* @__PURE__ */ jsx(MachineContext.Provider, { value, children });
2722
3023
  }
2723
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
+
2724
3033
  // src/screens/detect.tsx
2725
3034
  import { Box as Box2, Text as Text3 } from "ink";
2726
3035
 
@@ -2776,6 +3085,61 @@ var semantic = {
2776
3085
  muted: colors.onSurfaceVariant
2777
3086
  };
2778
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
+
2779
3143
  // src/components/step-header.tsx
2780
3144
  import { jsx as jsx2, jsxs } from "react/jsx-runtime";
2781
3145
  var STEP = {
@@ -2788,13 +3152,15 @@ var STEP = {
2788
3152
  function StepHeader({ phase }) {
2789
3153
  if (phase === "summary") {
2790
3154
  return /* @__PURE__ */ jsx2(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: semantic.success, bold: true, children: [
2791
- "\u2586 ",
3155
+ g.stepOn,
3156
+ " ",
2792
3157
  t("flow", "summary")
2793
3158
  ] }) });
2794
3159
  }
2795
3160
  if (phase === "settings") {
2796
3161
  return /* @__PURE__ */ jsx2(Box, { marginBottom: 1, children: /* @__PURE__ */ jsxs(Text, { color: semantic.action, bold: true, children: [
2797
- "\u2586 ",
3162
+ g.stepOn,
3163
+ " ",
2798
3164
  t("flow", "settings")
2799
3165
  ] }) });
2800
3166
  }
@@ -2802,7 +3168,7 @@ function StepHeader({ phase }) {
2802
3168
  if (!step) return null;
2803
3169
  return /* @__PURE__ */ jsxs(Box, { marginBottom: 1, children: [
2804
3170
  [1, 2, 3, 4].map((i) => /* @__PURE__ */ jsxs(Text, { color: i === step.n ? semantic.action : semantic.muted, bold: i === step.n, children: [
2805
- i === step.n ? "\u2586" : "\u2581",
3171
+ i === step.n ? g.stepOn : g.stepOff,
2806
3172
  " "
2807
3173
  ] }, i)),
2808
3174
  /* @__PURE__ */ jsxs(Text, { color: semantic.muted, children: [
@@ -2821,15 +3187,15 @@ function StepHeader({ phase }) {
2821
3187
  import { Text as Text2 } from "ink";
2822
3188
  import { jsx as jsx3 } from "react/jsx-runtime";
2823
3189
  var SPECS = {
2824
- pending: { glyph: "\xB7", color: semantic.muted },
2825
- scanning: { glyph: "\u25CC", color: semantic.action },
2826
- outdated: { glyph: "\u203A", color: semantic.warning },
2827
- uptodate: { glyph: "\u2713", color: semantic.muted },
2828
- queued: { glyph: "\xB7", color: semantic.muted },
2829
- running: { glyph: "\u25B8", color: semantic.action },
2830
- done: { glyph: "\u2713", color: semantic.success },
2831
- failed: { glyph: "\u2717", color: semantic.error },
2832
- 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 }
2833
3199
  };
2834
3200
  function statusColor(status) {
2835
3201
  return SPECS[status].color;
@@ -2869,8 +3235,9 @@ function DetectScreen() {
2869
3235
  /* @__PURE__ */ jsx4(Box2, { width: 18, children: /* @__PURE__ */ jsx4(Text3, { color: e.status === "outdated" ? semantic.text : semantic.muted, children: managerName(id) }) }),
2870
3236
  e.status === "outdated" ? /* @__PURE__ */ jsxs2(Text3, { color: semantic.warning, children: [
2871
3237
  e.outdated.length,
2872
- " \u203A"
2873
- ] }) : 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 })
2874
3241
  ] }, id);
2875
3242
  })
2876
3243
  ] });
@@ -2878,10 +3245,10 @@ function DetectScreen() {
2878
3245
 
2879
3246
  // src/screens/select.tsx
2880
3247
  import { useState } from "react";
2881
- import { Box as Box3, Text as Text4, useInput } from "ink";
3248
+ import { Box as Box3, Text as Text4 } from "ink";
2882
3249
  import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
2883
3250
  function clip(s, n) {
2884
- 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;
2885
3252
  }
2886
3253
  function SelectScreen() {
2887
3254
  const { state, toggleItem, selectAll, selectNone, goConfirm, openSettings } = useMachine();
@@ -2892,7 +3259,7 @@ function SelectScreen() {
2892
3259
  if (m && m.status === "outdated") for (const pkg of m.outdated) rows.push({ managerId: id, pkg });
2893
3260
  }
2894
3261
  const clamped = Math.min(cursor, Math.max(0, rows.length - 1));
2895
- useInput((input, key) => {
3262
+ useSafeInput((input, key) => {
2896
3263
  if (key.downArrow || input === "j") setCursor((c) => Math.min(rows.length - 1, c + 1));
2897
3264
  else if (key.upArrow || input === "k") setCursor((c) => Math.max(0, c - 1));
2898
3265
  else if (input === " ") {
@@ -2937,9 +3304,9 @@ function SelectScreen() {
2937
3304
  ] })
2938
3305
  ] }),
2939
3306
  start > 0 && /* @__PURE__ */ jsxs3(Text4, { color: colors.outline, children: [
2940
- "\u25B2 ",
2941
- start,
2942
- " \u2191"
3307
+ g.scrollUp,
3308
+ " ",
3309
+ start
2943
3310
  ] }),
2944
3311
  visible.map((r) => {
2945
3312
  const header = r.managerId !== prevManager ? managerName(r.managerId) : null;
@@ -2949,13 +3316,13 @@ function SelectScreen() {
2949
3316
  return /* @__PURE__ */ jsxs3(Box3, { flexDirection: "column", children: [
2950
3317
  header && /* @__PURE__ */ jsx5(Text4, { color: semantic.muted, bold: true, children: header }),
2951
3318
  /* @__PURE__ */ jsxs3(Box3, { children: [
2952
- /* @__PURE__ */ jsx5(Text4, { color: isCursor ? semantic.action : colors.outline, children: isCursor ? "\u276F " : " " }),
2953
- /* @__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} ` }),
2954
3321
  /* @__PURE__ */ jsx5(Box3, { width: 22, children: /* @__PURE__ */ jsx5(Text4, { color: semantic.text, bold: isCursor, children: clip(r.pkg.name, 21) }) }),
2955
3322
  /* @__PURE__ */ jsxs3(Text4, { color: semantic.muted, wrap: "truncate-end", children: [
2956
3323
  clip(r.pkg.currentVersion, 14),
2957
3324
  " ",
2958
- /* @__PURE__ */ jsx5(Text4, { color: semantic.action, children: "\u2192" }),
3325
+ /* @__PURE__ */ jsx5(Text4, { color: semantic.action, children: g.arrow }),
2959
3326
  " ",
2960
3327
  clip(r.pkg.newVersion, 14)
2961
3328
  ] })
@@ -2963,26 +3330,28 @@ function SelectScreen() {
2963
3330
  ] }, `${r.managerId}:${r.pkg.name}`);
2964
3331
  }),
2965
3332
  end < rows.length && /* @__PURE__ */ jsxs3(Text4, { color: colors.outline, children: [
2966
- "\u25BC ",
2967
- rows.length - end,
2968
- " \u2193"
3333
+ g.scrollDown,
3334
+ " ",
3335
+ rows.length - end
2969
3336
  ] }),
2970
3337
  /* @__PURE__ */ jsx5(Box3, { marginTop: 1, children: /* @__PURE__ */ jsx5(Text4, { color: semantic.muted, children: clip(t("ui", "selectHint"), width) }) })
2971
3338
  ] });
2972
3339
  }
2973
3340
 
2974
3341
  // src/screens/confirm.tsx
2975
- import { Box as Box4, Text as Text5, useInput as useInput2 } from "ink";
3342
+ import { Box as Box4, Text as Text5 } from "ink";
2976
3343
  import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
2977
3344
  function ConfirmScreen() {
2978
- const { state, startRun, goSelect, sudoMode: sudoMode2 } = useMachine();
3345
+ const { state, startRun, goSelect, sudoMode: sudoMode2, relaunch } = useMachine();
2979
3346
  const byManager = /* @__PURE__ */ new Map();
2980
3347
  for (const key of state.selection) {
2981
3348
  const [id] = parseSelectionKey(key);
2982
3349
  byManager.set(id, (byManager.get(id) ?? 0) + 1);
2983
3350
  }
2984
- useInput2((input, key) => {
2985
- 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();
2986
3355
  else if (key.escape) goSelect();
2987
3356
  });
2988
3357
  return /* @__PURE__ */ jsxs4(Box4, { flexDirection: "column", children: [
@@ -2992,28 +3361,32 @@ function ConfirmScreen() {
2992
3361
  const m = state.managers[id];
2993
3362
  const willSkip = m?.requiresAdmin && !sudoMode2;
2994
3363
  return /* @__PURE__ */ jsxs4(Box4, { children: [
2995
- /* @__PURE__ */ jsx6(Text5, { color: semantic.action, children: "\u25B8 " }),
3364
+ /* @__PURE__ */ jsxs4(Text5, { color: semantic.action, children: [
3365
+ g.bullet,
3366
+ " "
3367
+ ] }),
2996
3368
  /* @__PURE__ */ jsx6(Box4, { width: 20, children: /* @__PURE__ */ jsx6(Text5, { color: semantic.text, bold: true, children: managerName(id) }) }),
2997
3369
  /* @__PURE__ */ jsxs4(Text5, { color: semantic.muted, children: [
2998
3370
  count,
2999
3371
  " paquete(s)"
3000
3372
  ] }),
3001
- 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" })
3002
3374
  ] }, id);
3003
3375
  }) }),
3004
- /* @__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" })
3005
3378
  ] });
3006
3379
  }
3007
3380
 
3008
3381
  // src/screens/update.tsx
3009
- import { Box as Box5, Text as Text6, useInput as useInput3 } from "ink";
3382
+ import { Box as Box5, Text as Text6 } from "ink";
3010
3383
  import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
3011
3384
  function clip2(s, n) {
3012
- 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;
3013
3386
  }
3014
3387
  function Row({ e, width }) {
3015
3388
  let detail = "";
3016
- if (e.status === "running") detail = `${e.percent > 0 ? `${e.percent}% ` : ""}${e.currentPackage ?? ""}`;
3389
+ if (e.status === "running") detail = e.percent > 0 ? `${e.percent}%` : "";
3017
3390
  else if (e.status === "skipped") detail = e.manualCommand ?? "manual";
3018
3391
  else if (e.status === "failed") detail = e.result?.failures[0]?.message ?? "";
3019
3392
  return /* @__PURE__ */ jsxs5(Box5, { children: [
@@ -3025,7 +3398,7 @@ function Row({ e, width }) {
3025
3398
  }
3026
3399
  function UpdateScreen() {
3027
3400
  const { state, cancelRun } = useMachine();
3028
- useInput3((_input, key) => {
3401
+ useSafeInput((_input, key) => {
3029
3402
  if (key.escape) cancelRun();
3030
3403
  });
3031
3404
  const total = state.run.queue.length;
@@ -3041,17 +3414,20 @@ function UpdateScreen() {
3041
3414
  " "
3042
3415
  ] }),
3043
3416
  /* @__PURE__ */ jsxs5(Text6, { color: semantic.success, children: [
3044
- "\u2713 ",
3417
+ g.done,
3418
+ " ",
3045
3419
  state.run.doneCount,
3046
3420
  " "
3047
3421
  ] }),
3048
3422
  /* @__PURE__ */ jsxs5(Text6, { color: semantic.error, children: [
3049
- "\u2717 ",
3423
+ g.failed,
3424
+ " ",
3050
3425
  state.run.failedCount,
3051
3426
  " "
3052
3427
  ] }),
3053
3428
  /* @__PURE__ */ jsxs5(Text6, { color: semantic.warning, children: [
3054
- "\u2298 ",
3429
+ g.skipped,
3430
+ " ",
3055
3431
  state.run.skippedCount
3056
3432
  ] })
3057
3433
  ] }),
@@ -3059,16 +3435,19 @@ function UpdateScreen() {
3059
3435
  const e = state.managers[id];
3060
3436
  return e ? /* @__PURE__ */ jsx7(Row, { e, width }, id) : null;
3061
3437
  }),
3062
- /* @__PURE__ */ jsx7(Box5, { marginTop: 1, children: /* @__PURE__ */ jsx7(Text6, { color: semantic.muted, children: t("ui", "updatingHint") }) })
3438
+ /* @__PURE__ */ jsxs5(Box5, { marginTop: 1, flexDirection: "column", children: [
3439
+ /* @__PURE__ */ jsx7(Text6, { color: semantic.muted, children: t("ui", "updatingHint") }),
3440
+ /* @__PURE__ */ jsx7(Text6, { color: semantic.muted, children: t("ui", "passwordNote") })
3441
+ ] })
3063
3442
  ] });
3064
3443
  }
3065
3444
 
3066
3445
  // src/screens/summary.tsx
3067
- import { Box as Box6, Text as Text7, useInput as useInput4 } from "ink";
3446
+ import { Box as Box6, Text as Text7 } from "ink";
3068
3447
  import { jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
3069
3448
  function SummaryScreen() {
3070
3449
  const { state, rescan } = useMachine();
3071
- useInput4((input) => {
3450
+ useSafeInput((input) => {
3072
3451
  if (input === "r" || input === "R") rescan();
3073
3452
  });
3074
3453
  let upgraded = 0;
@@ -3076,6 +3455,7 @@ function SummaryScreen() {
3076
3455
  let skipped = 0;
3077
3456
  const failures = [];
3078
3457
  const manuals = [];
3458
+ const reboots = [];
3079
3459
  for (const id of state.run.queue) {
3080
3460
  const e = state.managers[id];
3081
3461
  if (!e) continue;
@@ -3089,12 +3469,13 @@ function SummaryScreen() {
3089
3469
  upgraded += r.upgraded;
3090
3470
  failed += r.failed;
3091
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 });
3092
3473
  }
3093
3474
  }
3094
3475
  const hasErrors = failed > 0;
3095
3476
  return /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", children: [
3096
3477
  /* @__PURE__ */ jsx8(StepHeader, { phase: state.phase }),
3097
- /* @__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")}` }) }),
3098
3479
  /* @__PURE__ */ jsxs6(Box6, { marginBottom: 1, children: [
3099
3480
  /* @__PURE__ */ jsxs6(Text7, { color: semantic.success, children: [
3100
3481
  upgraded,
@@ -3116,7 +3497,8 @@ function SummaryScreen() {
3116
3497
  ] }),
3117
3498
  failures.length > 0 && /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginBottom: 1, children: [
3118
3499
  failures.slice(0, 8).map((f, i) => /* @__PURE__ */ jsxs6(Text7, { color: semantic.error, wrap: "truncate-end", children: [
3119
- "\u2717 ",
3500
+ g.failed,
3501
+ " ",
3120
3502
  managerName(f.manager),
3121
3503
  f.package ? /* @__PURE__ */ jsxs6(Text7, { color: semantic.text, children: [
3122
3504
  " ",
@@ -3127,7 +3509,10 @@ function SummaryScreen() {
3127
3509
  f.kind
3128
3510
  ] }) : null
3129
3511
  ] }, i)),
3130
- 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
+ ] })
3131
3516
  ] }),
3132
3517
  manuals.length > 0 && /* @__PURE__ */ jsxs6(Box6, { flexDirection: "column", marginBottom: 1, children: [
3133
3518
  /* @__PURE__ */ jsx8(Text7, { color: semantic.warning, children: t("ui", "manualNeeded") }),
@@ -3138,6 +3523,11 @@ function SummaryScreen() {
3138
3523
  /* @__PURE__ */ jsx8(Text7, { color: semantic.text, children: m.command })
3139
3524
  ] }, i))
3140
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
+ ] }) }),
3141
3531
  hasErrors && /* @__PURE__ */ jsxs6(Text7, { color: semantic.muted, children: [
3142
3532
  t("ui", "logAt"),
3143
3533
  " ",
@@ -3149,14 +3539,14 @@ function SummaryScreen() {
3149
3539
 
3150
3540
  // src/screens/settings-screen.tsx
3151
3541
  import { useState as useState2 } from "react";
3152
- import { Box as Box7, Text as Text8, useInput as useInput5 } from "ink";
3542
+ import { Box as Box7, Text as Text8 } from "ink";
3153
3543
  import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
3154
3544
  function SettingsScreen() {
3155
3545
  const { state, toggleEnabled, setLang, closeSettings } = useMachine();
3156
3546
  const ids = state.order;
3157
3547
  const [cursor, setCursor] = useState2(0);
3158
3548
  const clamped = Math.min(cursor, Math.max(0, ids.length - 1));
3159
- useInput5((input, key) => {
3549
+ useSafeInput((input, key) => {
3160
3550
  if (key.escape) closeSettings();
3161
3551
  else if (key.downArrow || input === "j") setCursor((c) => Math.min(ids.length - 1, c + 1));
3162
3552
  else if (key.upArrow || input === "k") setCursor((c) => Math.max(0, c - 1));
@@ -3178,7 +3568,7 @@ function SettingsScreen() {
3178
3568
  const enabled = isManagerEnabled(state.config, id);
3179
3569
  const isCursor = i === clamped;
3180
3570
  return /* @__PURE__ */ jsxs7(Box7, { children: [
3181
- /* @__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} ` : " " }),
3182
3572
  /* @__PURE__ */ jsxs7(Text8, { color: enabled ? semantic.success : colors.outline, children: [
3183
3573
  enabled ? "[on ]" : "[off]",
3184
3574
  " "
@@ -3190,11 +3580,39 @@ function SettingsScreen() {
3190
3580
  ] });
3191
3581
  }
3192
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
+
3193
3605
  // src/app.tsx
3194
3606
  import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
3195
3607
  function Header({ sudoMode: sudoMode2 }) {
3196
3608
  return /* @__PURE__ */ jsxs8(Box8, { justifyContent: "space-between", marginBottom: 1, children: [
3197
- /* @__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
+ ] }),
3198
3616
  /* @__PURE__ */ jsx10(Text9, { color: sudoMode2 ? semantic.warning : colors.outline, children: sudoMode2 ? "SUDO" : `${process.platform}` })
3199
3617
  ] });
3200
3618
  }
@@ -3221,7 +3639,7 @@ function PhaseRouter() {
3221
3639
  }
3222
3640
  function Shell({ sudoMode: sudoMode2 }) {
3223
3641
  const { exit } = useInkApp();
3224
- useInput6((input) => {
3642
+ useSafeInput((input) => {
3225
3643
  if (input === "q" || input === "Q") {
3226
3644
  exit();
3227
3645
  process.exit(0);
@@ -3232,8 +3650,11 @@ function Shell({ sudoMode: sudoMode2 }) {
3232
3650
  /* @__PURE__ */ jsx10(PhaseRouter, {})
3233
3651
  ] });
3234
3652
  }
3235
- function App({ sudoMode: sudoMode2 = false }) {
3236
- const machine = useAppMachine(sudoMode2);
3653
+ function App({
3654
+ sudoMode: sudoMode2 = false,
3655
+ nonInteractive: nonInteractive2 = false
3656
+ }) {
3657
+ const machine = useAppMachine(sudoMode2, nonInteractive2);
3237
3658
  return /* @__PURE__ */ jsx10(MachineProvider, { value: machine, children: /* @__PURE__ */ jsx10(Shell, { sudoMode: sudoMode2 }) });
3238
3659
  }
3239
3660
 
@@ -3254,18 +3675,19 @@ if (args.includes("--help") || args.includes("-h")) {
3254
3675
  Flags:
3255
3676
  -s, --sudo Permite actualizar gestores que requieren admin
3256
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)
3257
3680
  -h, --help Mostrar ayuda
3258
3681
  -v, --version Mostrar versi\xF3n
3682
+
3683
+ Tip: ejecuta siempre la \xFAltima versi\xF3n con npx @tacuchi/updater@latest
3259
3684
  `);
3260
3685
  process.exit(0);
3261
3686
  }
3262
3687
  if (args.includes("--version") || args.includes("-v")) {
3263
- console.log("1.0.0");
3688
+ console.log(getVersion());
3264
3689
  process.exit(0);
3265
3690
  }
3266
- if (sudoRequested && process.platform === "win32") {
3267
- console.log("\x1B[33m\xBB En Windows, ejecuta la terminal como Administrador en vez de usar --sudo\x1B[0m");
3268
- }
3269
3691
  if (sudoRequested && !isRoot && process.platform !== "win32") {
3270
3692
  console.log("\x1B[35m\xBB Modo SUDO: ingresa tu contrase\xF1a para continuar...\x1B[0m");
3271
3693
  try {
@@ -3282,13 +3704,22 @@ if (sudoRequested && !isRoot && process.platform !== "win32") {
3282
3704
  console.error("\x1B[31m\u2717 No se pudo autenticar sudo. Continuando sin permisos elevados.\x1B[0m");
3283
3705
  }
3284
3706
  }
3285
- var sudoMode = isRoot || sudoRequested;
3286
- var { unmount } = render(/* @__PURE__ */ jsx11(App, { sudoMode }));
3287
- process.on("SIGINT", () => {
3288
- unmount();
3289
- process.exit(0);
3290
- });
3291
- process.on("SIGTERM", () => {
3292
- unmount();
3293
- process.exit(0);
3294
- });
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.3",
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",