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
|
@@ -3,19 +3,30 @@ import { join } from "node:path";
|
|
|
3
3
|
import { loadRegistry } from "../../accounts/registry.js";
|
|
4
4
|
import { migrationPending } from "../../core/config-edit.js";
|
|
5
5
|
import { loadConfig } from "../../core/config.js";
|
|
6
|
-
import { loadManifest } from "../../core/manifest.js";
|
|
7
|
-
import { paths,
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
6
|
+
import { effectiveLaunch, loadManifest, servesProfile } from "../../core/manifest.js";
|
|
7
|
+
import { paths, tildify } from "../../core/paths.js";
|
|
8
|
+
import { unsetVars } from "../../core/secrets.js";
|
|
9
|
+
import { AGENT_IDS, DEFAULT_AGENT, adapter, agentHub, agentProfileDir } from "../../agents/index.js";
|
|
10
|
+
import { agentOf, configFindings, listProfiles } from "../../core/profiles.js";
|
|
10
11
|
import { availableUpdate } from "../../core/update.js";
|
|
11
12
|
import { packageInfo } from "../../core/version.js";
|
|
12
13
|
import { FALLBACK, checkFonts, userFontDir } from "../../ui/fonts.js";
|
|
13
|
-
import { currentStatusLine, isTurnoStatusLine } from "../../ui/settings.js";
|
|
14
|
+
import { currentStatusLine, isTurnoStatusLine, statusLineLabel } from "../../ui/settings.js";
|
|
14
15
|
import { JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
|
|
15
|
-
import {
|
|
16
|
+
import { fail } from "../io.js";
|
|
16
17
|
import { findOnPath } from "../launch.js";
|
|
17
18
|
import { MARKER, isGenerated, launcherName, launcherText } from "../launchers.js";
|
|
18
|
-
import {
|
|
19
|
+
import { duration, padEnd, profileColor, style, visibleWidth } from "../style.js";
|
|
20
|
+
import { nerdHere } from "../../ui/terminal-id.js";
|
|
21
|
+
function statusOf(level) {
|
|
22
|
+
return level === "info" ? "skip" : level;
|
|
23
|
+
}
|
|
24
|
+
/** The command that fixes a check, whether `--fix` runs it or a person does. */
|
|
25
|
+
function fixCommand(c) {
|
|
26
|
+
return c.fix?.label ?? c.hint;
|
|
27
|
+
}
|
|
28
|
+
/** Whether a check is a problem: a warning or a failure. */
|
|
29
|
+
const isProblem = (c) => c.level === "warn" || c.level === "fail";
|
|
19
30
|
/** Whether a file is the original bash claudio script rather than this CLI. */
|
|
20
31
|
export function isLegacyScript(file) {
|
|
21
32
|
try {
|
|
@@ -59,6 +70,59 @@ export async function mcpdStatus(env, config) {
|
|
|
59
70
|
return { level: "info", running: false, port, text: `mcpd not reachable on port ${port} (turno mcp daemon start)` };
|
|
60
71
|
}
|
|
61
72
|
}
|
|
73
|
+
/** `turno mcp sync`, which plans every agent config first and rewrites only those that change. */
|
|
74
|
+
const syncFix = {
|
|
75
|
+
label: "turno mcp sync",
|
|
76
|
+
run: async (io) => (await import("./mcp.js")).command.run(["sync"], io),
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* Variables mcp.toml reads from mcpd's environment (`env:NAME`, `${NAME}`) that are not set in
|
|
80
|
+
* this one: in stdio servers' env and args (every profile variant), and in the headers and
|
|
81
|
+
* OAuth client secret of remotes mcpd proxies. Names only, never a value.
|
|
82
|
+
*/
|
|
83
|
+
function envRefChecks(manifest, env) {
|
|
84
|
+
const out = [];
|
|
85
|
+
let refs = 0;
|
|
86
|
+
for (const server of Object.values(manifest.servers)) {
|
|
87
|
+
const unset = new Set();
|
|
88
|
+
const scan = (value, whole = true) => {
|
|
89
|
+
if (value.includes("${") || (whole && value.startsWith("env:")))
|
|
90
|
+
refs++;
|
|
91
|
+
for (const name of unsetVars(value, env, whole))
|
|
92
|
+
unset.add(name);
|
|
93
|
+
};
|
|
94
|
+
if (server.kind === "stdio") {
|
|
95
|
+
if (server.builtin)
|
|
96
|
+
continue;
|
|
97
|
+
for (const variant of ["default", ...Object.keys(server.variants)]) {
|
|
98
|
+
const launch = effectiveLaunch(server, variant);
|
|
99
|
+
for (const v of Object.values(launch.env))
|
|
100
|
+
scan(v);
|
|
101
|
+
for (const a of launch.args)
|
|
102
|
+
scan(a, false);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
else if (server.proxy) {
|
|
106
|
+
for (const v of Object.values(server.headers))
|
|
107
|
+
scan(v);
|
|
108
|
+
if (server.oauth?.clientSecret)
|
|
109
|
+
scan(server.oauth.clientSecret);
|
|
110
|
+
}
|
|
111
|
+
if (!unset.size)
|
|
112
|
+
continue;
|
|
113
|
+
const names = [...unset].sort();
|
|
114
|
+
const list = names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
|
|
115
|
+
out.push({
|
|
116
|
+
area: "mcp",
|
|
117
|
+
level: "warn",
|
|
118
|
+
text: `${server.name} reads ${list} from mcpd's environment, and ${names.length === 1 ? "it is" : "they are"} not set here`,
|
|
119
|
+
manual: `set ${list} where mcpd starts, then turno mcp daemon restart; or store ${names.length === 1 ? "it" : "each"} with turno secret set <name> and write keychain:<name> instead`,
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (refs && !out.length)
|
|
123
|
+
out.push({ area: "mcp", level: "ok", text: `mcp.toml: every environment reference is set here (${refs})` });
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
62
126
|
const repair = (name) => ({
|
|
63
127
|
label: `turno profile repair ${name}`,
|
|
64
128
|
run: async (io) => (await import("./setup.js")).setupProfiles([name], io),
|
|
@@ -80,27 +144,39 @@ function lexists(path) {
|
|
|
80
144
|
return false;
|
|
81
145
|
}
|
|
82
146
|
}
|
|
83
|
-
/** Launcher, folder, hub links and
|
|
84
|
-
|
|
147
|
+
/** Launcher, folder, hub links and agent checks of one profile (ADR 0013, ADR 0032). */
|
|
148
|
+
function profileChecks(name, agent, env) {
|
|
85
149
|
const a = adapter(agent);
|
|
86
150
|
const area = `profile ${name}`;
|
|
87
151
|
const out = [];
|
|
88
152
|
const launcher = join(paths(env).bin, launcherName(name, agent));
|
|
89
153
|
if (!existsSync(launcher))
|
|
90
154
|
out.push({ area, level: "fail", text: `profile ${name}: no launcher ${tildify(launcher, env)}`, fix: repair(name) });
|
|
91
|
-
else if (!isGenerated(launcher))
|
|
92
|
-
out.push({
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
155
|
+
else if (!isGenerated(launcher)) {
|
|
156
|
+
out.push({
|
|
157
|
+
area,
|
|
158
|
+
level: "fail",
|
|
159
|
+
text: `profile ${name}: ${tildify(launcher, env)} was not generated by turno`,
|
|
160
|
+
manual: `move ${tildify(launcher, env)} aside (it is yours, so turno does not overwrite it), then turno profile repair ${name}`,
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
else {
|
|
164
|
+
// Classic launchers vary with the turno that wrote them: only a bash claudio one is stale.
|
|
165
|
+
const text = readFileSync(launcher, "utf8");
|
|
166
|
+
const stale = a.classicLauncher ? !text.includes(MARKER) && "launcher from the bash claudio" : text !== launcherText(name, env, agent) && "launcher is out of date";
|
|
167
|
+
if (stale)
|
|
168
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${stale}`, fix: repair(name) });
|
|
169
|
+
else
|
|
170
|
+
out.push({ area, level: "ok", text: `profile ${name}: ${agent === DEFAULT_AGENT ? "" : `${a.label} `}launcher ok` });
|
|
171
|
+
}
|
|
97
172
|
const dir = agentProfileDir(name, agent, env);
|
|
98
173
|
if (!existsSync(dir)) {
|
|
99
174
|
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(dir, env)} does not exist`, fix: repair(name) });
|
|
100
175
|
return out;
|
|
101
176
|
}
|
|
102
177
|
const hub = agentHub(agent, env);
|
|
103
|
-
|
|
178
|
+
const shared = [...a.sharedDirs, ...a.sharedFiles];
|
|
179
|
+
for (const item of shared) {
|
|
104
180
|
const path = join(dir, item);
|
|
105
181
|
const target = join(hub, item);
|
|
106
182
|
if (isLinkTo(path, target))
|
|
@@ -110,132 +186,135 @@ async function agentProfileChecks(name, agent, env) {
|
|
|
110
186
|
else if (existsSync(target))
|
|
111
187
|
out.push({ area, level: "warn", text: `profile ${name}: missing link for ${item}`, fix: repair(name) });
|
|
112
188
|
}
|
|
113
|
-
|
|
114
|
-
|
|
189
|
+
for (const w of a.doctorWarnings?.(dir) ?? [])
|
|
190
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${w}`, fix: repair(name) });
|
|
191
|
+
if (a.perAccount) {
|
|
192
|
+
const known = new Set([...shared, ...a.perAccount.items]);
|
|
193
|
+
let entries = [];
|
|
115
194
|
try {
|
|
116
|
-
|
|
195
|
+
entries = readdirSync(dir).sort();
|
|
117
196
|
}
|
|
118
197
|
catch {
|
|
119
|
-
|
|
198
|
+
entries = [];
|
|
199
|
+
}
|
|
200
|
+
for (const item of entries) {
|
|
201
|
+
if (known.has(item) || !lexists(join(dir, item)) || a.perAccount.ignore.test(item))
|
|
202
|
+
continue;
|
|
203
|
+
out.push({ area, level: "info", text: `profile ${name}: ${item} is new and unclassified: decide whether to share it` });
|
|
120
204
|
}
|
|
121
|
-
if (store !== "file")
|
|
122
|
-
out.push({ area, level: "warn", text: `profile ${name}: Codex may keep the login in the shared Keychain (cli_auth_credentials_store is not "file")`, fix: repair(name) });
|
|
123
205
|
}
|
|
124
|
-
if (!findOnPath(a.command, env))
|
|
125
|
-
out.push({ area, level: "warn", text: `profile ${name}: ${a.command} is not on PATH (${a.install})` });
|
|
126
206
|
return out;
|
|
127
207
|
}
|
|
128
|
-
|
|
129
|
-
async function profileChecks(name, env) {
|
|
130
|
-
const { PER_ACCOUNT, SHARED_DIRS, SHARED_FILES } = await import("./setup.js");
|
|
208
|
+
export async function collectChecks(env) {
|
|
131
209
|
const p = paths(env);
|
|
132
|
-
const
|
|
133
|
-
const
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
out.push({ area, level: "fail", text: `profile ${name}: no launcher ${tildify(launcher, env)}`, fix: repair(name) });
|
|
138
|
-
else if (!isGenerated(launcher))
|
|
139
|
-
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(launcher, env)} was not generated by turno` });
|
|
140
|
-
else if (!readFileSync(launcher, "utf8").includes(MARKER))
|
|
141
|
-
out.push({ area, level: "warn", text: `profile ${name}: launcher from the bash claudio`, fix: repair(name) });
|
|
210
|
+
const checks = [];
|
|
211
|
+
const add = (area, level, text, how = {}) => checks.push({ area, level, text, ...how });
|
|
212
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
213
|
+
if (major >= 20)
|
|
214
|
+
add("system", "ok", `node ${process.versions.node}`);
|
|
142
215
|
else
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return out;
|
|
147
|
-
}
|
|
148
|
-
const shared = [...SHARED_DIRS, ...SHARED_FILES];
|
|
149
|
-
const problems = [];
|
|
150
|
-
for (const item of shared) {
|
|
151
|
-
const path = join(dir, item);
|
|
152
|
-
const target = join(p.hub, item);
|
|
153
|
-
if (isLinkTo(path, target))
|
|
154
|
-
continue;
|
|
155
|
-
if (existsSync(path))
|
|
156
|
-
problems.push(`${item} is a local copy, not shared`);
|
|
157
|
-
else if (existsSync(target))
|
|
158
|
-
problems.push(`missing link for ${item}`);
|
|
159
|
-
}
|
|
160
|
-
for (const pr of problems)
|
|
161
|
-
out.push({ area, level: "warn", text: `profile ${name}: ${pr}`, fix: repair(name) });
|
|
162
|
-
const known = new Set([...shared, ...PER_ACCOUNT]);
|
|
163
|
-
let entries = [];
|
|
216
|
+
add("system", "fail", `node ${process.versions.node}, and turno needs 20 or newer`, { manual: "install Node.js 20 or newer (https://nodejs.org)" });
|
|
217
|
+
// Every agent is listed; only one that a profile uses can fail.
|
|
218
|
+
let early;
|
|
164
219
|
try {
|
|
165
|
-
|
|
220
|
+
early = loadConfig(env);
|
|
166
221
|
}
|
|
167
222
|
catch {
|
|
168
|
-
|
|
223
|
+
early = undefined;
|
|
224
|
+
}
|
|
225
|
+
const names = early ? listProfiles(early, env) : [];
|
|
226
|
+
const used = new Set(early ? names.map((n) => agentOf(n, early)) : []);
|
|
227
|
+
for (const id of AGENT_IDS) {
|
|
228
|
+
const a = adapter(id);
|
|
229
|
+
const at = findOnPath(a.command, env);
|
|
230
|
+
// An install line is a command, or a page to follow when the agent has no one-line install.
|
|
231
|
+
const install = /^https?:\/\//.test(a.install) ? { manual: `install it: ${a.install}` } : { hint: a.install };
|
|
232
|
+
if (at)
|
|
233
|
+
add("system", used.has(id) ? "ok" : "info", `${a.command} at ${tildify(at, env)}`);
|
|
234
|
+
else if (used.has(id))
|
|
235
|
+
add("system", "fail", `${a.command} not found on PATH, and profiles use it`, install);
|
|
236
|
+
else
|
|
237
|
+
add("system", "info", `${a.command} not installed`, install);
|
|
169
238
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
239
|
+
const { pathAdvice } = await import("./profile.js");
|
|
240
|
+
const advice = names.length ? pathAdvice(env) : undefined;
|
|
241
|
+
if (advice) {
|
|
242
|
+
add("system", "warn", `${tildify(p.bin, env)} is not on your PATH, so launchers like ${launcherName(names[0], agentOf(names[0], early))} will not be found (turno ${names[0]} works meanwhile)`, {
|
|
243
|
+
manual: `${advice.charAt(0).toLowerCase()}${advice.slice(1)}, then open a new terminal`,
|
|
244
|
+
});
|
|
176
245
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const major = Number(process.versions.node.split(".")[0]);
|
|
184
|
-
add("system", major >= 20 ? "ok" : "fail", `node ${process.versions.node}${major >= 20 ? "" : " (turno needs >= 20)"}`);
|
|
185
|
-
const claude = findOnPath("claude", env);
|
|
186
|
-
add("system", claude ? "ok" : "fail", claude ? `claude at ${tildify(claude, env)}` : "claude not found on PATH");
|
|
246
|
+
const { secretStoreLabel } = await import("../security.js");
|
|
247
|
+
const store = secretStoreLabel(env);
|
|
248
|
+
if (store === "none")
|
|
249
|
+
add("system", "info", "secret store: none (keychain: references cannot resolve; env: ones work)", { manual: "install secret-tool (libsecret) to use keychain: references" });
|
|
250
|
+
else
|
|
251
|
+
add("system", "ok", `secret store: ${store}`);
|
|
187
252
|
const chrome = env.TURNO_CHROME_APP || "/Applications/Google Chrome.app";
|
|
188
|
-
|
|
253
|
+
if (existsSync(chrome))
|
|
254
|
+
add("system", "ok", "Google Chrome installed");
|
|
255
|
+
else
|
|
256
|
+
add("system", "warn", "Google Chrome not found: claude.ai links open in the default browser", { manual: "install Google Chrome, or set TURNO_CHROME_APP to where it is" });
|
|
189
257
|
const { recordedVersion, finishUpgrade } = await import("./upgrade.js");
|
|
190
258
|
const version = packageInfo().version;
|
|
191
259
|
const recorded = recordedVersion(env);
|
|
192
260
|
if (recorded && recorded !== version) {
|
|
193
|
-
add("turno", "warn", `turno ${version} runs, but ${recorded} set up the launchers`, { label: "turno upgrade --finish", run: (io) => finishUpgrade(io) });
|
|
261
|
+
add("turno", "warn", `turno ${version} runs, but ${recorded} set up the launchers`, { fix: { label: "turno upgrade --finish", run: (io) => finishUpgrade(io, { sync: "no" }) } });
|
|
194
262
|
}
|
|
195
263
|
else
|
|
196
264
|
add("turno", "ok", `turno ${version}`);
|
|
197
265
|
const newer = availableUpdate(env);
|
|
198
266
|
if (newer)
|
|
199
|
-
add("turno", "info", `turno ${newer} is available
|
|
267
|
+
add("turno", "info", `turno ${newer} is available`, { hint: "turno upgrade" });
|
|
200
268
|
let config;
|
|
269
|
+
const editConfig = { hint: "turno config edit" };
|
|
201
270
|
try {
|
|
202
271
|
config = loadConfig(env);
|
|
203
272
|
if (existsSync(p.configFile))
|
|
204
273
|
add("config", "ok", `${tildify(p.configFile, env)} parses`);
|
|
205
274
|
else if (migrationPending(env))
|
|
206
|
-
add("config", "info", `no ${tildify(p.configFile, env)} yet: turno migrate
|
|
275
|
+
add("config", "info", `no ${tildify(p.configFile, env)} yet, but a bash claudio config is there`, { hint: "turno migrate" });
|
|
207
276
|
else
|
|
208
277
|
add("config", "info", `no ${tildify(p.configFile, env)} (defaults)`);
|
|
278
|
+
for (const f of configFindings(config, env))
|
|
279
|
+
add("config", "warn", f.text, f.manual ? { manual: f.manual } : { hint: f.hint ?? "turno config edit" });
|
|
209
280
|
}
|
|
210
281
|
catch (err) {
|
|
211
|
-
add("config", "fail", err.message);
|
|
282
|
+
add("config", "fail", err.message, editConfig);
|
|
212
283
|
}
|
|
284
|
+
let manifest;
|
|
213
285
|
try {
|
|
214
286
|
const m = loadManifest(env);
|
|
287
|
+
manifest = m;
|
|
215
288
|
if (existsSync(p.mcpFile))
|
|
216
289
|
add("config", "ok", `${tildify(p.mcpFile, env)} parses (${Object.keys(m.servers).length} servers)`);
|
|
217
290
|
else
|
|
218
|
-
add("config", "info", `no ${tildify(p.mcpFile, env)} yet
|
|
291
|
+
add("config", "info", `no ${tildify(p.mcpFile, env)} yet`, { hint: "turno mcp import" });
|
|
219
292
|
}
|
|
220
293
|
catch (err) {
|
|
221
|
-
add("config", "fail", err.message);
|
|
294
|
+
add("config", "fail", err.message, { manual: `correct ${tildify(p.mcpFile, env)} where the error points` });
|
|
222
295
|
}
|
|
223
296
|
if (existsSync(p.accountsFile)) {
|
|
224
297
|
try {
|
|
225
|
-
loadRegistry(env);
|
|
298
|
+
const reg = loadRegistry(env);
|
|
226
299
|
add("config", "ok", `${tildify(p.accountsFile, env)} parses`);
|
|
300
|
+
// Without read_tools a delegated read is a write (ADR 0024): confirmed, with every tool.
|
|
301
|
+
const noReads = Object.values(reg.accounts).filter((a) => !a.readTools?.length).map((a) => a.id).sort();
|
|
302
|
+
if (noReads.length) {
|
|
303
|
+
add("config", "warn", `accounts without read_tools: ${noReads.join(", ")}; delegated reads get every tool of the account and ask like writes`, {
|
|
304
|
+
manual: `add read_tools to each of them in ${tildify(p.accountsFile, env)}`,
|
|
305
|
+
});
|
|
306
|
+
}
|
|
227
307
|
}
|
|
228
308
|
catch (err) {
|
|
229
|
-
add("config", "fail", err.message);
|
|
309
|
+
add("config", "fail", err.message, { manual: `correct ${tildify(p.accountsFile, env)} where the error points` });
|
|
230
310
|
}
|
|
231
311
|
}
|
|
232
312
|
if (config) {
|
|
233
313
|
const profiles = listProfiles(config, env);
|
|
234
314
|
if (profiles.length === 0)
|
|
235
|
-
add("profiles", "info", "no profiles yet
|
|
315
|
+
add("profiles", "info", "no profiles yet", { hint: "turno profile add <name>" });
|
|
236
316
|
for (const name of profiles) {
|
|
237
|
-
|
|
238
|
-
checks.push(...(agent === "claude" ? await profileChecks(name, env) : await agentProfileChecks(name, agent, env)));
|
|
317
|
+
checks.push(...profileChecks(name, agentOf(name, config), env));
|
|
239
318
|
}
|
|
240
319
|
}
|
|
241
320
|
const legacyBin = join(p.bin, "claudio");
|
|
@@ -245,19 +324,40 @@ export async function collectChecks(env) {
|
|
|
245
324
|
const { bypassingServers } = await import("./mcp.js");
|
|
246
325
|
const b = await bypassingServers(env);
|
|
247
326
|
for (const s of b.plugins)
|
|
248
|
-
add("mcp", "info", `plugin server ${s.plugin}/${s.name} starts in every session
|
|
249
|
-
|
|
250
|
-
|
|
327
|
+
add("mcp", "info", `plugin server ${s.plugin}/${s.name} starts in every session`, { hint: "turno mcp doctor" });
|
|
328
|
+
// turno mcp sync replaces a hub entry with the gateway's when mcp.toml serves it to the profile the hub belongs to.
|
|
329
|
+
const hubProfile = config?.system ?? "default";
|
|
330
|
+
for (const d of b.direct) {
|
|
331
|
+
const def = manifest?.servers[d.name];
|
|
332
|
+
const how = !d.inManifest
|
|
333
|
+
? { hint: "turno mcp import" }
|
|
334
|
+
: def && servesProfile(def, hubProfile)
|
|
335
|
+
? { fix: syncFix }
|
|
336
|
+
: { manual: `remove ${d.name} from ${tildify(p.hubConfig, env)}, or serve it to profile ${hubProfile} in mcp.toml` };
|
|
337
|
+
add("mcp", "warn", `${d.name} runs outside mcpd`, how);
|
|
338
|
+
}
|
|
339
|
+
const { describeLogin, oauthLogins } = await import("./mcp-oauth.js");
|
|
340
|
+
for (const l of await oauthLogins(env)) {
|
|
341
|
+
const ok = l.state === "logged in" || l.state === "expired";
|
|
342
|
+
const login = `turno mcp login ${l.server}${l.variant === "default" ? "" : ` --profile ${l.variant}`}`;
|
|
343
|
+
const said = describeLogin(l);
|
|
344
|
+
// describeLogin ends with the login command; the fix line shows it instead.
|
|
345
|
+
const text = said.endsWith(`: ${login}`) ? said.slice(0, -login.length - 2) : said;
|
|
346
|
+
const how = ok ? {} : said !== text ? { hint: login } : { manual: "install a secret store (macOS Keychain or secret-tool) so turno can read the login" };
|
|
347
|
+
add("mcp", ok ? "ok" : "warn", `${l.server}${l.variant === "default" ? "" : `@${l.variant}`} OAuth: ${text}`, how);
|
|
348
|
+
}
|
|
251
349
|
}
|
|
252
350
|
catch {
|
|
253
351
|
/* a broken mcp.toml is reported above */
|
|
254
352
|
}
|
|
353
|
+
if (manifest)
|
|
354
|
+
checks.push(...envRefChecks(manifest, env));
|
|
255
355
|
const settings = join(p.hub, "settings.json");
|
|
256
356
|
const line = currentStatusLine(settings);
|
|
257
357
|
if (isTurnoStatusLine(line))
|
|
258
358
|
add("look", "ok", "status line: turno statusline");
|
|
259
359
|
else
|
|
260
|
-
add("look", "info", `status line: ${line
|
|
360
|
+
add("look", "info", `status line: ${statusLineLabel(line, env)} in ${tildify(settings, env)}`, { hint: "turno ui install" });
|
|
261
361
|
const fontDir = userFontDir(env);
|
|
262
362
|
if (fontDir) {
|
|
263
363
|
const fonts = checkFonts(FALLBACK, fontDir);
|
|
@@ -265,60 +365,228 @@ export async function collectChecks(env) {
|
|
|
265
365
|
if (have === fonts.length)
|
|
266
366
|
add("look", "ok", `font: ${FALLBACK.family} installed`);
|
|
267
367
|
else
|
|
268
|
-
add("look", "info", `font: ${FALLBACK.family} ${have}/${fonts.length} files in ${tildify(fontDir, env)}
|
|
368
|
+
add("look", "info", `font: ${FALLBACK.family} ${have}/${fonts.length} files in ${tildify(fontDir, env)}`, { hint: "turno ui install" });
|
|
269
369
|
}
|
|
270
|
-
|
|
271
|
-
add("mcpd", mcpd.level, mcpd.text);
|
|
370
|
+
checks.push(...(await mcpdSection(env)));
|
|
272
371
|
return checks;
|
|
273
372
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
373
|
+
// ---- mcpd section (ADR 0017): service file, token mode, port owner, start errors, synced ports.
|
|
374
|
+
// The checks live in mcpd/health.ts; keep this section separate from the rest of doctor.
|
|
375
|
+
async function mcpdSection(env) {
|
|
376
|
+
const { mcpdChecks } = await import("../../mcpd/health.js");
|
|
377
|
+
return (await mcpdChecks(env)).map((c) => ({ area: "mcpd", ...c }));
|
|
378
|
+
}
|
|
379
|
+
// ---- end of the mcpd section
|
|
380
|
+
// ---- security section (ADR 0027): `turno doctor --security` runs only these checks.
|
|
381
|
+
async function securitySection(env) {
|
|
382
|
+
return (await import("../security.js")).securityChecks(env);
|
|
383
|
+
}
|
|
384
|
+
// ---- end of the security section
|
|
385
|
+
/** Screen sections in order, and the check areas each one holds (ADR 0035). */
|
|
386
|
+
const SECTIONS = [
|
|
387
|
+
["System", (a) => a === "system" || a === "turno"],
|
|
388
|
+
["Config", (a) => a === "config"],
|
|
389
|
+
["Profiles", (a) => a === "profiles" || a.startsWith("profile ")],
|
|
390
|
+
["MCP", (a) => a === "mcp"],
|
|
391
|
+
["Look", (a) => a === "look"],
|
|
392
|
+
["Gateway", (a) => a === "mcpd"],
|
|
393
|
+
["Security", (a) => a === "security"],
|
|
394
|
+
];
|
|
395
|
+
function sectionOf(area) {
|
|
396
|
+
return SECTIONS.find(([, has]) => has(area))?.[0] ?? area.charAt(0).toUpperCase() + area.slice(1);
|
|
397
|
+
}
|
|
398
|
+
function countChecks(checks) {
|
|
399
|
+
const n = { ok: 0, warn: 0, fail: 0, skip: 0 };
|
|
400
|
+
for (const c of checks)
|
|
401
|
+
n[statusOf(c.level)]++;
|
|
402
|
+
return n;
|
|
403
|
+
}
|
|
404
|
+
/** "12 ok, 2 warnings, 1 failure, 3 skipped": zero problems and skips are left out. */
|
|
405
|
+
function countsText(n, paint = {}) {
|
|
406
|
+
const id = (s) => s;
|
|
407
|
+
const parts = [(paint.ok ?? id)(`${n.ok} ok`)];
|
|
408
|
+
if (n.warn)
|
|
409
|
+
parts.push((paint.warn ?? id)(`${n.warn} warning${n.warn === 1 ? "" : "s"}`));
|
|
410
|
+
if (n.fail)
|
|
411
|
+
parts.push((paint.err ?? id)(`${n.fail} failure${n.fail === 1 ? "" : "s"}`));
|
|
412
|
+
if (n.skip)
|
|
413
|
+
parts.push((paint.muted ?? id)(`${n.skip} skipped`));
|
|
414
|
+
return parts.join(", ");
|
|
415
|
+
}
|
|
416
|
+
/** The fix commands of every problem, failures first, each once: `next` in `--json`. */
|
|
417
|
+
function nextCommands(checks) {
|
|
418
|
+
const out = [];
|
|
419
|
+
for (const level of ["fail", "warn"]) {
|
|
420
|
+
for (const c of checks) {
|
|
421
|
+
const cmd = c.level === level ? fixCommand(c) : undefined;
|
|
422
|
+
if (cmd && !out.includes(cmd))
|
|
423
|
+
out.push(cmd);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
return out;
|
|
427
|
+
}
|
|
428
|
+
/** `--summary`: one line with the counts and the first fix, for hooks and the status line. */
|
|
429
|
+
function summaryLine(checks, opts = {}) {
|
|
430
|
+
const head = `turno doctor${opts.security ? " --security" : ""}: ${countsText(countChecks(checks))}`;
|
|
431
|
+
const problems = checks.filter(isProblem);
|
|
432
|
+
if (!problems.length)
|
|
433
|
+
return head;
|
|
434
|
+
const [first] = nextCommands(checks);
|
|
435
|
+
if (first)
|
|
436
|
+
return `${head}; fix: ${first}`;
|
|
437
|
+
return `${head}; turno doctor${opts.security ? " --security" : ""} shows the manual steps`;
|
|
438
|
+
}
|
|
439
|
+
/** The doctor screen as lines: sections, one row per check with its fix, and a summary. */
|
|
440
|
+
function renderDoctor(checks, io, opts) {
|
|
441
|
+
const s = style(io, { nerd: opts.nerd });
|
|
442
|
+
const out = [];
|
|
443
|
+
const order = [...SECTIONS.map(([name]) => name)];
|
|
444
|
+
for (const c of checks)
|
|
445
|
+
if (!order.includes(sectionOf(c.area)))
|
|
446
|
+
order.push(sectionOf(c.area));
|
|
447
|
+
const STATE = { ok: "ok", warn: "warn", fail: "err", skip: "skip" };
|
|
448
|
+
const profileNames = checks.filter((c) => c.area.startsWith("profile ")).map((c) => c.area.slice("profile ".length));
|
|
449
|
+
const pill = (name) => s.profile(name, opts.colors ? profileColor(opts.colors, name) : undefined);
|
|
450
|
+
const pillWidth = Math.max(0, ...profileNames.map((n) => visibleWidth(pill(n))));
|
|
451
|
+
// Fix lines start under the text, after the icon column.
|
|
452
|
+
const iconWidth = Math.max(...["ok", "warn", "err", "skip"].map((n) => visibleWidth(s.icon(n))));
|
|
453
|
+
const under = " ".repeat(2 + iconWidth + 1);
|
|
454
|
+
const fixFlag = `turno doctor${opts.security ? " --security" : ""} --fix`;
|
|
455
|
+
for (const section of order) {
|
|
456
|
+
const rows = checks.filter((c) => sectionOf(c.area) === section);
|
|
457
|
+
if (!rows.length)
|
|
458
|
+
continue;
|
|
459
|
+
if (out.length)
|
|
460
|
+
out.push("");
|
|
461
|
+
out.push(s.header(section));
|
|
462
|
+
for (const [i, c] of rows.entries()) {
|
|
463
|
+
const status = statusOf(c.level);
|
|
464
|
+
let text = c.text;
|
|
465
|
+
let lead = "";
|
|
466
|
+
if (c.area.startsWith("profile ")) {
|
|
467
|
+
const name = c.area.slice("profile ".length);
|
|
468
|
+
const prefix = `profile ${name}: `;
|
|
469
|
+
if (text.startsWith(prefix))
|
|
470
|
+
text = text.slice(prefix.length);
|
|
471
|
+
// On a terminal the pill opens each profile's rows; plain text names it on every row, for grep.
|
|
472
|
+
const first = rows[i - 1]?.area !== c.area;
|
|
473
|
+
lead = `${padEnd(first || !s.color ? pill(name) : "", pillWidth)} `;
|
|
474
|
+
}
|
|
475
|
+
const body = status === "skip" ? s.muted(text) : status === "fail" ? s.err(text) : text;
|
|
476
|
+
out.push(s.wrap(` ${padEnd(s.icon(STATE[status]), iconWidth)} ${lead}`, body));
|
|
477
|
+
if (status === "ok")
|
|
478
|
+
continue;
|
|
479
|
+
const cmd = fixCommand(c);
|
|
480
|
+
// Rows in a run with the same fix (one profile's links) share one fix line, after the last.
|
|
481
|
+
const nextRow = rows[i + 1];
|
|
482
|
+
if (cmd && nextRow && nextRow.area === c.area && statusOf(nextRow.level) !== "ok" && fixCommand(nextRow) === cmd)
|
|
483
|
+
continue;
|
|
484
|
+
const label = status === "skip" ? "optional:" : "fix:";
|
|
485
|
+
if (cmd) {
|
|
486
|
+
const auto = c.fix && isProblem(c) && cmd !== fixFlag ? s.muted(` (${fixFlag} runs it)`) : "";
|
|
487
|
+
out.push(s.wrap(`${under}${s.muted(label)} `, `${status === "skip" ? s.muted(cmd) : s.bold(cmd)}${auto}`));
|
|
488
|
+
}
|
|
489
|
+
else if (c.manual) {
|
|
490
|
+
out.push(s.wrap(`${under}${s.muted(status === "skip" ? label : "manual:")} `, status === "skip" ? s.muted(c.manual) : c.manual));
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
const n = countChecks(checks);
|
|
495
|
+
out.push("", `${countsText(n, { ok: s.ok, warn: s.warn, err: s.err, muted: s.muted })} ${s.muted(`in ${duration(opts.ms)}`)}`);
|
|
496
|
+
const problems = checks.filter(isProblem);
|
|
497
|
+
const repairable = problems.filter((c) => c.fix).length;
|
|
498
|
+
if (repairable && !opts.fixed) {
|
|
499
|
+
const label = s.lead("next", s.bold(s.accent("Next")));
|
|
500
|
+
const what = repairable === problems.length ? `repairs ${repairable === 1 ? "it" : `all ${repairable}`}` : `repairs ${repairable} of ${problems.length}; the others name their fix above`;
|
|
501
|
+
out.push(s.wrap(`${label} `, `${s.bold(fixFlag)} ${s.muted(what)}`));
|
|
502
|
+
}
|
|
503
|
+
return out;
|
|
277
504
|
}
|
|
278
505
|
export async function doctor(io, opts = {}) {
|
|
279
|
-
|
|
506
|
+
const start = Date.now();
|
|
507
|
+
const collect = opts.security ? securitySection : collectChecks;
|
|
508
|
+
const quiet = opts.json || opts.summary;
|
|
509
|
+
let checks = await collect(io.env);
|
|
280
510
|
if (opts.fix) {
|
|
281
511
|
const fixes = new Map();
|
|
282
512
|
for (const c of checks)
|
|
283
|
-
if (c.fix && (c
|
|
513
|
+
if (c.fix && isProblem(c) && !fixes.has(c.fix.label))
|
|
284
514
|
fixes.set(c.fix.label, c.fix);
|
|
515
|
+
const s = quiet ? undefined : style(io);
|
|
285
516
|
for (const f of fixes.values()) {
|
|
286
|
-
if (
|
|
287
|
-
io.out(
|
|
288
|
-
await f.run(
|
|
517
|
+
if (s)
|
|
518
|
+
io.out(s.bold(`$ ${f.label}`));
|
|
519
|
+
await f.run(quiet ? { ...io, out: () => { } } : io);
|
|
289
520
|
}
|
|
290
521
|
if (fixes.size) {
|
|
291
|
-
if (
|
|
522
|
+
if (s)
|
|
292
523
|
io.out("");
|
|
293
|
-
checks = await
|
|
524
|
+
checks = await collect(io.env);
|
|
294
525
|
}
|
|
295
|
-
else if (
|
|
296
|
-
io.out(
|
|
526
|
+
else if (s)
|
|
527
|
+
io.out(`Nothing to fix automatically.\n`);
|
|
297
528
|
}
|
|
298
529
|
const failed = checks.some((c) => c.level === "fail");
|
|
530
|
+
const ms = Date.now() - start;
|
|
299
531
|
if (opts.json) {
|
|
300
|
-
printJson(io
|
|
532
|
+
printJson(io, {
|
|
533
|
+
ok: !failed,
|
|
534
|
+
counts: countChecks(checks),
|
|
535
|
+
ms,
|
|
536
|
+
next: nextCommands(checks),
|
|
537
|
+
checks: checks.map(({ fix, hint, manual, ...c }) => {
|
|
538
|
+
const status = statusOf(c.level);
|
|
539
|
+
const command = status === "ok" ? undefined : (fix?.label ?? hint);
|
|
540
|
+
return { ...c, status, fix: command ?? null, auto: Boolean(fix) && status !== "ok" && status !== "skip", manual: status === "ok" ? null : (manual ?? null) };
|
|
541
|
+
}),
|
|
542
|
+
});
|
|
301
543
|
return failed ? 1 : 0;
|
|
302
544
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
545
|
+
if (opts.summary) {
|
|
546
|
+
io.out(summaryLine(checks, { security: opts.security }));
|
|
547
|
+
return failed ? 1 : 0;
|
|
548
|
+
}
|
|
549
|
+
const look = lookOf(io.env);
|
|
550
|
+
for (const line of renderDoctor(checks, io, { ms, security: opts.security, fixed: opts.fix, ...look }))
|
|
551
|
+
io.out(line);
|
|
308
552
|
return failed ? 1 : 0;
|
|
309
553
|
}
|
|
554
|
+
/** Icons and profile colors from config.toml, as `turno status` uses them; defaults when it does not parse. */
|
|
555
|
+
function lookOf(env) {
|
|
556
|
+
try {
|
|
557
|
+
const config = loadConfig(env);
|
|
558
|
+
return { nerd: config.icons === "nerd" || (config.icons === "auto" && nerdHere(env, config.nerdTerminals)), colors: config.profiles };
|
|
559
|
+
}
|
|
560
|
+
catch {
|
|
561
|
+
return { nerd: false };
|
|
562
|
+
}
|
|
563
|
+
}
|
|
310
564
|
export const command = {
|
|
311
565
|
summary: "check everything (system, config, profiles, MCP, look, mcpd) and fix what is safe to fix",
|
|
312
566
|
usage: [
|
|
313
|
-
"Usage: turno doctor [--fix] [--json]",
|
|
567
|
+
"Usage: turno doctor [--security] [--fix] [--json | --summary]",
|
|
568
|
+
"",
|
|
569
|
+
"One row per check, in sections. Under each problem: the command that fixes it",
|
|
570
|
+
"(fix: ...) or the manual step. Exits 1 when a check fails; warnings exit 0.",
|
|
571
|
+
"",
|
|
572
|
+
"--fix runs every repair marked \"turno doctor --fix runs it\" (relink a profile,",
|
|
573
|
+
"rewrite launchers, finish an upgrade, start mcpd, sync configs), then checks",
|
|
574
|
+
"again. --summary prints one line, the counts and the first fix, for hooks and",
|
|
575
|
+
"status lines. --json gives each check a status (ok, warn, fail or skip), fix (a",
|
|
576
|
+
"command or null), auto (whether --fix runs it) and manual, plus counts, ms and",
|
|
577
|
+
"next (the fix commands, failures first).",
|
|
314
578
|
"",
|
|
315
|
-
"
|
|
316
|
-
"
|
|
579
|
+
"--security runs the security checks instead: who can read turno's folders, who",
|
|
580
|
+
"holds the mcpd port, literal secrets in mcp.toml, agent configs and backups, MCP",
|
|
581
|
+
"servers without an exact version, the age of the mcpd token and the audit log's",
|
|
582
|
+
"hash chain. With --fix it narrows file modes under turno's folders.",
|
|
317
583
|
].join("\n"),
|
|
318
|
-
flags: ["--fix", "--json"],
|
|
584
|
+
flags: ["--security", "--fix", "--json", "--summary"],
|
|
319
585
|
async run(args, io) {
|
|
320
|
-
const p = parseFlags(args, { fix: { type: "boolean" }, ...JSON_FLAG }, 0);
|
|
321
|
-
|
|
586
|
+
const p = parseFlags(args, { security: { type: "boolean" }, fix: { type: "boolean" }, summary: { type: "boolean" }, ...JSON_FLAG }, 0);
|
|
587
|
+
if (bool(p, "json") && bool(p, "summary"))
|
|
588
|
+
return fail("--json and --summary do not go together");
|
|
589
|
+
return doctor(io, { fix: bool(p, "fix"), json: bool(p, "json"), security: bool(p, "security"), summary: bool(p, "summary") });
|
|
322
590
|
},
|
|
323
591
|
};
|
|
324
592
|
//# sourceMappingURL=doctor.js.map
|