turno-cli 0.1.1 → 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.
Files changed (104) hide show
  1. package/CHANGELOG.md +284 -0
  2. package/README.md +120 -53
  3. package/dist/accounts/audit.js +137 -7
  4. package/dist/accounts/builtin.js +68 -21
  5. package/dist/accounts/delegate.js +176 -35
  6. package/dist/accounts/policy.js +77 -0
  7. package/dist/accounts/registry.js +37 -21
  8. package/dist/agents/adapter.js +7 -0
  9. package/dist/agents/claude.js +195 -0
  10. package/dist/agents/codex.js +98 -0
  11. package/dist/agents/copilot.js +39 -0
  12. package/dist/agents/cursor.js +41 -0
  13. package/dist/agents/index.js +26 -86
  14. package/dist/agents/snippets.js +7 -4
  15. package/dist/cli/args.js +19 -4
  16. package/dist/cli/commands/accounts.js +96 -51
  17. package/dist/cli/commands/auto.js +82 -32
  18. package/dist/cli/commands/browser.js +216 -135
  19. package/dist/cli/commands/complete.js +2 -1
  20. package/dist/cli/commands/completion.js +4 -2
  21. package/dist/cli/commands/config.js +103 -18
  22. package/dist/cli/commands/demo.js +292 -0
  23. package/dist/cli/commands/doctor.js +387 -119
  24. package/dist/cli/commands/handoff.js +33 -22
  25. package/dist/cli/commands/identity.js +101 -50
  26. package/dist/cli/commands/init.js +616 -0
  27. package/dist/cli/commands/limit.js +25 -13
  28. package/dist/cli/commands/mcp-oauth.js +194 -0
  29. package/dist/cli/commands/mcp-observe.js +434 -0
  30. package/dist/cli/commands/mcp.js +653 -185
  31. package/dist/cli/commands/mcpd.js +323 -75
  32. package/dist/cli/commands/migrate.js +6 -4
  33. package/dist/cli/commands/open.js +92 -27
  34. package/dist/cli/commands/profile.js +205 -69
  35. package/dist/cli/commands/resolve.js +6 -2
  36. package/dist/cli/commands/run.js +15 -5
  37. package/dist/cli/commands/secret.js +61 -42
  38. package/dist/cli/commands/session.js +2 -2
  39. package/dist/cli/commands/sessions.js +42 -12
  40. package/dist/cli/commands/setup.js +136 -158
  41. package/dist/cli/commands/status.js +172 -41
  42. package/dist/cli/commands/statusline.js +305 -113
  43. package/dist/cli/commands/ui.js +64 -66
  44. package/dist/cli/commands/undo.js +161 -18
  45. package/dist/cli/commands/uninstall.js +462 -0
  46. package/dist/cli/commands/upgrade.js +75 -19
  47. package/dist/cli/commands/usage.js +117 -44
  48. package/dist/cli/commands/version.js +7 -5
  49. package/dist/cli/commands/which.js +7 -24
  50. package/dist/cli/compile-cache.js +32 -0
  51. package/dist/cli/group.js +10 -10
  52. package/dist/cli/help.js +57 -0
  53. package/dist/cli/highlight.js +236 -0
  54. package/dist/cli/io.js +170 -1
  55. package/dist/cli/launch.js +21 -37
  56. package/dist/cli/launchers.js +145 -94
  57. package/dist/cli/main.js +163 -27
  58. package/dist/cli/picker.js +447 -0
  59. package/dist/cli/registry.js +42 -5
  60. package/dist/cli/security.js +539 -0
  61. package/dist/cli/style.js +281 -0
  62. package/dist/core/config.js +145 -23
  63. package/dist/core/exhausted.js +6 -8
  64. package/dist/core/fsutil.js +47 -0
  65. package/dist/core/journal.js +281 -11
  66. package/dist/core/manifest.js +126 -6
  67. package/dist/core/paths.js +114 -7
  68. package/dist/core/profiles.js +139 -9
  69. package/dist/core/resolve.js +129 -23
  70. package/dist/core/secrets.js +215 -20
  71. package/dist/core/sessions.js +13 -20
  72. package/dist/core/update.js +18 -8
  73. package/dist/demo/server.js +34 -0
  74. package/dist/mcpd/cache.js +18 -4
  75. package/dist/mcpd/calllog.js +253 -0
  76. package/dist/mcpd/client-names.js +51 -0
  77. package/dist/mcpd/connectors.js +148 -17
  78. package/dist/mcpd/daemon.js +452 -116
  79. package/dist/mcpd/folder-sets.js +39 -0
  80. package/dist/mcpd/gateway.js +441 -47
  81. package/dist/mcpd/health.js +269 -0
  82. package/dist/mcpd/importer.js +356 -36
  83. package/dist/mcpd/instances.js +425 -65
  84. package/dist/mcpd/jsonrpc.js +8 -0
  85. package/dist/mcpd/launchd.js +65 -48
  86. package/dist/mcpd/modern.js +648 -0
  87. package/dist/mcpd/oauth.js +791 -0
  88. package/dist/mcpd/peerpid.js +122 -6
  89. package/dist/mcpd/pressure.js +85 -0
  90. package/dist/mcpd/rss.js +151 -0
  91. package/dist/mcpd/service.js +167 -0
  92. package/dist/mcpd/state.js +183 -0
  93. package/dist/mcpd/sync.js +55 -80
  94. package/dist/mcpd/systemd.js +80 -0
  95. package/dist/mcpd/tokens.js +89 -0
  96. package/dist/mcpd/upstream.js +154 -44
  97. package/dist/statusline/cost.js +154 -44
  98. package/dist/statusline/input.js +66 -0
  99. package/dist/statusline/render.js +9 -3
  100. package/dist/ui/fonts.js +8 -3
  101. package/dist/ui/settings.js +27 -15
  102. package/npm-shrinkwrap.json +1093 -0
  103. package/package.json +6 -6
  104. package/dist/cli/commands/available.js +0 -18
@@ -2,6 +2,8 @@ export const isRequest = (m) => typeof m.method === "string" && m.id !== undefin
2
2
  export const isNotification = (m) => typeof m.method === "string" && (m.id === undefined || m.id === null);
3
3
  export const isResponse = (m) => m.method === undefined && m.id !== undefined && ("result" in m || "error" in m);
4
4
  export const ErrorCode = {
5
+ ParseError: -32700,
6
+ InvalidRequest: -32600,
5
7
  MethodNotFound: -32601,
6
8
  InvalidParams: -32602,
7
9
  Internal: -32603,
@@ -9,6 +11,12 @@ export const ErrorCode = {
9
11
  Unavailable: -32002,
10
12
  /** Server-defined: an exclusive server is held by another session. */
11
13
  Busy: -32003,
14
+ /** Server-defined: a server-to-client request could not be tied to one client session. */
15
+ Ambiguous: -32004,
16
+ /** Same code the SDK uses for a request that ran out of time. */
17
+ RequestTimeout: -32001,
18
+ /** The request was cancelled (by the client, or because the client went away). */
19
+ RequestCancelled: -32800,
12
20
  };
13
21
  export function toResponse(id, outcome) {
14
22
  return "error" in outcome ? { jsonrpc: "2.0", id, error: outcome.error } : { jsonrpc: "2.0", id, result: outcome.result };
@@ -1,9 +1,6 @@
1
- import { execFile } from "node:child_process";
2
- import { mkdirSync, writeFileSync } from "node:fs";
3
1
  import { join } from "node:path";
4
- import { promisify } from "node:util";
5
- import { paths } from "../core/paths.js";
6
- const run = promisify(execFile);
2
+ import { ensurePrivateDir, paths } from "../core/paths.js";
3
+ import { ServiceError, runTool, serviceArgs, serviceEnv } from "./service.js";
7
4
  export const LABEL = "dev.turno.mcpd";
8
5
  export function plistPath(env = process.env) {
9
6
  return join(paths(env).home, "Library", "LaunchAgents", `${LABEL}.plist`);
@@ -11,19 +8,22 @@ export function plistPath(env = process.env) {
11
8
  function xml(s) {
12
9
  return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
13
10
  }
14
- /** LaunchAgent that keeps `turno mcpd run` alive, with the caller's PATH (launchd's is minimal). */
15
- export function plist(opts) {
16
- const p = paths(opts.env);
17
- const vars = {
18
- PATH: opts.env.PATH ?? "/usr/bin:/bin:/usr/sbin:/sbin",
19
- HOME: p.home,
20
- };
21
- for (const k of ["XDG_CONFIG_HOME", "XDG_STATE_HOME", "XDG_DATA_HOME", "LANG"])
22
- if (opts.env[k])
23
- vars[k] = opts.env[k];
24
- const envXml = Object.entries(vars)
11
+ function unxml(s) {
12
+ return s.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
13
+ }
14
+ /**
15
+ * LaunchAgent that keeps `turno mcp daemon run` alive. `Interactive` because mcpd answers
16
+ * calls the user is waiting for and starts browsers (a `Background` job gets throttled).
17
+ * KeepAlive only restarts it after a failure: a clean exit (another mcpd already serves) stays down.
18
+ */
19
+ export function plist(spec) {
20
+ const p = paths(spec.env);
21
+ const envXml = Object.entries(serviceEnv(spec, "launchd"))
25
22
  .map(([k, v]) => ` <key>${xml(k)}</key>\n <string>${xml(v)}</string>`)
26
23
  .join("\n");
24
+ const args = serviceArgs(spec)
25
+ .map((a) => ` <string>${xml(a)}</string>`)
26
+ .join("\n");
27
27
  return `<?xml version="1.0" encoding="UTF-8"?>
28
28
  <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
29
29
  <plist version="1.0">
@@ -32,10 +32,7 @@ export function plist(opts) {
32
32
  <string>${LABEL}</string>
33
33
  <key>ProgramArguments</key>
34
34
  <array>
35
- <string>${xml(opts.node)}</string>
36
- <string>${xml(opts.script)}</string>
37
- <string>mcpd</string>
38
- <string>run</string>
35
+ ${args}
39
36
  </array>
40
37
  <key>EnvironmentVariables</key>
41
38
  <dict>
@@ -44,9 +41,14 @@ ${envXml}
44
41
  <key>RunAtLoad</key>
45
42
  <true/>
46
43
  <key>KeepAlive</key>
47
- <true/>
44
+ <dict>
45
+ <key>SuccessfulExit</key>
46
+ <false/>
47
+ </dict>
48
+ <key>ThrottleInterval</key>
49
+ <integer>10</integer>
48
50
  <key>ProcessType</key>
49
- <string>Background</string>
51
+ <string>Interactive</string>
50
52
  <key>StandardOutPath</key>
51
53
  <string>${xml(join(p.logsDir, "mcpd.stdout.log"))}</string>
52
54
  <key>StandardErrorPath</key>
@@ -55,32 +57,47 @@ ${envXml}
55
57
  </plist>
56
58
  `;
57
59
  }
58
- function domain() {
59
- return `gui/${process.getuid?.() ?? 501}`;
60
- }
61
- export async function isLoaded() {
62
- try {
63
- await run("launchctl", ["print", `${domain()}/${LABEL}`], { timeout: 5000 });
64
- return true;
65
- }
66
- catch {
67
- return false;
68
- }
69
- }
70
- export async function install(opts) {
71
- const file = plistPath(opts.env);
72
- mkdirSync(join(paths(opts.env).home, "Library", "LaunchAgents"), { recursive: true });
73
- mkdirSync(paths(opts.env).logsDir, { recursive: true });
74
- writeFileSync(file, plist(opts));
75
- if (await isLoaded())
76
- await run("launchctl", ["bootout", `${domain()}/${LABEL}`], { timeout: 10_000 }).catch(() => { });
77
- await run("launchctl", ["bootstrap", domain(), file], { timeout: 10_000 });
78
- return file;
60
+ /** ProgramArguments of a plist written by `plist()` (or an earlier turno). */
61
+ export function plistProgram(text) {
62
+ const m = /<key>ProgramArguments<\/key>\s*<array>([\s\S]*?)<\/array>/.exec(text);
63
+ if (!m)
64
+ return [];
65
+ return [...m[1].matchAll(/<string>([\s\S]*?)<\/string>/g)].map((x) => unxml(x[1]));
79
66
  }
80
- export async function uninstall() {
81
- await run("launchctl", ["bootout", `${domain()}/${LABEL}`], { timeout: 10_000 });
82
- }
83
- export async function restart() {
84
- await run("launchctl", ["kickstart", "-k", `${domain()}/${LABEL}`], { timeout: 10_000 });
67
+ function domain() {
68
+ const uid = process.getuid?.();
69
+ if (uid === undefined)
70
+ throw new ServiceError("cannot tell the user id for launchctl");
71
+ return `gui/${uid}`;
85
72
  }
73
+ export const launchd = {
74
+ kind: "launchd",
75
+ noun: "LaunchAgent",
76
+ file: plistPath,
77
+ render: plist,
78
+ programOf: plistProgram,
79
+ async isLoaded(env) {
80
+ try {
81
+ await runTool("launchctl", ["print", `${domain()}/${LABEL}`], env, 5000);
82
+ return true;
83
+ }
84
+ catch (err) {
85
+ if (err instanceof ServiceError && /not found on PATH/.test(err.message))
86
+ throw err;
87
+ return false;
88
+ }
89
+ },
90
+ async load(env) {
91
+ ensurePrivateDir(paths(env).logsDir, env);
92
+ if (await launchd.isLoaded(env))
93
+ await runTool("launchctl", ["bootout", `${domain()}/${LABEL}`], env).catch(() => { });
94
+ await runTool("launchctl", ["bootstrap", domain(), plistPath(env)], env);
95
+ },
96
+ async unload(env) {
97
+ await runTool("launchctl", ["bootout", `${domain()}/${LABEL}`], env);
98
+ },
99
+ async restart(env) {
100
+ await runTool("launchctl", ["kickstart", "-k", `${domain()}/${LABEL}`], env);
101
+ },
102
+ };
86
103
  //# sourceMappingURL=launchd.js.map