turno-cli 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +21 -0
- package/LICENSE +202 -0
- package/NOTICE +18 -0
- package/README.md +334 -2
- package/dist/accounts/audit.js +54 -0
- package/dist/accounts/builtin.js +214 -0
- package/dist/accounts/delegate.js +185 -0
- package/dist/accounts/registry.js +190 -0
- package/dist/agents/index.js +101 -0
- package/dist/agents/snippets.js +64 -0
- package/dist/cli/args.js +47 -0
- package/dist/cli/commands/accounts.js +216 -0
- package/dist/cli/commands/auto.js +44 -0
- package/dist/cli/commands/available.js +18 -0
- package/dist/cli/commands/browser.js +175 -0
- package/dist/cli/commands/complete.js +112 -0
- package/dist/cli/commands/completion.js +57 -0
- package/dist/cli/commands/config.js +168 -0
- package/dist/cli/commands/doctor.js +324 -0
- package/dist/cli/commands/exhausted.js +40 -0
- package/dist/cli/commands/handoff.js +118 -0
- package/dist/cli/commands/hook.js +63 -0
- package/dist/cli/commands/identity.js +114 -0
- package/dist/cli/commands/limit.js +102 -0
- package/dist/cli/commands/mcp.js +350 -0
- package/dist/cli/commands/mcpd.js +161 -0
- package/dist/cli/commands/migrate.js +176 -0
- package/dist/cli/commands/open.js +60 -0
- package/dist/cli/commands/profile.js +259 -0
- package/dist/cli/commands/resolve.js +23 -0
- package/dist/cli/commands/run.js +15 -0
- package/dist/cli/commands/secret.js +123 -0
- package/dist/cli/commands/session.js +36 -0
- package/dist/cli/commands/sessions.js +27 -0
- package/dist/cli/commands/setup.js +224 -0
- package/dist/cli/commands/status.js +101 -0
- package/dist/cli/commands/statusline.js +275 -0
- package/dist/cli/commands/ui.js +276 -0
- package/dist/cli/commands/undo.js +67 -0
- package/dist/cli/commands/update-check.js +22 -0
- package/dist/cli/commands/upgrade.js +162 -0
- package/dist/cli/commands/usage.js +167 -0
- package/dist/cli/commands/version.js +27 -0
- package/dist/cli/commands/which.js +28 -0
- package/dist/cli/group.js +50 -0
- package/dist/cli/io.js +22 -0
- package/dist/cli/launch.js +98 -0
- package/dist/cli/launchers.js +200 -0
- package/dist/cli/main.js +94 -0
- package/dist/cli/registry.js +77 -0
- package/dist/core/config-edit.js +42 -0
- package/dist/core/config.js +137 -0
- package/dist/core/exhausted.js +30 -0
- package/dist/core/journal.js +185 -0
- package/dist/core/manifest.js +177 -0
- package/dist/core/paths.js +54 -0
- package/dist/core/profiles.js +61 -0
- package/dist/core/ratelimit.js +39 -0
- package/dist/core/resolve.js +78 -0
- package/dist/core/secrets.js +44 -0
- package/dist/core/sessions.js +173 -0
- package/dist/core/toml-edit.js +152 -0
- package/dist/core/update.js +102 -0
- package/dist/core/version.js +103 -0
- package/dist/mcpd/cache.js +41 -0
- package/dist/mcpd/connectors.js +63 -0
- package/dist/mcpd/daemon.js +163 -0
- package/dist/mcpd/gateway.js +308 -0
- package/dist/mcpd/importer.js +160 -0
- package/dist/mcpd/instances.js +303 -0
- package/dist/mcpd/jsonrpc.js +19 -0
- package/dist/mcpd/launchd.js +86 -0
- package/dist/mcpd/peerpid.js +25 -0
- package/dist/mcpd/sync.js +208 -0
- package/dist/mcpd/upstream.js +232 -0
- package/dist/statusline/cost.js +135 -0
- package/dist/statusline/render.js +246 -0
- package/dist/ui/cmap.js +57 -0
- package/dist/ui/fonts.js +107 -0
- package/dist/ui/settings.js +69 -0
- package/dist/ui/terminal-id.js +30 -0
- package/dist/ui/terminals.js +163 -0
- package/package.json +69 -3
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { loadConfig } from "../../core/config.js";
|
|
4
|
+
import { paths, tildify } from "../../core/paths.js";
|
|
5
|
+
import { NERD } from "../../statusline/render.js";
|
|
6
|
+
import { codePoints } from "../../ui/cmap.js";
|
|
7
|
+
import { checkFonts, fontSource, installFonts, userFontDir } from "../../ui/fonts.js";
|
|
8
|
+
import { currentStatusLine, isTurnoStatusLine, setStatusLine, withNerdTerminals } from "../../ui/settings.js";
|
|
9
|
+
import { Journal } from "../../core/journal.js";
|
|
10
|
+
import { BUILTIN_SYMBOLS, currentTerminal } from "../../ui/terminal-id.js";
|
|
11
|
+
import { TERMINALS, detectNerdTerminals, fontOf, installed, isNerdFamily, terminal } from "../../ui/terminals.js";
|
|
12
|
+
import { fail, paint } from "../io.js";
|
|
13
|
+
import { findOnPath } from "../launch.js";
|
|
14
|
+
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
|
|
24
|
+
|
|
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.`;
|
|
31
|
+
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;
|
|
53
|
+
}
|
|
54
|
+
/** Terminal ids to configure, from --terminal values. */
|
|
55
|
+
function chosenTerminals(values, env, platform) {
|
|
56
|
+
const out = new Map();
|
|
57
|
+
for (const v of values) {
|
|
58
|
+
if (v === "all") {
|
|
59
|
+
for (const t of TERMINALS)
|
|
60
|
+
if (t.write && installed(t, env, platform))
|
|
61
|
+
out.set(t.id, t);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const id = v === "current" ? currentTerminal(env) : v;
|
|
65
|
+
const t = id ? terminal(id) : undefined;
|
|
66
|
+
if (!t)
|
|
67
|
+
fail(v === "current" ? "could not tell which terminal this is; name it (warp, vscode, cursor, alacritty)" : `unknown terminal '${v}'`);
|
|
68
|
+
out.set(t.id, t);
|
|
69
|
+
}
|
|
70
|
+
return [...out.values()];
|
|
71
|
+
}
|
|
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]) {
|
|
74
|
+
const bin = findOnPath("turno", env);
|
|
75
|
+
if (bin && !isLegacyScript(bin))
|
|
76
|
+
return `${tildify(bin, env)} statusline`;
|
|
77
|
+
if (self) {
|
|
78
|
+
try {
|
|
79
|
+
return `${tildify(realpathSync(self), env)} statusline`;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
/* fall through */
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return "turno statusline";
|
|
86
|
+
}
|
|
87
|
+
/** Status line icons missing from a font file. */
|
|
88
|
+
function missingGlyphs(file) {
|
|
89
|
+
const have = codePoints(readFileSync(file));
|
|
90
|
+
return Object.values(NERD)
|
|
91
|
+
.map((g) => g.codePointAt(0))
|
|
92
|
+
.filter((c) => !have.has(c));
|
|
93
|
+
}
|
|
94
|
+
async function status(io) {
|
|
95
|
+
const env = io.env;
|
|
96
|
+
const platform = process.platform;
|
|
97
|
+
const p = paths(env);
|
|
98
|
+
const source = await fontSource();
|
|
99
|
+
const ok = (s) => paint(io, s, "32");
|
|
100
|
+
const warn = (s) => paint(io, s, "33");
|
|
101
|
+
const dir = userFontDir(env, platform);
|
|
102
|
+
if (!dir)
|
|
103
|
+
io.out(`font ${warn(`no user font folder on ${platform}; install ${source.family} by hand`)}`);
|
|
104
|
+
else {
|
|
105
|
+
const checks = checkFonts(source, dir);
|
|
106
|
+
const have = checks.filter((c) => c.state === "installed").length;
|
|
107
|
+
if (have === checks.length) {
|
|
108
|
+
const missing = missingGlyphs(checks[0].target);
|
|
109
|
+
io.out(`font ${ok(`${source.family} installed`)} in ${tildify(dir, env)}`);
|
|
110
|
+
io.out(` ${missing.length ? warn(`missing ${missing.length} status line icons`) : `has all ${Object.keys(NERD).length} status line icons`}`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
const other = checks.filter((c) => c.state === "different").length;
|
|
114
|
+
const elsewhere = platform === "darwin" && checks.every((c) => existsSync(join("/Library/Fonts", c.file)));
|
|
115
|
+
const note = elsewhere ? " (found in /Library/Fonts)" : other ? ` (${other} with other contents)` : "";
|
|
116
|
+
io.out(`font ${warn(`${source.family}: ${have}/${checks.length} files`)} in ${tildify(dir, env)}${note}; turno ui install`);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const s = currentStatusLine(join(p.hub, "settings.json"));
|
|
120
|
+
const where = tildify(join(p.hub, "settings.json"), env);
|
|
121
|
+
if (isTurnoStatusLine(s))
|
|
122
|
+
io.out(`status ${ok(`${where} runs \`${s.command}\``)}${s.refreshInterval ? ` every ${s.refreshInterval} s` : ""}`);
|
|
123
|
+
else if (s)
|
|
124
|
+
io.out(`status ${warn(`${where} runs \`${s.command}\``)}; turno ui install switches it`);
|
|
125
|
+
else
|
|
126
|
+
io.out(`status ${warn(`no statusLine in ${where}`)}; turno ui install adds it`);
|
|
127
|
+
let config;
|
|
128
|
+
try {
|
|
129
|
+
config = loadConfig(env);
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
io.out(`config ${warn(err.message)}`);
|
|
133
|
+
}
|
|
134
|
+
const here = currentTerminal(env);
|
|
135
|
+
const nerdList = config?.nerdTerminals ?? [];
|
|
136
|
+
const premigrate = !existsSync(p.configFile) && ["proyectos", "navegador"].some((f) => existsSync(join(p.legacyConfig, f)));
|
|
137
|
+
const shown = TERMINALS.filter((t) => t.id === here || installed(t, env, platform));
|
|
138
|
+
for (const [i, t] of shown.entries()) {
|
|
139
|
+
const font = fontOf(t, env, platform);
|
|
140
|
+
const nerd = BUILTIN_SYMBOLS.has(t.id) || nerdList.includes(t.id);
|
|
141
|
+
let line = `${t.name}${t.id === here ? " (this one)" : ""}: `;
|
|
142
|
+
if (t.symbols)
|
|
143
|
+
line += "ships the icons";
|
|
144
|
+
else if (font !== undefined)
|
|
145
|
+
line += `font ${font}`;
|
|
146
|
+
else if (t.manual)
|
|
147
|
+
line += "font set in the app";
|
|
148
|
+
else
|
|
149
|
+
line += "default font";
|
|
150
|
+
line += nerd ? `, ${ok("Nerd icons")}` : `, Unicode icons`;
|
|
151
|
+
if (!nerd && isNerdFamily(font))
|
|
152
|
+
line += ` (turno ${premigrate ? "migrate" : "ui install"} records it)`;
|
|
153
|
+
else if (!nerd && t.write)
|
|
154
|
+
line += ` (turno ui install --terminal ${t.id})`;
|
|
155
|
+
else if (!nerd && t.manual)
|
|
156
|
+
line += ` (${t.manual}, then add "${t.id}" to nerd_terminals)`;
|
|
157
|
+
else if (nerd && t.write && font !== undefined && font !== source.family) {
|
|
158
|
+
line += ` (turno ui install --terminal ${t.id} switches it to ${source.family})`;
|
|
159
|
+
}
|
|
160
|
+
io.out(`${i === 0 ? "terminal " : " "}${line}`);
|
|
161
|
+
}
|
|
162
|
+
const icons = config?.icons ?? "auto";
|
|
163
|
+
io.out(`icons ${icons}${icons === "auto" ? `: ${here && (BUILTIN_SYMBOLS.has(here) || nerdList.includes(here)) ? "Nerd" : "Unicode"} here` : ""}`);
|
|
164
|
+
return 0;
|
|
165
|
+
}
|
|
166
|
+
async function install(args, io) {
|
|
167
|
+
const o = parse(args);
|
|
168
|
+
const env = io.env;
|
|
169
|
+
const platform = process.platform;
|
|
170
|
+
const targets = chosenTerminals(o.terminals, env, platform); // validate before changing anything
|
|
171
|
+
const p = paths(env);
|
|
172
|
+
const journal = new Journal(env, `ui install ${args.join(" ")}`.trim(), o.dryRun);
|
|
173
|
+
const dry = o.dryRun ? " (dry run)" : "";
|
|
174
|
+
let source;
|
|
175
|
+
if (o.font) {
|
|
176
|
+
source = await fontSource();
|
|
177
|
+
const dir = userFontDir(env, platform);
|
|
178
|
+
if (!dir)
|
|
179
|
+
io.out(`font: no user font folder on ${platform}; install ${source.family} by hand from ${source.files[0].url}`);
|
|
180
|
+
else {
|
|
181
|
+
const results = await installFonts(source, { dir, force: o.force, dryRun: o.dryRun, platform, env, journal });
|
|
182
|
+
for (const r of results) {
|
|
183
|
+
const what = {
|
|
184
|
+
kept: "already installed",
|
|
185
|
+
copied: "installed",
|
|
186
|
+
downloaded: "downloaded and installed",
|
|
187
|
+
skipped: "skipped: a different file has this name (--force replaces it)",
|
|
188
|
+
}[r.action];
|
|
189
|
+
io.out(`font: ${r.file} ${what}${r.action === "kept" || r.action === "skipped" ? "" : dry}`);
|
|
190
|
+
}
|
|
191
|
+
if (results.some((r) => r.action === "copied" || r.action === "downloaded") && !o.dryRun) {
|
|
192
|
+
io.out("font: restart open terminals so they see the new font");
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (o.statusline) {
|
|
197
|
+
const r = setStatusLine(join(p.hub, "settings.json"), statusLineCommand(env), journal);
|
|
198
|
+
if (!r.changed)
|
|
199
|
+
io.out(`statusline: ${tildify(r.file, env)} already runs \`${r.after.command}\``);
|
|
200
|
+
else {
|
|
201
|
+
io.out(`statusline: ${tildify(r.file, env)} now runs \`${r.after.command}\` every ${r.after.refreshInterval} s${dry}`);
|
|
202
|
+
if (r.before)
|
|
203
|
+
io.out(`statusline: it ran \`${r.before.command}\``);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
const family = source?.family ?? (await fontSource()).family;
|
|
207
|
+
for (const t of targets) {
|
|
208
|
+
if (t.symbols) {
|
|
209
|
+
io.out(`${t.name}: ships the icons, nothing to change`);
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
if (!t.config || !t.write) {
|
|
213
|
+
io.out(`${t.name}: set it by hand: ${t.manual}`);
|
|
214
|
+
continue;
|
|
215
|
+
}
|
|
216
|
+
const file = t.config(env, platform);
|
|
217
|
+
const before = existsSync(file) ? readFileSync(file, "utf8") : "";
|
|
218
|
+
const after = t.write(before, family);
|
|
219
|
+
if (after === before) {
|
|
220
|
+
io.out(`${t.name}: already uses ${family}`);
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const was = t.read?.(before);
|
|
224
|
+
journal.write(file, after);
|
|
225
|
+
io.out(`${t.name}: font ${was ? `${was} -> ` : ""}${family} in ${tildify(file, env)}${dry}`);
|
|
226
|
+
}
|
|
227
|
+
// Record every terminal that now draws Nerd icons, after the font changes above.
|
|
228
|
+
const detected = o.dryRun
|
|
229
|
+
? [...detectNerdTerminals(env, platform), ...targets.filter((t) => t.write).map((t) => t.id)]
|
|
230
|
+
: detectNerdTerminals(env, platform);
|
|
231
|
+
let current = [];
|
|
232
|
+
try {
|
|
233
|
+
current = loadConfig(env).nerdTerminals;
|
|
234
|
+
}
|
|
235
|
+
catch (err) {
|
|
236
|
+
io.out(`config: ${err.message}; nerd_terminals not updated`);
|
|
237
|
+
return 1;
|
|
238
|
+
}
|
|
239
|
+
const merged = [...new Set([...current, ...detected])].sort();
|
|
240
|
+
const legacy = ["proyectos", "navegador"].some((f) => existsSync(join(p.legacyConfig, f)));
|
|
241
|
+
if (!existsSync(p.configFile) && legacy) {
|
|
242
|
+
// A config.toml written now would make `turno migrate` refuse; migrate detects the same list.
|
|
243
|
+
if (merged.length)
|
|
244
|
+
io.out(`config: no config.toml yet; turno migrate records nerd_terminals = [${merged.join(", ")}]`);
|
|
245
|
+
}
|
|
246
|
+
else if (merged.join() !== [...current].sort().join()) {
|
|
247
|
+
const text = existsSync(p.configFile) ? readFileSync(p.configFile, "utf8") : "";
|
|
248
|
+
journal.write(p.configFile, withNerdTerminals(text, merged));
|
|
249
|
+
io.out(`config: nerd_terminals = [${merged.join(", ")}] in ${tildify(p.configFile, env)}${dry}`);
|
|
250
|
+
}
|
|
251
|
+
const hint = journal.hint();
|
|
252
|
+
if (hint)
|
|
253
|
+
io.out(hint);
|
|
254
|
+
return 0;
|
|
255
|
+
}
|
|
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"] },
|
|
262
|
+
},
|
|
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
|
+
};
|
|
276
|
+
//# sourceMappingURL=ui.js.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { listJournals, undoJournal } from "../../core/journal.js";
|
|
2
|
+
import { tildify } from "../../core/paths.js";
|
|
3
|
+
import { DRY_RUN, FORCE, JSON_FLAG, bool, count, parseFlags, printJson } from "../args.js";
|
|
4
|
+
import { fail, paint } from "../io.js";
|
|
5
|
+
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
|
|
9
|
+
|
|
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.`;
|
|
13
|
+
function describe(j, io) {
|
|
14
|
+
if (!j.manifest)
|
|
15
|
+
return `${j.stamp} ${paint(io, "(older backup without a journal: restore by hand)", "2")}`;
|
|
16
|
+
const m = j.manifest;
|
|
17
|
+
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}`;
|
|
19
|
+
}
|
|
20
|
+
export const command = {
|
|
21
|
+
summary: "list recent changes turno made to your files, and put any of them back",
|
|
22
|
+
usage: USAGE,
|
|
23
|
+
args: ["stamp"],
|
|
24
|
+
flags: ["--list", "--dry-run", "--force", "--json", "--tail"],
|
|
25
|
+
async run(args, io) {
|
|
26
|
+
const p = parseFlags(args, { list: { type: "boolean" }, ...DRY_RUN, ...FORCE, ...JSON_FLAG, tail: { type: "string", short: "n" } }, 1);
|
|
27
|
+
const all = listJournals(io.env);
|
|
28
|
+
const target = p.positionals[0];
|
|
29
|
+
if (bool(p, "list") || !target) {
|
|
30
|
+
const shown = all.slice(0, count(p, "tail", 10));
|
|
31
|
+
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 })));
|
|
33
|
+
return 0;
|
|
34
|
+
}
|
|
35
|
+
if (!shown.length)
|
|
36
|
+
io.out("No changes recorded yet.");
|
|
37
|
+
for (const j of shown)
|
|
38
|
+
io.out(describe(j, io));
|
|
39
|
+
if (!target && shown.length)
|
|
40
|
+
io.out(`\nturno undo <stamp> puts one back (turno undo last: the newest).`);
|
|
41
|
+
return 0;
|
|
42
|
+
}
|
|
43
|
+
const info = target === "last" ? all.find((j) => j.manifest && !j.manifest.undoneBy) : all.find((j) => j.stamp === target);
|
|
44
|
+
if (!info)
|
|
45
|
+
return fail(target === "last" ? "nothing to undo" : `no change ${target} (turno undo --list)`);
|
|
46
|
+
if (info.manifest?.undoneBy && !bool(p, "force"))
|
|
47
|
+
fail(`${info.stamp} was already undone by ${info.manifest.undoneBy} (turno undo ${info.manifest.undoneBy} redoes it)`);
|
|
48
|
+
const dry = bool(p, "dry-run");
|
|
49
|
+
let result;
|
|
50
|
+
try {
|
|
51
|
+
result = undoJournal(info, io.env, { dryRun: dry, force: bool(p, "force") });
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
return fail(err.message);
|
|
55
|
+
}
|
|
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}` : ""}`);
|
|
61
|
+
}
|
|
62
|
+
if (result.journal.used)
|
|
63
|
+
io.out(`redo with: turno undo ${result.journal.stamp}`);
|
|
64
|
+
return result.steps.some((s) => s.action === "skip") ? 1 : 0;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=undo.js.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { loadConfig } from "../../core/config.js";
|
|
2
|
+
import { fetchLatest, updateChecksOff } from "../../core/update.js";
|
|
3
|
+
/** Background registry check started by the update notice. Prints nothing. */
|
|
4
|
+
export const command = {
|
|
5
|
+
summary: "background update check",
|
|
6
|
+
usage: "Usage: turno __update-check",
|
|
7
|
+
hidden: true,
|
|
8
|
+
async run(_args, io) {
|
|
9
|
+
let configured = true;
|
|
10
|
+
try {
|
|
11
|
+
configured = loadConfig(io.env).updateCheck;
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
/* default */
|
|
15
|
+
}
|
|
16
|
+
if (updateChecksOff(io.env, configured))
|
|
17
|
+
return 0;
|
|
18
|
+
await fetchLatest(io.env);
|
|
19
|
+
return 0;
|
|
20
|
+
},
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=update-check.js.map
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, join } from "node:path";
|
|
4
|
+
import { loadConfig } from "../../core/config.js";
|
|
5
|
+
import { paths } from "../../core/paths.js";
|
|
6
|
+
import { listProfiles } from "../../core/profiles.js";
|
|
7
|
+
import { fetchLatest, updateChecksOff } from "../../core/update.js";
|
|
8
|
+
import { compareVersions, detectInstall, packageInfo, upgradeCommand } from "../../core/version.js";
|
|
9
|
+
import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
|
|
10
|
+
import { fail } from "../io.js";
|
|
11
|
+
import { findOnPath, launcherPath } from "../launch.js";
|
|
12
|
+
import { turnoCommand, isGenerated, writeHelperLaunchers, writeLauncher } from "../launchers.js";
|
|
13
|
+
const USAGE = `Usage:
|
|
14
|
+
turno upgrade [--channel latest|next] [--to <version>] [--dry-run]
|
|
15
|
+
install the newest release with the tool that installed turno
|
|
16
|
+
turno upgrade --check [--json] only ask the registry what the newest release is
|
|
17
|
+
turno upgrade --finish after an upgrade: rewrite launchers, check config, show what changed
|
|
18
|
+
|
|
19
|
+
turno knows how it was installed (npm, pnpm, yarn, bun, volta, or a git checkout) and runs the
|
|
20
|
+
matching command. Once a day interactive commands look for a new release in the background and
|
|
21
|
+
mention it once; set update_check = false in config.toml or TURNO_NO_UPDATE_CHECK=1 to stop that.`;
|
|
22
|
+
function versionFile(env) {
|
|
23
|
+
return join(paths(env).state, "version");
|
|
24
|
+
}
|
|
25
|
+
/** The turno version that last finished an upgrade (or first ran setup). */
|
|
26
|
+
export function recordedVersion(env) {
|
|
27
|
+
try {
|
|
28
|
+
return readFileSync(versionFile(env), "utf8").trim() || undefined;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export function recordVersion(env) {
|
|
35
|
+
mkdirSync(dirname(versionFile(env)), { recursive: true });
|
|
36
|
+
writeFileSync(versionFile(env), `${packageInfo().version}\n`);
|
|
37
|
+
}
|
|
38
|
+
/** CHANGELOG sections newer than `from`, up to the running version. */
|
|
39
|
+
export function changesSince(from, changelog, to = packageInfo().version) {
|
|
40
|
+
const out = [];
|
|
41
|
+
let keep = false;
|
|
42
|
+
for (const line of changelog.split("\n")) {
|
|
43
|
+
const m = /^## \[?v?(\d+\.\d+\.\d+[^\]\s]*)/.exec(line);
|
|
44
|
+
if (m)
|
|
45
|
+
keep = compareVersions(m[1], to) <= 0 && (!from || compareVersions(m[1], from) > 0);
|
|
46
|
+
if (keep)
|
|
47
|
+
out.push(line);
|
|
48
|
+
}
|
|
49
|
+
return out.join("\n").trim();
|
|
50
|
+
}
|
|
51
|
+
/** Steps after the files changed: idempotent, safe to run any time. */
|
|
52
|
+
export function finishUpgrade(io) {
|
|
53
|
+
const env = io.env;
|
|
54
|
+
const before = recordedVersion(env);
|
|
55
|
+
const now = packageInfo().version;
|
|
56
|
+
let config;
|
|
57
|
+
try {
|
|
58
|
+
config = loadConfig(env);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
io.out(`config: ${err.message} (turno config edit)`);
|
|
62
|
+
}
|
|
63
|
+
// Launchers bake the path of the running turno, which changes with some package managers.
|
|
64
|
+
let rewritten = 0;
|
|
65
|
+
for (const name of config ? listProfiles(config, env) : []) {
|
|
66
|
+
const file = launcherPath(name, env);
|
|
67
|
+
if (file && isGenerated(file)) {
|
|
68
|
+
writeLauncher(name, env);
|
|
69
|
+
rewritten++;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const bin = paths(env).bin;
|
|
73
|
+
if (["turno-auto", "turno-open"].some((f) => existsSync(join(bin, f)) && isGenerated(join(bin, f)))) {
|
|
74
|
+
rewritten += writeHelperLaunchers(env, turnoCommand()).length;
|
|
75
|
+
}
|
|
76
|
+
if (rewritten)
|
|
77
|
+
io.out(`launchers: ${rewritten} rewritten for turno ${now}`);
|
|
78
|
+
recordVersion(env);
|
|
79
|
+
if (before && before !== now) {
|
|
80
|
+
io.out(`turno ${before} -> ${now}`);
|
|
81
|
+
const log = join(packageInfo().root, "CHANGELOG.md");
|
|
82
|
+
if (existsSync(log)) {
|
|
83
|
+
const changes = changesSince(before, readFileSync(log, "utf8"));
|
|
84
|
+
if (changes)
|
|
85
|
+
io.out(`\n${changes}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
else
|
|
89
|
+
io.out(`turno ${now} is set up`);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
export const command = {
|
|
93
|
+
summary: "update turno to the newest release (or check for one)",
|
|
94
|
+
usage: USAGE,
|
|
95
|
+
flags: ["--check", "--channel", "--to", "--dry-run", "--json", "--finish"],
|
|
96
|
+
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);
|
|
98
|
+
if (bool(p, "finish"))
|
|
99
|
+
return finishUpgrade(io);
|
|
100
|
+
const pkg = packageInfo();
|
|
101
|
+
const install = detectInstall();
|
|
102
|
+
const channel = str(p, "channel") ?? "latest";
|
|
103
|
+
const off = updateChecksOff(io.env);
|
|
104
|
+
const fromRegistry = install.method !== "source" && install.method !== "unknown";
|
|
105
|
+
if (bool(p, "check")) {
|
|
106
|
+
if (pkg.private || !fromRegistry) {
|
|
107
|
+
const why = pkg.private ? "this copy is not published to a registry" : `installed from ${install.method}`;
|
|
108
|
+
if (bool(p, "json"))
|
|
109
|
+
printJson(io.out, { current: pkg.version, latest: null, method: install.method, note: why });
|
|
110
|
+
else
|
|
111
|
+
io.out(`turno ${pkg.version} (${why}; turno upgrade pulls the source)`);
|
|
112
|
+
return 0;
|
|
113
|
+
}
|
|
114
|
+
const s = await fetchLatest(io.env, channel);
|
|
115
|
+
const newer = s.latest && compareVersions(s.latest, pkg.version) > 0;
|
|
116
|
+
if (bool(p, "json"))
|
|
117
|
+
printJson(io.out, { current: pkg.version, latest: s.latest ?? null, channel, method: install.method, updateAvailable: Boolean(newer), error: s.error ?? null });
|
|
118
|
+
else if (s.error)
|
|
119
|
+
io.out(`could not reach the registry: ${s.error}`);
|
|
120
|
+
else
|
|
121
|
+
io.out(newer ? `turno ${s.latest} is available (you have ${pkg.version}): turno upgrade` : `turno ${pkg.version} is the newest on ${channel}`);
|
|
122
|
+
return s.error ? 1 : 0;
|
|
123
|
+
}
|
|
124
|
+
if (fromRegistry && off === "this copy is not published to a registry")
|
|
125
|
+
fail("this copy is not published to a registry");
|
|
126
|
+
let spec = str(p, "to") ?? channel;
|
|
127
|
+
if (fromRegistry && !str(p, "to")) {
|
|
128
|
+
const s = await fetchLatest(io.env, channel);
|
|
129
|
+
if (s.error)
|
|
130
|
+
fail(`could not reach the registry: ${s.error}`);
|
|
131
|
+
if (s.latest && compareVersions(s.latest, pkg.version) <= 0) {
|
|
132
|
+
io.out(`turno ${pkg.version} is already the newest on ${channel}`);
|
|
133
|
+
return 0;
|
|
134
|
+
}
|
|
135
|
+
spec = s.latest ?? channel;
|
|
136
|
+
}
|
|
137
|
+
const steps = upgradeCommand(install, pkg.name, spec);
|
|
138
|
+
if (!steps)
|
|
139
|
+
return fail(`cannot tell how turno was installed (${install.root}); reinstall it with your package manager`);
|
|
140
|
+
for (const step of steps) {
|
|
141
|
+
io.out(`$ ${step.join(" ")}`);
|
|
142
|
+
if (bool(p, "dry-run"))
|
|
143
|
+
continue;
|
|
144
|
+
const r = spawnSync(step[0], step.slice(1), { stdio: "inherit", env: io.env });
|
|
145
|
+
if (r.status !== 0) {
|
|
146
|
+
io.err(`turno: ${step[0]} failed (exit ${r.status ?? r.signal}); nothing else was changed`);
|
|
147
|
+
return 1;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (bool(p, "dry-run"))
|
|
151
|
+
return 0;
|
|
152
|
+
// The new files are in place: let the new version finish its own upgrade.
|
|
153
|
+
const self = install.method === "source" ? process.argv[1] : findOnPath("turno", io.env);
|
|
154
|
+
if (!self) {
|
|
155
|
+
io.out("upgraded; run `turno upgrade --finish` to rewrite the launchers");
|
|
156
|
+
return 0;
|
|
157
|
+
}
|
|
158
|
+
const r = spawnSync(install.method === "source" ? process.execPath : self, install.method === "source" ? [self, "upgrade", "--finish"] : ["upgrade", "--finish"], { stdio: "inherit", env: io.env });
|
|
159
|
+
return r.status ?? 1;
|
|
160
|
+
},
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=upgrade.js.map
|