turno-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +293 -0
- package/README.md +143 -75
- 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/core/version.js +6 -0
- 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 +9 -9
- package/dist/cli/commands/available.js +0 -18
|
@@ -1,42 +1,97 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import { join } from "node:path";
|
|
3
|
+
import { loadManifest } from "../../core/manifest.js";
|
|
2
4
|
import { migrationPending } from "../../core/config-edit.js";
|
|
3
5
|
import { loadConfig } from "../../core/config.js";
|
|
4
6
|
import { paths, tildify } from "../../core/paths.js";
|
|
5
|
-
import { resolveProfile } from "../../core/resolve.js";
|
|
6
7
|
import { availableUpdate } from "../../core/update.js";
|
|
7
8
|
import { packageInfo } from "../../core/version.js";
|
|
8
9
|
import { FALLBACK, checkFonts, userFontDir } from "../../ui/fonts.js";
|
|
9
|
-
import { currentStatusLine, isTurnoStatusLine } from "../../ui/settings.js";
|
|
10
|
+
import { currentStatusLine, isTurnoStatusLine, statusLineLabel } from "../../ui/settings.js";
|
|
10
11
|
import { currentTerminal, nerdHere } from "../../ui/terminal-id.js";
|
|
11
12
|
import { JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
|
|
12
|
-
import {
|
|
13
|
+
import { plural } from "../io.js";
|
|
14
|
+
import { profileColor, style, visibleWidth } from "../style.js";
|
|
13
15
|
import { mcpdStatus } from "./doctor.js";
|
|
14
|
-
import { adapter } from "../../agents/index.js";
|
|
16
|
+
import { DEFAULT_AGENT, adapter } from "../../agents/index.js";
|
|
15
17
|
import { limitsData } from "./limit.js";
|
|
16
|
-
import { profilesData } from "./profile.js";
|
|
18
|
+
import { profilesData, resolveAll, usingText } from "./profile.js";
|
|
17
19
|
import { sessionsData } from "./session.js";
|
|
18
|
-
import {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
import { shortTime } from "./usage.js";
|
|
21
|
+
/** Servers in mcp.toml, or 0 when it is missing or unreadable (turno mcp list shows why). */
|
|
22
|
+
function manifestServers(env) {
|
|
23
|
+
if (!existsSync(paths(env).mcpFile))
|
|
24
|
+
return 0;
|
|
25
|
+
try {
|
|
26
|
+
return Object.keys(loadManifest(env).servers).length;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return 0;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/** Profiles whose agent config does not point at the gateway yet, from a silent `mcp sync --dry-run`. */
|
|
33
|
+
async function syncPending(env) {
|
|
34
|
+
try {
|
|
35
|
+
const { syncProfiles } = await import("./mcp.js");
|
|
36
|
+
const quiet = { env, isTty: false, out: () => { }, err: () => { } };
|
|
37
|
+
return (await syncProfiles(quiet, { dryRun: true })).changed;
|
|
38
|
+
}
|
|
39
|
+
catch {
|
|
40
|
+
return 0;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
/** First thing that keeps this machine from working fully, in the order a person would fix it. */
|
|
44
|
+
async function nextStep(env, d) {
|
|
45
|
+
if (d.migrationPending)
|
|
46
|
+
return { command: "turno migrate", why: "the bash claudio config is not moved to turno yet" };
|
|
47
|
+
if (!d.profiles.length)
|
|
48
|
+
return { command: "turno init", why: "no profiles yet; init finds your agents, folders and MCP servers" };
|
|
49
|
+
const notSetUp = d.profiles.find((x) => !x.setUp);
|
|
50
|
+
if (notSetUp)
|
|
51
|
+
return { command: `turno profile repair ${notSetUp.name}`, why: `profile ${notSetUp.name} has no folder or launcher yet` };
|
|
52
|
+
const servers = manifestServers(env);
|
|
53
|
+
if (servers && !d.mcpd.running)
|
|
54
|
+
return { command: "turno mcp daemon start", why: `mcp.toml has ${plural(servers, "server")} and the gateway is not running` };
|
|
55
|
+
if (servers) {
|
|
56
|
+
const pending = await syncPending(env);
|
|
57
|
+
if (pending)
|
|
58
|
+
return { command: "turno mcp sync", why: `${plural(pending, "agent config")} do not point at the gateway yet` };
|
|
59
|
+
}
|
|
60
|
+
if (d.update)
|
|
61
|
+
return { command: "turno upgrade", why: `turno ${d.update} is available` };
|
|
62
|
+
if (d.look.statusLine !== "turno")
|
|
63
|
+
return { command: "turno ui install", why: "optional: the status line with account, usage and gateway" };
|
|
64
|
+
return null;
|
|
24
65
|
}
|
|
25
66
|
/** Everything `turno status` shows, as data. */
|
|
26
67
|
export async function statusData(env, cwd = process.cwd()) {
|
|
68
|
+
const base = await statusBase(env, cwd);
|
|
69
|
+
return { ...base, next: await nextStep(env, base) };
|
|
70
|
+
}
|
|
71
|
+
async function statusBase(env, cwd) {
|
|
27
72
|
const config = loadConfig(env);
|
|
28
73
|
const [profiles, limits, mcpd] = await Promise.all([profilesData(env, config), limitsData(env, false), mcpdStatus(env, config)]);
|
|
29
|
-
const
|
|
74
|
+
const all = resolveAll(cwd, config, env);
|
|
75
|
+
const here = all[0].r;
|
|
30
76
|
const sessions = sessionsData(env);
|
|
31
77
|
const line = currentStatusLine(join(paths(env).hub, "settings.json"));
|
|
32
78
|
const fontDir = userFontDir(env);
|
|
33
79
|
const fonts = fontDir ? checkFonts(FALLBACK, fontDir) : [];
|
|
34
80
|
const terminal = currentTerminal(env);
|
|
81
|
+
// Why mcpd is down: the last start error (mcpd.error.json) and who holds its port.
|
|
82
|
+
const mcpdProblems = mcpd.running ? [] : await (await import("./mcpd.js")).downReasons(env).catch(() => []);
|
|
35
83
|
return {
|
|
36
84
|
version: packageInfo().version,
|
|
37
85
|
update: availableUpdate(env) ?? null,
|
|
38
86
|
migrationPending: migrationPending(env),
|
|
39
|
-
here: {
|
|
87
|
+
here: {
|
|
88
|
+
dir: tildify(cwd, env),
|
|
89
|
+
assigned: here.assigned || null,
|
|
90
|
+
chosen: here.chosen || null,
|
|
91
|
+
reason: here.reason,
|
|
92
|
+
note: here.note || null,
|
|
93
|
+
agents: Object.fromEntries(all.map(({ agent, r }) => [agent, { chosen: r.chosen || null, text: usingText(agent, r, env) }])),
|
|
94
|
+
},
|
|
40
95
|
profiles: profiles.map((p) => {
|
|
41
96
|
const l = limits.find((x) => x.profile === p.name);
|
|
42
97
|
return { ...p, fiveHour: l?.fiveHour ?? null, week: l?.week ?? null };
|
|
@@ -45,10 +100,11 @@ export async function statusData(env, cwd = process.cwd()) {
|
|
|
45
100
|
total: sessions.length,
|
|
46
101
|
byProfile: sessions.reduce((acc, s) => {
|
|
47
102
|
const key = s.profile ?? (s.source === "desktop" ? "desktop" : "unknown");
|
|
48
|
-
|
|
103
|
+
acc[key] = (acc[key] ?? 0) + 1;
|
|
104
|
+
return acc;
|
|
49
105
|
}, {}),
|
|
50
106
|
},
|
|
51
|
-
mcpd: { running: mcpd.running, port: mcpd.port },
|
|
107
|
+
mcpd: { running: mcpd.running, port: mcpd.port, problems: mcpdProblems },
|
|
52
108
|
look: {
|
|
53
109
|
statusLine: isTurnoStatusLine(line) ? "turno" : (line?.command ?? null),
|
|
54
110
|
font: fonts.length > 0 && fonts.every((f) => f.state === "installed"),
|
|
@@ -57,11 +113,87 @@ export async function statusData(env, cwd = process.cwd()) {
|
|
|
57
113
|
},
|
|
58
114
|
};
|
|
59
115
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
116
|
+
/** "33m", "2h06m", "5d 18h": time left until a window resets. */
|
|
117
|
+
export function resetIn(resetsAt, now) {
|
|
118
|
+
if (!resetsAt || resetsAt <= now)
|
|
119
|
+
return "";
|
|
120
|
+
const d = Math.floor(resetsAt - now);
|
|
121
|
+
const h = Math.floor(d / 3600);
|
|
122
|
+
const m = Math.floor((d % 3600) / 60);
|
|
123
|
+
return h >= 24 ? `${Math.floor(h / 24)}d ${h % 24}h` : h ? `${h}h${String(m).padStart(2, "0")}m` : `${m}m`;
|
|
124
|
+
}
|
|
125
|
+
/** The status screen as lines: the same layout with colors on a terminal and as plain text. */
|
|
126
|
+
export function renderStatus(d, io, opts = {}) {
|
|
127
|
+
const now = opts.now ?? Date.now() / 1000;
|
|
128
|
+
const s = style(io, { nerd: d.look.icons === "nerd" });
|
|
129
|
+
const pill = (name) => s.profile(name, opts.colors ? profileColor(opts.colors, name) : undefined);
|
|
130
|
+
const out = [];
|
|
131
|
+
const using = d.here.chosen ? pill(d.here.chosen) : "plain claude";
|
|
132
|
+
out.push(s.wrap(`${s.bold(s.accent("turno"))} ${s.muted(d.version)} `, `${d.here.dir} ${s.icon("arrow")} ${using}`));
|
|
133
|
+
if (d.update)
|
|
134
|
+
out.push(s.warn(`${s.icon("info")} turno ${d.update} is available: turno upgrade`));
|
|
135
|
+
if (d.migrationPending)
|
|
136
|
+
out.push(s.warn(`${s.icon("warn")} the bash claudio config is not migrated yet: turno migrate`));
|
|
137
|
+
// Here: what each agent opens in this folder.
|
|
138
|
+
out.push("", s.header("Here"));
|
|
139
|
+
const why = d.here.note ? `${d.here.assigned} ${d.here.note}` : d.here.reason;
|
|
140
|
+
const here = [[s.muted(DEFAULT_AGENT), d.here.chosen ? pill(d.here.chosen) : "plain claude", s.muted(why)]];
|
|
141
|
+
for (const [agent, a] of Object.entries(d.here.agents)) {
|
|
142
|
+
if (agent === DEFAULT_AGENT)
|
|
143
|
+
continue;
|
|
144
|
+
const m = /^(.*) \((.*)\)$/.exec(a.text);
|
|
145
|
+
here.push([s.muted(agent), a.chosen ? pill(a.chosen) : (m?.[1] ?? a.text), s.muted(m?.[2] ?? "")]);
|
|
146
|
+
}
|
|
147
|
+
out.push(...s.table(here, { columns: [{}, {}, { drop: 1 }] }));
|
|
148
|
+
// Profiles: usage of each account with its reset time, and who it is.
|
|
149
|
+
out.push("", s.header("Profiles"));
|
|
150
|
+
if (!d.profiles.length)
|
|
151
|
+
out.push(` none yet ${s.muted("(turno profile add <name>)")}`);
|
|
152
|
+
else {
|
|
153
|
+
const win = (w) => {
|
|
154
|
+
if (!w)
|
|
155
|
+
return [s.muted("-"), ""];
|
|
156
|
+
const used = w.resetsAt && w.resetsAt < now ? 0 : w.used;
|
|
157
|
+
return [s.bar(used, 8), s.muted(resetIn(w.resetsAt, now))];
|
|
158
|
+
};
|
|
159
|
+
const rows = [["", s.muted("5 hours"), "", s.muted("week"), "", s.muted("account")]];
|
|
160
|
+
for (const x of d.profiles) {
|
|
161
|
+
const who = !x.setUp ? s.warn("not set up") : !adapter(x.agent).accountDetails ? adapter(x.agent).label : x.email ? x.email : s.warn("not logged in");
|
|
162
|
+
const flags = [...x.roles, x.exhaustedUntil ? `exhausted until ${shortTime(x.exhaustedUntil)}` : ""].filter(Boolean).join(", ");
|
|
163
|
+
const usage = adapter(x.agent).accountDetails ? [...win(x.fiveHour), ...win(x.week)] : [s.muted("-"), "", s.muted("-"), ""];
|
|
164
|
+
rows.push([pill(x.name), ...usage, `${who}${x.plan ? s.muted(` · ${x.plan}`) : ""}${flags ? s.muted(` ${flags}`) : ""}`]);
|
|
165
|
+
}
|
|
166
|
+
out.push(...s.table(rows, { columns: [{}, {}, { drop: 3 }, {}, { drop: 4 }, {}] }));
|
|
167
|
+
}
|
|
168
|
+
// The machine: gateway, sessions and the look.
|
|
169
|
+
out.push("", s.header("Machine"));
|
|
170
|
+
const by = Object.entries(d.sessions.byProfile)
|
|
171
|
+
.map(([k, v]) => `${k} ${v}`)
|
|
172
|
+
.join(", ");
|
|
173
|
+
const gateway = d.mcpd.running
|
|
174
|
+
? `${s.lead("on", "running")} ${s.muted(`on port ${d.mcpd.port}`)}`
|
|
175
|
+
: `${s.lead("off", s.warn("not running"))} ${s.muted("(turno mcp daemon start)")}`;
|
|
176
|
+
const lineText = d.look.statusLine === "turno"
|
|
177
|
+
? "turno status line"
|
|
178
|
+
: d.look.statusLine
|
|
179
|
+
? `status line ${statusLineLabel({ type: "command", command: d.look.statusLine }, io.env, 40)}`
|
|
180
|
+
: "no status line";
|
|
181
|
+
const look = [lineText, d.look.font ? "font installed" : `font missing ${s.muted("(turno ui install)")}`, `${d.look.icons} icons here`].join(s.muted(" · "));
|
|
182
|
+
out.push(s.kv("gateway", gateway, 8));
|
|
183
|
+
for (const problem of d.mcpd.problems)
|
|
184
|
+
out.push(s.wrap(` ${" ".repeat(8)} ${s.warn(s.icon("warn"))} `, s.warn(problem)));
|
|
185
|
+
out.push(s.kv("sessions", `${plural(d.sessions.total, "live session")}${by ? s.muted(` (${by})`) : ""}`, 8));
|
|
186
|
+
out.push(s.kv("look", look, 8));
|
|
187
|
+
out.push("", ...nextLines(s, d.next));
|
|
188
|
+
out.push("", s.muted("turno doctor checks each part; turno limit, session and profile show more."));
|
|
189
|
+
return out;
|
|
190
|
+
}
|
|
191
|
+
function nextLines(s, next) {
|
|
192
|
+
const label = s.lead("next", s.bold(s.accent("Next")));
|
|
193
|
+
if (!next)
|
|
194
|
+
return [`${label} ${s.ok("nothing to do: everything is set up")}`];
|
|
195
|
+
const pad = " ".repeat(visibleWidth(label) + 2);
|
|
196
|
+
return [s.wrap(`${label} `, s.bold(next.command)), s.wrap(pad, s.muted(next.why))];
|
|
65
197
|
}
|
|
66
198
|
export const command = {
|
|
67
199
|
summary: "one screen with everything: this folder, profiles and usage, sessions, mcpd and the look",
|
|
@@ -71,31 +203,30 @@ export const command = {
|
|
|
71
203
|
const p = parseFlags(args, JSON_FLAG, 0);
|
|
72
204
|
const d = await statusData(io.env);
|
|
73
205
|
if (bool(p, "json")) {
|
|
74
|
-
printJson(io
|
|
206
|
+
printJson(io, d);
|
|
75
207
|
return 0;
|
|
76
208
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
io.out(`here ${d.here.dir} -> ${using}${d.here.note ? ` (${d.here.assigned} ${d.here.note})` : dim(` (${d.here.reason})`)}`);
|
|
84
|
-
if (!d.profiles.length)
|
|
85
|
-
io.out("profiles none yet (turno profile add <name>)");
|
|
86
|
-
const w = Math.max(0, ...d.profiles.map((x) => x.name.length));
|
|
87
|
-
for (const [i, x] of d.profiles.entries()) {
|
|
88
|
-
const who = !x.setUp ? "not set up" : x.agent !== "claude" ? adapter(x.agent).label : (x.email ?? "not logged in");
|
|
89
|
-
const flags = [...x.roles, x.exhaustedUntil ? `exhausted until ${shortTime(x.exhaustedUntil)}` : ""].filter(Boolean).join(", ");
|
|
90
|
-
io.out(`${i === 0 ? "profiles " : " "}${x.name.padEnd(w)} 5h ${pct(x.fiveHour, now)} week ${pct(x.week, now)} ${who}${x.plan ? ` · ${x.plan}` : ""}${flags ? dim(` ${flags}`) : ""}`);
|
|
209
|
+
let profiles = {};
|
|
210
|
+
try {
|
|
211
|
+
profiles = loadConfig(io.env).profiles;
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
/* statusData already read it */
|
|
91
215
|
}
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
io.out(`mcpd ${d.mcpd.running ? `running on port ${d.mcpd.port}` : "not running (turno mcp daemon start)"}`);
|
|
95
|
-
const lineText = d.look.statusLine === "turno" ? "turno status line" : d.look.statusLine ? `status line \`${d.look.statusLine}\`` : "no status line";
|
|
96
|
-
io.out(`look ${lineText}, ${d.look.font ? "font installed" : "font missing (turno ui install)"}, ${d.look.icons} icons here`);
|
|
97
|
-
io.out(dim("\nturno doctor checks each part; turno limit, session and profile show more."));
|
|
216
|
+
for (const line of renderStatus(d, io, { colors: profiles }))
|
|
217
|
+
io.out(line);
|
|
98
218
|
return 0;
|
|
99
219
|
},
|
|
100
220
|
};
|
|
221
|
+
/**
|
|
222
|
+
* What bare `turno` shows: this screen once turno is set up, the help before that (so a new
|
|
223
|
+
* person sees "Start here: turno init").
|
|
224
|
+
*/
|
|
225
|
+
export async function homeScreen(io) {
|
|
226
|
+
const p = paths(io.env);
|
|
227
|
+
if (!existsSync(p.configFile) && !existsSync(p.mcpFile))
|
|
228
|
+
return undefined;
|
|
229
|
+
const code = await command.run([], io);
|
|
230
|
+
return code;
|
|
231
|
+
}
|
|
101
232
|
//# sourceMappingURL=status.js.map
|