turno-cli 0.2.0 → 0.4.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 +266 -0
- package/README.md +134 -42
- package/dist/accounts/audit.js +27 -15
- package/dist/accounts/builtin.js +35 -7
- package/dist/accounts/delegate.js +30 -7
- package/dist/accounts/policy.js +4 -2
- package/dist/accounts/registry.js +3 -1
- package/dist/agents/adapter.js +22 -0
- package/dist/agents/claude.js +54 -3
- package/dist/agents/codex.js +94 -6
- package/dist/agents/copilot.js +19 -2
- package/dist/agents/cursor.js +19 -2
- package/dist/agents/index.js +1 -1
- package/dist/agents/snippets.js +37 -10
- package/dist/cli/args.js +32 -15
- package/dist/cli/commands/accounts.js +29 -7
- package/dist/cli/commands/auto.js +50 -12
- package/dist/cli/commands/browser-do-session.js +170 -0
- package/dist/cli/commands/browser-do.js +740 -0
- package/dist/cli/commands/browser-flows.js +300 -0
- package/dist/cli/commands/browser-identity.js +952 -0
- package/dist/cli/commands/browser-live.js +118 -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 +303 -62
- package/dist/cli/commands/complete.js +13 -3
- package/dist/cli/commands/completion.js +4 -0
- package/dist/cli/commands/config.js +90 -13
- package/dist/cli/commands/demo.js +36 -7
- package/dist/cli/commands/doctor.js +170 -36
- package/dist/cli/commands/identity.js +101 -12
- package/dist/cli/commands/init.js +42 -10
- package/dist/cli/commands/limit.js +65 -9
- package/dist/cli/commands/mcp-call.js +240 -0
- package/dist/cli/commands/mcp-oauth.js +33 -6
- package/dist/cli/commands/mcp-observe.js +128 -23
- package/dist/cli/commands/mcp-share.js +201 -0
- package/dist/cli/commands/mcp.js +203 -42
- package/dist/cli/commands/mcpd.js +76 -12
- package/dist/cli/commands/open.js +26 -3
- package/dist/cli/commands/profile.js +212 -30
- package/dist/cli/commands/resolve.js +8 -1
- package/dist/cli/commands/run.js +24 -4
- package/dist/cli/commands/secret.js +23 -38
- package/dist/cli/commands/session.js +16 -5
- package/dist/cli/commands/sessions.js +7 -1
- package/dist/cli/commands/setup.js +83 -11
- package/dist/cli/commands/status.js +67 -15
- package/dist/cli/commands/statusline.js +7 -2
- package/dist/cli/commands/ui.js +17 -5
- package/dist/cli/commands/undo.js +39 -7
- package/dist/cli/commands/uninstall.js +24 -5
- package/dist/cli/commands/upgrade.js +113 -76
- package/dist/cli/commands/usage.js +11 -10
- package/dist/cli/commands/version.js +20 -8
- package/dist/cli/commands/which.js +5 -3
- package/dist/cli/diagnostics.js +184 -0
- package/dist/cli/exit.js +65 -0
- package/dist/cli/group.js +20 -8
- package/dist/cli/help.js +6 -1
- package/dist/cli/hints.js +30 -0
- package/dist/cli/io.js +24 -8
- package/dist/cli/launch.js +31 -2
- package/dist/cli/launchers.js +25 -10
- package/dist/cli/main.js +52 -18
- package/dist/cli/optional.js +144 -0
- package/dist/cli/output.js +123 -0
- package/dist/cli/picker.js +17 -5
- package/dist/cli/registry.js +20 -2
- package/dist/cli/safe.js +87 -0
- package/dist/cli/secret-input.js +63 -0
- package/dist/cli/security.js +31 -9
- package/dist/cli/style.js +35 -5
- package/dist/cli/topics.js +155 -0
- package/dist/core/config.js +39 -3
- package/dist/core/fsutil.js +2 -10
- package/dist/core/journal.js +19 -11
- package/dist/core/manifest.js +28 -1
- package/dist/core/paths.js +6 -112
- package/dist/core/profiles.js +28 -8
- package/dist/core/resolve.js +13 -3
- package/dist/core/secrets.js +4 -154
- package/dist/core/state-file.js +107 -0
- package/dist/core/update.js +14 -11
- package/dist/core/version.js +57 -10
- package/dist/demo/server.js +10 -2
- package/dist/mcpd/cache.js +6 -7
- package/dist/mcpd/calllog.js +10 -9
- package/dist/mcpd/client-names.js +8 -13
- package/dist/mcpd/connectors.js +42 -3
- package/dist/mcpd/daemon.js +29 -8
- package/dist/mcpd/folder-sets.js +5 -2
- package/dist/mcpd/gateway.js +57 -29
- package/dist/mcpd/health.js +70 -26
- package/dist/mcpd/importer.js +106 -9
- package/dist/mcpd/instances.js +70 -32
- package/dist/mcpd/jsonrpc.js +3 -1
- package/dist/mcpd/middleware.js +156 -0
- package/dist/mcpd/modern.js +57 -19
- package/dist/mcpd/oauth.js +71 -17
- package/dist/mcpd/peerpid.js +63 -17
- package/dist/mcpd/pressure.js +4 -1
- package/dist/mcpd/rss.js +34 -19
- package/dist/mcpd/service.js +28 -4
- package/dist/mcpd/share.js +217 -0
- package/dist/mcpd/state.js +16 -16
- package/dist/mcpd/sync.js +22 -12
- package/dist/mcpd/systemd.js +4 -1
- package/dist/mcpd/tokens.js +4 -8
- package/dist/mcpd/upstream.js +12 -5
- package/dist/statusline/cost.js +17 -4
- package/dist/statusline/input.js +15 -3
- package/dist/ui/fonts.js +1 -1
- package/dist/ui/settings.js +6 -1
- package/npm-shrinkwrap.json +12 -3
- package/package.json +7 -6
|
@@ -6,11 +6,14 @@ import { Journal } from "../../core/journal.js";
|
|
|
6
6
|
import { paths, writePrivateFile } from "../../core/paths.js";
|
|
7
7
|
import { listProfiles } from "../../core/profiles.js";
|
|
8
8
|
import { fetchLatest, isSemver, updateChecksOff } from "../../core/update.js";
|
|
9
|
-
import { compareVersions, detectInstall, packageInfo, upgradeCommand } from "../../core/version.js";
|
|
10
|
-
import { DRY_RUN, JSON_FLAG, bool, parseFlags,
|
|
9
|
+
import { ONE_OFF_RUNNERS, compareVersions, detectInstall, isOneOff, packageInfo, upgradeCommand, } from "../../core/version.js";
|
|
10
|
+
import { DRY_RUN, JSON_FLAG, bool, parseFlags, str } from "../args.js";
|
|
11
|
+
import { emit, jsonOutput } from "../output.js";
|
|
11
12
|
import { confirm, fail } from "../io.js";
|
|
12
13
|
import { findOnPath, launcherPath } from "../launch.js";
|
|
13
14
|
import { turnoCommand, isGenerated, writeHelperLaunchers, writeLauncher } from "../launchers.js";
|
|
15
|
+
/** `turno upgrade --check --json`. */
|
|
16
|
+
const CHECK_JSON = jsonOutput(["current", "latest", "channel", "method", "updateAvailable", "error", "note"]);
|
|
14
17
|
const USAGE = `Usage:
|
|
15
18
|
turno upgrade [--channel latest|next] [--to <version>] [--dry-run] [--yes]
|
|
16
19
|
install the newest release with the tool that installed turno
|
|
@@ -20,9 +23,16 @@ const USAGE = `Usage:
|
|
|
20
23
|
When agent configs need a new gateway token, --finish offers to run turno mcp sync (in a
|
|
21
24
|
terminal it asks; --yes runs it without asking).
|
|
22
25
|
|
|
23
|
-
turno knows how it was installed (npm, pnpm, yarn, bun, volta, or a git checkout) and
|
|
24
|
-
matching command.
|
|
25
|
-
|
|
26
|
+
turno knows how it was installed (npm, pnpm, yarn, bun, volta, Homebrew, or a git checkout) and
|
|
27
|
+
runs the matching command. A copy that npx, pnpm dlx or bunx runs once has nothing to upgrade:
|
|
28
|
+
the next run of that runner with @latest gets the newest release. Once a day interactive commands look for a new release in the background and
|
|
29
|
+
mention it once; set update_check = false in config.toml or TURNO_NO_UPDATE_CHECK=1 to stop that.
|
|
30
|
+
|
|
31
|
+
Examples:
|
|
32
|
+
$ turno upgrade --check
|
|
33
|
+
$ turno upgrade
|
|
34
|
+
$ turno upgrade --dry-run --to 1.2.3
|
|
35
|
+
$ turno upgrade --finish`;
|
|
26
36
|
function versionFile(env) {
|
|
27
37
|
return join(paths(env).state, "version");
|
|
28
38
|
}
|
|
@@ -87,7 +97,7 @@ export async function finishUpgrade(io, opts = {}) {
|
|
|
87
97
|
const hint = journal.hint();
|
|
88
98
|
if (hint)
|
|
89
99
|
io.out(hint);
|
|
90
|
-
// Configs synced before per-profile gateway tokens
|
|
100
|
+
// Configs synced before per-profile gateway tokens send the master token, which
|
|
91
101
|
// mcpd refuses for MCP sessions: say so here instead of leaving it to the first failed call.
|
|
92
102
|
const tokens = (await import("../../mcpd/health.js")).tokenSyncCheck(env);
|
|
93
103
|
if (tokens) {
|
|
@@ -139,80 +149,107 @@ export const command = {
|
|
|
139
149
|
summary: "update turno to the newest release (or check for one)",
|
|
140
150
|
usage: USAGE,
|
|
141
151
|
flags: ["--check", "--channel", "--to", "--dry-run", "--json", "--finish", "--yes"],
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
152
|
+
json: CHECK_JSON,
|
|
153
|
+
run: (args, io) => runUpgrade(args, io),
|
|
154
|
+
};
|
|
155
|
+
/** `turno upgrade`; `deps.install` stands for how this turno was installed, for tests. */
|
|
156
|
+
export async function runUpgrade(args, io, deps = {}) {
|
|
157
|
+
const p = parseFlags(args, {
|
|
158
|
+
check: { type: "boolean" },
|
|
159
|
+
finish: { type: "boolean" },
|
|
160
|
+
yes: { type: "boolean", short: "y" },
|
|
161
|
+
channel: { type: "string" },
|
|
162
|
+
to: { type: "string" },
|
|
163
|
+
...DRY_RUN,
|
|
164
|
+
...JSON_FLAG,
|
|
165
|
+
}, 0);
|
|
166
|
+
const yes = bool(p, "yes");
|
|
167
|
+
if (bool(p, "finish"))
|
|
168
|
+
return finishUpgrade(io, { sync: yes ? "yes" : "ask" });
|
|
169
|
+
const to = str(p, "to");
|
|
170
|
+
if (to !== undefined && !isSemver(to))
|
|
171
|
+
fail(`--to needs a version like 1.2.3 (got "${to}")`);
|
|
172
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(str(p, "channel") ?? "latest"))
|
|
173
|
+
fail("--channel needs a dist-tag such as latest or next");
|
|
174
|
+
const pkg = packageInfo();
|
|
175
|
+
const install = deps.install ?? detectInstall();
|
|
176
|
+
const channel = str(p, "channel") ?? "latest";
|
|
177
|
+
const off = updateChecksOff(io.env);
|
|
178
|
+
const fromRegistry = install.method !== "source" && install.method !== "unknown";
|
|
179
|
+
if (bool(p, "check")) {
|
|
180
|
+
if (pkg.private || !fromRegistry) {
|
|
181
|
+
const why = pkg.private ? "this copy is not published to a registry" : `installed from ${install.method}`;
|
|
168
182
|
if (bool(p, "json"))
|
|
169
|
-
|
|
170
|
-
else if (s.error)
|
|
171
|
-
io.out(`could not reach the registry: ${s.error}`);
|
|
183
|
+
emit(io, p, CHECK_JSON, { current: pkg.version, latest: null, method: install.method, note: why });
|
|
172
184
|
else
|
|
173
|
-
io.out(
|
|
174
|
-
return
|
|
175
|
-
}
|
|
176
|
-
if (fromRegistry && off === "this copy is not published to a registry")
|
|
177
|
-
fail("this copy is not published to a registry");
|
|
178
|
-
let spec = str(p, "to") ?? channel;
|
|
179
|
-
if (fromRegistry && !str(p, "to")) {
|
|
180
|
-
const s = await fetchLatest(io.env, channel);
|
|
181
|
-
if (s.error)
|
|
182
|
-
fail(`could not reach the registry: ${s.error}`);
|
|
183
|
-
if (s.latest && compareVersions(s.latest, pkg.version) <= 0) {
|
|
184
|
-
io.out(`turno ${pkg.version} is already the newest on ${channel}`);
|
|
185
|
-
return 0;
|
|
186
|
-
}
|
|
187
|
-
spec = s.latest ?? channel;
|
|
185
|
+
io.out(`turno ${pkg.version} (${why}; turno upgrade pulls the source)`);
|
|
186
|
+
return 0;
|
|
188
187
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
188
|
+
const s = await fetchLatest(io.env, channel);
|
|
189
|
+
const newer = s.latest && compareVersions(s.latest, pkg.version) > 0;
|
|
190
|
+
if (bool(p, "json"))
|
|
191
|
+
emit(io, p, CHECK_JSON, {
|
|
192
|
+
current: pkg.version,
|
|
193
|
+
latest: s.latest ?? null,
|
|
194
|
+
channel,
|
|
195
|
+
method: install.method,
|
|
196
|
+
updateAvailable: Boolean(newer),
|
|
197
|
+
error: s.error ?? null,
|
|
198
|
+
});
|
|
199
|
+
else if (s.error)
|
|
200
|
+
io.out(`could not reach the registry: ${s.error}`);
|
|
201
|
+
else
|
|
202
|
+
io.out(newer
|
|
203
|
+
? `turno ${s.latest} is available (you have ${pkg.version}): turno upgrade`
|
|
204
|
+
: `turno ${pkg.version} is the newest on ${channel}`);
|
|
205
|
+
return s.error ? 1 : 0;
|
|
206
|
+
}
|
|
207
|
+
if (isOneOff(install.method)) {
|
|
208
|
+
// A copy in npx's (pnpm dlx's, bunx's) cache: nothing to replace, the runner fetches releases.
|
|
209
|
+
const once = ONE_OFF_RUNNERS[install.method];
|
|
210
|
+
io.out(`turno runs from ${once.runner}'s cache for this run: \`${once.latest}\` runs the newest release.`);
|
|
211
|
+
io.out(`To keep turno, install it: ${once.install}`);
|
|
212
|
+
return 0;
|
|
213
|
+
}
|
|
214
|
+
if (fromRegistry && off === "this copy is not published to a registry")
|
|
215
|
+
fail("this copy is not published to a registry");
|
|
216
|
+
let spec = str(p, "to") ?? channel;
|
|
217
|
+
if (fromRegistry && !str(p, "to")) {
|
|
218
|
+
const s = await fetchLatest(io.env, channel);
|
|
219
|
+
if (s.error)
|
|
220
|
+
fail(`could not reach the registry: ${s.error}`);
|
|
221
|
+
if (s.latest && compareVersions(s.latest, pkg.version) <= 0) {
|
|
222
|
+
io.out(`turno ${pkg.version} is already the newest on ${channel}`);
|
|
223
|
+
return 0;
|
|
204
224
|
}
|
|
225
|
+
spec = s.latest ?? channel;
|
|
226
|
+
}
|
|
227
|
+
// Whatever reaches the package manager is a plain version or a dist-tag, never a URL or range.
|
|
228
|
+
if (!isSemver(spec) && !/^[a-z][a-z0-9-]{0,63}$/.test(spec))
|
|
229
|
+
fail(`refusing to install "${spec}": not a version`);
|
|
230
|
+
const steps = upgradeCommand(install, pkg.name, spec);
|
|
231
|
+
if (!steps)
|
|
232
|
+
return fail(`cannot tell how turno was installed (${install.root}); reinstall it with your package manager`);
|
|
233
|
+
for (const step of steps) {
|
|
234
|
+
io.out(`$ ${step.join(" ")}`);
|
|
205
235
|
if (bool(p, "dry-run"))
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return 0;
|
|
236
|
+
continue;
|
|
237
|
+
const r = spawnSync(step[0], step.slice(1), { stdio: "inherit", env: io.env });
|
|
238
|
+
if (r.status !== 0) {
|
|
239
|
+
io.err(`turno: ${step[0]} failed (exit ${r.status ?? r.signal}); nothing else was changed`);
|
|
240
|
+
return 1;
|
|
212
241
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return
|
|
216
|
-
|
|
217
|
-
|
|
242
|
+
}
|
|
243
|
+
if (bool(p, "dry-run"))
|
|
244
|
+
return 0;
|
|
245
|
+
// The new files are in place: let the new version finish its own upgrade.
|
|
246
|
+
const self = install.method === "source" ? process.argv[1] : findOnPath("turno", io.env);
|
|
247
|
+
if (!self) {
|
|
248
|
+
io.out("upgraded; run `turno upgrade --finish` to rewrite the launchers");
|
|
249
|
+
return 0;
|
|
250
|
+
}
|
|
251
|
+
const finish = ["upgrade", "--finish", ...(yes ? ["--yes"] : [])];
|
|
252
|
+
const r = spawnSync(install.method === "source" ? process.execPath : self, install.method === "source" ? [self, ...finish] : finish, { stdio: "inherit", env: io.env });
|
|
253
|
+
return r.status ?? 1;
|
|
254
|
+
}
|
|
218
255
|
//# sourceMappingURL=upgrade.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { execFile } from "node:child_process";
|
|
2
|
-
import {
|
|
2
|
+
import { statSync } from "node:fs";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { loadConfig } from "../../core/config.js";
|
|
5
5
|
import { exhaustedUntil } from "../../core/exhausted.js";
|
|
@@ -7,6 +7,7 @@ import { isObject, readJsonFile } from "../../core/fsutil.js";
|
|
|
7
7
|
import { paths, profileDir, writePrivateFile } from "../../core/paths.js";
|
|
8
8
|
import { listProfiles } from "../../core/profiles.js";
|
|
9
9
|
import { profileColor, style } from "../style.js";
|
|
10
|
+
import { isRecord, readState } from "../../core/state-file.js";
|
|
10
11
|
/** Why `claude auth status` gave no answer, in a few words for the account column. */
|
|
11
12
|
function authFailure(err, stdout, stderr) {
|
|
12
13
|
if (err?.code === "ENOENT")
|
|
@@ -101,14 +102,10 @@ function authStatusResult(profile, env = process.env) {
|
|
|
101
102
|
export async function authStatus(profile, env = process.env) {
|
|
102
103
|
return (await authStatusResult(profile, env)).status;
|
|
103
104
|
}
|
|
105
|
+
/** The status line's usage snapshot: its windows are read field by field, so the shape check is light. */
|
|
106
|
+
const isSnapshot = (v) => isRecord(v) && (v.rate_limits === undefined || isRecord(v.rate_limits));
|
|
104
107
|
function readSnapshot(file) {
|
|
105
|
-
|
|
106
|
-
const v = JSON.parse(readFileSync(file, "utf8"));
|
|
107
|
-
return v && typeof v === "object" ? v : undefined;
|
|
108
|
-
}
|
|
109
|
-
catch {
|
|
110
|
-
return undefined;
|
|
111
|
-
}
|
|
108
|
+
return readState(file, isSnapshot);
|
|
112
109
|
}
|
|
113
110
|
/** The newer of the snapshot in the state dir and the one the bash tool's status line wrote. */
|
|
114
111
|
export function usageSnapshot(profile, env = process.env) {
|
|
@@ -190,14 +187,18 @@ export function renderUsage(profiles, accounts, io, opts = {}) {
|
|
|
190
187
|
if (reset && reset < now)
|
|
191
188
|
pct = 0;
|
|
192
189
|
const when = reset ? resetText(reset, now) : "";
|
|
193
|
-
out.push(s
|
|
190
|
+
out.push(s
|
|
191
|
+
.wrap(` ${s.muted(label.padEnd(7))} ${s.bar(pct, BAR_CELLS)} `, pct >= 100 ? s.err(`used up, ${when}`) : s.muted(when))
|
|
192
|
+
.trimEnd());
|
|
194
193
|
}
|
|
195
194
|
const exhausted = exhaustedUntil(p, io.env);
|
|
196
195
|
if (exhausted !== undefined && exhausted > now) {
|
|
197
196
|
out.push(s.note("err", `${s.err(`exhausted until ${shortTime(exhausted)}`)}${s.muted(": its projects open with the fallback, if one is set")}`));
|
|
198
197
|
}
|
|
199
198
|
if (!hasLimits) {
|
|
200
|
-
const why = plan === "team"
|
|
199
|
+
const why = plan === "team"
|
|
200
|
+
? "the Team plan does not report these limits"
|
|
201
|
+
: "shows up once a session of this account gets a response";
|
|
201
202
|
out.push(s.muted(` no usage data yet: ${why}`));
|
|
202
203
|
}
|
|
203
204
|
if (hasLimits && typeof data.updated_at === "number")
|
|
@@ -1,25 +1,37 @@
|
|
|
1
1
|
import { tildify } from "../../core/paths.js";
|
|
2
2
|
import { availableUpdate } from "../../core/update.js";
|
|
3
|
-
import { detectInstall, packageInfo } from "../../core/version.js";
|
|
4
|
-
import { JSON_FLAG, bool, flagsOf, parseFlags
|
|
3
|
+
import { ONE_OFF_RUNNERS, detectInstall, isOneOff, packageInfo } from "../../core/version.js";
|
|
4
|
+
import { JSON_FLAG, bool, flagsOf, parseFlags } from "../args.js";
|
|
5
|
+
import { emit, jsonOutput } from "../output.js";
|
|
6
|
+
const JSON_OUT = jsonOutput(["name", "version", "node", "method", "path", "latest"]);
|
|
5
7
|
export const command = {
|
|
6
8
|
summary: "the turno version, how it was installed, and whether a newer one is known",
|
|
7
|
-
usage: "Usage: turno version [--json]\n\nturno --version prints only the number
|
|
9
|
+
usage: "Usage: turno version [--json]\n\nturno --version prints only the number.\n\nExamples:\n $ turno version\n $ turno version --json",
|
|
8
10
|
flags: flagsOf(JSON_FLAG),
|
|
11
|
+
json: JSON_OUT,
|
|
9
12
|
async run(args, io) {
|
|
10
13
|
const p = parseFlags(args, JSON_FLAG, 0);
|
|
11
14
|
const pkg = packageInfo();
|
|
12
15
|
const install = detectInstall();
|
|
13
16
|
const latest = availableUpdate(io.env);
|
|
14
|
-
// npx
|
|
15
|
-
const
|
|
16
|
-
const data = {
|
|
17
|
+
// npx, pnpm dlx and bunx run a temporary copy from their cache: upgrade and launchers must not rely on it.
|
|
18
|
+
const once = isOneOff(install.method) ? ONE_OFF_RUNNERS[install.method] : undefined;
|
|
19
|
+
const data = {
|
|
20
|
+
name: pkg.name,
|
|
21
|
+
version: pkg.version,
|
|
22
|
+
node: process.versions.node,
|
|
23
|
+
method: install.method,
|
|
24
|
+
path: tildify(install.root, io.env),
|
|
25
|
+
latest: latest ?? null,
|
|
26
|
+
};
|
|
17
27
|
if (bool(p, "json")) {
|
|
18
|
-
|
|
28
|
+
emit(io, p, JSON_OUT, data);
|
|
19
29
|
return 0;
|
|
20
30
|
}
|
|
21
31
|
io.out(`turno ${pkg.version}`);
|
|
22
|
-
io.out(
|
|
32
|
+
io.out(once
|
|
33
|
+
? ` a temporary copy in ${once.runner}'s cache (${data.path}); install it with: ${once.install}`
|
|
34
|
+
: ` installed with ${install.method} at ${data.path}`);
|
|
23
35
|
io.out(` node ${data.node}`);
|
|
24
36
|
if (latest)
|
|
25
37
|
io.out(` ${latest} is available: turno upgrade`);
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { flagsOf } from "../args.js";
|
|
2
|
+
import { WHICH_JSON, WHICH_SPEC, whichCommand } from "./profile.js";
|
|
2
3
|
/** The 0.1 `turno which`; `which` is now an alias of `turno profile which`, which this runs. */
|
|
3
4
|
export const command = {
|
|
4
5
|
summary: "which account auto would use in a folder, and why",
|
|
5
|
-
usage: "Usage: turno profile which [dir] [--json]\n\nExplains the profile resolution for a folder (default: the current one), for each agent.",
|
|
6
|
+
usage: "Usage: turno profile which [dir] [--json] [--check]\n\nExplains the profile resolution for a folder (default: the current one), for each agent.",
|
|
6
7
|
hidden: true,
|
|
7
8
|
args: ["dir"],
|
|
8
|
-
flags:
|
|
9
|
+
flags: flagsOf(WHICH_SPEC),
|
|
10
|
+
json: WHICH_JSON,
|
|
9
11
|
run: whichCommand,
|
|
10
12
|
};
|
|
11
13
|
//# sourceMappingURL=which.js.map
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What `turno config path --all` and `turno doctor --report` show: every path turno uses, and a
|
|
3
|
+
* Markdown block for an issue with versions, agents, paths, mcpd and the doctor findings. Nothing
|
|
4
|
+
* here prints a token, a secret value or a variable's value: paths are shown with `~`, and the
|
|
5
|
+
* doctor findings already name secrets only by key.
|
|
6
|
+
*/
|
|
7
|
+
import { execFile } from "node:child_process";
|
|
8
|
+
import { existsSync } from "node:fs";
|
|
9
|
+
import { arch, release } from "node:os";
|
|
10
|
+
import { join } from "node:path";
|
|
11
|
+
import { AGENT_IDS, adapter, agentHub, agentProfileDir } from "../agents/index.js";
|
|
12
|
+
import { loadConfig } from "../core/config.js";
|
|
13
|
+
import { paths, tildify } from "../core/paths.js";
|
|
14
|
+
import { agentOf, listProfiles } from "../core/profiles.js";
|
|
15
|
+
import { detectInstall, packageInfo } from "../core/version.js";
|
|
16
|
+
import { plistPath } from "../mcpd/launchd.js";
|
|
17
|
+
import { daemonFiles } from "../mcpd/state.js";
|
|
18
|
+
import { unitPath } from "../mcpd/systemd.js";
|
|
19
|
+
import { userFontDir } from "../ui/fonts.js";
|
|
20
|
+
import { compileCacheDir } from "./compile-cache.js";
|
|
21
|
+
import { findOnPath, launcherName } from "./launchers.js";
|
|
22
|
+
function configOrNone(env) {
|
|
23
|
+
try {
|
|
24
|
+
return loadConfig(env);
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Every path turno uses on this machine, in a stable order: its own config, state and data, the
|
|
32
|
+
* launchers and the service file, each agent's hub, and each profile's folder and launcher.
|
|
33
|
+
*/
|
|
34
|
+
export function allPaths(env, platform = process.platform) {
|
|
35
|
+
const p = paths(env);
|
|
36
|
+
const d = daemonFiles(env);
|
|
37
|
+
const out = [
|
|
38
|
+
{ name: "config dir", path: p.config, about: "turno's configuration (TURNO_CONFIG_DIR)" },
|
|
39
|
+
{ name: "config", path: p.configFile, about: "profiles, folder rules, defaults" },
|
|
40
|
+
{ name: "mcp", path: p.mcpFile, about: "MCP servers behind mcpd" },
|
|
41
|
+
{ name: "accounts", path: p.accountsFile, about: "service accounts (turno identity)" },
|
|
42
|
+
{ name: "state dir", path: p.state, about: "state, logs and backups (TURNO_STATE_DIR)" },
|
|
43
|
+
{ name: "backups", path: p.backupsDir, about: "the journal turno undo reads" },
|
|
44
|
+
{ name: "logs", path: p.logsDir, about: "mcpd.log and calls.jsonl" },
|
|
45
|
+
{ name: "mcpd log", path: d.log, about: "what mcpd did" },
|
|
46
|
+
{ name: "call log", path: d.calls, about: "tool calls mcpd relayed (turno mcp log)" },
|
|
47
|
+
{ name: "mcpd token", path: p.mcpdToken, about: "the gateway's master token (mode 600)" },
|
|
48
|
+
{ name: "mcpd port", path: p.mcpdPort, about: "the port mcpd listens on" },
|
|
49
|
+
{ name: "mcpd lock", path: d.lock, about: "the running mcpd's pid" },
|
|
50
|
+
{
|
|
51
|
+
name: "profile tokens",
|
|
52
|
+
path: join(p.state, "mcpd-tokens"),
|
|
53
|
+
about: "each profile's gateway token, for launchers",
|
|
54
|
+
},
|
|
55
|
+
{ name: "managed entries", path: p.mcpdManaged, about: "agent config entries turno mcp sync wrote" },
|
|
56
|
+
{ name: "run records", path: p.runDir, about: "which profile each launcher started" },
|
|
57
|
+
{ name: "usage", path: p.usageDir, about: "usage snapshots for the status line" },
|
|
58
|
+
{ name: "exhausted", path: p.exhaustedDir, about: "exhausted marks (turno limit)" },
|
|
59
|
+
{ name: "audit log", path: p.auditLog, about: "accounts bridge audit log" },
|
|
60
|
+
{ name: "data dir", path: p.data, about: "installed servers and browser data (TURNO_DATA_DIR)" },
|
|
61
|
+
{ name: "servers", path: p.serversDir, about: "packages turno mcp install installed" },
|
|
62
|
+
{ name: "descriptions", path: p.mcpdCacheDir, about: "cached tool lists of each server" },
|
|
63
|
+
{ name: "browser", path: p.browserDir, about: "browser identities" },
|
|
64
|
+
{
|
|
65
|
+
name: "chrome profiles",
|
|
66
|
+
path: configOrNone(env)?.open.chromeDir ?? p.chromeProfilesDir,
|
|
67
|
+
about: "Chrome profiles of turno open",
|
|
68
|
+
},
|
|
69
|
+
{ name: "compile cache", path: compileCacheDir(env), about: "Node's compiled code of turno" },
|
|
70
|
+
{ name: "launchers", path: p.bin, about: "claude-<p>, codex-<p>, turno-auto, turno-open (TURNO_BIN)" },
|
|
71
|
+
];
|
|
72
|
+
if (platform === "darwin")
|
|
73
|
+
out.push({ name: "service", path: plistPath(env), about: "the LaunchAgent that keeps mcpd running" });
|
|
74
|
+
if (platform === "linux")
|
|
75
|
+
out.push({ name: "service", path: unitPath(env), about: "the systemd user unit that keeps mcpd running" });
|
|
76
|
+
const fonts = userFontDir(env, platform);
|
|
77
|
+
if (fonts)
|
|
78
|
+
out.push({ name: "fonts", path: fonts, about: "the status line font (turno ui install)" });
|
|
79
|
+
out.push({ name: "claude config", path: p.hubConfig, about: "plain claude's .claude.json (TURNO_HUB_CONFIG)" });
|
|
80
|
+
for (const id of AGENT_IDS)
|
|
81
|
+
out.push({
|
|
82
|
+
name: `${id} hub`,
|
|
83
|
+
path: agentHub(id, env),
|
|
84
|
+
about: `${adapter(id).label}'s own folder, shared by its profiles`,
|
|
85
|
+
});
|
|
86
|
+
const config = configOrNone(env);
|
|
87
|
+
if (config) {
|
|
88
|
+
for (const name of listProfiles(config, env)) {
|
|
89
|
+
const agent = agentOf(name, config);
|
|
90
|
+
out.push({
|
|
91
|
+
name: `profile ${name}`,
|
|
92
|
+
path: agentProfileDir(name, agent, env),
|
|
93
|
+
about: `${adapter(agent).label} profile folder`,
|
|
94
|
+
});
|
|
95
|
+
out.push({ name: `launcher ${name}`, path: join(p.bin, launcherName(name, agent)), about: `opens ${name}` });
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (existsSync(p.legacyConfig))
|
|
99
|
+
out.push({
|
|
100
|
+
name: "legacy config",
|
|
101
|
+
path: p.legacyConfig,
|
|
102
|
+
about: "the bash claudio config (turno migrate reads it)",
|
|
103
|
+
});
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
/** `<command> --version`, first line, or undefined when it does not answer within 3 s. */
|
|
107
|
+
function versionOf(file, env) {
|
|
108
|
+
return new Promise((resolve) => {
|
|
109
|
+
execFile(file, ["--version"], { env, timeout: 3000, encoding: "utf8" }, (err, stdout) => {
|
|
110
|
+
const line = String(stdout ?? "")
|
|
111
|
+
.trim()
|
|
112
|
+
.split("\n")[0]
|
|
113
|
+
?.trim();
|
|
114
|
+
resolve(err || !line ? undefined : line.slice(0, 80));
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
/** Markdown text in a table cell: no pipes or line breaks. */
|
|
119
|
+
const cell = (s) => s.replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ");
|
|
120
|
+
/**
|
|
121
|
+
* The `turno doctor --report` block: Markdown to paste in an issue. Profile and server names
|
|
122
|
+
* appear (they say which check is which); tokens, secret values and variable values never do.
|
|
123
|
+
*/
|
|
124
|
+
export async function reportMarkdown(env, input, platform = process.platform) {
|
|
125
|
+
const t = (s) => tildify(s, env);
|
|
126
|
+
const pkg = packageInfo();
|
|
127
|
+
const install = detectInstall();
|
|
128
|
+
const config = configOrNone(env);
|
|
129
|
+
const profiles = config ? listProfiles(config, env) : [];
|
|
130
|
+
const byAgent = new Map();
|
|
131
|
+
for (const n of profiles)
|
|
132
|
+
byAgent.set(agentOf(n, config), (byAgent.get(agentOf(n, config)) ?? 0) + 1);
|
|
133
|
+
const agents = await Promise.all(AGENT_IDS.map(async (id) => {
|
|
134
|
+
const a = adapter(id);
|
|
135
|
+
const at = findOnPath(a.command, env);
|
|
136
|
+
return { id, label: a.label, command: a.command, at, version: at ? await versionOf(at, env) : undefined };
|
|
137
|
+
}));
|
|
138
|
+
const shell = env.SHELL ? env.SHELL.split("/").pop() : undefined;
|
|
139
|
+
const terminal = env.TERM_PROGRAM
|
|
140
|
+
? `${env.TERM_PROGRAM}${env.TERM_PROGRAM_VERSION ? ` ${env.TERM_PROGRAM_VERSION}` : ""}`
|
|
141
|
+
: env.TERM;
|
|
142
|
+
const out = [
|
|
143
|
+
`### turno doctor${input.security ? " --security" : ""} --report`,
|
|
144
|
+
"",
|
|
145
|
+
"| | |",
|
|
146
|
+
"|---|---|",
|
|
147
|
+
`| turno | ${pkg.version} (${install.method}) |`,
|
|
148
|
+
`| node | ${process.versions.node} |`,
|
|
149
|
+
`| os | ${platform} ${release()} ${arch()} |`,
|
|
150
|
+
...(shell ? [`| shell | ${cell(shell)} |`] : []),
|
|
151
|
+
...(terminal ? [`| terminal | ${cell(terminal)} |`] : []),
|
|
152
|
+
`| config.toml | ${existsSync(paths(env).configFile) ? (config ? "parses" : "does not parse") : "none"} |`,
|
|
153
|
+
`| profiles | ${profiles.length ? [...byAgent].map(([id, n]) => `${n} ${id}`).join(", ") : "none"} |`,
|
|
154
|
+
"",
|
|
155
|
+
"**Agents**",
|
|
156
|
+
"",
|
|
157
|
+
"| agent | command | version | profiles |",
|
|
158
|
+
"|---|---|---|---|",
|
|
159
|
+
...agents.map((a) => `| ${a.label} | ${a.at ? cell(t(a.at)) : `${a.command} (not found)`} | ${a.version ? cell(a.version) : "-"} | ${byAgent.get(a.id) ?? 0} |`),
|
|
160
|
+
"",
|
|
161
|
+
"**mcpd**",
|
|
162
|
+
"",
|
|
163
|
+
];
|
|
164
|
+
const s = input.status;
|
|
165
|
+
if (input.mcpd.running && s) {
|
|
166
|
+
const instances = Array.isArray(s.instances) ? s.instances.length : 0;
|
|
167
|
+
const parts = [
|
|
168
|
+
`running on port ${input.mcpd.port}`,
|
|
169
|
+
typeof s.version === "string" ? `version ${s.version}` : "",
|
|
170
|
+
typeof s.startedAt === "string" ? `since ${s.startedAt}` : "",
|
|
171
|
+
`${typeof s.sessions === "number" ? s.sessions : 0} sessions`,
|
|
172
|
+
`${instances} server processes`,
|
|
173
|
+
].filter(Boolean);
|
|
174
|
+
out.push(`- ${parts.join(", ")}`);
|
|
175
|
+
}
|
|
176
|
+
else
|
|
177
|
+
out.push(`- ${cell(input.mcpd.text)}`);
|
|
178
|
+
const c = input.counts;
|
|
179
|
+
out.push("", "**Doctor**", "", `- ${c.ok} ok, ${c.warn} warnings, ${c.fail} failures, ${c.skip} skipped`, ...input.checks
|
|
180
|
+
.filter((x) => x.status === "warn" || x.status === "fail")
|
|
181
|
+
.map((x) => `- ${x.status}: ${cell(x.text)}${x.fix ? ` (fix: \`${cell(x.fix)}\`)` : ""}`), "", "<details><summary>Paths</summary>", "", "| name | path | exists |", "|---|---|---|", ...allPaths(env, platform).map((e) => `| ${cell(e.name)} | ${cell(t(e.path))} | ${existsSync(e.path) ? "yes" : "no"} |`), "", "</details>");
|
|
182
|
+
return out;
|
|
183
|
+
}
|
|
184
|
+
//# sourceMappingURL=diagnostics.js.map
|
package/dist/cli/exit.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exit codes turno promises, for scripts, hooks and status lines. Keep this file
|
|
3
|
+
* free of imports: io.ts and every command load it.
|
|
4
|
+
*/
|
|
5
|
+
export const Exit = {
|
|
6
|
+
/** Done. */
|
|
7
|
+
ok: 0,
|
|
8
|
+
/** It did not work: the message says why. */
|
|
9
|
+
failure: 1,
|
|
10
|
+
/** The command line was wrong (unknown command or flag, missing argument, a question nobody can answer). */
|
|
11
|
+
usage: 2,
|
|
12
|
+
/** No profile for the folder: no rule and no default, or a rule naming a profile that does not exist. */
|
|
13
|
+
noProfile: 3,
|
|
14
|
+
/** The profile exists but its account is not signed in. */
|
|
15
|
+
notSignedIn: 4,
|
|
16
|
+
/** The gateway (mcpd) does not answer. */
|
|
17
|
+
gatewayDown: 5,
|
|
18
|
+
/** The agent's own command is not installed (the shell's "command not found"). */
|
|
19
|
+
notInstalled: 127,
|
|
20
|
+
/** Cancelled by the person (Ctrl-C or Esc in a picker), as shells report SIGINT. */
|
|
21
|
+
cancelled: 130,
|
|
22
|
+
};
|
|
23
|
+
/** The stable name of each code, as `--json` errors carry it (`"code": "no_profile"`). */
|
|
24
|
+
const NAMES = {
|
|
25
|
+
0: "ok",
|
|
26
|
+
1: "failure",
|
|
27
|
+
2: "usage",
|
|
28
|
+
3: "no_profile",
|
|
29
|
+
4: "not_signed_in",
|
|
30
|
+
5: "gateway_down",
|
|
31
|
+
127: "not_installed",
|
|
32
|
+
130: "cancelled",
|
|
33
|
+
};
|
|
34
|
+
/** The name of an exit code; "failure" for a code outside the contract. */
|
|
35
|
+
export function exitName(code) {
|
|
36
|
+
return NAMES[code] ?? "failure";
|
|
37
|
+
}
|
|
38
|
+
/** One row per code for `turno help exit-codes`: code, name, meaning. */
|
|
39
|
+
export const EXIT_ROWS = [
|
|
40
|
+
[Exit.ok, "ok", "done"],
|
|
41
|
+
[Exit.failure, "failure", "it did not work; the message on stderr says why"],
|
|
42
|
+
[
|
|
43
|
+
Exit.usage,
|
|
44
|
+
"usage",
|
|
45
|
+
"the command line was wrong: an unknown command or flag, a missing argument, or a question nobody can answer (no terminal, --no-input)",
|
|
46
|
+
],
|
|
47
|
+
[
|
|
48
|
+
Exit.noProfile,
|
|
49
|
+
"no_profile",
|
|
50
|
+
"no profile for this folder: no rule and no default, or a rule naming a profile that does not exist (turno auto, turno profile which --check)",
|
|
51
|
+
],
|
|
52
|
+
[
|
|
53
|
+
Exit.notSignedIn,
|
|
54
|
+
"not_signed_in",
|
|
55
|
+
"the folder's profile exists but its account is not signed in (turno profile which --check)",
|
|
56
|
+
],
|
|
57
|
+
[
|
|
58
|
+
Exit.gatewayDown,
|
|
59
|
+
"gateway_down",
|
|
60
|
+
"the gateway (mcpd) does not answer (turno mcp daemon status, turno mcp top, turno mcp savings)",
|
|
61
|
+
],
|
|
62
|
+
[Exit.notInstalled, "not_installed", "the agent's own command is not installed (turno auto with no profile to open)"],
|
|
63
|
+
[Exit.cancelled, "cancelled", "cancelled by you: Ctrl-C, or Esc in a profile list"],
|
|
64
|
+
];
|
|
65
|
+
//# sourceMappingURL=exit.js.map
|