turno-cli 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +432 -0
- package/README.md +228 -73
- package/dist/accounts/audit.js +154 -12
- package/dist/accounts/builtin.js +100 -25
- package/dist/accounts/delegate.js +199 -35
- package/dist/accounts/policy.js +79 -0
- package/dist/accounts/registry.js +39 -21
- package/dist/agents/adapter.js +29 -0
- package/dist/agents/claude.js +246 -0
- package/dist/agents/codex.js +186 -0
- package/dist/agents/copilot.js +56 -0
- package/dist/agents/cursor.js +58 -0
- package/dist/agents/index.js +26 -86
- package/dist/agents/snippets.js +43 -13
- package/dist/cli/args.js +38 -6
- package/dist/cli/commands/accounts.js +119 -52
- package/dist/cli/commands/auto.js +121 -33
- package/dist/cli/commands/browser-identity.js +514 -0
- package/dist/cli/commands/browser-session.js +102 -0
- package/dist/cli/commands/browser-vault.js +193 -0
- package/dist/cli/commands/browser.js +319 -138
- package/dist/cli/commands/complete.js +14 -3
- package/dist/cli/commands/completion.js +8 -2
- package/dist/cli/commands/config.js +186 -24
- package/dist/cli/commands/demo.js +321 -0
- package/dist/cli/commands/doctor.js +525 -123
- package/dist/cli/commands/handoff.js +33 -22
- package/dist/cli/commands/identity.js +192 -54
- package/dist/cli/commands/init.js +648 -0
- package/dist/cli/commands/limit.js +84 -16
- package/dist/cli/commands/mcp-call.js +240 -0
- package/dist/cli/commands/mcp-oauth.js +221 -0
- package/dist/cli/commands/mcp-observe.js +539 -0
- package/dist/cli/commands/mcp-share.js +201 -0
- package/dist/cli/commands/mcp.js +816 -187
- package/dist/cli/commands/mcpd.js +388 -76
- package/dist/cli/commands/migrate.js +6 -4
- package/dist/cli/commands/open.js +115 -27
- package/dist/cli/commands/profile.js +396 -78
- package/dist/cli/commands/resolve.js +14 -3
- package/dist/cli/commands/run.js +36 -6
- package/dist/cli/commands/secret.js +80 -76
- package/dist/cli/commands/session.js +17 -6
- package/dist/cli/commands/sessions.js +48 -12
- package/dist/cli/commands/setup.js +214 -164
- package/dist/cli/commands/status.js +227 -44
- package/dist/cli/commands/statusline.js +311 -114
- package/dist/cli/commands/ui.js +78 -68
- package/dist/cli/commands/undo.js +193 -18
- package/dist/cli/commands/uninstall.js +481 -0
- package/dist/cli/commands/upgrade.js +172 -79
- package/dist/cli/commands/usage.js +125 -51
- package/dist/cli/commands/version.js +21 -7
- package/dist/cli/commands/which.js +9 -24
- package/dist/cli/compile-cache.js +32 -0
- package/dist/cli/diagnostics.js +184 -0
- package/dist/cli/exit.js +65 -0
- package/dist/cli/group.js +24 -12
- package/dist/cli/help.js +62 -0
- package/dist/cli/highlight.js +236 -0
- package/dist/cli/hints.js +30 -0
- package/dist/cli/io.js +186 -1
- package/dist/cli/launch.js +52 -39
- package/dist/cli/launchers.js +161 -95
- package/dist/cli/main.js +201 -31
- package/dist/cli/optional.js +144 -0
- package/dist/cli/output.js +123 -0
- package/dist/cli/picker.js +459 -0
- package/dist/cli/registry.js +61 -6
- package/dist/cli/safe.js +87 -0
- package/dist/cli/secret-input.js +63 -0
- package/dist/cli/security.js +561 -0
- package/dist/cli/style.js +311 -0
- package/dist/cli/topics.js +142 -0
- package/dist/core/config.js +181 -23
- package/dist/core/exhausted.js +6 -8
- package/dist/core/fsutil.js +39 -0
- package/dist/core/journal.js +294 -16
- package/dist/core/manifest.js +153 -6
- package/dist/core/paths.js +14 -13
- package/dist/core/profiles.js +160 -10
- package/dist/core/resolve.js +139 -23
- package/dist/core/secrets.js +68 -23
- package/dist/core/sessions.js +13 -20
- package/dist/core/state-file.js +107 -0
- package/dist/core/update.js +31 -18
- package/dist/core/version.js +57 -10
- package/dist/demo/server.js +42 -0
- package/dist/mcpd/cache.js +23 -10
- package/dist/mcpd/calllog.js +254 -0
- package/dist/mcpd/client-names.js +46 -0
- package/dist/mcpd/connectors.js +188 -18
- package/dist/mcpd/daemon.js +472 -115
- package/dist/mcpd/folder-sets.js +42 -0
- package/dist/mcpd/gateway.js +473 -51
- package/dist/mcpd/health.js +313 -0
- package/dist/mcpd/importer.js +453 -36
- package/dist/mcpd/instances.js +453 -65
- package/dist/mcpd/jsonrpc.js +11 -1
- package/dist/mcpd/launchd.js +65 -48
- package/dist/mcpd/middleware.js +144 -0
- package/dist/mcpd/modern.js +686 -0
- package/dist/mcpd/oauth.js +845 -0
- package/dist/mcpd/peerpid.js +134 -6
- package/dist/mcpd/pressure.js +88 -0
- package/dist/mcpd/rss.js +166 -0
- package/dist/mcpd/service.js +191 -0
- package/dist/mcpd/share.js +217 -0
- package/dist/mcpd/state.js +183 -0
- package/dist/mcpd/sync.js +72 -87
- package/dist/mcpd/systemd.js +83 -0
- package/dist/mcpd/tokens.js +85 -0
- package/dist/mcpd/upstream.js +163 -46
- package/dist/statusline/cost.js +167 -44
- package/dist/statusline/input.js +78 -0
- package/dist/statusline/render.js +9 -3
- package/dist/ui/fonts.js +8 -3
- package/dist/ui/settings.js +33 -16
- package/npm-shrinkwrap.json +1102 -0
- package/package.json +10 -9
- package/dist/cli/commands/available.js +0 -18
package/dist/agents/snippets.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { gatewayUrl } from "./adapter.js";
|
|
1
2
|
/**
|
|
2
|
-
* Config snippets that point agents turno does not manage at the MCP gateway
|
|
3
|
+
* Config snippets that point agents turno does not manage at the MCP gateway.
|
|
3
4
|
* turno prints them; the user pastes them. The token is never printed: each snippet reads it
|
|
4
5
|
* from TURNO_MCPD_TOKEN where the agent expands variables, and says so where it does not.
|
|
5
6
|
*/
|
|
@@ -7,57 +8,86 @@ export const SNIPPET_AGENTS = ["opencode", "gemini", "goose", "crush", "droid",
|
|
|
7
8
|
export function isSnippetAgent(v) {
|
|
8
9
|
return SNIPPET_AGENTS.includes(v);
|
|
9
10
|
}
|
|
10
|
-
const url = (port, name) =>
|
|
11
|
-
|
|
11
|
+
const url = (port, name) => gatewayUrl(name, port);
|
|
12
|
+
/** How the profile's own token reaches an agent that expands variables. */
|
|
13
|
+
const tokenEnv = (file) => `Start the agent with TURNO_MCPD_TOKEN set to this profile's token, e.g. in your shell profile: export TURNO_MCPD_TOKEN="$(cat ${file})"`;
|
|
12
14
|
function headers(profile, token) {
|
|
13
15
|
return { Authorization: `Bearer ${token}`, "X-Turno-Profile": profile };
|
|
14
16
|
}
|
|
15
17
|
function json(v) {
|
|
16
18
|
return `${JSON.stringify(v, null, 2)}\n`;
|
|
17
19
|
}
|
|
18
|
-
export function gatewaySnippet(agent, servers, port, profile) {
|
|
20
|
+
export function gatewaySnippet(agent, servers, port, profile, tokenFile = `~/.local/state/turno/mcpd-tokens/${profile}.token`) {
|
|
21
|
+
const TOKEN_ENV = tokenEnv(tokenFile);
|
|
19
22
|
const each = (f) => Object.fromEntries(servers.map((n) => [n, f(n)]));
|
|
20
23
|
switch (agent) {
|
|
21
24
|
case "opencode":
|
|
22
25
|
return {
|
|
23
26
|
file: "opencode.json (project) or ~/.config/opencode/opencode.json",
|
|
24
|
-
text: json({
|
|
27
|
+
text: json({
|
|
28
|
+
mcp: each((n) => ({
|
|
29
|
+
type: "remote",
|
|
30
|
+
url: url(port, n),
|
|
31
|
+
headers: headers(profile, "{env:TURNO_MCPD_TOKEN}"),
|
|
32
|
+
enabled: true,
|
|
33
|
+
})),
|
|
34
|
+
}),
|
|
25
35
|
notes: [TOKEN_ENV],
|
|
26
36
|
};
|
|
27
37
|
case "gemini":
|
|
28
38
|
return {
|
|
29
39
|
file: "~/.gemini/settings.json (or .gemini/settings.json in a project)",
|
|
30
|
-
text: json({
|
|
40
|
+
text: json({
|
|
41
|
+
mcpServers: each((n) => ({ httpUrl: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })),
|
|
42
|
+
}),
|
|
31
43
|
notes: [TOKEN_ENV],
|
|
32
44
|
};
|
|
33
45
|
case "goose": {
|
|
34
46
|
const lines = ["extensions:"];
|
|
35
47
|
for (const n of servers) {
|
|
36
|
-
lines.push(` ${n}:`, ` name: ${n}`, " type: streamable_http", ` uri: ${url(port, n)}`, " enabled: true", " timeout: 300", " headers:",
|
|
48
|
+
lines.push(` ${n}:`, ` name: ${n}`, " type: streamable_http", ` uri: ${url(port, n)}`, " enabled: true", " timeout: 300", " headers:", ` Authorization: "Bearer <paste the token from ${tokenFile}>"`, ` X-Turno-Profile: ${profile}`);
|
|
37
49
|
}
|
|
38
50
|
return {
|
|
39
51
|
file: "~/.config/goose/config.yaml",
|
|
40
52
|
text: `${lines.join("\n")}\n`,
|
|
41
|
-
notes: [
|
|
53
|
+
notes: [
|
|
54
|
+
"Goose does not document variable expansion in headers: paste the token by hand and keep the file private (chmod 600).",
|
|
55
|
+
],
|
|
42
56
|
};
|
|
43
57
|
}
|
|
44
58
|
case "crush":
|
|
45
59
|
return {
|
|
46
60
|
file: "crush.json (project) or ~/.config/crush/crush.json",
|
|
47
|
-
text: json({
|
|
61
|
+
text: json({
|
|
62
|
+
mcp: each((n) => ({ type: "http", url: url(port, n), headers: headers(profile, "$TURNO_MCPD_TOKEN") })),
|
|
63
|
+
}),
|
|
48
64
|
notes: [TOKEN_ENV],
|
|
49
65
|
};
|
|
50
66
|
case "droid":
|
|
51
67
|
return {
|
|
52
68
|
file: "~/.factory/mcp.json",
|
|
53
|
-
text: json({
|
|
54
|
-
|
|
69
|
+
text: json({
|
|
70
|
+
mcpServers: each((n) => ({
|
|
71
|
+
type: "http",
|
|
72
|
+
url: url(port, n),
|
|
73
|
+
headers: headers(profile, "${TURNO_MCPD_TOKEN}"),
|
|
74
|
+
})),
|
|
75
|
+
}),
|
|
76
|
+
notes: [
|
|
77
|
+
TOKEN_ENV,
|
|
78
|
+
"Variable expansion in Droid headers is not verified: if the gateway answers 401, paste the token instead.",
|
|
79
|
+
],
|
|
55
80
|
};
|
|
56
81
|
case "kiro":
|
|
57
82
|
return {
|
|
58
83
|
file: "~/.kiro/settings/mcp.json",
|
|
59
|
-
text: json({
|
|
60
|
-
|
|
84
|
+
text: json({
|
|
85
|
+
mcpServers: each((n) => ({ url: url(port, n), headers: headers(profile, "${TURNO_MCPD_TOKEN}") })),
|
|
86
|
+
}),
|
|
87
|
+
notes: [
|
|
88
|
+
TOKEN_ENV,
|
|
89
|
+
"Variable expansion in Kiro headers is not verified: if the gateway answers 401, paste the token instead.",
|
|
90
|
+
],
|
|
61
91
|
};
|
|
62
92
|
}
|
|
63
93
|
}
|
package/dist/cli/args.js
CHANGED
|
@@ -6,17 +6,53 @@ export const DRY_RUN = { "dry-run": { type: "boolean" } };
|
|
|
6
6
|
export const FORCE = { force: { type: "boolean" } };
|
|
7
7
|
export const TAIL = { tail: { type: "string", short: "n" } };
|
|
8
8
|
export const WATCH = { watch: { type: "boolean" } };
|
|
9
|
+
/**
|
|
10
|
+
* Completion flags of a spec (`--name` for each long flag), so the parser and the shell
|
|
11
|
+
* completion never disagree. Use it as `flags: flagsOf(SPEC)` next to `parseFlags(args, SPEC)`.
|
|
12
|
+
*/
|
|
13
|
+
export function flagsOf(...specs) {
|
|
14
|
+
return specs.flatMap((s) => Object.keys(s)).map((k) => `--${k}`);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Take `--json=<value>` out of `args` when the spec has a boolean --json: it turns
|
|
18
|
+
* --json on and keeps the value for `emit`. Only a command's own flags count, not those after --.
|
|
19
|
+
*/
|
|
20
|
+
function takeJsonValue(args, spec) {
|
|
21
|
+
if (spec.json?.type !== "boolean")
|
|
22
|
+
return { args };
|
|
23
|
+
let json;
|
|
24
|
+
const out = [];
|
|
25
|
+
let i = 0;
|
|
26
|
+
for (; i < args.length && args[i] !== "--"; i++) {
|
|
27
|
+
const a = args[i];
|
|
28
|
+
if (a.startsWith("--json=")) {
|
|
29
|
+
json = a.slice("--json=".length);
|
|
30
|
+
out.push("--json");
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
if (a === "--json")
|
|
34
|
+
json ??= "";
|
|
35
|
+
out.push(a);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return { args: [...out, ...args.slice(i)], ...(json !== undefined ? { json } : {}) };
|
|
39
|
+
}
|
|
9
40
|
/**
|
|
10
41
|
* Parse `args` against `spec` (long flags, `--flag=value`, short aliases). Unknown flags and
|
|
11
42
|
* positionals beyond `max` are usage errors with a plain message.
|
|
12
43
|
*/
|
|
13
|
-
export function parseFlags(
|
|
44
|
+
export function parseFlags(given, spec, max = Number.POSITIVE_INFINITY) {
|
|
45
|
+
const { args, json } = takeJsonValue(given, spec);
|
|
14
46
|
let parsed;
|
|
15
47
|
try {
|
|
16
48
|
parsed = parseArgs({ args, options: spec, allowPositionals: true, strict: true });
|
|
49
|
+
if (json !== undefined)
|
|
50
|
+
parsed.json = json;
|
|
17
51
|
}
|
|
18
52
|
catch (err) {
|
|
19
|
-
const msg = err.message
|
|
53
|
+
const msg = err.message
|
|
54
|
+
.replace(/^Unknown option '(.+?)'.*$/s, "unknown option $1")
|
|
55
|
+
.replace(/\. To specify.*$/s, "");
|
|
20
56
|
return fail(msg.replace(/^Option '(--[\w-]+)(?: <value>)?' argument missing$/, "$1 needs a value"));
|
|
21
57
|
}
|
|
22
58
|
if (parsed.positionals.length > max)
|
|
@@ -40,8 +76,4 @@ export function count(p, name, fallback) {
|
|
|
40
76
|
fail(`--${name} must be a positive integer`);
|
|
41
77
|
return n;
|
|
42
78
|
}
|
|
43
|
-
/** Print a value as indented JSON. */
|
|
44
|
-
export function printJson(out, value) {
|
|
45
|
-
out(JSON.stringify(value, null, 2));
|
|
46
|
-
}
|
|
47
79
|
//# sourceMappingURL=args.js.map
|
|
@@ -1,48 +1,87 @@
|
|
|
1
1
|
import { resolve } from "node:path";
|
|
2
|
-
import { readAudit } from "../../accounts/audit.js";
|
|
2
|
+
import { readAudit, verifyAudit } from "../../accounts/audit.js";
|
|
3
3
|
import { launcherExists } from "../../accounts/delegate.js";
|
|
4
|
-
import {
|
|
4
|
+
import { effectivePolicy } from "../../accounts/policy.js";
|
|
5
|
+
import { isValidService, loadRegistry, makeAccount, parseAccountId, saveRegistry, } from "../../accounts/registry.js";
|
|
5
6
|
import { Journal } from "../../core/journal.js";
|
|
6
7
|
import { expandHome, paths, tildify } from "../../core/paths.js";
|
|
8
|
+
import { DRY_RUN, JSON_FLAG, bool, count, parseFlags, str } from "../args.js";
|
|
7
9
|
import { fail, paint } from "../io.js";
|
|
10
|
+
import { emit, jsonOutput } from "../output.js";
|
|
8
11
|
const USAGE = `Usage:
|
|
9
12
|
turno accounts list accounts, owners and folder preferences
|
|
10
13
|
turno accounts add <service:label> --profile <p> --tools <pattern>[,<pattern>]
|
|
14
|
+
[--read-tools <pattern>[,<pattern>]] [--confirm always|writes|never]
|
|
11
15
|
[--service <s>] [--description <d>]
|
|
12
16
|
turno accounts remove <service:label>
|
|
13
17
|
turno accounts prefer <path> <service>=<account> (empty account removes the preference)
|
|
14
|
-
turno accounts log [-n N]
|
|
18
|
+
turno accounts log [-n N] [--verify] [--json]
|
|
19
|
+
recent calls to the accounts bridge; --verify
|
|
20
|
+
checks the log's hash chain (exit 1 if broken)
|
|
15
21
|
|
|
16
22
|
The registry lives in ~/.config/turno/accounts.toml. add, remove and prefer rewrite
|
|
17
|
-
the file (it is managed: comments in it are not preserved) and accept --dry-run
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
the file (it is managed: comments in it are not preserved) and accept --dry-run.
|
|
24
|
+
|
|
25
|
+
A delegated read gets only --read-tools; an account without them has every call confirmed.
|
|
26
|
+
--confirm defaults to "always" for mail and messaging services and "writes" elsewhere.`;
|
|
27
|
+
/** Flags of each subcommand, shared with completion through flagsOf. */
|
|
28
|
+
const ADD_SPEC = {
|
|
29
|
+
profile: { type: "string" },
|
|
30
|
+
tools: { type: "string" },
|
|
31
|
+
"read-tools": { type: "string" },
|
|
32
|
+
confirm: { type: "string" },
|
|
33
|
+
service: { type: "string" },
|
|
34
|
+
description: { type: "string" },
|
|
35
|
+
...DRY_RUN,
|
|
36
|
+
};
|
|
37
|
+
export const LOG_SPEC = { tail: { type: "string", short: "n" }, verify: { type: "boolean" }, ...JSON_FLAG };
|
|
38
|
+
/** `log --json`: one element per audit line; `log --verify --json`: the chain check. */
|
|
39
|
+
const AUDIT_JSON = jsonOutput([
|
|
40
|
+
"ts",
|
|
41
|
+
"caller",
|
|
42
|
+
"account",
|
|
43
|
+
"owner",
|
|
44
|
+
"write",
|
|
45
|
+
"task",
|
|
46
|
+
"outcome",
|
|
47
|
+
"detail",
|
|
48
|
+
"durationMs",
|
|
49
|
+
"costUsd",
|
|
50
|
+
"decision",
|
|
51
|
+
"prev",
|
|
52
|
+
]);
|
|
53
|
+
const VERIFY_JSON = jsonOutput(["file", "ok", "lines", "legacy", "line", "reason"]);
|
|
54
|
+
export const LOG_JSON = jsonOutput([
|
|
55
|
+
...AUDIT_JSON.fields,
|
|
56
|
+
...VERIFY_JSON.fields.filter((f) => !AUDIT_JSON.fields.includes(f)),
|
|
57
|
+
]);
|
|
58
|
+
/**
|
|
59
|
+
* `log --verify`: check the hash chain of audit.jsonl. It shows accidents and naive
|
|
60
|
+
* edits (a changed, inserted, removed or reordered line), not a determined attacker who can
|
|
61
|
+
* rewrite the whole file, and it cannot see lines cut from the end.
|
|
62
|
+
*/
|
|
63
|
+
function verifyLog(io, p) {
|
|
64
|
+
const json = bool(p, "json");
|
|
65
|
+
const v = verifyAudit(io.env);
|
|
66
|
+
const file = tildify(paths(io.env).auditLog, io.env);
|
|
67
|
+
if (json) {
|
|
68
|
+
emit(io, p, VERIFY_JSON, { file, ...v, line: v.line ?? null, reason: v.reason ?? null });
|
|
69
|
+
return v.ok ? 0 : 1;
|
|
70
|
+
}
|
|
71
|
+
if (!v.ok) {
|
|
72
|
+
io.out(`${paint(io, "broken", "31")} ${file}: line ${v.line}: ${v.reason}`);
|
|
73
|
+
io.out("The audit log was changed after it was written, or two writers raced. Keep a copy before you edit it.");
|
|
74
|
+
return 1;
|
|
75
|
+
}
|
|
76
|
+
if (v.lines === 0)
|
|
77
|
+
io.out(`No delegations recorded yet (${file}).`);
|
|
78
|
+
else {
|
|
79
|
+
const legacy = v.legacy ? `; ${v.legacy} older line${v.legacy === 1 ? "" : "s"} predate the chain` : "";
|
|
80
|
+
io.out(`${paint(io, "ok", "32")} ${file}: ${v.lines} line${v.lines === 1 ? "" : "s"}, hash chain intact${legacy}`);
|
|
42
81
|
}
|
|
43
|
-
return
|
|
82
|
+
return 0;
|
|
44
83
|
}
|
|
45
|
-
|
|
84
|
+
function list(io) {
|
|
46
85
|
const reg = loadRegistry(io.env);
|
|
47
86
|
const accounts = Object.values(reg.accounts).sort((a, b) => a.id.localeCompare(b.id));
|
|
48
87
|
if (!accounts.length) {
|
|
@@ -54,6 +93,7 @@ export function list(io) {
|
|
|
54
93
|
for (const a of accounts) {
|
|
55
94
|
const missing = launcherExists(a.profile, io.env) ? "" : paint(io, " (no launcher)", "33");
|
|
56
95
|
io.out(`${paint(io, a.id.padEnd(width), "1")} ${a.profile.padEnd(12)} ${a.tools.join(", ")}${missing}`);
|
|
96
|
+
io.out(`${" ".repeat(width)} ${paint(io, policyLine(a), "2")}`);
|
|
57
97
|
if (a.description)
|
|
58
98
|
io.out(`${" ".repeat(width)} ${paint(io, a.description, "2")}`);
|
|
59
99
|
}
|
|
@@ -66,27 +106,44 @@ export function list(io) {
|
|
|
66
106
|
}
|
|
67
107
|
return 0;
|
|
68
108
|
}
|
|
109
|
+
/** How the bridge treats an account: its confirm policy and what a read may call. */
|
|
110
|
+
export function policyLine(a) {
|
|
111
|
+
const policy = `confirm ${effectivePolicy(a)}${a.confirm ? "" : " (default)"}`;
|
|
112
|
+
if (a.readTools)
|
|
113
|
+
return `${policy}; reads: ${a.readTools.join(", ")}`;
|
|
114
|
+
return `${policy}; no read_tools: ${effectivePolicy(a) === "never" ? "reads get every tool" : "every call is confirmed"}`;
|
|
115
|
+
}
|
|
116
|
+
const list_ = (v) => v
|
|
117
|
+
?.split(",")
|
|
118
|
+
.map((t) => t.trim())
|
|
119
|
+
.filter(Boolean);
|
|
69
120
|
export function add(rawArgs, io) {
|
|
70
|
-
const
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const { pos, flags } = parseFlags(args, ["profile", "tools", "service", "description"]);
|
|
74
|
-
const [id, extra] = pos;
|
|
121
|
+
const p = parseFlags(rawArgs, ADD_SPEC);
|
|
122
|
+
const dry = bool(p, "dry-run");
|
|
123
|
+
const [id, extra] = p.positionals;
|
|
75
124
|
if (!id || extra !== undefined)
|
|
76
|
-
fail("usage: turno
|
|
125
|
+
fail("usage: turno identity add <service:label> --profile <p> --tools <pattern>[,<pattern>] [--read-tools <pattern>[,...]] [--confirm always|writes|never]");
|
|
126
|
+
const journal = new Journal(io.env, `accounts add ${id}`, dry);
|
|
127
|
+
const flags = {
|
|
128
|
+
profile: str(p, "profile"),
|
|
129
|
+
tools: str(p, "tools"),
|
|
130
|
+
readTools: str(p, "read-tools"),
|
|
131
|
+
confirm: str(p, "confirm"),
|
|
132
|
+
service: str(p, "service"),
|
|
133
|
+
description: str(p, "description"),
|
|
134
|
+
};
|
|
77
135
|
if (!flags.profile)
|
|
78
136
|
fail("--profile is required");
|
|
79
137
|
if (!flags.tools)
|
|
80
138
|
fail("--tools is required");
|
|
81
|
-
const tools = flags.tools
|
|
82
|
-
.split(",")
|
|
83
|
-
.map((t) => t.trim())
|
|
84
|
-
.filter(Boolean);
|
|
139
|
+
const tools = list_(flags.tools);
|
|
85
140
|
const reg = loadRegistry(io.env);
|
|
86
141
|
const existed = Boolean(reg.accounts[id]);
|
|
87
142
|
reg.accounts[id] = makeAccount(id, {
|
|
88
143
|
profile: flags.profile,
|
|
89
144
|
tools,
|
|
145
|
+
...(flags.readTools !== undefined ? { readTools: list_(flags.readTools) } : {}),
|
|
146
|
+
...(flags.confirm !== undefined ? { confirm: flags.confirm } : {}),
|
|
90
147
|
...(flags.service ? { service: flags.service } : {}),
|
|
91
148
|
...(flags.description ? { description: flags.description } : {}),
|
|
92
149
|
});
|
|
@@ -99,12 +156,13 @@ export function add(rawArgs, io) {
|
|
|
99
156
|
return 0;
|
|
100
157
|
}
|
|
101
158
|
export function remove(rawArgs, io) {
|
|
102
|
-
const
|
|
103
|
-
const
|
|
159
|
+
const p = parseFlags(rawArgs, DRY_RUN);
|
|
160
|
+
const dry = bool(p, "dry-run");
|
|
161
|
+
const args = p.positionals;
|
|
104
162
|
const journal = new Journal(io.env, `accounts remove ${args.join(" ")}`, dry);
|
|
105
163
|
const [id, extra] = args;
|
|
106
164
|
if (!id || extra !== undefined)
|
|
107
|
-
fail("usage: turno
|
|
165
|
+
fail("usage: turno identity remove <service:label>");
|
|
108
166
|
const reg = loadRegistry(io.env);
|
|
109
167
|
if (!reg.accounts[id])
|
|
110
168
|
fail(`unknown account "${id}"`);
|
|
@@ -125,12 +183,13 @@ function dropPreferences(reg, id) {
|
|
|
125
183
|
reg.prefer = reg.prefer.filter((r) => Object.keys(r.accounts).length > 0);
|
|
126
184
|
}
|
|
127
185
|
export function prefer(rawArgs, io) {
|
|
128
|
-
const
|
|
129
|
-
const
|
|
186
|
+
const p = parseFlags(rawArgs, DRY_RUN);
|
|
187
|
+
const dry = bool(p, "dry-run");
|
|
188
|
+
const args = p.positionals;
|
|
130
189
|
const journal = new Journal(io.env, `accounts prefer ${args.join(" ")}`, dry);
|
|
131
190
|
const [rawPath, pair, extra] = args;
|
|
132
191
|
if (!rawPath || !pair || extra !== undefined)
|
|
133
|
-
fail("usage: turno
|
|
192
|
+
fail("usage: turno identity prefer <path> <service>=<account>");
|
|
134
193
|
const eq = pair.indexOf("=");
|
|
135
194
|
if (eq <= 0)
|
|
136
195
|
fail("expected <service>=<account>, like linear=linear:work");
|
|
@@ -166,13 +225,15 @@ export function prefer(rawArgs, io) {
|
|
|
166
225
|
return 0;
|
|
167
226
|
}
|
|
168
227
|
export function log(args, io) {
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
171
|
-
|
|
172
|
-
const n =
|
|
173
|
-
if (!Number.isInteger(n) || n < 1)
|
|
174
|
-
fail("--tail must be a positive integer");
|
|
228
|
+
const p = parseFlags(args, LOG_SPEC, 0);
|
|
229
|
+
if (bool(p, "verify"))
|
|
230
|
+
return verifyLog(io, p);
|
|
231
|
+
const n = count(p, "tail", 20);
|
|
175
232
|
const entries = readAudit(n, io.env);
|
|
233
|
+
if (bool(p, "json")) {
|
|
234
|
+
emit(io, p, AUDIT_JSON, entries);
|
|
235
|
+
return 0;
|
|
236
|
+
}
|
|
176
237
|
if (!entries.length) {
|
|
177
238
|
io.out("No delegations recorded yet.");
|
|
178
239
|
return 0;
|
|
@@ -185,6 +246,12 @@ export function log(args, io) {
|
|
|
185
246
|
const task = e.task.replace(/\s+/g, " ");
|
|
186
247
|
io.out(`${when} ${paint(io, e.outcome.padEnd(7), color)} ${who} -> ${e.account} (${e.owner ?? "?"}) ${e.write ? "write" : "read"} ${Math.round(e.durationMs / 1000)}s${cost}`);
|
|
187
248
|
io.out(` ${task.length > 120 ? `${task.slice(0, 117)}...` : task}`);
|
|
249
|
+
if (e.decision) {
|
|
250
|
+
const d = e.decision;
|
|
251
|
+
const asked = d.asked ? (d.confirmed ? "confirmed" : "not confirmed") : "not asked";
|
|
252
|
+
const blocked = d.denied?.length ? `; blocked: ${d.denied.join(", ")}` : "";
|
|
253
|
+
io.out(` ${paint(io, `${d.toolset === "read" ? "read tools" : "all tools"}, ${asked}${d.mcp ? `, ${d.mcp} MCP` : ""}${blocked}`, "2")}`);
|
|
254
|
+
}
|
|
188
255
|
if (e.outcome !== "ok" && e.detail)
|
|
189
256
|
io.out(` ${paint(io, e.detail.replace(/\s+/g, " ").slice(0, 160), "2")}`);
|
|
190
257
|
}
|
|
@@ -1,44 +1,132 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join } from "node:path";
|
|
2
|
+
import { AGENT_IDS, DEFAULT_AGENT, adapter, agentHub, isAgentId } from "../../agents/index.js";
|
|
2
3
|
import { loadConfig } from "../../core/config.js";
|
|
4
|
+
import { paths, tildify } from "../../core/paths.js";
|
|
5
|
+
import { listProfiles } from "../../core/profiles.js";
|
|
3
6
|
import { resolveProfile } from "../../core/resolve.js";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
7
|
+
import { Exit } from "../exit.js";
|
|
8
|
+
import { CliError, fail } from "../io.js";
|
|
9
|
+
import { execLauncher, findOnPath, launcherPath, wantsSafe } from "../launch.js";
|
|
10
|
+
import { launcherName } from "../launchers.js";
|
|
11
|
+
/**
|
|
12
|
+
* Decide what `turno auto` runs in `cwd`. It never falls back to another account in silence:
|
|
13
|
+
* a chosen profile without its launcher, a rule naming a missing profile, or a broken
|
|
14
|
+
* config.toml are errors (TURNO_ALLOW_PLAIN=1 runs the plain agent despite a broken config).
|
|
15
|
+
*/
|
|
16
|
+
export function planAuto(argv, io, cwd = process.cwd()) {
|
|
17
|
+
let agent = DEFAULT_AGENT;
|
|
18
|
+
let args = argv;
|
|
19
|
+
if (argv[0] === "--agent" || argv[0]?.startsWith("--agent=")) {
|
|
20
|
+
const v = argv[0] === "--agent" ? argv[1] : argv[0].slice("--agent=".length);
|
|
21
|
+
if (!isAgentId(v))
|
|
22
|
+
return fail(`--agent must be ${AGENT_IDS.slice(0, -1).join(", ")} or ${AGENT_IDS.at(-1)}`);
|
|
23
|
+
agent = v;
|
|
24
|
+
args = argv.slice(argv[0] === "--agent" ? 2 : 1);
|
|
25
|
+
}
|
|
26
|
+
const env = io.env;
|
|
27
|
+
const a = adapter(agent);
|
|
28
|
+
const hub = tildify(agentHub(agent, env), env);
|
|
29
|
+
const plain = () => {
|
|
30
|
+
const file = findOnPath(a.command, env);
|
|
31
|
+
if (!file)
|
|
32
|
+
throw new CliError(`${a.command} is not installed (${a.install})`, Exit.notInstalled);
|
|
33
|
+
return file;
|
|
34
|
+
};
|
|
35
|
+
let config;
|
|
36
|
+
try {
|
|
37
|
+
config = loadConfig(env);
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
const msg = err.message;
|
|
41
|
+
if (env.TURNO_ALLOW_PLAIN === "1")
|
|
42
|
+
return {
|
|
43
|
+
file: plain(),
|
|
44
|
+
agent,
|
|
45
|
+
args,
|
|
46
|
+
notice: `turno: ${msg}; running plain ${a.command} (TURNO_ALLOW_PLAIN=1)`,
|
|
47
|
+
always: true,
|
|
48
|
+
};
|
|
49
|
+
throw new CliError(`${msg}\nturno auto does not guess an account while config.toml is broken. Fix it (turno config edit), or run plain ${a.command} once with TURNO_ALLOW_PLAIN=1.`);
|
|
50
|
+
}
|
|
51
|
+
const where = tildify(cwd, env);
|
|
52
|
+
const r = resolveProfile(cwd, config, env, undefined, agent);
|
|
53
|
+
if (r.chosen) {
|
|
54
|
+
const launcher = launcherPath(r.chosen, env, agent);
|
|
55
|
+
if (!launcher) {
|
|
56
|
+
if (!listProfiles(config, env).includes(r.chosen)) {
|
|
57
|
+
const add = `turno profile add ${r.chosen}${agent === DEFAULT_AGENT ? "" : ` --agent ${agent}`}`;
|
|
58
|
+
throw new CliError(`${where} uses the ${r.chosen} profile (${r.reason}), but there is no such profile. Run: ${add}, or change the rule (turno profile which)`, Exit.noProfile);
|
|
59
|
+
}
|
|
60
|
+
const missing = tildify(join(paths(env).bin, launcherName(r.chosen, agent)), env);
|
|
61
|
+
throw new CliError(`${where} uses the ${r.chosen} profile, but its launcher ${missing} is missing. Run: turno profile repair ${r.chosen}`);
|
|
62
|
+
}
|
|
63
|
+
return {
|
|
64
|
+
file: launcher,
|
|
65
|
+
agent,
|
|
66
|
+
profile: r.chosen,
|
|
67
|
+
args,
|
|
68
|
+
notice: r.note
|
|
69
|
+
? `turno: ${r.assigned} ${r.note} → using ${r.chosen} (${r.reason})`
|
|
70
|
+
: `turno: account ${r.chosen} (${r.reason})`,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
if (config.system === "") {
|
|
74
|
+
throw new CliError(`${where} has no rule and no default profile, and system = "" says there is no default account. Assign one: turno profile assign ${where} <profile>`, Exit.noProfile);
|
|
75
|
+
}
|
|
76
|
+
if (agent !== DEFAULT_AGENT && listProfiles(config, env, agent).length === 0) {
|
|
77
|
+
return {
|
|
78
|
+
file: plain(),
|
|
79
|
+
agent,
|
|
80
|
+
args,
|
|
81
|
+
notice: `turno: no ${a.label} profile yet, so this runs plain ${a.command} with ${hub} (turno profile add <name> --agent ${agent})`,
|
|
82
|
+
always: true,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
file: plain(),
|
|
87
|
+
agent,
|
|
88
|
+
args,
|
|
89
|
+
notice: `turno: no rule or default for ${where}; running plain ${a.command} with ${hub}`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
6
92
|
export const command = {
|
|
7
93
|
summary: "open the agent with the account assigned to this folder (turno-auto)",
|
|
8
94
|
usage: [
|
|
9
|
-
"Usage: turno auto [--agent
|
|
95
|
+
"Usage: turno auto [--agent <agent>] [--no-gateway] [agent args]",
|
|
96
|
+
"",
|
|
97
|
+
"<agent> is claude (the default), codex, copilot or cursor.",
|
|
98
|
+
"",
|
|
99
|
+
"Resolves the profile of that agent (Claude Code by default) for the current",
|
|
100
|
+
"folder (a git worktree counts as its main repository), switches to the fallback",
|
|
101
|
+
"when one is set and the assigned profile is exhausted, and execs its launcher.",
|
|
102
|
+
"Without a rule or a default, runs the agent's own command (claude, codex,",
|
|
103
|
+
"copilot, cursor-agent).",
|
|
104
|
+
"",
|
|
105
|
+
"It never switches accounts in silence: it exits 3 when the folder's profile does",
|
|
106
|
+
'not exist (or there is no rule and system = ""), 1 when its launcher is missing',
|
|
107
|
+
"or config.toml does not parse, and says how to fix it (turno help exit-codes).",
|
|
108
|
+
"TURNO_ALLOW_PLAIN=1 runs the plain agent despite a broken config.toml;",
|
|
109
|
+
'system = "" in config.toml makes folders without a rule an error too.',
|
|
110
|
+
"",
|
|
111
|
+
"--no-gateway (or TURNO_SAFE=1) opens the same account in safe mode: no mcpd",
|
|
112
|
+
"entries and no status line, to tell whether a problem comes from turno (turno",
|
|
113
|
+
"run --help).",
|
|
10
114
|
"",
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
115
|
+
"Examples:",
|
|
116
|
+
" $ turno auto",
|
|
117
|
+
" $ turno auto --resume",
|
|
118
|
+
" $ turno auto --agent codex",
|
|
119
|
+
" $ turno auto --no-gateway",
|
|
15
120
|
].join("\n"),
|
|
16
121
|
async run(argv, io) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
agent
|
|
24
|
-
|
|
25
|
-
}
|
|
26
|
-
let config;
|
|
27
|
-
try {
|
|
28
|
-
config = loadConfig(io.env);
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
// A broken config must not stop Claude Code from starting.
|
|
32
|
-
io.err(`turno: ${err.message}; running plain ${adapter(agent).command}`);
|
|
33
|
-
}
|
|
34
|
-
const r = config ? resolveProfile(process.cwd(), config, io.env, undefined, agent) : undefined;
|
|
35
|
-
const launcher = r?.chosen ? launcherPath(r.chosen, io.env, agent) : undefined;
|
|
36
|
-
if (!r || !launcher)
|
|
37
|
-
return execCommand(adapter(agent).command, args, io.env);
|
|
38
|
-
if (process.stderr.isTTY && args[0] !== "--version" && args[0] !== "-v") {
|
|
39
|
-
io.err(r.note ? `turno: ${r.assigned} ${r.note} → using ${r.chosen} (${r.reason})` : `turno: account ${r.chosen} (${r.reason})`);
|
|
40
|
-
}
|
|
41
|
-
return execLauncher(launcher, args, io.env);
|
|
122
|
+
const safe = wantsSafe(argv, io.env);
|
|
123
|
+
const plan = planAuto(safe ? (await import("../safe.js")).takeSafeFlag(argv).args : argv, io);
|
|
124
|
+
const quiet = plan.args[0] === "--version" || plan.args[0] === "-v";
|
|
125
|
+
if (plan.notice && (plan.always || (process.stderr.isTTY && !quiet)))
|
|
126
|
+
io.err(plan.notice);
|
|
127
|
+
if (safe)
|
|
128
|
+
return (await import("../safe.js")).launchSafe(plan.agent, plan.profile, plan.args, io);
|
|
129
|
+
return execLauncher(plan.file, plan.args, io.env);
|
|
42
130
|
},
|
|
43
131
|
};
|
|
44
132
|
//# sourceMappingURL=auto.js.map
|