@myrialabs/clopen 0.4.30 → 0.4.32
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/backend/auth/permissions.test.ts +0 -1
- package/backend/auth/permissions.ts +0 -4
- package/backend/chat/stream-manager.ts +28 -12
- package/backend/database/migrations/068_create_engine_config_revision.test.ts +121 -0
- package/backend/database/migrations/068_create_engine_config_revision.ts +117 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/engine/README.md +16 -0
- package/backend/engine/adapters/claude/stream.ts +89 -49
- package/backend/engine/adapters/cline/stream.ts +62 -24
- package/backend/engine/adapters/codex/stream.ts +51 -21
- package/backend/engine/adapters/copilot/stream.ts +96 -52
- package/backend/engine/adapters/cursor/stream.ts +74 -34
- package/backend/engine/adapters/opencode/server.ts +512 -126
- package/backend/engine/adapters/opencode/stream.ts +131 -79
- package/backend/engine/adapters/pi/stream.ts +63 -24
- package/backend/engine/adapters/qwen/stream.ts +91 -58
- package/backend/engine/adapters/run-registry.test.ts +75 -0
- package/backend/engine/adapters/run-registry.ts +63 -0
- package/backend/engine/bootstrap-default-engine.ts +67 -38
- package/backend/engine/config-revision.ts +150 -0
- package/backend/engine/docs/adapter-contract.md +40 -9
- package/backend/engine/docs/adding-an-engine.md +8 -0
- package/backend/engine/docs/frontend-and-chat.md +39 -0
- package/backend/engine/docs/lessons-learned.md +70 -0
- package/backend/engine/docs/quick-reference.md +3 -1
- package/backend/engine/engine-cli.ts +313 -0
- package/backend/engine/engine-setup.ts +40 -3
- package/backend/engine/hot-reload.ts +99 -0
- package/backend/engine/index.ts +96 -24
- package/backend/engine/install-recipes.test.ts +99 -5
- package/backend/engine/install-recipes.ts +47 -11
- package/backend/engine/install-runner.ts +34 -16
- package/backend/engine/stack-project.ts +72 -0
- package/backend/engine/types.ts +17 -5
- package/backend/git/git-executor.ts +22 -3
- package/backend/git/git-service.ts +1 -1
- package/backend/git/nested-repos.test.ts +121 -0
- package/backend/git/nested-repos.ts +301 -0
- package/backend/index.ts +7 -0
- package/backend/snapshot/gitignore.ts +10 -174
- package/backend/utils/path-enrich.ts +2 -0
- package/backend/ws/chat/stream.ts +24 -0
- package/backend/ws/engine/claude/accounts.ts +9 -4
- package/backend/ws/engine/codex/accounts.ts +8 -17
- package/backend/ws/engine/codex/status.ts +10 -17
- package/backend/ws/engine/copilot/accounts.ts +0 -10
- package/backend/ws/engine/cursor/accounts.ts +0 -10
- package/backend/ws/engine/index.ts +17 -2
- package/backend/ws/engine/opencode/providers.ts +0 -52
- package/backend/ws/files/read.ts +1 -1
- package/backend/ws/git/conflict.ts +1 -1
- package/backend/ws/git/diff.ts +1 -1
- package/backend/ws/git/staging.ts +1 -1
- package/backend/ws/git/status.ts +1 -1
- package/backend/ws/settings/crud.ts +1 -1
- package/backend/ws/stack/access.ts +5 -2
- package/dist/assets/{index-DYwQ5bP8.js → index-DSvGoxp2.js} +1 -1
- package/dist/assets/{index-DUc5T21e.js → index-hu17G6tX.js} +1 -1
- package/dist/assets/main-BccclZsC.js +1031 -0
- package/dist/assets/{main-VgdjTBLR.css → main-Ciuw0wF0.css} +1 -1
- package/dist/index.html +2 -2
- package/package.json +1 -1
- package/backend/ws/engine/restart.ts +0 -54
- package/dist/assets/main-r0iv2PDz.js +0 -1044
|
@@ -35,6 +35,7 @@ import { getCursorMcpConfig } from '../../../mcp';
|
|
|
35
35
|
import { subagentQueries } from '$backend/database/queries';
|
|
36
36
|
import { readSubagentMd } from '$backend/subagents/store';
|
|
37
37
|
import { buildJsonPrompt, extractJson } from '../../structured-helpers';
|
|
38
|
+
import { EngineRuns } from '../run-registry';
|
|
38
39
|
import { getActiveCursorAccount, resolveCursorApiKey } from './credential';
|
|
39
40
|
import { getCursorStore } from './environment';
|
|
40
41
|
import { forkCursorAgent } from './session-fork';
|
|
@@ -97,16 +98,28 @@ function buildCursorModelSelection(modelId: string, reasoningEffort?: string): M
|
|
|
97
98
|
return { id: modelId, params: [{ id: paramId, value }] };
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
/**
|
|
102
|
+
* One stream in flight on this instance. This engine instance is shared by every
|
|
103
|
+
* chat session of a project, so the run and agent belong here, not in instance
|
|
104
|
+
* fields — those would hold only the most recently started stream, and
|
|
105
|
+
* cancelling any chat would then cancel another chat's Cursor run.
|
|
106
|
+
*/
|
|
107
|
+
interface CursorRunState {
|
|
108
|
+
/** Identity of the run — the controller the caller passed to streamQuery. */
|
|
109
|
+
controller: AbortController;
|
|
110
|
+
run: Run | null;
|
|
111
|
+
agent: SDKAgent | null;
|
|
112
|
+
}
|
|
113
|
+
|
|
100
114
|
export class CursorEngine implements AIEngine {
|
|
101
115
|
readonly name = 'cursor' as const;
|
|
102
116
|
private _isInitialized = false;
|
|
103
|
-
private
|
|
104
|
-
|
|
105
|
-
private
|
|
106
|
-
private pendingAsks = new Map<string, PendingAsk>();
|
|
117
|
+
private runs = new EngineRuns<CursorRunState>();
|
|
118
|
+
/** Parked AskUserQuestion callbacks → the run that asked. */
|
|
119
|
+
private pendingAsks = new Map<string, PendingAsk & { owner: CursorRunState }>();
|
|
107
120
|
|
|
108
121
|
get isInitialized(): boolean { return this._isInitialized; }
|
|
109
|
-
get isActive(): boolean { return this.
|
|
122
|
+
get isActive(): boolean { return this.runs.isActive; }
|
|
110
123
|
|
|
111
124
|
async initialize(): Promise<void> {
|
|
112
125
|
if (this._isInitialized) return;
|
|
@@ -115,7 +128,7 @@ export class CursorEngine implements AIEngine {
|
|
|
115
128
|
}
|
|
116
129
|
|
|
117
130
|
async dispose(): Promise<void> {
|
|
118
|
-
await this.
|
|
131
|
+
await this.stopRuns(this.runs.all());
|
|
119
132
|
this.pendingAsks.clear();
|
|
120
133
|
this._isInitialized = false;
|
|
121
134
|
}
|
|
@@ -153,7 +166,9 @@ export class CursorEngine implements AIEngine {
|
|
|
153
166
|
}
|
|
154
167
|
const apiKey = resolveCursorApiKey(account);
|
|
155
168
|
|
|
156
|
-
|
|
169
|
+
const controller = abortController || new AbortController();
|
|
170
|
+
const runState: CursorRunState = { controller, run: null, agent: null };
|
|
171
|
+
this.runs.add(runState);
|
|
157
172
|
const resolvedProjectPath = resolveOsPath(projectPath);
|
|
158
173
|
|
|
159
174
|
// ── Active Profile scoping + artifact materialization ──
|
|
@@ -168,7 +183,7 @@ export class CursorEngine implements AIEngine {
|
|
|
168
183
|
|
|
169
184
|
// ── Tools: AskUserQuestion (in-process custom tool) + MCP (native config) ──
|
|
170
185
|
const askTool: SDKCustomTool = createAskUserQuestionTool({
|
|
171
|
-
register: (id, entry) => this.pendingAsks.set(id, entry),
|
|
186
|
+
register: (id, entry) => this.pendingAsks.set(id, { ...entry, owner: runState }),
|
|
172
187
|
unregister: (id) => this.pendingAsks.delete(id),
|
|
173
188
|
// Emit the tool_use with the COMPLETE questions from execute's args.
|
|
174
189
|
emit: (id, questions) => {
|
|
@@ -220,11 +235,11 @@ export class CursorEngine implements AIEngine {
|
|
|
220
235
|
...(agents ? { agents } : {}),
|
|
221
236
|
});
|
|
222
237
|
} catch (error) {
|
|
223
|
-
this.
|
|
238
|
+
this.runs.remove(runState);
|
|
224
239
|
handleStreamError(error);
|
|
225
240
|
return;
|
|
226
241
|
}
|
|
227
|
-
|
|
242
|
+
runState.agent = agent;
|
|
228
243
|
const sessionId = agent.agentId;
|
|
229
244
|
|
|
230
245
|
const converter = createCursorMessageConverter({ engine: engineMeta, sessionId });
|
|
@@ -260,11 +275,11 @@ export class CursorEngine implements AIEngine {
|
|
|
260
275
|
}
|
|
261
276
|
},
|
|
262
277
|
});
|
|
263
|
-
|
|
278
|
+
runState.run = run;
|
|
264
279
|
|
|
265
280
|
// Abort wiring: cancelling the stream cancels the Cursor run.
|
|
266
281
|
onAbort = () => { run.cancel().catch(() => { /* already terminal */ }); };
|
|
267
|
-
|
|
282
|
+
controller.signal.addEventListener('abort', onAbort, { once: true });
|
|
268
283
|
|
|
269
284
|
// Drive the pull stream + result in the background, funnelling into the queue.
|
|
270
285
|
const settle = (async () => {
|
|
@@ -287,38 +302,63 @@ export class CursorEngine implements AIEngine {
|
|
|
287
302
|
} catch (error) {
|
|
288
303
|
handleStreamError(error);
|
|
289
304
|
} finally {
|
|
290
|
-
if (onAbort)
|
|
305
|
+
if (onAbort) controller.signal.removeEventListener('abort', onAbort);
|
|
291
306
|
try { agent.close(); } catch { /* fire-and-forget */ }
|
|
292
|
-
|
|
293
|
-
this.
|
|
294
|
-
this.
|
|
295
|
-
this.pendingAsks.clear();
|
|
307
|
+
// Retire THIS run only — another chat session of the same project may
|
|
308
|
+
// still be streaming on this instance.
|
|
309
|
+
this.forgetRun(runState);
|
|
296
310
|
}
|
|
297
311
|
}
|
|
298
312
|
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
313
|
+
/** Drop a finished run and the asks only it could answer. */
|
|
314
|
+
private forgetRun(runState: CursorRunState): void {
|
|
315
|
+
this.runs.remove(runState);
|
|
316
|
+
for (const [id, pending] of this.pendingAsks) {
|
|
317
|
+
if (pending.owner === runState) this.pendingAsks.delete(id);
|
|
303
318
|
}
|
|
304
|
-
|
|
319
|
+
runState.run = null;
|
|
320
|
+
runState.agent = null;
|
|
321
|
+
}
|
|
305
322
|
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
this.
|
|
323
|
+
/**
|
|
324
|
+
* Cancel the run whose AbortController is `owner`, and only that run.
|
|
325
|
+
*/
|
|
326
|
+
async cancel(owner: AbortController): Promise<void> {
|
|
327
|
+
await this.stopRuns(this.runs.select(owner));
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* Tear down the given runs. `cancel` passes the one run it was asked to
|
|
332
|
+
* stop; `dispose` passes them all. Nothing else may reach this.
|
|
333
|
+
*/
|
|
334
|
+
private async stopRuns(targets: CursorRunState[]): Promise<void> {
|
|
335
|
+
for (const runState of targets) {
|
|
336
|
+
// Release the parked AskUserQuestion callbacks of THIS run so it can
|
|
337
|
+
// settle. Another run's parked ask is left alone — it is still live and
|
|
338
|
+
// still waiting for a real answer.
|
|
339
|
+
for (const [id, pending] of this.pendingAsks) {
|
|
340
|
+
if (pending.owner !== runState) continue;
|
|
341
|
+
pending.resolve('User did not answer the question.');
|
|
342
|
+
this.pendingAsks.delete(id);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
// Abort the local controller first (cuts the for-await loop), then RPC.
|
|
346
|
+
if (!runState.controller.signal.aborted) runState.controller.abort();
|
|
311
347
|
|
|
312
|
-
|
|
313
|
-
|
|
348
|
+
const run = runState.run;
|
|
349
|
+
this.forgetRun(runState);
|
|
350
|
+
if (run) {
|
|
351
|
+
try { await run.cancel(); } catch { /* may already be terminal */ }
|
|
352
|
+
}
|
|
314
353
|
}
|
|
315
|
-
this.activeRun = null;
|
|
316
|
-
this.activeAgent = null;
|
|
317
354
|
}
|
|
318
355
|
|
|
319
|
-
async interrupt(): Promise<void> {
|
|
320
|
-
|
|
321
|
-
|
|
356
|
+
async interrupt(owner: AbortController): Promise<void> {
|
|
357
|
+
const targets = this.runs.select(owner);
|
|
358
|
+
for (const runState of targets) {
|
|
359
|
+
if (runState.run) {
|
|
360
|
+
try { await runState.run.cancel(); } catch { /* ignore */ }
|
|
361
|
+
}
|
|
322
362
|
}
|
|
323
363
|
}
|
|
324
364
|
|