turno-cli 0.1.1 → 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.
- package/CHANGELOG.md +284 -0
- package/README.md +120 -53
- package/dist/accounts/audit.js +137 -7
- package/dist/accounts/builtin.js +68 -21
- package/dist/accounts/delegate.js +176 -35
- package/dist/accounts/policy.js +77 -0
- package/dist/accounts/registry.js +37 -21
- package/dist/agents/adapter.js +7 -0
- package/dist/agents/claude.js +195 -0
- package/dist/agents/codex.js +98 -0
- package/dist/agents/copilot.js +39 -0
- package/dist/agents/cursor.js +41 -0
- package/dist/agents/index.js +26 -86
- package/dist/agents/snippets.js +7 -4
- package/dist/cli/args.js +19 -4
- package/dist/cli/commands/accounts.js +96 -51
- package/dist/cli/commands/auto.js +82 -32
- package/dist/cli/commands/browser.js +216 -135
- package/dist/cli/commands/complete.js +2 -1
- package/dist/cli/commands/completion.js +4 -2
- package/dist/cli/commands/config.js +103 -18
- package/dist/cli/commands/demo.js +292 -0
- package/dist/cli/commands/doctor.js +387 -119
- package/dist/cli/commands/handoff.js +33 -22
- package/dist/cli/commands/identity.js +101 -50
- package/dist/cli/commands/init.js +616 -0
- package/dist/cli/commands/limit.js +25 -13
- package/dist/cli/commands/mcp-oauth.js +194 -0
- package/dist/cli/commands/mcp-observe.js +434 -0
- package/dist/cli/commands/mcp.js +653 -185
- package/dist/cli/commands/mcpd.js +323 -75
- package/dist/cli/commands/migrate.js +6 -4
- package/dist/cli/commands/open.js +92 -27
- package/dist/cli/commands/profile.js +205 -69
- package/dist/cli/commands/resolve.js +6 -2
- package/dist/cli/commands/run.js +15 -5
- package/dist/cli/commands/secret.js +61 -42
- package/dist/cli/commands/session.js +2 -2
- package/dist/cli/commands/sessions.js +42 -12
- package/dist/cli/commands/setup.js +136 -158
- package/dist/cli/commands/status.js +172 -41
- package/dist/cli/commands/statusline.js +305 -113
- package/dist/cli/commands/ui.js +64 -66
- package/dist/cli/commands/undo.js +161 -18
- package/dist/cli/commands/uninstall.js +462 -0
- package/dist/cli/commands/upgrade.js +75 -19
- package/dist/cli/commands/usage.js +117 -44
- package/dist/cli/commands/version.js +7 -5
- package/dist/cli/commands/which.js +7 -24
- package/dist/cli/compile-cache.js +32 -0
- package/dist/cli/group.js +10 -10
- package/dist/cli/help.js +57 -0
- package/dist/cli/highlight.js +236 -0
- package/dist/cli/io.js +170 -1
- package/dist/cli/launch.js +21 -37
- package/dist/cli/launchers.js +145 -94
- package/dist/cli/main.js +163 -27
- package/dist/cli/picker.js +447 -0
- package/dist/cli/registry.js +42 -5
- package/dist/cli/security.js +539 -0
- package/dist/cli/style.js +281 -0
- package/dist/core/config.js +145 -23
- package/dist/core/exhausted.js +6 -8
- package/dist/core/fsutil.js +47 -0
- package/dist/core/journal.js +281 -11
- package/dist/core/manifest.js +126 -6
- package/dist/core/paths.js +114 -7
- package/dist/core/profiles.js +139 -9
- package/dist/core/resolve.js +129 -23
- package/dist/core/secrets.js +215 -20
- package/dist/core/sessions.js +13 -20
- package/dist/core/update.js +18 -8
- package/dist/demo/server.js +34 -0
- package/dist/mcpd/cache.js +18 -4
- package/dist/mcpd/calllog.js +253 -0
- package/dist/mcpd/client-names.js +51 -0
- package/dist/mcpd/connectors.js +148 -17
- package/dist/mcpd/daemon.js +452 -116
- package/dist/mcpd/folder-sets.js +39 -0
- package/dist/mcpd/gateway.js +441 -47
- package/dist/mcpd/health.js +269 -0
- package/dist/mcpd/importer.js +356 -36
- package/dist/mcpd/instances.js +425 -65
- package/dist/mcpd/jsonrpc.js +8 -0
- package/dist/mcpd/launchd.js +65 -48
- package/dist/mcpd/modern.js +648 -0
- package/dist/mcpd/oauth.js +791 -0
- package/dist/mcpd/peerpid.js +122 -6
- package/dist/mcpd/pressure.js +85 -0
- package/dist/mcpd/rss.js +151 -0
- package/dist/mcpd/service.js +167 -0
- package/dist/mcpd/state.js +183 -0
- package/dist/mcpd/sync.js +55 -80
- package/dist/mcpd/systemd.js +80 -0
- package/dist/mcpd/tokens.js +89 -0
- package/dist/mcpd/upstream.js +154 -44
- package/dist/statusline/cost.js +154 -44
- package/dist/statusline/input.js +66 -0
- package/dist/statusline/render.js +9 -3
- package/dist/ui/fonts.js +8 -3
- package/dist/ui/settings.js +27 -15
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +6 -6
- package/dist/cli/commands/available.js +0 -18
|
@@ -0,0 +1,462 @@
|
|
|
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` (ADR 0025): 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
|
+
function lstat(p) {
|
|
51
|
+
try {
|
|
52
|
+
return lstatSync(p);
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
return undefined;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
function safeConfig(env) {
|
|
59
|
+
try {
|
|
60
|
+
return loadConfig(env);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return parseConfig("", paths(env).configFile, env);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/** Server names of an agent config file: `mcpServers` in JSON, `[mcp_servers.*]` in a Codex config.toml. */
|
|
67
|
+
function serverNames(file) {
|
|
68
|
+
try {
|
|
69
|
+
const text = readFileSync(file, "utf8");
|
|
70
|
+
const servers = file.endsWith(".toml") ? parseToml(text).mcp_servers : JSON.parse(text).mcpServers;
|
|
71
|
+
return servers && typeof servers === "object" ? Object.keys(servers) : [];
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Launchers turno wrote: regular files in the launcher folder that carry its marker. */
|
|
78
|
+
function turnoLaunchers(env) {
|
|
79
|
+
const bin = paths(env).bin;
|
|
80
|
+
let names = [];
|
|
81
|
+
try {
|
|
82
|
+
names = readdirSync(bin).sort();
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
return [];
|
|
86
|
+
}
|
|
87
|
+
return names
|
|
88
|
+
.map((n) => join(bin, n))
|
|
89
|
+
.filter((f) => {
|
|
90
|
+
if (!lstat(f)?.isFile())
|
|
91
|
+
return false;
|
|
92
|
+
try {
|
|
93
|
+
return readFileSync(f, "utf8").slice(0, 400).includes(MARKER);
|
|
94
|
+
}
|
|
95
|
+
catch {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The status line to put back: the one the settings file had before the newest `ui install`
|
|
102
|
+
* that changed it to turno's, or none when it had none.
|
|
103
|
+
*/
|
|
104
|
+
function statusLineBefore(file, env) {
|
|
105
|
+
const target = realOr(file);
|
|
106
|
+
for (const j of listJournals(env)) {
|
|
107
|
+
if (!j.manifest?.command.startsWith("ui install"))
|
|
108
|
+
continue;
|
|
109
|
+
const e = j.manifest.entries.find((x) => (x.kind ?? "file") === "file" && x.path === target);
|
|
110
|
+
if (!e)
|
|
111
|
+
continue;
|
|
112
|
+
if (!e.existed || !e.backup)
|
|
113
|
+
return undefined;
|
|
114
|
+
let before;
|
|
115
|
+
try {
|
|
116
|
+
before = JSON.parse(readFileSync(join(j.dir, e.backup), "utf8")).statusLine;
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (!before || typeof before !== "object")
|
|
122
|
+
return undefined;
|
|
123
|
+
if (!isTurnoStatusLine(before))
|
|
124
|
+
return before;
|
|
125
|
+
}
|
|
126
|
+
return undefined;
|
|
127
|
+
}
|
|
128
|
+
function walk(root) {
|
|
129
|
+
if (!lstat(root)?.isDirectory())
|
|
130
|
+
return undefined;
|
|
131
|
+
const out = { root, files: [], links: [], dirs: [] };
|
|
132
|
+
const visit = (dir) => {
|
|
133
|
+
for (const n of readdirSync(dir).sort()) {
|
|
134
|
+
const p = join(dir, n);
|
|
135
|
+
const st = lstat(p);
|
|
136
|
+
if (st?.isSymbolicLink())
|
|
137
|
+
out.links.push(p);
|
|
138
|
+
else if (st?.isDirectory())
|
|
139
|
+
visit(p);
|
|
140
|
+
else if (st?.isFile())
|
|
141
|
+
out.files.push(p);
|
|
142
|
+
}
|
|
143
|
+
out.dirs.push(dir);
|
|
144
|
+
};
|
|
145
|
+
visit(root);
|
|
146
|
+
return out;
|
|
147
|
+
}
|
|
148
|
+
const RC_FILES = [".zshrc", ".bashrc", ".bash_profile", ".profile", ".config/fish/config.fish"];
|
|
149
|
+
/**
|
|
150
|
+
* A folder --purge may remove whole: an absolute path that is neither the home folder, nor
|
|
151
|
+
* the root, nor a folder that holds the home folder (a TURNO_STATE_DIR set to one of those).
|
|
152
|
+
*/
|
|
153
|
+
function purgeable(path, home) {
|
|
154
|
+
if (!isAbsolute(path))
|
|
155
|
+
return false;
|
|
156
|
+
const dir = realOr(resolve(path));
|
|
157
|
+
const h = realOr(resolve(home));
|
|
158
|
+
return dir !== sep && dir !== h && !h.startsWith(dir + sep);
|
|
159
|
+
}
|
|
160
|
+
export async function planUninstall(env, opts = {}) {
|
|
161
|
+
const p = paths(env);
|
|
162
|
+
const plan = { configs: [], launchers: [], completions: [], profileTokens: [], purge: [], manual: [], kept: [] };
|
|
163
|
+
// Only a service whose file is in this HOME: never ask the service manager about one it is not.
|
|
164
|
+
const { installedBackend } = await import("../../mcpd/service.js");
|
|
165
|
+
const backend = await installedBackend(env);
|
|
166
|
+
if (backend)
|
|
167
|
+
plan.service = { backend, file: backend.file(env) };
|
|
168
|
+
const { liveLock } = await import("../../mcpd/state.js");
|
|
169
|
+
const lock = liveLock(env);
|
|
170
|
+
if (lock && lock.pid !== process.pid)
|
|
171
|
+
plan.daemonPid = lock.pid;
|
|
172
|
+
const { readManaged } = await import("../../mcpd/sync.js");
|
|
173
|
+
const managed = readManaged(p.mcpdManaged);
|
|
174
|
+
for (const [file, names] of Object.entries(managed)) {
|
|
175
|
+
if (!existsSync(file))
|
|
176
|
+
continue;
|
|
177
|
+
const present = new Set(serverNames(file));
|
|
178
|
+
const mine = names.filter((n) => present.has(n));
|
|
179
|
+
if (mine.length)
|
|
180
|
+
plan.configs.push({ file, names: mine });
|
|
181
|
+
}
|
|
182
|
+
if (existsSync(p.mcpdManaged))
|
|
183
|
+
plan.managedFile = p.mcpdManaged;
|
|
184
|
+
const settings = join(p.hub, "settings.json");
|
|
185
|
+
if (isTurnoStatusLine(currentStatusLine(settings))) {
|
|
186
|
+
const restore = statusLineBefore(settings, env);
|
|
187
|
+
plan.statusLine = { file: settings, ...(restore ? { restore } : {}) };
|
|
188
|
+
}
|
|
189
|
+
plan.launchers = turnoLaunchers(env);
|
|
190
|
+
const fish = join(env.XDG_CONFIG_HOME || join(p.home, ".config"), "fish", "completions", "turno.fish");
|
|
191
|
+
try {
|
|
192
|
+
if (lstat(fish)?.isFile() && readFileSync(fish, "utf8").includes("turno __complete"))
|
|
193
|
+
plan.completions.push(fish);
|
|
194
|
+
}
|
|
195
|
+
catch {
|
|
196
|
+
/* unreadable: leave it */
|
|
197
|
+
}
|
|
198
|
+
for (const rc of RC_FILES) {
|
|
199
|
+
const file = join(p.home, rc);
|
|
200
|
+
let lines;
|
|
201
|
+
try {
|
|
202
|
+
lines = readFileSync(file, "utf8").split("\n");
|
|
203
|
+
}
|
|
204
|
+
catch {
|
|
205
|
+
continue;
|
|
206
|
+
}
|
|
207
|
+
lines.forEach((l, i) => {
|
|
208
|
+
if (/\bturno\s+completion\b/.test(l))
|
|
209
|
+
plan.manual.push(`${tildify(file, env)} line ${i + 1}: ${l.trim()}`);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
if (existsSync(p.mcpdToken))
|
|
213
|
+
plan.token = p.mcpdToken;
|
|
214
|
+
const tokenDir = dirname(profileTokenFile("x", env));
|
|
215
|
+
if (existsSync(tokenDir)) {
|
|
216
|
+
for (const f of readdirSync(tokenDir))
|
|
217
|
+
if (f.endsWith(".token"))
|
|
218
|
+
plan.profileTokens.push(join(tokenDir, f));
|
|
219
|
+
}
|
|
220
|
+
if (opts.keepConfig) {
|
|
221
|
+
if (existsSync(p.config))
|
|
222
|
+
plan.kept.push(`${tildify(p.config, env)} stays (--keep-config)`);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
const c = walk(p.config);
|
|
226
|
+
if (c)
|
|
227
|
+
plan.turnoConfig = c;
|
|
228
|
+
}
|
|
229
|
+
const config = safeConfig(env);
|
|
230
|
+
for (const name of listProfiles(config, env)) {
|
|
231
|
+
const dir = agentProfileDir(name, agentOf(name, config), env);
|
|
232
|
+
if (existsSync(dir))
|
|
233
|
+
plan.kept.push(`${tildify(dir, env)} (profile ${name}: its login and history) stays; delete it by hand when you no longer need it`);
|
|
234
|
+
}
|
|
235
|
+
if (existsSync(p.chromeProfilesDir))
|
|
236
|
+
plan.kept.push(`${tildify(p.chromeProfilesDir, env)} (browser profiles with their logins) stays`);
|
|
237
|
+
const cache = dirname(compileCacheDir(env));
|
|
238
|
+
if (opts.purge) {
|
|
239
|
+
const targets = [
|
|
240
|
+
{ path: p.state, what: "state: backups for turno undo, logs, usage" },
|
|
241
|
+
{ path: cache, what: "caches" },
|
|
242
|
+
{ path: p.serversDir, what: "MCP servers turno installed" },
|
|
243
|
+
{ path: dirname(p.mcpdCacheDir), what: "mcpd's caches" },
|
|
244
|
+
];
|
|
245
|
+
for (const t of targets)
|
|
246
|
+
if (lstat(t.path) && purgeable(t.path, p.home))
|
|
247
|
+
plan.purge.push(t);
|
|
248
|
+
if (existsSync(p.browserDir))
|
|
249
|
+
plan.kept.push(`${tildify(p.browserDir, env)} (turno-browser profiles with their logins) stays`);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
if (existsSync(p.data))
|
|
253
|
+
plan.kept.push(`${tildify(p.data, env)} (installed MCP servers, caches) stays`);
|
|
254
|
+
plan.kept.push(`${tildify(p.state, env)} (backups for turno undo, logs) stays`);
|
|
255
|
+
if (existsSync(cache))
|
|
256
|
+
plan.kept.push(`${tildify(cache, env)} (compiled code, safe to delete) stays`);
|
|
257
|
+
}
|
|
258
|
+
plan.kept.push("secrets you stored with turno secret stay in the Keychain or Secret Service (turno secret --help)");
|
|
259
|
+
return plan;
|
|
260
|
+
}
|
|
261
|
+
function isEmpty(plan) {
|
|
262
|
+
return (!plan.service &&
|
|
263
|
+
!plan.daemonPid &&
|
|
264
|
+
!plan.configs.length &&
|
|
265
|
+
!plan.statusLine &&
|
|
266
|
+
!plan.launchers.length &&
|
|
267
|
+
!plan.completions.length &&
|
|
268
|
+
!plan.token &&
|
|
269
|
+
!plan.profileTokens.length &&
|
|
270
|
+
!plan.turnoConfig &&
|
|
271
|
+
!plan.purge.length);
|
|
272
|
+
}
|
|
273
|
+
function describe(plan, env) {
|
|
274
|
+
const t = (p) => tildify(p, env);
|
|
275
|
+
const out = [];
|
|
276
|
+
if (plan.service)
|
|
277
|
+
out.push(`the mcpd ${plan.service.backend.noun} ${t(plan.service.file)}`);
|
|
278
|
+
if (plan.daemonPid)
|
|
279
|
+
out.push(`stop mcpd (pid ${plan.daemonPid})`);
|
|
280
|
+
for (const c of plan.configs)
|
|
281
|
+
out.push(`MCP entries turno added: ${c.names.join(", ")} from ${t(c.file)}`);
|
|
282
|
+
if (plan.statusLine) {
|
|
283
|
+
const back = plan.statusLine.restore ? `; your earlier one comes back: ${plan.statusLine.restore.command}` : "";
|
|
284
|
+
out.push(`the statusLine turno set in ${t(plan.statusLine.file)}${back}`);
|
|
285
|
+
}
|
|
286
|
+
for (const l of plan.launchers)
|
|
287
|
+
out.push(`launcher ${t(l)}`);
|
|
288
|
+
for (const c of plan.completions)
|
|
289
|
+
out.push(`completion ${t(c)}`);
|
|
290
|
+
if (plan.token)
|
|
291
|
+
out.push(`the gateway token ${t(plan.token)}`);
|
|
292
|
+
if (plan.profileTokens.length)
|
|
293
|
+
out.push(`${plan.profileTokens.length} profile gateway token file${plan.profileTokens.length === 1 ? "" : "s"} in ${t(dirname(plan.profileTokens[0]))}`);
|
|
294
|
+
if (plan.turnoConfig) {
|
|
295
|
+
const names = plan.turnoConfig.files.map((f) => f.slice(plan.turnoConfig.root.length + 1));
|
|
296
|
+
out.push(`${t(plan.turnoConfig.root)}${names.length ? ` (${names.join(", ")})` : ""}`);
|
|
297
|
+
}
|
|
298
|
+
for (const x of plan.purge)
|
|
299
|
+
out.push(`${t(x.path)} (${x.what}; --purge, no undo)`);
|
|
300
|
+
return out;
|
|
301
|
+
}
|
|
302
|
+
/** The command that removes the package: Homebrew when this turno runs from a Cellar, else npm. */
|
|
303
|
+
export function packageRemoval(argv1 = process.argv[1]) {
|
|
304
|
+
const file = argv1 ? realOr(argv1) : "";
|
|
305
|
+
return /\/Cellar\/|\/homebrew\//i.test(file) ? "brew uninstall turno" : "npm uninstall --global turno-cli";
|
|
306
|
+
}
|
|
307
|
+
async function apply(plan, journal, io) {
|
|
308
|
+
const env = io.env;
|
|
309
|
+
const { ServiceError } = await import("../../mcpd/service.js");
|
|
310
|
+
if (plan.service) {
|
|
311
|
+
const { removeService } = await import("../../mcpd/service.js");
|
|
312
|
+
try {
|
|
313
|
+
await removeService(plan.service.backend, env, journal);
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
if (!(err instanceof ServiceError))
|
|
317
|
+
throw err;
|
|
318
|
+
// The file still goes, so the service does not come back at the next login.
|
|
319
|
+
io.err(`turno: warning: ${err.message}`);
|
|
320
|
+
if (existsSync(plan.service.file))
|
|
321
|
+
journal.remove(plan.service.file);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (plan.daemonPid) {
|
|
325
|
+
const { liveLock } = await import("../../mcpd/state.js");
|
|
326
|
+
try {
|
|
327
|
+
process.kill(plan.daemonPid, "SIGTERM");
|
|
328
|
+
}
|
|
329
|
+
catch {
|
|
330
|
+
/* gone already */
|
|
331
|
+
}
|
|
332
|
+
for (let waited = 0; waited < 5000 && liveLock(env); waited += 250)
|
|
333
|
+
await new Promise((r) => setTimeout(r, 250));
|
|
334
|
+
}
|
|
335
|
+
if (plan.configs.length) {
|
|
336
|
+
const { syncServers } = await import("../../mcpd/sync.js");
|
|
337
|
+
for (const c of plan.configs) {
|
|
338
|
+
const at = journal.save(c.file);
|
|
339
|
+
syncServers(c.file, c.file.endsWith(".toml") ? TOML_MCP_SERVERS : JSON_MCP_SERVERS, {}, c.names);
|
|
340
|
+
journal.settle(at);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
if (plan.managedFile && existsSync(plan.managedFile))
|
|
344
|
+
journal.remove(plan.managedFile);
|
|
345
|
+
if (plan.statusLine) {
|
|
346
|
+
const settings = readSettings(plan.statusLine.file);
|
|
347
|
+
if (plan.statusLine.restore)
|
|
348
|
+
settings.statusLine = plan.statusLine.restore;
|
|
349
|
+
else
|
|
350
|
+
delete settings.statusLine;
|
|
351
|
+
journal.write(plan.statusLine.file, `${JSON.stringify(settings, null, 2)}\n`);
|
|
352
|
+
}
|
|
353
|
+
for (const l of plan.launchers)
|
|
354
|
+
journal.remove(l);
|
|
355
|
+
for (const c of plan.completions)
|
|
356
|
+
journal.remove(c);
|
|
357
|
+
if (plan.token)
|
|
358
|
+
journal.remove(plan.token);
|
|
359
|
+
for (const f of plan.profileTokens)
|
|
360
|
+
journal.remove(f);
|
|
361
|
+
if (plan.turnoConfig) {
|
|
362
|
+
for (const f of plan.turnoConfig.files)
|
|
363
|
+
journal.remove(f);
|
|
364
|
+
for (const l of plan.turnoConfig.links)
|
|
365
|
+
journal.unlink(l);
|
|
366
|
+
for (const d of plan.turnoConfig.dirs) {
|
|
367
|
+
try {
|
|
368
|
+
journal.rmdir(d);
|
|
369
|
+
}
|
|
370
|
+
catch {
|
|
371
|
+
io.err(`turno: warning: ${tildify(d, env)} holds something turno cannot remove; it stays`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* --purge, after everything else: turno's state (with the journal just written), caches and
|
|
378
|
+
* installed servers go whole. Node's pending compile cache entries are written first, so
|
|
379
|
+
* nothing is left to write into ~/.cache/turno when this process exits.
|
|
380
|
+
*/
|
|
381
|
+
function purge(plan, io) {
|
|
382
|
+
try {
|
|
383
|
+
module.flushCompileCache?.();
|
|
384
|
+
}
|
|
385
|
+
catch {
|
|
386
|
+
/* the cache is best effort */
|
|
387
|
+
}
|
|
388
|
+
for (const x of plan.purge) {
|
|
389
|
+
try {
|
|
390
|
+
rmSync(x.path, { recursive: true, force: true });
|
|
391
|
+
}
|
|
392
|
+
catch (err) {
|
|
393
|
+
io.err(`turno: warning: could not remove ${tildify(x.path, io.env)}: ${err.message}`);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
// The data folder goes too once nothing of the person's is left in it.
|
|
397
|
+
const data = paths(io.env).data;
|
|
398
|
+
try {
|
|
399
|
+
if (plan.purge.some((x) => dirname(x.path) === data) && readdirSync(data).length === 0)
|
|
400
|
+
rmdirSync(data);
|
|
401
|
+
}
|
|
402
|
+
catch {
|
|
403
|
+
/* gone already, or not empty */
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
export const command = {
|
|
407
|
+
summary: "remove the service, launchers, status line and MCP entries turno set up (profile folders stay)",
|
|
408
|
+
usage: USAGE,
|
|
409
|
+
flags: ["--dry-run", "--yes", "--keep-config", "--purge"],
|
|
410
|
+
async run(args, io) {
|
|
411
|
+
const p = parseFlags(args, { ...DRY_RUN, yes: { type: "boolean", short: "y" }, "keep-config": { type: "boolean" }, purge: { type: "boolean" } }, 0);
|
|
412
|
+
const dry = bool(p, "dry-run");
|
|
413
|
+
const plan = await planUninstall(io.env, { keepConfig: bool(p, "keep-config"), purge: bool(p, "purge") });
|
|
414
|
+
const remove = describe(plan, io.env);
|
|
415
|
+
const last = `Last step, to remove the package: ${packageRemoval()}`;
|
|
416
|
+
const printStays = () => {
|
|
417
|
+
if (plan.manual.length) {
|
|
418
|
+
io.out("Remove by hand (turno does not edit shell startup files):");
|
|
419
|
+
for (const m of plan.manual)
|
|
420
|
+
io.out(` - ${m}`);
|
|
421
|
+
}
|
|
422
|
+
io.out("Stays:");
|
|
423
|
+
for (const k of plan.kept)
|
|
424
|
+
io.out(` - ${k}`);
|
|
425
|
+
};
|
|
426
|
+
if (isEmpty(plan)) {
|
|
427
|
+
io.out("Nothing of turno's to remove on this machine.");
|
|
428
|
+
printStays();
|
|
429
|
+
io.out(last);
|
|
430
|
+
return 0;
|
|
431
|
+
}
|
|
432
|
+
io.out(dry ? "turno uninstall would remove:" : "turno uninstall removes:");
|
|
433
|
+
for (const r of remove)
|
|
434
|
+
io.out(` - ${r}`);
|
|
435
|
+
printStays();
|
|
436
|
+
if (dry) {
|
|
437
|
+
io.out(last);
|
|
438
|
+
return 0;
|
|
439
|
+
}
|
|
440
|
+
if (!bool(p, "yes")) {
|
|
441
|
+
if (!io.ask)
|
|
442
|
+
needsAnswer("uninstall");
|
|
443
|
+
if (!(await confirm(io, "Remove all of this?"))) {
|
|
444
|
+
io.err("Nothing changed.");
|
|
445
|
+
return 1;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
const journal = new Journal(io.env, `uninstall${bool(p, "keep-config") ? " --keep-config" : ""}`);
|
|
449
|
+
await apply(plan, journal, io);
|
|
450
|
+
if (plan.purge.length)
|
|
451
|
+
purge(plan, io);
|
|
452
|
+
io.out("Done.");
|
|
453
|
+
if (plan.purge.length)
|
|
454
|
+
io.out("--purge removed turno's backups too, so turno undo cannot put this back.");
|
|
455
|
+
else if (journal.used) {
|
|
456
|
+
io.out(`Changed your mind? turno undo ${journal.stamp} puts it all back while turno is still installed (then turno mcp daemon start).`);
|
|
457
|
+
}
|
|
458
|
+
io.out(last);
|
|
459
|
+
return 0;
|
|
460
|
+
},
|
|
461
|
+
};
|
|
462
|
+
//# sourceMappingURL=uninstall.js.map
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { spawnSync } from "node:child_process";
|
|
2
|
-
import { existsSync,
|
|
3
|
-
import {
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
4
|
import { loadConfig } from "../../core/config.js";
|
|
5
|
-
import {
|
|
5
|
+
import { Journal } from "../../core/journal.js";
|
|
6
|
+
import { paths, writePrivateFile } from "../../core/paths.js";
|
|
6
7
|
import { listProfiles } from "../../core/profiles.js";
|
|
7
|
-
import { fetchLatest, updateChecksOff } from "../../core/update.js";
|
|
8
|
+
import { fetchLatest, isSemver, updateChecksOff } from "../../core/update.js";
|
|
8
9
|
import { compareVersions, detectInstall, packageInfo, upgradeCommand } from "../../core/version.js";
|
|
9
10
|
import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
|
|
10
|
-
import { fail } from "../io.js";
|
|
11
|
+
import { confirm, fail } from "../io.js";
|
|
11
12
|
import { findOnPath, launcherPath } from "../launch.js";
|
|
12
13
|
import { turnoCommand, isGenerated, writeHelperLaunchers, writeLauncher } from "../launchers.js";
|
|
13
14
|
const USAGE = `Usage:
|
|
14
|
-
turno upgrade [--channel latest|next] [--to <version>] [--dry-run]
|
|
15
|
+
turno upgrade [--channel latest|next] [--to <version>] [--dry-run] [--yes]
|
|
15
16
|
install the newest release with the tool that installed turno
|
|
16
17
|
turno upgrade --check [--json] only ask the registry what the newest release is
|
|
17
|
-
turno upgrade --finish
|
|
18
|
+
turno upgrade --finish [--yes] after an upgrade: rewrite launchers, check config, show what changed
|
|
19
|
+
|
|
20
|
+
When agent configs need a new gateway token, --finish offers to run turno mcp sync (in a
|
|
21
|
+
terminal it asks; --yes runs it without asking).
|
|
18
22
|
|
|
19
23
|
turno knows how it was installed (npm, pnpm, yarn, bun, volta, or a git checkout) and runs the
|
|
20
24
|
matching command. Once a day interactive commands look for a new release in the background and
|
|
@@ -32,8 +36,7 @@ export function recordedVersion(env) {
|
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
export function recordVersion(env) {
|
|
35
|
-
|
|
36
|
-
writeFileSync(versionFile(env), `${packageInfo().version}\n`);
|
|
39
|
+
writePrivateFile(versionFile(env), `${packageInfo().version}\n`, env);
|
|
37
40
|
}
|
|
38
41
|
/** CHANGELOG sections newer than `from`, up to the running version. */
|
|
39
42
|
export function changesSince(from, changelog, to = packageInfo().version) {
|
|
@@ -48,8 +51,12 @@ export function changesSince(from, changelog, to = packageInfo().version) {
|
|
|
48
51
|
}
|
|
49
52
|
return out.join("\n").trim();
|
|
50
53
|
}
|
|
51
|
-
/**
|
|
52
|
-
|
|
54
|
+
/**
|
|
55
|
+
* Steps after the files changed: idempotent, safe to run any time. `sync` says what to do when
|
|
56
|
+
* agent configs need `turno mcp sync`: ask (in a terminal; elsewhere only say so), run it, or
|
|
57
|
+
* only say so (doctor, which offers the sync as a fix of its own).
|
|
58
|
+
*/
|
|
59
|
+
export async function finishUpgrade(io, opts = {}) {
|
|
53
60
|
const env = io.env;
|
|
54
61
|
const before = recordedVersion(env);
|
|
55
62
|
const now = packageInfo().version;
|
|
@@ -61,20 +68,44 @@ export function finishUpgrade(io) {
|
|
|
61
68
|
io.out(`config: ${err.message} (turno config edit)`);
|
|
62
69
|
}
|
|
63
70
|
// Launchers bake the path of the running turno, which changes with some package managers.
|
|
71
|
+
// The journal records the ones that change, so `turno undo` can put the old ones back.
|
|
72
|
+
const journal = new Journal(env, "upgrade --finish");
|
|
64
73
|
let rewritten = 0;
|
|
65
74
|
for (const name of config ? listProfiles(config, env) : []) {
|
|
66
75
|
const file = launcherPath(name, env);
|
|
67
76
|
if (file && isGenerated(file)) {
|
|
68
|
-
writeLauncher(name, env);
|
|
77
|
+
writeLauncher(name, env, undefined, journal);
|
|
69
78
|
rewritten++;
|
|
70
79
|
}
|
|
71
80
|
}
|
|
72
81
|
const bin = paths(env).bin;
|
|
73
82
|
if (["turno-auto", "turno-open"].some((f) => existsSync(join(bin, f)) && isGenerated(join(bin, f)))) {
|
|
74
|
-
rewritten += writeHelperLaunchers(env, turnoCommand()).length;
|
|
83
|
+
rewritten += writeHelperLaunchers(env, turnoCommand(), journal).length;
|
|
75
84
|
}
|
|
76
85
|
if (rewritten)
|
|
77
86
|
io.out(`launchers: ${rewritten} rewritten for turno ${now}`);
|
|
87
|
+
const hint = journal.hint();
|
|
88
|
+
if (hint)
|
|
89
|
+
io.out(hint);
|
|
90
|
+
// Configs synced before per-profile gateway tokens (ADR 0023) send the master token, which
|
|
91
|
+
// mcpd refuses for MCP sessions: say so here instead of leaving it to the first failed call.
|
|
92
|
+
const tokens = (await import("../../mcpd/health.js")).tokenSyncCheck(env);
|
|
93
|
+
if (tokens) {
|
|
94
|
+
const mode = opts.sync ?? "ask";
|
|
95
|
+
let run = mode === "yes";
|
|
96
|
+
if (mode === "ask" && io.ask) {
|
|
97
|
+
io.out(tokens.text);
|
|
98
|
+
run = await confirm(io, "run turno mcp sync now?");
|
|
99
|
+
}
|
|
100
|
+
if (run) {
|
|
101
|
+
const { command } = await import("./mcp.js");
|
|
102
|
+
if ((await command.run(["sync"], io)) !== 0)
|
|
103
|
+
io.err("turno: turno mcp sync did not finish every profile; run it again once their sessions are closed");
|
|
104
|
+
}
|
|
105
|
+
else
|
|
106
|
+
io.out(`${tokens.text}; run: turno mcp sync`);
|
|
107
|
+
}
|
|
108
|
+
await refreshDaemonService(io);
|
|
78
109
|
recordVersion(env);
|
|
79
110
|
if (before && before !== now) {
|
|
80
111
|
io.out(`turno ${before} -> ${now}`);
|
|
@@ -89,14 +120,35 @@ export function finishUpgrade(io) {
|
|
|
89
120
|
io.out(`turno ${now} is set up`);
|
|
90
121
|
return 0;
|
|
91
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* The mcpd service runs the turno that installed it, and the old code keeps running until a
|
|
125
|
+
* restart: rewrite the service file for this version and restart it, when one is installed.
|
|
126
|
+
*/
|
|
127
|
+
async function refreshDaemonService(io) {
|
|
128
|
+
const { installedBackend } = await import("../../mcpd/service.js");
|
|
129
|
+
const backend = await installedBackend(io.env);
|
|
130
|
+
if (!backend)
|
|
131
|
+
return;
|
|
132
|
+
io.out(`mcpd: rewriting the ${backend.noun} for turno ${packageInfo().version} and restarting it; open sessions reconnect on their next call`);
|
|
133
|
+
const { installDaemonService } = await import("./mcpd.js");
|
|
134
|
+
const code = await installDaemonService(io, { command: "upgrade --finish" });
|
|
135
|
+
if (code)
|
|
136
|
+
io.err("turno: mcpd was not restarted; run turno mcp daemon start");
|
|
137
|
+
}
|
|
92
138
|
export const command = {
|
|
93
139
|
summary: "update turno to the newest release (or check for one)",
|
|
94
140
|
usage: USAGE,
|
|
95
|
-
flags: ["--check", "--channel", "--to", "--dry-run", "--json", "--finish"],
|
|
141
|
+
flags: ["--check", "--channel", "--to", "--dry-run", "--json", "--finish", "--yes"],
|
|
96
142
|
async run(args, io) {
|
|
97
|
-
const p = parseFlags(args, { check: { type: "boolean" }, finish: { type: "boolean" }, channel: { type: "string" }, to: { type: "string" }, ...DRY_RUN, ...JSON_FLAG }, 0);
|
|
143
|
+
const p = parseFlags(args, { check: { type: "boolean" }, finish: { type: "boolean" }, yes: { type: "boolean", short: "y" }, channel: { type: "string" }, to: { type: "string" }, ...DRY_RUN, ...JSON_FLAG }, 0);
|
|
144
|
+
const yes = bool(p, "yes");
|
|
98
145
|
if (bool(p, "finish"))
|
|
99
|
-
return finishUpgrade(io);
|
|
146
|
+
return finishUpgrade(io, { sync: yes ? "yes" : "ask" });
|
|
147
|
+
const to = str(p, "to");
|
|
148
|
+
if (to !== undefined && !isSemver(to))
|
|
149
|
+
fail(`--to needs a version like 1.2.3 (got "${to}")`);
|
|
150
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(str(p, "channel") ?? "latest"))
|
|
151
|
+
fail("--channel needs a dist-tag such as latest or next");
|
|
100
152
|
const pkg = packageInfo();
|
|
101
153
|
const install = detectInstall();
|
|
102
154
|
const channel = str(p, "channel") ?? "latest";
|
|
@@ -106,7 +158,7 @@ export const command = {
|
|
|
106
158
|
if (pkg.private || !fromRegistry) {
|
|
107
159
|
const why = pkg.private ? "this copy is not published to a registry" : `installed from ${install.method}`;
|
|
108
160
|
if (bool(p, "json"))
|
|
109
|
-
printJson(io
|
|
161
|
+
printJson(io, { current: pkg.version, latest: null, method: install.method, note: why });
|
|
110
162
|
else
|
|
111
163
|
io.out(`turno ${pkg.version} (${why}; turno upgrade pulls the source)`);
|
|
112
164
|
return 0;
|
|
@@ -114,7 +166,7 @@ export const command = {
|
|
|
114
166
|
const s = await fetchLatest(io.env, channel);
|
|
115
167
|
const newer = s.latest && compareVersions(s.latest, pkg.version) > 0;
|
|
116
168
|
if (bool(p, "json"))
|
|
117
|
-
printJson(io
|
|
169
|
+
printJson(io, { current: pkg.version, latest: s.latest ?? null, channel, method: install.method, updateAvailable: Boolean(newer), error: s.error ?? null });
|
|
118
170
|
else if (s.error)
|
|
119
171
|
io.out(`could not reach the registry: ${s.error}`);
|
|
120
172
|
else
|
|
@@ -134,6 +186,9 @@ export const command = {
|
|
|
134
186
|
}
|
|
135
187
|
spec = s.latest ?? channel;
|
|
136
188
|
}
|
|
189
|
+
// Whatever reaches the package manager is a plain version or a dist-tag, never a URL or range.
|
|
190
|
+
if (!isSemver(spec) && !/^[a-z][a-z0-9-]{0,63}$/.test(spec))
|
|
191
|
+
fail(`refusing to install "${spec}": not a version`);
|
|
137
192
|
const steps = upgradeCommand(install, pkg.name, spec);
|
|
138
193
|
if (!steps)
|
|
139
194
|
return fail(`cannot tell how turno was installed (${install.root}); reinstall it with your package manager`);
|
|
@@ -155,7 +210,8 @@ export const command = {
|
|
|
155
210
|
io.out("upgraded; run `turno upgrade --finish` to rewrite the launchers");
|
|
156
211
|
return 0;
|
|
157
212
|
}
|
|
158
|
-
const
|
|
213
|
+
const finish = ["upgrade", "--finish", ...(yes ? ["--yes"] : [])];
|
|
214
|
+
const r = spawnSync(install.method === "source" ? process.execPath : self, install.method === "source" ? [self, ...finish] : finish, { stdio: "inherit", env: io.env });
|
|
159
215
|
return r.status ?? 1;
|
|
160
216
|
},
|
|
161
217
|
};
|