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
|
@@ -2,11 +2,12 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { readAudit, verifyAudit } from "../../accounts/audit.js";
|
|
3
3
|
import { launcherExists } from "../../accounts/delegate.js";
|
|
4
4
|
import { effectivePolicy } from "../../accounts/policy.js";
|
|
5
|
-
import { isValidService, loadRegistry, makeAccount, parseAccountId, saveRegistry } from "../../accounts/registry.js";
|
|
5
|
+
import { isValidService, loadRegistry, makeAccount, parseAccountId, saveRegistry, } from "../../accounts/registry.js";
|
|
6
6
|
import { Journal } from "../../core/journal.js";
|
|
7
7
|
import { expandHome, paths, tildify } from "../../core/paths.js";
|
|
8
|
-
import { DRY_RUN, JSON_FLAG, bool, count, parseFlags,
|
|
8
|
+
import { DRY_RUN, JSON_FLAG, bool, count, parseFlags, str } from "../args.js";
|
|
9
9
|
import { fail, paint } from "../io.js";
|
|
10
|
+
import { emit, jsonOutput } from "../output.js";
|
|
10
11
|
const USAGE = `Usage:
|
|
11
12
|
turno accounts list accounts, owners and folder preferences
|
|
12
13
|
turno accounts add <service:label> --profile <p> --tools <pattern>[,<pattern>]
|
|
@@ -34,16 +35,37 @@ const ADD_SPEC = {
|
|
|
34
35
|
...DRY_RUN,
|
|
35
36
|
};
|
|
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
|
+
]);
|
|
37
58
|
/**
|
|
38
|
-
* `log --verify`: check the hash chain of audit.jsonl
|
|
59
|
+
* `log --verify`: check the hash chain of audit.jsonl. It shows accidents and naive
|
|
39
60
|
* edits (a changed, inserted, removed or reordered line), not a determined attacker who can
|
|
40
61
|
* rewrite the whole file, and it cannot see lines cut from the end.
|
|
41
62
|
*/
|
|
42
|
-
function verifyLog(io,
|
|
63
|
+
function verifyLog(io, p) {
|
|
64
|
+
const json = bool(p, "json");
|
|
43
65
|
const v = verifyAudit(io.env);
|
|
44
66
|
const file = tildify(paths(io.env).auditLog, io.env);
|
|
45
67
|
if (json) {
|
|
46
|
-
|
|
68
|
+
emit(io, p, VERIFY_JSON, { file, ...v, line: v.line ?? null, reason: v.reason ?? null });
|
|
47
69
|
return v.ok ? 0 : 1;
|
|
48
70
|
}
|
|
49
71
|
if (!v.ok) {
|
|
@@ -205,11 +227,11 @@ export function prefer(rawArgs, io) {
|
|
|
205
227
|
export function log(args, io) {
|
|
206
228
|
const p = parseFlags(args, LOG_SPEC, 0);
|
|
207
229
|
if (bool(p, "verify"))
|
|
208
|
-
return verifyLog(io,
|
|
230
|
+
return verifyLog(io, p);
|
|
209
231
|
const n = count(p, "tail", 20);
|
|
210
232
|
const entries = readAudit(n, io.env);
|
|
211
233
|
if (bool(p, "json")) {
|
|
212
|
-
|
|
234
|
+
emit(io, p, AUDIT_JSON, entries);
|
|
213
235
|
return 0;
|
|
214
236
|
}
|
|
215
237
|
if (!entries.length) {
|
|
@@ -4,8 +4,9 @@ import { loadConfig } from "../../core/config.js";
|
|
|
4
4
|
import { paths, tildify } from "../../core/paths.js";
|
|
5
5
|
import { listProfiles } from "../../core/profiles.js";
|
|
6
6
|
import { resolveProfile } from "../../core/resolve.js";
|
|
7
|
+
import { Exit } from "../exit.js";
|
|
7
8
|
import { CliError, fail } from "../io.js";
|
|
8
|
-
import { execLauncher, findOnPath, launcherPath } from "../launch.js";
|
|
9
|
+
import { execLauncher, findOnPath, launcherPath, wantsSafe } from "../launch.js";
|
|
9
10
|
import { launcherName } from "../launchers.js";
|
|
10
11
|
/**
|
|
11
12
|
* Decide what `turno auto` runs in `cwd`. It never falls back to another account in silence:
|
|
@@ -28,7 +29,7 @@ export function planAuto(argv, io, cwd = process.cwd()) {
|
|
|
28
29
|
const plain = () => {
|
|
29
30
|
const file = findOnPath(a.command, env);
|
|
30
31
|
if (!file)
|
|
31
|
-
throw new CliError(`${a.command} is not installed (${a.install})`,
|
|
32
|
+
throw new CliError(`${a.command} is not installed (${a.install})`, Exit.notInstalled);
|
|
32
33
|
return file;
|
|
33
34
|
};
|
|
34
35
|
let config;
|
|
@@ -38,7 +39,13 @@ export function planAuto(argv, io, cwd = process.cwd()) {
|
|
|
38
39
|
catch (err) {
|
|
39
40
|
const msg = err.message;
|
|
40
41
|
if (env.TURNO_ALLOW_PLAIN === "1")
|
|
41
|
-
return {
|
|
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
|
+
};
|
|
42
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.`);
|
|
43
50
|
}
|
|
44
51
|
const where = tildify(cwd, env);
|
|
@@ -48,29 +55,46 @@ export function planAuto(argv, io, cwd = process.cwd()) {
|
|
|
48
55
|
if (!launcher) {
|
|
49
56
|
if (!listProfiles(config, env).includes(r.chosen)) {
|
|
50
57
|
const add = `turno profile add ${r.chosen}${agent === DEFAULT_AGENT ? "" : ` --agent ${agent}`}`;
|
|
51
|
-
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)
|
|
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);
|
|
52
59
|
}
|
|
53
60
|
const missing = tildify(join(paths(env).bin, launcherName(r.chosen, agent)), env);
|
|
54
61
|
throw new CliError(`${where} uses the ${r.chosen} profile, but its launcher ${missing} is missing. Run: turno profile repair ${r.chosen}`);
|
|
55
62
|
}
|
|
56
63
|
return {
|
|
57
64
|
file: launcher,
|
|
65
|
+
agent,
|
|
66
|
+
profile: r.chosen,
|
|
58
67
|
args,
|
|
59
|
-
notice: r.note
|
|
68
|
+
notice: r.note
|
|
69
|
+
? `turno: ${r.assigned} ${r.note} → using ${r.chosen} (${r.reason})`
|
|
70
|
+
: `turno: account ${r.chosen} (${r.reason})`,
|
|
60
71
|
};
|
|
61
72
|
}
|
|
62
73
|
if (config.system === "") {
|
|
63
|
-
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
|
|
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);
|
|
64
75
|
}
|
|
65
76
|
if (agent !== DEFAULT_AGENT && listProfiles(config, env, agent).length === 0) {
|
|
66
|
-
return {
|
|
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
|
+
};
|
|
67
84
|
}
|
|
68
|
-
return {
|
|
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
|
+
};
|
|
69
91
|
}
|
|
70
92
|
export const command = {
|
|
71
93
|
summary: "open the agent with the account assigned to this folder (turno-auto)",
|
|
72
94
|
usage: [
|
|
73
|
-
"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.",
|
|
74
98
|
"",
|
|
75
99
|
"Resolves the profile of that agent (Claude Code by default) for the current",
|
|
76
100
|
"folder (a git worktree counts as its main repository), switches to the fallback",
|
|
@@ -78,16 +102,30 @@ export const command = {
|
|
|
78
102
|
"Without a rule or a default, runs the agent's own command (claude, codex,",
|
|
79
103
|
"copilot, cursor-agent).",
|
|
80
104
|
"",
|
|
81
|
-
"It never switches accounts in silence: when the
|
|
82
|
-
|
|
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).",
|
|
83
108
|
"TURNO_ALLOW_PLAIN=1 runs the plain agent despite a broken config.toml;",
|
|
84
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).",
|
|
114
|
+
"",
|
|
115
|
+
"Examples:",
|
|
116
|
+
" $ turno auto",
|
|
117
|
+
" $ turno auto --resume",
|
|
118
|
+
" $ turno auto --agent codex",
|
|
119
|
+
" $ turno auto --no-gateway",
|
|
85
120
|
].join("\n"),
|
|
86
121
|
async run(argv, io) {
|
|
87
|
-
const
|
|
122
|
+
const safe = wantsSafe(argv, io.env);
|
|
123
|
+
const plan = planAuto(safe ? (await import("../safe.js")).takeSafeFlag(argv).args : argv, io);
|
|
88
124
|
const quiet = plan.args[0] === "--version" || plan.args[0] === "-v";
|
|
89
125
|
if (plan.notice && (plan.always || (process.stderr.isTTY && !quiet)))
|
|
90
126
|
io.err(plan.notice);
|
|
127
|
+
if (safe)
|
|
128
|
+
return (await import("../safe.js")).launchSafe(plan.agent, plan.profile, plan.args, io);
|
|
91
129
|
return execLauncher(plan.file, plan.args, io.env);
|
|
92
130
|
},
|
|
93
131
|
};
|