turno-cli 0.3.0 → 0.5.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/dist/cli/hints.js CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * The next step after a command that writes: one `Next: ...` line, so a person knows what to run
3
- * after `profile add`, `mcp import --write` and the like. `hints = false` in config.toml turns
4
- * them off; they are never printed under --json, where stdout is data.
2
+ * The next step after a command that writes (turno-core's `nextStep`), on unless config.toml
3
+ * says `hints = false`.
5
4
  */
5
+ import { nextStep as printNext } from "turno-core/cli/hints";
6
6
  import { loadConfig } from "../core/config.js";
7
7
  /** Whether hints are on: config.toml's `hints`, true when the file is missing or does not parse. */
8
- function hintsOn(env) {
8
+ export function hintsOn(env) {
9
9
  try {
10
10
  return loadConfig(env).hints;
11
11
  }
@@ -18,13 +18,6 @@ function hintsOn(env) {
18
18
  * stdout is a file (`turno mcp export > file.toml`).
19
19
  */
20
20
  export function nextStep(io, steps, opts = {}) {
21
- const list = (typeof steps === "string" ? [steps] : steps).filter(Boolean);
22
- if (!list.length || opts.json || !hintsOn(io.env))
23
- return;
24
- const line = `Next: ${list.join("; ")}`;
25
- if (opts.stream === "err")
26
- io.err(line);
27
- else
28
- io.out(line);
21
+ printNext(io, steps, { ...opts, enabled: hintsOn });
29
22
  }
30
23
  //# sourceMappingURL=hints.js.map
package/dist/cli/io.js CHANGED
@@ -1,207 +1,3 @@
1
- /** Small helpers shared by command modules. Keep this file free of heavy imports. */
2
- import { Exit } from "./exit.js";
3
- /** A wrong command line: main prints `turno: <message>` and exits 2 (Exit.usage). */
4
- export class UsageError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "UsageError";
8
- }
9
- }
10
- /** A plain error with its exit code (see exit.ts): main prints `turno: <message>` and returns `code`. */
11
- export class CliError extends Error {
12
- code;
13
- constructor(message, code = Exit.failure) {
14
- super(message);
15
- this.code = code;
16
- this.name = "CliError";
17
- }
18
- }
19
- async function askStdin(question) {
20
- const { createInterface } = await import("node:readline/promises");
21
- const rl = createInterface({ input: process.stdin, output: process.stderr });
22
- try {
23
- return await rl.question(question);
24
- }
25
- finally {
26
- rl.close();
27
- }
28
- }
29
- export function defaultIo() {
30
- return {
31
- out: (line = "") => process.stdout.write(`${line}\n`),
32
- err: (line = "") => process.stderr.write(`${line}\n`),
33
- env: process.env,
34
- isTty: Boolean(process.stdout.isTTY),
35
- ...(process.stdin.isTTY && process.stderr.isTTY && !noInputReason(process.env) ? { ask: askStdin } : {}),
36
- };
37
- }
38
- /**
39
- * The variables each coding agent sets for the commands it runs, by agent id: inside them nobody
40
- * reads a question, so turno never asks one. Kept here rather than in
41
- * the adapters because every run loads io.ts and it stays free of heavy imports; a test keeps the
42
- * ids in step with src/agents.
43
- */
44
- export const AGENT_SESSION_ENV = {
45
- claude: ["CLAUDECODE", "CLAUDE_CODE_CHILD_SESSION"],
46
- codex: ["CODEX_THREAD_ID", "CODEX_SANDBOX"],
47
- copilot: ["COPILOT_CLI", "COPILOT_AGENT_SESSION_ID"],
48
- cursor: ["CURSOR_AGENT"],
49
- };
50
- const on = (v) => v !== undefined && v !== "" && v !== "0" && v.toLowerCase() !== "false";
51
- /**
52
- * The variable that keeps turno from asking anything here (TURNO_NO_INPUT, or an agent's), or
53
- * undefined when a person may answer on a terminal. TURNO_NO_INPUT=1 (or --no-input) turns
54
- * questions off; TURNO_NO_INPUT=0 allows them inside an agent session, for a person in an
55
- * editor terminal that sets an agent variable.
56
- */
57
- export function noInputReason(env) {
58
- const own = env.TURNO_NO_INPUT;
59
- if (own !== undefined && own !== "")
60
- return on(own) ? "TURNO_NO_INPUT" : undefined;
61
- return Object.values(AGENT_SESSION_ENV)
62
- .flat()
63
- .find((name) => on(env[name]));
64
- }
65
- /** The same Io without a way to ask. */
66
- export function withoutAsk(io) {
67
- const { ask: _ask, ...rest } = io;
68
- return rest;
69
- }
70
- /**
71
- * A question nobody can answer here (no terminal, --no-input, an agent session): exit 2 and
72
- * name the flag that answers it, the same way for every command.
73
- */
74
- export function needsAnswer(what, flag = "--yes") {
75
- throw new UsageError(`${what} needs an answer; pass ${flag} (or run it in a terminal)`);
76
- }
77
- /** Ask a yes/no question; false without a person to answer. */
78
- export async function confirm(io, question) {
79
- if (!io.ask)
80
- return false;
81
- const answer = (await io.ask(`${question} [y/N] `)).trim().toLowerCase();
82
- return answer === "y" || answer === "yes";
83
- }
84
- const COLOR_MODES = ["auto", "always", "never"];
85
- export function isColorMode(v) {
86
- return v !== undefined && COLOR_MODES.includes(v);
87
- }
88
- /**
89
- * Whether output gets ANSI colors. The first rule that applies wins:
90
- *
91
- * 1. `--color always|never` on the command line;
92
- * 2. TURNO_COLOR=always|never (any other value counts as auto; --color auto sets it aside);
93
- * 3. NO_COLOR set and not empty: off (https://no-color.org, which lets a flag or a tool's own
94
- * setting override it);
95
- * 4. FORCE_COLOR: 0 or false turns colors off, anything else turns them on, also in a pipe;
96
- * 5. CLICOLOR_FORCE set and not 0: on, also in a pipe (https://bixense.com/clicolors);
97
- * 6. CLICOLOR=0, or TERM=dumb: off;
98
- * 7. auto: on when output is a terminal.
99
- *
100
- * `--json` output is never colored outside a terminal, whatever this says (output.ts).
101
- */
102
- export function colors(io) {
103
- // An explicit --color auto also sets TURNO_COLOR aside.
104
- const own = io.color ?? io.env.TURNO_COLOR;
105
- if (own === "always")
106
- return true;
107
- if (own === "never")
108
- return false;
109
- const env = io.env;
110
- if (env.NO_COLOR)
111
- return false;
112
- const force = env.FORCE_COLOR;
113
- if (force !== undefined && force !== "")
114
- return force !== "0" && force !== "false";
115
- if (env.CLICOLOR_FORCE && env.CLICOLOR_FORCE !== "0")
116
- return true;
117
- if (env.CLICOLOR === "0" || env.TERM === "dumb")
118
- return false;
119
- return io.isTty;
120
- }
121
- export function paint(io, text, code) {
122
- return colors(io) ? `\x1b[${code}m${text}\x1b[0m` : text;
123
- }
124
- export function fail(message) {
125
- throw new UsageError(message);
126
- }
127
- /** "1 project", "2 projects". */
128
- export function plural(n, word, many = `${word}s`) {
129
- return `${n} ${n === 1 ? word : many}`;
130
- }
131
- /** Help text width. */
132
- const WIDTH = 80;
133
- /** Break `text` into lines of at most `width` columns at spaces (a longer word stays whole). */
134
- export function wrap(text, width) {
135
- const lines = [];
136
- let line = "";
137
- for (const word of text.split(/\s+/).filter(Boolean)) {
138
- if (line && line.length + 1 + word.length > width) {
139
- lines.push(line);
140
- line = word;
141
- }
142
- else
143
- line = line ? `${line} ${word}` : word;
144
- }
145
- if (line)
146
- lines.push(line);
147
- return lines.length ? lines : [""];
148
- }
149
- /**
150
- * Two-column rows (` left summary`) within WIDTH columns: summaries wrap under their
151
- * column, and a left side too wide for the column goes on its own line.
152
- */
153
- export function columns(rows, indent = 2, maxLeft = 32, left) {
154
- const fit = rows.map(([l]) => l.length).filter((n) => n <= maxLeft);
155
- const w = left ?? Math.max(0, ...fit);
156
- const pad = " ".repeat(indent);
157
- const out = [];
158
- for (const [left, summary] of rows) {
159
- const col = indent + w + 2;
160
- const body = wrap(summary, Math.max(20, WIDTH - col));
161
- if (left.length > w) {
162
- const [first, ...more] = wrap(left, WIDTH - indent - 4);
163
- out.push(`${pad}${first}`);
164
- for (const l of more)
165
- out.push(`${pad} ${l}`);
166
- for (const l of body)
167
- out.push(`${" ".repeat(col)}${l}`);
168
- continue;
169
- }
170
- out.push(`${pad}${left.padEnd(w)} ${body[0]}`);
171
- for (const l of body.slice(1))
172
- out.push(`${" ".repeat(col)}${l}`);
173
- }
174
- return out.join("\n");
175
- }
176
- /**
177
- * The `Examples:` block that ends a command's help: one `$ command` per line, with an optional
178
- * ` # why` after it.
179
- */
180
- export function examplesBlock(examples) {
181
- return ["Examples:", ...examples.map((e) => ` $ ${e}`)].join("\n");
182
- }
183
- /** Edit distance with adjacent transpositions (so "stauts" is 1 away from "status"). */
184
- export function distance(a, b) {
185
- const d = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
186
- for (let i = 1; i <= a.length; i++) {
187
- for (let j = 1; j <= b.length; j++) {
188
- const cost = a[i - 1] === b[j - 1] ? 0 : 1;
189
- d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
190
- if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1])
191
- d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
192
- }
193
- }
194
- return d[a.length][b.length];
195
- }
196
- /** The closest of `candidates` to `word` (at most 2 edits, 1 for words of 3 letters or less). */
197
- export function closest(word, candidates) {
198
- const max = word.length <= 3 ? 1 : 2;
199
- let best;
200
- for (const c of candidates) {
201
- const d = distance(word.toLowerCase(), c);
202
- if (d <= max && (!best || d < best.d))
203
- best = { c, d };
204
- }
205
- return best?.c;
206
- }
1
+ // Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
2
+ export * from "turno-core/cli/io";
207
3
  //# sourceMappingURL=io.js.map
@@ -1,123 +1,3 @@
1
- import { highlightJson } from "./highlight.js";
2
- import { UsageError, colors } from "./io.js";
3
- /** The key every JSON object turno prints carries. */
4
- export const SCHEMA_KEY = "schemaVersion";
5
- export function jsonOutput(fields, version = 1) {
6
- return { version, fields };
7
- }
8
- /** The word after `--json=` that lists the fields instead of printing anything. */
9
- const FIELDS_WORD = "fields";
10
- /** A usage error about `--json` fields: main adds the list to the JSON error. */
11
- export class JsonFieldError extends UsageError {
12
- fields;
13
- constructor(message, fields) {
14
- super(message);
15
- this.fields = fields;
16
- }
17
- }
18
- /**
19
- * The value of `--json=<value>` among a command's own arguments (not after `--`), undefined
20
- * without one. A bare `--json` gives "".
21
- */
22
- export function jsonArg(args) {
23
- let found;
24
- for (const a of args) {
25
- if (a === "--")
26
- break;
27
- if (a === "--json")
28
- found ??= "";
29
- else if (a.startsWith("--json="))
30
- found = a.slice("--json=".length);
31
- }
32
- return found;
33
- }
34
- /** The field list `--json=fields` prints, one per line after a header, like gh. */
35
- function fieldLines(out) {
36
- return [
37
- "Fields for --json=<field,...> (schemaVersion is always there):",
38
- ...[...out.fields].sort().map((f) => ` ${f}`),
39
- ];
40
- }
41
- /**
42
- * The fields `--json=<value>` selects: undefined for all of them (bare --json), "list" for
43
- * --json=fields. An unknown field is a usage error that lists the known ones.
44
- */
45
- export function selectFields(value, out) {
46
- if (value === undefined || value === "")
47
- return undefined;
48
- if (value === FIELDS_WORD)
49
- return "list";
50
- const asked = value
51
- .split(",")
52
- .map((f) => f.trim())
53
- .filter(Boolean);
54
- const unknown = asked.filter((f) => f !== SCHEMA_KEY && !out.fields.includes(f));
55
- if (unknown.length) {
56
- const known = [...out.fields].sort();
57
- throw new JsonFieldError(`unknown JSON field${unknown.length > 1 ? "s" : ""} ${unknown.map((f) => `"${f}"`).join(", ")}; available: ${known.join(", ")}`, known);
58
- }
59
- return asked;
60
- }
61
- /**
62
- * Before a command runs: answer `--json=fields` (true: the caller returns 0) and refuse an
63
- * unknown field (a usage error), so neither waits for the command's work.
64
- */
65
- export function answerFields(args, out, io) {
66
- if (!out)
67
- return false;
68
- const picked = selectFields(jsonArg(args), out);
69
- if (picked !== "list")
70
- return false;
71
- for (const l of fieldLines(out))
72
- io.out(l);
73
- return true;
74
- }
75
- function stamp(value, out, fields) {
76
- if (typeof value !== "object" || value === null || Array.isArray(value))
77
- return value;
78
- const o = value;
79
- const kept = fields ? Object.fromEntries(fields.filter((f) => f !== SCHEMA_KEY && f in o).map((f) => [f, o[f]])) : o;
80
- return { [SCHEMA_KEY]: out.version, ...kept };
81
- }
82
- /** The value as printed: schemaVersion on the object (or on each element of a list), fields picked. */
83
- export function shape(value, out, json) {
84
- const picked = selectFields(json, out);
85
- const fields = picked === "list" ? undefined : picked;
86
- return Array.isArray(value) ? value.map((v) => stamp(v, out, fields)) : stamp(value, out, fields);
87
- }
88
- const jsonValue = (p) => (typeof p === "object" ? p.json : p);
89
- /**
90
- * Print a command's JSON: indented, colored on a terminal only (never in a pipe, even with
91
- * FORCE_COLOR, since programs read it). `--json=fields` prints the field list instead.
92
- */
93
- export function emit(io, p, out, value) {
94
- if (selectFields(jsonValue(p), out) === "list") {
95
- for (const l of fieldLines(out))
96
- io.out(l);
97
- return;
98
- }
99
- const text = JSON.stringify(shape(value, out, jsonValue(p)), null, 2);
100
- io.out(io.isTty && colors(io) ? highlightJson(text) : text);
101
- }
102
- /**
103
- * `turno config get --json`: a config value as config.toml holds it, with no schemaVersion (its
104
- * shape is config.toml's, documented in docs/config.md). The one exception to the contract.
105
- */
106
- export function emitConfigValue(io, value) {
107
- const text = JSON.stringify(value, null, 2);
108
- io.out(io.isTty && colors(io) ? highlightJson(text) : text);
109
- }
110
- /** Print one record as one compact line (NDJSON): `--watch --json`, `mcp log --json`, `resolve --json`. */
111
- export function emitLine(io, p, out, value) {
112
- io.out(JSON.stringify(shape(value, out, jsonValue(p))));
113
- }
114
- /** Each element of a list as its own line (NDJSON). */
115
- export function emitLines(io, p, out, values) {
116
- for (const v of values)
117
- emitLine(io, p, out, v);
118
- }
119
- /** The JSON error object of the contract (`schemaVersion` 1), for stderr under --json. */
120
- export function jsonError(message, exitCode, code, extra = {}) {
121
- return JSON.stringify({ [SCHEMA_KEY]: 1, error: { code, exitCode, message, ...extra } });
122
- }
1
+ // Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
2
+ export * from "turno-core/cli/output";
123
3
  //# sourceMappingURL=output.js.map
@@ -53,9 +53,10 @@ export const COMMANDS = {
53
53
  session: () => import("./commands/session.js"),
54
54
  open: () => import("./commands/open.js"),
55
55
  mcp: () => import("./commands/mcp.js"),
56
- identity: () => import("./commands/identity.js"),
56
+ // Described by turno-browser when it is installed (the browser flags in help and completion).
57
+ identity: async () => ({ command: await (await import("./commands/identity.js")).loadCommand() }),
57
58
  secret: () => import("./commands/secret.js"),
58
- browser: () => import("./commands/browser.js"),
59
+ browser: async () => ({ command: await (await import("./commands/browser.js")).loadCommand() }),
59
60
  ui: () => import("./commands/ui.js"),
60
61
  status: () => import("./commands/status.js"),
61
62
  doctor: () => import("./commands/doctor.js"),
@@ -1,63 +1,3 @@
1
- /**
2
- * Reading a secret from a person or a pipe, for `turno secret set` and `turno browser vault add`.
3
- * On a terminal the input is hidden (raw mode, nothing echoed); otherwise stdin is read to the
4
- * end. Neither path ever prints what was read.
5
- */
6
- /** Whether stdin is a terminal a person types into. */
7
- export function stdinIsTty() {
8
- return Boolean(process.stdin.isTTY);
9
- }
10
- /** A line typed on the terminal without echo; Ctrl-C exits 130. */
11
- export function readHidden(prompt) {
12
- process.stderr.write(prompt);
13
- return new Promise((resolve) => {
14
- const stdin = process.stdin;
15
- let value = "";
16
- stdin.setRawMode(true);
17
- stdin.resume();
18
- stdin.setEncoding("utf8");
19
- const onData = (chunk) => {
20
- for (const ch of chunk) {
21
- if (ch === "\r" || ch === "\n" || ch === "\u0004") {
22
- stdin.setRawMode(false);
23
- stdin.pause();
24
- stdin.off("data", onData);
25
- process.stderr.write("\n");
26
- resolve(value);
27
- return;
28
- }
29
- if (ch === "\u0003") {
30
- stdin.setRawMode(false);
31
- process.stderr.write("\n");
32
- process.exit(130);
33
- }
34
- if (ch === "\u007f")
35
- value = value.slice(0, -1);
36
- else
37
- value += ch;
38
- }
39
- };
40
- stdin.on("data", onData);
41
- });
42
- }
43
- /** A line typed on the terminal, shown as typed (a username). */
44
- export async function readVisible(prompt) {
45
- const { createInterface } = await import("node:readline/promises");
46
- const rl = createInterface({ input: process.stdin, output: process.stderr });
47
- try {
48
- return (await rl.question(prompt)).trim();
49
- }
50
- finally {
51
- rl.close();
52
- }
53
- }
54
- /** All of stdin, without one trailing line break. */
55
- export async function readStdinText() {
56
- const chunks = [];
57
- for await (const c of process.stdin)
58
- chunks.push(c);
59
- return Buffer.concat(chunks)
60
- .toString("utf8")
61
- .replace(/\r?\n$/, "");
62
- }
1
+ // Moved to turno-core so turno-browser shares it; re-exported here so commands keep their imports.
2
+ export * from "turno-core/cli/secret-input";
63
3
  //# sourceMappingURL=secret-input.js.map