turno-cli 0.1.1 → 0.3.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.
Files changed (121) hide show
  1. package/CHANGELOG.md +432 -0
  2. package/README.md +228 -73
  3. package/dist/accounts/audit.js +154 -12
  4. package/dist/accounts/builtin.js +100 -25
  5. package/dist/accounts/delegate.js +199 -35
  6. package/dist/accounts/policy.js +79 -0
  7. package/dist/accounts/registry.js +39 -21
  8. package/dist/agents/adapter.js +29 -0
  9. package/dist/agents/claude.js +246 -0
  10. package/dist/agents/codex.js +186 -0
  11. package/dist/agents/copilot.js +56 -0
  12. package/dist/agents/cursor.js +58 -0
  13. package/dist/agents/index.js +26 -86
  14. package/dist/agents/snippets.js +43 -13
  15. package/dist/cli/args.js +38 -6
  16. package/dist/cli/commands/accounts.js +119 -52
  17. package/dist/cli/commands/auto.js +121 -33
  18. package/dist/cli/commands/browser-identity.js +514 -0
  19. package/dist/cli/commands/browser-session.js +102 -0
  20. package/dist/cli/commands/browser-vault.js +193 -0
  21. package/dist/cli/commands/browser.js +319 -138
  22. package/dist/cli/commands/complete.js +14 -3
  23. package/dist/cli/commands/completion.js +8 -2
  24. package/dist/cli/commands/config.js +186 -24
  25. package/dist/cli/commands/demo.js +321 -0
  26. package/dist/cli/commands/doctor.js +525 -123
  27. package/dist/cli/commands/handoff.js +33 -22
  28. package/dist/cli/commands/identity.js +192 -54
  29. package/dist/cli/commands/init.js +648 -0
  30. package/dist/cli/commands/limit.js +84 -16
  31. package/dist/cli/commands/mcp-call.js +240 -0
  32. package/dist/cli/commands/mcp-oauth.js +221 -0
  33. package/dist/cli/commands/mcp-observe.js +539 -0
  34. package/dist/cli/commands/mcp-share.js +201 -0
  35. package/dist/cli/commands/mcp.js +816 -187
  36. package/dist/cli/commands/mcpd.js +388 -76
  37. package/dist/cli/commands/migrate.js +6 -4
  38. package/dist/cli/commands/open.js +115 -27
  39. package/dist/cli/commands/profile.js +396 -78
  40. package/dist/cli/commands/resolve.js +14 -3
  41. package/dist/cli/commands/run.js +36 -6
  42. package/dist/cli/commands/secret.js +80 -76
  43. package/dist/cli/commands/session.js +17 -6
  44. package/dist/cli/commands/sessions.js +48 -12
  45. package/dist/cli/commands/setup.js +214 -164
  46. package/dist/cli/commands/status.js +227 -44
  47. package/dist/cli/commands/statusline.js +311 -114
  48. package/dist/cli/commands/ui.js +78 -68
  49. package/dist/cli/commands/undo.js +193 -18
  50. package/dist/cli/commands/uninstall.js +481 -0
  51. package/dist/cli/commands/upgrade.js +172 -79
  52. package/dist/cli/commands/usage.js +125 -51
  53. package/dist/cli/commands/version.js +21 -7
  54. package/dist/cli/commands/which.js +9 -24
  55. package/dist/cli/compile-cache.js +32 -0
  56. package/dist/cli/diagnostics.js +184 -0
  57. package/dist/cli/exit.js +65 -0
  58. package/dist/cli/group.js +24 -12
  59. package/dist/cli/help.js +62 -0
  60. package/dist/cli/highlight.js +236 -0
  61. package/dist/cli/hints.js +30 -0
  62. package/dist/cli/io.js +186 -1
  63. package/dist/cli/launch.js +52 -39
  64. package/dist/cli/launchers.js +161 -95
  65. package/dist/cli/main.js +201 -31
  66. package/dist/cli/optional.js +144 -0
  67. package/dist/cli/output.js +123 -0
  68. package/dist/cli/picker.js +459 -0
  69. package/dist/cli/registry.js +61 -6
  70. package/dist/cli/safe.js +87 -0
  71. package/dist/cli/secret-input.js +63 -0
  72. package/dist/cli/security.js +561 -0
  73. package/dist/cli/style.js +311 -0
  74. package/dist/cli/topics.js +142 -0
  75. package/dist/core/config.js +181 -23
  76. package/dist/core/exhausted.js +6 -8
  77. package/dist/core/fsutil.js +39 -0
  78. package/dist/core/journal.js +294 -16
  79. package/dist/core/manifest.js +153 -6
  80. package/dist/core/paths.js +14 -13
  81. package/dist/core/profiles.js +160 -10
  82. package/dist/core/resolve.js +139 -23
  83. package/dist/core/secrets.js +68 -23
  84. package/dist/core/sessions.js +13 -20
  85. package/dist/core/state-file.js +107 -0
  86. package/dist/core/update.js +31 -18
  87. package/dist/core/version.js +57 -10
  88. package/dist/demo/server.js +42 -0
  89. package/dist/mcpd/cache.js +23 -10
  90. package/dist/mcpd/calllog.js +254 -0
  91. package/dist/mcpd/client-names.js +46 -0
  92. package/dist/mcpd/connectors.js +188 -18
  93. package/dist/mcpd/daemon.js +472 -115
  94. package/dist/mcpd/folder-sets.js +42 -0
  95. package/dist/mcpd/gateway.js +473 -51
  96. package/dist/mcpd/health.js +313 -0
  97. package/dist/mcpd/importer.js +453 -36
  98. package/dist/mcpd/instances.js +453 -65
  99. package/dist/mcpd/jsonrpc.js +11 -1
  100. package/dist/mcpd/launchd.js +65 -48
  101. package/dist/mcpd/middleware.js +144 -0
  102. package/dist/mcpd/modern.js +686 -0
  103. package/dist/mcpd/oauth.js +845 -0
  104. package/dist/mcpd/peerpid.js +134 -6
  105. package/dist/mcpd/pressure.js +88 -0
  106. package/dist/mcpd/rss.js +166 -0
  107. package/dist/mcpd/service.js +191 -0
  108. package/dist/mcpd/share.js +217 -0
  109. package/dist/mcpd/state.js +183 -0
  110. package/dist/mcpd/sync.js +72 -87
  111. package/dist/mcpd/systemd.js +83 -0
  112. package/dist/mcpd/tokens.js +85 -0
  113. package/dist/mcpd/upstream.js +163 -46
  114. package/dist/statusline/cost.js +167 -44
  115. package/dist/statusline/input.js +78 -0
  116. package/dist/statusline/render.js +9 -3
  117. package/dist/ui/fonts.js +8 -3
  118. package/dist/ui/settings.js +33 -16
  119. package/npm-shrinkwrap.json +1102 -0
  120. package/package.json +10 -9
  121. package/dist/cli/commands/available.js +0 -18
@@ -0,0 +1,201 @@
1
+ /**
2
+ * `turno mcp export` and `turno mcp import <file>`: move MCP servers between machines
3
+ * without their secret values. The export is mcp.toml's own format; import also takes another
4
+ * agent's MCP config file.
5
+ */
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ import { parse } from "smol-toml";
8
+ import { isValidProfileName } from "../../core/config.js";
9
+ import { Journal } from "../../core/journal.js";
10
+ import { paths, tildify } from "../../core/paths.js";
11
+ import { JSON_FLAG, bool, parseFlags, str } from "../args.js";
12
+ import { nextStep } from "../hints.js";
13
+ import { CliError, fail, paint, plural } from "../io.js";
14
+ import { emit, jsonOutput } from "../output.js";
15
+ export const EXPORT_FLAGS = { profile: { type: "string" }, ...JSON_FLAG };
16
+ export const EXPORT_JSON = jsonOutput(["profile", "servers", "keychain", "envVars", "moved", "redacted", "text"]);
17
+ /** `turno mcp export [--profile p]`: mcp.toml on stdout, each secret by name only. */
18
+ export async function exportCmd(args, io) {
19
+ const p = parseFlags(args, EXPORT_FLAGS, 0);
20
+ const profile = str(p, "profile");
21
+ if (profile !== undefined && !isValidProfileName(profile))
22
+ fail(`invalid profile name: ${profile}`);
23
+ const file = paths(io.env).mcpFile;
24
+ if (!existsSync(file))
25
+ throw new CliError(`${tildify(file, io.env)} does not exist; nothing to export (turno mcp import drafts it)`);
26
+ const { exportManifest } = await import("../../mcpd/share.js");
27
+ const command = `turno mcp export${profile ? ` --profile ${profile}` : ""}`;
28
+ const r = exportManifest(readFileSync(file, "utf8"), { ...(profile ? { profile } : {}), command });
29
+ if (bool(p, "json")) {
30
+ emit(io, p, EXPORT_JSON, {
31
+ profile: profile ?? null,
32
+ servers: r.servers,
33
+ keychain: r.keychain,
34
+ envVars: r.envVars,
35
+ moved: r.moved,
36
+ redacted: r.redacted,
37
+ text: r.text,
38
+ });
39
+ return 0;
40
+ }
41
+ io.out(r.text.replace(/\n$/, ""));
42
+ // stderr: stdout is the file.
43
+ io.err(`turno: exported ${plural(r.servers.length, "server")}${profile ? ` for ${profile}` : ""}, no secret values`);
44
+ if (r.moved.length)
45
+ io.err(` literal secrets named as keychain references: ${r.moved.join(", ")}`);
46
+ if (r.redacted.length)
47
+ io.err(` ${paint(io, "warning", "33")}: secrets in ${r.redacted.join(", ")} replaced by <secret>; fill them in by hand`);
48
+ nextStep(io, "on the other machine, turno mcp import <file> --write, then the turno secret set lines at the top of the file", { stream: "err" });
49
+ return 0;
50
+ }
51
+ export const IMPORT_FLAGS = {
52
+ write: { type: "boolean" },
53
+ "move-secrets": { type: "boolean" },
54
+ force: { type: "boolean" },
55
+ "dry-run": { type: "boolean" },
56
+ };
57
+ /** The servers of `file`: mcp.toml's format, or an agent config converted like `turno mcp import` does. */
58
+ async function serversOf(file, io, write, moveSecrets) {
59
+ const { agentConfigServers, importServers, markOAuth, probeOAuth } = await import("../../mcpd/importer.js");
60
+ const { manifestServers } = await import("../../mcpd/share.js");
61
+ const shown = tildify(file, io.env);
62
+ if (!existsSync(file))
63
+ throw new CliError(`no such file: ${shown}`);
64
+ const text = readFileSync(file, "utf8");
65
+ const probe = write ? { probeAuth: (url) => probeOAuth(url) } : {};
66
+ let manifest = false;
67
+ try {
68
+ manifest = "server" in parse(text);
69
+ }
70
+ catch {
71
+ /* not TOML */
72
+ }
73
+ if (manifest) {
74
+ const servers = manifestServers(text, shown);
75
+ const notes = [];
76
+ if (probe.probeAuth)
77
+ await markOAuth(servers, probe.probeAuth, notes);
78
+ return { servers, notes, secrets: [], literalSecrets: [], from: "mcp.toml format" };
79
+ }
80
+ const found = agentConfigServers(text);
81
+ if (!found)
82
+ throw new CliError(`${shown} is not an mcp.toml (turno mcp export), a JSON file with mcpServers or a Codex config.toml with [mcp_servers]`);
83
+ const { binOf } = await import("./mcp.js");
84
+ const report = await importServers(found.servers, {
85
+ moveSecrets,
86
+ ...probe,
87
+ ...(write ? { binOf: (pkg) => binOf(io, pkg) } : {}),
88
+ });
89
+ return {
90
+ servers: manifestServers(report.toml, shown),
91
+ notes: report.notes,
92
+ secrets: report.secrets,
93
+ literalSecrets: report.literalSecrets,
94
+ from: `${found.agent} config`,
95
+ };
96
+ }
97
+ /** `turno mcp import <file>`: merge its servers into mcp.toml (a preview until --write). */
98
+ export async function importFile(file, args, io) {
99
+ const p = parseFlags(args, IMPORT_FLAGS, 1);
100
+ const write = bool(p, "write");
101
+ const force = bool(p, "force");
102
+ const moveSecrets = bool(p, "move-secrets");
103
+ if (write && bool(p, "dry-run"))
104
+ fail("--dry-run and --write do not go together (without --write it is a preview)");
105
+ const target = paths(io.env).mcpFile;
106
+ const r = await serversOf(file, io, write, moveSecrets);
107
+ const names = Object.keys(r.servers);
108
+ if (!names.length) {
109
+ io.out(`no MCP servers in ${tildify(file, io.env)}; nothing to import`);
110
+ return write ? 1 : 0;
111
+ }
112
+ const { mergeServers } = await import("../../mcpd/share.js");
113
+ const existing = existsSync(target) ? readFileSync(target, "utf8") : "";
114
+ let merged;
115
+ try {
116
+ merged = mergeServers(existing, r.servers, force);
117
+ }
118
+ catch (err) {
119
+ throw new CliError(err.message);
120
+ }
121
+ io.err(`found ${plural(names.length, "server")} in ${tildify(file, io.env)} (${r.from})`);
122
+ for (const n of r.notes)
123
+ io.err(` ${n}`);
124
+ if (r.literalSecrets.length)
125
+ io.err(` ${paint(io, "warning", "33")}: literal secrets kept (${r.literalSecrets.join(", ")}); add --move-secrets to store them in the Keychain`);
126
+ const verb = write ? ["added", "replaced", "kept"] : ["would add", "would replace", "would keep"];
127
+ const lines = [
128
+ merged.added.length ? `${verb[0]} ${merged.added.join(", ")}` : "",
129
+ merged.replaced.length ? `${verb[1]} ${merged.replaced.join(", ")}` : "",
130
+ merged.kept.length ? `${verb[2]} ${merged.kept.join(", ")} (already in mcp.toml; --force replaces them)` : "",
131
+ ].filter(Boolean);
132
+ if (!write) {
133
+ for (const l of lines)
134
+ io.out(l);
135
+ for (const s of r.secrets)
136
+ io.err(` would move ${s.where} to keychain:${s.service}`);
137
+ io.err(`Nothing written. Write it with: turno mcp import ${file} --write${moveSecrets ? " --move-secrets" : ""}${merged.kept.length ? " [--force]" : ""}`);
138
+ return 0;
139
+ }
140
+ if (!merged.added.length && !merged.replaced.length) {
141
+ for (const l of lines)
142
+ io.out(l);
143
+ return 0;
144
+ }
145
+ const { storeKeychainSecret } = await import("../../core/secrets.js");
146
+ for (const s of r.secrets) {
147
+ if (s.value.includes("${"))
148
+ continue;
149
+ await storeKeychainSecret(s.service, s.value, io.env);
150
+ io.err(` moved ${s.where} to keychain:${s.service}`);
151
+ }
152
+ const journal = new Journal(io.env, `mcp import ${file} --write`);
153
+ journal.write(target, merged.text, 0o600);
154
+ for (const l of lines)
155
+ io.out(l);
156
+ io.out(`wrote ${tildify(target, io.env)}`);
157
+ io.out(journal.hint());
158
+ nextStep(io, importNextSteps(merged.text, [...merged.added, ...merged.replaced]));
159
+ return 0;
160
+ }
161
+ /** What to run after importing `names`: secrets to store, packages to pin, logins, then sync. */
162
+ export function importNextSteps(text, names) {
163
+ const steps = [];
164
+ const keychain = new Set();
165
+ let packages = false;
166
+ const logins = [];
167
+ // Read back what was written, so the steps match the file.
168
+ const raw = parseRaw(text);
169
+ for (const n of names) {
170
+ const s = raw[n] ?? {};
171
+ if (typeof s.package === "string")
172
+ packages = true;
173
+ if (s.auth === "oauth")
174
+ logins.push(n);
175
+ const variants = s.variant && typeof s.variant === "object"
176
+ ? Object.values(s.variant)
177
+ : [];
178
+ for (const t of [s, ...variants]) {
179
+ for (const key of ["env", "headers"]) {
180
+ const m = t?.[key];
181
+ if (m && typeof m === "object")
182
+ for (const v of Object.values(m))
183
+ if (typeof v === "string" && v.startsWith("keychain:"))
184
+ keychain.add(v.slice(9));
185
+ }
186
+ }
187
+ }
188
+ if (keychain.size)
189
+ steps.push(`turno secret list shows which of ${plural(keychain.size, "keychain reference")} still need turno secret set`);
190
+ if (packages)
191
+ steps.push("turno mcp install pins and installs the packages");
192
+ if (logins.length)
193
+ steps.push(`turno mcp login ${logins.join(", ")} (one login each)`);
194
+ steps.push("turno mcp sync points your profiles at them");
195
+ return steps;
196
+ }
197
+ function parseRaw(text) {
198
+ const raw = parse(text);
199
+ return (raw.server ?? {});
200
+ }
201
+ //# sourceMappingURL=mcp-share.js.map