turno-cli 0.4.0 → 0.5.1
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 +36 -0
- package/README.md +2 -2
- package/dist/cli/args.js +2 -78
- package/dist/cli/commands/browser-do-session.js +16 -117
- package/dist/cli/commands/browser-do.js +99 -598
- package/dist/cli/commands/browser.js +130 -440
- package/dist/cli/commands/completion.js +3 -37
- package/dist/cli/commands/identity.js +101 -96
- package/dist/cli/commands/mcp-call.js +2 -38
- package/dist/cli/commands/mcpd.js +8 -0
- package/dist/cli/exit.js +2 -64
- package/dist/cli/group.js +2 -61
- package/dist/cli/highlight.js +2 -235
- package/dist/cli/hints.js +5 -12
- package/dist/cli/io.js +2 -206
- package/dist/cli/output.js +2 -122
- package/dist/cli/registry.js +3 -2
- package/dist/cli/secret-input.js +2 -62
- package/dist/cli/style.js +2 -289
- package/dist/cli/topics.js +4 -0
- package/dist/core/paths.js +2 -9
- package/dist/mcpd/daemon.js +13 -0
- package/npm-shrinkwrap.json +5 -5
- package/package.json +3 -3
- package/dist/cli/commands/browser-flows.js +0 -300
- package/dist/cli/commands/browser-identity.js +0 -952
- package/dist/cli/commands/browser-live.js +0 -118
- package/dist/cli/commands/browser-session.js +0 -102
- package/dist/cli/commands/browser-vault.js +0 -193
|
@@ -10,8 +10,7 @@ import { fail } from "../io.js";
|
|
|
10
10
|
import { profileColor, style } from "../style.js";
|
|
11
11
|
import * as accounts from "./accounts.js";
|
|
12
12
|
import { policyLine } from "./accounts.js";
|
|
13
|
-
import { NOT_INSTALLED, defaultDeps, dispatch } from "./browser.js";
|
|
14
|
-
import { SETTINGS_FLAGS, SETTINGS_FLAG_NAMES, SET_DETAILS, SET_FLAG_NAMES, SET_JSON, SET_SYNOPSIS, SHOW_JSON, } from "./browser-identity.js";
|
|
13
|
+
import { NOT_INSTALLED, browserCli, defaultDeps, dispatch, preload, } from "./browser.js";
|
|
15
14
|
/**
|
|
16
15
|
* Who acts on an outside service for a session: a service account (`linear:work`, run by a
|
|
17
16
|
* profile through the accounts bridge) or a browser identity (`browser:school`, a Chrome
|
|
@@ -120,12 +119,6 @@ function bareId(args) {
|
|
|
120
119
|
async function add(args, io) {
|
|
121
120
|
if (!firstId(args)?.startsWith(BROWSER))
|
|
122
121
|
return accounts.add(args, io);
|
|
123
|
-
const p = parseFlags(args, { ...DRY_RUN, ...SETTINGS_FLAGS }, 1);
|
|
124
|
-
const id = p.positionals[0].slice(BROWSER.length);
|
|
125
|
-
if (bool(p, "dry-run")) {
|
|
126
|
-
io.out(`(dry run) would create browser identity "${id}"`);
|
|
127
|
-
return 0;
|
|
128
|
-
}
|
|
129
122
|
return dispatch(await browserModule(io), "add", bareId(args), io, deps);
|
|
130
123
|
}
|
|
131
124
|
/** `show` and `set` exist for browser identities only. */
|
|
@@ -162,93 +155,105 @@ export function setBrowserDeps(next) {
|
|
|
162
155
|
deps = next;
|
|
163
156
|
return prev;
|
|
164
157
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
"
|
|
181
|
-
"--confirm",
|
|
182
|
-
"
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
158
|
+
/**
|
|
159
|
+
* The `identity` command. The browser parts of its help (the settings flags of `add` and `set`,
|
|
160
|
+
* set's details, the JSON of `show` and `set`) come from turno-browser when it is installed.
|
|
161
|
+
*/
|
|
162
|
+
export function identityCommand(browser) {
|
|
163
|
+
const setSynopsis = browser?.set?.synopsis?.replace(/^<id> /, "") ?? "[flags] [--dry-run] [--json]";
|
|
164
|
+
return group("identity", "who acts on outside services: service accounts (linear:work) and browser identities (browser:school)", {
|
|
165
|
+
list: {
|
|
166
|
+
summary: "service accounts, browser identities and folder preferences",
|
|
167
|
+
synopsis: "[--json]",
|
|
168
|
+
flags: ["--json"],
|
|
169
|
+
json: LIST_JSON,
|
|
170
|
+
run: list,
|
|
171
|
+
},
|
|
172
|
+
add: {
|
|
173
|
+
summary: "add a service account, or create a browser identity (browser:<id>)",
|
|
174
|
+
synopsis: "<service:label> --profile <p> --tools <pattern>[,...] [--read-tools <pattern>[,...]] [--confirm always|writes|never] | browser:<id> [--timezone <zone>] [--languages <tag,...>] [--health-url <url> --health-text <text>] [--dry-run]",
|
|
175
|
+
args: ["any"],
|
|
176
|
+
flags: [
|
|
177
|
+
"--profile",
|
|
178
|
+
"--tools",
|
|
179
|
+
"--read-tools",
|
|
180
|
+
"--confirm",
|
|
181
|
+
"--service",
|
|
182
|
+
"--description",
|
|
183
|
+
...(browser?.add?.flags ?? ["--dry-run"]),
|
|
184
|
+
],
|
|
185
|
+
run: add,
|
|
186
|
+
},
|
|
187
|
+
show: {
|
|
188
|
+
summary: "a browser identity's settings, session health and who holds it",
|
|
189
|
+
synopsis: "browser:<id> [--json]",
|
|
190
|
+
args: ["identity"],
|
|
191
|
+
flags: ["--json"],
|
|
192
|
+
...(browser?.show?.json ? { json: browser.show.json } : {}),
|
|
193
|
+
run: (a, io) => browserOnly("show", a, io),
|
|
194
|
+
},
|
|
195
|
+
set: {
|
|
196
|
+
summary: "change a browser identity's identity.json: place, languages, health check, tabs, blocking, cache",
|
|
197
|
+
synopsis: `browser:<id> ${setSynopsis}`,
|
|
198
|
+
details: browser?.set?.details ?? `The settings flags come with turno-browser (${NOT_INSTALLED}).`,
|
|
199
|
+
args: ["identity"],
|
|
200
|
+
flags: browser?.set?.flags ?? ["--dry-run", "--json"],
|
|
201
|
+
...(browser?.set?.json ? { json: browser.set.json } : {}),
|
|
202
|
+
run: (a, io) => browserOnly("set", a, io),
|
|
203
|
+
},
|
|
204
|
+
remove: {
|
|
205
|
+
summary: "remove a service account, or delete a browser identity and its logins",
|
|
206
|
+
synopsis: "<id> [--dry-run]",
|
|
207
|
+
args: ["identity"],
|
|
208
|
+
flags: ["--dry-run"],
|
|
209
|
+
run: remove,
|
|
210
|
+
},
|
|
211
|
+
login: {
|
|
212
|
+
summary: "open a browser identity's Chrome to sign in by hand once",
|
|
213
|
+
synopsis: "browser:<id> [--url <url>]",
|
|
214
|
+
args: ["identity"],
|
|
215
|
+
flags: ["--url"],
|
|
216
|
+
run: login,
|
|
217
|
+
},
|
|
218
|
+
prefer: {
|
|
219
|
+
summary: "pick the account of a service for a folder (empty account removes it)",
|
|
220
|
+
synopsis: "<dir> <service>=<account> [--dry-run]",
|
|
221
|
+
args: ["dir"],
|
|
222
|
+
flags: ["--dry-run"],
|
|
223
|
+
run: async (a, io) => accounts.prefer(a, io),
|
|
224
|
+
},
|
|
225
|
+
log: {
|
|
226
|
+
summary: "recent calls to the accounts bridge; --verify checks the log's hash chain",
|
|
227
|
+
synopsis: "[-n N] [--verify] [--json]",
|
|
228
|
+
flags: flagsOf(accounts.LOG_SPEC),
|
|
229
|
+
json: accounts.LOG_JSON,
|
|
230
|
+
run: async (a, io) => accounts.log(a, io),
|
|
231
|
+
},
|
|
232
|
+
}, {
|
|
233
|
+
fallback: "list",
|
|
234
|
+
examples: [
|
|
235
|
+
"turno identity list",
|
|
236
|
+
"turno identity add linear:work --profile work --tools 'mcp__linear__*'",
|
|
237
|
+
"turno identity add browser:school",
|
|
238
|
+
"turno identity login browser:school",
|
|
239
|
+
"turno identity show browser:school",
|
|
240
|
+
"turno identity set browser:school --timezone Europe/Madrid --languages es-ES,es,en",
|
|
241
|
+
"turno identity set browser:school --tabs-max 5 --tabs-park 10m --background-throttling true",
|
|
242
|
+
"turno identity set browser:school --block-trackers true --block-types image,font --cache-max-size 200MB",
|
|
243
|
+
"turno identity set browser:school --settle 500ms --dry-run --json",
|
|
244
|
+
"turno identity set browser:school --humanize adaptive",
|
|
245
|
+
"turno identity set browser:school --no-block --no-cache",
|
|
246
|
+
"turno identity set browser:school --sharing tabs",
|
|
247
|
+
"turno identity prefer ~/code/acme linear=linear:work",
|
|
248
|
+
"turno identity remove linear:work --dry-run",
|
|
249
|
+
"turno identity log --verify",
|
|
186
250
|
],
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
run: (a, io) => browserOnly("show", a, io),
|
|
196
|
-
},
|
|
197
|
-
set: {
|
|
198
|
-
summary: "change a browser identity's identity.json: place, languages, health check, tabs, blocking, cache",
|
|
199
|
-
synopsis: `browser:<id> ${SET_SYNOPSIS}`,
|
|
200
|
-
details: SET_DETAILS,
|
|
201
|
-
args: ["identity"],
|
|
202
|
-
flags: SET_FLAG_NAMES,
|
|
203
|
-
json: SET_JSON,
|
|
204
|
-
run: (a, io) => browserOnly("set", a, io),
|
|
205
|
-
},
|
|
206
|
-
remove: {
|
|
207
|
-
summary: "remove a service account, or delete a browser identity and its logins",
|
|
208
|
-
synopsis: "<id> [--dry-run]",
|
|
209
|
-
args: ["identity"],
|
|
210
|
-
flags: ["--dry-run"],
|
|
211
|
-
run: remove,
|
|
212
|
-
},
|
|
213
|
-
login: {
|
|
214
|
-
summary: "open a browser identity's Chrome to sign in by hand once",
|
|
215
|
-
synopsis: "browser:<id> [--url <url>]",
|
|
216
|
-
args: ["identity"],
|
|
217
|
-
flags: ["--url"],
|
|
218
|
-
run: login,
|
|
219
|
-
},
|
|
220
|
-
prefer: {
|
|
221
|
-
summary: "pick the account of a service for a folder (empty account removes it)",
|
|
222
|
-
synopsis: "<dir> <service>=<account> [--dry-run]",
|
|
223
|
-
args: ["dir"],
|
|
224
|
-
flags: ["--dry-run"],
|
|
225
|
-
run: async (a, io) => accounts.prefer(a, io),
|
|
226
|
-
},
|
|
227
|
-
log: {
|
|
228
|
-
summary: "recent calls to the accounts bridge; --verify checks the log's hash chain",
|
|
229
|
-
synopsis: "[-n N] [--verify] [--json]",
|
|
230
|
-
flags: flagsOf(accounts.LOG_SPEC),
|
|
231
|
-
json: accounts.LOG_JSON,
|
|
232
|
-
run: async (a, io) => accounts.log(a, io),
|
|
233
|
-
},
|
|
234
|
-
}, {
|
|
235
|
-
fallback: "list",
|
|
236
|
-
examples: [
|
|
237
|
-
"turno identity list",
|
|
238
|
-
"turno identity add linear:work --profile work --tools 'mcp__linear__*'",
|
|
239
|
-
"turno identity add browser:school",
|
|
240
|
-
"turno identity login browser:school",
|
|
241
|
-
"turno identity show browser:school",
|
|
242
|
-
"turno identity set browser:school --timezone Europe/Madrid --languages es-ES,es,en",
|
|
243
|
-
"turno identity set browser:school --tabs-max 5 --tabs-park 10m --background-throttling true",
|
|
244
|
-
"turno identity set browser:school --block-trackers true --block-types image,font --cache-max-size 200MB",
|
|
245
|
-
"turno identity set browser:school --settle 500ms --dry-run --json",
|
|
246
|
-
"turno identity set browser:school --humanize adaptive",
|
|
247
|
-
"turno identity set browser:school --no-block --no-cache",
|
|
248
|
-
"turno identity set browser:school --sharing tabs",
|
|
249
|
-
"turno identity prefer ~/code/acme linear=linear:work",
|
|
250
|
-
"turno identity remove linear:work --dry-run",
|
|
251
|
-
"turno identity log --verify",
|
|
252
|
-
],
|
|
253
|
-
});
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
export const command = identityCommand();
|
|
254
|
+
/** The command as the registry loads it: with the help of the installed turno-browser. */
|
|
255
|
+
export async function loadCommand() {
|
|
256
|
+
const mod = await preload();
|
|
257
|
+
return identityCommand(mod ? browserCli(mod).subs : undefined);
|
|
258
|
+
}
|
|
254
259
|
//# sourceMappingURL=identity.js.map
|
|
@@ -8,9 +8,9 @@ import { loadConfig } from "../../core/config.js";
|
|
|
8
8
|
import { loadManifest, servesProfile } from "../../core/manifest.js";
|
|
9
9
|
import { resolveProfile } from "../../core/resolve.js";
|
|
10
10
|
import { packageInfo } from "../../core/version.js";
|
|
11
|
-
import { JSON_FLAG, bool, parseFlags, str } from "../args.js";
|
|
11
|
+
import { JSON_FLAG, bool, callArguments, parseFlags, str } from "../args.js";
|
|
12
12
|
import { Exit } from "../exit.js";
|
|
13
|
-
import { CliError,
|
|
13
|
+
import { CliError, fail } from "../io.js";
|
|
14
14
|
import { emit, jsonOutput } from "../output.js";
|
|
15
15
|
import { duration, style } from "../style.js";
|
|
16
16
|
export const CALL_FLAGS = {
|
|
@@ -33,42 +33,6 @@ export const CALL_JSON = jsonOutput([
|
|
|
33
33
|
"tools",
|
|
34
34
|
"ms",
|
|
35
35
|
]);
|
|
36
|
-
/**
|
|
37
|
-
* The tool arguments: `--args` (a JSON object), then each `--arg key=value` (a string) or
|
|
38
|
-
* `--arg key:=json` (any JSON value) on top of it, as httpie writes them.
|
|
39
|
-
*/
|
|
40
|
-
export function callArguments(json, pairs) {
|
|
41
|
-
let out = {};
|
|
42
|
-
if (json !== undefined) {
|
|
43
|
-
let v;
|
|
44
|
-
try {
|
|
45
|
-
v = JSON.parse(json);
|
|
46
|
-
}
|
|
47
|
-
catch (err) {
|
|
48
|
-
throw new UsageError(`--args is not JSON: ${err.message}`);
|
|
49
|
-
}
|
|
50
|
-
if (typeof v !== "object" || v === null || Array.isArray(v))
|
|
51
|
-
throw new UsageError('--args must be a JSON object, like \'{"query": "x"}\'');
|
|
52
|
-
out = { ...v };
|
|
53
|
-
}
|
|
54
|
-
for (const pair of pairs) {
|
|
55
|
-
const m = /^([^=:]+)(:?=)([\s\S]*)$/.exec(pair);
|
|
56
|
-
if (!m)
|
|
57
|
-
throw new UsageError(`--arg ${pair}: use key=value (a string) or key:=json (a number, true, a list...)`);
|
|
58
|
-
const [, key, op, raw] = m;
|
|
59
|
-
if (op === "=") {
|
|
60
|
-
out[key] = raw;
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
out[key] = JSON.parse(raw);
|
|
65
|
-
}
|
|
66
|
-
catch (err) {
|
|
67
|
-
throw new UsageError(`--arg ${key}:= needs JSON: ${err.message}`);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
return out;
|
|
71
|
-
}
|
|
72
36
|
/** The profile a session in `cwd` would use: --profile, else the folder's Claude Code profile, else the hub's. */
|
|
73
37
|
export function callerProfile(given, env, cwd) {
|
|
74
38
|
if (given)
|
|
@@ -192,19 +192,27 @@ async function runDaemon(args, io) {
|
|
|
192
192
|
let waiting = false;
|
|
193
193
|
for (;;) {
|
|
194
194
|
try {
|
|
195
|
+
let homeGone;
|
|
195
196
|
const d = await startDaemon({
|
|
196
197
|
env: io.env,
|
|
197
198
|
logToStdout: Boolean(process.stdout.isTTY) && !service,
|
|
198
199
|
...(port !== undefined ? { port } : {}),
|
|
200
|
+
onHomeGone: () => homeGone?.(),
|
|
199
201
|
});
|
|
200
202
|
io.err(`mcpd listening on 127.0.0.1:${d.port}`);
|
|
201
203
|
const unguard = installCrashGuards(d.log, () => d.stop());
|
|
202
204
|
await new Promise((resolve) => {
|
|
203
205
|
const stop = () => {
|
|
206
|
+
process.off("SIGINT", stop);
|
|
207
|
+
process.off("SIGTERM", stop);
|
|
204
208
|
void d.stop().then(resolve, resolve);
|
|
205
209
|
};
|
|
206
210
|
process.once("SIGINT", stop);
|
|
207
211
|
process.once("SIGTERM", stop);
|
|
212
|
+
homeGone = () => {
|
|
213
|
+
io.err("turno: mcpd stopped: its home folder was removed");
|
|
214
|
+
stop();
|
|
215
|
+
};
|
|
208
216
|
});
|
|
209
217
|
unguard();
|
|
210
218
|
return 0;
|
package/dist/cli/exit.js
CHANGED
|
@@ -1,65 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
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
|
-
];
|
|
1
|
+
// Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
|
|
2
|
+
export * from "turno-core/cli/exit";
|
|
65
3
|
//# sourceMappingURL=exit.js.map
|
package/dist/cli/group.js
CHANGED
|
@@ -1,62 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/** Usage text of a group: one line per visible subcommand, then an optional footer and examples. */
|
|
4
|
-
function groupUsage(name, subs, footer, examples = []) {
|
|
5
|
-
const rows = Object.entries(subs)
|
|
6
|
-
.filter(([, s]) => !s.hidden)
|
|
7
|
-
.map(([n, s]) => [`turno ${name} ${n}${s.synopsis ? ` ${s.synopsis}` : ""}`, s.summary]);
|
|
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} `));
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* A command made of subcommands: `turno <name> <sub> [args]`. `fallback` runs when no
|
|
17
|
-
* subcommand is given (usually `list` or `show`). `--help` after a subcommand prints its usage,
|
|
18
|
-
* with the group's examples for it.
|
|
19
|
-
*/
|
|
20
|
-
export function group(name, summary, subs, opts = {}) {
|
|
21
|
-
const examples = opts.examples ?? [];
|
|
22
|
-
const usage = groupUsage(name, subs, opts.footer, examples);
|
|
23
|
-
const subcommands = Object.fromEntries(Object.entries(subs)
|
|
24
|
-
.filter(([, s]) => !s.hidden)
|
|
25
|
-
.map(([n, s]) => [n, { ...(s.args ? { args: s.args } : {}), ...(s.flags ? { flags: s.flags } : {}) }]));
|
|
26
|
-
return {
|
|
27
|
-
summary,
|
|
28
|
-
usage,
|
|
29
|
-
subcommands,
|
|
30
|
-
async run(args, io) {
|
|
31
|
-
let [sub, ...rest] = args;
|
|
32
|
-
if (sub === undefined || (sub.startsWith("-") && sub !== "-h" && sub !== "--help" && opts.fallback)) {
|
|
33
|
-
if (!opts.fallback) {
|
|
34
|
-
io.out(usage);
|
|
35
|
-
return 0;
|
|
36
|
-
}
|
|
37
|
-
if (sub !== undefined)
|
|
38
|
-
rest = args;
|
|
39
|
-
sub = opts.fallback;
|
|
40
|
-
}
|
|
41
|
-
if (sub === "-h" || sub === "--help" || sub === "help") {
|
|
42
|
-
io.out(usage);
|
|
43
|
-
return 0;
|
|
44
|
-
}
|
|
45
|
-
const s = subs[sub];
|
|
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)));
|
|
54
|
-
return 0;
|
|
55
|
-
}
|
|
56
|
-
if (answerFields(rest, s.json, io))
|
|
57
|
-
return 0;
|
|
58
|
-
return s.run(rest, io);
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
1
|
+
// Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
|
|
2
|
+
export * from "turno-core/cli/group";
|
|
62
3
|
//# sourceMappingURL=group.js.map
|
package/dist/cli/highlight.js
CHANGED
|
@@ -1,236 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
* diffs) and JSON (`--json` output, agent config snippets). Both work line by line on the text as
|
|
4
|
-
* it is, never reformat it, and only add ANSI color codes: removing them gives back the input.
|
|
5
|
-
* Callers decide whether to color (see `colors` in io.ts).
|
|
6
|
-
*/
|
|
7
|
-
const RESET = "\x1b[0m";
|
|
8
|
-
/** SGR codes. Magenta reads well on dark and light backgrounds, unlike bright yellow or blue. */
|
|
9
|
-
const STYLE = {
|
|
10
|
-
header: "1",
|
|
11
|
-
key: "36",
|
|
12
|
-
string: "32",
|
|
13
|
-
literal: "35",
|
|
14
|
-
comment: "2",
|
|
15
|
-
secret: "33",
|
|
16
|
-
};
|
|
17
|
-
function render(tokens) {
|
|
18
|
-
let out = "";
|
|
19
|
-
for (const t of tokens) {
|
|
20
|
-
if (!t.text)
|
|
21
|
-
continue;
|
|
22
|
-
out += t.kind === "plain" ? t.text : `\x1b[${STYLE[t.kind]}m${t.text}${RESET}`;
|
|
23
|
-
}
|
|
24
|
-
return out;
|
|
25
|
-
}
|
|
26
|
-
/** The trailing comment `turno mcp import` adds to a preview line whose value it masked. */
|
|
27
|
-
const SECRET_MARK = /^#\s*secret, hidden\s*$/;
|
|
28
|
-
// TOML ----------------------------------------------------------------------------------------
|
|
29
|
-
const BARE = "[A-Za-z0-9_-]+";
|
|
30
|
-
const BASIC = '"(?:[^"\\\\]|\\\\.)*"';
|
|
31
|
-
const LITERAL = "'[^']*'";
|
|
32
|
-
const SIMPLE = `(?:${BARE}|${BASIC}|${LITERAL})`;
|
|
33
|
-
const KEY_PATH = `${SIMPLE}(?:[ \\t]*\\.[ \\t]*${SIMPLE})*`;
|
|
34
|
-
/** A key (dotted or quoted) followed by `=`, at the start of what is left of the line. */
|
|
35
|
-
const KEY = new RegExp(`^${KEY_PATH}(?=[ \\t]*=)`);
|
|
36
|
-
/** `[table]` or `[[array.of.tables]]`, possibly indented, with only a comment after it. */
|
|
37
|
-
const HEADER = new RegExp(`^([ \\t]*)(\\[\\[?[ \\t]*${KEY_PATH}[ \\t]*\\]\\]?)(?=[ \\t]*(?:#.*)?$)`);
|
|
38
|
-
/** Numbers, booleans, dates and times, inf and nan: anything bare in a value position. */
|
|
39
|
-
const WORD = /^[A-Za-z0-9_+\-.:]+/;
|
|
40
|
-
export function tomlState() {
|
|
41
|
-
return { stack: [] };
|
|
42
|
-
}
|
|
43
|
-
/** Where a multi-line string that starts at `from` ends (index after the delimiter), or -1. */
|
|
44
|
-
function closeMultiline(line, from, delim) {
|
|
45
|
-
let i = from;
|
|
46
|
-
while (i < line.length) {
|
|
47
|
-
if (delim === '"""' && line[i] === "\\") {
|
|
48
|
-
i += 2;
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (line.startsWith(delim, i)) {
|
|
52
|
-
// A closing delimiter may carry up to two more quotes that belong to the string.
|
|
53
|
-
let end = i + 3;
|
|
54
|
-
while (end < line.length && end - i < 5 && line[end] === delim[0])
|
|
55
|
-
end++;
|
|
56
|
-
return end;
|
|
57
|
-
}
|
|
58
|
-
i++;
|
|
59
|
-
}
|
|
60
|
-
return -1;
|
|
61
|
-
}
|
|
62
|
-
/** Where a single-line string that starts at `from` (on its quote) ends, or the line end. */
|
|
63
|
-
function closeString(line, from) {
|
|
64
|
-
const quote = line[from];
|
|
65
|
-
let i = from + 1;
|
|
66
|
-
while (i < line.length) {
|
|
67
|
-
if (quote === '"' && line[i] === "\\") {
|
|
68
|
-
i += 2;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
if (line[i] === quote)
|
|
72
|
-
return i + 1;
|
|
73
|
-
i++;
|
|
74
|
-
}
|
|
75
|
-
return line.length;
|
|
76
|
-
}
|
|
77
|
-
function tomlTokens(line, state) {
|
|
78
|
-
const tokens = [];
|
|
79
|
-
const push = (text, kind) => tokens.push({ text, kind });
|
|
80
|
-
let i = 0;
|
|
81
|
-
if (state.multiline) {
|
|
82
|
-
const end = closeMultiline(line, 0, state.multiline);
|
|
83
|
-
if (end < 0) {
|
|
84
|
-
push(line, "string");
|
|
85
|
-
return tokens;
|
|
86
|
-
}
|
|
87
|
-
push(line.slice(0, end), "string");
|
|
88
|
-
state.multiline = undefined;
|
|
89
|
-
i = end;
|
|
90
|
-
}
|
|
91
|
-
else if (!state.stack.length) {
|
|
92
|
-
const h = HEADER.exec(line);
|
|
93
|
-
if (h) {
|
|
94
|
-
push(h[1], "plain");
|
|
95
|
-
push(h[2], "header");
|
|
96
|
-
i = h[0].length;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
// A key can start the line (outside arrays) and follow `{` or `,` inside an inline table.
|
|
100
|
-
let expectKey = i === 0 && !state.stack.length && !tokens.length;
|
|
101
|
-
while (i < line.length) {
|
|
102
|
-
const rest = line.slice(i);
|
|
103
|
-
const ch = line[i];
|
|
104
|
-
if (ch === " " || ch === "\t") {
|
|
105
|
-
const ws = /^[ \t]+/.exec(rest)[0];
|
|
106
|
-
push(ws, "plain");
|
|
107
|
-
i += ws.length;
|
|
108
|
-
continue;
|
|
109
|
-
}
|
|
110
|
-
if (expectKey) {
|
|
111
|
-
expectKey = false;
|
|
112
|
-
const k = KEY.exec(rest);
|
|
113
|
-
if (k) {
|
|
114
|
-
push(k[0], "key");
|
|
115
|
-
i += k[0].length;
|
|
116
|
-
continue;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
if (ch === "#") {
|
|
120
|
-
push(rest, "comment");
|
|
121
|
-
break;
|
|
122
|
-
}
|
|
123
|
-
if (rest.startsWith('"""') || rest.startsWith("'''")) {
|
|
124
|
-
const delim = rest.slice(0, 3);
|
|
125
|
-
const end = closeMultiline(line, i + 3, delim);
|
|
126
|
-
if (end < 0) {
|
|
127
|
-
push(rest, "string");
|
|
128
|
-
state.multiline = delim;
|
|
129
|
-
break;
|
|
130
|
-
}
|
|
131
|
-
push(line.slice(i, end), "string");
|
|
132
|
-
i = end;
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
if (ch === '"' || ch === "'") {
|
|
136
|
-
const end = closeString(line, i);
|
|
137
|
-
push(line.slice(i, end), "string");
|
|
138
|
-
i = end;
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
if (ch === "[" || ch === "{") {
|
|
142
|
-
state.stack.push(ch);
|
|
143
|
-
push(ch, "plain");
|
|
144
|
-
expectKey = ch === "{";
|
|
145
|
-
i++;
|
|
146
|
-
continue;
|
|
147
|
-
}
|
|
148
|
-
if (ch === "]" || ch === "}") {
|
|
149
|
-
if (state.stack.at(-1) === (ch === "]" ? "[" : "{"))
|
|
150
|
-
state.stack.pop();
|
|
151
|
-
push(ch, "plain");
|
|
152
|
-
i++;
|
|
153
|
-
continue;
|
|
154
|
-
}
|
|
155
|
-
if (ch === ",") {
|
|
156
|
-
expectKey = state.stack.at(-1) === "{";
|
|
157
|
-
push(ch, "plain");
|
|
158
|
-
i++;
|
|
159
|
-
continue;
|
|
160
|
-
}
|
|
161
|
-
const w = WORD.exec(rest);
|
|
162
|
-
if (w) {
|
|
163
|
-
push(w[0], /^(?:true|false|[+-]?(?:inf|nan)|[+-]?[0-9][A-Za-z0-9_+\-.:]*)$/.test(w[0]) ? "literal" : "plain");
|
|
164
|
-
i += w[0].length;
|
|
165
|
-
continue;
|
|
166
|
-
}
|
|
167
|
-
push(ch, "plain");
|
|
168
|
-
i++;
|
|
169
|
-
}
|
|
170
|
-
return markSecrets(tokens);
|
|
171
|
-
}
|
|
172
|
-
/** On a line marked `# secret, hidden`, the masked value (and the mark) stand out. */
|
|
173
|
-
function markSecrets(tokens) {
|
|
174
|
-
const last = tokens.at(-1);
|
|
175
|
-
if (last?.kind !== "comment" || !SECRET_MARK.test(last.text))
|
|
176
|
-
return tokens;
|
|
177
|
-
const strings = tokens.filter((t) => t.kind === "string");
|
|
178
|
-
const masked = strings.filter((t) => t.text.includes("****"));
|
|
179
|
-
for (const t of masked.length ? masked : strings)
|
|
180
|
-
t.kind = "secret";
|
|
181
|
-
last.kind = "secret";
|
|
182
|
-
return tokens;
|
|
183
|
-
}
|
|
184
|
-
/** One TOML line, colored; `state` carries open arrays and strings to the next line. */
|
|
185
|
-
export function highlightTomlLine(line, state) {
|
|
186
|
-
return render(tomlTokens(line, state));
|
|
187
|
-
}
|
|
188
|
-
/** A TOML text, colored line by line. */
|
|
189
|
-
export function highlightToml(text) {
|
|
190
|
-
const state = tomlState();
|
|
191
|
-
return text
|
|
192
|
-
.split("\n")
|
|
193
|
-
.map((l) => highlightTomlLine(l, state))
|
|
194
|
-
.join("\n");
|
|
195
|
-
}
|
|
196
|
-
// JSON ----------------------------------------------------------------------------------------
|
|
197
|
-
const JSON_LITERAL = /^(?:-?(?:0|[1-9][0-9]*)(?:\.[0-9]+)?(?:[eE][+-]?[0-9]+)?|true|false|null)/;
|
|
198
|
-
/** A JSON text, colored: keys, strings, and numbers with true, false and null. */
|
|
199
|
-
export function highlightJson(text) {
|
|
200
|
-
const tokens = [];
|
|
201
|
-
let i = 0;
|
|
202
|
-
let plain = "";
|
|
203
|
-
const flush = () => {
|
|
204
|
-
if (plain)
|
|
205
|
-
tokens.push({ text: plain, kind: "plain" });
|
|
206
|
-
plain = "";
|
|
207
|
-
};
|
|
208
|
-
while (i < text.length) {
|
|
209
|
-
const ch = text[i];
|
|
210
|
-
if (ch === '"') {
|
|
211
|
-
let end = i + 1;
|
|
212
|
-
while (end < text.length && text[end] !== '"' && text[end] !== "\n")
|
|
213
|
-
end += text[end] === "\\" ? 2 : 1;
|
|
214
|
-
if (text[end] === '"')
|
|
215
|
-
end++;
|
|
216
|
-
const after = /^\s*/.exec(text.slice(end))[0];
|
|
217
|
-
flush();
|
|
218
|
-
tokens.push({ text: text.slice(i, end), kind: text[end + after.length] === ":" ? "key" : "string" });
|
|
219
|
-
i = end;
|
|
220
|
-
continue;
|
|
221
|
-
}
|
|
222
|
-
const prev = text[i - 1];
|
|
223
|
-
const lit = prev === undefined || !/[A-Za-z0-9_.]/.test(prev) ? JSON_LITERAL.exec(text.slice(i)) : null;
|
|
224
|
-
if (lit) {
|
|
225
|
-
flush();
|
|
226
|
-
tokens.push({ text: lit[0], kind: "literal" });
|
|
227
|
-
i += lit[0].length;
|
|
228
|
-
continue;
|
|
229
|
-
}
|
|
230
|
-
plain += ch;
|
|
231
|
-
i++;
|
|
232
|
-
}
|
|
233
|
-
flush();
|
|
234
|
-
return render(tokens);
|
|
235
|
-
}
|
|
1
|
+
// Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
|
|
2
|
+
export * from "turno-core/cli/highlight";
|
|
236
3
|
//# sourceMappingURL=highlight.js.map
|