turno-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +293 -0
- package/README.md +143 -75
- package/dist/accounts/audit.js +137 -7
- package/dist/accounts/builtin.js +68 -21
- package/dist/accounts/delegate.js +176 -35
- package/dist/accounts/policy.js +77 -0
- package/dist/accounts/registry.js +37 -21
- package/dist/agents/adapter.js +7 -0
- package/dist/agents/claude.js +195 -0
- package/dist/agents/codex.js +98 -0
- package/dist/agents/copilot.js +39 -0
- package/dist/agents/cursor.js +41 -0
- package/dist/agents/index.js +26 -86
- package/dist/agents/snippets.js +7 -4
- package/dist/cli/args.js +19 -4
- package/dist/cli/commands/accounts.js +96 -51
- package/dist/cli/commands/auto.js +82 -32
- package/dist/cli/commands/browser.js +216 -135
- package/dist/cli/commands/complete.js +2 -1
- package/dist/cli/commands/completion.js +4 -2
- package/dist/cli/commands/config.js +103 -18
- package/dist/cli/commands/demo.js +292 -0
- package/dist/cli/commands/doctor.js +387 -119
- package/dist/cli/commands/handoff.js +33 -22
- package/dist/cli/commands/identity.js +101 -50
- package/dist/cli/commands/init.js +616 -0
- package/dist/cli/commands/limit.js +25 -13
- package/dist/cli/commands/mcp-oauth.js +194 -0
- package/dist/cli/commands/mcp-observe.js +434 -0
- package/dist/cli/commands/mcp.js +653 -185
- package/dist/cli/commands/mcpd.js +323 -75
- package/dist/cli/commands/migrate.js +6 -4
- package/dist/cli/commands/open.js +92 -27
- package/dist/cli/commands/profile.js +205 -69
- package/dist/cli/commands/resolve.js +6 -2
- package/dist/cli/commands/run.js +15 -5
- package/dist/cli/commands/secret.js +61 -42
- package/dist/cli/commands/session.js +2 -2
- package/dist/cli/commands/sessions.js +42 -12
- package/dist/cli/commands/setup.js +136 -158
- package/dist/cli/commands/status.js +172 -41
- package/dist/cli/commands/statusline.js +305 -113
- package/dist/cli/commands/ui.js +64 -66
- package/dist/cli/commands/undo.js +161 -18
- package/dist/cli/commands/uninstall.js +462 -0
- package/dist/cli/commands/upgrade.js +75 -19
- package/dist/cli/commands/usage.js +117 -44
- package/dist/cli/commands/version.js +7 -5
- package/dist/cli/commands/which.js +7 -24
- package/dist/cli/compile-cache.js +32 -0
- package/dist/cli/group.js +10 -10
- package/dist/cli/help.js +57 -0
- package/dist/cli/highlight.js +236 -0
- package/dist/cli/io.js +170 -1
- package/dist/cli/launch.js +21 -37
- package/dist/cli/launchers.js +145 -94
- package/dist/cli/main.js +163 -27
- package/dist/cli/picker.js +447 -0
- package/dist/cli/registry.js +42 -5
- package/dist/cli/security.js +539 -0
- package/dist/cli/style.js +281 -0
- package/dist/core/config.js +145 -23
- package/dist/core/exhausted.js +6 -8
- package/dist/core/fsutil.js +47 -0
- package/dist/core/journal.js +281 -11
- package/dist/core/manifest.js +126 -6
- package/dist/core/paths.js +114 -7
- package/dist/core/profiles.js +139 -9
- package/dist/core/resolve.js +129 -23
- package/dist/core/secrets.js +215 -20
- package/dist/core/sessions.js +13 -20
- package/dist/core/update.js +18 -8
- package/dist/core/version.js +6 -0
- package/dist/demo/server.js +34 -0
- package/dist/mcpd/cache.js +18 -4
- package/dist/mcpd/calllog.js +253 -0
- package/dist/mcpd/client-names.js +51 -0
- package/dist/mcpd/connectors.js +148 -17
- package/dist/mcpd/daemon.js +452 -116
- package/dist/mcpd/folder-sets.js +39 -0
- package/dist/mcpd/gateway.js +441 -47
- package/dist/mcpd/health.js +269 -0
- package/dist/mcpd/importer.js +356 -36
- package/dist/mcpd/instances.js +425 -65
- package/dist/mcpd/jsonrpc.js +8 -0
- package/dist/mcpd/launchd.js +65 -48
- package/dist/mcpd/modern.js +648 -0
- package/dist/mcpd/oauth.js +791 -0
- package/dist/mcpd/peerpid.js +122 -6
- package/dist/mcpd/pressure.js +85 -0
- package/dist/mcpd/rss.js +151 -0
- package/dist/mcpd/service.js +167 -0
- package/dist/mcpd/state.js +183 -0
- package/dist/mcpd/sync.js +55 -80
- package/dist/mcpd/systemd.js +80 -0
- package/dist/mcpd/tokens.js +89 -0
- package/dist/mcpd/upstream.js +154 -44
- package/dist/statusline/cost.js +154 -44
- package/dist/statusline/input.js +66 -0
- package/dist/statusline/render.js +9 -3
- package/dist/ui/fonts.js +8 -3
- package/dist/ui/settings.js +27 -15
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +9 -9
- package/dist/cli/commands/available.js +0 -18
|
@@ -1,33 +1,72 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
1
5
|
import { paths, tildify } from "../../core/paths.js";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
6
|
+
import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
|
|
7
|
+
import { group } from "../group.js";
|
|
8
|
+
import { fail, needsAnswer, paint } from "../io.js";
|
|
9
|
+
export const INSTALL_HINT = "npm install --global turno-browser";
|
|
10
|
+
export const NOT_INSTALLED = `turno-browser is not installed: ${INSTALL_HINT}`;
|
|
11
|
+
const SPEC = "turno-browser";
|
|
12
|
+
function isMissing(err) {
|
|
13
|
+
const code = err.code;
|
|
14
|
+
return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
|
|
15
|
+
}
|
|
16
|
+
/** The global npm folder, where `npm install --global turno-browser` puts the package. */
|
|
17
|
+
function npmGlobalRoot(env) {
|
|
18
|
+
try {
|
|
19
|
+
return execFileSync("npm", ["root", "--global"], { env, encoding: "utf8", stdio: ["ignore", "pipe", "ignore"], timeout: 5000 }).trim() || undefined;
|
|
20
|
+
}
|
|
21
|
+
catch {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Load turno-browser: next to this install first, then (with `global`) from the global npm
|
|
27
|
+
* folder, which a Homebrew or npx install of turno cannot see on its own.
|
|
28
|
+
*/
|
|
29
|
+
export async function loadBrowser(options = {}) {
|
|
30
|
+
try {
|
|
31
|
+
return (await import(SPEC));
|
|
32
|
+
}
|
|
33
|
+
catch (err) {
|
|
34
|
+
if (!isMissing(err))
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
|
+
if (!options.global)
|
|
38
|
+
return undefined;
|
|
39
|
+
const root = npmGlobalRoot(options.env ?? process.env);
|
|
40
|
+
if (!root)
|
|
41
|
+
return undefined;
|
|
18
42
|
try {
|
|
19
|
-
|
|
43
|
+
const entry = createRequire(join(root, "noop.js")).resolve(SPEC);
|
|
44
|
+
return (await import(pathToFileURL(entry).href));
|
|
20
45
|
}
|
|
21
46
|
catch (err) {
|
|
22
|
-
|
|
23
|
-
if (code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED")
|
|
47
|
+
if (isMissing(err))
|
|
24
48
|
return undefined;
|
|
25
49
|
throw err;
|
|
26
50
|
}
|
|
27
51
|
}
|
|
28
|
-
function
|
|
52
|
+
async function askOnTerminal(question) {
|
|
53
|
+
const { createInterface } = await import("node:readline/promises");
|
|
54
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
55
|
+
try {
|
|
56
|
+
return /^y(es)?$/i.test((await rl.question(question)).trim());
|
|
57
|
+
}
|
|
58
|
+
finally {
|
|
59
|
+
rl.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export const defaultDeps = {
|
|
63
|
+
load: (io) => loadBrowser({ global: true, env: io.env }),
|
|
64
|
+
interactive: (io) => Boolean(io.ask),
|
|
65
|
+
confirm: (question) => askOnTerminal(question),
|
|
66
|
+
};
|
|
67
|
+
function checkId(mod, id, sub) {
|
|
29
68
|
if (!id)
|
|
30
|
-
return fail(`browser ${sub} needs an identity id
|
|
69
|
+
return fail(`browser ${sub} needs an identity id (for example: turno browser ${sub} school)`);
|
|
31
70
|
try {
|
|
32
71
|
mod.assertIdentityId(id);
|
|
33
72
|
}
|
|
@@ -36,56 +75,57 @@ function requireId(mod, id, sub) {
|
|
|
36
75
|
}
|
|
37
76
|
return id;
|
|
38
77
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const engines = takeList(args, "--engine");
|
|
62
|
-
const urls = takeList(engines.rest, "--url");
|
|
63
|
-
const rest = urls.rest;
|
|
64
|
-
const json = rest.includes("--json");
|
|
65
|
-
const detectors = !rest.includes("--no-detectors");
|
|
66
|
-
const unknown = rest.filter((a) => a !== "--json" && a !== "--no-detectors");
|
|
67
|
-
if (unknown.length)
|
|
68
|
-
return fail(`unknown bench argument: ${unknown[0]}\n\n${USAGE}`);
|
|
69
|
-
const engineNames = engines.values.flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
|
|
70
|
-
for (const e of engineNames) {
|
|
71
|
-
if (!mod.ENGINES.includes(e))
|
|
78
|
+
const BENCH_FLAGS = {
|
|
79
|
+
engine: { type: "string", multiple: true },
|
|
80
|
+
url: { type: "string", multiple: true },
|
|
81
|
+
"only-urls": { type: "boolean" },
|
|
82
|
+
// Older name of --only-urls, kept so scripts keep working.
|
|
83
|
+
"no-detectors": { type: "boolean" },
|
|
84
|
+
yes: { type: "boolean", short: "y" },
|
|
85
|
+
...JSON_FLAG,
|
|
86
|
+
};
|
|
87
|
+
export const BENCH_PROMPT = "This opens Chrome and visits third-party test pages. Continue? [y/N] ";
|
|
88
|
+
const URLS_PROMPT = "This opens Chrome and visits the URLs you gave. Continue? [y/N] ";
|
|
89
|
+
async function bench(mod, args, io, deps) {
|
|
90
|
+
const p = parseFlags(args, BENCH_FLAGS, 0);
|
|
91
|
+
const list = (name) => (p.values[name] ?? []).flatMap((v) => v.split(",")).map((v) => v.trim()).filter(Boolean);
|
|
92
|
+
const given = list("engine");
|
|
93
|
+
const urls = p.values.url ?? [];
|
|
94
|
+
const onlyUrls = bool(p, "only-urls") || bool(p, "no-detectors");
|
|
95
|
+
const engines = [];
|
|
96
|
+
for (const e of given) {
|
|
97
|
+
// An older turno-browser has no engineId: its ENGINES list is the whole truth.
|
|
98
|
+
const id = mod.engineId ? mod.engineId(e) : mod.ENGINES.includes(e) ? e : undefined;
|
|
99
|
+
if (!id)
|
|
72
100
|
return fail(`unknown engine "${e}" (known: ${mod.ENGINES.join(", ")})`);
|
|
101
|
+
engines.push(id);
|
|
73
102
|
}
|
|
74
|
-
for (const u of urls
|
|
103
|
+
for (const u of urls) {
|
|
75
104
|
if (!/^https?:\/\//.test(u))
|
|
76
105
|
return fail(`--url must start with http:// or https://: ${u}`);
|
|
77
106
|
}
|
|
78
|
-
if (
|
|
79
|
-
return fail("--
|
|
107
|
+
if (onlyUrls && urls.length === 0)
|
|
108
|
+
return fail("--only-urls needs at least one --url");
|
|
109
|
+
// Opening a browser on outside pages needs a yes from a person: --json is not consent.
|
|
110
|
+
if (!bool(p, "yes")) {
|
|
111
|
+
if (!deps.interactive(io)) {
|
|
112
|
+
io.err("browser bench opens Chrome and visits third-party test pages.");
|
|
113
|
+
return needsAnswer("browser bench");
|
|
114
|
+
}
|
|
115
|
+
if (!(await deps.confirm(onlyUrls ? URLS_PROMPT : BENCH_PROMPT, io))) {
|
|
116
|
+
io.err("Cancelled; nothing was opened.");
|
|
117
|
+
return 1;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
80
120
|
const report = await mod.runBench({
|
|
81
|
-
engines
|
|
82
|
-
urls
|
|
83
|
-
detectors,
|
|
121
|
+
engines,
|
|
122
|
+
urls,
|
|
123
|
+
detectors: !onlyUrls,
|
|
84
124
|
env: io.env,
|
|
85
125
|
onProgress: (m) => io.err(paint(io, m, "2")),
|
|
86
126
|
});
|
|
87
|
-
if (json) {
|
|
88
|
-
io
|
|
127
|
+
if (bool(p, "json")) {
|
|
128
|
+
printJson(io, report);
|
|
89
129
|
}
|
|
90
130
|
else {
|
|
91
131
|
io.out(mod.formatBenchTable(report));
|
|
@@ -94,82 +134,123 @@ async function bench(mod, args, io) {
|
|
|
94
134
|
}
|
|
95
135
|
return 0;
|
|
96
136
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
137
|
+
function identities(mod, args, io) {
|
|
138
|
+
const p = parseFlags(args, JSON_FLAG, 0);
|
|
139
|
+
const list = mod.listIdentities(io.env);
|
|
140
|
+
if (bool(p, "json")) {
|
|
141
|
+
printJson(io, list.map((i) => ({ id: i.id, inUse: i.inUse, dir: tildify(i.dir, io.env) })));
|
|
142
|
+
return 0;
|
|
143
|
+
}
|
|
144
|
+
if (!list.length) {
|
|
145
|
+
io.out("No browser identities yet. Create one with `turno identity add browser:<id>`.");
|
|
146
|
+
return 0;
|
|
147
|
+
}
|
|
148
|
+
const width = Math.max(...list.map((i) => i.id.length));
|
|
149
|
+
for (const i of list) {
|
|
150
|
+
const state = i.inUse ? paint(io, "in use", "33") : paint(io, "free ", "32");
|
|
151
|
+
io.out(`${i.id.padEnd(width)} ${state} ${tildify(i.dir, io.env)}`);
|
|
152
|
+
}
|
|
153
|
+
return 0;
|
|
154
|
+
}
|
|
155
|
+
function add(mod, args, io) {
|
|
156
|
+
const p = parseFlags(args, DRY_RUN, 1);
|
|
157
|
+
const id = checkId(mod, p.positionals[0], "add");
|
|
158
|
+
if (bool(p, "dry-run")) {
|
|
159
|
+
io.out(`(dry run) would create browser identity "${id}"`);
|
|
160
|
+
return 0;
|
|
161
|
+
}
|
|
162
|
+
const info = mod.addIdentity(id, io.env);
|
|
163
|
+
io.out(`identity "${id}" ready at ${tildify(info.dir, io.env)}`);
|
|
164
|
+
io.out(`\nAdd this to ${tildify(paths(io.env).mcpFile, io.env)}, then run \`turno mcp sync\`:\n`);
|
|
165
|
+
io.out(mod.manifestSnippet(id));
|
|
166
|
+
io.out(`Sign in to your sites once with \`turno identity login browser:${id}\`.`);
|
|
167
|
+
return 0;
|
|
168
|
+
}
|
|
169
|
+
function remove(mod, args, io) {
|
|
170
|
+
const p = parseFlags(args, DRY_RUN, 1);
|
|
171
|
+
const id = checkId(mod, p.positionals[0], "remove");
|
|
172
|
+
if (bool(p, "dry-run")) {
|
|
173
|
+
io.out(`(dry run) would delete browser identity "${id}" and its saved logins`);
|
|
174
|
+
return 0;
|
|
175
|
+
}
|
|
176
|
+
mod.removeIdentity(id, io.env);
|
|
177
|
+
io.out(`removed identity "${id}" and its saved browser data`);
|
|
178
|
+
io.out(`Remove its [server.browser-${id}] block from ${tildify(paths(io.env).mcpFile, io.env)} if you added one.`);
|
|
179
|
+
return 0;
|
|
180
|
+
}
|
|
181
|
+
async function login(mod, args, io) {
|
|
182
|
+
const p = parseFlags(args, { url: { type: "string" } }, 1);
|
|
183
|
+
const id = checkId(mod, p.positionals[0], "login");
|
|
184
|
+
const url = str(p, "url");
|
|
185
|
+
if (url !== undefined && !/^https?:\/\//.test(url))
|
|
186
|
+
return fail(`--url must start with http:// or https://: ${url}`);
|
|
187
|
+
if (mod.isInUse(id, io.env)) {
|
|
188
|
+
return fail(`identity "${id}" is in use by a running Chrome (probably an MCP session through mcpd). Close that session or wait for its lease to end, then retry.`);
|
|
189
|
+
}
|
|
190
|
+
io.out(`Opening Chrome for identity "${id}". Sign in to your sites, then close the window to save the session.`);
|
|
191
|
+
const options = { env: io.env };
|
|
192
|
+
if (url)
|
|
193
|
+
options.url = url;
|
|
194
|
+
await mod.loginIdentity(id, options);
|
|
195
|
+
io.out(`saved. Sessions using browser-${id} now start signed in.`);
|
|
196
|
+
return 0;
|
|
197
|
+
}
|
|
198
|
+
/** Run one browser subcommand with a loaded module. `identity` uses it for browser:<id>. */
|
|
199
|
+
export async function dispatch(mod, sub, rest, io, deps = defaultDeps) {
|
|
200
|
+
try {
|
|
201
|
+
switch (sub) {
|
|
202
|
+
case "identities":
|
|
203
|
+
case "list":
|
|
204
|
+
return identities(mod, rest, io);
|
|
205
|
+
case "add":
|
|
206
|
+
return add(mod, rest, io);
|
|
207
|
+
case "remove":
|
|
208
|
+
case "rm":
|
|
209
|
+
return remove(mod, rest, io);
|
|
210
|
+
case "login":
|
|
211
|
+
return await login(mod, rest, io);
|
|
212
|
+
case "bench":
|
|
213
|
+
return await bench(mod, rest, io, deps);
|
|
214
|
+
default:
|
|
215
|
+
return fail(`unknown browser command "${sub}"`);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
catch (err) {
|
|
219
|
+
if (err.name === "IdentityError")
|
|
220
|
+
return fail(err.message);
|
|
221
|
+
throw err;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
const FOOTER = `A developer diagnostic for browser engine compatibility. It needs the separate
|
|
225
|
+
turno-browser package (${INSTALL_HINT}).
|
|
226
|
+
Identities are persistent Chrome profiles served by turno-browser-mcp, one session at a time
|
|
227
|
+
through mcpd; turno identity manages them too (browser:<id>). Ids use lowercase letters,
|
|
228
|
+
digits, "-" and "_", for example "school".`;
|
|
229
|
+
/** The `browser` command, with its loader and prompt injectable for tests. */
|
|
230
|
+
export function browserCommand(deps = defaultDeps) {
|
|
231
|
+
const withModule = (sub) => async (args, io) => {
|
|
232
|
+
const mod = await deps.load(io);
|
|
106
233
|
if (!mod) {
|
|
107
234
|
io.err(`turno: ${NOT_INSTALLED}`);
|
|
108
235
|
return 1;
|
|
109
236
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
return 0;
|
|
128
|
-
}
|
|
129
|
-
const width = Math.max(...list.map((i) => i.id.length));
|
|
130
|
-
for (const i of list) {
|
|
131
|
-
const state = i.inUse ? paint(io, "in use", "33") : paint(io, "free ", "32");
|
|
132
|
-
io.out(`${i.id.padEnd(width)} ${state} ${tildify(i.dir, io.env)}`);
|
|
133
|
-
}
|
|
134
|
-
return 0;
|
|
135
|
-
}
|
|
136
|
-
case "add": {
|
|
137
|
-
const id = requireId(mod, rest[0], "add");
|
|
138
|
-
const info = mod.addIdentity(id, io.env);
|
|
139
|
-
io.out(`identity "${id}" ready at ${tildify(info.dir, io.env)}`);
|
|
140
|
-
io.out(`\nAdd this to ${tildify(paths(io.env).mcpFile, io.env)}, then run \`turno mcp sync\`:\n`);
|
|
141
|
-
io.out(mod.manifestSnippet(id));
|
|
142
|
-
io.out(`Sign in to your sites once with \`turno browser login ${id}\`.`);
|
|
143
|
-
return 0;
|
|
144
|
-
}
|
|
145
|
-
case "remove":
|
|
146
|
-
case "rm": {
|
|
147
|
-
const id = requireId(mod, rest[0], "remove");
|
|
148
|
-
mod.removeIdentity(id, io.env);
|
|
149
|
-
io.out(`removed identity "${id}" and its saved browser data`);
|
|
150
|
-
io.out(`Remove its [server.browser-${id}] block from ${tildify(paths(io.env).mcpFile, io.env)} if you added one.`);
|
|
151
|
-
return 0;
|
|
152
|
-
}
|
|
153
|
-
case "login": {
|
|
154
|
-
const id = requireId(mod, rest[0], "login");
|
|
155
|
-
const { values, rest: extra } = takeList(rest.slice(1), "--url");
|
|
156
|
-
if (extra.length)
|
|
157
|
-
return fail(`unknown login argument: ${extra[0]}`);
|
|
158
|
-
if (mod.isInUse(id, io.env)) {
|
|
159
|
-
return fail(`identity "${id}" is in use by a running Chrome (probably an MCP session through mcpd). Close that session or wait for its lease to end, then retry.`);
|
|
160
|
-
}
|
|
161
|
-
io.out(`Opening Chrome for identity "${id}". Sign in to your sites, then close the window to save the session.`);
|
|
162
|
-
const options = { env: io.env };
|
|
163
|
-
if (values[0])
|
|
164
|
-
options.url = values[0];
|
|
165
|
-
await mod.loginIdentity(id, options);
|
|
166
|
-
io.out(`saved. Sessions using browser-${id} now start signed in.`);
|
|
167
|
-
return 0;
|
|
168
|
-
}
|
|
169
|
-
case "bench":
|
|
170
|
-
return bench(mod, rest, io);
|
|
171
|
-
default:
|
|
172
|
-
return fail(`unknown browser command "${sub}"\n\n${USAGE}`);
|
|
173
|
-
}
|
|
237
|
+
return dispatch(mod, sub, args, io, deps);
|
|
238
|
+
};
|
|
239
|
+
const subs = {
|
|
240
|
+
identities: { summary: "list browser identities and whether they are in use", synopsis: "[--json]", flags: ["--json"], run: withModule("identities") },
|
|
241
|
+
list: { summary: "same as identities", hidden: true, run: withModule("identities") },
|
|
242
|
+
add: { summary: "create an identity and print its mcp.toml block", synopsis: "<id> [--dry-run]", flags: ["--dry-run"], run: withModule("add") },
|
|
243
|
+
remove: { summary: "delete an identity and its saved logins", synopsis: "<id> [--dry-run]", flags: ["--dry-run"], run: withModule("remove") },
|
|
244
|
+
rm: { summary: "same as remove", hidden: true, run: withModule("remove") },
|
|
245
|
+
login: { summary: "open the identity's Chrome to sign in by hand once", synopsis: "<id> [--url <url>]", flags: ["--url"], run: withModule("login") },
|
|
246
|
+
bench: {
|
|
247
|
+
summary: "check how each browser engine loads reference test pages and your URLs (asks first)",
|
|
248
|
+
synopsis: "[--engine <name>]... [--url <url>]... [--only-urls] [--yes] [--json]",
|
|
249
|
+
flags: ["--engine", "--url", "--only-urls", "--yes", "--json"],
|
|
250
|
+
run: withModule("bench"),
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
return group("browser", "developer tool: compare browser engines (needs turno-browser)", subs, { footer: FOOTER });
|
|
174
254
|
}
|
|
255
|
+
export const command = browserCommand();
|
|
175
256
|
//# sourceMappingURL=browser.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { loadRegistry } from "../../accounts/registry.js";
|
|
2
|
+
import { AGENT_IDS, DEFAULT_AGENT } from "../../agents/index.js";
|
|
2
3
|
import { loadConfig } from "../../core/config.js";
|
|
3
4
|
import { listJournals } from "../../core/journal.js";
|
|
4
5
|
import { loadManifest } from "../../core/manifest.js";
|
|
@@ -50,7 +51,7 @@ async function values(kind, env) {
|
|
|
50
51
|
return ["last", ...listJournals(env).filter((j) => j.manifest).map((j) => j.stamp)];
|
|
51
52
|
case "key": {
|
|
52
53
|
const { CONFIG_KEYS } = await import("./config.js");
|
|
53
|
-
return CONFIG_KEYS.flatMap((k) =>
|
|
54
|
+
return CONFIG_KEYS.flatMap((k) => k.includes("<name>") ? profiles().map((p) => k.replace("<name>", p)) : k.includes("<agent>") ? AGENT_IDS.filter((a) => a !== DEFAULT_AGENT).map((a) => k.replace("<agent>", a)) : [k]);
|
|
54
55
|
}
|
|
55
56
|
case "shell":
|
|
56
57
|
return ["zsh", "bash", "fish"];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { parseFlags } from "../args.js";
|
|
1
2
|
import { fail } from "../io.js";
|
|
2
3
|
const ZSH = `#compdef turno
|
|
3
4
|
# turno completion for zsh. Load it with: source <(turno completion zsh)
|
|
@@ -47,8 +48,9 @@ export const command = {
|
|
|
47
48
|
].join("\n"),
|
|
48
49
|
args: ["shell"],
|
|
49
50
|
async run(args, io) {
|
|
50
|
-
const
|
|
51
|
-
|
|
51
|
+
const p = parseFlags(args, {}, 1);
|
|
52
|
+
const script = SCRIPTS[p.positionals[0] ?? ""];
|
|
53
|
+
if (!script)
|
|
52
54
|
return fail("usage: turno completion <zsh|bash|fish>");
|
|
53
55
|
io.out(script.trimEnd());
|
|
54
56
|
return 0;
|
|
@@ -3,32 +3,42 @@ import { existsSync } from "node:fs";
|
|
|
3
3
|
import { parse } from "smol-toml";
|
|
4
4
|
import { loadRegistry } from "../../accounts/registry.js";
|
|
5
5
|
import { editConfig, migrationPending, readConfigText } from "../../core/config-edit.js";
|
|
6
|
-
import { loadConfig } from "../../core/config.js";
|
|
6
|
+
import { IDLE_UNDER_PRESSURE_PROBLEM, loadConfig, parseIdleUnderPressure, requestBodyProblem } from "../../core/config.js";
|
|
7
|
+
import { DEFAULT_AGENT, adapter, isAgentId } from "../../agents/index.js";
|
|
8
|
+
import { agentOf, configProblems, listProfiles } from "../../core/profiles.js";
|
|
7
9
|
import { Journal } from "../../core/journal.js";
|
|
8
10
|
import { loadManifest } from "../../core/manifest.js";
|
|
9
11
|
import { paths, tildify } from "../../core/paths.js";
|
|
10
12
|
import { removeValue, setValue } from "../../core/toml-edit.js";
|
|
11
|
-
import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson } from "../args.js";
|
|
13
|
+
import { DRY_RUN, JSON_FLAG, bool, flagsOf, parseFlags, printJson } from "../args.js";
|
|
12
14
|
import { group } from "../group.js";
|
|
13
|
-
import {
|
|
15
|
+
import { highlightToml } from "../highlight.js";
|
|
16
|
+
import { colors, columns, fail, paint } from "../io.js";
|
|
17
|
+
import { parseColor } from "./profile.js";
|
|
14
18
|
/** Keys `config set` may change; tables of their own have their own commands. */
|
|
15
19
|
const KEYS = {
|
|
16
|
-
system:
|
|
17
|
-
default: "profile for folders without a rule",
|
|
18
|
-
fallback: "profile used while the assigned one is exhausted",
|
|
20
|
+
system: 'profile the plain claude command (~/.claude) is logged into; "" for none (then turno auto needs a rule)',
|
|
21
|
+
default: "Claude Code profile for folders without a rule",
|
|
22
|
+
fallback: "Claude Code profile used while the assigned one is exhausted (opt-in)",
|
|
23
|
+
"agents.<agent>.default": "the same for codex, copilot or cursor",
|
|
24
|
+
"agents.<agent>.fallback": "the same for codex, copilot or cursor (opt-in)",
|
|
19
25
|
icons: "auto, nerd or unicode",
|
|
20
26
|
nerd_terminals: "terminals whose font draws Nerd icons",
|
|
21
27
|
update_check: "true or false: look for new turno releases once a day",
|
|
22
28
|
"open.chrome_dir": "folder of the isolated Chrome profiles",
|
|
23
29
|
"mcpd.port": "port of the MCP gateway",
|
|
30
|
+
"mcpd.call_log": "true or false: keep the log of tool calls (turno mcp log)",
|
|
31
|
+
"mcpd.max_request_body": 'largest request mcpd accepts, like "64MiB" (default 32MiB)',
|
|
32
|
+
"mcpd.idle_under_pressure": 'idle limit of MCP servers while memory is low, like "5m" (default), or false',
|
|
24
33
|
"profiles.<name>.color": "status line pill color",
|
|
25
34
|
"profiles.<name>.browser": "chrome or default",
|
|
26
35
|
};
|
|
27
36
|
/** Split a dotted key into its table and key. */
|
|
28
37
|
export function splitKey(key) {
|
|
29
|
-
const
|
|
38
|
+
const pattern = (k) => new RegExp(`^${k.replace(/\./g, "\\.").replace("<name>", "[a-z0-9][a-z0-9_-]*").replace("<agent>", "(codex|copilot|cursor)")}$`);
|
|
39
|
+
const allowed = Object.keys(KEYS).some((k) => pattern(k).test(key));
|
|
30
40
|
if (!allowed)
|
|
31
|
-
fail(`unknown key '${key}'
|
|
41
|
+
fail(`unknown key '${key}' (turno config --help lists them)`);
|
|
32
42
|
const i = key.lastIndexOf(".");
|
|
33
43
|
return i < 0 ? { table: undefined, key } : { table: key.slice(0, i), key: key.slice(i + 1) };
|
|
34
44
|
}
|
|
@@ -60,7 +70,7 @@ async function path(args, io) {
|
|
|
60
70
|
const pp = paths(env);
|
|
61
71
|
const files = { config: pp.configFile, mcp: pp.mcpFile, accounts: pp.accountsFile, state: pp.state, backups: pp.backupsDir };
|
|
62
72
|
if (bool(p, "json")) {
|
|
63
|
-
printJson(io
|
|
73
|
+
printJson(io, Object.fromEntries(Object.entries(files).map(([k, v]) => [k, { path: tildify(v, env), exists: existsSync(v) }])));
|
|
64
74
|
return 0;
|
|
65
75
|
}
|
|
66
76
|
for (const [k, v] of Object.entries(files))
|
|
@@ -81,21 +91,94 @@ async function get(args, io) {
|
|
|
81
91
|
return 1;
|
|
82
92
|
}
|
|
83
93
|
if (bool(p, "json") || typeof v === "object")
|
|
84
|
-
printJson(io
|
|
94
|
+
printJson(io, v);
|
|
85
95
|
else
|
|
86
96
|
io.out(String(v));
|
|
87
97
|
return 0;
|
|
88
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Check a value before it is written, with the messages `profile add` uses: profile names
|
|
101
|
+
* must exist (and run the right agent), colors and enums must be valid. Returns the value to write.
|
|
102
|
+
*/
|
|
103
|
+
export function checkValue(key, raw, env) {
|
|
104
|
+
const value = parseValue(raw);
|
|
105
|
+
const profile = (name, agent) => {
|
|
106
|
+
if (typeof name !== "string" || !name)
|
|
107
|
+
fail(`${key} must be a profile name`);
|
|
108
|
+
const config = loadConfig(env);
|
|
109
|
+
if (!listProfiles(config, env).includes(name))
|
|
110
|
+
fail(`no profile '${name}' (turno profile list)`);
|
|
111
|
+
const has = agentOf(name, config);
|
|
112
|
+
if (has !== agent)
|
|
113
|
+
fail(`${name} is a ${adapter(has).label} profile, but ${key} is for ${adapter(agent).label}`);
|
|
114
|
+
return name;
|
|
115
|
+
};
|
|
116
|
+
const roles = /^(?:agents\.([a-z]+)\.)?(system|default|fallback)$/.exec(key);
|
|
117
|
+
if (roles) {
|
|
118
|
+
if (key === "system" && (value === "" || raw === '""'))
|
|
119
|
+
return "";
|
|
120
|
+
const agent = roles[1] ?? DEFAULT_AGENT;
|
|
121
|
+
if (!isAgentId(agent))
|
|
122
|
+
fail(`unknown agent '${agent}'`);
|
|
123
|
+
return profile(value, agent);
|
|
124
|
+
}
|
|
125
|
+
const prof = /^profiles\.([^.]+)\.(color|browser)$/.exec(key);
|
|
126
|
+
if (prof) {
|
|
127
|
+
if (!listProfiles(loadConfig(env), env).includes(prof[1]))
|
|
128
|
+
fail(`no profile '${prof[1]}' (turno profile list)`);
|
|
129
|
+
if (prof[2] === "color")
|
|
130
|
+
return parseColor(raw, key);
|
|
131
|
+
if (raw !== "chrome" && raw !== "default")
|
|
132
|
+
fail(`${key} must be chrome or default`);
|
|
133
|
+
return raw;
|
|
134
|
+
}
|
|
135
|
+
switch (key) {
|
|
136
|
+
case "icons":
|
|
137
|
+
if (raw !== "auto" && raw !== "nerd" && raw !== "unicode")
|
|
138
|
+
fail("icons must be auto, nerd or unicode");
|
|
139
|
+
return raw;
|
|
140
|
+
case "update_check":
|
|
141
|
+
if (typeof value !== "boolean")
|
|
142
|
+
fail("update_check must be true or false");
|
|
143
|
+
return value;
|
|
144
|
+
case "mcpd.port":
|
|
145
|
+
if (typeof value !== "number" || value < 1024 || value > 65535)
|
|
146
|
+
fail("mcpd.port must be an integer between 1024 and 65535");
|
|
147
|
+
return value;
|
|
148
|
+
case "mcpd.max_request_body": {
|
|
149
|
+
const problem = requestBodyProblem(value);
|
|
150
|
+
if (problem)
|
|
151
|
+
fail(problem);
|
|
152
|
+
return value;
|
|
153
|
+
}
|
|
154
|
+
case "mcpd.idle_under_pressure":
|
|
155
|
+
if (parseIdleUnderPressure(value) === undefined)
|
|
156
|
+
fail(IDLE_UNDER_PRESSURE_PROBLEM);
|
|
157
|
+
return value;
|
|
158
|
+
case "nerd_terminals":
|
|
159
|
+
if (!Array.isArray(value))
|
|
160
|
+
fail('nerd_terminals must be a list, like ["warp", "vscode"]');
|
|
161
|
+
return value;
|
|
162
|
+
case "open.chrome_dir":
|
|
163
|
+
return raw;
|
|
164
|
+
}
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
const SET_SPEC = { ...DRY_RUN };
|
|
89
168
|
async function set(args, io) {
|
|
90
|
-
const p = parseFlags(args,
|
|
169
|
+
const p = parseFlags(args, SET_SPEC, 2);
|
|
91
170
|
const [key, raw] = p.positionals;
|
|
92
171
|
if (!key || raw === undefined)
|
|
93
172
|
return fail("usage: turno config set <key> <value>");
|
|
94
173
|
const k = splitKey(key);
|
|
174
|
+
const value = checkValue(key, raw, io.env);
|
|
95
175
|
const dry = bool(p, "dry-run");
|
|
96
176
|
const journal = new Journal(io.env, `config set ${key}`, dry);
|
|
97
|
-
const { changed } = editConfig(io.env, journal, (t) => setValue(t, k.table, k.key,
|
|
98
|
-
|
|
177
|
+
const { changed } = editConfig(io.env, journal, (t) => setValue(t, k.table, k.key, value));
|
|
178
|
+
const line = `${key} = ${JSON.stringify(value)}`;
|
|
179
|
+
io.out(`${colors(io) ? highlightToml(line) : line}${changed ? "" : " (unchanged)"}${dry ? " (dry run)" : ""}`);
|
|
180
|
+
if (/(^|\.)fallback$/.test(key))
|
|
181
|
+
io.out('fallback is opt-in: read "Vendor terms" in the README before relying on it.');
|
|
99
182
|
if (journal.hint())
|
|
100
183
|
io.out(journal.hint());
|
|
101
184
|
return 0;
|
|
@@ -146,7 +229,10 @@ async function check(args, io) {
|
|
|
146
229
|
io.out(`${paint(io, "FAIL", "31")} ${err.message}`);
|
|
147
230
|
}
|
|
148
231
|
};
|
|
149
|
-
|
|
232
|
+
const problems = [];
|
|
233
|
+
one(pp.configFile, () => problems.push(...configProblems(loadConfig(io.env), io.env)));
|
|
234
|
+
for (const w of problems)
|
|
235
|
+
io.out(`${paint(io, "warn", "33")} ${w}`);
|
|
150
236
|
one(pp.mcpFile, () => loadManifest(io.env));
|
|
151
237
|
one(pp.accountsFile, () => loadRegistry(io.env));
|
|
152
238
|
return failed ? 1 : 0;
|
|
@@ -154,15 +240,14 @@ async function check(args, io) {
|
|
|
154
240
|
export const command = group("config", "read and change config.toml without losing its comments; check every config file", {
|
|
155
241
|
path: { summary: "where each config and state file lives", synopsis: "[--json]", flags: ["--json"], run: path },
|
|
156
242
|
get: { summary: "print a value (the whole file as JSON without a key)", synopsis: "[key] [--json]", args: ["key"], flags: ["--json"], run: get },
|
|
157
|
-
set: { summary: "set a value
|
|
243
|
+
set: { summary: "set a value, checked like profile add checks it", synopsis: "<key> <value> [--dry-run]", args: ["key", "any"], flags: flagsOf(SET_SPEC), run: set },
|
|
158
244
|
unset: { summary: "remove a value", synopsis: "<key> [--dry-run]", args: ["key"], flags: ["--dry-run"], run: unset },
|
|
159
245
|
edit: { summary: "open config.toml in $VISUAL or $EDITOR, then check it", run: edit },
|
|
160
246
|
check: { summary: "parse config.toml, mcp.toml and accounts.toml", run: check },
|
|
161
247
|
}, {
|
|
162
248
|
fallback: "path",
|
|
163
|
-
footer: `Keys:\n${Object.entries(KEYS)
|
|
164
|
-
|
|
165
|
-
.join("\n")}\n\nProjects use turno profile assign; MCP servers live in mcp.toml (turno mcp).`,
|
|
249
|
+
footer: `Keys:\n${columns(Object.entries(KEYS), 2, 26)}\n\nProjects use turno profile assign; MCP servers live in mcp.toml (turno mcp).
|
|
250
|
+
A [[projects]] rule with mcp = [...] limits the servers of that folder.`,
|
|
166
251
|
});
|
|
167
252
|
export const CONFIG_KEYS = Object.keys(KEYS);
|
|
168
253
|
//# sourceMappingURL=config.js.map
|