@sumeru/adapter-cursor-agent 0.1.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.
- package/LICENSE +18 -0
- package/dist/.build-fingerprint +1 -0
- package/dist/adapter.d.ts +28 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +350 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/spawn.d.ts +19 -0
- package/dist/spawn.d.ts.map +1 -0
- package/dist/spawn.js +117 -0
- package/dist/spawn.js.map +1 -0
- package/dist/stream-parser.d.ts +51 -0
- package/dist/stream-parser.d.ts.map +1 -0
- package/dist/stream-parser.js +366 -0
- package/dist/stream-parser.js.map +1 -0
- package/dist/types.d.ts +121 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +25 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 shazhou
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
6
|
+
associated documentation files (the "Software"), to deal in the Software without restriction, including
|
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
12
|
+
portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
|
|
15
|
+
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
|
|
16
|
+
EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
18
|
+
USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
e371c4a1fc9f2b118a38850ede13ff6ceeab014e825e4e0e60880bd531f04df1
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor Agent adapter — implements the `Adapter` contract from `@sumeru/core`
|
|
3
|
+
* by shelling out to `cursor-agent -p <prompt> --print --output-format
|
|
4
|
+
* stream-json --trust --force --workspace <cwd>` for create/send and parsing
|
|
5
|
+
* the resulting NDJSON stream into `Turn[]`.
|
|
6
|
+
*
|
|
7
|
+
* cursor-agent does NOT expose a stable on-disk session DB; the adapter
|
|
8
|
+
* therefore caches parsed turns in an in-memory `Map<string, Turn[]>` keyed by
|
|
9
|
+
* `nativeId` and is the sole authority on history for the lifetime of the
|
|
10
|
+
* adapter instance.
|
|
11
|
+
*
|
|
12
|
+
* The factory:
|
|
13
|
+
* - createSession spawns `cursor-agent -p "ping" --print
|
|
14
|
+
* --output-format stream-json --trust --force --workspace <cwd>` and
|
|
15
|
+
* parses the `system` line for the session id. Accepts `SessionConfig`
|
|
16
|
+
* with `model` and `cwd` fields; always uses a fixed "ping" prompt.
|
|
17
|
+
* - send is an async generator that spawns `cursor-agent -p <content>
|
|
18
|
+
* --resume <id> ...`, rewrites the per-run turn indices so they are
|
|
19
|
+
* globally monotonic across the whole `nativeId` lifetime, and yields
|
|
20
|
+
* `SendEvent`s (`turn`, `done`, or `error`).
|
|
21
|
+
* - close is a logical close — adds the nativeId to a per-instance Set; no
|
|
22
|
+
* cursor-agent-side notification, no cache eviction.
|
|
23
|
+
* - getTurns returns a defensive copy of the in-memory cache.
|
|
24
|
+
*/
|
|
25
|
+
import type { Adapter } from "@sumeru/core";
|
|
26
|
+
import type { CursorAgentAdapterOptions } from "./types.js";
|
|
27
|
+
export declare function createCursorAgentAdapter(options?: Partial<CursorAgentAdapterOptions>): Adapter;
|
|
28
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EACX,OAAO,EAMP,MAAM,cAAc,CAAC;AAMtB,OAAO,KAAK,EACX,yBAAyB,EAOzB,MAAM,YAAY,CAAC;AAsBpB,wBAAgB,wBAAwB,CACvC,OAAO,GAAE,OAAO,CAAC,yBAAyB,CAAM,GAC9C,OAAO,CA8ST"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cursor Agent adapter — implements the `Adapter` contract from `@sumeru/core`
|
|
3
|
+
* by shelling out to `cursor-agent -p <prompt> --print --output-format
|
|
4
|
+
* stream-json --trust --force --workspace <cwd>` for create/send and parsing
|
|
5
|
+
* the resulting NDJSON stream into `Turn[]`.
|
|
6
|
+
*
|
|
7
|
+
* cursor-agent does NOT expose a stable on-disk session DB; the adapter
|
|
8
|
+
* therefore caches parsed turns in an in-memory `Map<string, Turn[]>` keyed by
|
|
9
|
+
* `nativeId` and is the sole authority on history for the lifetime of the
|
|
10
|
+
* adapter instance.
|
|
11
|
+
*
|
|
12
|
+
* The factory:
|
|
13
|
+
* - createSession spawns `cursor-agent -p "ping" --print
|
|
14
|
+
* --output-format stream-json --trust --force --workspace <cwd>` and
|
|
15
|
+
* parses the `system` line for the session id. Accepts `SessionConfig`
|
|
16
|
+
* with `model` and `cwd` fields; always uses a fixed "ping" prompt.
|
|
17
|
+
* - send is an async generator that spawns `cursor-agent -p <content>
|
|
18
|
+
* --resume <id> ...`, rewrites the per-run turn indices so they are
|
|
19
|
+
* globally monotonic across the whole `nativeId` lifetime, and yields
|
|
20
|
+
* `SendEvent`s (`turn`, `done`, or `error`).
|
|
21
|
+
* - close is a logical close — adds the nativeId to a per-instance Set; no
|
|
22
|
+
* cursor-agent-side notification, no cache eviction.
|
|
23
|
+
* - getTurns returns a defensive copy of the in-memory cache.
|
|
24
|
+
*/
|
|
25
|
+
import { defaultSpawn, defaultStreamingSpawn } from "./spawn.js";
|
|
26
|
+
import { parseStreamJson, parseStreamJsonIncremental, } from "./stream-parser.js";
|
|
27
|
+
const DEFAULT_CURSOR_AGENT_BIN = "cursor-agent";
|
|
28
|
+
const DEFAULT_CREATE_TIMEOUT_MS = 5 * 60_000;
|
|
29
|
+
const DEFAULT_SEND_TIMEOUT_MS = 10 * 60_000;
|
|
30
|
+
const STDERR_TRUNCATE_LIMIT = 500;
|
|
31
|
+
const API_KEY_ERROR_MESSAGE = "cursor-agent API key error. Check your CURSOR_API_KEY configuration.";
|
|
32
|
+
const TRUST_ERROR_MESSAGE = "cursor-agent requires --trust for headless operation.";
|
|
33
|
+
const API_KEY_PATTERNS = [
|
|
34
|
+
/CURSOR_API_KEY/i,
|
|
35
|
+
/authentication/i,
|
|
36
|
+
/unauthorized/i,
|
|
37
|
+
/api.?key/i,
|
|
38
|
+
];
|
|
39
|
+
const TRUST_PATTERNS = [
|
|
40
|
+
/trust/i,
|
|
41
|
+
/untrusted/i,
|
|
42
|
+
/workspace not trusted/i,
|
|
43
|
+
];
|
|
44
|
+
export function createCursorAgentAdapter(options = {}) {
|
|
45
|
+
const cursorAgentBin = options.cursorAgentBin ?? DEFAULT_CURSOR_AGENT_BIN;
|
|
46
|
+
const defaultModel = options.model ?? null;
|
|
47
|
+
const cwd = options.cwd ?? null;
|
|
48
|
+
const createSessionTimeoutMs = options.createSessionTimeoutMs ?? DEFAULT_CREATE_TIMEOUT_MS;
|
|
49
|
+
const sendTimeoutMs = options.sendTimeoutMs ?? DEFAULT_SEND_TIMEOUT_MS;
|
|
50
|
+
const spawnFn = options.spawnFn ?? defaultSpawn;
|
|
51
|
+
const streamingSpawnFn = options.streamingSpawnFn ?? defaultStreamingSpawn;
|
|
52
|
+
const permissionMode = options.permissionMode ?? "force";
|
|
53
|
+
const sandbox = options.sandbox ?? null;
|
|
54
|
+
const turnsCache = new Map();
|
|
55
|
+
const closedRefs = new Set();
|
|
56
|
+
const sendLocks = new Map();
|
|
57
|
+
function resolveCwd() {
|
|
58
|
+
return cwd ?? process.cwd();
|
|
59
|
+
}
|
|
60
|
+
function buildArgs(prompt, resumeId, model, spawnCwd) {
|
|
61
|
+
const args = [
|
|
62
|
+
"-p",
|
|
63
|
+
prompt,
|
|
64
|
+
"--print",
|
|
65
|
+
"--output-format",
|
|
66
|
+
"stream-json",
|
|
67
|
+
"--trust",
|
|
68
|
+
];
|
|
69
|
+
// Permission mode flag
|
|
70
|
+
if (permissionMode === "force") {
|
|
71
|
+
args.push("--force");
|
|
72
|
+
}
|
|
73
|
+
else if (permissionMode === "yolo") {
|
|
74
|
+
args.push("--yolo");
|
|
75
|
+
}
|
|
76
|
+
if (resumeId !== null) {
|
|
77
|
+
args.push("--resume", resumeId);
|
|
78
|
+
}
|
|
79
|
+
if (model !== null) {
|
|
80
|
+
args.push("--model", model);
|
|
81
|
+
}
|
|
82
|
+
if (sandbox !== null) {
|
|
83
|
+
args.push("--sandbox", sandbox);
|
|
84
|
+
}
|
|
85
|
+
args.push("--workspace", spawnCwd);
|
|
86
|
+
return args;
|
|
87
|
+
}
|
|
88
|
+
async function runCursorAgent(prompt, resumeId, model, timeoutMs, spawnCwd) {
|
|
89
|
+
const args = buildArgs(prompt, resumeId, model, spawnCwd);
|
|
90
|
+
const result = await spawnFn({
|
|
91
|
+
command: cursorAgentBin,
|
|
92
|
+
args,
|
|
93
|
+
timeoutMs,
|
|
94
|
+
cwd: spawnCwd,
|
|
95
|
+
}).catch((err) => {
|
|
96
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
97
|
+
throw new Error(`cursor-agent adapter failed to spawn '${cursorAgentBin}': ${detail}`);
|
|
98
|
+
});
|
|
99
|
+
const parsed = parseStreamJson(result.stdout);
|
|
100
|
+
return { result, parsed };
|
|
101
|
+
}
|
|
102
|
+
async function createSession(config) {
|
|
103
|
+
const model = config.model !== null && config.model.length > 0
|
|
104
|
+
? config.model
|
|
105
|
+
: defaultModel;
|
|
106
|
+
const spawnCwd = config.cwd !== null && config.cwd.length > 0 ? config.cwd : resolveCwd();
|
|
107
|
+
const { result, parsed } = await runCursorAgent("ping", null, model, createSessionTimeoutMs, spawnCwd);
|
|
108
|
+
if (result.timedOut) {
|
|
109
|
+
throw new Error(`createSession timed out after ${createSessionTimeoutMs}ms`);
|
|
110
|
+
}
|
|
111
|
+
if (parsed === null) {
|
|
112
|
+
throw makeUnparseableOrExitError(result, cursorAgentBin);
|
|
113
|
+
}
|
|
114
|
+
if (parsed.sessionId === "") {
|
|
115
|
+
throw makeUnparseableOrExitError(result, cursorAgentBin);
|
|
116
|
+
}
|
|
117
|
+
const rewritten = rewriteIndices(parsed.turns, -1);
|
|
118
|
+
turnsCache.set(parsed.sessionId, rewritten);
|
|
119
|
+
const meta = {
|
|
120
|
+
cwd: spawnCwd,
|
|
121
|
+
model: parsed.model !== "" ? parsed.model : model,
|
|
122
|
+
createdAt: new Date().toISOString(),
|
|
123
|
+
subtype: parsed.subtype,
|
|
124
|
+
};
|
|
125
|
+
return { nativeId: parsed.sessionId, meta };
|
|
126
|
+
}
|
|
127
|
+
function send(ref, content) {
|
|
128
|
+
// Synchronous pre-checks — throw before returning the iterable.
|
|
129
|
+
assertRef(ref, "send");
|
|
130
|
+
if (closedRefs.has(ref.nativeId)) {
|
|
131
|
+
throw new Error(`cursor-agent session ${ref.nativeId} is closed`);
|
|
132
|
+
}
|
|
133
|
+
if (typeof content !== "string" || content.length === 0) {
|
|
134
|
+
throw new Error("send: content must be a non-empty string");
|
|
135
|
+
}
|
|
136
|
+
const nativeId = ref.nativeId;
|
|
137
|
+
async function* generate() {
|
|
138
|
+
// Acquire the lock — it stays held until this generator finishes.
|
|
139
|
+
const prev = sendLocks.get(nativeId) ?? Promise.resolve();
|
|
140
|
+
let release = () => { };
|
|
141
|
+
const next = new Promise((resolve) => {
|
|
142
|
+
release = resolve;
|
|
143
|
+
});
|
|
144
|
+
const chain = prev.then(() => next);
|
|
145
|
+
sendLocks.set(nativeId, chain);
|
|
146
|
+
try {
|
|
147
|
+
await prev;
|
|
148
|
+
yield* streamSend(nativeId, ref, content);
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
release();
|
|
152
|
+
if (sendLocks.get(nativeId) === chain) {
|
|
153
|
+
sendLocks.delete(nativeId);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return generate();
|
|
158
|
+
}
|
|
159
|
+
async function* streamSend(nativeId, ref, content) {
|
|
160
|
+
if (closedRefs.has(nativeId)) {
|
|
161
|
+
yield {
|
|
162
|
+
type: "error",
|
|
163
|
+
error: new Error(`cursor-agent session ${nativeId} is closed`),
|
|
164
|
+
};
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
const before = turnsCache.get(nativeId) ?? [];
|
|
168
|
+
const highWater = before.length === 0
|
|
169
|
+
? -1
|
|
170
|
+
: before.reduce((m, t) => (t.index > m ? t.index : m), -1);
|
|
171
|
+
let nextIndex = highWater + 1;
|
|
172
|
+
const refModel = typeof ref.meta.model === "string" && ref.meta.model.length > 0
|
|
173
|
+
? ref.meta.model
|
|
174
|
+
: defaultModel;
|
|
175
|
+
const refCwd = typeof ref.meta.cwd === "string" && ref.meta.cwd.length > 0
|
|
176
|
+
? ref.meta.cwd
|
|
177
|
+
: resolveCwd();
|
|
178
|
+
const args = buildArgs(content, nativeId, refModel, refCwd);
|
|
179
|
+
const startedAt = Date.now();
|
|
180
|
+
let streamResult;
|
|
181
|
+
try {
|
|
182
|
+
streamResult = streamingSpawnFn({
|
|
183
|
+
command: cursorAgentBin,
|
|
184
|
+
args,
|
|
185
|
+
timeoutMs: sendTimeoutMs,
|
|
186
|
+
cwd: refCwd,
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
const detail = err instanceof Error ? err.message : String(err);
|
|
191
|
+
yield {
|
|
192
|
+
type: "error",
|
|
193
|
+
error: new Error(`cursor-agent adapter failed to spawn '${cursorAgentBin}': ${detail}`),
|
|
194
|
+
};
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
let resultLine = null;
|
|
198
|
+
try {
|
|
199
|
+
for await (const event of parseStreamJsonIncremental(streamResult.lines)) {
|
|
200
|
+
if (event.type === "turn") {
|
|
201
|
+
const turn = event.turn;
|
|
202
|
+
turn.index = nextIndex++;
|
|
203
|
+
const existing = turnsCache.get(nativeId) ?? [];
|
|
204
|
+
turnsCache.set(nativeId, [...existing, turn]);
|
|
205
|
+
yield { type: "turn", turn };
|
|
206
|
+
}
|
|
207
|
+
else if (event.type === "result") {
|
|
208
|
+
resultLine = event.resultLine;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
catch (err) {
|
|
213
|
+
yield {
|
|
214
|
+
type: "error",
|
|
215
|
+
error: err instanceof Error
|
|
216
|
+
? err
|
|
217
|
+
: new Error(`stream read error: ${String(err)}`),
|
|
218
|
+
};
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let exitInfo;
|
|
222
|
+
try {
|
|
223
|
+
exitInfo = await streamResult.waitForExit();
|
|
224
|
+
}
|
|
225
|
+
catch (err) {
|
|
226
|
+
yield {
|
|
227
|
+
type: "error",
|
|
228
|
+
error: err instanceof Error
|
|
229
|
+
? err
|
|
230
|
+
: new Error(`process exit error: ${String(err)}`),
|
|
231
|
+
};
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
if (exitInfo.timedOut) {
|
|
235
|
+
yield {
|
|
236
|
+
type: "error",
|
|
237
|
+
error: new Error(`send timed out after ${sendTimeoutMs}ms`),
|
|
238
|
+
};
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
if (exitInfo.exitCode !== null && exitInfo.exitCode !== 0) {
|
|
242
|
+
const stderrTrimmed = exitInfo.stderr.trim();
|
|
243
|
+
const snippet = stderrTrimmed === ""
|
|
244
|
+
? ""
|
|
245
|
+
: `: ${tail(stderrTrimmed, STDERR_TRUNCATE_LIMIT)}`;
|
|
246
|
+
yield {
|
|
247
|
+
type: "error",
|
|
248
|
+
error: new Error(`cursor-agent exited with code ${String(exitInfo.exitCode)}${snippet}`),
|
|
249
|
+
};
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const tokens = deriveTokensFromResultLine(resultLine);
|
|
253
|
+
yield {
|
|
254
|
+
type: "done",
|
|
255
|
+
durationMs: Date.now() - startedAt,
|
|
256
|
+
tokens,
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
async function close(ref) {
|
|
260
|
+
assertRef(ref, "close");
|
|
261
|
+
closedRefs.add(ref.nativeId);
|
|
262
|
+
}
|
|
263
|
+
async function getTurns(ref) {
|
|
264
|
+
assertRef(ref, "getTurns");
|
|
265
|
+
const cached = turnsCache.get(ref.nativeId);
|
|
266
|
+
if (cached === undefined)
|
|
267
|
+
return [];
|
|
268
|
+
return [...cached];
|
|
269
|
+
}
|
|
270
|
+
return {
|
|
271
|
+
name: "cursor-agent",
|
|
272
|
+
createSession,
|
|
273
|
+
send,
|
|
274
|
+
close,
|
|
275
|
+
getTurns,
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function assertRef(ref, op) {
|
|
279
|
+
if (ref === null ||
|
|
280
|
+
ref === undefined ||
|
|
281
|
+
typeof ref !== "object" ||
|
|
282
|
+
typeof ref.nativeId !== "string" ||
|
|
283
|
+
ref.nativeId.length === 0) {
|
|
284
|
+
throw new Error(`${op}: invalid NativeSessionRef`);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function rewriteIndices(turns, highWater) {
|
|
288
|
+
let nextIndex = highWater + 1;
|
|
289
|
+
return turns.map((turn) => ({
|
|
290
|
+
...turn,
|
|
291
|
+
index: nextIndex++,
|
|
292
|
+
}));
|
|
293
|
+
}
|
|
294
|
+
function isRecord(value) {
|
|
295
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
296
|
+
}
|
|
297
|
+
function safeNumber(v, fallback = 0) {
|
|
298
|
+
return typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
299
|
+
}
|
|
300
|
+
function deriveTokensFromResultLine(resultLine) {
|
|
301
|
+
if (resultLine === null)
|
|
302
|
+
return null;
|
|
303
|
+
const usage = isRecord(resultLine.usage) ? resultLine.usage : {};
|
|
304
|
+
const input = safeNumber(usage.inputTokens);
|
|
305
|
+
const output = safeNumber(usage.outputTokens);
|
|
306
|
+
if (input === 0 && output === 0)
|
|
307
|
+
return null;
|
|
308
|
+
return { input, output };
|
|
309
|
+
}
|
|
310
|
+
function makeUnparseableOrExitError(result, cursorAgentBin, nativeId = null) {
|
|
311
|
+
const stderr = result.stderr ?? "";
|
|
312
|
+
const stdout = result.stdout ?? "";
|
|
313
|
+
const stderrTrimmed = stderr.trim();
|
|
314
|
+
// API key errors take precedence.
|
|
315
|
+
for (const pattern of API_KEY_PATTERNS) {
|
|
316
|
+
if (pattern.test(stderrTrimmed)) {
|
|
317
|
+
const codeText = result.exitCode === null ? "null" : String(result.exitCode);
|
|
318
|
+
return new Error(`cursor-agent exited with code ${codeText}: ${API_KEY_ERROR_MESSAGE}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Trust errors.
|
|
322
|
+
for (const pattern of TRUST_PATTERNS) {
|
|
323
|
+
if (pattern.test(stderrTrimmed)) {
|
|
324
|
+
const codeText = result.exitCode === null ? "null" : String(result.exitCode);
|
|
325
|
+
return new Error(`cursor-agent exited with code ${codeText}: ${TRUST_ERROR_MESSAGE}`);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
// Session-not-found heuristic for resume failures.
|
|
329
|
+
if (nativeId !== null &&
|
|
330
|
+
/not found|no such session|session.*not.*exist/i.test(stderrTrimmed)) {
|
|
331
|
+
return new Error(`cursor-agent session ${nativeId} not found: ${tail(stderrTrimmed, STDERR_TRUNCATE_LIMIT)}`);
|
|
332
|
+
}
|
|
333
|
+
if (result.exitCode !== null && result.exitCode !== 0) {
|
|
334
|
+
const codeText = String(result.exitCode);
|
|
335
|
+
const snippet = stderrTrimmed === ""
|
|
336
|
+
? ""
|
|
337
|
+
: `: ${tail(stderrTrimmed, STDERR_TRUNCATE_LIMIT)}`;
|
|
338
|
+
return new Error(`cursor-agent exited with code ${codeText}${snippet}`);
|
|
339
|
+
}
|
|
340
|
+
// Unparseable but exit was 0 (or null).
|
|
341
|
+
const head = stdout.slice(0, 500);
|
|
342
|
+
const stderrTail = tail(stderrTrimmed, STDERR_TRUNCATE_LIMIT);
|
|
343
|
+
return new Error(`cursor-agent returned unparseable stream-json output (bin=${cursorAgentBin}, first 500 chars: ${head}, stderr tail: ${stderrTail})`);
|
|
344
|
+
}
|
|
345
|
+
function tail(s, n) {
|
|
346
|
+
if (s.length <= n)
|
|
347
|
+
return s;
|
|
348
|
+
return s.slice(s.length - n);
|
|
349
|
+
}
|
|
350
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAUH,OAAO,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AACjE,OAAO,EACN,eAAe,EACf,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAW5B,MAAM,wBAAwB,GAAG,cAAc,CAAC;AAChD,MAAM,yBAAyB,GAAG,CAAC,GAAG,MAAM,CAAC;AAC7C,MAAM,uBAAuB,GAAG,EAAE,G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I,KAAK,CACf,wBAAwB,QAAQ,eAAe,IAAI,CAAC,aAAa,EAAE,qBAAqB,CAAC,EAAE,CAC3F,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,QAAQ,KAAK,IAAI,IAAI,MAAM,CAAC,QAAQ,KAAK,CAAC,EAAE,CAAC;QACvD,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzC,MAAM,OAAO,GACZ,aAAa,KAAK,EAAE;YACnB,CAAC,CAAC,EAAE;YACJ,CAAC,CAAC,KAAK,IAAI,CAAC,aAAa,EAAE,qBAAqB,CAAC,EAAE,CAAC;QACtD,OAAO,IAAI,KAAK,CAAC,iCAAiC,QAAQ,GAAG,OAAO,EAAE,CAAC,CAAC;IACzE,CAAC;IAED,wCAAwC;IACxC,MAAM,IAAI,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IAClC,MAAM,UAAU,GAAG,IAAI,CAAC,aAAa,EAAE,qBAAqB,CAAC,CAAC;IAC9D,OAAO,IAAI,KAAK,CACf,6DAA6D,cAAc,sBAAsB,IAAI,kBAAkB,UAAU,GAAG,CACpI,CAAC;AACH,CAAC;AAED,SAAS,IAAI,CAAC,CAAS,EAAE,CAAS;IACjC,IAAI,CAAC,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,CAAC,CAAC;IAC5B,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of `@sumeru/adapter-cursor-agent`.
|
|
3
|
+
*
|
|
4
|
+
* The factory `createCursorAgentAdapter` returns an `Adapter` (from
|
|
5
|
+
* `@sumeru/core`) that drives cursor-agent via its CLI in
|
|
6
|
+
* `--print --output-format stream-json --trust --force` mode.
|
|
7
|
+
* See `adapter.ts` for the implementation.
|
|
8
|
+
*/
|
|
9
|
+
export { createCursorAgentAdapter } from "./adapter.js";
|
|
10
|
+
export { parseStreamJson, parseStreamJsonIncremental, } from "./stream-parser.js";
|
|
11
|
+
export type { CursorAgentAdapterOptions, CursorAgentParsedResult, CursorAgentResultSubtype, SpawnArgs, SpawnExitInfo, SpawnFn, SpawnResult, SpawnStreamResult, StreamingSpawnFn, StreamParseEvent, } from "./types.js";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACN,eAAe,EACf,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EACX,yBAAyB,EACzB,uBAAuB,EACvB,wBAAwB,EACxB,SAAS,EACT,aAAa,EACb,OAAO,EACP,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,gBAAgB,GAChB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public surface of `@sumeru/adapter-cursor-agent`.
|
|
3
|
+
*
|
|
4
|
+
* The factory `createCursorAgentAdapter` returns an `Adapter` (from
|
|
5
|
+
* `@sumeru/core`) that drives cursor-agent via its CLI in
|
|
6
|
+
* `--print --output-format stream-json --trust --force` mode.
|
|
7
|
+
* See `adapter.ts` for the implementation.
|
|
8
|
+
*/
|
|
9
|
+
export { createCursorAgentAdapter } from "./adapter.js";
|
|
10
|
+
export { parseStreamJson, parseStreamJsonIncremental, } from "./stream-parser.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EACN,eAAe,EACf,0BAA0B,GAC1B,MAAM,oBAAoB,CAAC"}
|
package/dist/spawn.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default `SpawnFn` for the Cursor Agent adapter — wraps
|
|
3
|
+
* `node:child_process.spawn` with a timeout.
|
|
4
|
+
*
|
|
5
|
+
* Returns `{stdout, stderr, exitCode, signal, timedOut, durationMs}`. On
|
|
6
|
+
* timeout the child receives `SIGTERM`; if it is still alive after 5 s a
|
|
7
|
+
* `SIGKILL` follows. `timedOut` is set to `true`.
|
|
8
|
+
*
|
|
9
|
+
* Argv is passed as an explicit array — never via shell — so embedded
|
|
10
|
+
* quotes, backslashes, newlines, and emoji round-trip without corruption.
|
|
11
|
+
*/
|
|
12
|
+
import type { SpawnFn, StreamingSpawnFn } from "./types.js";
|
|
13
|
+
export declare const defaultSpawn: SpawnFn;
|
|
14
|
+
/**
|
|
15
|
+
* Streaming variant of `defaultSpawn` — returns synchronously with
|
|
16
|
+
* line-by-line stdout access via `lines` (an AsyncIterable<string>).
|
|
17
|
+
*/
|
|
18
|
+
export declare const defaultStreamingSpawn: StreamingSpawnFn;
|
|
19
|
+
//# sourceMappingURL=spawn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.d.ts","sourceRoot":"","sources":["../src/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,KAAK,EAGX,OAAO,EAGP,gBAAgB,EAChB,MAAM,YAAY,CAAC;AAIpB,eAAO,MAAM,YAAY,EAAE,OAyD1B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,qBAAqB,EAAE,gBA4DnC,CAAC"}
|
package/dist/spawn.js
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default `SpawnFn` for the Cursor Agent adapter — wraps
|
|
3
|
+
* `node:child_process.spawn` with a timeout.
|
|
4
|
+
*
|
|
5
|
+
* Returns `{stdout, stderr, exitCode, signal, timedOut, durationMs}`. On
|
|
6
|
+
* timeout the child receives `SIGTERM`; if it is still alive after 5 s a
|
|
7
|
+
* `SIGKILL` follows. `timedOut` is set to `true`.
|
|
8
|
+
*
|
|
9
|
+
* Argv is passed as an explicit array — never via shell — so embedded
|
|
10
|
+
* quotes, backslashes, newlines, and emoji round-trip without corruption.
|
|
11
|
+
*/
|
|
12
|
+
import { spawn } from "node:child_process";
|
|
13
|
+
import { createInterface } from "node:readline";
|
|
14
|
+
const FORCE_KILL_GRACE_MS = 5_000;
|
|
15
|
+
export const defaultSpawn = async ({ command, args, timeoutMs, cwd, }) => {
|
|
16
|
+
const startedAt = Date.now();
|
|
17
|
+
return new Promise((resolve, reject) => {
|
|
18
|
+
let child;
|
|
19
|
+
try {
|
|
20
|
+
child = spawn(command, args, {
|
|
21
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
22
|
+
windowsHide: true,
|
|
23
|
+
cwd,
|
|
24
|
+
env: process.env,
|
|
25
|
+
shell: false,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
reject(err instanceof Error ? err : new Error(String(err)));
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let timedOut = false;
|
|
33
|
+
const stdoutChunks = [];
|
|
34
|
+
const stderrChunks = [];
|
|
35
|
+
const timer = setTimeout(() => {
|
|
36
|
+
timedOut = true;
|
|
37
|
+
child.kill("SIGTERM");
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
40
|
+
child.kill("SIGKILL");
|
|
41
|
+
}
|
|
42
|
+
}, FORCE_KILL_GRACE_MS).unref();
|
|
43
|
+
}, timeoutMs);
|
|
44
|
+
timer.unref();
|
|
45
|
+
child.stdout?.on("data", (chunk) => stdoutChunks.push(chunk));
|
|
46
|
+
child.stderr?.on("data", (chunk) => stderrChunks.push(chunk));
|
|
47
|
+
child.once("error", (err) => {
|
|
48
|
+
clearTimeout(timer);
|
|
49
|
+
reject(err);
|
|
50
|
+
});
|
|
51
|
+
child.once("close", (code, signal) => {
|
|
52
|
+
clearTimeout(timer);
|
|
53
|
+
resolve({
|
|
54
|
+
stdout: Buffer.concat(stdoutChunks).toString("utf-8"),
|
|
55
|
+
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
56
|
+
exitCode: code,
|
|
57
|
+
signal: signal ?? null,
|
|
58
|
+
timedOut,
|
|
59
|
+
durationMs: Date.now() - startedAt,
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Streaming variant of `defaultSpawn` — returns synchronously with
|
|
66
|
+
* line-by-line stdout access via `lines` (an AsyncIterable<string>).
|
|
67
|
+
*/
|
|
68
|
+
export const defaultStreamingSpawn = ({ command, args, timeoutMs, cwd, }) => {
|
|
69
|
+
const startedAt = Date.now();
|
|
70
|
+
const child = spawn(command, args, {
|
|
71
|
+
stdio: ["ignore", "pipe", "pipe"],
|
|
72
|
+
windowsHide: true,
|
|
73
|
+
cwd,
|
|
74
|
+
env: process.env,
|
|
75
|
+
shell: false,
|
|
76
|
+
});
|
|
77
|
+
let timedOut = false;
|
|
78
|
+
const stderrChunks = [];
|
|
79
|
+
const timer = setTimeout(() => {
|
|
80
|
+
timedOut = true;
|
|
81
|
+
child.kill("SIGTERM");
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
if (child.exitCode === null && child.signalCode === null) {
|
|
84
|
+
child.kill("SIGKILL");
|
|
85
|
+
}
|
|
86
|
+
}, FORCE_KILL_GRACE_MS).unref();
|
|
87
|
+
}, timeoutMs);
|
|
88
|
+
timer.unref();
|
|
89
|
+
// stdio: ["ignore", "pipe", "pipe"] guarantees child.stdout is non-null
|
|
90
|
+
const stdout = child.stdout;
|
|
91
|
+
if (stdout === null) {
|
|
92
|
+
throw new Error("child.stdout is null despite pipe stdio configuration");
|
|
93
|
+
}
|
|
94
|
+
child.stderr?.on("data", (chunk) => stderrChunks.push(chunk));
|
|
95
|
+
const rl = createInterface({ input: stdout, crlfDelay: Infinity });
|
|
96
|
+
const exitPromise = new Promise((resolve, reject) => {
|
|
97
|
+
child.once("error", (err) => {
|
|
98
|
+
clearTimeout(timer);
|
|
99
|
+
reject(err);
|
|
100
|
+
});
|
|
101
|
+
child.once("close", (code, signal) => {
|
|
102
|
+
clearTimeout(timer);
|
|
103
|
+
resolve({
|
|
104
|
+
exitCode: code,
|
|
105
|
+
signal: signal ?? null,
|
|
106
|
+
timedOut,
|
|
107
|
+
durationMs: Date.now() - startedAt,
|
|
108
|
+
stderr: Buffer.concat(stderrChunks).toString("utf-8"),
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
return {
|
|
113
|
+
lines: rl,
|
|
114
|
+
waitForExit: () => exitPromise,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
//# sourceMappingURL=spawn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn.js","sourceRoot":"","sources":["../src/spawn.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAUhD,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,MAAM,CAAC,MAAM,YAAY,GAAY,KAAK,EAAE,EAC3C,OAAO,EACP,IAAI,EACJ,SAAS,EACT,GAAG,GACQ,EAAwB,EAAE;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,OAAO,IAAI,OAAO,CAAc,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnD,IAAI,KAA+B,CAAC;QACpC,IAAI,CAAC;YACJ,KAAK,GA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AAQ;gBACR,UAAU,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,SAAS;gBAClC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC;aACrD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO;QACN,KAAK,EAAE,EAAE;QACT,WAAW,EAAE,GAAG,EAAE,CAAC,WAAW;KAC9B,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream-json parser for cursor-agent's
|
|
3
|
+
* `cursor-agent -p ... --output-format stream-json` NDJSON output.
|
|
4
|
+
*
|
|
5
|
+
* Each line is a JSON object with a `type` field:
|
|
6
|
+
* - `"system"` (subtype: `init`) — first line; carries `session_id`, `model`,
|
|
7
|
+
* `cwd`, `permissionMode`.
|
|
8
|
+
* - `"user"` — carries `message.content` array with text segments.
|
|
9
|
+
* - `"thinking"` (subtype: `delta` or `completed`) — reasoning text; discarded.
|
|
10
|
+
* - `"assistant"` — carries `message.content` array.
|
|
11
|
+
* - `"tool_call"` (subtype: `started`) — carries `call_id`,
|
|
12
|
+
* `tool_call.{editToolCall|shellToolCall}.args`.
|
|
13
|
+
* - `"tool_call"` (subtype: `completed`) — carries `call_id`,
|
|
14
|
+
* `tool_call.{...}.result`.
|
|
15
|
+
* - `"result"` (subtype: `success`) — carries `result`, `duration_ms`, `usage`.
|
|
16
|
+
*
|
|
17
|
+
* Unlike Claude Code (where tool_use is embedded in assistant message content
|
|
18
|
+
* and tool_result is a user line), cursor-agent uses separate `tool_call`
|
|
19
|
+
* events with explicit `started`/`completed` subtypes. The parser maps these
|
|
20
|
+
* to Sumeru's `ToolCall` model.
|
|
21
|
+
*/
|
|
22
|
+
import type { CursorAgentParsedResult, StreamParseEvent } from "./types.js";
|
|
23
|
+
/**
|
|
24
|
+
* Parse cursor-agent stream-json (NDJSON) output into an ordered Turn[] plus
|
|
25
|
+
* a result summary.
|
|
26
|
+
*
|
|
27
|
+
* Behavior:
|
|
28
|
+
* - Pure: same input → same output (modulo the per-call `now()` timestamp).
|
|
29
|
+
* - Tolerant: malformed lines and lines without a recognized `type` are
|
|
30
|
+
* silently skipped.
|
|
31
|
+
* - Returns `null` when neither a `system` line (with session_id) NOR a
|
|
32
|
+
* `result` line was parsed — the adapter caller maps this to a hard error.
|
|
33
|
+
*
|
|
34
|
+
* @param stdout Raw NDJSON text (the full captured stdout of `cursor-agent -p`).
|
|
35
|
+
*/
|
|
36
|
+
export declare function parseStreamJson(stdout: string): CursorAgentParsedResult | null;
|
|
37
|
+
/**
|
|
38
|
+
* Incremental async-generator parser for cursor-agent NDJSON output.
|
|
39
|
+
*
|
|
40
|
+
* Yields `StreamParseEvent` as each line is consumed:
|
|
41
|
+
* - `{ type: "meta" }` after the first `system` line sets session + model.
|
|
42
|
+
* - `{ type: "turn" }` for each new Turn added (assistant, user, or
|
|
43
|
+
* assistant created by a `tool_call` started event).
|
|
44
|
+
* - `{ type: "result" }` when the `result` line is encountered.
|
|
45
|
+
*
|
|
46
|
+
* `tool_call` started events that MUTATE an existing turn's toolCalls array
|
|
47
|
+
* do NOT yield a new event (reference sharing). `tool_call` completed events
|
|
48
|
+
* fill in `ToolCall.output` on previously-yielded Turn objects — no new event.
|
|
49
|
+
*/
|
|
50
|
+
export declare function parseStreamJsonIncremental(lines: AsyncIterable<string>): AsyncGenerator<StreamParseEvent>;
|
|
51
|
+
//# sourceMappingURL=stream-parser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-parser.d.ts","sourceRoot":"","sources":["../src/stream-parser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EACX,uBAAuB,EAEvB,gBAAgB,EAChB,MAAM,YAAY,CAAC;AAyTpB;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC9B,MAAM,EAAE,MAAM,GACZ,uBAAuB,GAAG,IAAI,CAehC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAuB,0BAA0B,CAChD,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,GAC1B,cAAc,CAAC,gBAAgB,CAAC,CAuClC"}
|
|
@@ -0,0 +1,366 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stream-json parser for cursor-agent's
|
|
3
|
+
* `cursor-agent -p ... --output-format stream-json` NDJSON output.
|
|
4
|
+
*
|
|
5
|
+
* Each line is a JSON object with a `type` field:
|
|
6
|
+
* - `"system"` (subtype: `init`) — first line; carries `session_id`, `model`,
|
|
7
|
+
* `cwd`, `permissionMode`.
|
|
8
|
+
* - `"user"` — carries `message.content` array with text segments.
|
|
9
|
+
* - `"thinking"` (subtype: `delta` or `completed`) — reasoning text; discarded.
|
|
10
|
+
* - `"assistant"` — carries `message.content` array.
|
|
11
|
+
* - `"tool_call"` (subtype: `started`) — carries `call_id`,
|
|
12
|
+
* `tool_call.{editToolCall|shellToolCall}.args`.
|
|
13
|
+
* - `"tool_call"` (subtype: `completed`) — carries `call_id`,
|
|
14
|
+
* `tool_call.{...}.result`.
|
|
15
|
+
* - `"result"` (subtype: `success`) — carries `result`, `duration_ms`, `usage`.
|
|
16
|
+
*
|
|
17
|
+
* Unlike Claude Code (where tool_use is embedded in assistant message content
|
|
18
|
+
* and tool_result is a user line), cursor-agent uses separate `tool_call`
|
|
19
|
+
* events with explicit `started`/`completed` subtypes. The parser maps these
|
|
20
|
+
* to Sumeru's `ToolCall` model.
|
|
21
|
+
*/
|
|
22
|
+
function isRecord(value) {
|
|
23
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
24
|
+
}
|
|
25
|
+
function safeNumber(v, fallback = 0) {
|
|
26
|
+
return typeof v === "number" && Number.isFinite(v) ? v : fallback;
|
|
27
|
+
}
|
|
28
|
+
function extractTextContent(content) {
|
|
29
|
+
const texts = [];
|
|
30
|
+
for (const item of content) {
|
|
31
|
+
if (isRecord(item) &&
|
|
32
|
+
item.type === "text" &&
|
|
33
|
+
typeof item.text === "string") {
|
|
34
|
+
texts.push(item.text);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return texts.join("\n");
|
|
38
|
+
}
|
|
39
|
+
function processSystemLine(parsed, state) {
|
|
40
|
+
if (typeof parsed.session_id === "string")
|
|
41
|
+
state.sessionId = parsed.session_id;
|
|
42
|
+
if (typeof parsed.model === "string")
|
|
43
|
+
state.model = parsed.model;
|
|
44
|
+
}
|
|
45
|
+
function processAssistantLine(parsed, state) {
|
|
46
|
+
if (!isRecord(parsed.message))
|
|
47
|
+
return;
|
|
48
|
+
const content = Array.isArray(parsed.message.content)
|
|
49
|
+
? parsed.message.content
|
|
50
|
+
: [];
|
|
51
|
+
const textContent = extractTextContent(content);
|
|
52
|
+
if (textContent === "")
|
|
53
|
+
return;
|
|
54
|
+
const turn = {
|
|
55
|
+
index: state.turnIndex++,
|
|
56
|
+
role: "assistant",
|
|
57
|
+
content: textContent,
|
|
58
|
+
timestamp: state.now,
|
|
59
|
+
toolCalls: null,
|
|
60
|
+
tokens: null,
|
|
61
|
+
hash: null,
|
|
62
|
+
};
|
|
63
|
+
state.turns.push(turn);
|
|
64
|
+
}
|
|
65
|
+
function processUserLine(parsed, state) {
|
|
66
|
+
if (!isRecord(parsed.message))
|
|
67
|
+
return;
|
|
68
|
+
const content = Array.isArray(parsed.message.content)
|
|
69
|
+
? parsed.message.content
|
|
70
|
+
: [];
|
|
71
|
+
const userText = extractTextContent(content);
|
|
72
|
+
if (userText === "")
|
|
73
|
+
return;
|
|
74
|
+
state.turns.push({
|
|
75
|
+
index: state.turnIndex++,
|
|
76
|
+
role: "user",
|
|
77
|
+
content: userText,
|
|
78
|
+
timestamp: state.now,
|
|
79
|
+
toolCalls: null,
|
|
80
|
+
tokens: null,
|
|
81
|
+
hash: null,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
function getToolName(toolCallObj) {
|
|
85
|
+
if ("editToolCall" in toolCallObj)
|
|
86
|
+
return "editToolCall";
|
|
87
|
+
if ("shellToolCall" in toolCallObj)
|
|
88
|
+
return "shellToolCall";
|
|
89
|
+
// Fallback: find the first key that looks like a tool call
|
|
90
|
+
for (const key of Object.keys(toolCallObj)) {
|
|
91
|
+
if (key.endsWith("ToolCall"))
|
|
92
|
+
return key;
|
|
93
|
+
}
|
|
94
|
+
return "unknownTool";
|
|
95
|
+
}
|
|
96
|
+
function getToolArgs(toolCallObj, toolName) {
|
|
97
|
+
const inner = toolCallObj[toolName];
|
|
98
|
+
if (isRecord(inner) && isRecord(inner.args)) {
|
|
99
|
+
return inner.args;
|
|
100
|
+
}
|
|
101
|
+
if (isRecord(inner)) {
|
|
102
|
+
return inner;
|
|
103
|
+
}
|
|
104
|
+
return {};
|
|
105
|
+
}
|
|
106
|
+
function getToolResult(toolCallObj, toolName) {
|
|
107
|
+
const inner = toolCallObj[toolName];
|
|
108
|
+
if (!isRecord(inner))
|
|
109
|
+
return { output: "", exitCode: null };
|
|
110
|
+
const result = inner.result;
|
|
111
|
+
if (isRecord(result)) {
|
|
112
|
+
const stdout = typeof result.stdout === "string" ? result.stdout : "";
|
|
113
|
+
const content = typeof result.content === "string" ? result.content : "";
|
|
114
|
+
const output = stdout || content || JSON.stringify(result);
|
|
115
|
+
const exitCode = toolName === "shellToolCall" && typeof result.exitCode === "number"
|
|
116
|
+
? result.exitCode
|
|
117
|
+
: null;
|
|
118
|
+
return { output, exitCode };
|
|
119
|
+
}
|
|
120
|
+
if (typeof result === "string")
|
|
121
|
+
return { output: result, exitCode: null };
|
|
122
|
+
return { output: JSON.stringify(result ?? null), exitCode: null };
|
|
123
|
+
}
|
|
124
|
+
function processToolCallStarted(parsed, state) {
|
|
125
|
+
const callId = typeof parsed.call_id === "string" ? parsed.call_id : null;
|
|
126
|
+
if (callId === null)
|
|
127
|
+
return;
|
|
128
|
+
const toolCallObj = parsed.tool_call;
|
|
129
|
+
if (!isRecord(toolCallObj))
|
|
130
|
+
return;
|
|
131
|
+
const toolName = getToolName(toolCallObj);
|
|
132
|
+
const input = getToolArgs(toolCallObj, toolName);
|
|
133
|
+
const call = {
|
|
134
|
+
tool: toolName,
|
|
135
|
+
input,
|
|
136
|
+
output: null,
|
|
137
|
+
durationMs: null,
|
|
138
|
+
exitCode: null,
|
|
139
|
+
};
|
|
140
|
+
// Associate with the most recent assistant Turn.
|
|
141
|
+
const lastAssistantIdx = findLastAssistantTurnIndex(state.turns);
|
|
142
|
+
if (lastAssistantIdx >= 0) {
|
|
143
|
+
const turn = state.turns[lastAssistantIdx];
|
|
144
|
+
if (turn !== undefined) {
|
|
145
|
+
if (turn.toolCalls === null) {
|
|
146
|
+
turn.toolCalls = [call];
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
turn.toolCalls.push(call);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
// No assistant turn yet — create one with empty content to hold the tool call.
|
|
155
|
+
const turn = {
|
|
156
|
+
index: state.turnIndex++,
|
|
157
|
+
role: "assistant",
|
|
158
|
+
content: "",
|
|
159
|
+
timestamp: state.now,
|
|
160
|
+
toolCalls: [call],
|
|
161
|
+
tokens: null,
|
|
162
|
+
hash: null,
|
|
163
|
+
};
|
|
164
|
+
state.turns.push(turn);
|
|
165
|
+
}
|
|
166
|
+
state.pendingToolCalls.set(callId, call);
|
|
167
|
+
}
|
|
168
|
+
function processToolCallCompleted(parsed, state) {
|
|
169
|
+
const callId = typeof parsed.call_id === "string" ? parsed.call_id : null;
|
|
170
|
+
if (callId === null)
|
|
171
|
+
return;
|
|
172
|
+
const target = state.pendingToolCalls.get(callId);
|
|
173
|
+
if (target === undefined)
|
|
174
|
+
return; // unmatched completed — silently dropped
|
|
175
|
+
const toolCallObj = parsed.tool_call;
|
|
176
|
+
if (!isRecord(toolCallObj))
|
|
177
|
+
return;
|
|
178
|
+
const toolName = target.tool;
|
|
179
|
+
const { output, exitCode } = getToolResult(toolCallObj, toolName);
|
|
180
|
+
target.output = output;
|
|
181
|
+
target.exitCode = exitCode;
|
|
182
|
+
state.pendingToolCalls.delete(callId);
|
|
183
|
+
}
|
|
184
|
+
function processToolCall(parsed, state) {
|
|
185
|
+
const subtype = parsed.subtype;
|
|
186
|
+
if (subtype === "started") {
|
|
187
|
+
processToolCallStarted(parsed, state);
|
|
188
|
+
}
|
|
189
|
+
else if (subtype === "completed") {
|
|
190
|
+
processToolCallCompleted(parsed, state);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function findLastAssistantTurnIndex(turns) {
|
|
194
|
+
for (let i = turns.length - 1; i >= 0; i--) {
|
|
195
|
+
if (turns[i]?.role === "assistant")
|
|
196
|
+
return i;
|
|
197
|
+
}
|
|
198
|
+
return -1;
|
|
199
|
+
}
|
|
200
|
+
function processLine(line, state) {
|
|
201
|
+
const trimmed = line.trim();
|
|
202
|
+
if (trimmed === "")
|
|
203
|
+
return;
|
|
204
|
+
let parsed;
|
|
205
|
+
try {
|
|
206
|
+
parsed = JSON.parse(trimmed);
|
|
207
|
+
}
|
|
208
|
+
catch {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
if (!isRecord(parsed))
|
|
212
|
+
return;
|
|
213
|
+
const type = parsed.type;
|
|
214
|
+
if (type === "system")
|
|
215
|
+
processSystemLine(parsed, state);
|
|
216
|
+
else if (type === "assistant")
|
|
217
|
+
processAssistantLine(parsed, state);
|
|
218
|
+
else if (type === "user")
|
|
219
|
+
processUserLine(parsed, state);
|
|
220
|
+
else if (type === "tool_call")
|
|
221
|
+
processToolCall(parsed, state);
|
|
222
|
+
else if (type === "result")
|
|
223
|
+
state.resultLine = parsed;
|
|
224
|
+
// "thinking" lines are completely discarded — NOT emitted as Turns.
|
|
225
|
+
}
|
|
226
|
+
function extractLastAssistantContent(turns) {
|
|
227
|
+
for (let i = turns.length - 1; i >= 0; i--) {
|
|
228
|
+
const turn = turns[i];
|
|
229
|
+
if (turn !== undefined &&
|
|
230
|
+
turn.role === "assistant" &&
|
|
231
|
+
turn.content !== "") {
|
|
232
|
+
return turn.content;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return "";
|
|
236
|
+
}
|
|
237
|
+
function coerceSubtype(raw) {
|
|
238
|
+
if (raw === "success")
|
|
239
|
+
return "success";
|
|
240
|
+
return "incomplete";
|
|
241
|
+
}
|
|
242
|
+
function assembleResult(state) {
|
|
243
|
+
if (state.resultLine === null) {
|
|
244
|
+
// Incomplete path — at minimum we need a session id.
|
|
245
|
+
if (state.sessionId === "")
|
|
246
|
+
return null;
|
|
247
|
+
return {
|
|
248
|
+
type: "result",
|
|
249
|
+
subtype: "incomplete",
|
|
250
|
+
result: extractLastAssistantContent(state.turns),
|
|
251
|
+
sessionId: state.sessionId,
|
|
252
|
+
numTurns: state.turns.length,
|
|
253
|
+
durationMs: 0,
|
|
254
|
+
model: state.model,
|
|
255
|
+
usage: {
|
|
256
|
+
inputTokens: 0,
|
|
257
|
+
outputTokens: 0,
|
|
258
|
+
cacheReadTokens: 0,
|
|
259
|
+
cacheWriteTokens: 0,
|
|
260
|
+
},
|
|
261
|
+
turns: state.turns,
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
const result = state.resultLine.result;
|
|
265
|
+
const usage = isRecord(state.resultLine.usage) ? state.resultLine.usage : {};
|
|
266
|
+
const sessionIdFromResult = typeof state.resultLine.session_id === "string"
|
|
267
|
+
? state.resultLine.session_id
|
|
268
|
+
: state.sessionId;
|
|
269
|
+
return {
|
|
270
|
+
type: typeof state.resultLine.type === "string"
|
|
271
|
+
? state.resultLine.type
|
|
272
|
+
: "result",
|
|
273
|
+
subtype: coerceSubtype(state.resultLine.subtype),
|
|
274
|
+
result: typeof result === "string"
|
|
275
|
+
? result
|
|
276
|
+
: extractLastAssistantContent(state.turns),
|
|
277
|
+
sessionId: sessionIdFromResult || state.sessionId,
|
|
278
|
+
numTurns: state.turns.length,
|
|
279
|
+
durationMs: safeNumber(state.resultLine.duration_ms),
|
|
280
|
+
model: state.model,
|
|
281
|
+
usage: {
|
|
282
|
+
inputTokens: safeNumber(usage.inputTokens),
|
|
283
|
+
outputTokens: safeNumber(usage.outputTokens),
|
|
284
|
+
cacheReadTokens: safeNumber(usage.cacheReadTokens),
|
|
285
|
+
cacheWriteTokens: safeNumber(usage.cacheWriteTokens),
|
|
286
|
+
},
|
|
287
|
+
turns: state.turns,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Parse cursor-agent stream-json (NDJSON) output into an ordered Turn[] plus
|
|
292
|
+
* a result summary.
|
|
293
|
+
*
|
|
294
|
+
* Behavior:
|
|
295
|
+
* - Pure: same input → same output (modulo the per-call `now()` timestamp).
|
|
296
|
+
* - Tolerant: malformed lines and lines without a recognized `type` are
|
|
297
|
+
* silently skipped.
|
|
298
|
+
* - Returns `null` when neither a `system` line (with session_id) NOR a
|
|
299
|
+
* `result` line was parsed — the adapter caller maps this to a hard error.
|
|
300
|
+
*
|
|
301
|
+
* @param stdout Raw NDJSON text (the full captured stdout of `cursor-agent -p`).
|
|
302
|
+
*/
|
|
303
|
+
export function parseStreamJson(stdout) {
|
|
304
|
+
const lines = stdout.split("\n");
|
|
305
|
+
const state = {
|
|
306
|
+
turns: [],
|
|
307
|
+
pendingToolCalls: new Map(),
|
|
308
|
+
resultLine: null,
|
|
309
|
+
model: "",
|
|
310
|
+
sessionId: "",
|
|
311
|
+
turnIndex: 0,
|
|
312
|
+
now: new Date().toISOString(),
|
|
313
|
+
};
|
|
314
|
+
for (const line of lines) {
|
|
315
|
+
processLine(line, state);
|
|
316
|
+
}
|
|
317
|
+
return assembleResult(state);
|
|
318
|
+
}
|
|
319
|
+
/**
|
|
320
|
+
* Incremental async-generator parser for cursor-agent NDJSON output.
|
|
321
|
+
*
|
|
322
|
+
* Yields `StreamParseEvent` as each line is consumed:
|
|
323
|
+
* - `{ type: "meta" }` after the first `system` line sets session + model.
|
|
324
|
+
* - `{ type: "turn" }` for each new Turn added (assistant, user, or
|
|
325
|
+
* assistant created by a `tool_call` started event).
|
|
326
|
+
* - `{ type: "result" }` when the `result` line is encountered.
|
|
327
|
+
*
|
|
328
|
+
* `tool_call` started events that MUTATE an existing turn's toolCalls array
|
|
329
|
+
* do NOT yield a new event (reference sharing). `tool_call` completed events
|
|
330
|
+
* fill in `ToolCall.output` on previously-yielded Turn objects — no new event.
|
|
331
|
+
*/
|
|
332
|
+
export async function* parseStreamJsonIncremental(lines) {
|
|
333
|
+
const state = {
|
|
334
|
+
turns: [],
|
|
335
|
+
pendingToolCalls: new Map(),
|
|
336
|
+
resultLine: null,
|
|
337
|
+
model: "",
|
|
338
|
+
sessionId: "",
|
|
339
|
+
turnIndex: 0,
|
|
340
|
+
now: new Date().toISOString(),
|
|
341
|
+
};
|
|
342
|
+
let metaYielded = false;
|
|
343
|
+
for await (const line of lines) {
|
|
344
|
+
const turnsBefore = state.turns.length;
|
|
345
|
+
const hadResult = state.resultLine !== null;
|
|
346
|
+
const hadSession = state.sessionId !== "";
|
|
347
|
+
processLine(line, state);
|
|
348
|
+
// Yield meta event once session info is available
|
|
349
|
+
if (!metaYielded && !hadSession && state.sessionId !== "") {
|
|
350
|
+
metaYielded = true;
|
|
351
|
+
yield { type: "meta", sessionId: state.sessionId, model: state.model };
|
|
352
|
+
}
|
|
353
|
+
// Yield new turns (only newly created turns, not mutated ones)
|
|
354
|
+
for (let i = turnsBefore; i < state.turns.length; i++) {
|
|
355
|
+
const turn = state.turns[i];
|
|
356
|
+
if (turn !== undefined) {
|
|
357
|
+
yield { type: "turn", turn };
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
// Yield result event
|
|
361
|
+
if (!hadResult && state.resultLine !== null) {
|
|
362
|
+
yield { type: "result", resultLine: state.resultLine };
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
//# sourceMappingURL=stream-parser.js.map
|
|
@@ -0,0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,EAAE,CAAC;QACxD,CAAC;IACF,CAAC;AACF,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `@sumeru/adapter-cursor-agent`.
|
|
3
|
+
*
|
|
4
|
+
* The adapter contract lives in `@sumeru/core` (`Adapter`, `NativeSessionRef`,
|
|
5
|
+
* `SendEvent`, `SessionConfig`, `Turn`, `ToolCall`, `TokenUsage`). This module
|
|
6
|
+
* only declares package-local options, the parser's intermediate shape, and the
|
|
7
|
+
* `child_process.spawn` test seam.
|
|
8
|
+
*/
|
|
9
|
+
import type { Turn } from "@sumeru/core";
|
|
10
|
+
/** Post-exit metadata from a streaming spawn. */
|
|
11
|
+
export type SpawnExitInfo = {
|
|
12
|
+
exitCode: number | null;
|
|
13
|
+
signal: NodeJS.Signals | null;
|
|
14
|
+
timedOut: boolean;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
stderr: string;
|
|
17
|
+
};
|
|
18
|
+
/** Return value of `StreamingSpawnFn` — lines + exit promise. */
|
|
19
|
+
export type SpawnStreamResult = {
|
|
20
|
+
lines: AsyncIterable<string>;
|
|
21
|
+
waitForExit(): Promise<SpawnExitInfo>;
|
|
22
|
+
};
|
|
23
|
+
/** Streaming spawn test seam — returns synchronously with incremental stdout access. */
|
|
24
|
+
export type StreamingSpawnFn = (args: SpawnArgs) => SpawnStreamResult;
|
|
25
|
+
/** Events yielded by the incremental stream parser. */
|
|
26
|
+
export type StreamParseEvent = {
|
|
27
|
+
type: "turn";
|
|
28
|
+
turn: Turn;
|
|
29
|
+
} | {
|
|
30
|
+
type: "meta";
|
|
31
|
+
sessionId: string;
|
|
32
|
+
model: string;
|
|
33
|
+
} | {
|
|
34
|
+
type: "result";
|
|
35
|
+
resultLine: Record<string, unknown>;
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Optional configuration for `createCursorAgentAdapter`. Every field accepts
|
|
39
|
+
* `null` (or absence) to fall through to the defaults — no optional `?:`
|
|
40
|
+
* properties on this surface.
|
|
41
|
+
*/
|
|
42
|
+
export type CursorAgentAdapterOptions = {
|
|
43
|
+
/** Path to the `cursor-agent` executable. Defaults to `"cursor-agent"` (rely on $PATH). */
|
|
44
|
+
cursorAgentBin: string | null;
|
|
45
|
+
/**
|
|
46
|
+
* `--model` value passed on every spawn. Defaults to `null`, which means
|
|
47
|
+
* the adapter does NOT pass `--model` and lets cursor-agent use its default.
|
|
48
|
+
*/
|
|
49
|
+
model: string | null;
|
|
50
|
+
/** Working directory for the spawned process. Passed as `--workspace <path>`. Defaults to `process.cwd()`. */
|
|
51
|
+
cwd: string | null;
|
|
52
|
+
/** Default 5-minute timeout for `createSession`. */
|
|
53
|
+
createSessionTimeoutMs: number | null;
|
|
54
|
+
/** Default 10-minute timeout for `send`. */
|
|
55
|
+
sendTimeoutMs: number | null;
|
|
56
|
+
/**
|
|
57
|
+
* Test-only override for `child_process.spawn`. Production code never
|
|
58
|
+
* passes this — the integration tests inject a fake to avoid spawning a
|
|
59
|
+
* real `cursor-agent` binary.
|
|
60
|
+
*/
|
|
61
|
+
spawnFn: SpawnFn | null;
|
|
62
|
+
/**
|
|
63
|
+
* Test-only override for the streaming spawn used in `send()`. Inject a
|
|
64
|
+
* mock to control line timing in tests without spawning a real process.
|
|
65
|
+
*/
|
|
66
|
+
streamingSpawnFn: StreamingSpawnFn | null;
|
|
67
|
+
/**
|
|
68
|
+
* Controls permission bypass flag.
|
|
69
|
+
* `"force"` passes `--force`, `"yolo"` passes `--yolo`.
|
|
70
|
+
* Defaults to `"force"`.
|
|
71
|
+
*/
|
|
72
|
+
permissionMode: "force" | "yolo" | null;
|
|
73
|
+
/** `--sandbox` value; defaults to `null` (do not pass flag). */
|
|
74
|
+
sandbox: "enabled" | "disabled" | null;
|
|
75
|
+
};
|
|
76
|
+
/** Argument shape mirroring `child_process.spawn` minus the irrelevant overloads. */
|
|
77
|
+
export type SpawnArgs = {
|
|
78
|
+
command: string;
|
|
79
|
+
args: string[];
|
|
80
|
+
timeoutMs: number;
|
|
81
|
+
cwd: string;
|
|
82
|
+
};
|
|
83
|
+
/** Result of a spawned `cursor-agent` invocation. */
|
|
84
|
+
export type SpawnResult = {
|
|
85
|
+
stdout: string;
|
|
86
|
+
stderr: string;
|
|
87
|
+
exitCode: number | null;
|
|
88
|
+
signal: NodeJS.Signals | null;
|
|
89
|
+
timedOut: boolean;
|
|
90
|
+
durationMs: number;
|
|
91
|
+
};
|
|
92
|
+
/** Test seam for `child_process.spawn`. */
|
|
93
|
+
export type SpawnFn = (args: SpawnArgs) => Promise<SpawnResult>;
|
|
94
|
+
/**
|
|
95
|
+
* Subtype of a parsed cursor-agent result — string-literal union.
|
|
96
|
+
* The `"incomplete"` variant is synthesized by the parser when no `result`
|
|
97
|
+
* line was emitted (process was killed or its stream truncated).
|
|
98
|
+
*/
|
|
99
|
+
export type CursorAgentResultSubtype = "success" | "incomplete";
|
|
100
|
+
/**
|
|
101
|
+
* Intermediate parsed result from cursor-agent's
|
|
102
|
+
* `--output-format stream-json` NDJSON output. The adapter consumes `turns`,
|
|
103
|
+
* `sessionId`, `subtype`, and `usage` directly.
|
|
104
|
+
*/
|
|
105
|
+
export type CursorAgentParsedResult = {
|
|
106
|
+
type: string;
|
|
107
|
+
subtype: CursorAgentResultSubtype;
|
|
108
|
+
result: string;
|
|
109
|
+
sessionId: string;
|
|
110
|
+
numTurns: number;
|
|
111
|
+
durationMs: number;
|
|
112
|
+
model: string;
|
|
113
|
+
usage: {
|
|
114
|
+
inputTokens: number;
|
|
115
|
+
outputTokens: number;
|
|
116
|
+
cacheReadTokens: number;
|
|
117
|
+
cacheWriteTokens: number;
|
|
118
|
+
};
|
|
119
|
+
turns: Turn[];
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;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QACrB,eAAe,EAAE,MAAM,CAAC;QACxB,gBAAgB,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,KAAK,EAAE,IAAI,EAAE,CAAC;CACd,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for `@sumeru/adapter-cursor-agent`.
|
|
3
|
+
*
|
|
4
|
+
* The adapter contract lives in `@sumeru/core` (`Adapter`, `NativeSessionRef`,
|
|
5
|
+
* `SendEvent`, `SessionConfig`, `Turn`, `ToolCall`, `TokenUsage`). This module
|
|
6
|
+
* only declares package-local options, the parser's intermediate shape, and the
|
|
7
|
+
* `child_process.spawn` test seam.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sumeru/adapter-cursor-agent",
|
|
3
|
+
"description": "Sumeru adapter for Cursor Agent CLI",
|
|
4
|
+
"version": "0.1.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"@sumeru/core": "0.1.0"
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc -b",
|
|
23
|
+
"test:ci": "npx vitest run"
|
|
24
|
+
}
|
|
25
|
+
}
|