@myrialabs/clopen 0.3.9 → 0.3.11

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 (48) hide show
  1. package/README.md +22 -19
  2. package/backend/auth/auth-service.ts +56 -1
  3. package/backend/auth/permissions.test.ts +30 -0
  4. package/backend/auth/permissions.ts +28 -1
  5. package/backend/auth/session-cleanup.ts +58 -0
  6. package/backend/chat/stream-manager.ts +72 -13
  7. package/backend/db-client/connection-manager.ts +9 -3
  8. package/backend/engine/adapters/codex/error-handler.ts +2 -2
  9. package/backend/engine/adapters/codex/stream.ts +12 -8
  10. package/backend/engine/adapters/copilot/stream.ts +5 -8
  11. package/backend/engine/adapters/opencode/presets.ts +1 -1
  12. package/backend/engine/adapters/opencode/stream.ts +5 -1
  13. package/backend/engine/adapters/qwen/stream.ts +1 -2
  14. package/backend/files/path-browsing.ts +20 -0
  15. package/backend/git/git-service.ts +81 -11
  16. package/backend/git/git-spawn-validation.test.ts +75 -0
  17. package/backend/git/git-spawn-validation.ts +77 -0
  18. package/backend/index.ts +5 -0
  19. package/backend/preview/browser/browser-tab-manager.ts +23 -3
  20. package/backend/snapshot/gitignore.ts +4 -9
  21. package/backend/tunnel/cloudflared/binary.ts +2 -2
  22. package/backend/tunnel/global-tunnel-manager.ts +9 -3
  23. package/backend/utils/ws.ts +5 -1
  24. package/backend/ws/access.ts +5 -5
  25. package/backend/ws/auth/index.ts +14 -0
  26. package/backend/ws/auth/login.ts +3 -0
  27. package/backend/ws/auth/users.ts +61 -1
  28. package/backend/ws/chat/stream.ts +103 -10
  29. package/backend/ws/db-client/query.ts +3 -1
  30. package/backend/ws/files/path-access.ts +101 -0
  31. package/backend/ws/files/read.ts +35 -12
  32. package/backend/ws/files/search.ts +10 -6
  33. package/backend/ws/files/watch.ts +1 -1
  34. package/backend/ws/files/write.ts +109 -15
  35. package/backend/ws/preview/browser/console.ts +2 -2
  36. package/backend/ws/projects/crud.ts +15 -7
  37. package/backend/ws/projects/status.ts +3 -1
  38. package/backend/ws/sessions/crud.ts +10 -4
  39. package/backend/ws/terminal/access.ts +3 -3
  40. package/backend/ws/terminal/persistence.ts +1 -1
  41. package/backend/ws/terminal/session.ts +2 -2
  42. package/dist/assets/{index-D8V2wj9B.js → index-DmghE6mf.js} +2 -2
  43. package/dist/assets/main-DiDuzJJh.js +318 -0
  44. package/dist/assets/main-N1w7Llvp.css +1 -0
  45. package/dist/index.html +2 -2
  46. package/package.json +2 -1
  47. package/dist/assets/main-C9nYVmnw.js +0 -312
  48. package/dist/assets/main-hspyFOoK.css +0 -1
@@ -23,6 +23,9 @@ import {
23
23
  uploadFileOperation,
24
24
  deleteOperation
25
25
  } from '../../files/file-operations';
26
+ import { join } from 'node:path';
27
+ import { stat as fsStat, readdir as fsReaddir, rename as fsRename, access as fsAccess } from 'node:fs/promises';
28
+ import { requireFilePathAccess, requireSharedFilePathAccess } from './path-access';
26
29
 
27
30
  export const writeHandler = createRouter()
28
31
  // Write file operation
@@ -36,12 +39,13 @@ export const writeHandler = createRouter()
36
39
  size: t.Number(),
37
40
  modified: t.String()
38
41
  })
39
- }, async ({ data }) => {
42
+ }, async ({ data, conn }) => {
43
+ const filePath = requireFilePathAccess(conn, data.filePath);
40
44
  debug.log('file', 'Write file operation:', {
41
- filePath: data.filePath,
45
+ filePath,
42
46
  contentLength: data.content.length
43
47
  });
44
- return await writeFileOperation(data.filePath, data.content);
48
+ return await writeFileOperation(filePath, data.content);
45
49
  })
46
50
 
47
51
  // Create file operation
@@ -56,8 +60,9 @@ export const writeHandler = createRouter()
56
60
  size: t.Number(),
57
61
  modified: t.String()
58
62
  })
59
- }, async ({ data }) => {
60
- return await createFileOperation(data.filePath, data.content);
63
+ }, async ({ data, conn }) => {
64
+ const filePath = requireFilePathAccess(conn, data.filePath);
65
+ return await createFileOperation(filePath, data.content);
61
66
  })
62
67
 
63
68
  // Create directory operation
@@ -70,8 +75,12 @@ export const writeHandler = createRouter()
70
75
  path: t.String(),
71
76
  modified: t.String()
72
77
  })
73
- }, async ({ data }) => {
74
- return await createDirectoryOperation(data.dirPath);
78
+ }, async ({ data, conn }) => {
79
+ // Uses the shared guard so FolderBrowser can create candidate project
80
+ // folders outside any existing project, while still preventing writes
81
+ // inside another user's project.
82
+ const dirPath = requireSharedFilePathAccess(conn, data.dirPath);
83
+ return await createDirectoryOperation(dirPath);
75
84
  })
76
85
 
77
86
  // Rename operation
@@ -86,8 +95,10 @@ export const writeHandler = createRouter()
86
95
  newPath: t.String(),
87
96
  modified: t.String()
88
97
  })
89
- }, async ({ data }) => {
90
- return await renameOperation(data.oldPath, data.newPath);
98
+ }, async ({ data, conn }) => {
99
+ const oldPath = requireFilePathAccess(conn, data.oldPath);
100
+ const newPath = requireFilePathAccess(conn, data.newPath);
101
+ return await renameOperation(oldPath, newPath);
91
102
  })
92
103
 
93
104
  // Duplicate operation
@@ -103,8 +114,10 @@ export const writeHandler = createRouter()
103
114
  size: t.Number(),
104
115
  modified: t.String()
105
116
  })
106
- }, async ({ data }) => {
107
- return await duplicateOperation(data.sourcePath, data.targetPath);
117
+ }, async ({ data, conn }) => {
118
+ const sourcePath = requireFilePathAccess(conn, data.sourcePath);
119
+ const targetPath = requireFilePathAccess(conn, data.targetPath);
120
+ return await duplicateOperation(sourcePath, targetPath);
108
121
  })
109
122
 
110
123
  // Upload file operation
@@ -124,8 +137,10 @@ export const writeHandler = createRouter()
124
137
  size: t.Number(),
125
138
  modified: t.String()
126
139
  })
127
- }, async ({ data }) => {
128
- return await uploadFileOperation(data.file, data.targetPath);
140
+ }, async ({ data, conn }) => {
141
+ const targetPath = requireFilePathAccess(conn, data.targetPath);
142
+ requireFilePathAccess(conn, join(targetPath, data.file.name));
143
+ return await uploadFileOperation(data.file, targetPath);
129
144
  })
130
145
 
131
146
  // Delete operation
@@ -138,6 +153,85 @@ export const writeHandler = createRouter()
138
153
  message: t.String(),
139
154
  path: t.String()
140
155
  })
141
- }, async ({ data }) => {
142
- return await deleteOperation(data.filePath, data.force);
156
+ }, async ({ data, conn }) => {
157
+ const filePath = requireFilePathAccess(conn, data.filePath);
158
+ return await deleteOperation(filePath, data.force);
159
+ })
160
+
161
+ // Delete an empty directory from FolderBrowser. Restricted to:
162
+ // - real directory (not a file)
163
+ // - empty contents (no force, no recursive)
164
+ // - shared guard (outside all projects, or inside the user's own project)
165
+ .http('files:delete-directory', {
166
+ data: t.Object({
167
+ dirPath: t.String()
168
+ }),
169
+ response: t.Object({
170
+ message: t.String(),
171
+ path: t.String()
172
+ })
173
+ }, async ({ data, conn }) => {
174
+ const dirPath = requireSharedFilePathAccess(conn, data.dirPath);
175
+
176
+ const stats = await fsStat(dirPath);
177
+ if (!stats.isDirectory()) {
178
+ throw new Error('Path is not a directory');
179
+ }
180
+ const entries = await fsReaddir(dirPath);
181
+ if (entries.length > 0) {
182
+ throw new Error('Directory is not empty');
183
+ }
184
+
185
+ return await deleteOperation(dirPath, false);
186
+ })
187
+
188
+ // Rename a directory from FolderBrowser (e.g. fix typo on a candidate
189
+ // project folder). Restricted to real directories on both sides and
190
+ // guarded by the shared path access policy. Uses fs.rename directly
191
+ // because Bun.file(...).exists() returns false for directories, which
192
+ // makes the generic renameOperation unusable here.
193
+ .http('files:rename-directory', {
194
+ data: t.Object({
195
+ oldPath: t.String(),
196
+ newPath: t.String()
197
+ }),
198
+ response: t.Object({
199
+ message: t.String(),
200
+ oldPath: t.String(),
201
+ newPath: t.String(),
202
+ modified: t.String()
203
+ })
204
+ }, async ({ data, conn }) => {
205
+ const oldPath = requireSharedFilePathAccess(conn, data.oldPath);
206
+ const newPath = requireSharedFilePathAccess(conn, data.newPath);
207
+
208
+ let oldStats;
209
+ try {
210
+ oldStats = await fsStat(oldPath);
211
+ } catch {
212
+ throw new Error('Source path does not exist');
213
+ }
214
+ if (!oldStats.isDirectory()) {
215
+ throw new Error('Source path is not a directory');
216
+ }
217
+
218
+ try {
219
+ await fsAccess(newPath);
220
+ throw new Error('Destination path already exists');
221
+ } catch (err) {
222
+ if (err instanceof Error && err.message === 'Destination path already exists') {
223
+ throw err;
224
+ }
225
+ // fsAccess threw because newPath does not exist — that is what we want.
226
+ }
227
+
228
+ await fsRename(oldPath, newPath);
229
+ const newStats = await fsStat(newPath);
230
+
231
+ return {
232
+ message: 'Directory renamed successfully',
233
+ oldPath,
234
+ newPath,
235
+ modified: newStats.mtime.toISOString()
236
+ };
143
237
  });
@@ -33,7 +33,7 @@ export const consolePreviewHandler = createRouter()
33
33
  const success = previewService.clearConsoleLogs(tab.id);
34
34
 
35
35
  if (!success) {
36
- throw new Error('Session not found');
36
+ throw new Error('Access denied');
37
37
  }
38
38
 
39
39
  return { message: 'Console logs cleared' };
@@ -69,7 +69,7 @@ export const consolePreviewHandler = createRouter()
69
69
  const success = previewService.toggleConsoleLogging(tab.id, data.enabled);
70
70
 
71
71
  if (!success) {
72
- throw new Error('Session not found');
72
+ throw new Error('Access denied');
73
73
  }
74
74
 
75
75
  return {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * HTTP endpoints for project management:
5
5
  * - List all projects (per-user)
6
- * - Create new project (or join existing)
6
+ * - Create new project (or return an existing project already joined by the user)
7
7
  * - Get project by ID
8
8
  * - Update project info
9
9
  * - Delete project (remove user association, cleanup if orphaned)
@@ -34,7 +34,7 @@ export const crudHandler = createRouter()
34
34
  return projects;
35
35
  })
36
36
 
37
- // Create new project (or join existing by path)
37
+ // Create new project (or return an existing project already joined by the user)
38
38
  .http('projects:create', {
39
39
  data: t.Object({
40
40
  name: t.String({ minLength: 1 }),
@@ -46,11 +46,15 @@ export const crudHandler = createRouter()
46
46
  const userId = ws.getUserId(conn);
47
47
  const { name, path } = data;
48
48
 
49
- // Check if project with this path already exists
49
+ // Check if project with this path already exists. If so, ensure the
50
+ // current user is joined to it and return the existing record. This
51
+ // covers re-adding a project that was previously removed (mode='remove')
52
+ // which preserves the project row for session restoration.
50
53
  const existing = projectQueries.getByPath(path);
51
54
  if (existing) {
52
- // Project exists - just add user association (join)
53
- projectQueries.addUserProject(userId, existing.id);
55
+ if (!projectQueries.userHasProject(userId, existing.id)) {
56
+ projectQueries.addUserProject(userId, existing.id);
57
+ }
54
58
  return existing;
55
59
  }
56
60
 
@@ -111,7 +115,9 @@ export const crudHandler = createRouter()
111
115
  if (sessions.length > 0) {
112
116
  // Cancel active chat streams
113
117
  await Promise.all(
114
- sessions.map(s => streamManager.cleanupSessionStreams(s.id).catch(() => {}))
118
+ sessions.map(s => streamManager.cleanupSessionStreams(s.id).catch((err) => {
119
+ debug.warn('project', `Stream cleanup error for session ${s.id} during project delete:`, err);
120
+ }))
115
121
  );
116
122
 
117
123
  // Collect blob hashes before deleting
@@ -163,7 +169,9 @@ export const crudHandler = createRouter()
163
169
  }
164
170
  }
165
171
 
166
- broadcastPresence().catch(() => {});
172
+ broadcastPresence().catch((err) => {
173
+ debug.warn('project', 'Presence broadcast error after project delete:', err);
174
+ });
167
175
 
168
176
  return {
169
177
  id: data.id,
@@ -71,7 +71,9 @@ export const statusHandler = createRouter()
71
71
  ws.addCleanup(conn, () => {
72
72
  updateUserPresence(projectId, userId, '', 'leave');
73
73
  debug.log('project', `Auto-cleaned presence for ${userId} from project ${projectId}`);
74
- broadcastPresence().catch(() => {});
74
+ broadcastPresence().catch((err) => {
75
+ debug.warn('project', `Presence broadcast error after auto-cleanup for ${userId}:`, err);
76
+ });
75
77
  });
76
78
 
77
79
  await broadcastPresence();
@@ -272,7 +272,9 @@ export const crudHandler = createRouter()
272
272
  });
273
273
 
274
274
  // Broadcast updated presence so status indicators reflect the deletion
275
- broadcastPresence().catch(() => {});
275
+ broadcastPresence().catch((err) => {
276
+ debug.warn('session', 'Presence broadcast error after session deletion:', err);
277
+ });
276
278
 
277
279
  return {
278
280
  message: 'Session deleted successfully'
@@ -297,7 +299,9 @@ export const crudHandler = createRouter()
297
299
 
298
300
  // Cancel and clean up active streams for all sessions
299
301
  await Promise.all(
300
- sessions.map(s => streamManager.cleanupSessionStreams(s.id).catch(() => {}))
302
+ sessions.map(s => streamManager.cleanupSessionStreams(s.id).catch((err) => {
303
+ debug.warn('session', `Stream cleanup error for session ${s.id}:`, err);
304
+ }))
301
305
  );
302
306
 
303
307
  // Collect ALL blob hashes before deleting anything:
@@ -348,7 +352,9 @@ export const crudHandler = createRouter()
348
352
  });
349
353
  }
350
354
 
351
- broadcastPresence().catch(() => {});
355
+ broadcastPresence().catch((err) => {
356
+ debug.warn('session', 'Presence broadcast error after bulk session deletion:', err);
357
+ });
352
358
 
353
359
  debug.log('session', `Deleted all ${deletedIds.length} sessions in project: ${projectId}`);
354
360
  return {
@@ -392,7 +398,7 @@ export const crudHandler = createRouter()
392
398
  const session = requireSessionAccess(conn, data.sessionId);
393
399
  requireProjectAccess(conn, data.projectId);
394
400
  if (session.project_id !== data.projectId) {
395
- throw new Error('Session not found');
401
+ throw new Error('Access denied');
396
402
  }
397
403
  sessionQueries.markUnread(userId, data.sessionId, data.projectId);
398
404
  debug.log('session', `[unread] Marked session ${data.sessionId} as UNREAD for user ${userId} in project ${data.projectId}`);
@@ -17,7 +17,7 @@ type TerminalStream = NonNullable<ReturnType<typeof terminalStreamManager.getStr
17
17
  export function requirePtySessionAccess(conn: WSConnection, sessionId: string): PtySession {
18
18
  const session = ptySessionManager.getSession(sessionId);
19
19
  if (!session || !session.projectId) {
20
- throw new Error('Session not found');
20
+ throw new Error('Access denied');
21
21
  }
22
22
  requireProjectAccess(conn, session.projectId);
23
23
  return session;
@@ -26,7 +26,7 @@ export function requirePtySessionAccess(conn: WSConnection, sessionId: string):
26
26
  export function requireTerminalStreamAccess(conn: WSConnection, streamId: string): TerminalStream {
27
27
  const stream = terminalStreamManager.getStream(streamId);
28
28
  if (!stream || !stream.projectId) {
29
- throw new Error('Stream not found');
29
+ throw new Error('Access denied');
30
30
  }
31
31
  requireProjectAccess(conn, stream.projectId);
32
32
  return stream;
@@ -49,7 +49,7 @@ export function requireTerminalLookupAccess(
49
49
 
50
50
  const projectId = session?.projectId || stream?.projectId;
51
51
  if (!projectId) {
52
- throw new Error('Session not found');
52
+ throw new Error('Access denied');
53
53
  }
54
54
  requireProjectAccess(conn, projectId);
55
55
  return { projectId, stream, session };
@@ -88,7 +88,7 @@ export const persistenceHandler = createRouter()
88
88
  const fallbackProjectId = ws.getProjectId(conn);
89
89
  ws.emit.project(fallbackProjectId, 'terminal:error', {
90
90
  sessionId,
91
- error: 'Stream not found'
91
+ error: 'Access denied'
92
92
  });
93
93
  return;
94
94
  }
@@ -58,7 +58,7 @@ export const sessionHandler = createRouter()
58
58
  // caller's current project. Prevents hijacking another project's PTY id.
59
59
  const existingForOwnership = ptySessionManager.getSession(sessionId);
60
60
  if (existingForOwnership && existingForOwnership.projectId && existingForOwnership.projectId !== projectId) {
61
- throw new Error('Session not found');
61
+ throw new Error('Access denied');
62
62
  }
63
63
 
64
64
  debug.log('terminal', `🌐 WebSocket: Creating PTY session: ${sessionId}`);
@@ -313,7 +313,7 @@ export const sessionHandler = createRouter()
313
313
  debug.log('terminal', `💀 [kill-session] No active PTY session found for: ${sessionId}`);
314
314
  return { sessionId };
315
315
  }
316
- if (!session.projectId) throw new Error('Session not found');
316
+ if (!session.projectId) throw new Error('Access denied');
317
317
  requireProjectAccess(conn, session.projectId);
318
318
 
319
319
  debug.log('terminal', `💀 [kill-session] Killing PTY session: ${sessionId}`);
@@ -1,2 +1,2 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-C9nYVmnw.js","assets/main-hspyFOoK.css"])))=>i.map(i=>d[i]);
2
- import{t as c,a as h,d,b as m,c as S,_ as p,o as P}from"./main-C9nYVmnw.js";class v{projectContexts=new Map;currentProjectId=null;constructor(){}getOrCreateProjectContext(e,s){let t=this.projectContexts.get(e);return t||(t={projectId:e,projectPath:s,sessionIds:[],activeSessionId:null,lastActiveAt:new Date,sessionOutputs:new Map,sessionCommandHistories:new Map},this.projectContexts.set(e,t),this.persistContexts()),t}async switchToProject(e,s){this.currentProjectId&&this.currentProjectId!==e&&(await this.saveCurrentProjectState(),await this.hideProjectTerminalSessions(this.currentProjectId));const t=this.getOrCreateProjectContext(e,s);this.currentProjectId!==e&&c.clearAllSessions(),t.sessionIds.length===0?await this.createProjectTerminalSessions(e,s):await this.showProjectTerminalSessions(t),this.currentProjectId=e,t.lastActiveAt=new Date,this.persistContexts(),await this.checkAndRestoreActiveStreams(e)}async createProjectTerminalSessions(e,s){const t=this.getOrCreateProjectContext(e,s),n=await h.listProjectSessions(e);if(n.length>0){d.log("terminal",`Found ${n.length} existing PTY sessions for project ${e}`),n.sort((r,l)=>r.sessionId.localeCompare(l.sessionId));for(const r of n){const l=r.sessionId.split("-"),f=l[l.length-1]||"1",I={id:r.sessionId,name:`Terminal ${f}`,directory:r.cwd||s,lines:[],commandHistory:[],isActive:!1,createdAt:new Date(r.createdAt),lastUsedAt:new Date(r.lastActivityAt),shellType:"Unknown",terminalBuffer:void 0,projectId:e,projectPath:s};c.addSession(I),m.createSession(r.sessionId,e,s,r.cwd||s),t.sessionIds.push(r.sessionId);const u=r.sessionId.match(/terminal-(\d+)/);u&&c.updateNextSessionId(parseInt(u[1],10)+1)}let o=n[0].sessionId;if(typeof sessionStorage<"u")try{const r=sessionStorage.getItem(`terminal-active-session-${e}`);r&&t.sessionIds.includes(r)&&(o=r)}catch{}t.activeSessionId=o,c.switchToSession(t.activeSessionId),this.persistContexts();return}const i=c.createNewSession(s,s,e),a=c.getSession(i);a&&(a.directory=s),m.createSession(i,e,s,s),t.sessionIds.push(i),t.activeSessionId=i,c.switchToSession(i),this.persistContexts()}async hideProjectTerminalSessions(e){const s=this.projectContexts.get(e);if(s){for(const t of s.sessionIds){const n=m.getSession(t);n&&n.isExecuting&&n.streamId&&S.saveActiveStream(t,n.streamId,n.lastCommand||"",e)}for(const t of s.sessionIds)h.cleanupListeners(t);c.clearAllSessions()}}async showProjectTerminalSessions(e){c.clearAllSessions();const{terminalPersistenceManager:s}=await p(async()=>{const{terminalPersistenceManager:n}=await import("./main-C9nYVmnw.js").then(i=>i.p);return{terminalPersistenceManager:n}},__vite__mapDeps([0,1])),t=s.getAllActiveStreams();if(e.sessionIds.length>0)for(const n of e.sessionIds){const i=n.split("-"),a=i[i.length-1]||"1",o={id:n,name:`Terminal ${a}`,directory:e.projectPath,lines:[],commandHistory:[],isActive:!1,createdAt:new Date,lastUsedAt:new Date,shellType:"Unknown",terminalBuffer:void 0,projectId:e.projectId,projectPath:e.projectPath};let r=!1,l=null;for(const u of t)if(u.projectId===e.projectId){const g=u.sessionId.split("-");if(g[g.length-1]===a){r=!0,l=u;break}}o.lines=[];const f=e.sessionCommandHistories.get(n);f&&(o.commandHistory=f);const I=m.getSession(n);if(I&&(f&&(I.commandHistory=f),o.directory=e.projectPath,(r||I.isExecuting)&&(c.setExecutingState(n,!0),l&&(I.isExecuting=!0,I.streamId=l.streamId,I.lastCommand=l.command))),c.addSession(o),!I||I.projectId!==e.projectId){const u=m.createSession(n,e.projectId,e.projectPath,e.projectPath);r&&l&&(u.isExecuting=!0,u.streamId=l.streamId,u.lastCommand=l.command)}else m.updateSession(n,{projectId:e.projectId,projectPath:e.projectPath,workingDirectory:e.projectPath})}else{const n=c.createNewSession(e.projectPath,e.projectPath,e.projectId);m.createSession(n,e.projectId,e.projectPath,e.projectPath),e.sessionIds.push(n),e.activeSessionId=n}e.activeSessionId&&e.sessionIds.includes(e.activeSessionId)?c.switchToSession(e.activeSessionId):e.sessionIds.length>0&&(e.activeSessionId=e.sessionIds[0],c.switchToSession(e.activeSessionId)),this.persistContexts()}async restoreProjectTerminalSessions(e){for(const s of e.sessionIds){const t=c.getSession(s),n=m.getSession(s);if(!t)if(n)this.restoreSessionToStore(n);else{const i=c.createNewSession(e.projectPath,e.projectPath,e.projectId),a=e.sessionIds.indexOf(s);a!==-1&&(e.sessionIds[a]=i),m.updateSession(i,{projectId:e.projectId,projectPath:e.projectPath}),e.activeSessionId===s&&(e.activeSessionId=i)}}e.activeSessionId?c.switchToSession(e.activeSessionId):e.sessionIds.length>0&&(e.activeSessionId=e.sessionIds[0],c.switchToSession(e.activeSessionId))}restoreSessionToStore(e,s){const t=e.projectPath||e.workingDirectory,n=e.id.split("-"),i=n[n.length-1]||"1",a={id:e.id,name:`Terminal ${i}`,directory:t,lines:[],commandHistory:e.commandHistory||[],isActive:!1,createdAt:e.createdAt||new Date,lastUsedAt:e.lastUsedAt||new Date,shellType:"Unknown",terminalBuffer:void 0,projectId:e.projectId,projectPath:e.projectPath};if(s&&s.sessionOutputs.has(e.id)){const o=s.sessionOutputs.get(e.id);o&&(a.lines=o.map(r=>({content:r.content,type:r.type,timestamp:r.timestamp})))}c.addSession(a)}async saveCurrentProjectState(){if(!this.currentProjectId)return;const e=this.projectContexts.get(this.currentProjectId);if(!e)return;const s=c.activeSessionId;s&&(e.activeSessionId=s);for(const t of e.sessionIds){const n=c.getSession(t);if(n){const i=n.lines.map(o=>({content:o.content,type:o.type,timestamp:o.timestamp||new Date}));e.sessionOutputs.set(t,i);let a=0;for(const o of n.lines)(o.type==="output"||o.type==="error")&&a++;e.sessionOutputs.set(`${t}-metadata`,{outputCount:a}),n.commandHistory&&n.commandHistory.length>0&&e.sessionCommandHistories.set(t,n.commandHistory),m.updateSession(t,{commandHistory:n.commandHistory,workingDirectory:n.directory,projectId:this.currentProjectId,projectPath:e.projectPath})}}this.persistContexts()}saveAllProjectStates(){this.currentProjectId&&this.saveCurrentProjectState();for(const[e,s]of this.projectContexts.entries())if(e!==this.currentProjectId)for(const t of s.sessionIds){const n=m.getSession(t);n&&n.commandHistory&&s.sessionCommandHistories.set(t,n.commandHistory)}this.persistContexts()}addTerminalToCurrentProject(e,s){const t=e||this.currentProjectId;if(!t)return null;let n=this.projectContexts.get(t);if(!n&&s&&(n=this.getOrCreateProjectContext(t,s)),!n)return null;e&&e!==this.currentProjectId&&(this.currentProjectId=e);const i=c.createNewSession(n.projectPath,n.projectPath,t),a=c.getSession(i);return a&&(a.directory=n.projectPath),m.createSession(i,t,n.projectPath,n.projectPath),n.sessionIds.push(i),n.activeSessionId=i,this.persistContexts(),i}async removeTerminalFromCurrentProject(e){if(!this.currentProjectId)return!1;const s=this.projectContexts.get(this.currentProjectId);return!s||s.sessionIds.length<=1?!1:(s.sessionIds=s.sessionIds.filter(t=>t!==e),s.activeSessionId===e&&s.sessionIds.length>0&&(s.activeSessionId=s.sessionIds[0]),await c.closeSession(e),m.removeSession(e),this.persistContexts(),!0)}removeSessionFromContext(e){d.log("terminal",`🗑️ [projectManager] Removing session from context: ${e}`);for(const[s,t]of this.projectContexts.entries()){const n=t.sessionIds.indexOf(e);if(n!==-1){d.log("terminal",`🗑️ [projectManager] Found session in project: ${s}`),d.log("terminal",`🗑️ [projectManager] Sessions before: ${t.sessionIds.join(", ")}`),t.sessionIds.splice(n,1),t.sessionOutputs.delete(e),t.sessionOutputs.delete(`${e}-metadata`),t.sessionCommandHistories.delete(e),t.activeSessionId===e&&(t.activeSessionId=t.sessionIds[0]||null,d.log("terminal",`🗑️ [projectManager] Updated activeSessionId to: ${t.activeSessionId}`)),d.log("terminal",`🗑️ [projectManager] Sessions after: ${t.sessionIds.join(", ")}`),m.removeSession(e),this.persistContexts(),d.log("terminal","🗑️ [projectManager] Context persisted");return}}d.log("terminal","🗑️ [projectManager] Session not found in any project context")}getProjectSessions(e){return this.projectContexts.get(e)?.sessionIds||[]}hasRunningTerminals(e){const s=this.projectContexts.get(e);return s?s.sessionIds.some(t=>m.getSession(t)?.isExecuting||!1):!1}getTerminalCount(e){return this.projectContexts.get(e)?.sessionIds.length||0}persistContexts(){for(const[e,s]of this.projectContexts.entries())for(const t of s.sessionIds){const n=m.getSession(t);n&&n.isExecuting&&n.streamId&&S.saveActiveStream(t,n.streamId,n.lastCommand||"",e)}}loadPersistedContexts(){}clearAll(){this.projectContexts.clear(),this.currentProjectId=null}initialize(){typeof window>"u"||this.setupCollaborativeListeners()}setupCollaborativeListeners(){p(async()=>{const{default:e}=await import("./main-C9nYVmnw.js").then(s=>s.w);return{default:e}},__vite__mapDeps([0,1])).then(({default:e})=>{e.on("terminal:tab-created",s=>{if(d.log("terminal",`📥 Received terminal:tab-created: ${s.sessionId}`),!this.currentProjectId)return;const t=this.projectContexts.get(this.currentProjectId);if(!t)return;if(t.sessionIds.includes(s.sessionId)){d.log("terminal",`✓ Terminal tab ${s.sessionId} already exists locally, skipping`);return}if(c.getSession(s.sessionId)){d.log("terminal",`✓ Terminal tab ${s.sessionId} already in store, skipping`);return}d.log("terminal",`➕ Adding remote terminal tab: ${s.sessionId}`);const i=s.sessionId.split("-"),a=i[i.length-1]||"1",o={id:s.sessionId,name:`Terminal ${a}`,directory:s.currentDirectory,lines:[],commandHistory:[],isActive:!1,createdAt:new Date,lastUsedAt:new Date,shellType:"Unknown",terminalBuffer:void 0,projectId:this.currentProjectId,projectPath:t.projectPath};c.addSession(o),t.sessionIds.push(s.sessionId),m.createSession(s.sessionId,this.currentProjectId,t.projectPath,s.currentDirectory);const r=s.sessionId.match(/terminal-(\d+)/);r&&c.updateNextSessionId(parseInt(r[1],10)+1)}),e.on("terminal:tab-closed",s=>{if(d.log("terminal",`📥 Received terminal:tab-closed: ${s.sessionId}`),!this.currentProjectId)return;const t=this.projectContexts.get(this.currentProjectId);if(!t)return;if(!t.sessionIds.includes(s.sessionId)){d.log("terminal",`✓ Terminal tab ${s.sessionId} not in our context, skipping`);return}if(!c.getSession(s.sessionId)){this.removeSessionFromContext(s.sessionId);return}d.log("terminal",`➖ Removing remote terminal tab: ${s.sessionId}`),this.removeSessionFromContext(s.sessionId),c.removeSessionFromStore(s.sessionId)}),d.log("terminal","✅ Terminal collaborative listeners registered")}),P(()=>{this.validateSessionsAfterReconnect()})}async validateSessionsAfterReconnect(){if(!this.currentProjectId)return;const e=this.projectContexts.get(this.currentProjectId);if(!(!e||e.sessionIds.length===0)){d.log("terminal","Validating terminal sessions after reconnect...");try{const s=await h.listProjectSessions(this.currentProjectId),t=new Set(s.map(i=>i.sessionId)),n=e.sessionIds.filter(i=>!t.has(i));if(n.length===0){d.log("terminal","All terminal sessions still alive after reconnect");return}d.log("terminal",`Found ${n.length} dead terminal session(s) after reconnect, cleaning up`);for(const i of n)this.removeSessionFromContext(i),c.removeSessionFromStore(i),h.cleanupListeners(i);e.sessionIds.length===0&&(d.log("terminal","All terminal sessions dead after reconnect, creating new session"),await this.createProjectTerminalSessions(this.currentProjectId,e.projectPath))}catch(s){d.error("terminal","Failed to validate terminal sessions after reconnect:",s)}}}getProjectIndicator(e){const s=this.projectContexts.get(e);if(!s)return{hasTerminals:!1,runningCount:0,totalCount:0};let t=0;const n=new Set;for(const o of s.sessionIds)if(m.getSession(o)?.isExecuting){const l=o.split("-"),f=l[l.length-1];n.add(f),t++}const i=S.getAllActiveStreams(),a=new Set;for(const o of i)if(!a.has(o.streamId)&&o.projectId===e){const r=o.sessionId.split("-"),l=r[r.length-1];n.has(l)||s.sessionIds.some(I=>{const u=I.split("-");return u[u.length-1]===l})&&(n.add(l),t++),a.add(o.streamId)}return{hasTerminals:s.sessionIds.length>0,runningCount:t,totalCount:s.sessionIds.length}}async checkAndRestoreActiveStreams(e){if(typeof window>"u")return;const s=this.projectContexts.get(e);if(!s)return;const{terminalPersistenceManager:t}=await p(async()=>{const{terminalPersistenceManager:a}=await import("./main-C9nYVmnw.js").then(o=>o.p);return{terminalPersistenceManager:a}},__vite__mapDeps([0,1])),{backgroundTerminalService:n}=await p(async()=>{const{backgroundTerminalService:a}=await import("./main-C9nYVmnw.js").then(o=>o.i);return{backgroundTerminalService:a}},__vite__mapDeps([0,1])),i=t.getAllActiveStreams();for(const a of i)if(a.projectId===e){const o=a.sessionId.split("-"),r=o[o.length-1];for(const l of s.sessionIds){const f=l.split("-");if(f[f.length-1]===r&&m.getSession(l)){m.startExecution(l,a.command,a.streamId),c.setExecutingState(l,!0);break}}}}}const j=new v,T=Object.freeze(Object.defineProperty({__proto__:null,terminalProjectManager:j},Symbol.toStringTag,{value:"Module"})),A=Object.freeze(Object.defineProperty({__proto__:null,terminalPersistenceManager:S,terminalProjectManager:j,terminalService:h,terminalSessionManager:m},Symbol.toStringTag,{value:"Module"}));export{A as i,T as p};
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/main-DiDuzJJh.js","assets/main-N1w7Llvp.css"])))=>i.map(i=>d[i]);
2
+ import{t as c,a as h,d,b as m,c as S,_ as p,o as P}from"./main-DiDuzJJh.js";class v{projectContexts=new Map;currentProjectId=null;constructor(){}getOrCreateProjectContext(e,s){let t=this.projectContexts.get(e);return t||(t={projectId:e,projectPath:s,sessionIds:[],activeSessionId:null,lastActiveAt:new Date,sessionOutputs:new Map,sessionCommandHistories:new Map},this.projectContexts.set(e,t),this.persistContexts()),t}async switchToProject(e,s){this.currentProjectId&&this.currentProjectId!==e&&(await this.saveCurrentProjectState(),await this.hideProjectTerminalSessions(this.currentProjectId));const t=this.getOrCreateProjectContext(e,s);this.currentProjectId!==e&&c.clearAllSessions(),t.sessionIds.length===0?await this.createProjectTerminalSessions(e,s):await this.showProjectTerminalSessions(t),this.currentProjectId=e,t.lastActiveAt=new Date,this.persistContexts(),await this.checkAndRestoreActiveStreams(e)}async createProjectTerminalSessions(e,s){const t=this.getOrCreateProjectContext(e,s),n=await h.listProjectSessions(e);if(n.length>0){d.log("terminal",`Found ${n.length} existing PTY sessions for project ${e}`),n.sort((r,l)=>r.sessionId.localeCompare(l.sessionId));for(const r of n){const l=r.sessionId.split("-"),f=l[l.length-1]||"1",I={id:r.sessionId,name:`Terminal ${f}`,directory:r.cwd||s,lines:[],commandHistory:[],isActive:!1,createdAt:new Date(r.createdAt),lastUsedAt:new Date(r.lastActivityAt),shellType:"Unknown",terminalBuffer:void 0,projectId:e,projectPath:s};c.addSession(I),m.createSession(r.sessionId,e,s,r.cwd||s),t.sessionIds.push(r.sessionId);const u=r.sessionId.match(/terminal-(\d+)/);u&&c.updateNextSessionId(parseInt(u[1],10)+1)}let o=n[0].sessionId;if(typeof sessionStorage<"u")try{const r=sessionStorage.getItem(`terminal-active-session-${e}`);r&&t.sessionIds.includes(r)&&(o=r)}catch{}t.activeSessionId=o,c.switchToSession(t.activeSessionId),this.persistContexts();return}const i=c.createNewSession(s,s,e),a=c.getSession(i);a&&(a.directory=s),m.createSession(i,e,s,s),t.sessionIds.push(i),t.activeSessionId=i,c.switchToSession(i),this.persistContexts()}async hideProjectTerminalSessions(e){const s=this.projectContexts.get(e);if(s){for(const t of s.sessionIds){const n=m.getSession(t);n&&n.isExecuting&&n.streamId&&S.saveActiveStream(t,n.streamId,n.lastCommand||"",e)}for(const t of s.sessionIds)h.cleanupListeners(t);c.clearAllSessions()}}async showProjectTerminalSessions(e){c.clearAllSessions();const{terminalPersistenceManager:s}=await p(async()=>{const{terminalPersistenceManager:n}=await import("./main-DiDuzJJh.js").then(i=>i.p);return{terminalPersistenceManager:n}},__vite__mapDeps([0,1])),t=s.getAllActiveStreams();if(e.sessionIds.length>0)for(const n of e.sessionIds){const i=n.split("-"),a=i[i.length-1]||"1",o={id:n,name:`Terminal ${a}`,directory:e.projectPath,lines:[],commandHistory:[],isActive:!1,createdAt:new Date,lastUsedAt:new Date,shellType:"Unknown",terminalBuffer:void 0,projectId:e.projectId,projectPath:e.projectPath};let r=!1,l=null;for(const u of t)if(u.projectId===e.projectId){const g=u.sessionId.split("-");if(g[g.length-1]===a){r=!0,l=u;break}}o.lines=[];const f=e.sessionCommandHistories.get(n);f&&(o.commandHistory=f);const I=m.getSession(n);if(I&&(f&&(I.commandHistory=f),o.directory=e.projectPath,(r||I.isExecuting)&&(c.setExecutingState(n,!0),l&&(I.isExecuting=!0,I.streamId=l.streamId,I.lastCommand=l.command))),c.addSession(o),!I||I.projectId!==e.projectId){const u=m.createSession(n,e.projectId,e.projectPath,e.projectPath);r&&l&&(u.isExecuting=!0,u.streamId=l.streamId,u.lastCommand=l.command)}else m.updateSession(n,{projectId:e.projectId,projectPath:e.projectPath,workingDirectory:e.projectPath})}else{const n=c.createNewSession(e.projectPath,e.projectPath,e.projectId);m.createSession(n,e.projectId,e.projectPath,e.projectPath),e.sessionIds.push(n),e.activeSessionId=n}e.activeSessionId&&e.sessionIds.includes(e.activeSessionId)?c.switchToSession(e.activeSessionId):e.sessionIds.length>0&&(e.activeSessionId=e.sessionIds[0],c.switchToSession(e.activeSessionId)),this.persistContexts()}async restoreProjectTerminalSessions(e){for(const s of e.sessionIds){const t=c.getSession(s),n=m.getSession(s);if(!t)if(n)this.restoreSessionToStore(n);else{const i=c.createNewSession(e.projectPath,e.projectPath,e.projectId),a=e.sessionIds.indexOf(s);a!==-1&&(e.sessionIds[a]=i),m.updateSession(i,{projectId:e.projectId,projectPath:e.projectPath}),e.activeSessionId===s&&(e.activeSessionId=i)}}e.activeSessionId?c.switchToSession(e.activeSessionId):e.sessionIds.length>0&&(e.activeSessionId=e.sessionIds[0],c.switchToSession(e.activeSessionId))}restoreSessionToStore(e,s){const t=e.projectPath||e.workingDirectory,n=e.id.split("-"),i=n[n.length-1]||"1",a={id:e.id,name:`Terminal ${i}`,directory:t,lines:[],commandHistory:e.commandHistory||[],isActive:!1,createdAt:e.createdAt||new Date,lastUsedAt:e.lastUsedAt||new Date,shellType:"Unknown",terminalBuffer:void 0,projectId:e.projectId,projectPath:e.projectPath};if(s&&s.sessionOutputs.has(e.id)){const o=s.sessionOutputs.get(e.id);o&&(a.lines=o.map(r=>({content:r.content,type:r.type,timestamp:r.timestamp})))}c.addSession(a)}async saveCurrentProjectState(){if(!this.currentProjectId)return;const e=this.projectContexts.get(this.currentProjectId);if(!e)return;const s=c.activeSessionId;s&&(e.activeSessionId=s);for(const t of e.sessionIds){const n=c.getSession(t);if(n){const i=n.lines.map(o=>({content:o.content,type:o.type,timestamp:o.timestamp||new Date}));e.sessionOutputs.set(t,i);let a=0;for(const o of n.lines)(o.type==="output"||o.type==="error")&&a++;e.sessionOutputs.set(`${t}-metadata`,{outputCount:a}),n.commandHistory&&n.commandHistory.length>0&&e.sessionCommandHistories.set(t,n.commandHistory),m.updateSession(t,{commandHistory:n.commandHistory,workingDirectory:n.directory,projectId:this.currentProjectId,projectPath:e.projectPath})}}this.persistContexts()}saveAllProjectStates(){this.currentProjectId&&this.saveCurrentProjectState();for(const[e,s]of this.projectContexts.entries())if(e!==this.currentProjectId)for(const t of s.sessionIds){const n=m.getSession(t);n&&n.commandHistory&&s.sessionCommandHistories.set(t,n.commandHistory)}this.persistContexts()}addTerminalToCurrentProject(e,s){const t=e||this.currentProjectId;if(!t)return null;let n=this.projectContexts.get(t);if(!n&&s&&(n=this.getOrCreateProjectContext(t,s)),!n)return null;e&&e!==this.currentProjectId&&(this.currentProjectId=e);const i=c.createNewSession(n.projectPath,n.projectPath,t),a=c.getSession(i);return a&&(a.directory=n.projectPath),m.createSession(i,t,n.projectPath,n.projectPath),n.sessionIds.push(i),n.activeSessionId=i,this.persistContexts(),i}async removeTerminalFromCurrentProject(e){if(!this.currentProjectId)return!1;const s=this.projectContexts.get(this.currentProjectId);return!s||s.sessionIds.length<=1?!1:(s.sessionIds=s.sessionIds.filter(t=>t!==e),s.activeSessionId===e&&s.sessionIds.length>0&&(s.activeSessionId=s.sessionIds[0]),await c.closeSession(e),m.removeSession(e),this.persistContexts(),!0)}removeSessionFromContext(e){d.log("terminal",`🗑️ [projectManager] Removing session from context: ${e}`);for(const[s,t]of this.projectContexts.entries()){const n=t.sessionIds.indexOf(e);if(n!==-1){d.log("terminal",`🗑️ [projectManager] Found session in project: ${s}`),d.log("terminal",`🗑️ [projectManager] Sessions before: ${t.sessionIds.join(", ")}`),t.sessionIds.splice(n,1),t.sessionOutputs.delete(e),t.sessionOutputs.delete(`${e}-metadata`),t.sessionCommandHistories.delete(e),t.activeSessionId===e&&(t.activeSessionId=t.sessionIds[0]||null,d.log("terminal",`🗑️ [projectManager] Updated activeSessionId to: ${t.activeSessionId}`)),d.log("terminal",`🗑️ [projectManager] Sessions after: ${t.sessionIds.join(", ")}`),m.removeSession(e),this.persistContexts(),d.log("terminal","🗑️ [projectManager] Context persisted");return}}d.log("terminal","🗑️ [projectManager] Session not found in any project context")}getProjectSessions(e){return this.projectContexts.get(e)?.sessionIds||[]}hasRunningTerminals(e){const s=this.projectContexts.get(e);return s?s.sessionIds.some(t=>m.getSession(t)?.isExecuting||!1):!1}getTerminalCount(e){return this.projectContexts.get(e)?.sessionIds.length||0}persistContexts(){for(const[e,s]of this.projectContexts.entries())for(const t of s.sessionIds){const n=m.getSession(t);n&&n.isExecuting&&n.streamId&&S.saveActiveStream(t,n.streamId,n.lastCommand||"",e)}}loadPersistedContexts(){}clearAll(){this.projectContexts.clear(),this.currentProjectId=null}initialize(){typeof window>"u"||this.setupCollaborativeListeners()}setupCollaborativeListeners(){p(async()=>{const{default:e}=await import("./main-DiDuzJJh.js").then(s=>s.w);return{default:e}},__vite__mapDeps([0,1])).then(({default:e})=>{e.on("terminal:tab-created",s=>{if(d.log("terminal",`📥 Received terminal:tab-created: ${s.sessionId}`),!this.currentProjectId)return;const t=this.projectContexts.get(this.currentProjectId);if(!t)return;if(t.sessionIds.includes(s.sessionId)){d.log("terminal",`✓ Terminal tab ${s.sessionId} already exists locally, skipping`);return}if(c.getSession(s.sessionId)){d.log("terminal",`✓ Terminal tab ${s.sessionId} already in store, skipping`);return}d.log("terminal",`➕ Adding remote terminal tab: ${s.sessionId}`);const i=s.sessionId.split("-"),a=i[i.length-1]||"1",o={id:s.sessionId,name:`Terminal ${a}`,directory:s.currentDirectory,lines:[],commandHistory:[],isActive:!1,createdAt:new Date,lastUsedAt:new Date,shellType:"Unknown",terminalBuffer:void 0,projectId:this.currentProjectId,projectPath:t.projectPath};c.addSession(o),t.sessionIds.push(s.sessionId),m.createSession(s.sessionId,this.currentProjectId,t.projectPath,s.currentDirectory);const r=s.sessionId.match(/terminal-(\d+)/);r&&c.updateNextSessionId(parseInt(r[1],10)+1)}),e.on("terminal:tab-closed",s=>{if(d.log("terminal",`📥 Received terminal:tab-closed: ${s.sessionId}`),!this.currentProjectId)return;const t=this.projectContexts.get(this.currentProjectId);if(!t)return;if(!t.sessionIds.includes(s.sessionId)){d.log("terminal",`✓ Terminal tab ${s.sessionId} not in our context, skipping`);return}if(!c.getSession(s.sessionId)){this.removeSessionFromContext(s.sessionId);return}d.log("terminal",`➖ Removing remote terminal tab: ${s.sessionId}`),this.removeSessionFromContext(s.sessionId),c.removeSessionFromStore(s.sessionId)}),d.log("terminal","✅ Terminal collaborative listeners registered")}),P(()=>{this.validateSessionsAfterReconnect()})}async validateSessionsAfterReconnect(){if(!this.currentProjectId)return;const e=this.projectContexts.get(this.currentProjectId);if(!(!e||e.sessionIds.length===0)){d.log("terminal","Validating terminal sessions after reconnect...");try{const s=await h.listProjectSessions(this.currentProjectId),t=new Set(s.map(i=>i.sessionId)),n=e.sessionIds.filter(i=>!t.has(i));if(n.length===0){d.log("terminal","All terminal sessions still alive after reconnect");return}d.log("terminal",`Found ${n.length} dead terminal session(s) after reconnect, cleaning up`);for(const i of n)this.removeSessionFromContext(i),c.removeSessionFromStore(i),h.cleanupListeners(i);e.sessionIds.length===0&&(d.log("terminal","All terminal sessions dead after reconnect, creating new session"),await this.createProjectTerminalSessions(this.currentProjectId,e.projectPath))}catch(s){d.error("terminal","Failed to validate terminal sessions after reconnect:",s)}}}getProjectIndicator(e){const s=this.projectContexts.get(e);if(!s)return{hasTerminals:!1,runningCount:0,totalCount:0};let t=0;const n=new Set;for(const o of s.sessionIds)if(m.getSession(o)?.isExecuting){const l=o.split("-"),f=l[l.length-1];n.add(f),t++}const i=S.getAllActiveStreams(),a=new Set;for(const o of i)if(!a.has(o.streamId)&&o.projectId===e){const r=o.sessionId.split("-"),l=r[r.length-1];n.has(l)||s.sessionIds.some(I=>{const u=I.split("-");return u[u.length-1]===l})&&(n.add(l),t++),a.add(o.streamId)}return{hasTerminals:s.sessionIds.length>0,runningCount:t,totalCount:s.sessionIds.length}}async checkAndRestoreActiveStreams(e){if(typeof window>"u")return;const s=this.projectContexts.get(e);if(!s)return;const{terminalPersistenceManager:t}=await p(async()=>{const{terminalPersistenceManager:a}=await import("./main-DiDuzJJh.js").then(o=>o.p);return{terminalPersistenceManager:a}},__vite__mapDeps([0,1])),{backgroundTerminalService:n}=await p(async()=>{const{backgroundTerminalService:a}=await import("./main-DiDuzJJh.js").then(o=>o.i);return{backgroundTerminalService:a}},__vite__mapDeps([0,1])),i=t.getAllActiveStreams();for(const a of i)if(a.projectId===e){const o=a.sessionId.split("-"),r=o[o.length-1];for(const l of s.sessionIds){const f=l.split("-");if(f[f.length-1]===r&&m.getSession(l)){m.startExecution(l,a.command,a.streamId),c.setExecutingState(l,!0);break}}}}}const j=new v,T=Object.freeze(Object.defineProperty({__proto__:null,terminalProjectManager:j},Symbol.toStringTag,{value:"Module"})),A=Object.freeze(Object.defineProperty({__proto__:null,terminalPersistenceManager:S,terminalProjectManager:j,terminalService:h,terminalSessionManager:m},Symbol.toStringTag,{value:"Module"}));export{A as i,T as p};