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,292 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { chmodSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { fileURLToPath } from "node:url";
|
|
6
|
+
import { Journal } from "../../core/journal.js";
|
|
7
|
+
import { paths } from "../../core/paths.js";
|
|
8
|
+
import { literal, setValue } from "../../core/toml-edit.js";
|
|
9
|
+
import { bool, parseFlags } from "../args.js";
|
|
10
|
+
import { profileColor, stripAnsi, style } from "../style.js";
|
|
11
|
+
import { findOnPath } from "../launchers.js";
|
|
12
|
+
import { setupProfiles } from "./setup.js";
|
|
13
|
+
import { pidAlive } from "../../core/fsutil.js";
|
|
14
|
+
/**
|
|
15
|
+
* `turno demo` (ADR 0030): turno in a throwaway HOME under the OS temp folder, with two Claude
|
|
16
|
+
* Code profiles, a folder rule, two MCP servers behind an mcpd on a free port, and the status
|
|
17
|
+
* line. It never reads or writes the person's own HOME, never signs in, needs no global install
|
|
18
|
+
* (it works from npx's cache), and always stops mcpd and removes the folder when it ends.
|
|
19
|
+
*/
|
|
20
|
+
const PREFIX = "turno-demo-";
|
|
21
|
+
/** A file in every demo HOME with the PID of the demo that owns it. */
|
|
22
|
+
const OWNER = ".turno-demo";
|
|
23
|
+
/** Variables a demo session keeps from the caller: terminal and locale, never config or tokens. */
|
|
24
|
+
const KEEP = ["PATH", "TERM", "COLORTERM", "TERM_PROGRAM", "LANG", "LC_ALL", "LC_CTYPE", "TMPDIR", "USER", "LOGNAME", "SHELL", "COLUMNS", "NO_COLOR"];
|
|
25
|
+
/** The env of everything that runs inside the demo: the demo HOME, its launchers first on PATH. */
|
|
26
|
+
export function demoEnv(base, home) {
|
|
27
|
+
const env = {};
|
|
28
|
+
for (const k of KEEP)
|
|
29
|
+
if (base[k] !== undefined)
|
|
30
|
+
env[k] = base[k];
|
|
31
|
+
env.HOME = home;
|
|
32
|
+
env.PATH = `${join(home, ".local", "bin")}:${base.PATH ?? "/usr/bin:/bin"}`;
|
|
33
|
+
env.TURNO_NO_UPDATE_CHECK = "1";
|
|
34
|
+
return env;
|
|
35
|
+
}
|
|
36
|
+
const PROFILES = [
|
|
37
|
+
{ name: "work", color: "violet", folder: "code/acme" },
|
|
38
|
+
{ name: "personal", color: "green", folder: "code/personal-site" },
|
|
39
|
+
];
|
|
40
|
+
const SERVERS = ["docs", "issues"];
|
|
41
|
+
/** Remove demo HOMEs left by a demo that was killed (SIGKILL, power loss): their owner is gone. */
|
|
42
|
+
function removeStale(tmp) {
|
|
43
|
+
let names = [];
|
|
44
|
+
try {
|
|
45
|
+
names = readdirSync(tmp);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const n of names) {
|
|
51
|
+
if (!n.startsWith(PREFIX))
|
|
52
|
+
continue;
|
|
53
|
+
const dir = join(tmp, n);
|
|
54
|
+
let pid = 0;
|
|
55
|
+
try {
|
|
56
|
+
pid = Number.parseInt(readFileSync(join(dir, OWNER), "utf8"), 10);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
continue; // not made by turno demo: never touched
|
|
60
|
+
}
|
|
61
|
+
if (pid > 0 && !pidAlive(pid))
|
|
62
|
+
rmSync(dir, { recursive: true, force: true });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** An Io that keeps the output of the steps the demo runs for itself. */
|
|
66
|
+
function quietIo(env) {
|
|
67
|
+
const text = [];
|
|
68
|
+
return { env, isTty: false, text, out: (l = "") => text.push(l), err: (l = "") => text.push(l) };
|
|
69
|
+
}
|
|
70
|
+
/** A single-quoted POSIX shell word. */
|
|
71
|
+
const sq = (s) => `'${s.replace(/'/g, "'\\''")}'`;
|
|
72
|
+
function write(file, text, mode = 0o600) {
|
|
73
|
+
mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
|
|
74
|
+
writeFileSync(file, text, { mode });
|
|
75
|
+
chmodSync(file, mode);
|
|
76
|
+
}
|
|
77
|
+
function manifestText(server) {
|
|
78
|
+
const lines = ["# turno demo: two MCP servers behind the gateway. Each starts on first use and stops when idle.", ""];
|
|
79
|
+
for (const name of SERVERS) {
|
|
80
|
+
lines.push(`[server.${name}]`, `command = ${literal(server.command)}`, `args = ${literal([...server.args, name])}`, 'scope = "shared"', "");
|
|
81
|
+
}
|
|
82
|
+
// The same server, another account: the work profile gets its own process.
|
|
83
|
+
lines.push("[server.issues.variant.work]", 'env = { DEMO_ACCOUNT = "work" }', "");
|
|
84
|
+
return lines.join("\n");
|
|
85
|
+
}
|
|
86
|
+
function configText() {
|
|
87
|
+
const lines = ["# turno demo: ~/code/acme opens with the work profile, every other folder with personal.", 'default = "personal"', 'icons = "unicode"', ""];
|
|
88
|
+
for (const p of PROFILES)
|
|
89
|
+
lines.push(`[profiles.${p.name}]`, `color = "${p.color}"`, "");
|
|
90
|
+
lines.push("[[projects]]", 'path = "~/code/acme"', 'profile = "work"', "");
|
|
91
|
+
return lines.join("\n");
|
|
92
|
+
}
|
|
93
|
+
function samplePayload(home, folder, now) {
|
|
94
|
+
return {
|
|
95
|
+
session_id: "turno-demo",
|
|
96
|
+
model: { display_name: "Opus" },
|
|
97
|
+
workspace: { current_dir: join(home, folder), project_dir: join(home, folder) },
|
|
98
|
+
cost: { total_cost_usd: 0.42, total_lines_added: 120, total_lines_removed: 18 },
|
|
99
|
+
context_window: { used_percentage: 23, total_input_tokens: 46_000, context_window_size: 200_000 },
|
|
100
|
+
rate_limits: { five_hour: { used_percentage: 38, resets_at: Math.trunc(now) + 2 * 3600 }, seven_day: { used_percentage: 12, resets_at: Math.trunc(now) + 4 * 86400 } },
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
/** Build the demo HOME and start its gateway. The caller must call stop(). */
|
|
104
|
+
export async function startDemo(io, opts = {}) {
|
|
105
|
+
const tmp = realpathSync(opts.tmp ?? tmpdir());
|
|
106
|
+
removeStale(tmp);
|
|
107
|
+
const home = mkdtempSync(join(tmp, PREFIX));
|
|
108
|
+
writeFileSync(join(home, OWNER), `${process.pid}\n`);
|
|
109
|
+
let daemon;
|
|
110
|
+
let stopped = false;
|
|
111
|
+
// Last resort if the process ends without stop() (an uncaught error): the files still go.
|
|
112
|
+
const onExit = () => rmSync(home, { recursive: true, force: true });
|
|
113
|
+
process.on("exit", onExit);
|
|
114
|
+
const stop = async () => {
|
|
115
|
+
if (stopped)
|
|
116
|
+
return;
|
|
117
|
+
stopped = true;
|
|
118
|
+
try {
|
|
119
|
+
await daemon?.stop();
|
|
120
|
+
}
|
|
121
|
+
finally {
|
|
122
|
+
rmSync(home, { recursive: true, force: true });
|
|
123
|
+
process.off("exit", onExit);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
try {
|
|
127
|
+
const env = demoEnv(io.env, home);
|
|
128
|
+
const p = paths(env);
|
|
129
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
130
|
+
const entry = opts.entry ?? join(here, "..", "main.js");
|
|
131
|
+
const server = opts.server ?? { command: process.execPath, args: [join(here, "..", "..", "demo", "server.js")] };
|
|
132
|
+
const shim = join(p.bin, "turno");
|
|
133
|
+
write(shim, `#!/bin/sh\n# turno demo: the turno that started this demo\nexec ${sq(process.execPath)} ${sq(entry)} "$@"\n`, 0o755);
|
|
134
|
+
write(join(home, ".zshrc"), "# turno demo\nPROMPT='%F{magenta}turno demo%f %~ %# '\n");
|
|
135
|
+
write(join(home, ".bashrc"), "# turno demo\nPS1='turno demo \\w \\$ '\n");
|
|
136
|
+
// The hub settings.json is linked into every profile, so both draw turno's status line.
|
|
137
|
+
write(join(p.hub, "settings.json"), `${JSON.stringify({ statusLine: { type: "command", command: `${JSON.stringify(shim)} statusline`, padding: 0 } }, null, 2)}\n`);
|
|
138
|
+
for (const f of PROFILES)
|
|
139
|
+
mkdirSync(join(home, f.folder), { recursive: true });
|
|
140
|
+
write(p.mcpFile, manifestText(server));
|
|
141
|
+
write(p.configFile, configText());
|
|
142
|
+
const quiet = quietIo(env);
|
|
143
|
+
setupProfiles(PROFILES.map((f) => f.name), quiet, { turno: sq(shim), journal: new Journal(env, "demo setup") });
|
|
144
|
+
const { startDaemon } = await import("../../mcpd/daemon.js");
|
|
145
|
+
daemon = await startDaemon({ env, port: 0 });
|
|
146
|
+
const port = daemon.port;
|
|
147
|
+
write(p.configFile, setValue(configText(), "mcpd", "port", port));
|
|
148
|
+
const { command: mcp } = await import("./mcp.js");
|
|
149
|
+
if ((await mcp.run(["sync"], quiet)) !== 0)
|
|
150
|
+
throw new Error(`mcp sync failed in the demo:\n${quiet.text.join("\n")}`);
|
|
151
|
+
// The status line without its background workers: a known plan, a gateway known to answer.
|
|
152
|
+
const now = Date.now() / 1000;
|
|
153
|
+
write(join(p.planDir, "work"), "max");
|
|
154
|
+
write(join(p.planDir, "personal"), "pro");
|
|
155
|
+
write(join(p.state, "cache", "mcpd-health.json"), JSON.stringify({ ok: true, port, checked_at: Math.trunc(now) + 10 * 365 * 86400 }));
|
|
156
|
+
write(join(home, "statusline.json"), `${JSON.stringify(samplePayload(home, PROFILES[0].folder, now), null, 2)}\n`);
|
|
157
|
+
const { collect } = await import("./statusline.js");
|
|
158
|
+
const { render } = await import("../../statusline/render.js");
|
|
159
|
+
const statusLines = PROFILES.map((f) => render(collect(samplePayload(home, f.folder, now), { ...env, CLAUDE_CONFIG_DIR: join(home, `.claude-${f.name}`) }, now, [])).replace(/\n$/, ""));
|
|
160
|
+
return { home, env, port, statusLines, stop };
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
await stop();
|
|
164
|
+
throw err;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
function intro(io, d) {
|
|
168
|
+
const s = style(io);
|
|
169
|
+
io.out(s.wrap(`${s.bold(s.accent("turno demo"))} `, s.muted(`a throwaway HOME at ${d.home}`)));
|
|
170
|
+
io.out("");
|
|
171
|
+
io.out(s.header("Set up"));
|
|
172
|
+
const colors = Object.fromEntries(PROFILES.map((p) => [p.name, { color: p.color }]));
|
|
173
|
+
const [work, personal] = PROFILES.map((p) => s.profile(p.name, profileColor(colors, p.name)));
|
|
174
|
+
io.out(s.kv("profiles", `${work} for ~/code/acme, ${personal} for every other folder ${s.muted("(Claude Code)")}`, 8));
|
|
175
|
+
io.out(s.kv("gateway", `${s.lead("on", "mcpd")} on 127.0.0.1:${d.port} ${s.muted("with docs and issues, synced into both profiles")}`, 8));
|
|
176
|
+
io.out(s.kv("status", s.muted("the line Claude Code draws for each profile:"), 8));
|
|
177
|
+
io.out("");
|
|
178
|
+
for (const l of d.statusLines)
|
|
179
|
+
io.out(s.color ? l : stripAnsi(l));
|
|
180
|
+
io.out("");
|
|
181
|
+
io.out(s.header("Try"));
|
|
182
|
+
const rows = [
|
|
183
|
+
["turno status", "the one-screen summary"],
|
|
184
|
+
["turno profile which ~/code/acme", "which account a folder opens with, and why"],
|
|
185
|
+
["turno mcp list", "the servers behind the gateway"],
|
|
186
|
+
["cat ~/.claude-work/.claude.json", "the gateway entries turno mcp sync wrote"],
|
|
187
|
+
["CLAUDE_CONFIG_DIR=~/.claude-work turno statusline < ~/statusline.json", "draw the work status line yourself"],
|
|
188
|
+
["turno undo --list", "every change turno made, each one undoable"],
|
|
189
|
+
];
|
|
190
|
+
if (findOnPath("claude", d.env))
|
|
191
|
+
rows.push(["cd ~/code/acme && turno auto mcp list", "Claude Code connects to both servers through mcpd (no sign-in)"]);
|
|
192
|
+
// Commands up to 40 columns share one column; a longer one puts its note on the next line.
|
|
193
|
+
const w = Math.max(...rows.map(([c]) => c.length).filter((n) => n <= 40));
|
|
194
|
+
for (const [c, why] of rows) {
|
|
195
|
+
if (c.length > w)
|
|
196
|
+
io.out(` ${s.bold(c)}\n${s.wrap(` ${" ".repeat(w)} `, s.muted(why))}`);
|
|
197
|
+
else
|
|
198
|
+
io.out(s.wrap(` ${s.bold(c.padEnd(w))} `, s.muted(why)));
|
|
199
|
+
}
|
|
200
|
+
io.out("");
|
|
201
|
+
io.out(s.muted("Nothing here reads or changes your own HOME, and nothing signs in."));
|
|
202
|
+
}
|
|
203
|
+
const USAGE = `Usage: turno demo [--keep] [-- <command> [args...]]
|
|
204
|
+
|
|
205
|
+
Try turno without touching your setup. The demo builds a throwaway HOME under the temp folder
|
|
206
|
+
with two Claude Code profiles (work, personal), a folder rule, two MCP servers behind an mcpd on
|
|
207
|
+
a free port, and the status line. It never signs in.
|
|
208
|
+
|
|
209
|
+
In a terminal it opens a shell in that HOME; exit the shell to end the demo. With a command after
|
|
210
|
+
--, it runs that command in the demo instead. With --keep it waits for Ctrl-C instead, so you can
|
|
211
|
+
use the demo from another terminal. Without a terminal (a pipe, --no-input, an agent) and without
|
|
212
|
+
--keep it prints what it set up and ends. Either way it stops mcpd and removes the folder when it
|
|
213
|
+
ends. Works from npx: npx turno-cli demo`;
|
|
214
|
+
const KEEP_FLAG = { keep: { type: "boolean" } };
|
|
215
|
+
/** Run the demo: a shell, a command, or a wait for Ctrl-C. Returns the exit code. */
|
|
216
|
+
export async function runDemo(args, io, opts = {}) {
|
|
217
|
+
const end = args.indexOf("--");
|
|
218
|
+
const keep = bool(parseFlags(end < 0 ? args : args.slice(0, end), KEEP_FLAG, 0), "keep");
|
|
219
|
+
const cmd = end < 0 ? [] : args.slice(end + 1);
|
|
220
|
+
const d = await startDemo(io, opts);
|
|
221
|
+
let child;
|
|
222
|
+
let wake;
|
|
223
|
+
// Ctrl-C reaches a child in the foreground from the terminal; the demo waits for it to end.
|
|
224
|
+
// SIGTERM and SIGHUP (the terminal closed) end the child, then the demo cleans up.
|
|
225
|
+
const onSignal = (sig) => {
|
|
226
|
+
if (!child)
|
|
227
|
+
return wake?.();
|
|
228
|
+
if (sig === "SIGINT")
|
|
229
|
+
return;
|
|
230
|
+
child.kill(cmd.length ? sig : "SIGHUP");
|
|
231
|
+
setTimeout(() => child?.kill("SIGKILL"), 3000).unref();
|
|
232
|
+
};
|
|
233
|
+
const signals = ["SIGINT", "SIGTERM", "SIGHUP"];
|
|
234
|
+
for (const s of signals)
|
|
235
|
+
process.on(s, onSignal);
|
|
236
|
+
const onAbort = () => wake?.();
|
|
237
|
+
opts.signal?.addEventListener("abort", onAbort);
|
|
238
|
+
try {
|
|
239
|
+
if (cmd.length) {
|
|
240
|
+
io.err(`turno demo: running ${cmd.join(" ")} in a throwaway HOME at ${d.home} (mcpd on 127.0.0.1:${d.port})`);
|
|
241
|
+
return await runChild(cmd[0], cmd.slice(1), d, (c) => (child = c));
|
|
242
|
+
}
|
|
243
|
+
intro(io, d);
|
|
244
|
+
io.out("");
|
|
245
|
+
if (io.ask && !keep) {
|
|
246
|
+
io.out("Opening a shell in the demo HOME. Type exit to end the demo; it then stops mcpd and removes everything.");
|
|
247
|
+
const shell = d.env.SHELL || "/bin/sh";
|
|
248
|
+
return await runChild(shell, ["-i"], d, (c) => (child = c));
|
|
249
|
+
}
|
|
250
|
+
if (!keep) {
|
|
251
|
+
// Nobody can open the shell or press Ctrl-C here: show what the demo holds and end it.
|
|
252
|
+
io.out(style(io).wrap("", style(io).muted("No terminal here (a pipe, --no-input or an agent), so the demo ends now. Run a command in it with turno demo -- turno status, or pass --keep to keep it until Ctrl-C.")));
|
|
253
|
+
return 0;
|
|
254
|
+
}
|
|
255
|
+
io.out(`From another terminal: export HOME=${d.home} PATH=${d.home}/.local/bin:$PATH`);
|
|
256
|
+
io.out("Press Ctrl-C to stop the demo and remove it.");
|
|
257
|
+
await new Promise((resolve) => {
|
|
258
|
+
wake = resolve;
|
|
259
|
+
if (opts.signal?.aborted)
|
|
260
|
+
resolve();
|
|
261
|
+
});
|
|
262
|
+
return 0;
|
|
263
|
+
}
|
|
264
|
+
finally {
|
|
265
|
+
for (const s of signals)
|
|
266
|
+
process.off(s, onSignal);
|
|
267
|
+
opts.signal?.removeEventListener("abort", onAbort);
|
|
268
|
+
await d.stop();
|
|
269
|
+
io.err(`turno demo: stopped mcpd and removed ${d.home}`);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function runChild(file, args, d, track) {
|
|
273
|
+
return new Promise((resolve) => {
|
|
274
|
+
const c = spawn(file, args, { stdio: "inherit", env: d.env, cwd: d.home });
|
|
275
|
+
track(c);
|
|
276
|
+
c.once("error", (err) => {
|
|
277
|
+
process.stderr.write(`turno demo: cannot run ${file}: ${err.message}\n`);
|
|
278
|
+
resolve(127);
|
|
279
|
+
});
|
|
280
|
+
c.once("exit", (code, signal) => resolve(code ?? (signal ? 128 + (signalNumber(signal) ?? 1) : 1)));
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function signalNumber(signal) {
|
|
284
|
+
return { SIGHUP: 1, SIGINT: 2, SIGKILL: 9, SIGTERM: 15 }[signal];
|
|
285
|
+
}
|
|
286
|
+
export const command = {
|
|
287
|
+
summary: "try turno in a throwaway HOME: two profiles, a gateway and the status line (removed on exit)",
|
|
288
|
+
usage: USAGE,
|
|
289
|
+
flags: ["--keep"],
|
|
290
|
+
run: (args, io) => runDemo(args, io),
|
|
291
|
+
};
|
|
292
|
+
//# sourceMappingURL=demo.js.map
|