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
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { tildify } from "../../core/paths.js";
|
|
5
|
-
import { resolveProfile } from "../../core/resolve.js";
|
|
6
|
-
import { fail } from "../io.js";
|
|
1
|
+
import { flagsOf } from "../args.js";
|
|
2
|
+
import { WHICH_JSON, WHICH_SPEC, whichCommand } from "./profile.js";
|
|
3
|
+
/** The 0.1 `turno which`; `which` is now an alias of `turno profile which`, which this runs. */
|
|
7
4
|
export const command = {
|
|
8
5
|
summary: "which account auto would use in a folder, and why",
|
|
9
|
-
usage: "Usage: turno which [dir]\n\nExplains the profile resolution for a folder (default: the current one).",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
isDir = false;
|
|
18
|
-
}
|
|
19
|
-
if (!isDir)
|
|
20
|
-
fail(`no such folder: ${args[0] ?? dir}`);
|
|
21
|
-
const r = resolveProfile(dir, loadConfig(io.env), io.env);
|
|
22
|
-
io.out(tildify(dir, io.env));
|
|
23
|
-
io.out(` assigned: ${r.assigned || "none"} (${r.reason})`);
|
|
24
|
-
io.out(r.note ? ` using now: ${r.chosen} (${r.assigned} ${r.note})` : ` using now: ${r.chosen || "plain claude"}`);
|
|
25
|
-
return 0;
|
|
26
|
-
},
|
|
6
|
+
usage: "Usage: turno profile which [dir] [--json] [--check]\n\nExplains the profile resolution for a folder (default: the current one), for each agent.",
|
|
7
|
+
hidden: true,
|
|
8
|
+
args: ["dir"],
|
|
9
|
+
flags: flagsOf(WHICH_SPEC),
|
|
10
|
+
json: WHICH_JSON,
|
|
11
|
+
run: whichCommand,
|
|
27
12
|
};
|
|
28
13
|
//# sourceMappingURL=which.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import module from "node:module";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
/**
|
|
5
|
+
* Where Node keeps turno's compiled code between runs: the user cache dir
|
|
6
|
+
* ($XDG_CACHE_HOME/turno, else ~/.cache/turno), never the shared temp dir Node uses by default.
|
|
7
|
+
*/
|
|
8
|
+
export function compileCacheDir(env) {
|
|
9
|
+
return join(env.XDG_CACHE_HOME || join(env.HOME || homedir(), ".cache"), "turno", "node-compile-cache");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Turn on Node's on-disk compile cache (module.enableCompileCache, Node 22.1+), so later runs
|
|
13
|
+
* skip compiling the modules they import. Only the CLI entry calls it, before it imports any
|
|
14
|
+
* command. NODE_COMPILE_CACHE picks another folder and NODE_DISABLE_COMPILE_CACHE turns it off,
|
|
15
|
+
* as for any Node program. A Node without the API, or a cache that cannot be written, only
|
|
16
|
+
* makes turno a little slower. `turno demo` promises to leave HOME as it found it, so it runs
|
|
17
|
+
* without the cache (the turno commands inside the demo cache in the demo's own HOME).
|
|
18
|
+
*/
|
|
19
|
+
export function enableCompileCache(argv, env = process.env) {
|
|
20
|
+
if (argv[0] === "demo")
|
|
21
|
+
return;
|
|
22
|
+
const enable = module.enableCompileCache;
|
|
23
|
+
if (typeof enable !== "function")
|
|
24
|
+
return;
|
|
25
|
+
try {
|
|
26
|
+
enable(env.NODE_COMPILE_CACHE ? undefined : compileCacheDir(env));
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* never fail a command over the cache */
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=compile-cache.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
|
package/dist/cli/group.js
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
|
-
import { fail } from "./io.js";
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { closest, columns, examplesBlock, fail } from "./io.js";
|
|
2
|
+
import { answerFields } from "./output.js";
|
|
3
|
+
/** Usage text of a group: one line per visible subcommand, then an optional footer and examples. */
|
|
4
|
+
function groupUsage(name, subs, footer, examples = []) {
|
|
4
5
|
const rows = Object.entries(subs)
|
|
5
6
|
.filter(([, s]) => !s.hidden)
|
|
6
7
|
.map(([n, s]) => [`turno ${name} ${n}${s.synopsis ? ` ${s.synopsis}` : ""}`, s.summary]);
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
return `Usage:\n${columns(rows, 2, 36)}${footer ? `\n\n${footer}` : ""}${examples.length ? `\n\n${examplesBlock(examples)}` : ""}`;
|
|
9
|
+
}
|
|
10
|
+
/** The group's examples that run `turno <name> <sub>`, for that subcommand's help. */
|
|
11
|
+
function subExamples(name, sub, examples) {
|
|
12
|
+
const head = `turno ${name} ${sub}`;
|
|
13
|
+
return examples.filter((e) => e === head || e.startsWith(`${head} `));
|
|
10
14
|
}
|
|
11
15
|
/**
|
|
12
16
|
* A command made of subcommands: `turno <name> <sub> [args]`. `fallback` runs when no
|
|
13
|
-
* subcommand is given (usually `list` or `show`). `--help` after a subcommand prints
|
|
17
|
+
* subcommand is given (usually `list` or `show`). `--help` after a subcommand prints its usage,
|
|
18
|
+
* with the group's examples for it.
|
|
14
19
|
*/
|
|
15
20
|
export function group(name, summary, subs, opts = {}) {
|
|
16
|
-
const
|
|
21
|
+
const examples = opts.examples ?? [];
|
|
22
|
+
const usage = groupUsage(name, subs, opts.footer, examples);
|
|
17
23
|
const subcommands = Object.fromEntries(Object.entries(subs)
|
|
18
24
|
.filter(([, s]) => !s.hidden)
|
|
19
25
|
.map(([n, s]) => [n, { ...(s.args ? { args: s.args } : {}), ...(s.flags ? { flags: s.flags } : {}) }]));
|
|
@@ -37,12 +43,18 @@ export function group(name, summary, subs, opts = {}) {
|
|
|
37
43
|
return 0;
|
|
38
44
|
}
|
|
39
45
|
const s = subs[sub];
|
|
40
|
-
if (!s)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
46
|
+
if (!s) {
|
|
47
|
+
const near = closest(sub, Object.keys(subs).filter((n) => !subs[n].hidden));
|
|
48
|
+
return fail(near
|
|
49
|
+
? `unknown ${name} command '${sub}'. Did you mean 'turno ${name} ${near}'?`
|
|
50
|
+
: `unknown ${name} command '${sub}'\n\n${usage}`);
|
|
51
|
+
}
|
|
52
|
+
if (!s.ownHelp && (rest.includes("--help") || rest.includes("-h"))) {
|
|
53
|
+
io.out(groupUsage(name, { [sub]: s }, s.details, subExamples(name, sub, examples)));
|
|
44
54
|
return 0;
|
|
45
55
|
}
|
|
56
|
+
if (answerFields(rest, s.json, io))
|
|
57
|
+
return 0;
|
|
46
58
|
return s.run(rest, io);
|
|
47
59
|
},
|
|
48
60
|
};
|
package/dist/cli/help.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/** The main `turno help` screen: drawn from static rows, so it loads nothing but the style. */
|
|
2
|
+
import { wrap } from "./io.js";
|
|
3
|
+
import { HELP_TOPICS } from "./registry.js";
|
|
4
|
+
import { padEnd, style } from "./style.js";
|
|
5
|
+
const EXAMPLES = [
|
|
6
|
+
["turno init", "find your agents, accounts and MCP servers, and set them up"],
|
|
7
|
+
["turno", "this folder, your accounts and their usage, and what to do next"],
|
|
8
|
+
["turno work", "open the work profile with its agent"],
|
|
9
|
+
["turno profile assign . work", "make this folder and everything under it use work"],
|
|
10
|
+
["turno mcp sync", "point every profile at the gateway"],
|
|
11
|
+
];
|
|
12
|
+
/** Rows of `left summary`, with summaries wrapped under their column within the width. */
|
|
13
|
+
function rows(left, right, leftWidth, width, paintLeft, paintRight) {
|
|
14
|
+
const out = [];
|
|
15
|
+
const col = 2 + leftWidth + 2;
|
|
16
|
+
for (const [i, l] of left.entries()) {
|
|
17
|
+
const body = wrap(right[i] ?? "", Math.max(24, width - col));
|
|
18
|
+
if (l.length > leftWidth) {
|
|
19
|
+
out.push(` ${paintLeft(l)}`);
|
|
20
|
+
for (const b of body)
|
|
21
|
+
out.push(`${" ".repeat(col)}${paintRight(b)}`);
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
out.push(` ${padEnd(paintLeft(l), leftWidth)} ${paintRight(body[0])}`);
|
|
25
|
+
for (const b of body.slice(1))
|
|
26
|
+
out.push(`${" ".repeat(col)}${paintRight(b)}`);
|
|
27
|
+
}
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
export function renderHelp(io, sections) {
|
|
31
|
+
const s = style(io);
|
|
32
|
+
// Help reads best at a modest width even on a wide terminal.
|
|
33
|
+
const width = Math.min(s.width, 100);
|
|
34
|
+
const out = [];
|
|
35
|
+
const tagline = "one MCP gateway and per-folder accounts for Claude Code, Codex, Copilot CLI and Cursor CLI.";
|
|
36
|
+
const first = wrap(`turno: ${tagline}`, width);
|
|
37
|
+
out.push(s.color ? `${s.bold(s.accent("turno"))}${s.bold(first[0].slice("turno".length))}` : first[0]);
|
|
38
|
+
for (const l of first.slice(1))
|
|
39
|
+
out.push(s.bold(l));
|
|
40
|
+
out.push("");
|
|
41
|
+
out.push(`${s.lead("next", "Start here:")} ${s.bold(s.accent("turno init"))}, or ${s.accent("turno demo")} to try turno in a throwaway HOME.`);
|
|
42
|
+
const usage = ["turno <command> [flags]", "turno <profile> [args...]"];
|
|
43
|
+
out.push("", s.header("Usage"));
|
|
44
|
+
out.push(...rows(usage, [
|
|
45
|
+
"a command below; turno <command> --help shows its flags",
|
|
46
|
+
"open that profile with its agent; the arguments after it go to the agent",
|
|
47
|
+
], Math.max(...usage.map((u) => u.length)), width, (l) => `${s.muted("turno")}${l.slice("turno".length)}`, (r) => r));
|
|
48
|
+
const w = Math.max(...sections.flatMap((x) => x.rows.map(([n]) => n.length)));
|
|
49
|
+
for (const sec of sections) {
|
|
50
|
+
out.push("", s.header(sec.title));
|
|
51
|
+
out.push(...rows(sec.rows.map(([n]) => n), sec.rows.map(([, sum]) => sum), w, width, (l) => s.bold(s.accent(l)), (r) => r));
|
|
52
|
+
}
|
|
53
|
+
const ew = Math.max(...EXAMPLES.map(([c]) => c.length)) + 2;
|
|
54
|
+
out.push("", s.header("Examples"));
|
|
55
|
+
out.push(...rows(EXAMPLES.map(([c]) => `$ ${c}`), EXAMPLES.map(([, why]) => why), ew, width, (l) => `${s.muted("$")}${l.slice(1)}`, (r) => s.muted(r)));
|
|
56
|
+
out.push("", `Run ${s.bold("turno <command> --help")}, or ${s.bold("turno help <command>")}, for details.`);
|
|
57
|
+
out.push(`Topics: ${HELP_TOPICS.map((t) => s.bold(`turno help ${t}`)).join(", ")}.`);
|
|
58
|
+
out.push(s.muted("Scripts and agents: --no-input or TURNO_NO_INPUT=1 never asks (exit 2 instead)."));
|
|
59
|
+
out.push(s.muted("Colors: --color auto|always|never or TURNO_COLOR, then NO_COLOR and FORCE_COLOR."));
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=help.js.map
|