@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.
Files changed (64) hide show
  1. package/backend/auth/permissions.test.ts +0 -1
  2. package/backend/auth/permissions.ts +0 -4
  3. package/backend/chat/stream-manager.ts +28 -12
  4. package/backend/database/migrations/068_create_engine_config_revision.test.ts +121 -0
  5. package/backend/database/migrations/068_create_engine_config_revision.ts +117 -0
  6. package/backend/database/migrations/index.ts +7 -0
  7. package/backend/engine/README.md +16 -0
  8. package/backend/engine/adapters/claude/stream.ts +89 -49
  9. package/backend/engine/adapters/cline/stream.ts +62 -24
  10. package/backend/engine/adapters/codex/stream.ts +51 -21
  11. package/backend/engine/adapters/copilot/stream.ts +96 -52
  12. package/backend/engine/adapters/cursor/stream.ts +74 -34
  13. package/backend/engine/adapters/opencode/server.ts +512 -126
  14. package/backend/engine/adapters/opencode/stream.ts +131 -79
  15. package/backend/engine/adapters/pi/stream.ts +63 -24
  16. package/backend/engine/adapters/qwen/stream.ts +91 -58
  17. package/backend/engine/adapters/run-registry.test.ts +75 -0
  18. package/backend/engine/adapters/run-registry.ts +63 -0
  19. package/backend/engine/bootstrap-default-engine.ts +67 -38
  20. package/backend/engine/config-revision.ts +150 -0
  21. package/backend/engine/docs/adapter-contract.md +40 -9
  22. package/backend/engine/docs/adding-an-engine.md +8 -0
  23. package/backend/engine/docs/frontend-and-chat.md +39 -0
  24. package/backend/engine/docs/lessons-learned.md +70 -0
  25. package/backend/engine/docs/quick-reference.md +3 -1
  26. package/backend/engine/engine-cli.ts +313 -0
  27. package/backend/engine/engine-setup.ts +40 -3
  28. package/backend/engine/hot-reload.ts +99 -0
  29. package/backend/engine/index.ts +96 -24
  30. package/backend/engine/install-recipes.test.ts +99 -5
  31. package/backend/engine/install-recipes.ts +47 -11
  32. package/backend/engine/install-runner.ts +34 -16
  33. package/backend/engine/stack-project.ts +72 -0
  34. package/backend/engine/types.ts +17 -5
  35. package/backend/git/git-executor.ts +22 -3
  36. package/backend/git/git-service.ts +1 -1
  37. package/backend/git/nested-repos.test.ts +121 -0
  38. package/backend/git/nested-repos.ts +301 -0
  39. package/backend/index.ts +7 -0
  40. package/backend/snapshot/gitignore.ts +10 -174
  41. package/backend/utils/path-enrich.ts +2 -0
  42. package/backend/ws/chat/stream.ts +24 -0
  43. package/backend/ws/engine/claude/accounts.ts +9 -4
  44. package/backend/ws/engine/codex/accounts.ts +8 -17
  45. package/backend/ws/engine/codex/status.ts +10 -17
  46. package/backend/ws/engine/copilot/accounts.ts +0 -10
  47. package/backend/ws/engine/cursor/accounts.ts +0 -10
  48. package/backend/ws/engine/index.ts +17 -2
  49. package/backend/ws/engine/opencode/providers.ts +0 -52
  50. package/backend/ws/files/read.ts +1 -1
  51. package/backend/ws/git/conflict.ts +1 -1
  52. package/backend/ws/git/diff.ts +1 -1
  53. package/backend/ws/git/staging.ts +1 -1
  54. package/backend/ws/git/status.ts +1 -1
  55. package/backend/ws/settings/crud.ts +1 -1
  56. package/backend/ws/stack/access.ts +5 -2
  57. package/dist/assets/{index-DYwQ5bP8.js → index-DSvGoxp2.js} +1 -1
  58. package/dist/assets/{index-DUc5T21e.js → index-hu17G6tX.js} +1 -1
  59. package/dist/assets/main-BccclZsC.js +1031 -0
  60. package/dist/assets/{main-VgdjTBLR.css → main-Ciuw0wF0.css} +1 -1
  61. package/dist/index.html +2 -2
  62. package/package.json +1 -1
  63. package/backend/ws/engine/restart.ts +0 -54
  64. package/dist/assets/main-r0iv2PDz.js +0 -1044
@@ -253,6 +253,7 @@ export const streamHandler = createRouter()
253
253
  const stream = streamManager.getStream(streamId);
254
254
  if (stream) {
255
255
  ws.emit.chatSession(data.chatSessionId, 'chat:connection', {
256
+ chatSessionId: data.chatSessionId,
256
257
  processId: stream.processId,
257
258
  timestamp: stream.startedAt.toISOString(),
258
259
  seq: 1
@@ -273,6 +274,7 @@ export const streamHandler = createRouter()
273
274
  switch (event.type) {
274
275
  case 'connection':
275
276
  ws.emit.chatSession(chatSessionId, 'chat:connection', {
277
+ chatSessionId,
276
278
  processId: event.data.processId,
277
279
  timestamp: event.data.timestamp,
278
280
  seq: event.seq
@@ -284,6 +286,7 @@ export const streamHandler = createRouter()
284
286
 
285
287
  case 'message': {
286
288
  ws.emit.chatSession(chatSessionId, 'chat:message', {
289
+ chatSessionId,
287
290
  processId: event.processId,
288
291
  message: trimSubAgentForWire(event.data.message),
289
292
  usage: event.data.usage,
@@ -302,6 +305,7 @@ export const streamHandler = createRouter()
302
305
 
303
306
  case 'partial':
304
307
  ws.emit.chatSession(chatSessionId, 'chat:partial', {
308
+ chatSessionId,
305
309
  processId: event.processId,
306
310
  eventType: event.data.eventType as any,
307
311
  partialText: event.data.partialText || '',
@@ -336,6 +340,7 @@ export const streamHandler = createRouter()
336
340
 
337
341
  case 'complete':
338
342
  ws.emit.chatSession(chatSessionId, 'chat:complete', {
343
+ chatSessionId,
339
344
  processId: event.processId,
340
345
  timestamp: event.data.timestamp,
341
346
  seq: event.seq
@@ -347,6 +352,7 @@ export const streamHandler = createRouter()
347
352
 
348
353
  case 'error':
349
354
  ws.emit.chatSession(chatSessionId, 'chat:error', {
355
+ chatSessionId,
350
356
  processId: event.processId,
351
357
  error: event.data.error,
352
358
  timestamp: event.data.timestamp,
@@ -358,6 +364,7 @@ export const streamHandler = createRouter()
358
364
 
359
365
  case 'cancelled':
360
366
  ws.emit.chatSession(chatSessionId, 'chat:error', {
367
+ chatSessionId,
361
368
  processId: event.processId,
362
369
  error: 'Stream cancelled',
363
370
  timestamp: event.data.timestamp,
@@ -387,6 +394,7 @@ export const streamHandler = createRouter()
387
394
  debug.error('chat', 'WS chat:stream error:', errorMessage);
388
395
 
389
396
  ws.emit.chatSession(data.chatSessionId, 'chat:error', {
397
+ chatSessionId: data.chatSessionId,
390
398
  processId: crypto.randomUUID(),
391
399
  error: errorMessage,
392
400
  timestamp: new Date().toISOString()
@@ -420,6 +428,7 @@ export const streamHandler = createRouter()
420
428
  switch (event.type) {
421
429
  case 'connection':
422
430
  ws.emit.chatSession(chatSessionId, 'chat:connection', {
431
+ chatSessionId,
423
432
  processId: event.data.processId,
424
433
  timestamp: event.data.timestamp,
425
434
  seq: event.seq
@@ -428,6 +437,7 @@ export const streamHandler = createRouter()
428
437
 
429
438
  case 'message': {
430
439
  ws.emit.chatSession(chatSessionId, 'chat:message', {
440
+ chatSessionId,
431
441
  processId: event.processId,
432
442
  message: trimSubAgentForWire(event.data.message),
433
443
  usage: event.data.usage,
@@ -446,6 +456,7 @@ export const streamHandler = createRouter()
446
456
 
447
457
  case 'partial':
448
458
  ws.emit.chatSession(chatSessionId, 'chat:partial', {
459
+ chatSessionId,
449
460
  processId: event.processId,
450
461
  eventType: event.data.eventType as any,
451
462
  partialText: event.data.partialText || '',
@@ -480,6 +491,7 @@ export const streamHandler = createRouter()
480
491
 
481
492
  case 'complete':
482
493
  ws.emit.chatSession(chatSessionId, 'chat:complete', {
494
+ chatSessionId,
483
495
  processId: event.processId,
484
496
  timestamp: event.data.timestamp,
485
497
  seq: event.seq
@@ -490,6 +502,7 @@ export const streamHandler = createRouter()
490
502
 
491
503
  case 'error':
492
504
  ws.emit.chatSession(chatSessionId, 'chat:error', {
505
+ chatSessionId,
493
506
  processId: event.processId,
494
507
  error: event.data.error,
495
508
  timestamp: event.data.timestamp,
@@ -501,6 +514,7 @@ export const streamHandler = createRouter()
501
514
 
502
515
  case 'cancelled':
503
516
  ws.emit.chatSession(chatSessionId, 'chat:error', {
517
+ chatSessionId,
504
518
  processId: event.processId,
505
519
  error: 'Stream cancelled',
506
520
  timestamp: event.data.timestamp,
@@ -523,6 +537,7 @@ export const streamHandler = createRouter()
523
537
 
524
538
  // Send current state snapshot to chat session room so frontend can catch up
525
539
  ws.emit.chatSession(chatSessionId, 'chat:connection', {
540
+ chatSessionId,
526
541
  processId: streamState.processId,
527
542
  timestamp: streamState.startedAt.toISOString(),
528
543
  seq: streamState.eventSeq
@@ -657,6 +672,7 @@ export const streamHandler = createRouter()
657
672
  // Stream not found - could already be completed/cleaned up
658
673
  // Send cancellation to chat session room so frontend stops loading
659
674
  ws.emit.chatSession(chatSessionId, 'chat:cancelled', {
675
+ chatSessionId,
660
676
  status: 'cancelled',
661
677
  processId: ''
662
678
  });
@@ -669,6 +685,7 @@ export const streamHandler = createRouter()
669
685
  await streamManager.cancelStream(streamState.streamId);
670
686
  // Always send cancelled to chat session room to clear UI
671
687
  ws.emit.chatSession(chatSessionId, 'chat:cancelled', {
688
+ chatSessionId,
672
689
  status: 'cancelled',
673
690
  processId: streamState.processId
674
691
  });
@@ -679,6 +696,7 @@ export const streamHandler = createRouter()
679
696
  } catch (error) {
680
697
  const errorMessage = error instanceof Error ? error.message : 'Unknown error';
681
698
  ws.emit.chatSession(chatSessionId, 'chat:error', {
699
+ chatSessionId,
682
700
  processId: '',
683
701
  error: errorMessage,
684
702
  timestamp: new Date().toISOString()
@@ -966,12 +984,14 @@ export const streamHandler = createRouter()
966
984
  }))
967
985
 
968
986
  .emit('chat:connection', t.Object({
987
+ chatSessionId: t.String(),
969
988
  processId: t.String(),
970
989
  timestamp: t.String(),
971
990
  seq: t.Optional(t.Number())
972
991
  }))
973
992
 
974
993
  .emit('chat:message', t.Object({
994
+ chatSessionId: t.String(),
975
995
  processId: t.String(),
976
996
  message: t.Any(), // SDKMessage
977
997
  usage: t.Optional(t.Any()),
@@ -985,6 +1005,7 @@ export const streamHandler = createRouter()
985
1005
  }))
986
1006
 
987
1007
  .emit('chat:partial', t.Object({
1008
+ chatSessionId: t.String(),
988
1009
  processId: t.String(),
989
1010
  eventType: t.Union([
990
1011
  t.Literal('start'),
@@ -1030,12 +1051,14 @@ export const streamHandler = createRouter()
1030
1051
  }))
1031
1052
 
1032
1053
  .emit('chat:complete', t.Object({
1054
+ chatSessionId: t.String(),
1033
1055
  processId: t.String(),
1034
1056
  timestamp: t.String(),
1035
1057
  seq: t.Optional(t.Number())
1036
1058
  }))
1037
1059
 
1038
1060
  .emit('chat:error', t.Object({
1061
+ chatSessionId: t.String(),
1039
1062
  processId: t.String(),
1040
1063
  error: t.String(),
1041
1064
  timestamp: t.String(),
@@ -1043,6 +1066,7 @@ export const streamHandler = createRouter()
1043
1066
  }))
1044
1067
 
1045
1068
  .emit('chat:cancelled', t.Object({
1069
+ chatSessionId: t.String(),
1046
1070
  status: t.Literal('cancelled'),
1047
1071
  processId: t.Optional(t.String()),
1048
1072
  seq: t.Optional(t.Number())
@@ -19,7 +19,7 @@ import { createRouter } from '$shared/utils/ws-server';
19
19
  import { ws } from '$backend/utils/ws';
20
20
  import { engineQueries } from '../../../database/queries';
21
21
  import { resetEnvironment, getClaudeUserConfigDir } from '../../../engine/adapters/claude/environment';
22
- import { resolveBinaryWithRefresh } from '../../../utils/cli';
22
+ import { resolveEngineCli } from '$backend/engine/engine-cli';
23
23
  import { debug } from '$shared/utils/logger';
24
24
  import { getCleanSpawnEnv } from '../../../utils/env';
25
25
  import { requireSetupSessionAccess } from '../access';
@@ -209,11 +209,16 @@ export const accountsHandler = createRouter()
209
209
  ptyEnv['CLAUDE_CONFIG_DIR'] = getClaudeUserConfigDir();
210
210
  ptyEnv['BROWSER'] = 'false';
211
211
 
212
- const claudeCmd = await resolveBinaryWithRefresh('claude');
213
- if (!claudeCmd) throw new Error('claude binary not found on PATH');
212
+ // The CLI ships inside the Claude Agent SDK's platform package in the
213
+ // managed stack dir, so sign-in must not demand a global install the way
214
+ // it used to — `resolveEngineCli` prefers that copy and falls back to PATH.
215
+ const claudeCli = await resolveEngineCli('claude');
216
+ if (!claudeCli) {
217
+ throw new Error('Claude Code CLI not found. Open Settings → Stack to install the engine.');
218
+ }
214
219
  let pty: ReturnType<typeof spawn>;
215
220
  try {
216
- pty = spawn(claudeCmd, ['setup-token'], {
221
+ pty = spawn(claudeCli.path, ['setup-token'], {
217
222
  name: 'xterm-256color',
218
223
  cols: 1000,
219
224
  rows: 30,
@@ -48,7 +48,7 @@ import {
48
48
  serializeCodexCredential,
49
49
  getCodexHomeDir,
50
50
  } from '../../../engine/adapters/codex/credential';
51
- import { resolveBinaryWithRefresh } from '../../../utils/cli';
51
+ import { resolveEngineCli } from '$backend/engine/engine-cli';
52
52
  import { getCleanSpawnEnv } from '../../../utils/env';
53
53
  import { debug } from '$shared/utils/logger';
54
54
  import { requireSetupSessionAccess } from '../access';
@@ -328,11 +328,14 @@ export const codexAccountsHandler = createRouter()
328
328
  const existing = userSetups.get(userId);
329
329
  if (existing) cleanupSetup(existing);
330
330
 
331
- const codexCmd = await resolveBinaryWithRefresh('codex');
332
- if (!codexCmd) {
331
+ // The CLI is vendored inside the Codex SDK's platform package in the
332
+ // managed stack dir; resolving through `resolveEngineCli` means sign-in
333
+ // works off a Stack install instead of demanding a global one.
334
+ const codexCli = await resolveEngineCli('codex');
335
+ if (!codexCli) {
333
336
  ws.emit.user(userId, 'engine:codex-account-setup-error', {
334
337
  setupId,
335
- message: 'Codex CLI not found on PATH. Install it via Settings → Stack.'
338
+ message: 'Codex CLI not found. Install the engine via Settings → Stack.'
336
339
  });
337
340
  return;
338
341
  }
@@ -352,7 +355,7 @@ export const codexAccountsHandler = createRouter()
352
355
 
353
356
  let pty: ReturnType<typeof spawn>;
354
357
  try {
355
- pty = spawn(codexCmd, args, {
358
+ pty = spawn(codexCli.path, args, {
356
359
  name: 'xterm-256color',
357
360
  cols: 1000,
358
361
  rows: 30,
@@ -501,18 +504,6 @@ export const codexAccountsHandler = createRouter()
501
504
  cleanupSetup(data.setupId);
502
505
  })
503
506
 
504
- // Restart all Codex engine instances. Use after changing the active
505
- // account so subsequent models:list / chat calls re-initialise with the
506
- // right credential. (The auth-blob swap on accounts-switch already
507
- // handles the on-disk file; this just drops cached engine instances.)
508
- .http('engine:codex-restart', {
509
- data: t.Object({}),
510
- response: t.Object({ success: t.Boolean() })
511
- }, async () => {
512
- await disposeCodexEngines();
513
- return { success: true };
514
- })
515
-
516
507
  // ─── Server → client events ───
517
508
 
518
509
  .emit('engine:codex-account-setup-url', t.Object({
@@ -1,33 +1,26 @@
1
1
  /**
2
2
  * OpenAI Codex Engine Status Handler
3
3
  *
4
- * Reports SDK availability + active account state. Codex differs from
5
- * Copilot in that the SDK does NOT bundle a CLI internally — the CLI must
6
- * be installed on PATH (Stack → Codex CLI). `installed` reflects
7
- * whether the `codex` binary resolves on the host's PATH.
4
+ * Reports SDK availability + active account state. `installed` tracks the SDK;
5
+ * `version` is the CLI's, since that is the process Codex actually runs. That
6
+ * binary is vendored inside the SDK's platform package in the managed stack dir
7
+ * (or comes from PATH when the user installed Codex themselves) — reading it
8
+ * off PATH alone left the version blank on a Stack-only install.
8
9
  */
9
10
 
10
11
  import { t } from 'elysia';
11
12
  import { createRouter } from '$shared/utils/ws-server';
12
13
  import { engineQueries } from '../../../database/queries';
13
- import { resolveBinaryWithRefresh } from '../../../utils/cli';
14
+ import { resolveEngineCli } from '$backend/engine/engine-cli';
14
15
  import { getBackendOS } from '../../../utils/os';
15
16
  import { debug } from '$shared/utils/logger';
16
17
  import { readEngineSdkVersion } from '$backend/engine/sdk-loader';
17
18
 
18
19
  async function readCliVersion(): Promise<string | null> {
19
- const bin = await resolveBinaryWithRefresh('codex');
20
- if (!bin) return null;
21
- try {
22
- const proc = Bun.spawn([bin, '--version'], { stdout: 'pipe', stderr: 'pipe' });
23
- const exitCode = await proc.exited;
24
- if (exitCode !== 0) return null;
25
- const stdout = await new Response(proc.stdout).text();
26
- const first = stdout.trim().split('\n')[0]?.trim() ?? '';
27
- return first || null;
28
- } catch {
29
- return null;
30
- }
20
+ // `resolveEngineCli` already ran `--version` on the binary it handed back,
21
+ // so the version comes for free with the resolution.
22
+ const cli = await resolveEngineCli('codex');
23
+ return cli?.version ?? null;
31
24
  }
32
25
 
33
26
  export const codexStatusHandler = createRouter()
@@ -121,14 +121,4 @@ export const copilotAccountsHandler = createRouter()
121
121
  const active = engineQueries.getActiveAccountForEngine('copilot');
122
122
  if (active?.id === data.id) await disposeCopilotEngines();
123
123
  return { success: true };
124
- })
125
-
126
- // Restart all Copilot engine instances. Use after changing the active token
127
- // so subsequent models:list / chat calls re-initialise with fresh credentials.
128
- .http('engine:copilot-restart', {
129
- data: t.Object({}),
130
- response: t.Object({ success: t.Boolean() })
131
- }, async () => {
132
- await disposeCopilotEngines();
133
- return { success: true };
134
124
  });
@@ -150,14 +150,4 @@ export const cursorAccountsHandler = createRouter()
150
150
  const active = engineQueries.getActiveAccountForEngine('cursor');
151
151
  if (active?.id === data.id) await disposeCursorEngines();
152
152
  return { success: true };
153
- })
154
-
155
- // Restart all Cursor engine instances so subsequent models:list / chat calls
156
- // re-initialise with fresh credentials.
157
- .http('engine:cursor-restart', {
158
- data: t.Object({}),
159
- response: t.Object({ success: t.Boolean() })
160
- }, async () => {
161
- await disposeCursorEngines();
162
- return { success: true };
163
153
  });
@@ -5,6 +5,7 @@
5
5
  * Merges Claude Code and Open Code engine routers.
6
6
  */
7
7
 
8
+ import { t } from 'elysia';
8
9
  import { createRouter } from '$shared/utils/ws-server';
9
10
  import { claudeCodeEngineRouter } from './claude';
10
11
  import { openCodeEngineRouter } from './opencode';
@@ -14,7 +15,6 @@ import { qwenEngineRouter } from './qwen';
14
15
  import { piEngineRouter } from './pi';
15
16
  import { clineEngineRouter } from './cline';
16
17
  import { cursorEngineRouter } from './cursor';
17
- import { engineRestartRouter } from './restart';
18
18
 
19
19
  export const engineRouter = createRouter()
20
20
  .merge(claudeCodeEngineRouter)
@@ -25,4 +25,19 @@ export const engineRouter = createRouter()
25
25
  .merge(piEngineRouter)
26
26
  .merge(clineEngineRouter)
27
27
  .merge(cursorEngineRouter)
28
- .merge(engineRestartRouter);
28
+
29
+ // ─── Server → client events ───
30
+
31
+ /**
32
+ * Engine-affecting config changed and has been applied.
33
+ *
34
+ * A doorbell, not a delivery: it carries the revision and nothing else, and
35
+ * clients refetch over the routes they already use. This is the one piece of
36
+ * the removed "Restart Server" button that had to survive — the button's
37
+ * success path also refreshed the model list, and without an announcement a
38
+ * newly added provider would sit invisible in the picker until something else
39
+ * happened to trigger a refetch.
40
+ */
41
+ .emit('engine:config-changed', t.Object({
42
+ revision: t.Number()
43
+ }));
@@ -11,9 +11,6 @@ import {
11
11
  fetchAndCacheModelsDevCatalog,
12
12
  getCachedModelsDevCatalog,
13
13
  } from '../../../engine/adapters/opencode/presets';
14
- import { disposeOpenCodeClient } from '../../../engine/adapters/opencode/server';
15
- import { disposeEngine } from '../../../engine';
16
- import { streamManager } from '../../../chat';
17
14
  import { debug } from '$shared/utils/logger';
18
15
 
19
16
  // Shared typebox schemas
@@ -319,53 +316,4 @@ export const openCodeProviderHandler = createRouter()
319
316
  const body = await res.json() as { data?: { id: string; name?: string }[] };
320
317
  const models = (body.data || []).map(m => ({ id: m.id, name: m.name }));
321
318
  return { models };
322
- })
323
-
324
- // ═══════════════════════════════════════
325
- // Server Restart
326
- // ═══════════════════════════════════════
327
-
328
- .http('engine:opencode-server-restart', {
329
- data: t.Object({
330
- force: t.Optional(t.Boolean()),
331
- }),
332
- response: t.Object({
333
- success: t.Boolean(),
334
- activeChats: t.Optional(t.Number()),
335
- needsConfirmation: t.Optional(t.Boolean()),
336
- })
337
- }, async ({ data }) => {
338
- // Check for active opencode streams
339
- const activeStreams = streamManager.getActiveStreams()
340
- .filter(s => s.engine === 'opencode');
341
-
342
- if (activeStreams.length > 0 && !data.force) {
343
- return {
344
- success: false,
345
- activeChats: activeStreams.length,
346
- needsConfirmation: true,
347
- };
348
- }
349
-
350
- // Force: abort all active opencode streams first
351
- if (activeStreams.length > 0) {
352
- debug.log('engine', `Force-aborting ${activeStreams.length} active OpenCode streams before restart`);
353
- for (const stream of activeStreams) {
354
- try {
355
- await streamManager.cancelStream(stream.streamId);
356
- } catch (error) {
357
- debug.warn('engine', `Failed to abort stream ${stream.streamId}:`, error);
358
- }
359
- }
360
- }
361
-
362
- // Dispose global opencode engine + shared client/server.
363
- // forRestart=true ensures the server is killed even if we didn't
364
- // spawn it, and the stored URL is purged so next init() spawns fresh.
365
- await disposeEngine('opencode');
366
- await disposeOpenCodeClient(true);
367
-
368
- debug.log('engine', 'OpenCode server disposed. Will re-initialize on next use.');
369
-
370
- return { success: true };
371
319
  });
@@ -19,7 +19,7 @@ import {
19
19
  } from '../../files/file-reading';
20
20
  import { handlePathBrowsing } from '../../files/path-browsing';
21
21
  import { gitService } from '../../git/git-service';
22
- import { findRepoForFile } from '../../snapshot/gitignore';
22
+ import { findRepoForFile } from '../../git/nested-repos';
23
23
  import { projectQueries } from '../../database/queries/project-queries';
24
24
  import { isAbsolute, relative } from 'node:path';
25
25
  import { requireProjectAccess } from '../access';
@@ -6,7 +6,7 @@ import { t } from 'elysia';
6
6
  import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
- import { findNestedRepoPaths, findRepoForFile } from '../../snapshot/gitignore';
9
+ import { findNestedRepoPaths, findRepoForFile } from '../../git/nested-repos';
10
10
  import { requireProjectAccess } from '../access';
11
11
  import { debug } from '$shared/utils/logger';
12
12
 
@@ -6,7 +6,7 @@ import { t } from 'elysia';
6
6
  import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
- import { findRepoForFile } from '../../snapshot/gitignore';
9
+ import { findRepoForFile } from '../../git/nested-repos';
10
10
  import { requireProjectAccess } from '../access';
11
11
  import { debug } from '$shared/utils/logger';
12
12
 
@@ -6,7 +6,7 @@ import { t } from 'elysia';
6
6
  import path from 'node:path';
7
7
  import { createRouter } from '$shared/utils/ws-server';
8
8
  import { gitService } from '../../git/git-service';
9
- import { findRepoForFile } from '../../snapshot/gitignore';
9
+ import { findRepoForFile } from '../../git/nested-repos';
10
10
  import { requireProjectAccess } from '../access';
11
11
  import { debug } from '$shared/utils/logger';
12
12
 
@@ -5,7 +5,7 @@
5
5
  import { t } from 'elysia';
6
6
  import { createRouter } from '$shared/utils/ws-server';
7
7
  import { gitService } from '../../git/git-service';
8
- import { findNestedRepoPaths } from '../../snapshot/gitignore';
8
+ import { findNestedRepoPaths } from '../../git/nested-repos';
9
9
  import { requireProjectAccess } from '../access';
10
10
  import { relative as pathRelative } from 'path';
11
11
 
@@ -133,7 +133,7 @@ export const crudHandler = createRouter()
133
133
  // account and has none (→ Engines). Mirrors the chat pre-stream gate so
134
134
  // the model picker reflects the same install/sign-in state as chat.
135
135
  const activeAccount = engineQueries.getActiveAccountForEngine(engineType);
136
- const setupIssue = checkEngineSetup(engineType, activeAccount?.id ?? 0);
136
+ const setupIssue = await checkEngineSetup(engineType, activeAccount?.id ?? 0);
137
137
  if (setupIssue) throw new Error(setupIssue.message);
138
138
 
139
139
  // Uniform path for every engine. Each adapter's getAvailableModels()
@@ -9,7 +9,7 @@
9
9
 
10
10
  import type { WSConnection } from '$shared/utils/ws-server';
11
11
  import { ws } from '$backend/utils/ws';
12
- import { getSession, getSessionOwner } from '$backend/engine/install-runner';
12
+ import { getSession, getSessionOwner, SYSTEM_INSTALL_USER } from '$backend/engine/install-runner';
13
13
 
14
14
  type InstallSession = NonNullable<ReturnType<typeof getSession>>;
15
15
 
@@ -21,7 +21,10 @@ type InstallSession = NonNullable<ReturnType<typeof getSession>>;
21
21
  export function requireInstallSessionAccess(conn: WSConnection, sessionId: string): InstallSession | null {
22
22
  const userId = ws.getUserId(conn);
23
23
  const owner = getSessionOwner(sessionId);
24
- if (owner && owner !== userId) {
24
+ // Installs clopen starts itself belong to no user; any admin reaching this
25
+ // guard may watch or cancel them, otherwise a startup repair would show up
26
+ // in Settings → Stack as a running session nobody is allowed to touch.
27
+ if (owner && owner !== SYSTEM_INSTALL_USER && owner !== userId) {
25
28
  throw new Error('Install session not found');
26
29
  }
27
30
  return getSession(sessionId);
@@ -1 +1 @@
1
- import{s as _,_ as d,r as s,a as u}from"./main-r0iv2PDz.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-r0iv2PDz.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};
1
+ import{s as _,_ as d,r as s,a as u}from"./main-BccclZsC.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-BccclZsC.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};