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
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Choose a profile when a command needs one and the argument is missing (ADR 0036). A small
|
|
3
|
+
* picker with no dependencies: arrow keys or j/k move, typing filters, Enter chooses, Esc or
|
|
4
|
+
* Ctrl-C cancels. It draws on stderr and reads stdin in raw mode, only when both are terminals;
|
|
5
|
+
* the terminal is restored on every way out (a choice, a cancel, an error, a signal).
|
|
6
|
+
*
|
|
7
|
+
* Where nobody can answer (no terminal, --no-input, an agent session: `io.ask` is unset) the
|
|
8
|
+
* command fails with exit 2 and the valid values instead.
|
|
9
|
+
*
|
|
10
|
+
* The key handling is a pure state machine (`parseKeys`, `reduce`), so tests drive it without a
|
|
11
|
+
* terminal. Loaded lazily by the commands that use it.
|
|
12
|
+
*/
|
|
13
|
+
import { DEFAULT_AGENT, adapter } from "../agents/index.js";
|
|
14
|
+
import { loadConfig } from "../core/config.js";
|
|
15
|
+
import { exhaustedUntil } from "../core/exhausted.js";
|
|
16
|
+
import { agentOf, listProfiles } from "../core/profiles.js";
|
|
17
|
+
import { candidateRoots, resolveProfile } from "../core/resolve.js";
|
|
18
|
+
import { CliError, fail, needsAnswer } from "./io.js";
|
|
19
|
+
import { launcherPath } from "./launch.js";
|
|
20
|
+
import { profileColor, style, visibleWidth } from "./style.js";
|
|
21
|
+
/** Rows a page key moves. */
|
|
22
|
+
const PAGE = 5;
|
|
23
|
+
/** Items that match the query: the name first, then the other fields; case does not matter. */
|
|
24
|
+
export function matching(state) {
|
|
25
|
+
const q = state.query.trim().toLowerCase();
|
|
26
|
+
if (!q)
|
|
27
|
+
return [...state.items];
|
|
28
|
+
const byName = state.items.filter((i) => i.value.toLowerCase().includes(q));
|
|
29
|
+
const byOther = state.items.filter((i) => !byName.includes(i) && i.search.toLowerCase().includes(q));
|
|
30
|
+
return [...byName, ...byOther];
|
|
31
|
+
}
|
|
32
|
+
/** The first state: the cursor on `initial` when it is one of the items. */
|
|
33
|
+
export function initialState(items, initial) {
|
|
34
|
+
return { items, query: "", cursor: Math.max(0, items.findIndex((i) => i.value === initial)) };
|
|
35
|
+
}
|
|
36
|
+
/** The item under the cursor, if any matches. */
|
|
37
|
+
export function selected(state) {
|
|
38
|
+
return matching(state)[state.cursor];
|
|
39
|
+
}
|
|
40
|
+
/** The same state with new items (accounts arrived), the cursor kept on the same value. */
|
|
41
|
+
export function withItems(state, items) {
|
|
42
|
+
const value = selected(state)?.value;
|
|
43
|
+
const next = { ...state, items };
|
|
44
|
+
const idx = matching(next).findIndex((i) => i.value === value);
|
|
45
|
+
return { ...next, cursor: Math.max(0, idx) };
|
|
46
|
+
}
|
|
47
|
+
/** A new query: the cursor stays on the same item while it still matches, else goes to the first. */
|
|
48
|
+
function requery(state, query) {
|
|
49
|
+
const value = selected(state)?.value;
|
|
50
|
+
const next = { ...state, query };
|
|
51
|
+
const idx = matching(next).findIndex((i) => i.value === value);
|
|
52
|
+
return { ...next, cursor: Math.max(0, idx) };
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* One key applied to the state. j and k move while the filter is empty (once typing starts they
|
|
56
|
+
* are letters); arrows and Ctrl-N/Ctrl-P always move. Enter with nothing matching does nothing.
|
|
57
|
+
*/
|
|
58
|
+
export function reduce(state, key) {
|
|
59
|
+
const n = matching(state).length;
|
|
60
|
+
const move = (to) => ({ state: { ...state, cursor: n ? Math.min(Math.max(to, 0), n - 1) : 0 } });
|
|
61
|
+
switch (key.name) {
|
|
62
|
+
case "up":
|
|
63
|
+
return move(state.cursor - 1 < 0 ? n - 1 : state.cursor - 1);
|
|
64
|
+
case "down":
|
|
65
|
+
return move(state.cursor + 1 >= n ? 0 : state.cursor + 1);
|
|
66
|
+
case "pageUp":
|
|
67
|
+
return move(state.cursor - PAGE);
|
|
68
|
+
case "pageDown":
|
|
69
|
+
return move(state.cursor + PAGE);
|
|
70
|
+
case "home":
|
|
71
|
+
return move(0);
|
|
72
|
+
case "end":
|
|
73
|
+
return move(n - 1);
|
|
74
|
+
case "cancel":
|
|
75
|
+
return { state, outcome: { kind: "cancel" } };
|
|
76
|
+
case "enter": {
|
|
77
|
+
const item = selected(state);
|
|
78
|
+
return item ? { state, outcome: { kind: "pick", value: item.value } } : { state };
|
|
79
|
+
}
|
|
80
|
+
case "backspace":
|
|
81
|
+
return { state: requery(state, [...state.query].slice(0, -1).join("")) };
|
|
82
|
+
case "clear":
|
|
83
|
+
return { state: requery(state, "") };
|
|
84
|
+
case "char":
|
|
85
|
+
if (!state.query && (key.ch === "j" || key.ch === "k"))
|
|
86
|
+
return reduce(state, { name: key.ch === "j" ? "down" : "up" });
|
|
87
|
+
if (!state.query && key.ch === " ")
|
|
88
|
+
return { state };
|
|
89
|
+
return { state: requery(state, state.query + key.ch) };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
const CSI_KEYS = {
|
|
93
|
+
A: "up",
|
|
94
|
+
B: "down",
|
|
95
|
+
H: "home",
|
|
96
|
+
F: "end",
|
|
97
|
+
"1~": "home",
|
|
98
|
+
"7~": "home",
|
|
99
|
+
"4~": "end",
|
|
100
|
+
"8~": "end",
|
|
101
|
+
"5~": "pageUp",
|
|
102
|
+
"6~": "pageDown",
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Keys in a chunk of raw terminal input. A lone Esc (no sequence after it) cancels; escape
|
|
106
|
+
* sequences the picker does not use are skipped whole.
|
|
107
|
+
*/
|
|
108
|
+
export function parseKeys(chunk) {
|
|
109
|
+
const keys = [];
|
|
110
|
+
const chars = [...chunk];
|
|
111
|
+
for (let i = 0; i < chars.length; i++) {
|
|
112
|
+
const c = chars[i];
|
|
113
|
+
if (c === "\x1b") {
|
|
114
|
+
const next = chars[i + 1];
|
|
115
|
+
if (next === "[" || next === "O") {
|
|
116
|
+
let j = i + 2;
|
|
117
|
+
let params = "";
|
|
118
|
+
while (j < chars.length && /[0-9;]/.test(chars[j]))
|
|
119
|
+
params += chars[j++];
|
|
120
|
+
const final = chars[j] ?? "";
|
|
121
|
+
const name = CSI_KEYS[final === "~" ? `${params}~` : final];
|
|
122
|
+
if (name)
|
|
123
|
+
keys.push({ name });
|
|
124
|
+
i = j;
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
keys.push({ name: "cancel" });
|
|
128
|
+
// Alt+key arrives as Esc then the key: both belong to the cancel.
|
|
129
|
+
if (next !== undefined)
|
|
130
|
+
i++;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (c === "\r" || c === "\n")
|
|
134
|
+
keys.push({ name: "enter" });
|
|
135
|
+
else if (c === "\x03" || c === "\x04")
|
|
136
|
+
keys.push({ name: "cancel" });
|
|
137
|
+
else if (c === "\x7f" || c === "\b")
|
|
138
|
+
keys.push({ name: "backspace" });
|
|
139
|
+
else if (c === "\x15")
|
|
140
|
+
keys.push({ name: "clear" });
|
|
141
|
+
else if (c === "\x0e")
|
|
142
|
+
keys.push({ name: "down" });
|
|
143
|
+
else if (c === "\x10")
|
|
144
|
+
keys.push({ name: "up" });
|
|
145
|
+
else if (c === "\t")
|
|
146
|
+
keys.push({ name: "down" });
|
|
147
|
+
else if (c >= " ")
|
|
148
|
+
keys.push({ name: "char", ch: c });
|
|
149
|
+
}
|
|
150
|
+
return keys;
|
|
151
|
+
}
|
|
152
|
+
/** The picker as lines: a title (with the filter), the matching rows, then the keys. */
|
|
153
|
+
export function renderPicker(state, s, opts) {
|
|
154
|
+
const shown = matching(state);
|
|
155
|
+
const ascii = s.icons === "ascii";
|
|
156
|
+
const pointer = ascii ? ">" : s.accent("❯");
|
|
157
|
+
const blank = " ".repeat(visibleWidth(pointer));
|
|
158
|
+
const title = `${s.accent("?")} ${s.bold(opts.title)}`;
|
|
159
|
+
const out = [state.query ? `${title} ${s.muted("filter")} ${state.query}${s.muted("_")}` : title];
|
|
160
|
+
const rows = Math.max(1, opts.maxRows);
|
|
161
|
+
const start = Math.max(0, Math.min(state.cursor - Math.floor(rows / 2), shown.length - rows));
|
|
162
|
+
const page = shown.slice(start, start + rows);
|
|
163
|
+
if (!shown.length)
|
|
164
|
+
out.push(` ${s.muted(`no profile matches "${state.query}"`)}`);
|
|
165
|
+
const cells = page.map((item, k) => {
|
|
166
|
+
const on = start + k === state.cursor;
|
|
167
|
+
const [name = "", ...rest] = item.cells;
|
|
168
|
+
return [`${on ? pointer : blank} ${name}`, ...rest.map((c) => (on ? c : s.muted(c)))];
|
|
169
|
+
});
|
|
170
|
+
// The agent column goes first on a narrow terminal, then the account; the mark stays.
|
|
171
|
+
out.push(...s.table(cells, { indent: 1, columns: [{}, { drop: 2 }, { drop: 1 }, {}] }));
|
|
172
|
+
const hidden = shown.length - page.length;
|
|
173
|
+
if (hidden > 0)
|
|
174
|
+
out.push(` ${s.muted(`${hidden} more`)}`);
|
|
175
|
+
const hint = ascii ? "up/down or j/k move, type to filter, enter choose, esc cancel" : "↑↓ or j/k move · type to filter · enter choose · esc cancel";
|
|
176
|
+
out.push(` ${s.muted(hint)}`);
|
|
177
|
+
return out;
|
|
178
|
+
}
|
|
179
|
+
const SHOW_CURSOR = "\x1b[?25h";
|
|
180
|
+
const HIDE_CURSOR = "\x1b[?25l";
|
|
181
|
+
const SIGNALS = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
182
|
+
/**
|
|
183
|
+
* The real terminal: raw stdin, drawing on stderr. A signal while the picker is open restores
|
|
184
|
+
* the terminal (raw mode off, cursor shown) and then ends the process as the signal would.
|
|
185
|
+
*/
|
|
186
|
+
export function realTerminal(input = process.stdin, output = process.stderr, proc = process) {
|
|
187
|
+
return {
|
|
188
|
+
columns: () => output.columns || 80,
|
|
189
|
+
rows: () => output.rows || 24,
|
|
190
|
+
write: (text) => {
|
|
191
|
+
output.write(text);
|
|
192
|
+
},
|
|
193
|
+
start(onData, onResize) {
|
|
194
|
+
const wasRaw = Boolean(input.isRaw);
|
|
195
|
+
let restored = false;
|
|
196
|
+
const restore = () => {
|
|
197
|
+
if (restored)
|
|
198
|
+
return;
|
|
199
|
+
restored = true;
|
|
200
|
+
input.off("data", onData);
|
|
201
|
+
if (onResize)
|
|
202
|
+
output.off("resize", onResize);
|
|
203
|
+
for (const sig of SIGNALS)
|
|
204
|
+
proc.off(sig, onSignal);
|
|
205
|
+
proc.off("exit", restore);
|
|
206
|
+
try {
|
|
207
|
+
input.setRawMode(wasRaw);
|
|
208
|
+
}
|
|
209
|
+
catch {
|
|
210
|
+
/* the terminal is gone */
|
|
211
|
+
}
|
|
212
|
+
input.pause();
|
|
213
|
+
output.write(SHOW_CURSOR);
|
|
214
|
+
};
|
|
215
|
+
const onSignal = (sig) => {
|
|
216
|
+
restore();
|
|
217
|
+
proc.kill(proc.pid, sig);
|
|
218
|
+
};
|
|
219
|
+
for (const sig of SIGNALS)
|
|
220
|
+
proc.on(sig, onSignal);
|
|
221
|
+
proc.on("exit", restore);
|
|
222
|
+
try {
|
|
223
|
+
input.setRawMode(true);
|
|
224
|
+
input.setEncoding("utf8");
|
|
225
|
+
input.on("data", onData);
|
|
226
|
+
if (onResize)
|
|
227
|
+
output.on("resize", onResize);
|
|
228
|
+
input.resume();
|
|
229
|
+
}
|
|
230
|
+
catch (err) {
|
|
231
|
+
restore();
|
|
232
|
+
throw err;
|
|
233
|
+
}
|
|
234
|
+
return restore;
|
|
235
|
+
},
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/** Physical rows `lines` take on a terminal `columns` wide (long lines wrap). */
|
|
239
|
+
function physicalRows(lines, columns) {
|
|
240
|
+
return lines.reduce((n, l) => n + Math.max(1, Math.ceil(visibleWidth(l) / Math.max(1, columns))), 0);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Run the picker on `term`. Resolves with the chosen value, or undefined when cancelled. The
|
|
244
|
+
* picker's lines are erased at the end, and the terminal is restored on every path.
|
|
245
|
+
*/
|
|
246
|
+
export function runPicker(term, s, items, opts) {
|
|
247
|
+
return new Promise((resolve, reject) => {
|
|
248
|
+
let state = initialState(items, opts.initial);
|
|
249
|
+
let drawn = 0;
|
|
250
|
+
let done = false;
|
|
251
|
+
let stop;
|
|
252
|
+
const erase = () => {
|
|
253
|
+
if (drawn > 0)
|
|
254
|
+
term.write(`\r${drawn > 1 ? `\x1b[${drawn - 1}A` : ""}\x1b[J`);
|
|
255
|
+
drawn = 0;
|
|
256
|
+
};
|
|
257
|
+
const draw = () => {
|
|
258
|
+
const maxRows = Math.max(3, Math.min(opts.maxRows, term.rows() - 4));
|
|
259
|
+
const lines = renderPicker(state, opts.styleAt ? opts.styleAt(term.columns()) : s, { ...opts, maxRows });
|
|
260
|
+
erase();
|
|
261
|
+
term.write(lines.join("\n"));
|
|
262
|
+
drawn = physicalRows(lines, term.columns());
|
|
263
|
+
};
|
|
264
|
+
const finish = (err, value) => {
|
|
265
|
+
if (done)
|
|
266
|
+
return;
|
|
267
|
+
done = true;
|
|
268
|
+
try {
|
|
269
|
+
erase();
|
|
270
|
+
if (value !== undefined && opts.chosen)
|
|
271
|
+
term.write(`${opts.chosen(value)}\n`);
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
/* restoring matters more than the last line */
|
|
275
|
+
}
|
|
276
|
+
try {
|
|
277
|
+
term.write(SHOW_CURSOR);
|
|
278
|
+
}
|
|
279
|
+
catch {
|
|
280
|
+
/* ditto */
|
|
281
|
+
}
|
|
282
|
+
try {
|
|
283
|
+
stop?.();
|
|
284
|
+
}
|
|
285
|
+
catch {
|
|
286
|
+
/* ditto */
|
|
287
|
+
}
|
|
288
|
+
if (err)
|
|
289
|
+
reject(err);
|
|
290
|
+
else
|
|
291
|
+
resolve(value);
|
|
292
|
+
};
|
|
293
|
+
const onData = (chunk) => {
|
|
294
|
+
if (done)
|
|
295
|
+
return;
|
|
296
|
+
try {
|
|
297
|
+
for (const key of parseKeys(chunk)) {
|
|
298
|
+
const r = reduce(state, key);
|
|
299
|
+
state = r.state;
|
|
300
|
+
if (r.outcome)
|
|
301
|
+
return finish(undefined, r.outcome.kind === "pick" ? r.outcome.value : undefined);
|
|
302
|
+
}
|
|
303
|
+
draw();
|
|
304
|
+
}
|
|
305
|
+
catch (err) {
|
|
306
|
+
finish(err);
|
|
307
|
+
}
|
|
308
|
+
};
|
|
309
|
+
const redraw = () => {
|
|
310
|
+
if (done)
|
|
311
|
+
return;
|
|
312
|
+
try {
|
|
313
|
+
draw();
|
|
314
|
+
}
|
|
315
|
+
catch (err) {
|
|
316
|
+
finish(err);
|
|
317
|
+
}
|
|
318
|
+
};
|
|
319
|
+
try {
|
|
320
|
+
term.write(HIDE_CURSOR);
|
|
321
|
+
stop = term.start(onData, redraw);
|
|
322
|
+
draw();
|
|
323
|
+
}
|
|
324
|
+
catch (err) {
|
|
325
|
+
finish(err);
|
|
326
|
+
return;
|
|
327
|
+
}
|
|
328
|
+
opts.update?.then((next) => {
|
|
329
|
+
if (done)
|
|
330
|
+
return;
|
|
331
|
+
state = withItems(state, next);
|
|
332
|
+
redraw();
|
|
333
|
+
}, () => {
|
|
334
|
+
/* keep the first items */
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
/** "alice@example.com", "not logged in", or the launcher of an agent without account details. */
|
|
339
|
+
async function accountText(name, agent, env) {
|
|
340
|
+
if (!launcherPath(name, env, agent))
|
|
341
|
+
return { text: "not set up", warn: true };
|
|
342
|
+
// turno reads no account for these agents (Codex, Copilot, Cursor).
|
|
343
|
+
if (!adapter(agent).accountDetails)
|
|
344
|
+
return { text: "-", warn: false };
|
|
345
|
+
const { authStatus } = await import("./commands/usage.js");
|
|
346
|
+
const s = await authStatus(name, env);
|
|
347
|
+
if (!s)
|
|
348
|
+
return { text: "account unknown", warn: true };
|
|
349
|
+
return s.loggedIn ? { text: s.email || "logged in", warn: false } : { text: "not logged in", warn: true };
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* The profile a command needs, chosen by a person. Without anyone to answer it fails with exit
|
|
353
|
+
* 2 and the valid values; a cancel fails with exit 130 and nothing changed.
|
|
354
|
+
*/
|
|
355
|
+
export async function pickProfile(io, opts) {
|
|
356
|
+
const config = loadConfig(io.env);
|
|
357
|
+
const names = listProfiles(config, io.env, opts.agent);
|
|
358
|
+
if (!names.length)
|
|
359
|
+
return fail(`no profiles yet${opts.agent && opts.agent !== DEFAULT_AGENT ? ` for ${adapter(opts.agent).label}` : ""}; create one with turno profile add <name>`);
|
|
360
|
+
if (!io.ask)
|
|
361
|
+
return needsAnswer(opts.command, `a profile: ${[...names, ...(opts.extra ?? [])].join(", ")}`);
|
|
362
|
+
const dir = opts.dir ?? process.cwd();
|
|
363
|
+
const roots = candidateRoots(dir);
|
|
364
|
+
const agents = [...new Set(names.map((n) => agentOf(n, config)))];
|
|
365
|
+
const here = new Map();
|
|
366
|
+
for (const agent of agents) {
|
|
367
|
+
const chosen = resolveProfile(dir, config, io.env, roots, agent).chosen;
|
|
368
|
+
if (chosen)
|
|
369
|
+
here.set(chosen, true);
|
|
370
|
+
}
|
|
371
|
+
const folderPick = names.find((n) => here.has(n) && agentOf(n, config) === DEFAULT_AGENT) ?? names.find((n) => here.has(n));
|
|
372
|
+
// What `turno auto` would open here (Claude Code, as `turno run auto` does).
|
|
373
|
+
const auto = opts.auto ? resolveProfile(dir, config, io.env, roots, DEFAULT_AGENT) : undefined;
|
|
374
|
+
const autoTo = auto?.chosen && names.includes(auto.chosen) ? auto.chosen : undefined;
|
|
375
|
+
const initial = opts.initial && names.includes(opts.initial) ? opts.initial : autoTo ? "auto" : folderPick;
|
|
376
|
+
const term = io.terminal ?? (process.stdin.isTTY && process.stderr.isTTY ? realTerminal() : undefined);
|
|
377
|
+
const styleAt = (columns) => style({ env: { ...io.env, COLUMNS: String(columns) }, isTty: true });
|
|
378
|
+
const s = term ? styleAt(term.columns()) : style({ env: io.env, isTty: Boolean(process.stderr.isTTY) });
|
|
379
|
+
const pill = (n) => s.profile(n, profileColor(config.profiles, n));
|
|
380
|
+
const now = Date.now() / 1000;
|
|
381
|
+
const mark = (n) => {
|
|
382
|
+
const parts = [];
|
|
383
|
+
if (here.has(n))
|
|
384
|
+
parts.push(s.lead("on", "this folder"));
|
|
385
|
+
if (opts.marks?.[n])
|
|
386
|
+
parts.push(opts.marks[n]);
|
|
387
|
+
const until = exhaustedUntil(n, io.env);
|
|
388
|
+
if (until !== undefined && until > now)
|
|
389
|
+
parts.push(s.warn("exhausted"));
|
|
390
|
+
return parts.join(s.muted(" · "));
|
|
391
|
+
};
|
|
392
|
+
const item = (n, account) => {
|
|
393
|
+
const agent = adapter(agentOf(n, config));
|
|
394
|
+
const acc = account ? (account.warn ? s.warn(account.text) : account.text) : s.muted("...");
|
|
395
|
+
return { value: n, cells: [pill(n), agent.label, acc, mark(n)], search: `${agent.label} ${account?.text ?? ""}` };
|
|
396
|
+
};
|
|
397
|
+
const autoName = (st) => `${st.bold("auto")} ${st.muted("(")}${autoTo}${st.muted(")")}`;
|
|
398
|
+
const first = autoTo
|
|
399
|
+
? [
|
|
400
|
+
{
|
|
401
|
+
value: "auto",
|
|
402
|
+
cells: [autoName(s), adapter(DEFAULT_AGENT).label, s.muted(auto.reason), auto.note ? s.warn(`${auto.assigned} ${auto.note}`) : ""],
|
|
403
|
+
search: `auto ${autoTo}`,
|
|
404
|
+
},
|
|
405
|
+
]
|
|
406
|
+
: [];
|
|
407
|
+
const withAccounts = Promise.all(names.map(async (n) => item(n, await accountText(n, agentOf(n, config), io.env)))).then((items) => [...first, ...items]);
|
|
408
|
+
let value;
|
|
409
|
+
if (term) {
|
|
410
|
+
value = await runPicker(term, s, [...first, ...names.map((n) => item(n))], {
|
|
411
|
+
title: opts.title,
|
|
412
|
+
maxRows: 10,
|
|
413
|
+
...(initial ? { initial } : {}),
|
|
414
|
+
update: withAccounts,
|
|
415
|
+
styleAt,
|
|
416
|
+
chosen: (v) => `${s.icon("ok")} ${opts.title} ${v === "auto" && autoTo ? autoName(s) : pill(v)}`,
|
|
417
|
+
});
|
|
418
|
+
}
|
|
419
|
+
else {
|
|
420
|
+
value = await askByNumber(io, s, await withAccounts, opts.title, initial);
|
|
421
|
+
}
|
|
422
|
+
if (value === undefined)
|
|
423
|
+
throw new CliError("cancelled; nothing changed", 130);
|
|
424
|
+
return value;
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* The picker as a numbered question, for a person who can answer but not on a raw terminal
|
|
428
|
+
* (an `ask` without a TTY on stdin): a number, a name, or Enter for the marked one.
|
|
429
|
+
*/
|
|
430
|
+
async function askByNumber(io, s, items, title, initial) {
|
|
431
|
+
io.err(`${s.accent("?")} ${s.bold(title)}`);
|
|
432
|
+
const rows = items.map((it, i) => [s.muted(String(i + 1)), ...it.cells]);
|
|
433
|
+
for (const line of s.table(rows, { columns: [{ align: "right" }] }))
|
|
434
|
+
io.err(line);
|
|
435
|
+
const def = initial ? items.findIndex((i) => i.value === initial) + 1 : 0;
|
|
436
|
+
const answer = (await io.ask(`Number or name${def ? ` [${def}]` : ""}: `)).trim();
|
|
437
|
+
if (!answer)
|
|
438
|
+
return def ? items[def - 1].value : undefined;
|
|
439
|
+
const n = Number(answer);
|
|
440
|
+
if (Number.isInteger(n) && n >= 1 && n <= items.length)
|
|
441
|
+
return items[n - 1].value;
|
|
442
|
+
const named = items.find((i) => i.value === answer);
|
|
443
|
+
if (named)
|
|
444
|
+
return named.value;
|
|
445
|
+
return fail(`no profile '${answer}'; pass a profile: ${items.map((i) => i.value).join(", ")}`);
|
|
446
|
+
}
|
|
447
|
+
//# sourceMappingURL=picker.js.map
|
package/dist/cli/registry.js
CHANGED
|
@@ -3,13 +3,44 @@
|
|
|
3
3
|
* the MCP SDK. Order and section decide `turno help`.
|
|
4
4
|
*/
|
|
5
5
|
export const SECTIONS = [
|
|
6
|
+
{ title: "Get started", commands: ["init", "demo"] },
|
|
6
7
|
{ title: "Start an agent", commands: ["run", "auto"] },
|
|
7
8
|
{ title: "Accounts", commands: ["profile", "limit", "session", "open"] },
|
|
8
|
-
{ title: "MCP servers and outside services", commands: ["mcp", "identity", "secret"
|
|
9
|
+
{ title: "MCP servers and outside services", commands: ["mcp", "identity", "secret"] },
|
|
9
10
|
{ title: "Look", commands: ["ui"] },
|
|
10
|
-
{ title: "Maintenance", commands: ["status", "doctor", "config", "undo", "upgrade", "
|
|
11
|
+
{ title: "Maintenance", commands: ["status", "doctor", "config", "undo", "upgrade", "uninstall", "version", "completion"] },
|
|
12
|
+
{ title: "Developer tools", commands: ["browser"] },
|
|
11
13
|
];
|
|
14
|
+
/**
|
|
15
|
+
* One line per visible command for `turno help`, so the help renders from this table without
|
|
16
|
+
* loading any command module. Each must equal the command's own `summary` (a test checks it).
|
|
17
|
+
*/
|
|
18
|
+
export const HELP_SUMMARY = {
|
|
19
|
+
init: "set turno up in one step: find agents, profiles, folders and MCP servers, show the diff, write it (one undo)",
|
|
20
|
+
demo: "try turno in a throwaway HOME: two profiles, a gateway and the status line (removed on exit)",
|
|
21
|
+
run: "open a profile with its agent (turno <profile> is the short form), or auto",
|
|
22
|
+
auto: "open the agent with the account assigned to this folder (turno-auto)",
|
|
23
|
+
profile: "accounts (profiles) for each agent: list, add, repair, remove, and which folders use each",
|
|
24
|
+
limit: "usage limits of each account, and the exhausted marks that move projects to the fallback",
|
|
25
|
+
session: "live Claude Code sessions, and moving one to another account",
|
|
26
|
+
open: "open a claude.ai link with an account (default: the session's)",
|
|
27
|
+
mcp: "MCP servers behind the lazy gateway, and the gateway daemon itself",
|
|
28
|
+
identity: "who acts on outside services: service accounts (linear:work) and browser identities (browser:school)",
|
|
29
|
+
secret: "store MCP secrets in the Keychain (macOS) or the Secret Service (Linux)",
|
|
30
|
+
ui: "the status line, its font and icons in every terminal",
|
|
31
|
+
status: "one screen with everything: this folder, profiles and usage, sessions, mcpd and the look",
|
|
32
|
+
doctor: "check everything (system, config, profiles, MCP, look, mcpd) and fix what is safe to fix",
|
|
33
|
+
config: "read and change config.toml without losing its comments; check every config file",
|
|
34
|
+
undo: "list recent changes turno made to your files, and put any of them back",
|
|
35
|
+
upgrade: "update turno to the newest release (or check for one)",
|
|
36
|
+
uninstall: "remove the service, launchers, status line and MCP entries turno set up (profile folders stay)",
|
|
37
|
+
version: "the turno version, how it was installed, and whether a newer one is known",
|
|
38
|
+
completion: "shell completion for commands, profiles, identities and config keys",
|
|
39
|
+
browser: "developer tool: compare browser engines (needs turno-browser)",
|
|
40
|
+
};
|
|
12
41
|
export const COMMANDS = {
|
|
42
|
+
init: () => import("./commands/init.js"),
|
|
43
|
+
demo: () => import("./commands/demo.js"),
|
|
13
44
|
run: () => import("./commands/run.js"),
|
|
14
45
|
auto: () => import("./commands/auto.js"),
|
|
15
46
|
profile: () => import("./commands/profile.js"),
|
|
@@ -26,8 +57,10 @@ export const COMMANDS = {
|
|
|
26
57
|
config: () => import("./commands/config.js"),
|
|
27
58
|
undo: () => import("./commands/undo.js"),
|
|
28
59
|
upgrade: () => import("./commands/upgrade.js"),
|
|
60
|
+
uninstall: () => import("./commands/uninstall.js"),
|
|
29
61
|
version: () => import("./commands/version.js"),
|
|
30
62
|
completion: () => import("./commands/completion.js"),
|
|
63
|
+
// Kept for people coming from the bash tool; not in the help.
|
|
31
64
|
migrate: () => import("./commands/migrate.js"),
|
|
32
65
|
// Called by Claude Code, hooks, launchers and the LaunchAgent; not in the help.
|
|
33
66
|
statusline: () => import("./commands/statusline.js"),
|
|
@@ -39,9 +72,9 @@ export const COMMANDS = {
|
|
|
39
72
|
};
|
|
40
73
|
/**
|
|
41
74
|
* Earlier names: the 0.1 commands and the Spanish words of the bash script. They keep
|
|
42
|
-
* working so hooks,
|
|
75
|
+
* working so hooks, editors, skills and muscle memory do not break; the help shows the new ones.
|
|
43
76
|
*/
|
|
44
|
-
|
|
77
|
+
const ALIASES = {
|
|
45
78
|
which: ["profile", "which"],
|
|
46
79
|
setup: ["profile", "repair"],
|
|
47
80
|
sessions: ["session", "list"],
|
|
@@ -60,7 +93,7 @@ export const ALIASES = {
|
|
|
60
93
|
abrir: ["open"],
|
|
61
94
|
"sync-mcp": ["mcp", "sync"],
|
|
62
95
|
};
|
|
63
|
-
|
|
96
|
+
const ALIAS_FLAGS = {
|
|
64
97
|
uso: { "--vigilar": "--watch" },
|
|
65
98
|
agotada: { hasta: "until" },
|
|
66
99
|
};
|
|
@@ -74,4 +107,8 @@ export function expand(first, rest) {
|
|
|
74
107
|
const flags = ALIAS_FLAGS[first] ?? {};
|
|
75
108
|
return [alias[0], [...alias.slice(1), ...rest.map((a) => flags[a] ?? a)]];
|
|
76
109
|
}
|
|
110
|
+
/** Every visible command name, for suggestions after a typo. */
|
|
111
|
+
export function visibleCommands() {
|
|
112
|
+
return SECTIONS.flatMap((s) => s.commands);
|
|
113
|
+
}
|
|
77
114
|
//# sourceMappingURL=registry.js.map
|