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,144 @@
1
+ /**
2
+ * Optional packages: installed apart from turno-cli and loaded only by the commands that need
3
+ * them. turno-browser today; a turno-tui later goes in OPTIONAL the same way.
4
+ */
5
+ import { execFileSync } from "node:child_process";
6
+ import { existsSync, readdirSync, realpathSync } from "node:fs";
7
+ import { createRequire } from "node:module";
8
+ import { join, sep } from "node:path";
9
+ import { fileURLToPath, pathToFileURL } from "node:url";
10
+ import { CliError } from "./io.js";
11
+ export const OPTIONAL = {
12
+ browser: { name: "turno-browser", install: "npm install --global turno-browser" },
13
+ tui: { name: "turno-tui", install: "npm install --global turno-tui" },
14
+ };
15
+ function isApiVersion(v) {
16
+ const o = v;
17
+ return (typeof o === "object" && o !== null && [o.major, o.minor].every((n) => Number.isInteger(n) && n >= 0));
18
+ }
19
+ /**
20
+ * Why an installed package's `API_VERSION` does not fit the one this turno was built against,
21
+ * or undefined when it does: the same major and at least the minor. One line that names the
22
+ * command to run: update the package when it is older, update turno when it is newer.
23
+ */
24
+ export function apiMismatch(pkg, found, wanted) {
25
+ const needs = `this turno needs ${wanted.major}.${wanted.minor} or a later ${wanted.major}.x`;
26
+ const update = `update it: ${pkg.install}@latest`;
27
+ if (!isApiVersion(found))
28
+ return `${pkg.name} is too old for this turno (it has no API_VERSION, ${needs}); ${update}`;
29
+ if (found.major > wanted.major)
30
+ return `${pkg.name} is too new for this turno (its API is ${found.major}.${found.minor}, this turno speaks ${wanted.major}.x); update turno: turno upgrade`;
31
+ if (found.major < wanted.major || found.minor < wanted.minor)
32
+ return `${pkg.name} is too old for this turno (its API is ${found.major}.${found.minor}, ${needs}); ${update}`;
33
+ return undefined;
34
+ }
35
+ /** "turno-browser is not installed: npm install --global turno-browser". */
36
+ export function notInstalled(pkg) {
37
+ return `${pkg.name} is not installed: ${pkg.install}`;
38
+ }
39
+ /** Whether an import failed because the package (or its entry) is not there. */
40
+ export function isMissingModule(err) {
41
+ const code = err?.code;
42
+ return code === "ERR_MODULE_NOT_FOUND" || code === "MODULE_NOT_FOUND" || code === "ERR_PACKAGE_PATH_NOT_EXPORTED";
43
+ }
44
+ /** The global npm folder, where `npm install --global <pkg>` puts packages. */
45
+ function npmGlobalRoot(env) {
46
+ try {
47
+ return (execFileSync("npm", ["root", "--global"], {
48
+ env,
49
+ encoding: "utf8",
50
+ stdio: ["ignore", "pipe", "ignore"],
51
+ timeout: 5000,
52
+ }).trim() || undefined);
53
+ }
54
+ catch {
55
+ return undefined;
56
+ }
57
+ }
58
+ /**
59
+ * The node_modules folders of every pnpm global group, when `self` (this turno's package
60
+ * folder) is in one. pnpm 11 and later install each global package in its own group
61
+ * (`$PNPM_HOME/global/v11/<group>/node_modules`), so a package added with its own
62
+ * `pnpm add --global` is not next to turno, and npm's global folder does not have it either.
63
+ */
64
+ export function pnpmGlobalRoots(self) {
65
+ let real = self;
66
+ try {
67
+ real = realpathSync(self);
68
+ }
69
+ catch {
70
+ /* keep it */
71
+ }
72
+ const parts = real.split(sep);
73
+ const at = parts.findIndex((p, i) => p === "global" && /^v\d+$/.test(parts[i + 1] ?? "") && parts[i + 3] === "node_modules");
74
+ if (at < 0)
75
+ return [];
76
+ const groups = parts.slice(0, at + 2).join(sep);
77
+ let names;
78
+ try {
79
+ names = readdirSync(groups).sort();
80
+ }
81
+ catch {
82
+ return [];
83
+ }
84
+ return names.map((g) => join(groups, g, "node_modules")).filter((d) => existsSync(d));
85
+ }
86
+ /**
87
+ * Load an optional package: next to this install first, then (with `global`) from the global
88
+ * npm folder. Undefined when it is not installed; any other import error is thrown, as is a
89
+ * module whose API_VERSION does not fit or that the guard rejects (a CliError naming the
90
+ * update command).
91
+ */
92
+ export async function loadOptional(pkg, options = {}) {
93
+ const load = options.importer ?? ((s) => import(s));
94
+ const checked = (mod) => {
95
+ if (options.api) {
96
+ const problem = apiMismatch(pkg, mod?.API_VERSION, options.api);
97
+ if (problem)
98
+ throw new CliError(problem);
99
+ }
100
+ if (options.guard && !options.guard(mod))
101
+ throw new CliError(`this ${pkg.name} is too old or not a ${pkg.name} for this turno; update it: ${pkg.install}@latest`);
102
+ return mod;
103
+ };
104
+ try {
105
+ return checked(await load(pkg.name));
106
+ }
107
+ catch (err) {
108
+ if (!isMissingModule(err))
109
+ throw err;
110
+ }
111
+ if (!options.global)
112
+ return undefined;
113
+ const self = options.self ?? fileURLToPath(new URL("../../", import.meta.url));
114
+ for (const root of pnpmGlobalRoots(self)) {
115
+ const found = await loadFrom(root, pkg, load, checked);
116
+ if (found !== undefined)
117
+ return found;
118
+ }
119
+ const root = (options.globalRoot ?? npmGlobalRoot)(options.env ?? process.env);
120
+ if (!root)
121
+ return undefined;
122
+ return await loadFrom(root, pkg, load, checked);
123
+ }
124
+ /** The package as installed in the node_modules folder `root`, undefined when it is not there. */
125
+ async function loadFrom(root, pkg, load, checked) {
126
+ let entry;
127
+ try {
128
+ entry = createRequire(join(root, "noop.js")).resolve(pkg.name);
129
+ }
130
+ catch (err) {
131
+ if (isMissingModule(err))
132
+ return undefined;
133
+ throw err;
134
+ }
135
+ try {
136
+ return checked(await load(pathToFileURL(entry).href));
137
+ }
138
+ catch (err) {
139
+ if (isMissingModule(err))
140
+ return undefined;
141
+ throw err;
142
+ }
143
+ }
144
+ //# sourceMappingURL=optional.js.map
@@ -0,0 +1,123 @@
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
+ }
123
+ //# sourceMappingURL=output.js.map