@botiverse/oar 0.100.0 → 0.101.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 (75) hide show
  1. package/README.md +2 -2
  2. package/dist/contracts/session-options.d.ts +1 -1
  3. package/dist/runtimes/codex/installation-candidates.d.ts +31 -0
  4. package/dist/runtimes/codex/installation-candidates.d.ts.map +1 -0
  5. package/dist/runtimes/codex/installation-candidates.js +92 -0
  6. package/dist/runtimes/codex/installation-candidates.js.map +1 -0
  7. package/dist/runtimes/codex/installation.d.ts +1 -30
  8. package/dist/runtimes/codex/installation.d.ts.map +1 -1
  9. package/dist/runtimes/codex/installation.js +2 -82
  10. package/dist/runtimes/codex/installation.js.map +1 -1
  11. package/dist/runtimes/cursor/access.d.ts +68 -0
  12. package/dist/runtimes/cursor/access.d.ts.map +1 -0
  13. package/dist/runtimes/cursor/access.js +77 -0
  14. package/dist/runtimes/cursor/access.js.map +1 -0
  15. package/dist/runtimes/cursor/auth-status.d.ts +4 -3
  16. package/dist/runtimes/cursor/auth-status.d.ts.map +1 -1
  17. package/dist/runtimes/cursor/auth-status.js +20 -18
  18. package/dist/runtimes/cursor/auth-status.js.map +1 -1
  19. package/dist/runtimes/cursor/index.d.ts +50 -10
  20. package/dist/runtimes/cursor/index.d.ts.map +1 -1
  21. package/dist/runtimes/cursor/index.js +40 -21
  22. package/dist/runtimes/cursor/index.js.map +1 -1
  23. package/dist/runtimes/cursor/installation.d.ts +1 -1
  24. package/dist/runtimes/cursor/installation.d.ts.map +1 -1
  25. package/dist/runtimes/cursor/installation.js +5 -2
  26. package/dist/runtimes/cursor/installation.js.map +1 -1
  27. package/dist/runtimes/cursor/list-models.d.ts +4 -2
  28. package/dist/runtimes/cursor/list-models.d.ts.map +1 -1
  29. package/dist/runtimes/cursor/list-models.js +31 -14
  30. package/dist/runtimes/cursor/list-models.js.map +1 -1
  31. package/dist/runtimes/cursor/login.d.ts +8 -3
  32. package/dist/runtimes/cursor/login.d.ts.map +1 -1
  33. package/dist/runtimes/cursor/login.js +29 -22
  34. package/dist/runtimes/cursor/login.js.map +1 -1
  35. package/dist/runtimes/cursor/logout.d.ts +3 -3
  36. package/dist/runtimes/cursor/logout.d.ts.map +1 -1
  37. package/dist/runtimes/cursor/logout.js +19 -18
  38. package/dist/runtimes/cursor/logout.js.map +1 -1
  39. package/dist/runtimes/cursor/model.d.ts +5 -0
  40. package/dist/runtimes/cursor/model.d.ts.map +1 -1
  41. package/dist/runtimes/cursor/model.js +10 -1
  42. package/dist/runtimes/cursor/model.js.map +1 -1
  43. package/dist/runtimes/cursor/sdk.d.ts +0 -4
  44. package/dist/runtimes/cursor/sdk.d.ts.map +1 -1
  45. package/dist/runtimes/cursor/sdk.js +5 -11
  46. package/dist/runtimes/cursor/sdk.js.map +1 -1
  47. package/dist/runtimes/cursor/session-process.d.ts +31 -0
  48. package/dist/runtimes/cursor/session-process.d.ts.map +1 -0
  49. package/dist/runtimes/cursor/session-process.js +80 -0
  50. package/dist/runtimes/cursor/session-process.js.map +1 -0
  51. package/dist/runtimes/cursor/session.d.ts +2 -2
  52. package/dist/runtimes/cursor/session.d.ts.map +1 -1
  53. package/dist/runtimes/cursor/session.js +10 -10
  54. package/dist/runtimes/cursor/session.js.map +1 -1
  55. package/dist/runtimes/cursor/subprocess/channel.d.ts +37 -0
  56. package/dist/runtimes/cursor/subprocess/channel.d.ts.map +1 -0
  57. package/dist/runtimes/cursor/subprocess/channel.js +170 -0
  58. package/dist/runtimes/cursor/subprocess/channel.js.map +1 -0
  59. package/dist/runtimes/cursor/subprocess/child-script.d.ts +12 -0
  60. package/dist/runtimes/cursor/subprocess/child-script.d.ts.map +1 -0
  61. package/dist/runtimes/cursor/subprocess/child-script.js +257 -0
  62. package/dist/runtimes/cursor/subprocess/child-script.js.map +1 -0
  63. package/dist/runtimes/cursor/subprocess/proxy.d.ts +11 -0
  64. package/dist/runtimes/cursor/subprocess/proxy.d.ts.map +1 -0
  65. package/dist/runtimes/cursor/subprocess/proxy.js +242 -0
  66. package/dist/runtimes/cursor/subprocess/proxy.js.map +1 -0
  67. package/dist/shared/executable/environment-marker.d.ts +21 -0
  68. package/dist/shared/executable/environment-marker.d.ts.map +1 -0
  69. package/dist/shared/executable/environment-marker.js +137 -0
  70. package/dist/shared/executable/environment-marker.js.map +1 -0
  71. package/dist/shared/executable/node-script.d.ts +53 -0
  72. package/dist/shared/executable/node-script.d.ts.map +1 -0
  73. package/dist/shared/executable/node-script.js +131 -0
  74. package/dist/shared/executable/node-script.js.map +1 -0
  75. package/package.json +5 -1
@@ -0,0 +1,257 @@
1
+ import path from "node:path";
2
+ import { environmentValue, sessionEnvironment } from "../../../shared/environment.js";
3
+ import { newEnvironmentMarker } from "../../../shared/executable/environment-marker.js";
4
+ import { killGraceMs } from "../../../shared/executable/index.js";
5
+ /*
6
+ * The script a cursor child runs: `process.execPath -e SCRIPT SPEC`. It is
7
+ * self-contained (Node built-ins only, nothing from OAR), because hosts bundle
8
+ * OAR and a separate file next to OAR's code may not exist; it is kept small
9
+ * for the Windows command line limit. SPEC is `[sdkModule, graceMs,
10
+ * electronRunAsNode, taskkill, marker]`.
11
+ *
12
+ * Before the SDK loads, the child puts back the environment's own
13
+ * `ELECTRON_RUN_AS_NODE` (the host set it to 1 only so an Electron
14
+ * `process.execPath` runs the script as Node), and sets the SDK's native
15
+ * companion paths the way `cursorNativeEnvironment()` resolves them, from
16
+ * `sdkModule`, unless the environment already has them.
17
+ *
18
+ * Protocol (Node IPC, plain data only). Host to child: `{ id, m, a }`, a
19
+ * call of method `m` with arguments `a`. Child to host: `{ t: "ready" }`
20
+ * once the SDK loaded (or `e`, its error), with what the SDK has in `v`;
21
+ * `{ t: "reply", id, v | e }` answering a call; `{ t: "event", id, v }`
22
+ * during a call: a send's `onDelta` updates, a stream's messages, a
23
+ * login's URL and save request. Values the SDK returns are copied through
24
+ * JSON; errors cross as their name, message and scalar fields.
25
+ *
26
+ * The login never sends its credentials: the SDK's `store.save` asks the
27
+ * host (`save`), the host answers with `commit` (save to the SDK's own
28
+ * `FileCredentialStore` in this process), then `saved`, or `refused` with
29
+ * the reason, and the login's own reply carries no value.
30
+ *
31
+ * Closing an agent awaits its `Symbol.asyncDispose` when it has one (SDK
32
+ * 1.3.1: `close()` only starts its async close work). Shutting down (the
33
+ * host's `shutdown` call, a SIGTERM, or the IPC channel disconnecting
34
+ * because the host ended or died, SIGKILL included) closes every open agent
35
+ * and waits for the closes for up to `graceMs`, then exits. On exit, also
36
+ * an exit after an uncaught exception, the child ends the descendants it
37
+ * can find by parent pid (POSIX: `/proc/<pid>/stat` on Linux, `ps -A -o
38
+ * pid=,ppid=` elsewhere), so tools that lead process groups of their own
39
+ * are reached too, plus the ones seen when the shutdown began; Windows:
40
+ * `taskkill /T /F` on itself, which walks by parent, except after a
41
+ * shutdown the host asked for (the host ends the tree it captured before,
42
+ * and the exit code stays 0). An uncaught exception is written to stderr
43
+ * synchronously first, so its text reaches the host. On Linux it also
44
+ * SIGKILLs every process of this user whose environment holds `marker`
45
+ * (environment-marker.ts), which reaches what it started and was
46
+ * reparented away from it (a shell's background job after the shell
47
+ * exited), unless that process cleared the variable; it scans again until
48
+ * a pass finds nothing, at most five times. After a disconnect, or once its
49
+ * parent pid changed (checked every second, for a host gone without the
50
+ * disconnect being seen), with no host left to do it, it also SIGKILLs its
51
+ * own process group. A child blocked in synchronous code runs neither
52
+ * check.
53
+ * Not reached: on macOS and Windows, a process reparented away from the
54
+ * child before its exit (no marker scan there); anywhere, a process that
55
+ * cleared the marker and left the child's tree or group.
56
+ */
57
+ const SCRIPT = String.raw `
58
+ const [sdkModule, graceMs, electron, taskkill, marker] = JSON.parse(process.argv[1]);
59
+ const path = require("node:path");
60
+ const fs = require("node:fs");
61
+ const { execFileSync } = require("node:child_process");
62
+ const windows = process.platform === "win32";
63
+ let stopping = false;
64
+ let orphaned = false;
65
+ let seen = new Map();
66
+ const table = () => {
67
+ if (process.platform === "linux") {
68
+ const rows = [];
69
+ for (const name of fs.readdirSync("/proc")) {
70
+ if (!/^\d+$/.test(name)) { continue; }
71
+ try {
72
+ const stat = fs.readFileSync("/proc/" + name + "/stat", "utf8");
73
+ const fields = stat.slice(stat.lastIndexOf(")") + 2).split(" ");
74
+ rows.push([Number(name), Number(fields[1]), fields[19]]);
75
+ } catch {}
76
+ }
77
+ return rows;
78
+ }
79
+ return execFileSync("/bin/ps", ["-A", "-o", "pid=,ppid=,lstart="], { encoding: "utf8", timeout: 10000 }).split("\n")
80
+ .map((line) => line.trim().split(/\s+/)).filter((cells) => cells.length > 2).map((cells) => [Number(cells[0]), Number(cells[1]), cells.slice(2).join(" ")]);
81
+ };
82
+ const descendants = (rows) => {
83
+ const below = new Map();
84
+ for (const row of rows) { below.set(row[1], [...(below.get(row[1]) ?? []), row]); }
85
+ const found = new Map();
86
+ const pending = [process.pid];
87
+ while (pending.length > 0) {
88
+ for (const row of below.get(pending.pop()) ?? []) {
89
+ if (!found.has(row[0])) { found.set(row[0], row[2]); pending.push(row[0]); }
90
+ }
91
+ }
92
+ return found;
93
+ };
94
+ const remember = () => { if (!windows) { try { seen = descendants(table()); } catch {} } };
95
+ let asked = false;
96
+ process.on("exit", () => {
97
+ // Windows, last: no process groups, so taskkill /T walks by parent, this process included (exit code 1).
98
+ // Not after a shutdown the host asked for: the host ends the tree it captured, and the exit stays 0.
99
+ if (windows) {
100
+ if (!asked) { try { execFileSync(taskkill, ["/pid", String(process.pid), "/T", "/F"], { stdio: "ignore", windowsHide: true, timeout: 10000 }); } catch {} }
101
+ return;
102
+ }
103
+ try {
104
+ const rows = table();
105
+ const now = new Map(rows.map((row) => [row[0], row[2]]));
106
+ const targets = new Map([...[...seen].filter(([pid, start]) => now.get(pid) === start), ...descendants(rows)]);
107
+ for (const pid of targets.keys()) { try { process.kill(pid, "SIGKILL"); } catch {} }
108
+ } catch {}
109
+ // What kept the marker, also reparented away from this process (Linux reads every environment).
110
+ // Again until a pass finds nothing (at most 5): a marked process may fork between the read and the kill.
111
+ for (let pass = 0; process.platform === "linux" && pass < 5; pass += 1) {
112
+ let found = 0;
113
+ for (const name of fs.readdirSync("/proc")) {
114
+ try {
115
+ if (!/^\d+$/.test(name) || Number(name) === process.pid || fs.statSync("/proc/" + name).uid !== process.getuid()) { continue; }
116
+ if (fs.readFileSync("/proc/" + name + "/environ", "latin1").split("\0").includes(marker)) { process.kill(Number(name), "SIGKILL"); found += 1; }
117
+ } catch {}
118
+ }
119
+ if (found === 0) { break; }
120
+ }
121
+ if (orphaned) { try { process.kill(-process.pid, "SIGKILL"); } catch {} }
122
+ });
123
+ const agents = new Map();
124
+ const closing = new Set();
125
+ const closeAgent = (agent) => {
126
+ const done = (async () => { if (typeof agent[Symbol.asyncDispose] === "function") { await agent[Symbol.asyncDispose](); } else { agent.close(); } })();
127
+ closing.add(done);
128
+ return done;
129
+ };
130
+ const shutdown = async (code) => {
131
+ if (stopping) { return; }
132
+ stopping = true;
133
+ asked = code === 0;
134
+ remember();
135
+ for (const agent of agents.values()) { void closeAgent(agent); }
136
+ agents.clear();
137
+ await Promise.race([Promise.allSettled([...closing]), new Promise((resolve) => { setTimeout(resolve, graceMs); })]);
138
+ process.exit(code);
139
+ };
140
+ process.on("SIGTERM", () => { void shutdown(0); });
141
+ // Written synchronously, so the error reaches the host's stderr tail before the exit hook ends anything.
142
+ process.on("uncaughtException", (error) => {
143
+ try { fs.writeSync(2, (error instanceof Error && error.stack ? error.stack : String(error)) + "\n"); } catch {}
144
+ process.exit(1);
145
+ });
146
+ process.on("disconnect", () => { orphaned = true; void shutdown(1); });
147
+ // A host gone without the disconnect reaching this process. Needs an event loop that still yields. POSIX reparents an
148
+ // orphan, so its ppid changes; Windows keeps the dead parent's pid, so there the parent pid is checked for a live process.
149
+ const parent = process.ppid;
150
+ const parentGone = () => {
151
+ if (process.ppid !== parent) { return true; }
152
+ if (!windows) { return false; }
153
+ try { process.kill(parent, 0); return false; } catch (error) { return error.code === "ESRCH"; }
154
+ };
155
+ setInterval(() => { if (parentGone()) { orphaned = true; void shutdown(1); } }, 1000).unref();
156
+ if (electron === null) { delete process.env.ELECTRON_RUN_AS_NODE; } else { process.env.ELECTRON_RUN_AS_NODE = electron; }
157
+ try {
158
+ const root = path.dirname(require("node:module").createRequire(sdkModule).resolve("@cursor/sdk-" + process.platform + "-" + process.arch + "/package.json"));
159
+ process.env.CURSOR_TREE_SITTER_VENDOR_DIR ??= path.join(root, "vendor");
160
+ process.env.CURSOR_RIPGREP_PATH ??= path.join(root, "bin", windows ? "rg.exe" : "rg");
161
+ } catch {}
162
+ const post = (message) => { if (process.connected) { process.send(message); } };
163
+ const plain = (value) => value === undefined ? undefined : JSON.parse(JSON.stringify(value));
164
+ const fault = (error) => {
165
+ if (!(error instanceof Error)) { return { name: "Error", message: String(error) }; }
166
+ const out = {};
167
+ for (const key of [...Object.keys(error), "code", "status", "operation", "isRetryable"]) {
168
+ if (["string", "number", "boolean"].includes(typeof error[key])) { out[key] = error[key]; }
169
+ }
170
+ return { ...out, name: error.name, message: error.message };
171
+ };
172
+ let sdk;
173
+ let pending;
174
+ let abort;
175
+ const runs = new Map();
176
+ const streams = new Map();
177
+ const opened = async (id, opening) => {
178
+ const agent = await opening;
179
+ agents.set(id, agent);
180
+ return { agentId: agent.agentId, model: agent.model, summarize: typeof agent.summarize === "function" };
181
+ };
182
+ const started = async (id, starting) => {
183
+ const run = await starting;
184
+ runs.set(id, run);
185
+ return { runId: run.id, steer: typeof run.steer === "function" };
186
+ };
187
+ const calls = {
188
+ models: (id, options) => sdk.Cursor.models.list(options),
189
+ listRuns: (id, agentId, options) => sdk.Agent.listRuns(agentId, options),
190
+ create: (id, options) => opened(id, sdk.Agent.create(options)),
191
+ resume: (id, agentId, options) => opened(id, sdk.Agent.resume(agentId, options)),
192
+ send: (id, agent, message, local) => started(id, agents.get(agent).send(message, { onDelta: ({ update }) => post({ t: "event", id, v: plain(update) }), ...(local ? { local } : {}) })),
193
+ summarize: (id, agent) => started(id, agents.get(agent).summarize()),
194
+ close: async (id, key) => { const agent = agents.get(key); agents.delete(key); if (agent !== undefined) { await closeAgent(agent); } },
195
+ shutdown: () => { void shutdown(0); },
196
+ wait: (id, run) => runs.get(run).wait(),
197
+ cancel: (id, run) => runs.get(run).cancel(),
198
+ steer: (id, run, text) => runs.get(run).steer(text),
199
+ stream: async (id, run) => {
200
+ const iterator = runs.get(run).stream()[Symbol.asyncIterator]();
201
+ streams.set(id, iterator);
202
+ try {
203
+ for (;;) {
204
+ const next = await iterator.next();
205
+ if (next.done) { return; }
206
+ post({ t: "event", id, v: plain(next.value) });
207
+ }
208
+ } finally { streams.delete(id); }
209
+ },
210
+ unstream: (id, stream) => { void streams.get(stream)?.return?.(); },
211
+ status: () => sdk.Cursor.auth.status(),
212
+ logout: async () => { await sdk.Cursor.auth.logout(); },
213
+ login: async (id) => {
214
+ abort = new AbortController();
215
+ const store = {
216
+ load: async () => undefined,
217
+ clear: async () => { throw new Error("oar's cursor login never clears the stored login"); },
218
+ save: (credentials) => new Promise((resolve, reject) => { pending = { credentials, resolve, reject }; post({ t: "event", id, v: { save: true } }); }),
219
+ };
220
+ await sdk.Cursor.auth.login({ openBrowser: false, signal: abort.signal, onLoginUrl: (url) => post({ t: "event", id, v: { url } }), store });
221
+ },
222
+ abortLogin: () => { abort?.abort(); },
223
+ commit: async () => { const { credentials } = pending; pending.credentials = undefined; await new sdk.FileCredentialStore().save(credentials); },
224
+ saved: () => { pending.resolve(); },
225
+ refused: (id, message) => { pending.reject(new Error(message)); },
226
+ };
227
+ process.on("message", async ({ id, m, a }) => {
228
+ try { post({ t: "reply", id, v: plain(await calls[m](id, ...a)) }); }
229
+ catch (error) { post({ t: "reply", id, e: fault(error) }); }
230
+ });
231
+ import(sdkModule).then((module) => {
232
+ sdk = module;
233
+ const auth = module.Cursor?.auth;
234
+ post({ t: "ready", v: { auth: auth !== undefined, logout: typeof auth?.logout === "function", store: typeof module.FileCredentialStore === "function" } });
235
+ }, (error) => { post({ t: "ready", e: fault(error) }); });
236
+ `;
237
+ /**
238
+ * Windows: taskkill by absolute path from the host's own `SystemRoot`, since
239
+ * the child's environment may have no PATH (`envBase: "clean"`).
240
+ */
241
+ function taskkillPath() {
242
+ if (process.platform !== "win32") {
243
+ return null;
244
+ }
245
+ return path.win32.join(environmentValue(process.env, "SystemRoot") ?? String.raw `C:\Windows`, "System32", "taskkill.exe");
246
+ }
247
+ /**
248
+ * The launch of one cursor child: the script, its spec, and its environment
249
+ * with `ELECTRON_RUN_AS_NODE=1` and a fresh environment marker
250
+ * (`OAR_CURSOR_CHILD_<id>=1`), which everything the child starts inherits.
251
+ */
252
+ export function cursorChildLaunch(sdkModule, env) {
253
+ const marker = newEnvironmentMarker();
254
+ const spec = [sdkModule, Math.floor(killGraceMs() / 2), environmentValue(env, "ELECTRON_RUN_AS_NODE") ?? null, taskkillPath(), marker.entry];
255
+ return { script: SCRIPT, argument: JSON.stringify(spec), env: sessionEnvironment({ ELECTRON_RUN_AS_NODE: "1", [marker.name]: "1" }, env), marker: marker.entry };
256
+ }
257
+ //# sourceMappingURL=child-script.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"child-script.js","sources":["../../../../src/runtimes/cursor/subprocess/child-script.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AACtF,OAAO,EAAE,oBAAoB,EAAE,MAAM,kDAAkD,CAAC;AACxF,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AAElE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmDG;AACH,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmLxB,CAAC;AAEF;;;GAGG;AACH,SAAS,YAAY;IACnB,IAAI,OAAO,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;QAAC,OAAO,IAAI,CAAC;IAAC,CAAC;IAClD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,GAAG,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,GAAG,CAAA,YAAY,EAAE,UAAU,EAAE,cAAc,CAAC,CAAC;AAC5H,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iBAAiB,CAAC,SAAiB,EAAE,GAAgC;IACnF,MAAM,MAAM,GAAG,oBAAoB,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,GAAG,EAAE,sBAAsB,CAAC,IAAI,IAAI,EAAE,YAAY,EAAE,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7I,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,kBAAkB,CAAC,EAAE,oBAAoB,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,EAAE,CAAC;AACnK,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { CursorSdk } from "../sdk.js";
2
+ import type { CursorChannel } from "./channel.js";
3
+ /**
4
+ * `CursorSdk` over one cursor child. `apiKey` is the `CURSOR_API_KEY` the
5
+ * lease took out of the child's environment: it goes to the SDK as
6
+ * `AgentOptions.apiKey` (create, resume) and `CursorRequestOptions.apiKey`
7
+ * (`Cursor.models.list`), which SDK 1.3.1 uses instead of the variable.
8
+ * Local `Agent.listRuns` reads the local store and takes none.
9
+ */
10
+ export declare function proxySdk(channel: CursorChannel, apiKey?: string): CursorSdk;
11
+ //# sourceMappingURL=proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.d.ts","sources":["../../../../src/runtimes/cursor/subprocess/proxy.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAOV,SAAS,EAIV,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAgLlD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAoC3E"}
@@ -0,0 +1,242 @@
1
+ import { asRecord, asRecordList } from "../../../shared/json.js";
2
+ function isModelSelection(value) {
3
+ return typeof asRecord(value)?.id === "string";
4
+ }
5
+ function isModelList(value) {
6
+ return Array.isArray(value) && asRecordList(value).length === value.length
7
+ && asRecordList(value).every((model) => typeof model.id === "string" && typeof model.displayName === "string");
8
+ }
9
+ function isListRunsPage(value) {
10
+ const page = asRecord(value);
11
+ return page !== null && Array.isArray(page.items) && (page.nextCursor === undefined || typeof page.nextCursor === "string");
12
+ }
13
+ function isAuthStatus(value) {
14
+ const status = asRecord(value)?.status;
15
+ return status === "logged-in" || status === "logged-out";
16
+ }
17
+ function isSteerAck(value) {
18
+ return value === "complete_delivered" || value === "revert_to_followup";
19
+ }
20
+ function unexpected(call) {
21
+ return new Error(`cursor's child process answered ${call} with a shape oar cannot read`);
22
+ }
23
+ /** The run a `send` or `summarize` call made, as the child described it. */
24
+ function proxyRun(channel, key, value) {
25
+ const described = asRecord(value);
26
+ if (typeof described?.runId !== "string") {
27
+ throw unexpected("a send");
28
+ }
29
+ const runId = described.runId;
30
+ const run = {
31
+ id: runId,
32
+ stream: () => proxyStream(channel, key),
33
+ wait: async () => { const result = await channel.call("wait", [key]); return result; },
34
+ cancel: async () => { await channel.call("cancel", [key]); },
35
+ };
36
+ if (described.steer !== true) {
37
+ return run;
38
+ }
39
+ return {
40
+ ...run,
41
+ async steer(text) {
42
+ const ack = await channel.call("steer", [key, text]);
43
+ if (!isSteerAck(ack)) {
44
+ throw unexpected("a steer");
45
+ }
46
+ return ack;
47
+ },
48
+ };
49
+ }
50
+ /** The run's `stream()`: the child reads it and forwards each message; `return()` stops the child's reading. */
51
+ function proxyStream(channel, key) {
52
+ return {
53
+ [Symbol.asyncIterator]: () => {
54
+ const queue = [];
55
+ let wake = Promise.withResolvers();
56
+ const state = { ended: false, error: null };
57
+ const streaming = channel.start("stream", [key], (message) => { queue.push(message); wake.resolve(); });
58
+ void (async () => {
59
+ try {
60
+ await streaming.reply;
61
+ }
62
+ catch (error) {
63
+ state.error = error instanceof Error ? error : new Error(String(error));
64
+ }
65
+ finally {
66
+ state.ended = true;
67
+ wake.resolve();
68
+ }
69
+ })();
70
+ return {
71
+ async next() {
72
+ for (;;) {
73
+ if (queue.length > 0) {
74
+ return { done: false, value: queue.shift() };
75
+ }
76
+ if (state.ended) {
77
+ if (state.error !== null) {
78
+ throw state.error;
79
+ }
80
+ return { done: true, value: undefined };
81
+ }
82
+ await wake.promise;
83
+ wake = Promise.withResolvers();
84
+ }
85
+ },
86
+ async return() {
87
+ queue.length = 0;
88
+ // Not waiting for the child's reading to end: an SDK stream can queue return() behind its pending next() (run.ts).
89
+ if (!state.ended) {
90
+ try {
91
+ await channel.call("unstream", [streaming.id]);
92
+ }
93
+ catch { /* The child may be gone; nothing more arrives then. */ }
94
+ }
95
+ return { done: true, value: undefined };
96
+ },
97
+ };
98
+ },
99
+ };
100
+ }
101
+ async function proxyAgent(channel, opening) {
102
+ const key = opening.id;
103
+ const value = await opening.reply;
104
+ const described = asRecord(value);
105
+ if (typeof described?.agentId !== "string") {
106
+ throw unexpected("an open");
107
+ }
108
+ const model = isModelSelection(described.model) ? described.model : undefined;
109
+ const launch = async (method, args, onDelta) => {
110
+ const started = channel.start(method, [key, ...args], onDelta === undefined ? undefined : (update) => { onDelta({ update }); });
111
+ return proxyRun(channel, started.id, await started.reply);
112
+ };
113
+ const agent = {
114
+ agentId: described.agentId,
115
+ model,
116
+ send: async (message, options) => {
117
+ const run = await launch("send", [message, options.local], options.onDelta);
118
+ return run;
119
+ },
120
+ close() {
121
+ void (async () => {
122
+ try {
123
+ await channel.call("close", [key]);
124
+ }
125
+ catch { /* The child ending closes the agent with it. */ }
126
+ })();
127
+ },
128
+ };
129
+ if (described.summarize !== true) {
130
+ return agent;
131
+ }
132
+ return { ...agent, summarize: async () => { const run = await launch("summarize", []); return run; } };
133
+ }
134
+ /** `Cursor.auth` over the child: the login's save is decided here, and done there. */
135
+ function proxyAuth(channel) {
136
+ const auth = {
137
+ async login(options) {
138
+ const stop = () => {
139
+ void (async () => {
140
+ try {
141
+ await channel.call("abortLogin", []);
142
+ }
143
+ catch { /* The child may be gone. */ }
144
+ })();
145
+ };
146
+ options.signal.addEventListener("abort", stop, { once: true });
147
+ try {
148
+ await channel.call("login", [], (event) => {
149
+ const step = asRecord(event);
150
+ if (typeof step?.url === "string") {
151
+ options.onLoginUrl(step.url);
152
+ }
153
+ if (step?.save === true) {
154
+ void decideSave(channel, options);
155
+ }
156
+ });
157
+ }
158
+ finally {
159
+ options.signal.removeEventListener("abort", stop);
160
+ }
161
+ },
162
+ async status() {
163
+ const status = await channel.call("status", []);
164
+ if (!isAuthStatus(status)) {
165
+ throw unexpected("Cursor.auth.status");
166
+ }
167
+ return status;
168
+ },
169
+ };
170
+ if (!channel.features.logout) {
171
+ return auth;
172
+ }
173
+ return { ...auth, logout: async () => { await channel.call("logout", []); } };
174
+ }
175
+ /**
176
+ * The SDK in the child asked to save its key. The host's login store decides
177
+ * (login.ts): it refuses once OAR ended the login, or passes the save on to
178
+ * `FileCredentialStore.save`, which here tells the child to save to its own
179
+ * store (`commit`). The child is then told how it went.
180
+ */
181
+ async function decideSave(channel, options) {
182
+ try {
183
+ // A placeholder: the credentials stay in the child.
184
+ await options.store.save({});
185
+ await channel.call("saved", []);
186
+ }
187
+ catch (error) {
188
+ try {
189
+ await channel.call("refused", [error instanceof Error ? error.message : String(error)]);
190
+ }
191
+ catch { /* The child is gone. */ }
192
+ }
193
+ }
194
+ /**
195
+ * `CursorSdk` over one cursor child. `apiKey` is the `CURSOR_API_KEY` the
196
+ * lease took out of the child's environment: it goes to the SDK as
197
+ * `AgentOptions.apiKey` (create, resume) and `CursorRequestOptions.apiKey`
198
+ * (`Cursor.models.list`), which SDK 1.3.1 uses instead of the variable.
199
+ * Local `Agent.listRuns` reads the local store and takes none.
200
+ */
201
+ export function proxySdk(channel, apiKey) {
202
+ const keyed = (options) => (apiKey === undefined ? options : { ...options, apiKey });
203
+ const open = async (method, args) => {
204
+ const agent = await proxyAgent(channel, channel.start(method, args));
205
+ return agent;
206
+ };
207
+ const { features } = channel;
208
+ return {
209
+ Agent: {
210
+ create: async (options) => { const agent = await open("create", [keyed(options)]); return agent; },
211
+ resume: async (agentId, options) => { const agent = await open("resume", [agentId, keyed(options)]); return agent; },
212
+ async listRuns(agentId, options) {
213
+ const page = await channel.call("listRuns", [agentId, options]);
214
+ if (!isListRunsPage(page)) {
215
+ throw unexpected("Agent.listRuns");
216
+ }
217
+ return page;
218
+ },
219
+ },
220
+ Cursor: {
221
+ models: {
222
+ async list() {
223
+ const models = await channel.call("models", apiKey === undefined ? [] : [{ apiKey }]);
224
+ if (!isModelList(models)) {
225
+ throw unexpected("Cursor.models.list");
226
+ }
227
+ return models;
228
+ },
229
+ },
230
+ ...(features.auth ? { auth: proxyAuth(channel) } : {}),
231
+ },
232
+ ...(features.store ? {
233
+ FileCredentialStore: class {
234
+ // The argument is the login store's placeholder; the child saves what its SDK gave it.
235
+ async save() {
236
+ await channel.call("commit", []);
237
+ }
238
+ },
239
+ } : {}),
240
+ };
241
+ }
242
+ //# sourceMappingURL=proxy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"proxy.js","sources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YACD,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACvD;QACD,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;YACnB,mBAAmB,EAAE;gBACnB,uFAAuF;gBACvF,KAAK,CAAC,IAAI;oBACR,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;gBACnC,CAAC;aACF;SACF,CAAC,CAAC,CAAC,EAAE,CAAC;KACR,CAAC;AACJ,CAAC"}
@@ -0,0 +1,21 @@
1
+ /** A fresh marker: `NAME=1`, the name unique to one child. Not a secret. */
2
+ export declare function newEnvironmentMarker(): {
3
+ readonly name: string;
4
+ readonly entry: string;
5
+ };
6
+ /** The pids of this user's processes, other than this one, started with `entry` (`NAME=value`) in their environment. Linux only; empty elsewhere. */
7
+ export declare function markedProcesses(entry: string): number[];
8
+ /** SIGKILL every process `markedProcesses(entry)` finds, pass after pass until one finds none (at most five). Synchronous, so an `exit` hook can call it. */
9
+ export declare function killMarked(entry: string): void;
10
+ /** The same without blocking the event loop: `/proc` is read asynchronously. */
11
+ export declare function markedProcessesAsync(entry: string): Promise<number[]>;
12
+ /** `killMarked` without blocking the event loop. */
13
+ export declare function killMarkedAsync(entry: string): Promise<void>;
14
+ /**
15
+ * Keep `entry` scanned for while its child may run: a host that calls
16
+ * `process.exit` ends the marked processes from its `exit` hook too.
17
+ * Returns the release, for once the child exited and its marked processes
18
+ * were ended.
19
+ */
20
+ export declare function trackEnvironmentMarker(entry: string): () => void;
21
+ //# sourceMappingURL=environment-marker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"environment-marker.d.ts","sources":["../../../src/shared/executable/environment-marker.ts"],"names":[],"mappings":"AAiBA,4EAA4E;AAC5E,wBAAgB,oBAAoB,IAAI;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAGxF;AAED,qJAAqJ;AACrJ,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAiBvD;AAcD,6JAA6J;AAC7J,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAM9C;AAED,gFAAgF;AAChF,wBAAsB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAkB3E;AAED,oDAAoD;AACpD,wBAAsB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAOlE;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,IAAI,CAShE"}