turno-cli 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +293 -0
- package/README.md +143 -75
- package/dist/accounts/audit.js +137 -7
- package/dist/accounts/builtin.js +68 -21
- package/dist/accounts/delegate.js +176 -35
- package/dist/accounts/policy.js +77 -0
- package/dist/accounts/registry.js +37 -21
- package/dist/agents/adapter.js +7 -0
- package/dist/agents/claude.js +195 -0
- package/dist/agents/codex.js +98 -0
- package/dist/agents/copilot.js +39 -0
- package/dist/agents/cursor.js +41 -0
- package/dist/agents/index.js +26 -86
- package/dist/agents/snippets.js +7 -4
- package/dist/cli/args.js +19 -4
- package/dist/cli/commands/accounts.js +96 -51
- package/dist/cli/commands/auto.js +82 -32
- package/dist/cli/commands/browser.js +216 -135
- package/dist/cli/commands/complete.js +2 -1
- package/dist/cli/commands/completion.js +4 -2
- package/dist/cli/commands/config.js +103 -18
- package/dist/cli/commands/demo.js +292 -0
- package/dist/cli/commands/doctor.js +387 -119
- package/dist/cli/commands/handoff.js +33 -22
- package/dist/cli/commands/identity.js +101 -50
- package/dist/cli/commands/init.js +616 -0
- package/dist/cli/commands/limit.js +25 -13
- package/dist/cli/commands/mcp-oauth.js +194 -0
- package/dist/cli/commands/mcp-observe.js +434 -0
- package/dist/cli/commands/mcp.js +653 -185
- package/dist/cli/commands/mcpd.js +323 -75
- package/dist/cli/commands/migrate.js +6 -4
- package/dist/cli/commands/open.js +92 -27
- package/dist/cli/commands/profile.js +205 -69
- package/dist/cli/commands/resolve.js +6 -2
- package/dist/cli/commands/run.js +15 -5
- package/dist/cli/commands/secret.js +61 -42
- package/dist/cli/commands/session.js +2 -2
- package/dist/cli/commands/sessions.js +42 -12
- package/dist/cli/commands/setup.js +136 -158
- package/dist/cli/commands/status.js +172 -41
- package/dist/cli/commands/statusline.js +305 -113
- package/dist/cli/commands/ui.js +64 -66
- package/dist/cli/commands/undo.js +161 -18
- package/dist/cli/commands/uninstall.js +462 -0
- package/dist/cli/commands/upgrade.js +75 -19
- package/dist/cli/commands/usage.js +117 -44
- package/dist/cli/commands/version.js +7 -5
- package/dist/cli/commands/which.js +7 -24
- package/dist/cli/compile-cache.js +32 -0
- package/dist/cli/group.js +10 -10
- package/dist/cli/help.js +57 -0
- package/dist/cli/highlight.js +236 -0
- package/dist/cli/io.js +170 -1
- package/dist/cli/launch.js +21 -37
- package/dist/cli/launchers.js +145 -94
- package/dist/cli/main.js +163 -27
- package/dist/cli/picker.js +447 -0
- package/dist/cli/registry.js +42 -5
- package/dist/cli/security.js +539 -0
- package/dist/cli/style.js +281 -0
- package/dist/core/config.js +145 -23
- package/dist/core/exhausted.js +6 -8
- package/dist/core/fsutil.js +47 -0
- package/dist/core/journal.js +281 -11
- package/dist/core/manifest.js +126 -6
- package/dist/core/paths.js +114 -7
- package/dist/core/profiles.js +139 -9
- package/dist/core/resolve.js +129 -23
- package/dist/core/secrets.js +215 -20
- package/dist/core/sessions.js +13 -20
- package/dist/core/update.js +18 -8
- package/dist/core/version.js +6 -0
- package/dist/demo/server.js +34 -0
- package/dist/mcpd/cache.js +18 -4
- package/dist/mcpd/calllog.js +253 -0
- package/dist/mcpd/client-names.js +51 -0
- package/dist/mcpd/connectors.js +148 -17
- package/dist/mcpd/daemon.js +452 -116
- package/dist/mcpd/folder-sets.js +39 -0
- package/dist/mcpd/gateway.js +441 -47
- package/dist/mcpd/health.js +269 -0
- package/dist/mcpd/importer.js +356 -36
- package/dist/mcpd/instances.js +425 -65
- package/dist/mcpd/jsonrpc.js +8 -0
- package/dist/mcpd/launchd.js +65 -48
- package/dist/mcpd/modern.js +648 -0
- package/dist/mcpd/oauth.js +791 -0
- package/dist/mcpd/peerpid.js +122 -6
- package/dist/mcpd/pressure.js +85 -0
- package/dist/mcpd/rss.js +151 -0
- package/dist/mcpd/service.js +167 -0
- package/dist/mcpd/state.js +183 -0
- package/dist/mcpd/sync.js +55 -80
- package/dist/mcpd/systemd.js +80 -0
- package/dist/mcpd/tokens.js +89 -0
- package/dist/mcpd/upstream.js +154 -44
- package/dist/statusline/cost.js +154 -44
- package/dist/statusline/input.js +66 -0
- package/dist/statusline/render.js +9 -3
- package/dist/ui/fonts.js +8 -3
- package/dist/ui/settings.js +27 -15
- package/npm-shrinkwrap.json +1093 -0
- package/package.json +9 -9
- package/dist/cli/commands/available.js +0 -18
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
import { existsSync, statSync } from "node:fs";
|
|
2
2
|
import { resolve as resolvePath } from "node:path";
|
|
3
|
-
import {
|
|
3
|
+
import { delimiter } from "node:path";
|
|
4
|
+
import { DEFAULT_AGENT, adapter, agentHub, agentProfileDir, isAgentId, AGENT_IDS } from "../../agents/index.js";
|
|
4
5
|
import { editConfig } from "../../core/config-edit.js";
|
|
5
6
|
import { loadConfig } from "../../core/config.js";
|
|
6
7
|
import { exhaustedUntil } from "../../core/exhausted.js";
|
|
7
8
|
import { Journal } from "../../core/journal.js";
|
|
8
9
|
import { expandHome, paths, tildify } from "../../core/paths.js";
|
|
9
10
|
import { agentOf, listProfiles } from "../../core/profiles.js";
|
|
10
|
-
import { resolveProfile } from "../../core/resolve.js";
|
|
11
|
+
import { candidateRoots, folderMcpSet, resolveProfile } from "../../core/resolve.js";
|
|
11
12
|
import { addArrayTable, ensureTable, removeArrayTables, removeTable, setValue } from "../../core/toml-edit.js";
|
|
12
13
|
import { NAMED_COLORS } from "../../statusline/render.js";
|
|
13
|
-
import { DRY_RUN, JSON_FLAG, bool, parseFlags, printJson, str } from "../args.js";
|
|
14
|
+
import { DRY_RUN, JSON_FLAG, bool, flagsOf, parseFlags, printJson, str } from "../args.js";
|
|
14
15
|
import { group } from "../group.js";
|
|
15
|
-
import { fail } from "../io.js";
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
16
|
+
import { confirm, fail, needsAnswer, plural } from "../io.js";
|
|
17
|
+
import { profileColor, style } from "../style.js";
|
|
18
|
+
import { findOnPath, launcherPath } from "../launch.js";
|
|
19
|
+
import { isGenerated, launcherName, refuseNpx } from "../launchers.js";
|
|
20
|
+
import { checkName, localCopies, setupProfiles } from "./setup.js";
|
|
21
|
+
import { authStatus, shortTime } from "./usage.js";
|
|
20
22
|
/** A named color, or a 256-color code. */
|
|
21
|
-
export function parseColor(v) {
|
|
23
|
+
export function parseColor(v, label = "--color") {
|
|
22
24
|
if (/^\d+$/.test(v)) {
|
|
23
25
|
const n = Number(v);
|
|
24
26
|
if (n > 255)
|
|
25
|
-
fail(
|
|
27
|
+
fail(`${label} ${v}: a 256-color code goes from 0 to 255`);
|
|
26
28
|
return n;
|
|
27
29
|
}
|
|
28
30
|
if (NAMED_COLORS[v.toLowerCase()] === undefined)
|
|
29
|
-
fail(
|
|
31
|
+
fail(`${label} ${v}: use a number (0-255) or one of ${Object.keys(NAMED_COLORS).join(", ")}`);
|
|
30
32
|
return v.toLowerCase();
|
|
31
33
|
}
|
|
32
34
|
export async function profilesData(env, config, withAccounts = true) {
|
|
33
35
|
const names = listProfiles(config, env);
|
|
34
36
|
// Account details come from `claude auth status`; other agents show whether they are set up.
|
|
35
|
-
const auth = withAccounts ? await Promise.all(names.map((n) => (agentOf(n, config)
|
|
37
|
+
const auth = withAccounts ? await Promise.all(names.map((n) => (adapter(agentOf(n, config)).accountDetails ? authStatus(n, env) : undefined))) : [];
|
|
36
38
|
return names.map((name, i) => {
|
|
37
39
|
const s = auth[i];
|
|
38
40
|
const agent = agentOf(name, config);
|
|
@@ -56,85 +58,160 @@ async function list(args, io) {
|
|
|
56
58
|
const config = loadConfig(io.env);
|
|
57
59
|
const rows = await profilesData(io.env, config);
|
|
58
60
|
if (bool(p, "json")) {
|
|
59
|
-
printJson(io
|
|
61
|
+
printJson(io, rows);
|
|
60
62
|
return 0;
|
|
61
63
|
}
|
|
62
64
|
if (!rows.length) {
|
|
63
65
|
io.out("No profiles yet. Create one with: turno profile add <name>");
|
|
64
66
|
return 0;
|
|
65
67
|
}
|
|
66
|
-
const
|
|
67
|
-
|
|
68
|
-
const who = r.setUp
|
|
69
|
-
? r.agent !== "claude"
|
|
70
|
-
? `${adapter(r.agent).label} (${launcherName(r.name, r.agent)})`
|
|
71
|
-
: r.email
|
|
72
|
-
? `${r.email}${r.plan ? ` · ${r.plan}` : ""}`
|
|
73
|
-
: "not logged in"
|
|
74
|
-
: `not set up (turno profile repair ${r.name})`;
|
|
75
|
-
const extra = [r.roles.join(", "), r.projects ? `${r.projects} projects` : "", r.exhaustedUntil ? "exhausted" : ""].filter(Boolean).join(" · ");
|
|
76
|
-
io.out(`${r.name.padEnd(w)} ${who}${extra ? ` (${extra})` : ""}`);
|
|
77
|
-
}
|
|
68
|
+
for (const line of renderProfiles(rows, config, io))
|
|
69
|
+
io.out(line);
|
|
78
70
|
return 0;
|
|
79
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* `turno profile list` as lines: each profile as its pill, its agent, its account, how many
|
|
74
|
+
* folders use it, and its roles. Plain text (a pipe, NO_COLOR) keeps one row per profile
|
|
75
|
+
* starting with its name.
|
|
76
|
+
*/
|
|
77
|
+
export function renderProfiles(rows, config, io, now = Date.now() / 1000) {
|
|
78
|
+
const s = style(io);
|
|
79
|
+
const table = rows.map((r) => {
|
|
80
|
+
const a = adapter(r.agent);
|
|
81
|
+
const who = !r.setUp
|
|
82
|
+
? s.warn(`not set up (turno profile repair ${r.name})`)
|
|
83
|
+
: !a.accountDetails
|
|
84
|
+
? s.muted(s.color ? "-" : launcherName(r.name, r.agent))
|
|
85
|
+
: r.email
|
|
86
|
+
? `${r.email}${r.plan ? s.muted(` · ${r.plan}`) : ""}`
|
|
87
|
+
: s.warn("not logged in");
|
|
88
|
+
const exhausted = r.exhaustedUntil && r.exhaustedUntil > now ? s.warn(`exhausted until ${shortTime(r.exhaustedUntil)}`) : "";
|
|
89
|
+
const flags = [r.roles.join(", "), exhausted].filter(Boolean).join(s.muted(" · "));
|
|
90
|
+
return [s.profile(r.name, profileColor(config.profiles, r.name)), s.muted(a.label), who, s.muted(r.projects ? plural(r.projects, "folder") : "no folders"), flags];
|
|
91
|
+
});
|
|
92
|
+
if (!s.color)
|
|
93
|
+
return s.table(table, { indent: 0 });
|
|
94
|
+
// turno reads no account for agents without account details: a "-" there, not the launcher.
|
|
95
|
+
const head = ["", "agent", "account", "folders", "role"].map((h) => s.muted(h));
|
|
96
|
+
return [s.header("Profiles"), ...s.table([head, ...table], { columns: [{}, { drop: 2 }, {}, { drop: 1 }, {}] }), "", s.muted("turno <name> opens one; turno profile assign <dir> gives a folder its profile.")];
|
|
97
|
+
}
|
|
98
|
+
/** The PATH line for a shell, or undefined when `dir` is on PATH. */
|
|
99
|
+
export function pathAdvice(env, dir = paths(env).bin) {
|
|
100
|
+
if ((env.PATH ?? "").split(delimiter).some((d) => d.replace(/\/+$/, "") === dir))
|
|
101
|
+
return undefined;
|
|
102
|
+
const shell = (env.SHELL ?? "").split("/").pop();
|
|
103
|
+
const shown = tildify(dir, env).replace(/^~/, "$HOME");
|
|
104
|
+
if (shell === "fish")
|
|
105
|
+
return `Add to ~/.config/fish/config.fish: fish_add_path ${shown.replace("$HOME", "~")}`;
|
|
106
|
+
const rc = shell === "bash" ? "~/.bashrc" : "~/.zshrc";
|
|
107
|
+
return `Add to ${rc}: export PATH="${shown}:$PATH"`;
|
|
108
|
+
}
|
|
109
|
+
/** Warn when the folder of the launchers is not on PATH, so `claude-<name>` would not be found. */
|
|
110
|
+
export function warnPath(io, launcher) {
|
|
111
|
+
const advice = pathAdvice(io.env);
|
|
112
|
+
if (!advice)
|
|
113
|
+
return false;
|
|
114
|
+
io.err(`warning: ${tildify(paths(io.env).bin, io.env)} is not on your PATH, so ${launcher} will not be found. ${advice}`);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Before moving the person's own files aside: ask in a terminal, or need --yes. Returns false
|
|
119
|
+
* when the person said no.
|
|
120
|
+
*/
|
|
121
|
+
async function approveAside(cmd, names, io, yes) {
|
|
122
|
+
const own = localCopies(names, io.env).filter((x) => x.items.length);
|
|
123
|
+
if (!own.length || yes)
|
|
124
|
+
return true;
|
|
125
|
+
const text = own.map((x) => `${tildify(x.dir, io.env)} has its own ${x.items.join(", ")}`).join("; ");
|
|
126
|
+
const what = `${text}. turno moves ${own.length === 1 && own[0].items.length === 1 ? "it" : "them"} to .aside-<time>/ in that folder and links the shared ones instead.`;
|
|
127
|
+
io.err(what);
|
|
128
|
+
if (!io.ask)
|
|
129
|
+
needsAnswer(cmd);
|
|
130
|
+
if (await confirm(io, "Go ahead?"))
|
|
131
|
+
return true;
|
|
132
|
+
io.err("Nothing changed.");
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const ADD_SPEC = {
|
|
136
|
+
agent: { type: "string" },
|
|
137
|
+
color: { type: "string" },
|
|
138
|
+
browser: { type: "string" },
|
|
139
|
+
...DRY_RUN,
|
|
140
|
+
yes: { type: "boolean", short: "y" },
|
|
141
|
+
verbose: { type: "boolean", short: "v" },
|
|
142
|
+
};
|
|
80
143
|
async function add(args, io) {
|
|
81
|
-
const p = parseFlags(args,
|
|
144
|
+
const p = parseFlags(args, ADD_SPEC, 1);
|
|
82
145
|
const name = p.positionals[0];
|
|
83
146
|
if (!name)
|
|
84
|
-
return fail(
|
|
147
|
+
return fail(`usage: turno profile add <name> [--agent ${AGENT_IDS.join("|")}] [--color <c>] [--browser chrome|default]`);
|
|
85
148
|
checkName(name);
|
|
86
|
-
const agent = str(p, "agent") ??
|
|
149
|
+
const agent = str(p, "agent") ?? DEFAULT_AGENT;
|
|
87
150
|
if (!isAgentId(agent))
|
|
88
151
|
fail(`--agent must be one of ${AGENT_IDS.join(", ")}`);
|
|
89
152
|
const color = str(p, "color");
|
|
153
|
+
const parsedColor = color ? parseColor(color) : undefined;
|
|
90
154
|
const browser = str(p, "browser");
|
|
91
155
|
if (browser && browser !== "chrome" && browser !== "default")
|
|
92
156
|
fail("--browser must be chrome or default");
|
|
93
157
|
const dry = bool(p, "dry-run");
|
|
158
|
+
if (!dry) {
|
|
159
|
+
refuseNpx();
|
|
160
|
+
if (!(await approveAside("profile add", [name], io, bool(p, "yes"))))
|
|
161
|
+
return 1;
|
|
162
|
+
}
|
|
94
163
|
const journal = new Journal(io.env, `profile add ${name}`, dry);
|
|
95
164
|
const table = `profiles.${name}`;
|
|
96
165
|
const { changed } = editConfig(io.env, journal, (t) => {
|
|
97
166
|
let text = ensureTable(t, table);
|
|
98
|
-
if (agent !==
|
|
167
|
+
if (agent !== DEFAULT_AGENT)
|
|
99
168
|
text = setValue(text, table, "agent", agent);
|
|
100
|
-
if (
|
|
101
|
-
text = setValue(text, table, "color",
|
|
169
|
+
if (parsedColor !== undefined)
|
|
170
|
+
text = setValue(text, table, "color", parsedColor);
|
|
102
171
|
if (browser)
|
|
103
172
|
text = setValue(text, table, "browser", browser);
|
|
104
173
|
return text;
|
|
105
174
|
});
|
|
106
175
|
io.out(`${changed ? "+" : "="} [${table}] in ${tildify(paths(io.env).configFile, io.env)}${dry ? " (dry run)" : ""}`);
|
|
176
|
+
const a = adapter(agent);
|
|
177
|
+
if (!findOnPath(a.command, io.env))
|
|
178
|
+
io.err(`warning: ${a.command} is not installed yet (${a.install}); the profile works once it is`);
|
|
107
179
|
if (dry) {
|
|
108
180
|
io.out(`(dry run) would set up ${tildify(agentProfileDir(name, agent, io.env), io.env)} and the ${launcherName(name, agent)} command`);
|
|
109
181
|
return 0;
|
|
110
182
|
}
|
|
111
|
-
|
|
112
|
-
io
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
};
|
|
119
|
-
io.out(`Next: ${login[agent]}. turno profile list shows the profile.`);
|
|
183
|
+
// The same journal as the config.toml change: one `turno undo` reverts the whole profile add.
|
|
184
|
+
setupProfiles([name], io, { verbose: bool(p, "verbose"), journal });
|
|
185
|
+
const launcher = launcherName(name, agent);
|
|
186
|
+
const offPath = warnPath(io, launcher);
|
|
187
|
+
// `turno <name>` works without ~/.local/bin on PATH.
|
|
188
|
+
const run = offPath ? `turno ${name}` : launcher;
|
|
189
|
+
const sub = adapter(agent).loginSubcommand;
|
|
190
|
+
io.out(`Next: ${sub ? `run ${run} ${sub}` : `run ${run} and sign in with /login`}. turno profile list shows the profile.`);
|
|
120
191
|
const hint = journal.hint();
|
|
121
192
|
if (hint)
|
|
122
193
|
io.out(hint);
|
|
123
194
|
return 0;
|
|
124
195
|
}
|
|
196
|
+
const REPAIR_SPEC = { yes: { type: "boolean", short: "y" }, verbose: { type: "boolean", short: "v" } };
|
|
125
197
|
async function repair(args, io) {
|
|
126
|
-
const p = parseFlags(args,
|
|
198
|
+
const p = parseFlags(args, REPAIR_SPEC);
|
|
127
199
|
const names = p.positionals.length ? p.positionals : listProfiles(loadConfig(io.env), io.env);
|
|
128
200
|
if (!names.length)
|
|
129
201
|
return fail("no profiles to repair (turno profile add <name>)");
|
|
130
|
-
|
|
202
|
+
for (const n of names)
|
|
203
|
+
checkName(n);
|
|
204
|
+
refuseNpx();
|
|
205
|
+
if (!(await approveAside("profile repair", names, io, bool(p, "yes"))))
|
|
206
|
+
return 1;
|
|
207
|
+
setupProfiles(names, io, { verbose: bool(p, "verbose") });
|
|
131
208
|
return 0;
|
|
132
209
|
}
|
|
133
210
|
async function remove(args, io) {
|
|
134
211
|
const p = parseFlags(args, DRY_RUN, 1);
|
|
135
|
-
const
|
|
136
|
-
|
|
137
|
-
|
|
212
|
+
const dry = bool(p, "dry-run");
|
|
213
|
+
const picked = !p.positionals[0];
|
|
214
|
+
const name = p.positionals[0] ?? (await (await import("../picker.js")).pickProfile(io, { command: "profile remove", title: "Profile to remove" }));
|
|
138
215
|
const config = loadConfig(io.env);
|
|
139
216
|
if (!listProfiles(config, io.env).includes(name))
|
|
140
217
|
fail(`no profile '${name}'`);
|
|
@@ -142,20 +219,24 @@ async function remove(args, io) {
|
|
|
142
219
|
if (config[role] === name)
|
|
143
220
|
fail(`${name} is the ${role} profile; point ${role} elsewhere first (turno config set ${role} <profile>)`);
|
|
144
221
|
}
|
|
145
|
-
|
|
222
|
+
// A profile chosen in the picker is confirmed: one key should not remove an account.
|
|
223
|
+
if (picked && !dry && !(await confirm(io, `Remove ${name} from config.toml and its launcher? Its folder stays.`))) {
|
|
224
|
+
io.err("Nothing changed.");
|
|
225
|
+
return 1;
|
|
226
|
+
}
|
|
146
227
|
const journal = new Journal(io.env, `profile remove ${name}`, dry);
|
|
147
228
|
let rules = 0;
|
|
148
229
|
editConfig(io.env, journal, (t) => {
|
|
149
230
|
const r = removeArrayTables(removeTable(t, `profiles.${name}`), "projects", (e) => e.profile === name);
|
|
150
231
|
rules = r.removed;
|
|
151
|
-
return r.text;
|
|
232
|
+
return keepSets(r.text, config.projects.filter((x) => x.profile === name), io.env);
|
|
152
233
|
});
|
|
153
234
|
const agent = agentOf(name, config);
|
|
154
235
|
const launcher = launcherPath(name, io.env, agent);
|
|
155
236
|
if (launcher && isGenerated(launcher))
|
|
156
237
|
journal.remove(launcher);
|
|
157
238
|
const d = dry ? " (dry run)" : "";
|
|
158
|
-
io.out(`- [profiles.${name}] and ${rules
|
|
239
|
+
io.out(`- [profiles.${name}] and ${plural(rules, "project rule")} from config.toml${d}`);
|
|
159
240
|
if (launcher)
|
|
160
241
|
io.out(`- ${tildify(launcher, io.env)}${d}`);
|
|
161
242
|
io.out(`${tildify(agentProfileDir(name, agent, io.env), io.env)} stays (sign-in, history); delete it by hand when you no longer need it.`);
|
|
@@ -164,6 +245,23 @@ async function remove(args, io) {
|
|
|
164
245
|
io.out(hint);
|
|
165
246
|
return 0;
|
|
166
247
|
}
|
|
248
|
+
/** The server set keys of a rule (ADR 0031), to write back when its profile part goes. */
|
|
249
|
+
function setKeys(rule) {
|
|
250
|
+
return { ...(rule?.mcp ? { mcp: rule.mcp } : {}), ...(rule?.mcpDeny ? { mcp_deny: rule.mcpDeny } : {}) };
|
|
251
|
+
}
|
|
252
|
+
/** Write back, as rules of their own, the server sets of removed profile rules: the folder keeps them. */
|
|
253
|
+
function keepSets(text, removed, env) {
|
|
254
|
+
let out = text;
|
|
255
|
+
for (const r of removed)
|
|
256
|
+
if (r.mcp || r.mcpDeny)
|
|
257
|
+
out = addArrayTable(out, "projects", { path: tildify(r.path, env), ...setKeys(r) });
|
|
258
|
+
return out;
|
|
259
|
+
}
|
|
260
|
+
/** "only docs, not mail": what a folder's server set lets sessions see. */
|
|
261
|
+
function setText(set) {
|
|
262
|
+
const parts = [set.mcp ? `only ${set.mcp.join(", ") || "none"}` : "", set.mcpDeny ? `${set.mcp ? "not" : "all but"} ${set.mcpDeny.join(", ")}` : ""];
|
|
263
|
+
return parts.filter(Boolean).join(", ");
|
|
264
|
+
}
|
|
167
265
|
function folder(arg, io) {
|
|
168
266
|
const dir = resolvePath(expandHome(arg ?? process.cwd(), io.env));
|
|
169
267
|
let ok = false;
|
|
@@ -177,25 +275,50 @@ function folder(arg, io) {
|
|
|
177
275
|
fail(`no such folder: ${arg ?? dir}`);
|
|
178
276
|
return dir;
|
|
179
277
|
}
|
|
180
|
-
|
|
278
|
+
/** How a folder resolves for each agent that has profiles (Claude Code always). */
|
|
279
|
+
/** Each agent's resolution of `dir`; `roots` is computed once (one git call) for all of them. */
|
|
280
|
+
export function resolveAll(dir, config, env, roots = candidateRoots(dir)) {
|
|
281
|
+
const agents = AGENT_IDS.filter((a) => a === DEFAULT_AGENT || listProfiles(config, env, a).length > 0);
|
|
282
|
+
return agents.map((agent) => ({ agent, r: resolveProfile(dir, config, env, roots, agent) }));
|
|
283
|
+
}
|
|
284
|
+
/** "work (project ~/code)", or the plain agent and its home. */
|
|
285
|
+
export function usingText(agent, r, env) {
|
|
286
|
+
if (r.note)
|
|
287
|
+
return `${r.chosen} (${r.assigned} ${r.note})`;
|
|
288
|
+
return r.chosen ? `${r.chosen} (${r.reason})` : `plain ${adapter(agent).command} with ${tildify(agentHub(agent, env), env)} (${r.reason})`;
|
|
289
|
+
}
|
|
290
|
+
export async function whichCommand(args, io) {
|
|
181
291
|
const p = parseFlags(args, JSON_FLAG, 1);
|
|
182
292
|
const dir = folder(p.positionals[0], io);
|
|
183
|
-
const
|
|
293
|
+
const config = loadConfig(io.env);
|
|
294
|
+
const roots = candidateRoots(dir);
|
|
295
|
+
const all = resolveAll(dir, config, io.env, roots);
|
|
296
|
+
const r = all[0].r;
|
|
297
|
+
const set = folderMcpSet(roots, config.projects, r.chosen || undefined);
|
|
184
298
|
if (bool(p, "json")) {
|
|
185
|
-
|
|
299
|
+
const one = (x) => ({ assigned: x.assigned || null, chosen: x.chosen || null, reason: x.reason, note: x.note || null });
|
|
300
|
+
const mcp = set ? { rule: tildify(set.path, io.env), allow: set.mcp ?? null, deny: set.mcpDeny ?? null } : null;
|
|
301
|
+
printJson(io, { dir: tildify(dir, io.env), ...one(r), agents: Object.fromEntries(all.map(({ agent, r: x }) => [agent, one(x)])), mcp });
|
|
186
302
|
return 0;
|
|
187
303
|
}
|
|
188
304
|
io.out(tildify(dir, io.env));
|
|
189
305
|
io.out(` assigned: ${r.assigned || "none"} (${r.reason})`);
|
|
190
306
|
io.out(r.note ? ` using now: ${r.chosen} (${r.assigned} ${r.note})` : ` using now: ${r.chosen || "plain claude"}`);
|
|
307
|
+
for (const { agent, r: x } of all.slice(1))
|
|
308
|
+
io.out(` ${agent}: ${usingText(agent, x, io.env)}`);
|
|
309
|
+
if (set)
|
|
310
|
+
io.out(` mcp: ${setText(set)} (rule ${tildify(set.path, io.env)})`);
|
|
191
311
|
return 0;
|
|
192
312
|
}
|
|
193
313
|
async function assign(args, io) {
|
|
194
314
|
const p = parseFlags(args, DRY_RUN, 2);
|
|
195
|
-
const [dirArg,
|
|
196
|
-
if (
|
|
197
|
-
|
|
315
|
+
const [dirArg, given] = p.positionals;
|
|
316
|
+
if (dirArg && !given && !existsSync(expandHome(dirArg, io.env)) && listProfiles(loadConfig(io.env), io.env).includes(dirArg)) {
|
|
317
|
+
fail(`no such folder: ${dirArg} (to give this folder the profile ${dirArg}: turno profile assign . ${dirArg})`);
|
|
318
|
+
}
|
|
198
319
|
const dir = folder(dirArg, io);
|
|
320
|
+
const name = given ??
|
|
321
|
+
(await (await import("../picker.js")).pickProfile(io, { command: "profile assign", title: `Profile for ${tildify(dir, io.env)}`, dir }));
|
|
199
322
|
const config = loadConfig(io.env);
|
|
200
323
|
if (!listProfiles(config, io.env).includes(name))
|
|
201
324
|
fail(`no profile '${name}' (turno profile list)`);
|
|
@@ -203,11 +326,12 @@ async function assign(args, io) {
|
|
|
203
326
|
const journal = new Journal(io.env, `profile assign ${tildify(dir, io.env)} ${name}`, dry);
|
|
204
327
|
const shown = tildify(dir, io.env);
|
|
205
328
|
// One rule per folder and agent: a Codex rule does not replace the folder's Claude Code rule.
|
|
329
|
+
// A rule with only a server set (ADR 0031) is not a profile rule and stays; a replaced rule
|
|
330
|
+
// passes its set on to the new one.
|
|
206
331
|
const agent = agentOf(name, config);
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
});
|
|
332
|
+
const same = (e) => e.profile !== undefined && resolvePath(expandHome(e.path ?? "", io.env)) === dir && agentOf(e.profile, config) === agent;
|
|
333
|
+
const carried = config.projects.find((r) => same(r) && (r.mcp || r.mcpDeny));
|
|
334
|
+
editConfig(io.env, journal, (t) => addArrayTable(removeArrayTables(t, "projects", same).text, "projects", { path: shown, profile: name, ...setKeys(carried) }));
|
|
211
335
|
io.out(`${shown} -> ${name}${dry ? " (dry run)" : ""}`);
|
|
212
336
|
const hint = journal.hint();
|
|
213
337
|
if (hint)
|
|
@@ -219,11 +343,14 @@ async function unassign(args, io) {
|
|
|
219
343
|
const dir = resolvePath(expandHome(p.positionals[0] ?? process.cwd(), io.env));
|
|
220
344
|
const dry = bool(p, "dry-run");
|
|
221
345
|
const journal = new Journal(io.env, `profile unassign ${tildify(dir, io.env)}`, dry);
|
|
346
|
+
const config = loadConfig(io.env);
|
|
347
|
+
// Profile rules only: the folder keeps its server set (ADR 0031).
|
|
348
|
+
const own = (e) => e.profile !== undefined && resolvePath(expandHome(e.path ?? "", io.env)) === dir;
|
|
222
349
|
let removed = 0;
|
|
223
350
|
editConfig(io.env, journal, (t) => {
|
|
224
|
-
const r = removeArrayTables(t, "projects",
|
|
351
|
+
const r = removeArrayTables(t, "projects", own);
|
|
225
352
|
removed = r.removed;
|
|
226
|
-
return r.text;
|
|
353
|
+
return removed ? keepSets(r.text, config.projects.filter(own), io.env) : t;
|
|
227
354
|
});
|
|
228
355
|
if (!removed) {
|
|
229
356
|
io.out(`${tildify(dir, io.env)} has no rule of its own (turno profile which explains what applies)`);
|
|
@@ -235,25 +362,34 @@ async function unassign(args, io) {
|
|
|
235
362
|
io.out(hint);
|
|
236
363
|
return 0;
|
|
237
364
|
}
|
|
238
|
-
export const command = group("profile", "
|
|
365
|
+
export const command = group("profile", "accounts (profiles) for each agent: list, add, repair, remove, and which folders use each", {
|
|
239
366
|
list: { summary: "each profile, its account and roles", synopsis: "[--json]", flags: ["--json"], run: list },
|
|
240
367
|
add: {
|
|
241
|
-
summary: "declare a profile in config.toml and set up its folder and launcher (claude-<name>, codex-<name>, ...)",
|
|
242
|
-
synopsis: "<name> [--agent claude|codex|copilot|cursor] [--color <c>] [--browser chrome|default] [--dry-run]",
|
|
368
|
+
summary: "declare a profile in config.toml and set up its folder and launcher (claude-<name>, codex-<name>, ...); asks before moving your own files aside (--yes skips the question), -v lists every shared item; turno undo reverts all of it",
|
|
369
|
+
synopsis: "<name> [--agent claude|codex|copilot|cursor] [--color <c>] [--browser chrome|default] [--dry-run] [--yes] [-v]",
|
|
243
370
|
args: ["any"],
|
|
244
|
-
flags:
|
|
371
|
+
flags: flagsOf(ADD_SPEC),
|
|
245
372
|
run: add,
|
|
246
373
|
},
|
|
247
|
-
repair: {
|
|
374
|
+
repair: {
|
|
375
|
+
summary: "relink shared folders and rewrite launchers (all profiles by default); turno undo reverts it",
|
|
376
|
+
synopsis: "[profile...] [--yes] [-v]",
|
|
377
|
+
args: ["profile"],
|
|
378
|
+
flags: flagsOf(REPAIR_SPEC),
|
|
379
|
+
run: repair,
|
|
380
|
+
},
|
|
248
381
|
remove: {
|
|
249
|
-
summary: "drop a profile from config.toml and its launcher (its folder stays)",
|
|
250
|
-
synopsis: "
|
|
382
|
+
summary: "drop a profile from config.toml and its launcher (its folder stays); without a name, choose one and confirm",
|
|
383
|
+
synopsis: "[name] [--dry-run]",
|
|
251
384
|
args: ["profile"],
|
|
252
385
|
flags: ["--dry-run"],
|
|
253
386
|
run: remove,
|
|
254
387
|
},
|
|
255
|
-
which: { summary: "which profile auto uses in a folder, and why", synopsis: "[dir] [--json]", args: ["dir"], flags: ["--json"], run:
|
|
256
|
-
assign: {
|
|
388
|
+
which: { summary: "which profile auto uses in a folder for each agent, and why", synopsis: "[dir] [--json]", args: ["dir"], flags: ["--json"], run: whichCommand },
|
|
389
|
+
assign: {
|
|
390
|
+
summary: "make a folder (and everything under it) use a profile; without a profile, choose one from a list",
|
|
391
|
+
synopsis: "[dir] [profile] [--dry-run]", args: ["dir", "profile"], flags: ["--dry-run"], run: assign
|
|
392
|
+
},
|
|
257
393
|
unassign: { summary: "remove a folder's own rule", synopsis: "[dir] [--dry-run]", args: ["dir"], flags: ["--dry-run"], run: unassign },
|
|
258
394
|
}, { fallback: "list" });
|
|
259
395
|
//# sourceMappingURL=profile.js.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { resolve as resolvePath } from "node:path";
|
|
2
2
|
import { loadConfig } from "../../core/config.js";
|
|
3
3
|
import { resolveProfile } from "../../core/resolve.js";
|
|
4
|
+
import { JSON_FLAG, bool, flagsOf, parseFlags } from "../args.js";
|
|
4
5
|
/** Field separator of the machine output read by status lines. */
|
|
5
6
|
export const SEP = "\x1f";
|
|
6
7
|
export const command = {
|
|
@@ -12,9 +13,12 @@ export const command = {
|
|
|
12
13
|
"or a JSON object with --json.",
|
|
13
14
|
].join("\n"),
|
|
14
15
|
hidden: true,
|
|
16
|
+
args: ["dir"],
|
|
17
|
+
flags: flagsOf(JSON_FLAG),
|
|
15
18
|
async run(args, io) {
|
|
16
|
-
const
|
|
17
|
-
const
|
|
19
|
+
const p = parseFlags(args, JSON_FLAG, 1);
|
|
20
|
+
const json = bool(p, "json");
|
|
21
|
+
const dir = p.positionals[0];
|
|
18
22
|
const r = resolveProfile(resolvePath(dir ?? process.cwd()), loadConfig(io.env), io.env);
|
|
19
23
|
io.out(json ? JSON.stringify(r) : [r.chosen, r.assigned, r.reason, r.note].join(SEP));
|
|
20
24
|
return 0;
|
package/dist/cli/commands/run.js
CHANGED
|
@@ -1,14 +1,24 @@
|
|
|
1
|
-
import { fail } from "../io.js";
|
|
2
1
|
import { launchProfile } from "../launch.js";
|
|
3
2
|
import { command as auto } from "./auto.js";
|
|
4
3
|
export const command = {
|
|
5
4
|
summary: "open a profile with its agent (turno <profile> is the short form), or auto",
|
|
6
|
-
usage:
|
|
5
|
+
usage: [
|
|
6
|
+
"Usage: turno run <profile|auto> [agent args]",
|
|
7
|
+
"",
|
|
8
|
+
"Everything after the profile goes to its agent, for example:",
|
|
9
|
+
" turno run work --resume",
|
|
10
|
+
"",
|
|
11
|
+
"Without a profile, a terminal shows the profiles to choose from. When this",
|
|
12
|
+
"folder resolves to a profile, auto comes first, named with it: auto (work).",
|
|
13
|
+
].join("\n"),
|
|
7
14
|
args: ["profile-or-auto"],
|
|
8
15
|
async run(args, io) {
|
|
9
|
-
|
|
10
|
-
if (!name)
|
|
11
|
-
|
|
16
|
+
let [name, ...rest] = args;
|
|
17
|
+
if (!name) {
|
|
18
|
+
const { pickProfile } = await import("../picker.js");
|
|
19
|
+
name = await pickProfile(io, { command: "run", title: "Profile to open", extra: ["auto"], auto: true });
|
|
20
|
+
rest = [];
|
|
21
|
+
}
|
|
12
22
|
return name === "auto" ? auto.run(rest, io) : launchProfile(name, rest, io);
|
|
13
23
|
},
|
|
14
24
|
};
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
import { execFile } from "node:child_process";
|
|
2
|
-
import { promisify } from "node:util";
|
|
3
|
-
import { storeKeychainSecret } from "../../core/secrets.js";
|
|
4
1
|
import { readFileSync } from "node:fs";
|
|
5
2
|
import { paths, tildify } from "../../core/paths.js";
|
|
6
|
-
import {
|
|
7
|
-
|
|
3
|
+
import { SecretError, requireSecretStore } from "../../core/secrets.js";
|
|
4
|
+
import { JSON_FLAG, bool, flagsOf, parseFlags } from "../args.js";
|
|
5
|
+
import { fail, needsAnswer, noInputReason } from "../io.js";
|
|
8
6
|
const USAGE = `Usage:
|
|
9
|
-
turno secret set <service> read a value from stdin and store it
|
|
10
|
-
turno secret has <service> exit 0 when the
|
|
11
|
-
turno secret rm <service> delete the
|
|
7
|
+
turno secret set <service> read a value from stdin and store it
|
|
8
|
+
turno secret has <service> exit 0 when the item exists
|
|
9
|
+
turno secret rm <service> delete the item
|
|
12
10
|
turno secret list [--json] every keychain: reference in mcp.toml and whether it is stored
|
|
13
11
|
|
|
14
|
-
Reference it in mcp.toml as "keychain:<service>". Values are never printed
|
|
12
|
+
Reference it in mcp.toml as "keychain:<service>". Values are never printed and never passed
|
|
13
|
+
as a command argument. The store is the login Keychain on macOS and the Secret Service
|
|
14
|
+
(libsecret's secret-tool, attributes service=turno account=<service>) on Linux. Without
|
|
15
|
+
either, use "env:NAME" references.`;
|
|
15
16
|
async function readStdin() {
|
|
16
17
|
if (process.stdin.isTTY) {
|
|
17
18
|
process.stderr.write("value (input hidden, end with Enter): ");
|
|
@@ -47,14 +48,13 @@ async function readStdin() {
|
|
|
47
48
|
chunks.push(c);
|
|
48
49
|
return Buffer.concat(chunks).toString("utf8").replace(/\r?\n$/, "");
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
/** The store, with its SecretError turned into a one-line usage error. */
|
|
52
|
+
function store(io) {
|
|
51
53
|
try {
|
|
52
|
-
|
|
53
|
-
await run("security", ["find-generic-password", "-s", service], { timeout: 10_000 });
|
|
54
|
-
return true;
|
|
54
|
+
return requireSecretStore(io.env);
|
|
55
55
|
}
|
|
56
|
-
catch {
|
|
57
|
-
return
|
|
56
|
+
catch (err) {
|
|
57
|
+
return fail(err.message);
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
/** keychain:<service> references in mcp.toml. */
|
|
@@ -62,7 +62,7 @@ export function keychainRefs(text) {
|
|
|
62
62
|
return [...new Set([...text.matchAll(/"keychain:([^"\\]+)"/g)].map((m) => m[1]))].sort();
|
|
63
63
|
}
|
|
64
64
|
async function list(args, io) {
|
|
65
|
-
const json = args
|
|
65
|
+
const json = bool(parseFlags(args, JSON_FLAG, 0), "json");
|
|
66
66
|
let text = "";
|
|
67
67
|
try {
|
|
68
68
|
text = readFileSync(paths(io.env).mcpFile, "utf8");
|
|
@@ -71,7 +71,8 @@ async function list(args, io) {
|
|
|
71
71
|
text = "";
|
|
72
72
|
}
|
|
73
73
|
const refs = keychainRefs(text);
|
|
74
|
-
const
|
|
74
|
+
const s = refs.length ? store(io) : undefined;
|
|
75
|
+
const found = s ? await Promise.all(refs.map((r) => s.has(r))) : [];
|
|
75
76
|
if (json) {
|
|
76
77
|
io.out(JSON.stringify(refs.map((r, i) => ({ service: r, stored: found[i] })), null, 2));
|
|
77
78
|
return 0;
|
|
@@ -83,40 +84,58 @@ async function list(args, io) {
|
|
|
83
84
|
return found.every(Boolean) ? 0 : 1;
|
|
84
85
|
}
|
|
85
86
|
export const command = {
|
|
86
|
-
summary: "store MCP secrets in the macOS
|
|
87
|
+
summary: "store MCP secrets in the Keychain (macOS) or the Secret Service (Linux)",
|
|
87
88
|
usage: USAGE,
|
|
88
|
-
subcommands: { set: { args: ["any"] }, has: { args: ["any"] }, rm: { args: ["any"] }, list: { flags:
|
|
89
|
+
subcommands: { set: { args: ["any"] }, has: { args: ["any"] }, rm: { args: ["any"] }, list: { flags: flagsOf(JSON_FLAG) } },
|
|
89
90
|
async run(args, io) {
|
|
90
|
-
const [sub
|
|
91
|
+
const [sub] = args;
|
|
92
|
+
const rest = args.slice(1);
|
|
93
|
+
if (sub === "--help" || sub === "-h" || sub === "help" || rest.includes("--help") || rest.includes("-h")) {
|
|
94
|
+
io.out(USAGE);
|
|
95
|
+
return 0;
|
|
96
|
+
}
|
|
91
97
|
if (sub === "list" || sub === undefined)
|
|
92
|
-
return list(
|
|
98
|
+
return list(rest, io);
|
|
99
|
+
// One service name and no flags: an unknown flag must not become a service name.
|
|
100
|
+
const service = parseFlags(rest, {}, 1).positionals[0];
|
|
93
101
|
if (!service)
|
|
94
102
|
return fail(USAGE);
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
io.out(`keychain:${service} exists`);
|
|
103
|
+
try {
|
|
104
|
+
switch (sub) {
|
|
105
|
+
case "set": {
|
|
106
|
+
const s = store(io);
|
|
107
|
+
// The hidden prompt waits for a person: never with --no-input or inside an agent.
|
|
108
|
+
if (process.stdin.isTTY && noInputReason(io.env))
|
|
109
|
+
needsAnswer("secret set", "the value on stdin");
|
|
110
|
+
const value = await readStdin();
|
|
111
|
+
if (!value)
|
|
112
|
+
return fail("empty value");
|
|
113
|
+
await s.set(service, value);
|
|
114
|
+
io.out(`stored keychain:${service}`);
|
|
108
115
|
return 0;
|
|
109
116
|
}
|
|
110
|
-
|
|
117
|
+
case "has":
|
|
118
|
+
if (await store(io).has(service)) {
|
|
119
|
+
io.out(`keychain:${service} exists`);
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
111
122
|
io.out(`keychain:${service} not found`);
|
|
112
123
|
return 1;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
124
|
+
case "rm":
|
|
125
|
+
if (!(await store(io).remove(service))) {
|
|
126
|
+
io.out(`keychain:${service} not found`);
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
io.out(`removed keychain:${service}`);
|
|
130
|
+
return 0;
|
|
131
|
+
default:
|
|
132
|
+
return fail(USAGE);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
if (err instanceof SecretError)
|
|
137
|
+
return fail(err.message);
|
|
138
|
+
throw err;
|
|
120
139
|
}
|
|
121
140
|
},
|
|
122
141
|
};
|