turno-cli 0.2.0 → 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 +148 -0
- package/README.md +127 -39
- package/dist/accounts/audit.js +27 -15
- package/dist/accounts/builtin.js +35 -7
- package/dist/accounts/delegate.js +30 -7
- package/dist/accounts/policy.js +4 -2
- package/dist/accounts/registry.js +3 -1
- package/dist/agents/adapter.js +22 -0
- package/dist/agents/claude.js +54 -3
- package/dist/agents/codex.js +94 -6
- package/dist/agents/copilot.js +19 -2
- package/dist/agents/cursor.js +19 -2
- package/dist/agents/index.js +1 -1
- package/dist/agents/snippets.js +37 -10
- package/dist/cli/args.js +32 -15
- package/dist/cli/commands/accounts.js +29 -7
- package/dist/cli/commands/auto.js +50 -12
- package/dist/cli/commands/browser-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 +159 -59
- package/dist/cli/commands/complete.js +13 -3
- package/dist/cli/commands/completion.js +4 -0
- package/dist/cli/commands/config.js +90 -13
- package/dist/cli/commands/demo.js +36 -7
- package/dist/cli/commands/doctor.js +170 -36
- package/dist/cli/commands/identity.js +99 -12
- package/dist/cli/commands/init.js +42 -10
- package/dist/cli/commands/limit.js +65 -9
- package/dist/cli/commands/mcp-call.js +240 -0
- package/dist/cli/commands/mcp-oauth.js +33 -6
- package/dist/cli/commands/mcp-observe.js +128 -23
- package/dist/cli/commands/mcp-share.js +201 -0
- package/dist/cli/commands/mcp.js +203 -42
- package/dist/cli/commands/mcpd.js +76 -12
- package/dist/cli/commands/open.js +26 -3
- package/dist/cli/commands/profile.js +212 -30
- package/dist/cli/commands/resolve.js +8 -1
- package/dist/cli/commands/run.js +24 -4
- package/dist/cli/commands/secret.js +23 -38
- package/dist/cli/commands/session.js +16 -5
- package/dist/cli/commands/sessions.js +7 -1
- package/dist/cli/commands/setup.js +83 -11
- package/dist/cli/commands/status.js +67 -15
- package/dist/cli/commands/statusline.js +7 -2
- package/dist/cli/commands/ui.js +17 -5
- package/dist/cli/commands/undo.js +39 -7
- package/dist/cli/commands/uninstall.js +24 -5
- package/dist/cli/commands/upgrade.js +113 -76
- package/dist/cli/commands/usage.js +11 -10
- package/dist/cli/commands/version.js +20 -8
- package/dist/cli/commands/which.js +5 -3
- package/dist/cli/diagnostics.js +184 -0
- package/dist/cli/exit.js +65 -0
- package/dist/cli/group.js +20 -8
- package/dist/cli/help.js +6 -1
- package/dist/cli/hints.js +30 -0
- package/dist/cli/io.js +24 -8
- package/dist/cli/launch.js +31 -2
- package/dist/cli/launchers.js +25 -10
- package/dist/cli/main.js +52 -18
- package/dist/cli/optional.js +144 -0
- package/dist/cli/output.js +123 -0
- package/dist/cli/picker.js +17 -5
- package/dist/cli/registry.js +20 -2
- package/dist/cli/safe.js +87 -0
- package/dist/cli/secret-input.js +63 -0
- package/dist/cli/security.js +31 -9
- package/dist/cli/style.js +35 -5
- package/dist/cli/topics.js +142 -0
- package/dist/core/config.js +39 -3
- package/dist/core/fsutil.js +2 -10
- package/dist/core/journal.js +19 -11
- package/dist/core/manifest.js +28 -1
- package/dist/core/paths.js +6 -112
- package/dist/core/profiles.js +28 -8
- package/dist/core/resolve.js +13 -3
- package/dist/core/secrets.js +4 -154
- package/dist/core/state-file.js +107 -0
- package/dist/core/update.js +14 -11
- package/dist/core/version.js +57 -10
- package/dist/demo/server.js +10 -2
- package/dist/mcpd/cache.js +6 -7
- package/dist/mcpd/calllog.js +10 -9
- package/dist/mcpd/client-names.js +8 -13
- package/dist/mcpd/connectors.js +42 -3
- package/dist/mcpd/daemon.js +29 -8
- package/dist/mcpd/folder-sets.js +5 -2
- package/dist/mcpd/gateway.js +57 -29
- package/dist/mcpd/health.js +69 -25
- package/dist/mcpd/importer.js +106 -9
- package/dist/mcpd/instances.js +59 -31
- package/dist/mcpd/jsonrpc.js +3 -1
- package/dist/mcpd/middleware.js +144 -0
- package/dist/mcpd/modern.js +57 -19
- package/dist/mcpd/oauth.js +71 -17
- package/dist/mcpd/peerpid.js +15 -3
- package/dist/mcpd/pressure.js +4 -1
- package/dist/mcpd/rss.js +34 -19
- package/dist/mcpd/service.js +28 -4
- package/dist/mcpd/share.js +217 -0
- package/dist/mcpd/state.js +16 -16
- package/dist/mcpd/sync.js +22 -12
- package/dist/mcpd/systemd.js +4 -1
- package/dist/mcpd/tokens.js +4 -8
- package/dist/mcpd/upstream.js +12 -5
- package/dist/statusline/cost.js +17 -4
- package/dist/statusline/input.js +15 -3
- package/dist/ui/fonts.js +1 -1
- package/dist/ui/settings.js +6 -1
- package/npm-shrinkwrap.json +12 -3
- package/package.json +7 -6
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { highlightJson } from "./highlight.js";
|
|
2
|
+
import { UsageError, colors } from "./io.js";
|
|
3
|
+
/** The key every JSON object turno prints carries. */
|
|
4
|
+
export const SCHEMA_KEY = "schemaVersion";
|
|
5
|
+
export function jsonOutput(fields, version = 1) {
|
|
6
|
+
return { version, fields };
|
|
7
|
+
}
|
|
8
|
+
/** The word after `--json=` that lists the fields instead of printing anything. */
|
|
9
|
+
const FIELDS_WORD = "fields";
|
|
10
|
+
/** A usage error about `--json` fields: main adds the list to the JSON error. */
|
|
11
|
+
export class JsonFieldError extends UsageError {
|
|
12
|
+
fields;
|
|
13
|
+
constructor(message, fields) {
|
|
14
|
+
super(message);
|
|
15
|
+
this.fields = fields;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The value of `--json=<value>` among a command's own arguments (not after `--`), undefined
|
|
20
|
+
* without one. A bare `--json` gives "".
|
|
21
|
+
*/
|
|
22
|
+
export function jsonArg(args) {
|
|
23
|
+
let found;
|
|
24
|
+
for (const a of args) {
|
|
25
|
+
if (a === "--")
|
|
26
|
+
break;
|
|
27
|
+
if (a === "--json")
|
|
28
|
+
found ??= "";
|
|
29
|
+
else if (a.startsWith("--json="))
|
|
30
|
+
found = a.slice("--json=".length);
|
|
31
|
+
}
|
|
32
|
+
return found;
|
|
33
|
+
}
|
|
34
|
+
/** The field list `--json=fields` prints, one per line after a header, like gh. */
|
|
35
|
+
function fieldLines(out) {
|
|
36
|
+
return [
|
|
37
|
+
"Fields for --json=<field,...> (schemaVersion is always there):",
|
|
38
|
+
...[...out.fields].sort().map((f) => ` ${f}`),
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The fields `--json=<value>` selects: undefined for all of them (bare --json), "list" for
|
|
43
|
+
* --json=fields. An unknown field is a usage error that lists the known ones.
|
|
44
|
+
*/
|
|
45
|
+
export function selectFields(value, out) {
|
|
46
|
+
if (value === undefined || value === "")
|
|
47
|
+
return undefined;
|
|
48
|
+
if (value === FIELDS_WORD)
|
|
49
|
+
return "list";
|
|
50
|
+
const asked = value
|
|
51
|
+
.split(",")
|
|
52
|
+
.map((f) => f.trim())
|
|
53
|
+
.filter(Boolean);
|
|
54
|
+
const unknown = asked.filter((f) => f !== SCHEMA_KEY && !out.fields.includes(f));
|
|
55
|
+
if (unknown.length) {
|
|
56
|
+
const known = [...out.fields].sort();
|
|
57
|
+
throw new JsonFieldError(`unknown JSON field${unknown.length > 1 ? "s" : ""} ${unknown.map((f) => `"${f}"`).join(", ")}; available: ${known.join(", ")}`, known);
|
|
58
|
+
}
|
|
59
|
+
return asked;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Before a command runs: answer `--json=fields` (true: the caller returns 0) and refuse an
|
|
63
|
+
* unknown field (a usage error), so neither waits for the command's work.
|
|
64
|
+
*/
|
|
65
|
+
export function answerFields(args, out, io) {
|
|
66
|
+
if (!out)
|
|
67
|
+
return false;
|
|
68
|
+
const picked = selectFields(jsonArg(args), out);
|
|
69
|
+
if (picked !== "list")
|
|
70
|
+
return false;
|
|
71
|
+
for (const l of fieldLines(out))
|
|
72
|
+
io.out(l);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
function stamp(value, out, fields) {
|
|
76
|
+
if (typeof value !== "object" || value === null || Array.isArray(value))
|
|
77
|
+
return value;
|
|
78
|
+
const o = value;
|
|
79
|
+
const kept = fields ? Object.fromEntries(fields.filter((f) => f !== SCHEMA_KEY && f in o).map((f) => [f, o[f]])) : o;
|
|
80
|
+
return { [SCHEMA_KEY]: out.version, ...kept };
|
|
81
|
+
}
|
|
82
|
+
/** The value as printed: schemaVersion on the object (or on each element of a list), fields picked. */
|
|
83
|
+
export function shape(value, out, json) {
|
|
84
|
+
const picked = selectFields(json, out);
|
|
85
|
+
const fields = picked === "list" ? undefined : picked;
|
|
86
|
+
return Array.isArray(value) ? value.map((v) => stamp(v, out, fields)) : stamp(value, out, fields);
|
|
87
|
+
}
|
|
88
|
+
const jsonValue = (p) => (typeof p === "object" ? p.json : p);
|
|
89
|
+
/**
|
|
90
|
+
* Print a command's JSON: indented, colored on a terminal only (never in a pipe, even with
|
|
91
|
+
* FORCE_COLOR, since programs read it). `--json=fields` prints the field list instead.
|
|
92
|
+
*/
|
|
93
|
+
export function emit(io, p, out, value) {
|
|
94
|
+
if (selectFields(jsonValue(p), out) === "list") {
|
|
95
|
+
for (const l of fieldLines(out))
|
|
96
|
+
io.out(l);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
const text = JSON.stringify(shape(value, out, jsonValue(p)), null, 2);
|
|
100
|
+
io.out(io.isTty && colors(io) ? highlightJson(text) : text);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* `turno config get --json`: a config value as config.toml holds it, with no schemaVersion (its
|
|
104
|
+
* shape is config.toml's, documented in docs/config.md). The one exception to the contract.
|
|
105
|
+
*/
|
|
106
|
+
export function emitConfigValue(io, value) {
|
|
107
|
+
const text = JSON.stringify(value, null, 2);
|
|
108
|
+
io.out(io.isTty && colors(io) ? highlightJson(text) : text);
|
|
109
|
+
}
|
|
110
|
+
/** Print one record as one compact line (NDJSON): `--watch --json`, `mcp log --json`, `resolve --json`. */
|
|
111
|
+
export function emitLine(io, p, out, value) {
|
|
112
|
+
io.out(JSON.stringify(shape(value, out, jsonValue(p))));
|
|
113
|
+
}
|
|
114
|
+
/** Each element of a list as its own line (NDJSON). */
|
|
115
|
+
export function emitLines(io, p, out, values) {
|
|
116
|
+
for (const v of values)
|
|
117
|
+
emitLine(io, p, out, v);
|
|
118
|
+
}
|
|
119
|
+
/** The JSON error object of the contract (`schemaVersion` 1), for stderr under --json. */
|
|
120
|
+
export function jsonError(message, exitCode, code, extra = {}) {
|
|
121
|
+
return JSON.stringify({ [SCHEMA_KEY]: 1, error: { code, exitCode, message, ...extra } });
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=output.js.map
|
package/dist/cli/picker.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Choose a profile when a command needs one and the argument is missing
|
|
2
|
+
* Choose a profile when a command needs one and the argument is missing. A small
|
|
3
3
|
* picker with no dependencies: arrow keys or j/k move, typing filters, Enter chooses, Esc or
|
|
4
4
|
* Ctrl-C cancels. It draws on stderr and reads stdin in raw mode, only when both are terminals;
|
|
5
5
|
* the terminal is restored on every way out (a choice, a cancel, an error, a signal).
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
* The key handling is a pure state machine (`parseKeys`, `reduce`), so tests drive it without a
|
|
11
11
|
* terminal. Loaded lazily by the commands that use it.
|
|
12
12
|
*/
|
|
13
|
+
import { Exit } from "./exit.js";
|
|
13
14
|
import { DEFAULT_AGENT, adapter } from "../agents/index.js";
|
|
14
15
|
import { loadConfig } from "../core/config.js";
|
|
15
16
|
import { exhaustedUntil } from "../core/exhausted.js";
|
|
@@ -31,7 +32,11 @@ export function matching(state) {
|
|
|
31
32
|
}
|
|
32
33
|
/** The first state: the cursor on `initial` when it is one of the items. */
|
|
33
34
|
export function initialState(items, initial) {
|
|
34
|
-
return {
|
|
35
|
+
return {
|
|
36
|
+
items,
|
|
37
|
+
query: "",
|
|
38
|
+
cursor: Math.max(0, items.findIndex((i) => i.value === initial)),
|
|
39
|
+
};
|
|
35
40
|
}
|
|
36
41
|
/** The item under the cursor, if any matches. */
|
|
37
42
|
export function selected(state) {
|
|
@@ -172,7 +177,9 @@ export function renderPicker(state, s, opts) {
|
|
|
172
177
|
const hidden = shown.length - page.length;
|
|
173
178
|
if (hidden > 0)
|
|
174
179
|
out.push(` ${s.muted(`${hidden} more`)}`);
|
|
175
|
-
const hint = ascii
|
|
180
|
+
const hint = ascii
|
|
181
|
+
? "up/down or j/k move, type to filter, enter choose, esc cancel"
|
|
182
|
+
: "↑↓ or j/k move · type to filter · enter choose · esc cancel";
|
|
176
183
|
out.push(` ${s.muted(hint)}`);
|
|
177
184
|
return out;
|
|
178
185
|
}
|
|
@@ -399,7 +406,12 @@ export async function pickProfile(io, opts) {
|
|
|
399
406
|
? [
|
|
400
407
|
{
|
|
401
408
|
value: "auto",
|
|
402
|
-
cells: [
|
|
409
|
+
cells: [
|
|
410
|
+
autoName(s),
|
|
411
|
+
adapter(DEFAULT_AGENT).label,
|
|
412
|
+
s.muted(auto.reason),
|
|
413
|
+
auto.note ? s.warn(`${auto.assigned} ${auto.note}`) : "",
|
|
414
|
+
],
|
|
403
415
|
search: `auto ${autoTo}`,
|
|
404
416
|
},
|
|
405
417
|
]
|
|
@@ -420,7 +432,7 @@ export async function pickProfile(io, opts) {
|
|
|
420
432
|
value = await askByNumber(io, s, await withAccounts, opts.title, initial);
|
|
421
433
|
}
|
|
422
434
|
if (value === undefined)
|
|
423
|
-
throw new CliError("cancelled; nothing changed",
|
|
435
|
+
throw new CliError("cancelled; nothing changed", Exit.cancelled);
|
|
424
436
|
return value;
|
|
425
437
|
}
|
|
426
438
|
/**
|
package/dist/cli/registry.js
CHANGED
|
@@ -8,7 +8,10 @@ export const SECTIONS = [
|
|
|
8
8
|
{ title: "Accounts", commands: ["profile", "limit", "session", "open"] },
|
|
9
9
|
{ title: "MCP servers and outside services", commands: ["mcp", "identity", "secret"] },
|
|
10
10
|
{ title: "Look", commands: ["ui"] },
|
|
11
|
-
{
|
|
11
|
+
{
|
|
12
|
+
title: "Maintenance",
|
|
13
|
+
commands: ["status", "doctor", "config", "undo", "upgrade", "uninstall", "version", "completion"],
|
|
14
|
+
},
|
|
12
15
|
{ title: "Developer tools", commands: ["browser"] },
|
|
13
16
|
];
|
|
14
17
|
/**
|
|
@@ -38,6 +41,8 @@ export const HELP_SUMMARY = {
|
|
|
38
41
|
completion: "shell completion for commands, profiles, identities and config keys",
|
|
39
42
|
browser: "developer tool: compare browser engines (needs turno-browser)",
|
|
40
43
|
};
|
|
44
|
+
/** `turno help <topic>` (cli/topics.ts), listed here so `turno help` loads nothing. */
|
|
45
|
+
export const HELP_TOPICS = ["environment", "exit-codes", "json"];
|
|
41
46
|
export const COMMANDS = {
|
|
42
47
|
init: () => import("./commands/init.js"),
|
|
43
48
|
demo: () => import("./commands/demo.js"),
|
|
@@ -98,7 +103,20 @@ const ALIAS_FLAGS = {
|
|
|
98
103
|
agotada: { hasta: "until" },
|
|
99
104
|
};
|
|
100
105
|
/** Commands that run on every prompt or launch: no update notice, no extra work. */
|
|
101
|
-
export const QUIET = new Set([
|
|
106
|
+
export const QUIET = new Set([
|
|
107
|
+
"run",
|
|
108
|
+
"auto",
|
|
109
|
+
"open",
|
|
110
|
+
"statusline",
|
|
111
|
+
"hook",
|
|
112
|
+
"resolve",
|
|
113
|
+
"mcpd",
|
|
114
|
+
"__complete",
|
|
115
|
+
"__update-check",
|
|
116
|
+
"completion",
|
|
117
|
+
"upgrade",
|
|
118
|
+
"version",
|
|
119
|
+
]);
|
|
102
120
|
/** Expand an alias: the command name and the arguments it stands for. */
|
|
103
121
|
export function expand(first, rest) {
|
|
104
122
|
const alias = ALIASES[first];
|
package/dist/cli/safe.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Safe mode: `turno run <profile> --no-gateway`, `turno auto --no-gateway` or TURNO_SAFE=1.
|
|
3
|
+
* The agent opens with the profile's account, as its launcher would set it up, but without the
|
|
4
|
+
* gateway: no mcpd entries, no gateway token, no session headers, and (Claude Code) no status
|
|
5
|
+
* line. When a problem goes away in safe mode, it comes from turno's gateway or status line;
|
|
6
|
+
* when it stays, it does not. How each agent leaves the entries out is in docs/agents.md.
|
|
7
|
+
*/
|
|
8
|
+
import { existsSync, writeFileSync } from "node:fs";
|
|
9
|
+
import { join } from "node:path";
|
|
10
|
+
import { adapter, agentProfileDir } from "../agents/index.js";
|
|
11
|
+
import { ensurePrivateDir, paths, tildify } from "../core/paths.js";
|
|
12
|
+
import { Exit } from "./exit.js";
|
|
13
|
+
import { CliError } from "./io.js";
|
|
14
|
+
import { execLauncher } from "./launch.js";
|
|
15
|
+
import { findOnPath, launcherBrowser } from "./launchers.js";
|
|
16
|
+
/** The flag that asks for safe mode, taken out of the agent's arguments. */
|
|
17
|
+
const SAFE_FLAG = "--no-gateway";
|
|
18
|
+
/** `--no-gateway` out of the arguments (only turno's, before a `--`), and whether it was there. */
|
|
19
|
+
export function takeSafeFlag(args) {
|
|
20
|
+
const end = args.indexOf("--");
|
|
21
|
+
const head = end < 0 ? [...args] : args.slice(0, end);
|
|
22
|
+
const tail = end < 0 ? [] : args.slice(end);
|
|
23
|
+
const kept = head.filter((a) => a !== SAFE_FLAG);
|
|
24
|
+
return { args: [...kept, ...tail], safe: kept.length !== head.length };
|
|
25
|
+
}
|
|
26
|
+
/** Variables a launcher sets for the gateway, which safe mode leaves out. */
|
|
27
|
+
const GATEWAY_VARS = ["TURNO_MCPD_TOKEN", "TURNO_SESSION_PID", "TURNO_SESSION_CWD_B64"];
|
|
28
|
+
/**
|
|
29
|
+
* The safe-mode arguments of an agent for the MCP file it reads (a profile's or the hub's): the
|
|
30
|
+
* adapter's `safeMode` (src/agents), with a private scratch file under the state folder.
|
|
31
|
+
*/
|
|
32
|
+
export function safePlan(agent, file, cwd, env, key) {
|
|
33
|
+
const dir = ensurePrivateDir(join(paths(env).state, "safe"), env);
|
|
34
|
+
return adapter(agent).safeMode({ file, cwd, env, scratch: join(dir, `${key}.mcp.json`) });
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The environment a launcher gives `profile`, without the gateway variables, and with
|
|
38
|
+
* TURNO_SAFE=1 so a turno the agent runs stays in safe mode. Without a profile: the plain agent.
|
|
39
|
+
*/
|
|
40
|
+
export function safeEnv(agent, profile, env, platform = process.platform) {
|
|
41
|
+
const a = adapter(agent);
|
|
42
|
+
const out = { ...env, TURNO_SAFE: "1" };
|
|
43
|
+
for (const v of GATEWAY_VARS)
|
|
44
|
+
delete out[v];
|
|
45
|
+
if (!profile)
|
|
46
|
+
return out;
|
|
47
|
+
out[a.homeEnv] = agentProfileDir(profile, agent, env);
|
|
48
|
+
out.TURNO_PROFILE = profile;
|
|
49
|
+
if (!a.classicLauncher)
|
|
50
|
+
out.TURNO_AGENT = agent;
|
|
51
|
+
Object.assign(out, a.launcherEnv);
|
|
52
|
+
const browser = launcherBrowser(env, platform);
|
|
53
|
+
if (browser)
|
|
54
|
+
out.BROWSER = browser;
|
|
55
|
+
return out;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Open `profile` (or the plain agent) in safe mode: the agent's own command with the profile's
|
|
59
|
+
* environment, never the launcher, which would export the gateway token. The run record is
|
|
60
|
+
* written as the launcher writes it, so turno sessions still knows the account.
|
|
61
|
+
*/
|
|
62
|
+
export async function launchSafe(agent, profile, args, io, cwd = process.cwd()) {
|
|
63
|
+
const a = adapter(agent);
|
|
64
|
+
const bin = findOnPath(a.command, io.env);
|
|
65
|
+
if (!bin)
|
|
66
|
+
throw new CliError(`${a.command} is not installed (${a.install})`, Exit.notInstalled);
|
|
67
|
+
if (profile && !existsSync(agentProfileDir(profile, agent, io.env))) {
|
|
68
|
+
throw new CliError(`profile ${profile} has no folder (${tildify(agentProfileDir(profile, agent, io.env), io.env)}). Run: turno profile repair ${profile}`);
|
|
69
|
+
}
|
|
70
|
+
const configFile = profile ? a.mcp.file(agentProfileDir(profile, agent, io.env), io.env) : a.mcp.hubFile(io.env);
|
|
71
|
+
const plan = safePlan(agent, configFile, cwd, io.env, profile ?? `plain-${agent}`);
|
|
72
|
+
io.err(`turno: safe mode, ${profile ? `profile ${profile}` : `plain ${a.command}`} without the gateway (${SAFE_FLAG} or TURNO_SAFE=1)`);
|
|
73
|
+
for (const n of plan.notes)
|
|
74
|
+
io.err(` ${n}`);
|
|
75
|
+
// execve keeps this PID, as the launcher's exec does; a child process would have another.
|
|
76
|
+
if (profile && typeof process.execve === "function") {
|
|
77
|
+
try {
|
|
78
|
+
const run = ensurePrivateDir(paths(io.env).runDir, io.env);
|
|
79
|
+
writeFileSync(join(run, String(process.pid)), `${profile}\n`);
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
/* turno sessions shows it as unknown */
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
return execLauncher(bin, [...plan.args, ...args], safeEnv(agent, profile, io.env));
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=safe.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reading a secret from a person or a pipe, for `turno secret set` and `turno browser vault add`.
|
|
3
|
+
* On a terminal the input is hidden (raw mode, nothing echoed); otherwise stdin is read to the
|
|
4
|
+
* end. Neither path ever prints what was read.
|
|
5
|
+
*/
|
|
6
|
+
/** Whether stdin is a terminal a person types into. */
|
|
7
|
+
export function stdinIsTty() {
|
|
8
|
+
return Boolean(process.stdin.isTTY);
|
|
9
|
+
}
|
|
10
|
+
/** A line typed on the terminal without echo; Ctrl-C exits 130. */
|
|
11
|
+
export function readHidden(prompt) {
|
|
12
|
+
process.stderr.write(prompt);
|
|
13
|
+
return new Promise((resolve) => {
|
|
14
|
+
const stdin = process.stdin;
|
|
15
|
+
let value = "";
|
|
16
|
+
stdin.setRawMode(true);
|
|
17
|
+
stdin.resume();
|
|
18
|
+
stdin.setEncoding("utf8");
|
|
19
|
+
const onData = (chunk) => {
|
|
20
|
+
for (const ch of chunk) {
|
|
21
|
+
if (ch === "\r" || ch === "\n" || ch === "\u0004") {
|
|
22
|
+
stdin.setRawMode(false);
|
|
23
|
+
stdin.pause();
|
|
24
|
+
stdin.off("data", onData);
|
|
25
|
+
process.stderr.write("\n");
|
|
26
|
+
resolve(value);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (ch === "\u0003") {
|
|
30
|
+
stdin.setRawMode(false);
|
|
31
|
+
process.stderr.write("\n");
|
|
32
|
+
process.exit(130);
|
|
33
|
+
}
|
|
34
|
+
if (ch === "\u007f")
|
|
35
|
+
value = value.slice(0, -1);
|
|
36
|
+
else
|
|
37
|
+
value += ch;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
stdin.on("data", onData);
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/** A line typed on the terminal, shown as typed (a username). */
|
|
44
|
+
export async function readVisible(prompt) {
|
|
45
|
+
const { createInterface } = await import("node:readline/promises");
|
|
46
|
+
const rl = createInterface({ input: process.stdin, output: process.stderr });
|
|
47
|
+
try {
|
|
48
|
+
return (await rl.question(prompt)).trim();
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
rl.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** All of stdin, without one trailing line break. */
|
|
55
|
+
export async function readStdinText() {
|
|
56
|
+
const chunks = [];
|
|
57
|
+
for await (const c of process.stdin)
|
|
58
|
+
chunks.push(c);
|
|
59
|
+
return Buffer.concat(chunks)
|
|
60
|
+
.toString("utf8")
|
|
61
|
+
.replace(/\r?\n$/, "");
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=secret-input.js.map
|
package/dist/cli/security.js
CHANGED
|
@@ -11,7 +11,7 @@ import { secretStore } from "../core/secrets.js";
|
|
|
11
11
|
import { profileTokenFile, tokenProfile } from "../mcpd/tokens.js";
|
|
12
12
|
import { isObject } from "../core/fsutil.js";
|
|
13
13
|
/**
|
|
14
|
-
* `turno doctor --security
|
|
14
|
+
* `turno doctor --security`: who can read turno's files, who holds the mcpd port,
|
|
15
15
|
* literal secrets left in configs and backups, MCP servers that run whatever version is newest,
|
|
16
16
|
* the age of the gateway token, and the audit log's hash chain. Every check only reads, except
|
|
17
17
|
* the permissions fix, which narrows modes under turno's own folders.
|
|
@@ -133,7 +133,10 @@ function permissionChecks(env) {
|
|
|
133
133
|
if (!roots.length)
|
|
134
134
|
return [check({ level: "info", text: "permissions: turno has no folders yet" })];
|
|
135
135
|
if (!wide.length && !foreign.length)
|
|
136
|
-
out.push(check({
|
|
136
|
+
out.push(check({
|
|
137
|
+
level: "ok",
|
|
138
|
+
text: `permissions: only you can read turno's folders (${roots.map((r) => tildify(r, env)).join(", ")})`,
|
|
139
|
+
}));
|
|
137
140
|
if (wide.length) {
|
|
138
141
|
const writable = wide.filter((f) => f.mode & 0o022);
|
|
139
142
|
out.push(check({
|
|
@@ -177,7 +180,10 @@ async function portCheck(env) {
|
|
|
177
180
|
}
|
|
178
181
|
const ours = await answersAsMcpd(port, readToken(env, () => { }));
|
|
179
182
|
if (ours)
|
|
180
|
-
return check({
|
|
183
|
+
return check({
|
|
184
|
+
level: "ok",
|
|
185
|
+
text: `mcpd port ${port}: held by mcpd${ours.pid ? ` (pid ${ours.pid})` : ""} under your user`,
|
|
186
|
+
});
|
|
181
187
|
return check({
|
|
182
188
|
level: "warn",
|
|
183
189
|
text: `mcpd port ${port}: held by ${describeOwner(owner)}, which does not answer as mcpd, so sessions would send it the gateway token`,
|
|
@@ -415,7 +421,10 @@ async function versionChecks(env) {
|
|
|
415
421
|
runtime.push(s.name);
|
|
416
422
|
continue;
|
|
417
423
|
}
|
|
418
|
-
for (const launch of [
|
|
424
|
+
for (const launch of [
|
|
425
|
+
{ command: s.command, args: s.args },
|
|
426
|
+
...Object.values(s.variants).map((v) => ({ command: v.command ?? s.command, args: v.args ?? s.args })),
|
|
427
|
+
]) {
|
|
419
428
|
const f = await fetchedPackage(launch.command, launch.args);
|
|
420
429
|
if (f && !f.exact) {
|
|
421
430
|
loose.push(`${s.name} (${f.runner} ${f.spec} fetches the newest version at each start)`);
|
|
@@ -431,11 +440,17 @@ async function versionChecks(env) {
|
|
|
431
440
|
text: `MCP servers without an exact version: ${loose.join("; ")}`,
|
|
432
441
|
...(all
|
|
433
442
|
? { hint: `turno mcp install ${pinnable.join(" ")}` }
|
|
434
|
-
: {
|
|
443
|
+
: {
|
|
444
|
+
manual: `write an exact version (pkg@1.2.3) in each command in mcp.toml${pinnable.length ? `; turno mcp install ${pinnable.join(" ")} pins the npm packages` : ""}`,
|
|
445
|
+
}),
|
|
435
446
|
}));
|
|
436
447
|
}
|
|
437
448
|
if (runtime.length)
|
|
438
|
-
out.push(check({
|
|
449
|
+
out.push(check({
|
|
450
|
+
level: "info",
|
|
451
|
+
text: `pinned but not installed, so npx downloads them at each start: ${runtime.join(", ")}`,
|
|
452
|
+
hint: "turno mcp install",
|
|
453
|
+
}));
|
|
439
454
|
if (!loose.length && stdio)
|
|
440
455
|
out.push(check({ level: "ok", text: `every stdio MCP server runs an exact version or a fixed command (${stdio})` }));
|
|
441
456
|
return out;
|
|
@@ -452,7 +467,7 @@ function tokenAgeCheck(env, now = Date.now()) {
|
|
|
452
467
|
catch {
|
|
453
468
|
return [];
|
|
454
469
|
}
|
|
455
|
-
// Profile tokens
|
|
470
|
+
// Profile tokens derive from the master token, so they share its age; a token file
|
|
456
471
|
// that does not match it was written before a rotation and no longer opens mcpd.
|
|
457
472
|
const dir = dirname(profileTokenFile("x", env));
|
|
458
473
|
let names = [];
|
|
@@ -504,7 +519,11 @@ function auditCheck(env) {
|
|
|
504
519
|
v = verifyAudit(env);
|
|
505
520
|
}
|
|
506
521
|
catch (err) {
|
|
507
|
-
return check({
|
|
522
|
+
return check({
|
|
523
|
+
level: "warn",
|
|
524
|
+
text: `audit log: cannot read it: ${err.message}`,
|
|
525
|
+
manual: `check the owner and mode of ${tildify(paths(env).auditLog, env)} (yours, 600)`,
|
|
526
|
+
});
|
|
508
527
|
}
|
|
509
528
|
if (v.lines === 0)
|
|
510
529
|
return undefined;
|
|
@@ -515,7 +534,10 @@ function auditCheck(env) {
|
|
|
515
534
|
manual: `find out who changed ${tildify(paths(env).auditLog, env)} after it was written; turno identity log --verify shows the line`,
|
|
516
535
|
});
|
|
517
536
|
}
|
|
518
|
-
return check({
|
|
537
|
+
return check({
|
|
538
|
+
level: "ok",
|
|
539
|
+
text: `audit log: hash chain intact (${v.lines} line${v.lines === 1 ? "" : "s"}${v.legacy ? `, ${v.legacy} before the chain` : ""})`,
|
|
540
|
+
});
|
|
519
541
|
}
|
|
520
542
|
/** Every security check, in the order `turno doctor --security` prints them. */
|
|
521
543
|
export async function securityChecks(env) {
|
package/dist/cli/style.js
CHANGED
|
@@ -23,8 +23,32 @@ export const ICONS = {
|
|
|
23
23
|
next: cp(0xf0a9),
|
|
24
24
|
skip: cp(0xf05e),
|
|
25
25
|
},
|
|
26
|
-
unicode: {
|
|
27
|
-
|
|
26
|
+
unicode: {
|
|
27
|
+
ok: "✓",
|
|
28
|
+
warn: "!",
|
|
29
|
+
err: "✗",
|
|
30
|
+
info: "•",
|
|
31
|
+
add: "+",
|
|
32
|
+
remove: "-",
|
|
33
|
+
on: "●",
|
|
34
|
+
off: "○",
|
|
35
|
+
arrow: "→",
|
|
36
|
+
next: "➜",
|
|
37
|
+
skip: "–",
|
|
38
|
+
},
|
|
39
|
+
ascii: {
|
|
40
|
+
ok: "ok",
|
|
41
|
+
warn: "!",
|
|
42
|
+
err: "x",
|
|
43
|
+
info: "-",
|
|
44
|
+
add: "+",
|
|
45
|
+
remove: "-",
|
|
46
|
+
on: "",
|
|
47
|
+
off: "",
|
|
48
|
+
arrow: "->",
|
|
49
|
+
next: "",
|
|
50
|
+
skip: "-",
|
|
51
|
+
},
|
|
28
52
|
};
|
|
29
53
|
/** SGR codes of the semantic colors: the terminal's own palette, so dark and light themes both work. */
|
|
30
54
|
const CODES = { ok: "32", warn: "33", err: "31", accent: "36", muted: "2", faint: "90", bold: "1" };
|
|
@@ -187,7 +211,9 @@ export function style(io, opts = {}) {
|
|
|
187
211
|
let keep = Array.from({ length: n }, (_, i) => i);
|
|
188
212
|
const widthOf = (i) => Math.max(0, ...rows.map((r) => visibleWidth(r[i] ?? "")));
|
|
189
213
|
// The last column wraps under itself, so it only needs LAST_MIN columns to fit.
|
|
190
|
-
const total = (ks) => indent +
|
|
214
|
+
const total = (ks) => indent +
|
|
215
|
+
ks.reduce((a, i, k) => a + (k === ks.length - 1 ? Math.min(widthOf(i), LAST_MIN) : widthOf(i)), 0) +
|
|
216
|
+
gap * Math.max(0, ks.length - 1);
|
|
191
217
|
// Only a terminal drops columns: a pipe keeps everything for whoever reads it.
|
|
192
218
|
while (color && total(keep) > width) {
|
|
193
219
|
const droppable = keep.filter((i) => cols[i]?.drop !== undefined).sort((a, b) => cols[b].drop - cols[a].drop);
|
|
@@ -204,7 +230,11 @@ export function style(io, opts = {}) {
|
|
|
204
230
|
return padStart(cell, w);
|
|
205
231
|
return k === keep.length - 1 ? cell : padEnd(cell, w);
|
|
206
232
|
});
|
|
207
|
-
const head = " ".repeat(indent) +
|
|
233
|
+
const head = " ".repeat(indent) +
|
|
234
|
+
cells
|
|
235
|
+
.slice(0, -1)
|
|
236
|
+
.map((c) => `${c}${" ".repeat(gap)}`)
|
|
237
|
+
.join("");
|
|
208
238
|
return wrapLine(head, cells.at(-1) ?? "")
|
|
209
239
|
.split("\n")
|
|
210
240
|
.map((l) => l.trimEnd());
|
|
@@ -223,7 +253,7 @@ export function style(io, opts = {}) {
|
|
|
223
253
|
err,
|
|
224
254
|
icon,
|
|
225
255
|
lead: (name, text) => (ICONS[icons][name] ? `${icon(name)} ${text}` : text),
|
|
226
|
-
profile: (name, c) =>
|
|
256
|
+
profile: (name, c) => color && c !== undefined ? `\x1b[48;5;${c};1;38;5;255m ${name} \x1b[0m` : color ? bold(name) : name,
|
|
227
257
|
header: (title) => {
|
|
228
258
|
if (!color)
|
|
229
259
|
return title;
|