turno-cli 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +432 -0
- package/README.md +228 -73
- package/dist/accounts/audit.js +154 -12
- package/dist/accounts/builtin.js +100 -25
- package/dist/accounts/delegate.js +199 -35
- package/dist/accounts/policy.js +79 -0
- package/dist/accounts/registry.js +39 -21
- package/dist/agents/adapter.js +29 -0
- package/dist/agents/claude.js +246 -0
- package/dist/agents/codex.js +186 -0
- package/dist/agents/copilot.js +56 -0
- package/dist/agents/cursor.js +58 -0
- package/dist/agents/index.js +26 -86
- package/dist/agents/snippets.js +43 -13
- package/dist/cli/args.js +38 -6
- package/dist/cli/commands/accounts.js +119 -52
- package/dist/cli/commands/auto.js +121 -33
- package/dist/cli/commands/browser-identity.js +514 -0
- package/dist/cli/commands/browser-session.js +102 -0
- package/dist/cli/commands/browser-vault.js +193 -0
- package/dist/cli/commands/browser.js +319 -138
- package/dist/cli/commands/complete.js +14 -3
- package/dist/cli/commands/completion.js +8 -2
- package/dist/cli/commands/config.js +186 -24
- package/dist/cli/commands/demo.js +321 -0
- package/dist/cli/commands/doctor.js +525 -123
- package/dist/cli/commands/handoff.js +33 -22
- package/dist/cli/commands/identity.js +192 -54
- package/dist/cli/commands/init.js +648 -0
- package/dist/cli/commands/limit.js +84 -16
- package/dist/cli/commands/mcp-call.js +240 -0
- package/dist/cli/commands/mcp-oauth.js +221 -0
- package/dist/cli/commands/mcp-observe.js +539 -0
- package/dist/cli/commands/mcp-share.js +201 -0
- package/dist/cli/commands/mcp.js +816 -187
- package/dist/cli/commands/mcpd.js +388 -76
- package/dist/cli/commands/migrate.js +6 -4
- package/dist/cli/commands/open.js +115 -27
- package/dist/cli/commands/profile.js +396 -78
- package/dist/cli/commands/resolve.js +14 -3
- package/dist/cli/commands/run.js +36 -6
- package/dist/cli/commands/secret.js +80 -76
- package/dist/cli/commands/session.js +17 -6
- package/dist/cli/commands/sessions.js +48 -12
- package/dist/cli/commands/setup.js +214 -164
- package/dist/cli/commands/status.js +227 -44
- package/dist/cli/commands/statusline.js +311 -114
- package/dist/cli/commands/ui.js +78 -68
- package/dist/cli/commands/undo.js +193 -18
- package/dist/cli/commands/uninstall.js +481 -0
- package/dist/cli/commands/upgrade.js +172 -79
- package/dist/cli/commands/usage.js +125 -51
- package/dist/cli/commands/version.js +21 -7
- package/dist/cli/commands/which.js +9 -24
- package/dist/cli/compile-cache.js +32 -0
- package/dist/cli/diagnostics.js +184 -0
- package/dist/cli/exit.js +65 -0
- package/dist/cli/group.js +24 -12
- package/dist/cli/help.js +62 -0
- package/dist/cli/highlight.js +236 -0
- package/dist/cli/hints.js +30 -0
- package/dist/cli/io.js +186 -1
- package/dist/cli/launch.js +52 -39
- package/dist/cli/launchers.js +161 -95
- package/dist/cli/main.js +201 -31
- package/dist/cli/optional.js +144 -0
- package/dist/cli/output.js +123 -0
- package/dist/cli/picker.js +459 -0
- package/dist/cli/registry.js +61 -6
- package/dist/cli/safe.js +87 -0
- package/dist/cli/secret-input.js +63 -0
- package/dist/cli/security.js +561 -0
- package/dist/cli/style.js +311 -0
- package/dist/cli/topics.js +142 -0
- package/dist/core/config.js +181 -23
- package/dist/core/exhausted.js +6 -8
- package/dist/core/fsutil.js +39 -0
- package/dist/core/journal.js +294 -16
- package/dist/core/manifest.js +153 -6
- package/dist/core/paths.js +14 -13
- package/dist/core/profiles.js +160 -10
- package/dist/core/resolve.js +139 -23
- package/dist/core/secrets.js +68 -23
- package/dist/core/sessions.js +13 -20
- package/dist/core/state-file.js +107 -0
- package/dist/core/update.js +31 -18
- package/dist/core/version.js +57 -10
- package/dist/demo/server.js +42 -0
- package/dist/mcpd/cache.js +23 -10
- package/dist/mcpd/calllog.js +254 -0
- package/dist/mcpd/client-names.js +46 -0
- package/dist/mcpd/connectors.js +188 -18
- package/dist/mcpd/daemon.js +472 -115
- package/dist/mcpd/folder-sets.js +42 -0
- package/dist/mcpd/gateway.js +473 -51
- package/dist/mcpd/health.js +313 -0
- package/dist/mcpd/importer.js +453 -36
- package/dist/mcpd/instances.js +453 -65
- package/dist/mcpd/jsonrpc.js +11 -1
- package/dist/mcpd/launchd.js +65 -48
- package/dist/mcpd/middleware.js +144 -0
- package/dist/mcpd/modern.js +686 -0
- package/dist/mcpd/oauth.js +845 -0
- package/dist/mcpd/peerpid.js +134 -6
- package/dist/mcpd/pressure.js +88 -0
- package/dist/mcpd/rss.js +166 -0
- package/dist/mcpd/service.js +191 -0
- package/dist/mcpd/share.js +217 -0
- package/dist/mcpd/state.js +183 -0
- package/dist/mcpd/sync.js +72 -87
- package/dist/mcpd/systemd.js +83 -0
- package/dist/mcpd/tokens.js +85 -0
- package/dist/mcpd/upstream.js +163 -46
- package/dist/statusline/cost.js +167 -44
- package/dist/statusline/input.js +78 -0
- package/dist/statusline/render.js +9 -3
- package/dist/ui/fonts.js +8 -3
- package/dist/ui/settings.js +33 -16
- package/npm-shrinkwrap.json +1102 -0
- package/package.json +10 -9
- package/dist/cli/commands/available.js +0 -18
|
@@ -3,19 +3,33 @@ 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 { JSON_FLAG, bool, parseFlags
|
|
15
|
-
import {
|
|
14
|
+
import { currentStatusLine, isTurnoStatusLine, statusLineLabel } from "../../ui/settings.js";
|
|
15
|
+
import { JSON_FLAG, bool, parseFlags } from "../args.js";
|
|
16
|
+
import { emit, jsonOutput } from "../output.js";
|
|
17
|
+
import { fail } from "../io.js";
|
|
16
18
|
import { findOnPath } from "../launch.js";
|
|
17
19
|
import { MARKER, isGenerated, launcherName, launcherText } from "../launchers.js";
|
|
18
|
-
import {
|
|
20
|
+
import { duration, padEnd, profileColor, style, visibleWidth } from "../style.js";
|
|
21
|
+
import { nerdHere } from "../../ui/terminal-id.js";
|
|
22
|
+
/** `turno doctor --json`. */
|
|
23
|
+
const DOCTOR_JSON = jsonOutput(["ok", "counts", "ms", "next", "checks"]);
|
|
24
|
+
function statusOf(level) {
|
|
25
|
+
return level === "info" ? "skip" : level;
|
|
26
|
+
}
|
|
27
|
+
/** The command that fixes a check, whether `--fix` runs it or a person does. */
|
|
28
|
+
function fixCommand(c) {
|
|
29
|
+
return c.fix?.label ?? c.hint;
|
|
30
|
+
}
|
|
31
|
+
/** Whether a check is a problem: a warning or a failure. */
|
|
32
|
+
const isProblem = (c) => c.level === "warn" || c.level === "fail";
|
|
19
33
|
/** Whether a file is the original bash claudio script rather than this CLI. */
|
|
20
34
|
export function isLegacyScript(file) {
|
|
21
35
|
try {
|
|
@@ -44,7 +58,12 @@ export async function mcpdStatus(env, config) {
|
|
|
44
58
|
token = readFileSync(p.mcpdToken, "utf8").trim();
|
|
45
59
|
}
|
|
46
60
|
catch {
|
|
47
|
-
return {
|
|
61
|
+
return {
|
|
62
|
+
level: "info",
|
|
63
|
+
running: false,
|
|
64
|
+
port,
|
|
65
|
+
text: `mcpd: no token at ${tildify(p.mcpdToken, env)} (not started yet: turno mcp daemon start)`,
|
|
66
|
+
};
|
|
48
67
|
}
|
|
49
68
|
try {
|
|
50
69
|
const res = await fetch(`http://127.0.0.1:${port}/status`, {
|
|
@@ -59,6 +78,59 @@ export async function mcpdStatus(env, config) {
|
|
|
59
78
|
return { level: "info", running: false, port, text: `mcpd not reachable on port ${port} (turno mcp daemon start)` };
|
|
60
79
|
}
|
|
61
80
|
}
|
|
81
|
+
/** `turno mcp sync`, which plans every agent config first and rewrites only those that change. */
|
|
82
|
+
const syncFix = {
|
|
83
|
+
label: "turno mcp sync",
|
|
84
|
+
run: async (io) => (await import("./mcp.js")).command.run(["sync"], io),
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Variables mcp.toml reads from mcpd's environment (`env:NAME`, `${NAME}`) that are not set in
|
|
88
|
+
* this one: in stdio servers' env and args (every profile variant), and in the headers and
|
|
89
|
+
* OAuth client secret of remotes mcpd proxies. Names only, never a value.
|
|
90
|
+
*/
|
|
91
|
+
function envRefChecks(manifest, env) {
|
|
92
|
+
const out = [];
|
|
93
|
+
let refs = 0;
|
|
94
|
+
for (const server of Object.values(manifest.servers)) {
|
|
95
|
+
const unset = new Set();
|
|
96
|
+
const scan = (value, whole = true) => {
|
|
97
|
+
if (value.includes("${") || (whole && value.startsWith("env:")))
|
|
98
|
+
refs++;
|
|
99
|
+
for (const name of unsetVars(value, env, whole))
|
|
100
|
+
unset.add(name);
|
|
101
|
+
};
|
|
102
|
+
if (server.kind === "stdio") {
|
|
103
|
+
if (server.builtin)
|
|
104
|
+
continue;
|
|
105
|
+
for (const variant of ["default", ...Object.keys(server.variants)]) {
|
|
106
|
+
const launch = effectiveLaunch(server, variant);
|
|
107
|
+
for (const v of Object.values(launch.env))
|
|
108
|
+
scan(v);
|
|
109
|
+
for (const a of launch.args)
|
|
110
|
+
scan(a, false);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
else if (server.proxy) {
|
|
114
|
+
for (const v of Object.values(server.headers))
|
|
115
|
+
scan(v);
|
|
116
|
+
if (server.oauth?.clientSecret)
|
|
117
|
+
scan(server.oauth.clientSecret);
|
|
118
|
+
}
|
|
119
|
+
if (!unset.size)
|
|
120
|
+
continue;
|
|
121
|
+
const names = [...unset].sort();
|
|
122
|
+
const list = names.length === 1 ? names[0] : `${names.slice(0, -1).join(", ")} and ${names.at(-1)}`;
|
|
123
|
+
out.push({
|
|
124
|
+
area: "mcp",
|
|
125
|
+
level: "warn",
|
|
126
|
+
text: `${server.name} reads ${list} from mcpd's environment, and ${names.length === 1 ? "it is" : "they are"} not set here`,
|
|
127
|
+
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`,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
if (refs && !out.length)
|
|
131
|
+
out.push({ area: "mcp", level: "ok", text: `mcp.toml: every environment reference is set here (${refs})` });
|
|
132
|
+
return out;
|
|
133
|
+
}
|
|
62
134
|
const repair = (name) => ({
|
|
63
135
|
label: `turno profile repair ${name}`,
|
|
64
136
|
run: async (io) => (await import("./setup.js")).setupProfiles([name], io),
|
|
@@ -80,162 +152,214 @@ function lexists(path) {
|
|
|
80
152
|
return false;
|
|
81
153
|
}
|
|
82
154
|
}
|
|
83
|
-
/** Launcher, folder, hub links and
|
|
84
|
-
|
|
155
|
+
/** Launcher, folder, hub links and agent checks of one profile. */
|
|
156
|
+
function profileChecks(name, agent, env) {
|
|
85
157
|
const a = adapter(agent);
|
|
86
158
|
const area = `profile ${name}`;
|
|
87
159
|
const out = [];
|
|
88
160
|
const launcher = join(paths(env).bin, launcherName(name, agent));
|
|
89
161
|
if (!existsSync(launcher))
|
|
90
|
-
out.push({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
162
|
+
out.push({
|
|
163
|
+
area,
|
|
164
|
+
level: "fail",
|
|
165
|
+
text: `profile ${name}: no launcher ${tildify(launcher, env)}`,
|
|
166
|
+
fix: repair(name),
|
|
167
|
+
});
|
|
168
|
+
else if (!isGenerated(launcher)) {
|
|
169
|
+
out.push({
|
|
170
|
+
area,
|
|
171
|
+
level: "fail",
|
|
172
|
+
text: `profile ${name}: ${tildify(launcher, env)} was not generated by turno`,
|
|
173
|
+
manual: `move ${tildify(launcher, env)} aside (it is yours, so turno does not overwrite it), then turno profile repair ${name}`,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
// Classic launchers vary with the turno that wrote them: only a bash claudio one is stale.
|
|
178
|
+
const text = readFileSync(launcher, "utf8");
|
|
179
|
+
const stale = a.classicLauncher
|
|
180
|
+
? !text.includes(MARKER) && "launcher from the bash claudio"
|
|
181
|
+
: text !== launcherText(name, env, agent) && "launcher is out of date";
|
|
182
|
+
if (stale)
|
|
183
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${stale}`, fix: repair(name) });
|
|
184
|
+
else
|
|
185
|
+
out.push({
|
|
186
|
+
area,
|
|
187
|
+
level: "ok",
|
|
188
|
+
text: `profile ${name}: ${agent === DEFAULT_AGENT ? "" : `${a.label} `}launcher ok`,
|
|
189
|
+
});
|
|
190
|
+
}
|
|
97
191
|
const dir = agentProfileDir(name, agent, env);
|
|
98
192
|
if (!existsSync(dir)) {
|
|
99
193
|
out.push({ area, level: "fail", text: `profile ${name}: ${tildify(dir, env)} does not exist`, fix: repair(name) });
|
|
100
194
|
return out;
|
|
101
195
|
}
|
|
102
196
|
const hub = agentHub(agent, env);
|
|
103
|
-
|
|
197
|
+
const shared = [...a.sharedDirs, ...a.sharedFiles];
|
|
198
|
+
for (const item of shared) {
|
|
104
199
|
const path = join(dir, item);
|
|
105
200
|
const target = join(hub, item);
|
|
106
201
|
if (isLinkTo(path, target))
|
|
107
202
|
continue;
|
|
108
203
|
if (existsSync(path))
|
|
109
|
-
out.push({
|
|
204
|
+
out.push({
|
|
205
|
+
area,
|
|
206
|
+
level: "warn",
|
|
207
|
+
text: `profile ${name}: ${item} is a local copy, not shared`,
|
|
208
|
+
fix: repair(name),
|
|
209
|
+
});
|
|
110
210
|
else if (existsSync(target))
|
|
111
211
|
out.push({ area, level: "warn", text: `profile ${name}: missing link for ${item}`, fix: repair(name) });
|
|
112
212
|
}
|
|
113
|
-
|
|
114
|
-
|
|
213
|
+
for (const w of a.doctorWarnings?.(dir) ?? [])
|
|
214
|
+
out.push({ area, level: "warn", text: `profile ${name}: ${w}`, fix: repair(name) });
|
|
215
|
+
if (a.perAccount) {
|
|
216
|
+
const known = new Set([...shared, ...a.perAccount.items]);
|
|
217
|
+
let entries = [];
|
|
115
218
|
try {
|
|
116
|
-
|
|
219
|
+
entries = readdirSync(dir).sort();
|
|
117
220
|
}
|
|
118
221
|
catch {
|
|
119
|
-
|
|
222
|
+
entries = [];
|
|
223
|
+
}
|
|
224
|
+
for (const item of entries) {
|
|
225
|
+
if (known.has(item) || !lexists(join(dir, item)) || a.perAccount.ignore.test(item))
|
|
226
|
+
continue;
|
|
227
|
+
out.push({
|
|
228
|
+
area,
|
|
229
|
+
level: "info",
|
|
230
|
+
text: `profile ${name}: ${item} is new and unclassified: decide whether to share it`,
|
|
231
|
+
});
|
|
120
232
|
}
|
|
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
233
|
}
|
|
124
|
-
if (!findOnPath(a.command, env))
|
|
125
|
-
out.push({ area, level: "warn", text: `profile ${name}: ${a.command} is not on PATH (${a.install})` });
|
|
126
234
|
return out;
|
|
127
235
|
}
|
|
128
|
-
|
|
129
|
-
async function profileChecks(name, env) {
|
|
130
|
-
const { PER_ACCOUNT, SHARED_DIRS, SHARED_FILES } = await import("./setup.js");
|
|
236
|
+
export async function collectChecks(env) {
|
|
131
237
|
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) });
|
|
238
|
+
const checks = [];
|
|
239
|
+
const add = (area, level, text, how = {}) => checks.push({ area, level, text, ...how });
|
|
240
|
+
const major = Number(process.versions.node.split(".")[0]);
|
|
241
|
+
if (major >= 20)
|
|
242
|
+
add("system", "ok", `node ${process.versions.node}`);
|
|
142
243
|
else
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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 = [];
|
|
244
|
+
add("system", "fail", `node ${process.versions.node}, and turno needs 20 or newer`, {
|
|
245
|
+
manual: "install Node.js 20 or newer (https://nodejs.org)",
|
|
246
|
+
});
|
|
247
|
+
// Every agent is listed; only one that a profile uses can fail.
|
|
248
|
+
let early;
|
|
164
249
|
try {
|
|
165
|
-
|
|
250
|
+
early = loadConfig(env);
|
|
166
251
|
}
|
|
167
252
|
catch {
|
|
168
|
-
|
|
253
|
+
early = undefined;
|
|
254
|
+
}
|
|
255
|
+
const names = early ? listProfiles(early, env) : [];
|
|
256
|
+
const used = new Set(early ? names.map((n) => agentOf(n, early)) : []);
|
|
257
|
+
for (const id of AGENT_IDS) {
|
|
258
|
+
const a = adapter(id);
|
|
259
|
+
const at = findOnPath(a.command, env);
|
|
260
|
+
// An install line is a command, or a page to follow when the agent has no one-line install.
|
|
261
|
+
const install = /^https?:\/\//.test(a.install) ? { manual: `install it: ${a.install}` } : { hint: a.install };
|
|
262
|
+
if (at)
|
|
263
|
+
add("system", used.has(id) ? "ok" : "info", `${a.command} at ${tildify(at, env)}`);
|
|
264
|
+
else if (used.has(id))
|
|
265
|
+
add("system", "fail", `${a.command} not found on PATH, and profiles use it`, install);
|
|
266
|
+
else
|
|
267
|
+
add("system", "info", `${a.command} not installed`, install);
|
|
169
268
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
269
|
+
const { pathAdvice } = await import("./profile.js");
|
|
270
|
+
const advice = names.length ? pathAdvice(env) : undefined;
|
|
271
|
+
if (advice) {
|
|
272
|
+
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)`, {
|
|
273
|
+
manual: `${advice.charAt(0).toLowerCase()}${advice.slice(1)}, then open a new terminal`,
|
|
274
|
+
});
|
|
176
275
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const claude = findOnPath("claude", env);
|
|
186
|
-
add("system", claude ? "ok" : "fail", claude ? `claude at ${tildify(claude, env)}` : "claude not found on PATH");
|
|
276
|
+
const { secretStoreLabel } = await import("../security.js");
|
|
277
|
+
const store = secretStoreLabel(env);
|
|
278
|
+
if (store === "none")
|
|
279
|
+
add("system", "info", "secret store: none (keychain: references cannot resolve; env: ones work)", {
|
|
280
|
+
manual: "install secret-tool (libsecret) to use keychain: references",
|
|
281
|
+
});
|
|
282
|
+
else
|
|
283
|
+
add("system", "ok", `secret store: ${store}`);
|
|
187
284
|
const chrome = env.TURNO_CHROME_APP || "/Applications/Google Chrome.app";
|
|
188
|
-
|
|
285
|
+
if (existsSync(chrome))
|
|
286
|
+
add("system", "ok", "Google Chrome installed");
|
|
287
|
+
else
|
|
288
|
+
add("system", "warn", "Google Chrome not found: claude.ai links open in the default browser", {
|
|
289
|
+
manual: "install Google Chrome, or set TURNO_CHROME_APP to where it is",
|
|
290
|
+
});
|
|
189
291
|
const { recordedVersion, finishUpgrade } = await import("./upgrade.js");
|
|
190
292
|
const version = packageInfo().version;
|
|
191
293
|
const recorded = recordedVersion(env);
|
|
192
294
|
if (recorded && recorded !== version) {
|
|
193
|
-
add("turno", "warn", `turno ${version} runs, but ${recorded} set up the launchers`, {
|
|
295
|
+
add("turno", "warn", `turno ${version} runs, but ${recorded} set up the launchers`, {
|
|
296
|
+
fix: { label: "turno upgrade --finish", run: (io) => finishUpgrade(io, { sync: "no" }) },
|
|
297
|
+
});
|
|
194
298
|
}
|
|
195
299
|
else
|
|
196
300
|
add("turno", "ok", `turno ${version}`);
|
|
197
301
|
const newer = availableUpdate(env);
|
|
198
302
|
if (newer)
|
|
199
|
-
add("turno", "info", `turno ${newer} is available
|
|
303
|
+
add("turno", "info", `turno ${newer} is available`, { hint: "turno upgrade" });
|
|
200
304
|
let config;
|
|
305
|
+
const editConfig = { hint: "turno config edit" };
|
|
201
306
|
try {
|
|
202
307
|
config = loadConfig(env);
|
|
203
308
|
if (existsSync(p.configFile))
|
|
204
309
|
add("config", "ok", `${tildify(p.configFile, env)} parses`);
|
|
205
310
|
else if (migrationPending(env))
|
|
206
|
-
add("config", "info", `no ${tildify(p.configFile, env)} yet
|
|
311
|
+
add("config", "info", `no ${tildify(p.configFile, env)} yet, but a bash claudio config is there`, {
|
|
312
|
+
hint: "turno migrate",
|
|
313
|
+
});
|
|
207
314
|
else
|
|
208
315
|
add("config", "info", `no ${tildify(p.configFile, env)} (defaults)`);
|
|
316
|
+
for (const f of configFindings(config, env))
|
|
317
|
+
add("config", "warn", f.text, f.manual ? { manual: f.manual } : { hint: f.hint ?? "turno config edit" });
|
|
209
318
|
}
|
|
210
319
|
catch (err) {
|
|
211
|
-
add("config", "fail", err.message);
|
|
320
|
+
add("config", "fail", err.message, editConfig);
|
|
212
321
|
}
|
|
322
|
+
let manifest;
|
|
213
323
|
try {
|
|
214
324
|
const m = loadManifest(env);
|
|
325
|
+
manifest = m;
|
|
215
326
|
if (existsSync(p.mcpFile))
|
|
216
327
|
add("config", "ok", `${tildify(p.mcpFile, env)} parses (${Object.keys(m.servers).length} servers)`);
|
|
217
328
|
else
|
|
218
|
-
add("config", "info", `no ${tildify(p.mcpFile, env)} yet
|
|
329
|
+
add("config", "info", `no ${tildify(p.mcpFile, env)} yet`, { hint: "turno mcp import" });
|
|
219
330
|
}
|
|
220
331
|
catch (err) {
|
|
221
|
-
add("config", "fail", err.message
|
|
332
|
+
add("config", "fail", err.message, {
|
|
333
|
+
manual: `correct ${tildify(p.mcpFile, env)} where the error points`,
|
|
334
|
+
});
|
|
222
335
|
}
|
|
223
336
|
if (existsSync(p.accountsFile)) {
|
|
224
337
|
try {
|
|
225
|
-
loadRegistry(env);
|
|
338
|
+
const reg = loadRegistry(env);
|
|
226
339
|
add("config", "ok", `${tildify(p.accountsFile, env)} parses`);
|
|
340
|
+
// Without read_tools a delegated read is a write: confirmed, with every tool.
|
|
341
|
+
const noReads = Object.values(reg.accounts)
|
|
342
|
+
.filter((a) => !a.readTools?.length)
|
|
343
|
+
.map((a) => a.id)
|
|
344
|
+
.sort();
|
|
345
|
+
if (noReads.length) {
|
|
346
|
+
add("config", "warn", `accounts without read_tools: ${noReads.join(", ")}; delegated reads get every tool of the account and ask like writes`, {
|
|
347
|
+
manual: `add read_tools to each of them in ${tildify(p.accountsFile, env)}`,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
227
350
|
}
|
|
228
351
|
catch (err) {
|
|
229
|
-
add("config", "fail", err.message
|
|
352
|
+
add("config", "fail", err.message, {
|
|
353
|
+
manual: `correct ${tildify(p.accountsFile, env)} where the error points`,
|
|
354
|
+
});
|
|
230
355
|
}
|
|
231
356
|
}
|
|
232
357
|
if (config) {
|
|
233
358
|
const profiles = listProfiles(config, env);
|
|
234
359
|
if (profiles.length === 0)
|
|
235
|
-
add("profiles", "info", "no profiles yet
|
|
360
|
+
add("profiles", "info", "no profiles yet", { hint: "turno profile add <name>" });
|
|
236
361
|
for (const name of profiles) {
|
|
237
|
-
|
|
238
|
-
checks.push(...(agent === "claude" ? await profileChecks(name, env) : await agentProfileChecks(name, agent, env)));
|
|
362
|
+
checks.push(...profileChecks(name, agentOf(name, config), env));
|
|
239
363
|
}
|
|
240
364
|
}
|
|
241
365
|
const legacyBin = join(p.bin, "claudio");
|
|
@@ -245,19 +369,48 @@ export async function collectChecks(env) {
|
|
|
245
369
|
const { bypassingServers } = await import("./mcp.js");
|
|
246
370
|
const b = await bypassingServers(env);
|
|
247
371
|
for (const s of b.plugins)
|
|
248
|
-
add("mcp", "info", `plugin server ${s.plugin}/${s.name} starts in every session
|
|
249
|
-
|
|
250
|
-
|
|
372
|
+
add("mcp", "info", `plugin server ${s.plugin}/${s.name} starts in every session`, { hint: "turno mcp doctor" });
|
|
373
|
+
// turno mcp sync replaces a hub entry with the gateway's when mcp.toml serves it to the profile the hub belongs to.
|
|
374
|
+
const hubProfile = config?.system || "default";
|
|
375
|
+
for (const d of b.direct) {
|
|
376
|
+
const def = manifest?.servers[d.name];
|
|
377
|
+
const how = !d.inManifest
|
|
378
|
+
? { hint: "turno mcp import" }
|
|
379
|
+
: def && servesProfile(def, hubProfile)
|
|
380
|
+
? { fix: syncFix }
|
|
381
|
+
: {
|
|
382
|
+
manual: `remove ${d.name} from ${tildify(p.hubConfig, env)}, or serve it to profile ${hubProfile} in mcp.toml`,
|
|
383
|
+
};
|
|
384
|
+
add("mcp", "warn", `${d.name} runs outside mcpd`, how);
|
|
385
|
+
}
|
|
386
|
+
const { describeLogin, oauthLogins } = await import("./mcp-oauth.js");
|
|
387
|
+
for (const l of await oauthLogins(env)) {
|
|
388
|
+
const ok = l.state === "logged in" || l.state === "expired";
|
|
389
|
+
const login = `turno mcp login ${l.server}${l.variant === "default" ? "" : ` --profile ${l.variant}`}`;
|
|
390
|
+
const said = describeLogin(l);
|
|
391
|
+
// describeLogin ends with the login command; the fix line shows it instead.
|
|
392
|
+
const text = said.endsWith(`: ${login}`) ? said.slice(0, -login.length - 2) : said;
|
|
393
|
+
const how = ok
|
|
394
|
+
? {}
|
|
395
|
+
: said !== text
|
|
396
|
+
? { hint: login }
|
|
397
|
+
: { manual: "install a secret store (macOS Keychain or secret-tool) so turno can read the login" };
|
|
398
|
+
add("mcp", ok ? "ok" : "warn", `${l.server}${l.variant === "default" ? "" : `@${l.variant}`} OAuth: ${text}`, how);
|
|
399
|
+
}
|
|
251
400
|
}
|
|
252
401
|
catch {
|
|
253
402
|
/* a broken mcp.toml is reported above */
|
|
254
403
|
}
|
|
404
|
+
if (manifest)
|
|
405
|
+
checks.push(...envRefChecks(manifest, env));
|
|
255
406
|
const settings = join(p.hub, "settings.json");
|
|
256
407
|
const line = currentStatusLine(settings);
|
|
257
408
|
if (isTurnoStatusLine(line))
|
|
258
409
|
add("look", "ok", "status line: turno statusline");
|
|
259
410
|
else
|
|
260
|
-
add("look", "info", `status line: ${line
|
|
411
|
+
add("look", "info", `status line: ${statusLineLabel(line, env)} in ${tildify(settings, env)}`, {
|
|
412
|
+
hint: "turno ui install",
|
|
413
|
+
});
|
|
261
414
|
const fontDir = userFontDir(env);
|
|
262
415
|
if (fontDir) {
|
|
263
416
|
const fonts = checkFonts(FALLBACK, fontDir);
|
|
@@ -265,60 +418,309 @@ export async function collectChecks(env) {
|
|
|
265
418
|
if (have === fonts.length)
|
|
266
419
|
add("look", "ok", `font: ${FALLBACK.family} installed`);
|
|
267
420
|
else
|
|
268
|
-
add("look", "info", `font: ${FALLBACK.family} ${have}/${fonts.length} files in ${tildify(fontDir, env)}
|
|
421
|
+
add("look", "info", `font: ${FALLBACK.family} ${have}/${fonts.length} files in ${tildify(fontDir, env)}`, {
|
|
422
|
+
hint: "turno ui install",
|
|
423
|
+
});
|
|
269
424
|
}
|
|
270
|
-
|
|
271
|
-
add("mcpd", mcpd.level, mcpd.text);
|
|
425
|
+
checks.push(...(await mcpdSection(env)));
|
|
272
426
|
return checks;
|
|
273
427
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
428
|
+
// ---- mcpd section: service file, token mode, port owner, start errors, synced ports.
|
|
429
|
+
// The checks live in mcpd/health.ts; keep this section separate from the rest of doctor.
|
|
430
|
+
async function mcpdSection(env) {
|
|
431
|
+
const { mcpdChecks } = await import("../../mcpd/health.js");
|
|
432
|
+
return (await mcpdChecks(env)).map((c) => ({ area: "mcpd", ...c }));
|
|
433
|
+
}
|
|
434
|
+
// ---- end of the mcpd section
|
|
435
|
+
// ---- security section: `turno doctor --security` runs only these checks.
|
|
436
|
+
async function securitySection(env) {
|
|
437
|
+
return (await import("../security.js")).securityChecks(env);
|
|
438
|
+
}
|
|
439
|
+
// ---- end of the security section
|
|
440
|
+
/** Screen sections in order, and the check areas each one holds. */
|
|
441
|
+
const SECTIONS = [
|
|
442
|
+
["System", (a) => a === "system" || a === "turno"],
|
|
443
|
+
["Config", (a) => a === "config"],
|
|
444
|
+
["Profiles", (a) => a === "profiles" || a.startsWith("profile ")],
|
|
445
|
+
["MCP", (a) => a === "mcp"],
|
|
446
|
+
["Look", (a) => a === "look"],
|
|
447
|
+
["Gateway", (a) => a === "mcpd"],
|
|
448
|
+
["Security", (a) => a === "security"],
|
|
449
|
+
];
|
|
450
|
+
function sectionOf(area) {
|
|
451
|
+
return SECTIONS.find(([, has]) => has(area))?.[0] ?? area.charAt(0).toUpperCase() + area.slice(1);
|
|
452
|
+
}
|
|
453
|
+
function countChecks(checks) {
|
|
454
|
+
const n = { ok: 0, warn: 0, fail: 0, skip: 0 };
|
|
455
|
+
for (const c of checks)
|
|
456
|
+
n[statusOf(c.level)]++;
|
|
457
|
+
return n;
|
|
458
|
+
}
|
|
459
|
+
/** "12 ok, 2 warnings, 1 failure, 3 skipped": zero problems and skips are left out. */
|
|
460
|
+
function countsText(n, paint = {}) {
|
|
461
|
+
const id = (s) => s;
|
|
462
|
+
const parts = [(paint.ok ?? id)(`${n.ok} ok`)];
|
|
463
|
+
if (n.warn)
|
|
464
|
+
parts.push((paint.warn ?? id)(`${n.warn} warning${n.warn === 1 ? "" : "s"}`));
|
|
465
|
+
if (n.fail)
|
|
466
|
+
parts.push((paint.err ?? id)(`${n.fail} failure${n.fail === 1 ? "" : "s"}`));
|
|
467
|
+
if (n.skip)
|
|
468
|
+
parts.push((paint.muted ?? id)(`${n.skip} skipped`));
|
|
469
|
+
return parts.join(", ");
|
|
470
|
+
}
|
|
471
|
+
/** The fix commands of every problem, failures first, each once: `next` in `--json`. */
|
|
472
|
+
function nextCommands(checks) {
|
|
473
|
+
const out = [];
|
|
474
|
+
for (const level of ["fail", "warn"]) {
|
|
475
|
+
for (const c of checks) {
|
|
476
|
+
const cmd = c.level === level ? fixCommand(c) : undefined;
|
|
477
|
+
if (cmd && !out.includes(cmd))
|
|
478
|
+
out.push(cmd);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
return out;
|
|
482
|
+
}
|
|
483
|
+
/** `--summary`: one line with the counts and the first fix, for hooks and the status line. */
|
|
484
|
+
function summaryLine(checks, opts = {}) {
|
|
485
|
+
const head = `turno doctor${opts.security ? " --security" : ""}: ${countsText(countChecks(checks))}`;
|
|
486
|
+
const problems = checks.filter(isProblem);
|
|
487
|
+
if (!problems.length)
|
|
488
|
+
return head;
|
|
489
|
+
const [first] = nextCommands(checks);
|
|
490
|
+
if (first)
|
|
491
|
+
return `${head}; fix: ${first}`;
|
|
492
|
+
return `${head}; turno doctor${opts.security ? " --security" : ""} shows the manual steps`;
|
|
493
|
+
}
|
|
494
|
+
/** The doctor screen as lines: sections, one row per check with its fix, and a summary. */
|
|
495
|
+
function renderDoctor(checks, io, opts) {
|
|
496
|
+
const s = style(io, { nerd: opts.nerd });
|
|
497
|
+
const out = [];
|
|
498
|
+
const order = [...SECTIONS.map(([name]) => name)];
|
|
499
|
+
for (const c of checks)
|
|
500
|
+
if (!order.includes(sectionOf(c.area)))
|
|
501
|
+
order.push(sectionOf(c.area));
|
|
502
|
+
const STATE = { ok: "ok", warn: "warn", fail: "err", skip: "skip" };
|
|
503
|
+
const profileNames = checks.filter((c) => c.area.startsWith("profile ")).map((c) => c.area.slice("profile ".length));
|
|
504
|
+
const pill = (name) => s.profile(name, opts.colors ? profileColor(opts.colors, name) : undefined);
|
|
505
|
+
const pillWidth = Math.max(0, ...profileNames.map((n) => visibleWidth(pill(n))));
|
|
506
|
+
// Fix lines start under the text, after the icon column.
|
|
507
|
+
const iconWidth = Math.max(...["ok", "warn", "err", "skip"].map((n) => visibleWidth(s.icon(n))));
|
|
508
|
+
const under = " ".repeat(2 + iconWidth + 1);
|
|
509
|
+
const fixFlag = `turno doctor${opts.security ? " --security" : ""} --fix`;
|
|
510
|
+
for (const section of order) {
|
|
511
|
+
const rows = checks.filter((c) => sectionOf(c.area) === section);
|
|
512
|
+
if (!rows.length)
|
|
513
|
+
continue;
|
|
514
|
+
if (out.length)
|
|
515
|
+
out.push("");
|
|
516
|
+
out.push(s.header(section));
|
|
517
|
+
for (const [i, c] of rows.entries()) {
|
|
518
|
+
const status = statusOf(c.level);
|
|
519
|
+
let text = c.text;
|
|
520
|
+
let lead = "";
|
|
521
|
+
if (c.area.startsWith("profile ")) {
|
|
522
|
+
const name = c.area.slice("profile ".length);
|
|
523
|
+
const prefix = `profile ${name}: `;
|
|
524
|
+
if (text.startsWith(prefix))
|
|
525
|
+
text = text.slice(prefix.length);
|
|
526
|
+
// On a terminal the pill opens each profile's rows; plain text names it on every row, for grep.
|
|
527
|
+
const first = rows[i - 1]?.area !== c.area;
|
|
528
|
+
lead = `${padEnd(first || !s.color ? pill(name) : "", pillWidth)} `;
|
|
529
|
+
}
|
|
530
|
+
const body = status === "skip" ? s.muted(text) : status === "fail" ? s.err(text) : text;
|
|
531
|
+
out.push(s.wrap(` ${padEnd(s.icon(STATE[status]), iconWidth)} ${lead}`, body));
|
|
532
|
+
if (status === "ok")
|
|
533
|
+
continue;
|
|
534
|
+
const cmd = fixCommand(c);
|
|
535
|
+
// Rows in a run with the same fix (one profile's links) share one fix line, after the last.
|
|
536
|
+
const nextRow = rows[i + 1];
|
|
537
|
+
if (cmd && nextRow && nextRow.area === c.area && statusOf(nextRow.level) !== "ok" && fixCommand(nextRow) === cmd)
|
|
538
|
+
continue;
|
|
539
|
+
const label = status === "skip" ? "optional:" : "fix:";
|
|
540
|
+
if (cmd) {
|
|
541
|
+
const auto = c.fix && isProblem(c) && cmd !== fixFlag ? s.muted(` (${fixFlag} runs it)`) : "";
|
|
542
|
+
out.push(s.wrap(`${under}${s.muted(label)} `, `${status === "skip" ? s.muted(cmd) : s.bold(cmd)}${auto}`));
|
|
543
|
+
}
|
|
544
|
+
else if (c.manual) {
|
|
545
|
+
out.push(s.wrap(`${under}${s.muted(status === "skip" ? label : "manual:")} `, status === "skip" ? s.muted(c.manual) : c.manual));
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
const n = countChecks(checks);
|
|
550
|
+
out.push("", `${countsText(n, { ok: s.ok, warn: s.warn, err: s.err, muted: s.muted })} ${s.muted(`in ${duration(opts.ms)}`)}`);
|
|
551
|
+
const problems = checks.filter(isProblem);
|
|
552
|
+
const repairable = problems.filter((c) => c.fix).length;
|
|
553
|
+
if (repairable && !opts.fixed) {
|
|
554
|
+
const label = s.lead("next", s.bold(s.accent("Next")));
|
|
555
|
+
const what = repairable === problems.length
|
|
556
|
+
? `repairs ${repairable === 1 ? "it" : `all ${repairable}`}`
|
|
557
|
+
: `repairs ${repairable} of ${problems.length}; the others name their fix above`;
|
|
558
|
+
out.push(s.wrap(`${label} `, `${s.bold(fixFlag)} ${s.muted(what)}`));
|
|
559
|
+
}
|
|
560
|
+
return out;
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* `--report`: a Markdown block for an issue (versions, OS, agents, paths, mcpd, the findings),
|
|
564
|
+
* with no tokens or secret values. Exits like doctor does.
|
|
565
|
+
*/
|
|
566
|
+
async function report(io, checks, security) {
|
|
567
|
+
let config;
|
|
568
|
+
try {
|
|
569
|
+
config = loadConfig(io.env);
|
|
570
|
+
}
|
|
571
|
+
catch {
|
|
572
|
+
config = undefined;
|
|
573
|
+
}
|
|
574
|
+
const mcpd = await mcpdStatus(io.env, config);
|
|
575
|
+
let status;
|
|
576
|
+
if (mcpd.running) {
|
|
577
|
+
const { mcpdRequest } = await import("./mcp.js");
|
|
578
|
+
const r = await mcpdRequest(io.env, "GET", "/status");
|
|
579
|
+
if (r !== "down" && r.status === 200 && typeof r.body === "object" && r.body !== null)
|
|
580
|
+
status = r.body;
|
|
581
|
+
}
|
|
582
|
+
const { reportMarkdown } = await import("../diagnostics.js");
|
|
583
|
+
const lines = await reportMarkdown(io.env, {
|
|
584
|
+
counts: countChecks(checks),
|
|
585
|
+
checks: checks.map((c) => ({
|
|
586
|
+
status: statusOf(c.level),
|
|
587
|
+
area: c.area,
|
|
588
|
+
text: c.text,
|
|
589
|
+
...(fixCommand(c) ? { fix: fixCommand(c) } : {}),
|
|
590
|
+
})),
|
|
591
|
+
mcpd,
|
|
592
|
+
...(status ? { status } : {}),
|
|
593
|
+
security,
|
|
594
|
+
});
|
|
595
|
+
for (const l of lines)
|
|
596
|
+
io.out(l);
|
|
597
|
+
return checks.some((c) => c.level === "fail") ? 1 : 0;
|
|
277
598
|
}
|
|
278
599
|
export async function doctor(io, opts = {}) {
|
|
279
|
-
|
|
600
|
+
const start = Date.now();
|
|
601
|
+
const collect = opts.security ? securitySection : collectChecks;
|
|
602
|
+
const quiet = opts.json || opts.summary;
|
|
603
|
+
let checks = await collect(io.env);
|
|
604
|
+
if (opts.report)
|
|
605
|
+
return report(io, checks, Boolean(opts.security));
|
|
280
606
|
if (opts.fix) {
|
|
281
607
|
const fixes = new Map();
|
|
282
608
|
for (const c of checks)
|
|
283
|
-
if (c.fix && (c
|
|
609
|
+
if (c.fix && isProblem(c) && !fixes.has(c.fix.label))
|
|
284
610
|
fixes.set(c.fix.label, c.fix);
|
|
611
|
+
const s = quiet ? undefined : style(io);
|
|
285
612
|
for (const f of fixes.values()) {
|
|
286
|
-
if (
|
|
287
|
-
io.out(
|
|
288
|
-
await f.run(
|
|
613
|
+
if (s)
|
|
614
|
+
io.out(s.bold(`$ ${f.label}`));
|
|
615
|
+
await f.run(quiet ? { ...io, out: () => { } } : io);
|
|
289
616
|
}
|
|
290
617
|
if (fixes.size) {
|
|
291
|
-
if (
|
|
618
|
+
if (s)
|
|
292
619
|
io.out("");
|
|
293
|
-
checks = await
|
|
620
|
+
checks = await collect(io.env);
|
|
294
621
|
}
|
|
295
|
-
else if (
|
|
296
|
-
io.out(
|
|
622
|
+
else if (s)
|
|
623
|
+
io.out(`Nothing to fix automatically.\n`);
|
|
297
624
|
}
|
|
298
625
|
const failed = checks.some((c) => c.level === "fail");
|
|
626
|
+
const ms = Date.now() - start;
|
|
299
627
|
if (opts.json) {
|
|
300
|
-
|
|
628
|
+
emit(io, opts.parsed, DOCTOR_JSON, {
|
|
629
|
+
ok: !failed,
|
|
630
|
+
counts: countChecks(checks),
|
|
631
|
+
ms,
|
|
632
|
+
next: nextCommands(checks),
|
|
633
|
+
checks: checks.map(({ fix, hint, manual, ...c }) => {
|
|
634
|
+
const status = statusOf(c.level);
|
|
635
|
+
const command = status === "ok" ? undefined : (fix?.label ?? hint);
|
|
636
|
+
return {
|
|
637
|
+
...c,
|
|
638
|
+
status,
|
|
639
|
+
fix: command ?? null,
|
|
640
|
+
auto: Boolean(fix) && status !== "ok" && status !== "skip",
|
|
641
|
+
manual: status === "ok" ? null : (manual ?? null),
|
|
642
|
+
};
|
|
643
|
+
}),
|
|
644
|
+
});
|
|
301
645
|
return failed ? 1 : 0;
|
|
302
646
|
}
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
647
|
+
if (opts.summary) {
|
|
648
|
+
io.out(summaryLine(checks, { security: opts.security }));
|
|
649
|
+
return failed ? 1 : 0;
|
|
650
|
+
}
|
|
651
|
+
const look = lookOf(io.env);
|
|
652
|
+
for (const line of renderDoctor(checks, io, { ms, security: opts.security, fixed: opts.fix, ...look }))
|
|
653
|
+
io.out(line);
|
|
308
654
|
return failed ? 1 : 0;
|
|
309
655
|
}
|
|
656
|
+
/** Icons and profile colors from config.toml, as `turno status` uses them; defaults when it does not parse. */
|
|
657
|
+
function lookOf(env) {
|
|
658
|
+
try {
|
|
659
|
+
const config = loadConfig(env);
|
|
660
|
+
return {
|
|
661
|
+
nerd: config.icons === "nerd" || (config.icons === "auto" && nerdHere(env, config.nerdTerminals)),
|
|
662
|
+
colors: config.profiles,
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
catch {
|
|
666
|
+
return { nerd: false };
|
|
667
|
+
}
|
|
668
|
+
}
|
|
310
669
|
export const command = {
|
|
311
670
|
summary: "check everything (system, config, profiles, MCP, look, mcpd) and fix what is safe to fix",
|
|
312
671
|
usage: [
|
|
313
|
-
"Usage: turno doctor [--fix] [--json]",
|
|
672
|
+
"Usage: turno doctor [--security] [--fix] [--json | --summary | --report]",
|
|
314
673
|
"",
|
|
315
|
-
"
|
|
316
|
-
"
|
|
674
|
+
"One row per check, in sections. Under each problem: the command that fixes it",
|
|
675
|
+
"(fix: ...) or the manual step. Exits 1 when a check fails; warnings exit 0.",
|
|
676
|
+
"",
|
|
677
|
+
'--fix runs every repair marked "turno doctor --fix runs it" (relink a profile,',
|
|
678
|
+
"rewrite launchers, finish an upgrade, start mcpd, sync configs), then checks",
|
|
679
|
+
"again. --summary prints one line, the counts and the first fix, for hooks and",
|
|
680
|
+
"status lines. --json gives each check a status (ok, warn, fail or skip), fix (a",
|
|
681
|
+
"command or null), auto (whether --fix runs it) and manual, plus counts, ms and",
|
|
682
|
+
"next (the fix commands, failures first).",
|
|
683
|
+
"",
|
|
684
|
+
"--report prints a Markdown block to paste in an issue: turno, Node and OS",
|
|
685
|
+
"versions, each agent and its version, mcpd's state, the warnings and failures,",
|
|
686
|
+
"and every path turno uses. It holds no tokens or secret values; profile and",
|
|
687
|
+
"server names appear.",
|
|
688
|
+
"",
|
|
689
|
+
"--security runs the security checks instead: who can read turno's folders, who",
|
|
690
|
+
"holds the mcpd port, literal secrets in mcp.toml, agent configs and backups, MCP",
|
|
691
|
+
"servers without an exact version, the age of the mcpd token and the audit log's",
|
|
692
|
+
"hash chain. With --fix it narrows file modes under turno's folders.",
|
|
693
|
+
"",
|
|
694
|
+
"Examples:",
|
|
695
|
+
" $ turno doctor",
|
|
696
|
+
" $ turno doctor --fix",
|
|
697
|
+
" $ turno doctor --summary",
|
|
698
|
+
" $ turno doctor --security --json",
|
|
699
|
+
" $ turno doctor --report | pbcopy # paste it in an issue",
|
|
317
700
|
].join("\n"),
|
|
318
|
-
flags: ["--fix", "--json"],
|
|
701
|
+
flags: ["--security", "--fix", "--json", "--summary", "--report"],
|
|
702
|
+
json: DOCTOR_JSON,
|
|
319
703
|
async run(args, io) {
|
|
320
|
-
const p = parseFlags(args, {
|
|
321
|
-
|
|
704
|
+
const p = parseFlags(args, {
|
|
705
|
+
security: { type: "boolean" },
|
|
706
|
+
fix: { type: "boolean" },
|
|
707
|
+
summary: { type: "boolean" },
|
|
708
|
+
report: { type: "boolean" },
|
|
709
|
+
...JSON_FLAG,
|
|
710
|
+
}, 0);
|
|
711
|
+
const modes = ["json", "summary", "report"].filter((m) => bool(p, m));
|
|
712
|
+
if (modes.length > 1)
|
|
713
|
+
return fail(`${modes.map((m) => `--${m}`).join(" and ")} do not go together`);
|
|
714
|
+
if (bool(p, "report") && bool(p, "fix"))
|
|
715
|
+
return fail("--report only reads; run turno doctor --fix first, then --report");
|
|
716
|
+
return doctor(io, {
|
|
717
|
+
fix: bool(p, "fix"),
|
|
718
|
+
json: bool(p, "json"),
|
|
719
|
+
security: bool(p, "security"),
|
|
720
|
+
summary: bool(p, "summary"),
|
|
721
|
+
report: bool(p, "report"),
|
|
722
|
+
parsed: p,
|
|
723
|
+
});
|
|
322
724
|
},
|
|
323
725
|
};
|
|
324
726
|
//# sourceMappingURL=doctor.js.map
|