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
@@ -0,0 +1,481 @@
1
+ import { existsSync, lstatSync, readFileSync, readdirSync, rmSync, rmdirSync } from "node:fs";
2
+ import module from "node:module";
3
+ import { dirname, isAbsolute, join, resolve, sep } from "node:path";
4
+ import { parse as parseToml } from "smol-toml";
5
+ import { JSON_MCP_SERVERS, TOML_MCP_SERVERS } from "../../agents/adapter.js";
6
+ import { agentProfileDir } from "../../agents/index.js";
7
+ import { loadConfig, parseConfig } from "../../core/config.js";
8
+ import { Journal, listJournals } from "../../core/journal.js";
9
+ import { paths, tildify } from "../../core/paths.js";
10
+ import { agentOf, listProfiles } from "../../core/profiles.js";
11
+ import { profileTokenFile } from "../../mcpd/tokens.js";
12
+ import { currentStatusLine, isTurnoStatusLine, readSettings } from "../../ui/settings.js";
13
+ import { DRY_RUN, bool, parseFlags } from "../args.js";
14
+ import { compileCacheDir } from "../compile-cache.js";
15
+ import { confirm, needsAnswer } from "../io.js";
16
+ import { MARKER } from "../launchers.js";
17
+ import { realOr } from "../../core/fsutil.js";
18
+ /**
19
+ * `turno uninstall`: remove everything turno set up outside its package, through
20
+ * one journal, so `turno undo <stamp>` puts it back while turno is still installed. It never
21
+ * deletes a profile folder (they hold logins), turno's backups, or anything turno did not write.
22
+ */
23
+ const USAGE = `Usage: turno uninstall [--dry-run] [--yes] [--keep-config] [--purge]
24
+
25
+ Removes what turno set up on this machine, then tells you the command that
26
+ removes the package itself:
27
+ - the mcpd service (LaunchAgent or systemd user unit), and stops mcpd
28
+ - the MCP entries turno mcp sync added to agent configs (your own entries stay)
29
+ - the status line turno ui install set (the one you had before comes back)
30
+ - the launchers turno wrote in ~/.local/bin (claude-<name>, turno-auto, ...)
31
+ - turno's fish completion file, and the gateway token
32
+ - ~/.config/turno (config.toml, mcp.toml, accounts.toml), unless --keep-config
33
+
34
+ Profile folders (~/.claude-<name> and the like) hold your logins and history:
35
+ they stay, and the list says where they are. So do turno's backups under
36
+ ~/.local/state/turno, which let \`turno undo <stamp>\` put everything back
37
+ before you remove the package. Lines that load turno in your shell startup
38
+ files are listed for you to remove by hand.
39
+
40
+ --purge also removes turno's state and caches: ~/.local/state/turno (backups,
41
+ logs, usage, exhausted marks), ~/.cache/turno, and the MCP servers and caches
42
+ under ~/.local/share/turno. Then turno undo cannot put anything back. Browser
43
+ profiles with logins (~/.local/share/turno/chrome and browser) and profile
44
+ folders still stay.
45
+
46
+ --dry-run print the list and change nothing
47
+ --yes do not ask (needed when there is no terminal to ask in)
48
+ --keep-config keep ~/.config/turno
49
+ --purge remove turno's state and caches too (no undo)
50
+
51
+ Examples:
52
+ $ turno uninstall --dry-run
53
+ $ turno uninstall --yes --keep-config`;
54
+ function lstat(p) {
55
+ try {
56
+ return lstatSync(p);
57
+ }
58
+ catch {
59
+ return undefined;
60
+ }
61
+ }
62
+ function safeConfig(env) {
63
+ try {
64
+ return loadConfig(env);
65
+ }
66
+ catch {
67
+ return parseConfig("", paths(env).configFile, env);
68
+ }
69
+ }
70
+ /** Server names of an agent config file: `mcpServers` in JSON, `[mcp_servers.*]` in a Codex config.toml. */
71
+ function serverNames(file) {
72
+ try {
73
+ const text = readFileSync(file, "utf8");
74
+ const servers = file.endsWith(".toml")
75
+ ? parseToml(text).mcp_servers
76
+ : JSON.parse(text).mcpServers;
77
+ return servers && typeof servers === "object" ? Object.keys(servers) : [];
78
+ }
79
+ catch {
80
+ return [];
81
+ }
82
+ }
83
+ /** Launchers turno wrote: regular files in the launcher folder that carry its marker. */
84
+ function turnoLaunchers(env) {
85
+ const bin = paths(env).bin;
86
+ let names = [];
87
+ try {
88
+ names = readdirSync(bin).sort();
89
+ }
90
+ catch {
91
+ return [];
92
+ }
93
+ return names
94
+ .map((n) => join(bin, n))
95
+ .filter((f) => {
96
+ if (!lstat(f)?.isFile())
97
+ return false;
98
+ try {
99
+ return readFileSync(f, "utf8").slice(0, 400).includes(MARKER);
100
+ }
101
+ catch {
102
+ return false;
103
+ }
104
+ });
105
+ }
106
+ /**
107
+ * The status line to put back: the one the settings file had before the newest `ui install`
108
+ * that changed it to turno's, or none when it had none.
109
+ */
110
+ function statusLineBefore(file, env) {
111
+ const target = realOr(file);
112
+ for (const j of listJournals(env)) {
113
+ if (!j.manifest?.command.startsWith("ui install"))
114
+ continue;
115
+ const e = j.manifest.entries.find((x) => (x.kind ?? "file") === "file" && x.path === target);
116
+ if (!e)
117
+ continue;
118
+ if (!e.existed || !e.backup)
119
+ return undefined;
120
+ let before;
121
+ try {
122
+ before = JSON.parse(readFileSync(join(j.dir, e.backup), "utf8")).statusLine;
123
+ }
124
+ catch {
125
+ return undefined;
126
+ }
127
+ if (!before || typeof before !== "object")
128
+ return undefined;
129
+ if (!isTurnoStatusLine(before))
130
+ return before;
131
+ }
132
+ return undefined;
133
+ }
134
+ function walk(root) {
135
+ if (!lstat(root)?.isDirectory())
136
+ return undefined;
137
+ const out = { root, files: [], links: [], dirs: [] };
138
+ const visit = (dir) => {
139
+ for (const n of readdirSync(dir).sort()) {
140
+ const p = join(dir, n);
141
+ const st = lstat(p);
142
+ if (st?.isSymbolicLink())
143
+ out.links.push(p);
144
+ else if (st?.isDirectory())
145
+ visit(p);
146
+ else if (st?.isFile())
147
+ out.files.push(p);
148
+ }
149
+ out.dirs.push(dir);
150
+ };
151
+ visit(root);
152
+ return out;
153
+ }
154
+ const RC_FILES = [".zshrc", ".bashrc", ".bash_profile", ".profile", ".config/fish/config.fish"];
155
+ /**
156
+ * A folder --purge may remove whole: an absolute path that is neither the home folder, nor
157
+ * the root, nor a folder that holds the home folder (a TURNO_STATE_DIR set to one of those).
158
+ */
159
+ function purgeable(path, home) {
160
+ if (!isAbsolute(path))
161
+ return false;
162
+ const dir = realOr(resolve(path));
163
+ const h = realOr(resolve(home));
164
+ return dir !== sep && dir !== h && !h.startsWith(dir + sep);
165
+ }
166
+ export async function planUninstall(env, opts = {}) {
167
+ const p = paths(env);
168
+ const plan = {
169
+ configs: [],
170
+ launchers: [],
171
+ completions: [],
172
+ profileTokens: [],
173
+ purge: [],
174
+ manual: [],
175
+ kept: [],
176
+ };
177
+ // Only a service whose file is in this HOME: never ask the service manager about one it is not.
178
+ const { installedBackend } = await import("../../mcpd/service.js");
179
+ const backend = await installedBackend(env);
180
+ if (backend)
181
+ plan.service = { backend, file: backend.file(env) };
182
+ const { liveLock } = await import("../../mcpd/state.js");
183
+ const lock = liveLock(env);
184
+ if (lock && lock.pid !== process.pid)
185
+ plan.daemonPid = lock.pid;
186
+ const { readManaged } = await import("../../mcpd/sync.js");
187
+ const managed = readManaged(p.mcpdManaged);
188
+ for (const [file, names] of Object.entries(managed)) {
189
+ if (!existsSync(file))
190
+ continue;
191
+ const present = new Set(serverNames(file));
192
+ const mine = names.filter((n) => present.has(n));
193
+ if (mine.length)
194
+ plan.configs.push({ file, names: mine });
195
+ }
196
+ if (existsSync(p.mcpdManaged))
197
+ plan.managedFile = p.mcpdManaged;
198
+ const settings = join(p.hub, "settings.json");
199
+ if (isTurnoStatusLine(currentStatusLine(settings))) {
200
+ const restore = statusLineBefore(settings, env);
201
+ plan.statusLine = { file: settings, ...(restore ? { restore } : {}) };
202
+ }
203
+ plan.launchers = turnoLaunchers(env);
204
+ const fish = join(env.XDG_CONFIG_HOME || join(p.home, ".config"), "fish", "completions", "turno.fish");
205
+ try {
206
+ if (lstat(fish)?.isFile() && readFileSync(fish, "utf8").includes("turno __complete"))
207
+ plan.completions.push(fish);
208
+ }
209
+ catch {
210
+ /* unreadable: leave it */
211
+ }
212
+ for (const rc of RC_FILES) {
213
+ const file = join(p.home, rc);
214
+ let lines;
215
+ try {
216
+ lines = readFileSync(file, "utf8").split("\n");
217
+ }
218
+ catch {
219
+ continue;
220
+ }
221
+ lines.forEach((l, i) => {
222
+ if (/\bturno\s+completion\b/.test(l))
223
+ plan.manual.push(`${tildify(file, env)} line ${i + 1}: ${l.trim()}`);
224
+ });
225
+ }
226
+ if (existsSync(p.mcpdToken))
227
+ plan.token = p.mcpdToken;
228
+ const tokenDir = dirname(profileTokenFile("x", env));
229
+ if (existsSync(tokenDir)) {
230
+ for (const f of readdirSync(tokenDir))
231
+ if (f.endsWith(".token"))
232
+ plan.profileTokens.push(join(tokenDir, f));
233
+ }
234
+ if (opts.keepConfig) {
235
+ if (existsSync(p.config))
236
+ plan.kept.push(`${tildify(p.config, env)} stays (--keep-config)`);
237
+ }
238
+ else {
239
+ const c = walk(p.config);
240
+ if (c)
241
+ plan.turnoConfig = c;
242
+ }
243
+ const config = safeConfig(env);
244
+ for (const name of listProfiles(config, env)) {
245
+ const dir = agentProfileDir(name, agentOf(name, config), env);
246
+ if (existsSync(dir))
247
+ plan.kept.push(`${tildify(dir, env)} (profile ${name}: its login and history) stays; delete it by hand when you no longer need it`);
248
+ }
249
+ if (existsSync(p.chromeProfilesDir))
250
+ plan.kept.push(`${tildify(p.chromeProfilesDir, env)} (browser profiles with their logins) stays`);
251
+ const cache = dirname(compileCacheDir(env));
252
+ if (opts.purge) {
253
+ const targets = [
254
+ { path: p.state, what: "state: backups for turno undo, logs, usage" },
255
+ { path: cache, what: "caches" },
256
+ { path: p.serversDir, what: "MCP servers turno installed" },
257
+ { path: dirname(p.mcpdCacheDir), what: "mcpd's caches" },
258
+ ];
259
+ for (const t of targets)
260
+ if (lstat(t.path) && purgeable(t.path, p.home))
261
+ plan.purge.push(t);
262
+ if (existsSync(p.browserDir))
263
+ plan.kept.push(`${tildify(p.browserDir, env)} (turno-browser profiles with their logins) stays`);
264
+ }
265
+ else {
266
+ if (existsSync(p.data))
267
+ plan.kept.push(`${tildify(p.data, env)} (installed MCP servers, caches) stays`);
268
+ plan.kept.push(`${tildify(p.state, env)} (backups for turno undo, logs) stays`);
269
+ if (existsSync(cache))
270
+ plan.kept.push(`${tildify(cache, env)} (compiled code, safe to delete) stays`);
271
+ }
272
+ plan.kept.push("secrets you stored with turno secret stay in the Keychain or Secret Service (turno secret --help)");
273
+ return plan;
274
+ }
275
+ function isEmpty(plan) {
276
+ return (!plan.service &&
277
+ !plan.daemonPid &&
278
+ !plan.configs.length &&
279
+ !plan.statusLine &&
280
+ !plan.launchers.length &&
281
+ !plan.completions.length &&
282
+ !plan.token &&
283
+ !plan.profileTokens.length &&
284
+ !plan.turnoConfig &&
285
+ !plan.purge.length);
286
+ }
287
+ function describe(plan, env) {
288
+ const t = (p) => tildify(p, env);
289
+ const out = [];
290
+ if (plan.service)
291
+ out.push(`the mcpd ${plan.service.backend.noun} ${t(plan.service.file)}`);
292
+ if (plan.daemonPid)
293
+ out.push(`stop mcpd (pid ${plan.daemonPid})`);
294
+ for (const c of plan.configs)
295
+ out.push(`MCP entries turno added: ${c.names.join(", ")} from ${t(c.file)}`);
296
+ if (plan.statusLine) {
297
+ const back = plan.statusLine.restore ? `; your earlier one comes back: ${plan.statusLine.restore.command}` : "";
298
+ out.push(`the statusLine turno set in ${t(plan.statusLine.file)}${back}`);
299
+ }
300
+ for (const l of plan.launchers)
301
+ out.push(`launcher ${t(l)}`);
302
+ for (const c of plan.completions)
303
+ out.push(`completion ${t(c)}`);
304
+ if (plan.token)
305
+ out.push(`the gateway token ${t(plan.token)}`);
306
+ if (plan.profileTokens.length)
307
+ out.push(`${plan.profileTokens.length} profile gateway token file${plan.profileTokens.length === 1 ? "" : "s"} in ${t(dirname(plan.profileTokens[0]))}`);
308
+ if (plan.turnoConfig) {
309
+ const names = plan.turnoConfig.files.map((f) => f.slice(plan.turnoConfig.root.length + 1));
310
+ out.push(`${t(plan.turnoConfig.root)}${names.length ? ` (${names.join(", ")})` : ""}`);
311
+ }
312
+ for (const x of plan.purge)
313
+ out.push(`${t(x.path)} (${x.what}; --purge, no undo)`);
314
+ return out;
315
+ }
316
+ /** The command that removes the package: Homebrew when this turno runs from a Cellar, else npm. */
317
+ export function packageRemoval(argv1 = process.argv[1]) {
318
+ const file = argv1 ? realOr(argv1) : "";
319
+ return /\/Cellar\/|\/homebrew\//i.test(file) ? "brew uninstall turno" : "npm uninstall --global turno-cli";
320
+ }
321
+ async function apply(plan, journal, io) {
322
+ const env = io.env;
323
+ const { ServiceError } = await import("../../mcpd/service.js");
324
+ if (plan.service) {
325
+ const { removeService } = await import("../../mcpd/service.js");
326
+ try {
327
+ await removeService(plan.service.backend, env, journal);
328
+ }
329
+ catch (err) {
330
+ if (!(err instanceof ServiceError))
331
+ throw err;
332
+ // The file still goes, so the service does not come back at the next login.
333
+ io.err(`turno: warning: ${err.message}`);
334
+ if (existsSync(plan.service.file))
335
+ journal.remove(plan.service.file);
336
+ }
337
+ }
338
+ if (plan.daemonPid) {
339
+ const { liveLock } = await import("../../mcpd/state.js");
340
+ try {
341
+ process.kill(plan.daemonPid, "SIGTERM");
342
+ }
343
+ catch {
344
+ /* gone already */
345
+ }
346
+ for (let waited = 0; waited < 5000 && liveLock(env); waited += 250)
347
+ await new Promise((r) => setTimeout(r, 250));
348
+ }
349
+ if (plan.configs.length) {
350
+ const { syncServers } = await import("../../mcpd/sync.js");
351
+ for (const c of plan.configs) {
352
+ const at = journal.save(c.file);
353
+ syncServers(c.file, c.file.endsWith(".toml") ? TOML_MCP_SERVERS : JSON_MCP_SERVERS, {}, c.names);
354
+ journal.settle(at);
355
+ }
356
+ }
357
+ if (plan.managedFile && existsSync(plan.managedFile))
358
+ journal.remove(plan.managedFile);
359
+ if (plan.statusLine) {
360
+ const settings = readSettings(plan.statusLine.file);
361
+ if (plan.statusLine.restore)
362
+ settings.statusLine = plan.statusLine.restore;
363
+ else
364
+ delete settings.statusLine;
365
+ journal.write(plan.statusLine.file, `${JSON.stringify(settings, null, 2)}\n`);
366
+ }
367
+ for (const l of plan.launchers)
368
+ journal.remove(l);
369
+ for (const c of plan.completions)
370
+ journal.remove(c);
371
+ if (plan.token)
372
+ journal.remove(plan.token);
373
+ for (const f of plan.profileTokens)
374
+ journal.remove(f);
375
+ if (plan.turnoConfig) {
376
+ for (const f of plan.turnoConfig.files)
377
+ journal.remove(f);
378
+ for (const l of plan.turnoConfig.links)
379
+ journal.unlink(l);
380
+ for (const d of plan.turnoConfig.dirs) {
381
+ try {
382
+ journal.rmdir(d);
383
+ }
384
+ catch {
385
+ io.err(`turno: warning: ${tildify(d, env)} holds something turno cannot remove; it stays`);
386
+ }
387
+ }
388
+ }
389
+ }
390
+ /**
391
+ * --purge, after everything else: turno's state (with the journal just written), caches and
392
+ * installed servers go whole. Node's pending compile cache entries are written first, so
393
+ * nothing is left to write into ~/.cache/turno when this process exits.
394
+ */
395
+ function purge(plan, io) {
396
+ try {
397
+ module.flushCompileCache?.();
398
+ }
399
+ catch {
400
+ /* the cache is best effort */
401
+ }
402
+ for (const x of plan.purge) {
403
+ try {
404
+ rmSync(x.path, { recursive: true, force: true });
405
+ }
406
+ catch (err) {
407
+ io.err(`turno: warning: could not remove ${tildify(x.path, io.env)}: ${err.message}`);
408
+ }
409
+ }
410
+ // The data folder goes too once nothing of the person's is left in it.
411
+ const data = paths(io.env).data;
412
+ try {
413
+ if (plan.purge.some((x) => dirname(x.path) === data) && readdirSync(data).length === 0)
414
+ rmdirSync(data);
415
+ }
416
+ catch {
417
+ /* gone already, or not empty */
418
+ }
419
+ }
420
+ export const command = {
421
+ summary: "remove the service, launchers, status line and MCP entries turno set up (profile folders stay)",
422
+ usage: USAGE,
423
+ flags: ["--dry-run", "--yes", "--keep-config", "--purge"],
424
+ async run(args, io) {
425
+ const p = parseFlags(args, {
426
+ ...DRY_RUN,
427
+ yes: { type: "boolean", short: "y" },
428
+ "keep-config": { type: "boolean" },
429
+ purge: { type: "boolean" },
430
+ }, 0);
431
+ const dry = bool(p, "dry-run");
432
+ const plan = await planUninstall(io.env, { keepConfig: bool(p, "keep-config"), purge: bool(p, "purge") });
433
+ const remove = describe(plan, io.env);
434
+ const last = `Last step, to remove the package: ${packageRemoval()}`;
435
+ const printStays = () => {
436
+ if (plan.manual.length) {
437
+ io.out("Remove by hand (turno does not edit shell startup files):");
438
+ for (const m of plan.manual)
439
+ io.out(` - ${m}`);
440
+ }
441
+ io.out("Stays:");
442
+ for (const k of plan.kept)
443
+ io.out(` - ${k}`);
444
+ };
445
+ if (isEmpty(plan)) {
446
+ io.out("Nothing of turno's to remove on this machine.");
447
+ printStays();
448
+ io.out(last);
449
+ return 0;
450
+ }
451
+ io.out(dry ? "turno uninstall would remove:" : "turno uninstall removes:");
452
+ for (const r of remove)
453
+ io.out(` - ${r}`);
454
+ printStays();
455
+ if (dry) {
456
+ io.out(last);
457
+ return 0;
458
+ }
459
+ if (!bool(p, "yes")) {
460
+ if (!io.ask)
461
+ needsAnswer("uninstall");
462
+ if (!(await confirm(io, "Remove all of this?"))) {
463
+ io.err("Nothing changed.");
464
+ return 1;
465
+ }
466
+ }
467
+ const journal = new Journal(io.env, `uninstall${bool(p, "keep-config") ? " --keep-config" : ""}`);
468
+ await apply(plan, journal, io);
469
+ if (plan.purge.length)
470
+ purge(plan, io);
471
+ io.out("Done.");
472
+ if (plan.purge.length)
473
+ io.out("--purge removed turno's backups too, so turno undo cannot put this back.");
474
+ else if (journal.used) {
475
+ io.out(`Changed your mind? turno undo ${journal.stamp} puts it all back while turno is still installed (then turno mcp daemon start).`);
476
+ }
477
+ io.out(last);
478
+ return 0;
479
+ },
480
+ };
481
+ //# sourceMappingURL=uninstall.js.map