withruntime 1.1.0 → 1.1.2

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 CHANGED
@@ -4,6 +4,14 @@ Every release of the Runtime Cloud SDKs: npm `withruntime`, PyPI `withruntime`,
4
4
  module `withruntime.com/go`. Versions follow [Semantic Versioning](https://semver.org). Each release is generated from
5
5
  the API's OpenAPI description, `https://api.withruntime.com/v2/openapi.json`.
6
6
 
7
+ ## 1.1.1 (24 November 2026), npm
8
+
9
+ ### Fixed
10
+
11
+ - `npx withruntime <command>` runs the command. In 1.0.0 and 1.1.0 it exited at once with no output, because the CLI
12
+ ran only when started under the name `runtime`; `npx withruntime login`, `npx withruntime mcp` and every other
13
+ command did nothing. The `runtime` command was not affected.
14
+
7
15
  ## 1.1.0 (24 November 2026), and Go v2.0.0
8
16
 
9
17
  npm, PyPI and RubyGems `withruntime` 1.1.0. The Go module moves to `withruntime.com/go/v2` at v2.0.0: import
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/v2/bin.js ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env node
2
+ /* The `runtime` and `withruntime` commands. This file only runs the CLI: npx starts it by a link named for the
3
+ command (node_modules/.bin/withruntime), so cli.ts never guesses from its own name whether it was started
4
+ (1.0.0's guard matched /runtime and /cli.js, and `npx withruntime ...` did nothing at all). */
5
+ import { main } from "./cli.js";
6
+ // exitCode, never exit(): a pipe's stdout on macOS is written after the call returns, and exit() cut --help at 64 KiB.
7
+ // A reader that closed its end (`runtime ... | head`) has all it wanted.
8
+ process.stdout.on("error", (e) => {
9
+ if (e.code !== "EPIPE")
10
+ throw e;
11
+ process.exit(process.exitCode ?? 0);
12
+ });
13
+ void main(process.argv.slice(2)).then((code) => {
14
+ process.exitCode = code;
15
+ });
package/dist/v2/cli.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  import { type Command, type Flag } from "./table.js";
3
2
  /** One flag's text as its field's type in the API's description, refused here, before anything is sent, when it is
4
3
  * not one. 18 Nov 2026: a number went as its text (`--memory-gb 4` as "4"), and the API refused it. */
package/dist/v2/cli.js CHANGED
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env node
2
1
  /* `runtime`: every verb and shortcut the API serves, as commands read from
3
2
  its own description (./table.ts). Nothing here names a product: parsing
4
3
  argv into a verb's arguments, printing its answer, and the primitives a
@@ -387,17 +386,3 @@ export async function main(argv) {
387
386
  return 1;
388
387
  }
389
388
  }
390
- if (import.meta.url === `file://${process.argv[1]}` ||
391
- process.argv[1]?.endsWith("/runtime") ||
392
- process.argv[1]?.endsWith("/cli.js")) {
393
- // exitCode, never exit(): a pipe's stdout on macOS is written after the call returns, and exit() cut --help at 64 KiB.
394
- // A reader that closed its end (`runtime ... | head`) has all it wanted.
395
- process.stdout.on("error", (e) => {
396
- if (e.code !== "EPIPE")
397
- throw e;
398
- process.exit(process.exitCode ?? 0);
399
- });
400
- void main(process.argv.slice(2)).then((code) => {
401
- process.exitCode = code;
402
- });
403
- }
@@ -25,6 +25,8 @@ export type LoginOptions = {
25
25
  sleep?: (ms: number) => Promise<void>;
26
26
  now?: () => number;
27
27
  say?: (line: string) => void;
28
+ /** Told the link and code once the API has given them, before the wait for the approval. */
29
+ started?: (link: string, userCode: string) => void;
28
30
  };
29
31
  export declare function login(baseUrl: string, o?: LoginOptions): Promise<number>;
30
32
  /** Forgets the key a login saved for `baseUrl`. The key itself works until
package/dist/v2/login.js CHANGED
@@ -141,6 +141,7 @@ export async function login(baseUrl, o = {}) {
141
141
  const link = started.verification_uri_complete ?? started.verification_uri;
142
142
  say(`Approve this computer at ${link}`);
143
143
  say(`and check that the page shows the code ${started.user_code}.`);
144
+ o.started?.(link, started.user_code);
144
145
  const page = sitePage(link, baseUrl);
145
146
  if (page)
146
147
  (o.open ?? openBrowser)(page);
package/dist/v2/mcp.d.ts CHANGED
@@ -1 +1,4 @@
1
+ import { type LoginOptions } from "./login.js";
2
+ /** The bridge: `handle` takes one line a client sent, and each answer goes to `write`. */
3
+ export declare function bridge(baseUrl: string, write: (m: unknown) => void, fetcher?: typeof fetch, connect?: LoginOptions): (line: string) => Promise<void>;
1
4
  export declare function serveMcp(baseUrl: string, fetcher?: typeof fetch): Promise<number>;
package/dist/v2/mcp.js CHANGED
@@ -3,60 +3,164 @@
3
3
  to the API's own MCP endpoint (POST /mcp, which serves every verb and
4
4
  shortcut the spec names) under RUNTIME_API_KEY, and its answer written
5
5
  back as one line: the tools are always the server's, never this
6
- package's, so a verb is a tool the moment it is live. */
6
+ package's, so a verb is a tool the moment it is live.
7
+
8
+ With no key (none set, none saved by `runtime login`), the bridge answers
9
+ itself with one tool, runtime_connect, which signs this computer in as
10
+ `runtime login` does, from inside the agent; once approved, the server's
11
+ tools are listed. 24 Nov 2026: without a key every message was refused,
12
+ `initialize` too, so a client added before `npx withruntime login` showed
13
+ the server as failed and nothing said what to do. */
7
14
  import { createInterface } from "node:readline";
8
- export async function serveMcp(baseUrl, fetcher = fetch) {
9
- const key = process.env["RUNTIME_API_KEY"];
10
- const endpoint = `${baseUrl}/mcp`;
11
- const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
12
- const write = (m) => process.stdout.write(`${JSON.stringify(m)}\n`);
13
- for await (const line of lines) {
15
+ import { login, savedKey } from "./login.js";
16
+ const CONNECT = "runtime_connect";
17
+ const NOT_CONNECTED = "Runtime is not connected on this computer. Call runtime_connect to sign in: it returns a link and a code for the person you work for to approve in a browser, and Runtime's tools are listed once they have. With RUNTIME_API_KEY set, or after `npx withruntime login`, the server starts connected.";
18
+ const connectTool = {
19
+ name: CONNECT,
20
+ title: "Connect this computer to Runtime",
21
+ description: "Signs this computer in to Runtime with a browser approval, with no key to copy. The first call returns a link and a code: show both to the person you work for and ask them to approve. Call it again after they have; it waits up to 45 seconds for the approval, then Runtime's tools are listed.",
22
+ inputSchema: { type: "object", properties: {}, additionalProperties: false },
23
+ };
24
+ /** How long a call of runtime_connect after the first waits for the approval. */
25
+ const WAIT_MS = 45_000;
26
+ /** The bridge: `handle` takes one line a client sent, and each answer goes to `write`. */
27
+ export function bridge(baseUrl, write, fetcher = fetch, connect = {}) {
28
+ const env = connect.env ?? process.env;
29
+ let key = env["RUNTIME_API_KEY"] || undefined;
30
+ let pending;
31
+ /** Starts a sign-in, resolved with its link and code once the API gave them; its `done` is the error, or "". */
32
+ const begin = () => new Promise((started, failed) => {
33
+ const said = [];
34
+ const done = login(baseUrl, {
35
+ fetch: fetcher,
36
+ ...connect,
37
+ env,
38
+ tty: () => false,
39
+ say: (l) => void (said.push(l), process.stderr.write(`${l}\n`)),
40
+ started: (link, code) => started({ link, code, done }),
41
+ }).then((code) => {
42
+ const saved = code === 0 ? savedKey(baseUrl, env) : undefined;
43
+ if (saved) {
44
+ key = saved;
45
+ write({ jsonrpc: "2.0", method: "notifications/tools/list_changed" });
46
+ return "";
47
+ }
48
+ pending = undefined;
49
+ const why = said.at(-1)?.replace(/^runtime login: /, "") ?? "the sign-in ended.";
50
+ failed(new Error(why));
51
+ return why;
52
+ });
53
+ });
54
+ const text = (t, isError = false) => ({ content: [{ type: "text", text: t }], ...(isError ? { isError } : {}) });
55
+ const ask = (p) => `Open ${p.link} and check that the page shows the code ${p.code}, then choose Connect. Show the link and code to the person you work for. When they have approved, call runtime_connect again.`;
56
+ async function connectCall() {
57
+ if (key)
58
+ return text("Connected. Runtime's tools are listed.");
59
+ if (!pending) {
60
+ try {
61
+ pending = await begin();
62
+ }
63
+ catch (e) {
64
+ return text(`The sign-in could not start: ${e.message}`, true);
65
+ }
66
+ return text(ask(pending));
67
+ }
68
+ const p = pending;
69
+ const why = await Promise.race([p.done, new Promise((r) => setTimeout(() => r(null), WAIT_MS).unref())]);
70
+ if (why === "")
71
+ return text("Connected. Runtime's tools are listed.");
72
+ if (why === null)
73
+ return text(`Not approved yet. ${ask(p)}`);
74
+ return text(`The sign-in ended: ${why} Call runtime_connect for a new link.`, true);
75
+ }
76
+ /** The answer to `m` while no key is held. */
77
+ async function unconnected(m) {
78
+ switch (m.method) {
79
+ case "initialize":
80
+ return {
81
+ protocolVersion: typeof m.params?.protocolVersion === "string" ? m.params.protocolVersion : "2025-06-18",
82
+ capabilities: { tools: { listChanged: true } },
83
+ serverInfo: { name: "runtime-cloud", version: "not connected" },
84
+ instructions: NOT_CONNECTED,
85
+ };
86
+ case "ping":
87
+ return {};
88
+ case "tools/list":
89
+ return { tools: [connectTool] };
90
+ case "tools/call":
91
+ return m.params?.name === CONNECT ? connectCall() : text(NOT_CONNECTED, true);
92
+ default:
93
+ throw new Error(NOT_CONNECTED);
94
+ }
95
+ }
96
+ return async (line) => {
14
97
  if (!line.trim())
15
- continue;
16
- let id = null;
98
+ return;
99
+ let m;
17
100
  try {
18
- id = JSON.parse(line).id ?? null;
101
+ m = JSON.parse(line);
19
102
  }
20
103
  catch {
21
104
  write({ jsonrpc: "2.0", id: null, error: { code: -32700, message: "The line is not JSON." } });
22
- continue;
105
+ return;
106
+ }
107
+ const id = m.id ?? null;
108
+ if (!key || (m.method === "tools/call" && m.params?.name === CONNECT)) {
109
+ if (m.id === undefined)
110
+ return; // a notification
111
+ try {
112
+ write({ jsonrpc: "2.0", id, result: await (key ? connectCall() : unconnected(m)) });
113
+ }
114
+ catch (e) {
115
+ write({ jsonrpc: "2.0", id, error: { code: -32001, message: e.message } });
116
+ }
117
+ return;
23
118
  }
24
119
  try {
25
- const res = await fetcher(endpoint, {
120
+ const res = await fetcher(`${baseUrl}/mcp`, {
26
121
  method: "POST",
27
122
  headers: {
28
123
  "content-type": "application/json",
29
124
  accept: "application/json, text/event-stream",
30
- ...(key ? { authorization: `Bearer ${key}` } : {}),
125
+ authorization: `Bearer ${key}`,
31
126
  },
32
127
  body: line,
33
128
  });
34
129
  if (res.status === 202)
35
- continue;
36
- const text = await res.text();
37
- let body;
130
+ return;
131
+ const body = await res.text();
132
+ let parsed;
38
133
  try {
39
- body = JSON.parse(text);
134
+ parsed = JSON.parse(body);
40
135
  }
41
136
  catch {
42
- write({ jsonrpc: "2.0", id, error: { code: -32603, message: `The API answered ${res.status}: ${text.slice(0, 200)}` } });
43
- continue;
137
+ write({ jsonrpc: "2.0", id, error: { code: -32603, message: `The API answered ${res.status}: ${body.slice(0, 200)}` } });
138
+ return;
44
139
  }
45
140
  if (res.ok) {
46
- write(body);
47
- continue;
48
- }
49
- // A refusal of the call itself (no key, a bad key, a limit) is the API's error body, not a JSON-RPC answer: the
50
- // client is told it as this request's error, or it waits for an answer that never comes.
51
- const api = body.error;
52
- const message = !key && res.status === 401
53
- ? "No API key. Set RUNTIME_API_KEY, or run `npx withruntime login` once on this machine."
54
- : `${api?.code ?? res.status}: ${api?.message ?? text.slice(0, 200)}${api?.hint ? ` ${api.hint}` : ""}`;
141
+ write(parsed);
142
+ return;
143
+ }
144
+ // A refusal of the call itself (a bad key, a limit) is the API's error body, not a JSON-RPC answer: the client
145
+ // is told it as this request's error, or it waits for an answer that never comes.
146
+ const api = parsed.error;
147
+ const message = `${api?.code ?? res.status}: ${api?.message ?? body.slice(0, 200)}${api?.hint ? ` ${api.hint}` : ""}`;
55
148
  write({ jsonrpc: "2.0", id, error: { code: -32001, message, data: { status: res.status, ...api } } });
56
149
  }
57
150
  catch (e) {
58
151
  write({ jsonrpc: "2.0", id, error: { code: -32603, message: `The API did not answer: ${e.message}` } });
59
152
  }
153
+ };
154
+ }
155
+ export async function serveMcp(baseUrl, fetcher = fetch) {
156
+ const handle = bridge(baseUrl, (m) => process.stdout.write(`${JSON.stringify(m)}\n`), fetcher);
157
+ const lines = createInterface({ input: process.stdin, crlfDelay: Infinity });
158
+ // Each line at once: a runtime_connect that waits for an approval holds up no other call.
159
+ const running = new Set();
160
+ for await (const line of lines) {
161
+ const p = handle(line).finally(() => running.delete(p));
162
+ running.add(p);
60
163
  }
164
+ await Promise.all(running);
61
165
  return 0;
62
166
  }