turno-cli 0.4.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/style.js CHANGED
@@ -1,57 +1,6 @@
1
- /**
2
- * The look of turno's own screens: semantic colors, status icons, section headers, key/value
3
- * rows, tables sized to the terminal, usage bars, a spinner and timings. Every command draws with
4
- * this so the CLI reads as one tool. Without colors (a pipe, NO_COLOR) the same layout comes out
5
- * as plain text with ASCII icons, stable for scripts and tests.
6
- *
7
- * Keep this file free of heavy imports: `turno --help`, `turno status` and the status line load it.
8
- */
1
+ // The look moved to turno-core so turno-browser shares it; profile colors stay with the status line.
9
2
  import { NAMED_COLORS, PILL_DEFAULTS } from "../statusline/render.js";
10
- import { colors } from "./io.js";
11
- const cp = (n) => String.fromCodePoint(n);
12
- export const ICONS = {
13
- nerd: {
14
- ok: cp(0xf00c),
15
- warn: cp(0xf071),
16
- err: cp(0xf00d),
17
- info: cp(0xf05a),
18
- add: "+",
19
- remove: "-",
20
- on: cp(0xf111),
21
- off: cp(0xf10c),
22
- arrow: cp(0xf061),
23
- next: cp(0xf0a9),
24
- skip: cp(0xf05e),
25
- },
26
- unicode: {
27
- ok: "✓",
28
- warn: "!",
29
- err: "✗",
30
- info: "•",
31
- add: "+",
32
- remove: "-",
33
- on: "●",
34
- off: "○",
35
- arrow: "→",
36
- next: "➜",
37
- skip: "–",
38
- },
39
- ascii: {
40
- ok: "ok",
41
- warn: "!",
42
- err: "x",
43
- info: "-",
44
- add: "+",
45
- remove: "-",
46
- on: "",
47
- off: "",
48
- arrow: "->",
49
- next: "",
50
- skip: "-",
51
- },
52
- };
53
- /** SGR codes of the semantic colors: the terminal's own palette, so dark and light themes both work. */
54
- const CODES = { ok: "32", warn: "33", err: "31", accent: "36", muted: "2", faint: "90", bold: "1" };
3
+ export * from "turno-core/cli/style";
55
4
  /**
56
5
  * The 256-color code of a profile: its `color` in config.toml, or one of the defaults by its
57
6
  * place in the config. The one rule for every profile pill: the status line (`pillColor` in
@@ -72,240 +21,4 @@ export function profileColor(profiles, name) {
72
21
  const idx = names.includes(name) ? names.indexOf(name) : [...name].reduce((a, ch) => a + ch.charCodeAt(0), 0);
73
22
  return PILL_DEFAULTS[idx % PILL_DEFAULTS.length];
74
23
  }
75
- // biome-ignore lint/suspicious/noControlCharactersInRegex: matching ANSI escapes is the point
76
- const ANSI = /\x1b\[[0-9;]*m/g;
77
- /** Text without its ANSI color codes. */
78
- export function stripAnsi(text) {
79
- return text.replace(ANSI, "");
80
- }
81
- /** Columns a string takes on screen (ANSI codes take none). */
82
- export function visibleWidth(text) {
83
- return [...stripAnsi(text)].length;
84
- }
85
- /** Pad to `width` visible columns. */
86
- export function padEnd(text, width) {
87
- return text + " ".repeat(Math.max(0, width - visibleWidth(text)));
88
- }
89
- function padStart(text, width) {
90
- return " ".repeat(Math.max(0, width - visibleWidth(text))) + text;
91
- }
92
- /**
93
- * Columns of the terminal: COLUMNS, then the real terminal, then 80 (a pipe, a test). Never
94
- * below 40, so layouts keep a sane minimum.
95
- */
96
- export function termWidth(io) {
97
- const env = Number(io.env.COLUMNS);
98
- if (Number.isInteger(env) && env > 0)
99
- return Math.max(40, env);
100
- const real = io.isTty ? process.stdout.columns : undefined;
101
- return real && real > 0 ? Math.max(40, real) : 80;
102
- }
103
- /** "420ms", "1.2s", "1m05s". */
104
- export function duration(ms) {
105
- if (ms < 1000)
106
- return `${Math.max(0, Math.round(ms))}ms`;
107
- if (ms < 60_000)
108
- return `${(ms / 1000).toFixed(1)}s`;
109
- const s = Math.round(ms / 1000);
110
- return `${Math.floor(s / 60)}m${String(s % 60).padStart(2, "0")}s`;
111
- }
112
- /** Level of a usage percentage: below 60 fine, below 85 a warning, then a problem. */
113
- export function level(pct) {
114
- return pct < 60 ? "ok" : pct < 85 ? "warn" : "err";
115
- }
116
- /** Cut a word that may hold ANSI codes into pieces of at most `width` visible columns. */
117
- function chop(word, width) {
118
- const pieces = [];
119
- let piece = "";
120
- let w = 0;
121
- // ANSI codes take no columns and stay with the character after them.
122
- // biome-ignore lint/suspicious/noControlCharactersInRegex: matching ANSI escapes is the point
123
- for (const m of word.matchAll(/\x1b\[[0-9;]*m|[^\x1b]/gu)) {
124
- const t = m[0];
125
- if (t.startsWith("\x1b")) {
126
- piece += t;
127
- continue;
128
- }
129
- if (w === width) {
130
- pieces.push(piece);
131
- piece = "";
132
- w = 0;
133
- }
134
- piece += t;
135
- w++;
136
- }
137
- if (piece)
138
- pieces.push(piece);
139
- return pieces;
140
- }
141
- /**
142
- * Break text that may hold ANSI codes into lines of at most `width` visible columns, at spaces.
143
- * A word longer than the width (a long path) is cut at the width. Colors carry over: a terminal
144
- * keeps the active SGR across a line break.
145
- */
146
- export function wrapAnsi(text, width) {
147
- if (visibleWidth(text) <= width)
148
- return [text];
149
- const words = text.split(" ").flatMap((word) => (visibleWidth(word) > width ? chop(word, width) : [word]));
150
- const [first = "", ...rest] = words;
151
- const lines = [];
152
- let line = first;
153
- let w = visibleWidth(first);
154
- for (const word of rest) {
155
- const ww = visibleWidth(word);
156
- // Break before a word that does not fit; spaces inside a line (alignment) stay as they are.
157
- if (w > 0 && ww > 0 && w + 1 + ww > width) {
158
- lines.push(line);
159
- line = word;
160
- w = ww;
161
- }
162
- else {
163
- line += ` ${word}`;
164
- w += 1 + ww;
165
- }
166
- }
167
- lines.push(line);
168
- return lines;
169
- }
170
- /** Columns a wrapping last table column keeps before other columns are dropped for it. */
171
- const LAST_MIN = 24;
172
- export function style(io, opts = {}) {
173
- const color = colors(io);
174
- const icons = !color ? "ascii" : opts.nerd ? "nerd" : "unicode";
175
- const width = termWidth(io);
176
- const sgr = (code) => (s) => (color && s ? `\x1b[${code}m${s}\x1b[0m` : s);
177
- const ok = sgr(CODES.ok);
178
- const warn = sgr(CODES.warn);
179
- const err = sgr(CODES.err);
180
- const accent = sgr(CODES.accent);
181
- const muted = sgr(CODES.muted);
182
- const faint = sgr(CODES.faint);
183
- const bold = sgr(CODES.bold);
184
- const ICON_COLOR = {
185
- ok,
186
- warn,
187
- err,
188
- info: accent,
189
- add: ok,
190
- remove: err,
191
- on: ok,
192
- off: faint,
193
- arrow: faint,
194
- next: accent,
195
- skip: faint,
196
- };
197
- const icon = (name) => (ICON_COLOR[name] ?? ((s) => s))(ICONS[icons][name]);
198
- const iconWidth = Math.max(...["ok", "warn", "err", "skip", "info"].map((n) => visibleWidth(ICONS[icons][n])));
199
- const wrapLine = (prefix, text) => {
200
- if (!color)
201
- return `${prefix}${text}`;
202
- const hang = visibleWidth(prefix);
203
- const body = wrapAnsi(text, Math.max(20, width - hang));
204
- return [`${prefix}${body[0]}`, ...body.slice(1).map((l) => `${" ".repeat(hang)}${l}`)].join("\n");
205
- };
206
- const tableRows = (rows, o = {}) => {
207
- const indent = o.indent ?? 2;
208
- const gap = o.gap ?? 2;
209
- const cols = o.columns ?? [];
210
- const n = Math.max(0, ...rows.map((r) => r.length));
211
- let keep = Array.from({ length: n }, (_, i) => i);
212
- const widthOf = (i) => Math.max(0, ...rows.map((r) => visibleWidth(r[i] ?? "")));
213
- // The last column wraps under itself, so it only needs LAST_MIN columns to fit.
214
- const total = (ks) => indent +
215
- ks.reduce((a, i, k) => a + (k === ks.length - 1 ? Math.min(widthOf(i), LAST_MIN) : widthOf(i)), 0) +
216
- gap * Math.max(0, ks.length - 1);
217
- // Only a terminal drops columns: a pipe keeps everything for whoever reads it.
218
- while (color && total(keep) > width) {
219
- const droppable = keep.filter((i) => cols[i]?.drop !== undefined).sort((a, b) => cols[b].drop - cols[a].drop);
220
- if (!droppable.length)
221
- break;
222
- keep = keep.filter((i) => i !== droppable[0]);
223
- }
224
- const widths = new Map(keep.map((i) => [i, widthOf(i)]));
225
- return rows.map((r) => {
226
- const cells = keep.map((i, k) => {
227
- const cell = r[i] ?? "";
228
- const w = widths.get(i);
229
- if (cols[i]?.align === "right")
230
- return padStart(cell, w);
231
- return k === keep.length - 1 ? cell : padEnd(cell, w);
232
- });
233
- const head = " ".repeat(indent) +
234
- cells
235
- .slice(0, -1)
236
- .map((c) => `${c}${" ".repeat(gap)}`)
237
- .join("");
238
- return wrapLine(head, cells.at(-1) ?? "")
239
- .split("\n")
240
- .map((l) => l.trimEnd());
241
- });
242
- };
243
- const table = (rows, o) => tableRows(rows, o).flat();
244
- return {
245
- color,
246
- icons,
247
- width,
248
- bold,
249
- muted,
250
- accent,
251
- ok,
252
- warn,
253
- err,
254
- icon,
255
- lead: (name, text) => (ICONS[icons][name] ? `${icon(name)} ${text}` : text),
256
- profile: (name, c) => color && c !== undefined ? `\x1b[48;5;${c};1;38;5;255m ${name} \x1b[0m` : color ? bold(name) : name,
257
- header: (title) => {
258
- if (!color)
259
- return title;
260
- const rule = Math.max(0, Math.min(width, 80) - visibleWidth(title) - 1);
261
- return `${bold(title)} ${faint("─".repeat(rule))}`;
262
- },
263
- kv: (key, value, keyWidth, indent = 2) => wrapLine(`${" ".repeat(indent)}${muted(padEnd(key, keyWidth))} `, value).trimEnd(),
264
- table,
265
- tableRows,
266
- wrap: wrapLine,
267
- note: (state, text, indent = 2) => wrapLine(`${" ".repeat(indent)}${padEnd(icon(state), iconWidth)} `, text),
268
- bar: (pct, cells = 10) => {
269
- const p = Math.min(Math.max(pct, 0), 100);
270
- const filled = Math.round((p * cells) / 100);
271
- const paint = { ok, warn, err }[level(p)];
272
- // A heavy rule on a terminal (colored, the rest faint); blocks in plain text, where only shape tells.
273
- const [on, off] = color ? ["━", "━"] : ["█", "░"];
274
- return `${paint(on.repeat(filled))}${faint(off.repeat(cells - filled))} ${paint(`${p.toFixed(0)}%`.padStart(4))}`;
275
- },
276
- check: (state, text) => `${padEnd(icon(state), iconWidth)} ${text}`,
277
- };
278
- }
279
- const FRAMES = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
280
- /**
281
- * A spinner with the elapsed time on stderr, for steps that wait (the gateway starting). Only on
282
- * a terminal with colors: anywhere else it draws nothing, and the caller prints the result line.
283
- */
284
- export function spinner(io, text, opts = {}) {
285
- const now = opts.now ?? Date.now;
286
- const start = now();
287
- const tty = opts.tty ?? Boolean(process.stderr.isTTY);
288
- const write = opts.write ?? ((s) => process.stderr.write(s));
289
- if (!tty || !colors(io))
290
- return { update: () => { }, stop: () => now() - start };
291
- let current = text;
292
- let frame = 0;
293
- const draw = () => {
294
- const secs = ((now() - start) / 1000).toFixed(1);
295
- write(`\r\x1b[K\x1b[36m${FRAMES[frame++ % FRAMES.length]}\x1b[0m ${current} \x1b[2m${secs}s\x1b[0m`);
296
- };
297
- draw();
298
- const timer = setInterval(draw, 80);
299
- timer.unref?.();
300
- return {
301
- update: (t) => {
302
- current = t;
303
- },
304
- stop: () => {
305
- clearInterval(timer);
306
- write("\r\x1b[K");
307
- return now() - start;
308
- },
309
- };
310
- }
311
24
  //# sourceMappingURL=style.js.map
@@ -44,6 +44,10 @@ const ENVIRONMENT = [
44
44
  ["TURNO_NO_UPDATE_NOTIFIER", "1: same as TURNO_NO_UPDATE_CHECK (the name gh uses)"],
45
45
  ["TURNO_REGISTRY", "npm registry for update checks (default: npm_config_registry, else registry.npmjs.org)"],
46
46
  ["TURNO_BROWSER_IDLE", "turno-browser closes Chrome after this long without a tool call (default: 15m)"],
47
+ [
48
+ "TURNO_BROWSER_BACKGROUND_IDLE",
49
+ "the background server of a browser identity exits after this long without a request (default: 15m; 0: never)",
50
+ ],
47
51
  ["TURNO_LIGHTPANDA_PATH", "the Lightpanda binary turno-browser's read mode runs (default: lightpanda on PATH)"],
48
52
  [
49
53
  "TURNO_BROWSER_SESSION",
@@ -1,7 +1,7 @@
1
- import { isAbsolute, join, normalize } from "node:path";
1
+ import { join } from "node:path";
2
2
  import { browserPaths, turnoRoots } from "turno-core/paths";
3
3
  // The roots, private folders and PATH lookup are shared with turno-browser.
4
- export { PRIVATE_DIR_MODE, PRIVATE_FILE_MODE, ensurePrivateDir, findOnPath, isPrivatePath, privateRoots, resetPrivateDirCache, writePrivateFile, } from "turno-core/paths";
4
+ export { PRIVATE_DIR_MODE, PRIVATE_FILE_MODE, ensurePrivateDir, findOnPath, isPrivatePath, privateRoots, resetPrivateDirCache, tildify, writePrivateFile, } from "turno-core/paths";
5
5
  export function paths(env) {
6
6
  const { home, config, state, data } = turnoRoots(env);
7
7
  return {
@@ -36,13 +36,6 @@ export function paths(env) {
36
36
  export function profileDir(name, env) {
37
37
  return join(paths(env).home, `.claude-${name}`);
38
38
  }
39
- /** Replace the home prefix with ~ for display. */
40
- export function tildify(p, env) {
41
- // HOME may come with a trailing slash or doubled slashes (HOME=/Users/a/): compare normalized.
42
- const home = normalize(paths(env).home).replace(/(.)\/+$/, "$1");
43
- const q = isAbsolute(p) ? normalize(p) : p;
44
- return q === home ? "~" : home !== "/" && q.startsWith(`${home}/`) ? `~${q.slice(home.length)}` : p;
45
- }
46
39
  /** Expand a leading ~ to the home directory. */
47
40
  export function expandHome(p, env) {
48
41
  const home = paths(env).home;
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "turno-cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "turno-cli",
9
- "version": "0.4.0",
9
+ "version": "0.5.0",
10
10
  "license": "Apache-2.0",
11
11
  "dependencies": {
12
12
  "@modelcontextprotocol/sdk": "1.32.2",
13
13
  "smol-toml": "1.9.1",
14
- "turno-core": "0.1.0"
14
+ "turno-core": "0.2.0"
15
15
  },
16
16
  "bin": {
17
17
  "turno": "dist/cli/main.js"
@@ -1014,8 +1014,8 @@
1014
1014
  }
1015
1015
  },
1016
1016
  "node_modules/turno-core": {
1017
- "version": "0.1.0",
1018
- "resolved": "https://registry.npmjs.org/turno-core/-/turno-core-0.1.0.tgz",
1017
+ "version": "0.2.0",
1018
+ "resolved": "https://registry.npmjs.org/turno-core/-/turno-core-0.2.0.tgz",
1019
1019
  "license": "Apache-2.0",
1020
1020
  "engines": {
1021
1021
  "node": ">=22.11"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "turno-cli",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Switch accounts in your coding agents and keep the conversation, the MCP sign-ins and the browser session.",
5
5
  "keywords": [
6
6
  "claude-code",
@@ -47,11 +47,11 @@
47
47
  "dependencies": {
48
48
  "@modelcontextprotocol/sdk": "1.32.2",
49
49
  "smol-toml": "1.9.1",
50
- "turno-core": "0.1.0"
50
+ "turno-core": "0.2.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^26.6.6",
54
- "turno-browser": "0.4.0",
54
+ "turno-browser": "0.5.0",
55
55
  "turno-fonts": "0.1.2",
56
56
  "typescript": "^7.0.2",
57
57
  "vitest": "^5.1.0"