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