turno-cli 0.1.0 → 0.2.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 (105) hide show
  1. package/CHANGELOG.md +293 -0
  2. package/README.md +143 -75
  3. package/dist/accounts/audit.js +137 -7
  4. package/dist/accounts/builtin.js +68 -21
  5. package/dist/accounts/delegate.js +176 -35
  6. package/dist/accounts/policy.js +77 -0
  7. package/dist/accounts/registry.js +37 -21
  8. package/dist/agents/adapter.js +7 -0
  9. package/dist/agents/claude.js +195 -0
  10. package/dist/agents/codex.js +98 -0
  11. package/dist/agents/copilot.js +39 -0
  12. package/dist/agents/cursor.js +41 -0
  13. package/dist/agents/index.js +26 -86
  14. package/dist/agents/snippets.js +7 -4
  15. package/dist/cli/args.js +19 -4
  16. package/dist/cli/commands/accounts.js +96 -51
  17. package/dist/cli/commands/auto.js +82 -32
  18. package/dist/cli/commands/browser.js +216 -135
  19. package/dist/cli/commands/complete.js +2 -1
  20. package/dist/cli/commands/completion.js +4 -2
  21. package/dist/cli/commands/config.js +103 -18
  22. package/dist/cli/commands/demo.js +292 -0
  23. package/dist/cli/commands/doctor.js +387 -119
  24. package/dist/cli/commands/handoff.js +33 -22
  25. package/dist/cli/commands/identity.js +101 -50
  26. package/dist/cli/commands/init.js +616 -0
  27. package/dist/cli/commands/limit.js +25 -13
  28. package/dist/cli/commands/mcp-oauth.js +194 -0
  29. package/dist/cli/commands/mcp-observe.js +434 -0
  30. package/dist/cli/commands/mcp.js +653 -185
  31. package/dist/cli/commands/mcpd.js +323 -75
  32. package/dist/cli/commands/migrate.js +6 -4
  33. package/dist/cli/commands/open.js +92 -27
  34. package/dist/cli/commands/profile.js +205 -69
  35. package/dist/cli/commands/resolve.js +6 -2
  36. package/dist/cli/commands/run.js +15 -5
  37. package/dist/cli/commands/secret.js +61 -42
  38. package/dist/cli/commands/session.js +2 -2
  39. package/dist/cli/commands/sessions.js +42 -12
  40. package/dist/cli/commands/setup.js +136 -158
  41. package/dist/cli/commands/status.js +172 -41
  42. package/dist/cli/commands/statusline.js +305 -113
  43. package/dist/cli/commands/ui.js +64 -66
  44. package/dist/cli/commands/undo.js +161 -18
  45. package/dist/cli/commands/uninstall.js +462 -0
  46. package/dist/cli/commands/upgrade.js +75 -19
  47. package/dist/cli/commands/usage.js +117 -44
  48. package/dist/cli/commands/version.js +7 -5
  49. package/dist/cli/commands/which.js +7 -24
  50. package/dist/cli/compile-cache.js +32 -0
  51. package/dist/cli/group.js +10 -10
  52. package/dist/cli/help.js +57 -0
  53. package/dist/cli/highlight.js +236 -0
  54. package/dist/cli/io.js +170 -1
  55. package/dist/cli/launch.js +21 -37
  56. package/dist/cli/launchers.js +145 -94
  57. package/dist/cli/main.js +163 -27
  58. package/dist/cli/picker.js +447 -0
  59. package/dist/cli/registry.js +42 -5
  60. package/dist/cli/security.js +539 -0
  61. package/dist/cli/style.js +281 -0
  62. package/dist/core/config.js +145 -23
  63. package/dist/core/exhausted.js +6 -8
  64. package/dist/core/fsutil.js +47 -0
  65. package/dist/core/journal.js +281 -11
  66. package/dist/core/manifest.js +126 -6
  67. package/dist/core/paths.js +114 -7
  68. package/dist/core/profiles.js +139 -9
  69. package/dist/core/resolve.js +129 -23
  70. package/dist/core/secrets.js +215 -20
  71. package/dist/core/sessions.js +13 -20
  72. package/dist/core/update.js +18 -8
  73. package/dist/core/version.js +6 -0
  74. package/dist/demo/server.js +34 -0
  75. package/dist/mcpd/cache.js +18 -4
  76. package/dist/mcpd/calllog.js +253 -0
  77. package/dist/mcpd/client-names.js +51 -0
  78. package/dist/mcpd/connectors.js +148 -17
  79. package/dist/mcpd/daemon.js +452 -116
  80. package/dist/mcpd/folder-sets.js +39 -0
  81. package/dist/mcpd/gateway.js +441 -47
  82. package/dist/mcpd/health.js +269 -0
  83. package/dist/mcpd/importer.js +356 -36
  84. package/dist/mcpd/instances.js +425 -65
  85. package/dist/mcpd/jsonrpc.js +8 -0
  86. package/dist/mcpd/launchd.js +65 -48
  87. package/dist/mcpd/modern.js +648 -0
  88. package/dist/mcpd/oauth.js +791 -0
  89. package/dist/mcpd/peerpid.js +122 -6
  90. package/dist/mcpd/pressure.js +85 -0
  91. package/dist/mcpd/rss.js +151 -0
  92. package/dist/mcpd/service.js +167 -0
  93. package/dist/mcpd/state.js +183 -0
  94. package/dist/mcpd/sync.js +55 -80
  95. package/dist/mcpd/systemd.js +80 -0
  96. package/dist/mcpd/tokens.js +89 -0
  97. package/dist/mcpd/upstream.js +154 -44
  98. package/dist/statusline/cost.js +154 -44
  99. package/dist/statusline/input.js +66 -0
  100. package/dist/statusline/render.js +9 -3
  101. package/dist/ui/fonts.js +8 -3
  102. package/dist/ui/settings.js +27 -15
  103. package/npm-shrinkwrap.json +1093 -0
  104. package/package.json +9 -9
  105. package/dist/cli/commands/available.js +0 -18
@@ -9,47 +9,43 @@ import { currentStatusLine, isTurnoStatusLine, setStatusLine, withNerdTerminals
9
9
  import { Journal } from "../../core/journal.js";
10
10
  import { BUILTIN_SYMBOLS, currentTerminal } from "../../ui/terminal-id.js";
11
11
  import { TERMINALS, detectNerdTerminals, fontOf, installed, isNerdFamily, terminal } from "../../ui/terminals.js";
12
+ import { DRY_RUN, FORCE, bool, flagsOf, parseFlags } from "../args.js";
13
+ import { group } from "../group.js";
12
14
  import { fail, paint } from "../io.js";
13
15
  import { findOnPath } from "../launch.js";
16
+ import { refuseNpx } from "../launchers.js";
14
17
  import { isLegacyScript } from "./doctor.js";
15
- const USAGE = `Usage:
16
- turno ui status font, status line and icons, terminal by terminal
17
- turno ui install [options] set up the turno look of Claude Code
18
- --terminal <ids> also set the font in these terminals: current, all, or a
19
- comma list of warp, vscode, cursor, alacritty
20
- --no-font leave the font alone
21
- --no-statusline leave Claude Code's settings.json alone
22
- --force replace font files that have the same name but other bytes
23
- --dry-run print what would change and change nothing
18
+ const INSTALL_SPEC = {
19
+ terminal: { type: "string", multiple: true },
20
+ "no-font": { type: "boolean" },
21
+ "no-statusline": { type: "boolean" },
22
+ ...FORCE,
23
+ ...DRY_RUN,
24
+ };
25
+ const INSTALL_HELP = `Options:
26
+ --terminal <ids> also set the font in these terminals: current, all, or a
27
+ comma list of warp, vscode, cursor, alacritty
28
+ --no-font leave the font alone
29
+ --no-statusline leave Claude Code's settings.json alone
30
+ --force replace font files that have the same name but other bytes
31
+ --dry-run print what would change and change nothing
24
32
 
25
- install copies MesloLGS Nerd Font 3.4.0 (the Nerd Font the icons come from, the same
26
- release Orca ships) into your user font folder,
27
- points the statusLine of the hub settings.json (shared by every profile) at
28
- \`turno statusline\`, and records in config.toml which terminals already use a Nerd Font,
29
- so \`icons = "auto"\` draws Nerd icons there and Unicode ones elsewhere. Every file it changes
30
- is backed up first under ~/.local/state/turno/backups/<stamp>/, and turno undo puts it back.`;
33
+ install copies MesloLGS Nerd Font 3.4.0 (the Nerd Font the icons come from) into
34
+ your user font folder, points the statusLine of the hub settings.json (shared by
35
+ every profile) at \`turno statusline\`, and records in config.toml which terminals
36
+ already use a Nerd Font, so \`icons = "auto"\` draws Nerd icons there and Unicode
37
+ ones elsewhere. Every file it changes is backed up first under
38
+ ~/.local/state/turno/backups/<stamp>/, and turno undo puts it back.`;
31
39
  function parse(args) {
32
- const o = { terminals: [], font: true, statusline: true, force: false, dryRun: false };
33
- for (let i = 0; i < args.length; i++) {
34
- const a = args[i];
35
- if (a === "--no-font")
36
- o.font = false;
37
- else if (a === "--no-statusline")
38
- o.statusline = false;
39
- else if (a === "--force")
40
- o.force = true;
41
- else if (a === "--dry-run")
42
- o.dryRun = true;
43
- else if (a === "--terminal" || a.startsWith("--terminal=")) {
44
- const v = a.includes("=") ? a.slice(a.indexOf("=") + 1) : args[++i];
45
- if (!v)
46
- fail("--terminal needs a value");
47
- o.terminals.push(...v.split(",").map((s) => s.trim()).filter(Boolean));
48
- }
49
- else
50
- fail(`unknown option ${a}`);
51
- }
52
- return o;
40
+ const p = parseFlags(args, INSTALL_SPEC, 0);
41
+ const values = p.values.terminal ?? [];
42
+ return {
43
+ terminals: values.flatMap((v) => v.split(",").map((s) => s.trim()).filter(Boolean)),
44
+ font: !bool(p, "no-font"),
45
+ statusline: !bool(p, "no-statusline"),
46
+ force: bool(p, "force"),
47
+ dryRun: bool(p, "dry-run"),
48
+ };
53
49
  }
54
50
  /** Terminal ids to configure, from --terminal values. */
55
51
  function chosenTerminals(values, env, platform) {
@@ -69,20 +65,25 @@ function chosenTerminals(values, env, platform) {
69
65
  }
70
66
  return [...out.values()];
71
67
  }
72
- /** The turno on PATH, unless it is still the bash original: then this very script. */
73
- export function statusLineCommand(env, self = process.argv[1]) {
68
+ /** The status line command, and a warning when it holds a path that may stop working. */
69
+ export function statusLineInfo(env, self = process.argv[1]) {
74
70
  const bin = findOnPath("turno", env);
75
- if (bin && !isLegacyScript(bin))
76
- return `${tildify(bin, env)} statusline`;
71
+ if (bin && !isLegacyScript(bin) && !bin.includes("/_npx/"))
72
+ return { command: `${tildify(bin, env)} statusline` };
77
73
  if (self) {
78
74
  try {
79
- return `${tildify(realpathSync(self), env)} statusline`;
75
+ const real = tildify(realpathSync(self), env);
76
+ return { command: `${real} statusline`, warning: `wrote an absolute path (${real}) because turno is not on your PATH; it breaks if you switch Node versions or move this copy` };
80
77
  }
81
78
  catch {
82
79
  /* fall through */
83
80
  }
84
81
  }
85
- return "turno statusline";
82
+ return { command: "turno statusline" };
83
+ }
84
+ /** The turno on PATH, unless it is still the bash original: then this very script. */
85
+ export function statusLineCommand(env, self = process.argv[1]) {
86
+ return statusLineInfo(env, self).command;
86
87
  }
87
88
  /** Status line icons missing from a font file. */
88
89
  function missingGlyphs(file) {
@@ -91,7 +92,8 @@ function missingGlyphs(file) {
91
92
  .map((g) => g.codePointAt(0))
92
93
  .filter((c) => !have.has(c));
93
94
  }
94
- async function status(io) {
95
+ async function status(args, io) {
96
+ parseFlags(args, {}, 0);
95
97
  const env = io.env;
96
98
  const platform = process.platform;
97
99
  const p = paths(env);
@@ -165,6 +167,9 @@ async function status(io) {
165
167
  }
166
168
  async function install(args, io) {
167
169
  const o = parse(args);
170
+ // The status line keeps the path of this turno; a path into npx's cache disappears.
171
+ if (o.statusline)
172
+ refuseNpx();
168
173
  const env = io.env;
169
174
  const platform = process.platform;
170
175
  const targets = chosenTerminals(o.terminals, env, platform); // validate before changing anything
@@ -182,11 +187,11 @@ async function install(args, io) {
182
187
  for (const r of results) {
183
188
  const what = {
184
189
  kept: "already installed",
185
- copied: "installed",
186
- downloaded: "downloaded and installed",
190
+ copied: o.dryRun ? "would be installed" : "installed",
191
+ downloaded: o.dryRun ? "would be downloaded and installed" : "downloaded and installed",
187
192
  skipped: "skipped: a different file has this name (--force replaces it)",
188
193
  }[r.action];
189
- io.out(`font: ${r.file} ${what}${r.action === "kept" || r.action === "skipped" ? "" : dry}`);
194
+ io.out(`font: ${r.file} ${what}`);
190
195
  }
191
196
  if (results.some((r) => r.action === "copied" || r.action === "downloaded") && !o.dryRun) {
192
197
  io.out("font: restart open terminals so they see the new font");
@@ -194,13 +199,16 @@ async function install(args, io) {
194
199
  }
195
200
  }
196
201
  if (o.statusline) {
197
- const r = setStatusLine(join(p.hub, "settings.json"), statusLineCommand(env), journal);
202
+ const line = statusLineInfo(env);
203
+ const r = setStatusLine(join(p.hub, "settings.json"), line.command, journal);
198
204
  if (!r.changed)
199
205
  io.out(`statusline: ${tildify(r.file, env)} already runs \`${r.after.command}\``);
200
206
  else {
201
207
  io.out(`statusline: ${tildify(r.file, env)} now runs \`${r.after.command}\` every ${r.after.refreshInterval} s${dry}`);
202
208
  if (r.before)
203
209
  io.out(`statusline: it ran \`${r.before.command}\``);
210
+ if (line.warning)
211
+ io.out(`statusline: ${line.warning}`);
204
212
  }
205
213
  }
206
214
  const family = source?.family ?? (await fontSource()).family;
@@ -253,24 +261,14 @@ async function install(args, io) {
253
261
  io.out(hint);
254
262
  return 0;
255
263
  }
256
- export const command = {
257
- summary: "the status line, its font and icons in every terminal",
258
- usage: USAGE,
259
- subcommands: {
260
- status: {},
261
- install: { flags: ["--terminal", "--no-font", "--no-statusline", "--force", "--dry-run"] },
264
+ export const command = group("ui", "the status line, its font and icons in every terminal", {
265
+ status: { summary: "font, status line and icons, terminal by terminal", run: status },
266
+ install: {
267
+ summary: "set up the turno look of Claude Code (font, status line, terminals)",
268
+ synopsis: "[--terminal <ids>] [--no-font] [--no-statusline] [--force] [--dry-run]",
269
+ flags: flagsOf(INSTALL_SPEC),
270
+ details: INSTALL_HELP,
271
+ run: install,
262
272
  },
263
- async run(args, io) {
264
- const [sub, ...rest] = args;
265
- if (sub === "status" || sub === undefined)
266
- return status(io);
267
- if (sub === "install")
268
- return install(rest, io);
269
- if (sub === "--help" || sub === "-h") {
270
- io.out(USAGE);
271
- return 0;
272
- }
273
- return fail(`unknown subcommand '${sub}'\n\n${USAGE}`);
274
- },
275
- };
273
+ }, { fallback: "status", footer: "turno ui install --help explains each option." });
276
274
  //# sourceMappingURL=ui.js.map
@@ -1,35 +1,156 @@
1
- import { listJournals, undoJournal } from "../../core/journal.js";
1
+ import { PRUNE_DEFAULT_AGE_MS, PRUNE_DEFAULT_KEEP, listJournals, parseAge, pruneJournals, undoJournal } from "../../core/journal.js";
2
2
  import { tildify } from "../../core/paths.js";
3
- import { DRY_RUN, FORCE, JSON_FLAG, bool, count, parseFlags, printJson } from "../args.js";
3
+ import { DRY_RUN, FORCE, JSON_FLAG, bool, count, parseFlags, printJson, str } from "../args.js";
4
4
  import { fail, paint } from "../io.js";
5
+ import { duration, style } from "../style.js";
5
6
  const USAGE = `Usage:
6
- turno undo --list [-n N] [--json] recent changes, newest first
7
- turno undo <stamp|last> [--dry-run] [--force]
8
- put back every file that change touched
7
+ turno undo --list [-n N] [--json] recent changes, newest first
8
+ turno undo <stamp|last> [--dry-run] [--force] [-v]
9
+ put back every file that change touched;
10
+ one line per folder, -v lists each change
11
+ turno undo --prune [--older-than 30d] [--keep 10] [--dry-run] [--json]
12
+ delete old backups
9
13
 
10
- Every command that writes your files (ui install, migrate, profile, config, mcp sync, identity)
11
- keeps a copy under ~/.local/state/turno/backups/<stamp>/ first. A file that changed again
12
- after that command is left alone unless --force. An undo is itself recorded, so it can be undone.`;
14
+ Every command that writes your files (ui install, profile, config, mcp sync,
15
+ mcp daemon, identity, uninstall) keeps a copy under
16
+ ~/.local/state/turno/backups/<stamp>/ first. A file that changed again after
17
+ that command is left alone unless --force. An undo is itself recorded, so it can
18
+ be undone.
19
+
20
+ profile add and profile repair also record the links, launchers and folders
21
+ they create and the files they move to .aside-<time>/: undo removes those links
22
+ and launchers, moves your files back and removes the .aside-* folder. A profile
23
+ folder is removed only when it is empty again; one that holds a login stays.
24
+ turno uninstall is recorded the same way, so undo puts back what it removed.
25
+
26
+ Backups can hold secrets that were in those files, so they are private (folders
27
+ 0700, files 0600) and pruned: each new backup deletes those older than 30 days,
28
+ keeping the newest 10. A backup that is still the only way back for a file it
29
+ changed (the file is unchanged since) is kept.`;
30
+ function prune(p, io) {
31
+ let olderThanMs = PRUNE_DEFAULT_AGE_MS;
32
+ const age = str(p, "older-than");
33
+ if (age !== undefined) {
34
+ try {
35
+ olderThanMs = parseAge(age);
36
+ }
37
+ catch (err) {
38
+ return fail(err.message);
39
+ }
40
+ }
41
+ const keepText = str(p, "keep");
42
+ const keep = keepText === undefined ? PRUNE_DEFAULT_KEEP : Number(keepText);
43
+ if (!Number.isInteger(keep) || keep < 0)
44
+ return fail("--keep must be a whole number");
45
+ const dry = bool(p, "dry-run");
46
+ const r = pruneJournals(io.env, { olderThanMs, keep, dryRun: dry });
47
+ if (bool(p, "json")) {
48
+ printJson(io, { dryRun: dry, pruned: r.pruned, kept: r.kept.map((k) => ({ stamp: k.stamp, path: tildify(k.path, io.env) })) });
49
+ return 0;
50
+ }
51
+ const verb = dry ? "would delete" : "deleted";
52
+ if (!r.pruned.length)
53
+ io.out("No backups to prune.");
54
+ else
55
+ io.out(`${verb} ${r.pruned.length} backup${r.pruned.length === 1 ? "" : "s"}: ${r.pruned.join(" ")}`);
56
+ for (const k of r.kept)
57
+ io.out(`kept ${k.stamp}: still undoable (${tildify(k.path, io.env)} is unchanged since)`);
58
+ return 0;
59
+ }
60
+ /** Paths under HOME inside a sentence, shown with ~. */
61
+ function tildifyText(text, env) {
62
+ return text
63
+ .split(" ")
64
+ .map((w) => (w.startsWith("/") ? tildify(w, env) : w))
65
+ .join(" ");
66
+ }
67
+ /** How each undo step reads: alone (with -v), and counted in a folder summary. */
68
+ const VERBS = {
69
+ restore: { one: "restored", done: "restored", noun: "files" },
70
+ delete: { one: "removed", done: "removed", noun: "files" },
71
+ skip: { one: "skipped", done: "skipped", noun: "files" },
72
+ unlink: { one: "removed link", done: "removed", noun: "links" },
73
+ link: { one: "linked again", done: "linked again", noun: "links" },
74
+ move: { one: "moved back", done: "moved back", noun: "files" },
75
+ rmdir: { one: "removed folder", done: "removed", noun: "folders" },
76
+ mkdir: { one: "made folder", done: "made again", noun: "folders" },
77
+ keep: { one: "kept", done: "kept", noun: "folders" },
78
+ chmod: { one: "mode put back", done: "mode put back", noun: "modes" },
79
+ };
80
+ /** Folders that hold other folders: a summary groups one level below them (~/.config/turno). */
81
+ const CONTAINERS = ["Library", ".config", ".local/state", ".local/share", ".local"];
82
+ const DIR_ACTIONS = new Set(["rmdir", "mkdir", "chmod", "keep"]);
83
+ /** The folder a step is summarized under (~/.claude-work, ~/.config/turno, ~/.local/bin), and its path in it. */
84
+ function folderOf(step, env) {
85
+ const t = tildify(step.path, env);
86
+ const isDir = DIR_ACTIONS.has(step.action);
87
+ if (!t.startsWith("~/")) {
88
+ if (isDir)
89
+ return { folder: t, rel: "" };
90
+ const cut = t.lastIndexOf("/");
91
+ return { folder: t.slice(0, Math.max(1, cut)), rel: t.slice(cut + 1) };
92
+ }
93
+ const parts = t.slice(2).split("/");
94
+ const container = CONTAINERS.find((c) => t.slice(2).startsWith(`${c}/`));
95
+ const depth = container ? container.split("/").length + 1 : 1;
96
+ if (parts.length > depth)
97
+ return { folder: `~/${parts.slice(0, depth).join("/")}`, rel: parts.slice(depth).join("/") };
98
+ if (isDir)
99
+ return { folder: t, rel: "" };
100
+ return { folder: parts.length > 1 ? `~/${parts.slice(0, -1).join("/")}` : "~", rel: parts[parts.length - 1] };
101
+ }
102
+ /** One line per folder: "23 links removed, settings.json moved back". */
103
+ export function summarize(steps, env) {
104
+ const groups = new Map();
105
+ for (const s of steps) {
106
+ const { folder, rel } = folderOf(s, env);
107
+ const g = groups.get(folder) ?? new Map();
108
+ g.set(s.action, [...(g.get(s.action) ?? []), rel]);
109
+ groups.set(folder, g);
110
+ }
111
+ // Folders in name order, HOME itself last.
112
+ const order = [...groups].sort(([a], [b]) => (a === "~" ? 1 : b === "~" ? -1 : a < b ? -1 : a > b ? 1 : 0));
113
+ return order.map(([folder, g]) => ({
114
+ folder,
115
+ skipped: g.has("skip"),
116
+ text: [...g].map(([action, rels]) => {
117
+ const v = VERBS[action];
118
+ if (rels.length > 1)
119
+ return `${rels.length} ${v.noun} ${v.done}`;
120
+ const rel = rels[0].replace(/^\.aside-[^/]*$/, "aside folder");
121
+ return `${rel || "folder"} ${v.done}`;
122
+ }),
123
+ }));
124
+ }
13
125
  function describe(j, io) {
14
126
  if (!j.manifest)
15
127
  return `${j.stamp} ${paint(io, "(older backup without a journal: restore by hand)", "2")}`;
16
128
  const m = j.manifest;
17
129
  const undone = m.undoneBy ? paint(io, ` undone by ${m.undoneBy}`, "2") : "";
18
- return `${j.stamp} ${m.command} (${m.entries.length} file${m.entries.length === 1 ? "" : "s"})${undone}`;
130
+ const n = m.entries.length;
131
+ const what = m.entries.every((e) => (e.kind ?? "file") === "file") ? `${n} file${n === 1 ? "" : "s"}` : `${n} change${n === 1 ? "" : "s"}`;
132
+ return `${j.stamp} ${m.command} (${what})${undone}`;
19
133
  }
20
134
  export const command = {
21
135
  summary: "list recent changes turno made to your files, and put any of them back",
22
136
  usage: USAGE,
23
137
  args: ["stamp"],
24
- flags: ["--list", "--dry-run", "--force", "--json", "--tail"],
138
+ flags: ["--list", "--verbose", "--dry-run", "--force", "--json", "--tail", "--prune", "--older-than", "--keep"],
25
139
  async run(args, io) {
26
- const p = parseFlags(args, { list: { type: "boolean" }, ...DRY_RUN, ...FORCE, ...JSON_FLAG, tail: { type: "string", short: "n" } }, 1);
140
+ const p = parseFlags(args, { list: { type: "boolean" }, prune: { type: "boolean" }, verbose: { type: "boolean", short: "v" }, "older-than": { type: "string" }, keep: { type: "string" }, ...DRY_RUN, ...FORCE, ...JSON_FLAG, tail: { type: "string", short: "n" } }, 1);
141
+ if (bool(p, "prune")) {
142
+ if (p.positionals.length)
143
+ return fail("--prune takes no stamp");
144
+ return prune(p, io);
145
+ }
146
+ if (str(p, "older-than") !== undefined || str(p, "keep") !== undefined)
147
+ return fail("--older-than and --keep go with --prune");
27
148
  const all = listJournals(io.env);
28
149
  const target = p.positionals[0];
29
150
  if (bool(p, "list") || !target) {
30
151
  const shown = all.slice(0, count(p, "tail", 10));
31
152
  if (bool(p, "json")) {
32
- printJson(io.out, shown.map((j) => ({ stamp: j.stamp, command: j.manifest?.command ?? null, files: j.manifest?.entries.map((e) => tildify(e.path, io.env)) ?? null, undoneBy: j.manifest?.undoneBy ?? null })));
153
+ printJson(io, shown.map((j) => ({ stamp: j.stamp, command: j.manifest?.command ?? null, files: j.manifest?.entries.map((e) => tildify(e.path, io.env)) ?? null, undoneBy: j.manifest?.undoneBy ?? null })));
33
154
  return 0;
34
155
  }
35
156
  if (!shown.length)
@@ -46,6 +167,7 @@ export const command = {
46
167
  if (info.manifest?.undoneBy && !bool(p, "force"))
47
168
  fail(`${info.stamp} was already undone by ${info.manifest.undoneBy} (turno undo ${info.manifest.undoneBy} redoes it)`);
48
169
  const dry = bool(p, "dry-run");
170
+ const started = Date.now();
49
171
  let result;
50
172
  try {
51
173
  result = undoJournal(info, io.env, { dryRun: dry, force: bool(p, "force") });
@@ -53,14 +175,35 @@ export const command = {
53
175
  catch (err) {
54
176
  return fail(err.message);
55
177
  }
56
- const d = dry ? " (dry run)" : "";
57
- io.out(`undo ${info.stamp}: ${info.manifest.command}${d}`);
58
- for (const s of result.steps) {
59
- const what = { restore: "restored", delete: "removed", skip: paint(io, "skipped", "33") }[s.action];
60
- io.out(` ${what} ${tildify(s.path, io.env)}${s.reason ? `: ${s.reason}` : ""}`);
178
+ const st = style(io);
179
+ io.out(`${st.bold(`undo ${info.stamp}`)} ${info.manifest.command}${dry ? st.muted(" (dry run)") : ""}`);
180
+ if (bool(p, "verbose")) {
181
+ for (const s of result.steps) {
182
+ const what = s.action === "chmod" ? `mode ${(s.mode ?? 0).toString(8)} again` : VERBS[s.action].one;
183
+ const from = s.from ? st.muted(` from ${tildify(s.from, io.env)}`) : "";
184
+ const text = `${s.action === "skip" ? st.warn(what) : what} ${tildify(s.path, io.env)}${from}${s.reason ? st.muted(`: ${tildifyText(s.reason, io.env)}`) : ""}`;
185
+ io.out(st.note(s.action === "skip" ? "warn" : s.action === "keep" ? "info" : "ok", text));
186
+ }
187
+ }
188
+ else {
189
+ const rows = summarize(result.steps, io.env).map(({ folder, text, skipped }) => [
190
+ st.icon(skipped ? "warn" : "ok"),
191
+ st.bold(folder),
192
+ text.map((t) => (t.startsWith("skipped") ? st.warn(t) : t)).join(st.muted(", ")),
193
+ ]);
194
+ for (const line of st.table(rows))
195
+ io.out(line);
196
+ // What was left alone, and why: never folded into a count.
197
+ for (const s of result.steps.filter((x) => x.action === "skip" || x.action === "keep")) {
198
+ const skip = s.action === "skip";
199
+ io.out(st.note(skip ? "warn" : "info", `${skip ? st.warn("skipped") : "kept"} ${tildify(s.path, io.env)}${s.reason ? st.muted(`: ${tildifyText(s.reason, io.env)}`) : ""}`));
200
+ }
61
201
  }
202
+ const n = result.steps.length;
203
+ io.out("");
204
+ io.out(st.wrap("", `${dry ? "Would put back" : "Put back"} ${n} ${n === 1 ? "change" : "changes"}${bool(p, "verbose") ? "" : st.muted(" (-v lists each one)")}${dry ? "" : st.muted(` in ${duration(Date.now() - started)}`)}.`));
62
205
  if (result.journal.used)
63
- io.out(`redo with: turno undo ${result.journal.stamp}`);
206
+ io.out(`${st.muted("Redo with:")} turno undo ${result.journal.stamp}`);
64
207
  return result.steps.some((s) => s.action === "skip") ? 1 : 0;
65
208
  },
66
209
  };