@myrialabs/clopen 0.2.16 → 0.2.18
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/.env.example +4 -4
- package/backend/utils/env.ts +5 -5
- package/bin/clopen.ts +21 -298
- package/dist/assets/addon-clipboard-wHJhZAA4.js +1 -0
- package/dist/assets/addon-fit-DX4qG4td.js +1 -0
- package/dist/assets/addon-ligatures-DpDY8N_X.js +2 -0
- package/dist/assets/addon-unicode11-Bt8F3D7-.js +7 -0
- package/dist/assets/addon-web-links-DIbG5aQx.js +1 -0
- package/dist/assets/index-C-eR9PGW.js +2 -0
- package/dist/assets/main-D1IISCsM.js +247 -0
- package/dist/assets/main-DzSwlujO.css +1 -0
- package/dist/assets/xterm-B-qIQCd3.js +16 -0
- package/{index.html → dist/index.html} +2 -1
- package/package.json +12 -2
- package/scripts/start.ts +3 -3
- package/shared/utils/logger.ts +1 -1
- package/.dockerignore +0 -5
- package/.github/workflows/ci.yml +0 -86
- package/CONTRIBUTING.md +0 -188
- package/bun.lock +0 -1127
- package/docker-compose.yml +0 -31
- package/frontend/App.svelte +0 -77
- package/frontend/app-environment.ts +0 -10
- package/frontend/app.css +0 -313
- package/frontend/components/auth/InvitePage.svelte +0 -215
- package/frontend/components/auth/LoginPage.svelte +0 -129
- package/frontend/components/auth/SetupPage.svelte +0 -1054
- package/frontend/components/chat/ChatInterface.svelte +0 -426
- package/frontend/components/chat/formatters/ErrorMessage.svelte +0 -57
- package/frontend/components/chat/formatters/MessageFormatter.svelte +0 -244
- package/frontend/components/chat/formatters/TextMessage.svelte +0 -383
- package/frontend/components/chat/formatters/Tools.svelte +0 -79
- package/frontend/components/chat/formatters/index.ts +0 -3
- package/frontend/components/chat/input/ChatInput.svelte +0 -492
- package/frontend/components/chat/input/components/ChatInputActions.svelte +0 -88
- package/frontend/components/chat/input/components/DragDropOverlay.svelte +0 -30
- package/frontend/components/chat/input/components/EditModeIndicator.svelte +0 -33
- package/frontend/components/chat/input/components/EngineModelPicker.svelte +0 -642
- package/frontend/components/chat/input/components/FileAttachmentPreview.svelte +0 -48
- package/frontend/components/chat/input/components/LoadingIndicator.svelte +0 -43
- package/frontend/components/chat/input/composables/use-animations.svelte.ts +0 -217
- package/frontend/components/chat/input/composables/use-chat-actions.svelte.ts +0 -152
- package/frontend/components/chat/input/composables/use-file-handling.svelte.ts +0 -216
- package/frontend/components/chat/input/composables/use-input-state.svelte.ts +0 -357
- package/frontend/components/chat/input/composables/use-textarea-resize.svelte.ts +0 -69
- package/frontend/components/chat/message/ChatMessage.svelte +0 -509
- package/frontend/components/chat/message/ChatMessages.svelte +0 -553
- package/frontend/components/chat/message/DateSeparator.svelte +0 -86
- package/frontend/components/chat/message/MessageBubble.svelte +0 -114
- package/frontend/components/chat/message/MessageHeader.svelte +0 -143
- package/frontend/components/chat/modal/DebugModal.svelte +0 -59
- package/frontend/components/chat/shared/index.ts +0 -2
- package/frontend/components/chat/shared/utils.ts +0 -116
- package/frontend/components/chat/tools/AgentTool.svelte +0 -96
- package/frontend/components/chat/tools/AskUserQuestionTool.svelte +0 -391
- package/frontend/components/chat/tools/BashOutputTool.svelte +0 -35
- package/frontend/components/chat/tools/BashTool.svelte +0 -51
- package/frontend/components/chat/tools/CustomMcpTool.svelte +0 -141
- package/frontend/components/chat/tools/EditTool.svelte +0 -48
- package/frontend/components/chat/tools/EnterPlanModeTool.svelte +0 -24
- package/frontend/components/chat/tools/ExitPlanModeTool.svelte +0 -29
- package/frontend/components/chat/tools/GlobTool.svelte +0 -51
- package/frontend/components/chat/tools/GrepTool.svelte +0 -90
- package/frontend/components/chat/tools/ListMcpResourcesTool.svelte +0 -31
- package/frontend/components/chat/tools/NotebookEditTool.svelte +0 -38
- package/frontend/components/chat/tools/ReadMcpResourceTool.svelte +0 -34
- package/frontend/components/chat/tools/ReadTool.svelte +0 -41
- package/frontend/components/chat/tools/SkillTool.svelte +0 -21
- package/frontend/components/chat/tools/TaskStopTool.svelte +0 -26
- package/frontend/components/chat/tools/TaskTool.svelte +0 -64
- package/frontend/components/chat/tools/TodoWriteTool.svelte +0 -75
- package/frontend/components/chat/tools/WebFetchTool.svelte +0 -35
- package/frontend/components/chat/tools/WebSearchTool.svelte +0 -84
- package/frontend/components/chat/tools/WriteTool.svelte +0 -33
- package/frontend/components/chat/tools/components/CodeBlock.svelte +0 -79
- package/frontend/components/chat/tools/components/DiffBlock.svelte +0 -408
- package/frontend/components/chat/tools/components/FileHeader.svelte +0 -59
- package/frontend/components/chat/tools/components/InfoLine.svelte +0 -19
- package/frontend/components/chat/tools/components/StatsBadges.svelte +0 -27
- package/frontend/components/chat/tools/components/TerminalCommand.svelte +0 -61
- package/frontend/components/chat/tools/components/index.ts +0 -7
- package/frontend/components/chat/tools/index.ts +0 -30
- package/frontend/components/chat/widgets/ContextIndicator.svelte +0 -186
- package/frontend/components/chat/widgets/FloatingTodoList.svelte +0 -367
- package/frontend/components/checkpoint/ConflictResolutionModal.svelte +0 -189
- package/frontend/components/checkpoint/TimelineModal.svelte +0 -447
- package/frontend/components/checkpoint/timeline/TimelineEdge.svelte +0 -26
- package/frontend/components/checkpoint/timeline/TimelineGraph.svelte +0 -87
- package/frontend/components/checkpoint/timeline/TimelineNode.svelte +0 -119
- package/frontend/components/checkpoint/timeline/TimelineVersionGroup.svelte +0 -59
- package/frontend/components/checkpoint/timeline/animation.ts +0 -168
- package/frontend/components/checkpoint/timeline/config.ts +0 -44
- package/frontend/components/checkpoint/timeline/graph-builder.ts +0 -304
- package/frontend/components/checkpoint/timeline/types.ts +0 -69
- package/frontend/components/checkpoint/timeline/utils.ts +0 -53
- package/frontend/components/common/display/AvatarBubble.svelte +0 -56
- package/frontend/components/common/display/Button.svelte +0 -71
- package/frontend/components/common/display/Card.svelte +0 -102
- package/frontend/components/common/display/Icon.svelte +0 -58
- package/frontend/components/common/display/PageTemplate.svelte +0 -76
- package/frontend/components/common/display/ProjectUserAvatars.svelte +0 -79
- package/frontend/components/common/display/ThemeToggle.svelte +0 -44
- package/frontend/components/common/editor/MonacoEditor.svelte +0 -583
- package/frontend/components/common/feedback/Alert.svelte +0 -139
- package/frontend/components/common/feedback/ConnectionBanner.svelte +0 -55
- package/frontend/components/common/feedback/LoadingScreen.svelte +0 -52
- package/frontend/components/common/feedback/LoadingSpinner.svelte +0 -48
- package/frontend/components/common/feedback/NotificationToast.svelte +0 -128
- package/frontend/components/common/feedback/RestartRequiredModal.svelte +0 -53
- package/frontend/components/common/feedback/UpdateBanner.svelte +0 -99
- package/frontend/components/common/form/Checkbox.svelte +0 -48
- package/frontend/components/common/form/FolderBrowser.svelte +0 -856
- package/frontend/components/common/form/Input.svelte +0 -72
- package/frontend/components/common/form/ModelSelector.svelte +0 -110
- package/frontend/components/common/form/Select.svelte +0 -98
- package/frontend/components/common/form/Textarea.svelte +0 -80
- package/frontend/components/common/lucide-icons.ts +0 -1642
- package/frontend/components/common/material-icons.ts +0 -1082
- package/frontend/components/common/media/MediaPreview.svelte +0 -187
- package/frontend/components/common/overlay/Dialog.svelte +0 -251
- package/frontend/components/common/overlay/Lightbox.svelte +0 -233
- package/frontend/components/common/overlay/Modal.svelte +0 -177
- package/frontend/components/common/overlay/ModalProvider.svelte +0 -28
- package/frontend/components/common/xterm/XTerm.svelte +0 -743
- package/frontend/components/common/xterm/index.ts +0 -16
- package/frontend/components/common/xterm/terminal-config.ts +0 -68
- package/frontend/components/common/xterm/types.ts +0 -32
- package/frontend/components/common/xterm/xterm-service.ts +0 -437
- package/frontend/components/files/FileNode.svelte +0 -327
- package/frontend/components/files/FileTree.svelte +0 -690
- package/frontend/components/files/FileViewer.svelte +0 -551
- package/frontend/components/files/SearchResults.svelte +0 -303
- package/frontend/components/git/BranchManager.svelte +0 -446
- package/frontend/components/git/ChangesSection.svelte +0 -196
- package/frontend/components/git/CommitForm.svelte +0 -128
- package/frontend/components/git/ConflictResolver.svelte +0 -158
- package/frontend/components/git/DiffViewer.svelte +0 -298
- package/frontend/components/git/FileChangeItem.svelte +0 -119
- package/frontend/components/git/GitButton.svelte +0 -33
- package/frontend/components/git/GitLog.svelte +0 -401
- package/frontend/components/git/GitModal.svelte +0 -80
- package/frontend/components/history/HistoryModal.svelte +0 -602
- package/frontend/components/history/HistoryView.svelte +0 -561
- package/frontend/components/index.ts +0 -34
- package/frontend/components/preview/browser/BrowserPreview.svelte +0 -558
- package/frontend/components/preview/browser/components/Canvas.svelte +0 -1523
- package/frontend/components/preview/browser/components/ConsolePanel.svelte +0 -757
- package/frontend/components/preview/browser/components/Container.svelte +0 -507
- package/frontend/components/preview/browser/components/ContextMenu.svelte +0 -236
- package/frontend/components/preview/browser/components/SelectDropdown.svelte +0 -224
- package/frontend/components/preview/browser/components/Toolbar.svelte +0 -358
- package/frontend/components/preview/browser/components/VirtualCursor.svelte +0 -36
- package/frontend/components/preview/browser/core/cleanup.svelte.ts +0 -155
- package/frontend/components/preview/browser/core/coordinator.svelte.ts +0 -885
- package/frontend/components/preview/browser/core/interactions.svelte.ts +0 -113
- package/frontend/components/preview/browser/core/mcp-handlers.svelte.ts +0 -331
- package/frontend/components/preview/browser/core/native-ui-handlers.svelte.ts +0 -391
- package/frontend/components/preview/browser/core/stream-handler.svelte.ts +0 -288
- package/frontend/components/preview/browser/core/tab-manager.svelte.ts +0 -210
- package/frontend/components/preview/browser/core/tab-operations.svelte.ts +0 -241
- package/frontend/components/preview/index.ts +0 -2
- package/frontend/components/settings/SettingsModal.svelte +0 -268
- package/frontend/components/settings/SettingsView.svelte +0 -54
- package/frontend/components/settings/account/AccountSettings.svelte +0 -5
- package/frontend/components/settings/admin/InviteManagement.svelte +0 -239
- package/frontend/components/settings/admin/UserManagement.svelte +0 -127
- package/frontend/components/settings/appearance/AppearanceSettings.svelte +0 -104
- package/frontend/components/settings/appearance/LayoutPresetSettings.svelte +0 -160
- package/frontend/components/settings/appearance/LayoutPreview.svelte +0 -76
- package/frontend/components/settings/engines/AIEnginesSettings.svelte +0 -917
- package/frontend/components/settings/general/AdvancedSettings.svelte +0 -193
- package/frontend/components/settings/general/AuthModeSettings.svelte +0 -229
- package/frontend/components/settings/general/DataManagementSettings.svelte +0 -89
- package/frontend/components/settings/general/GeneralSettings.svelte +0 -20
- package/frontend/components/settings/general/UpdateSettings.svelte +0 -130
- package/frontend/components/settings/git/GitSettings.svelte +0 -392
- package/frontend/components/settings/model/EngineModelPicker.svelte +0 -284
- package/frontend/components/settings/model/ModelSettings.svelte +0 -240
- package/frontend/components/settings/notifications/NotificationSettings.svelte +0 -205
- package/frontend/components/settings/security/SecuritySettings.svelte +0 -10
- package/frontend/components/settings/system/SystemSettings.svelte +0 -10
- package/frontend/components/settings/tunnel/TunnelSettings.svelte +0 -1060
- package/frontend/components/settings/user/UserSettings.svelte +0 -270
- package/frontend/components/terminal/Terminal.svelte +0 -338
- package/frontend/components/terminal/TerminalTabs.svelte +0 -88
- package/frontend/components/terminal/TerminalView.svelte +0 -55
- package/frontend/components/tunnel/TunnelActive.svelte +0 -218
- package/frontend/components/tunnel/TunnelButton.svelte +0 -60
- package/frontend/components/tunnel/TunnelInactive.svelte +0 -260
- package/frontend/components/tunnel/TunnelModal.svelte +0 -101
- package/frontend/components/tunnel/TunnelQRCode.svelte +0 -49
- package/frontend/components/workspace/DesktopNavigator.svelte +0 -445
- package/frontend/components/workspace/MobileNavigator.svelte +0 -427
- package/frontend/components/workspace/PanelContainer.svelte +0 -100
- package/frontend/components/workspace/PanelHeader.svelte +0 -664
- package/frontend/components/workspace/ViewMenu.svelte +0 -146
- package/frontend/components/workspace/WorkspaceLayout.svelte +0 -199
- package/frontend/components/workspace/layout/DesktopLayout.svelte +0 -15
- package/frontend/components/workspace/layout/MobileLayout.svelte +0 -17
- package/frontend/components/workspace/layout/split-pane/Container.svelte +0 -42
- package/frontend/components/workspace/layout/split-pane/Handle.svelte +0 -85
- package/frontend/components/workspace/layout/split-pane/Layout.svelte +0 -62
- package/frontend/components/workspace/panels/ChatPanel.svelte +0 -282
- package/frontend/components/workspace/panels/FilesPanel.svelte +0 -1376
- package/frontend/components/workspace/panels/GitPanel.svelte +0 -1601
- package/frontend/components/workspace/panels/PreviewPanel.svelte +0 -153
- package/frontend/components/workspace/panels/TerminalPanel.svelte +0 -73
- package/frontend/main.ts +0 -17
- package/frontend/services/chat/chat.service.ts +0 -975
- package/frontend/services/chat/index.ts +0 -7
- package/frontend/services/favicon.service.ts +0 -103
- package/frontend/services/notification/global-stream-monitor.ts +0 -120
- package/frontend/services/notification/index.ts +0 -8
- package/frontend/services/notification/push.service.ts +0 -144
- package/frontend/services/notification/sound.service.ts +0 -127
- package/frontend/services/preview/browser/browser-console.service.ts +0 -61
- package/frontend/services/preview/browser/browser-webcodecs.service.ts +0 -1643
- package/frontend/services/preview/browser/mcp-integration.svelte.ts +0 -67
- package/frontend/services/preview/index.ts +0 -23
- package/frontend/services/project/index.ts +0 -8
- package/frontend/services/project/status.service.ts +0 -170
- package/frontend/services/snapshot/snapshot.service.ts +0 -86
- package/frontend/services/terminal/background/index.ts +0 -130
- package/frontend/services/terminal/background/session-restore.ts +0 -274
- package/frontend/services/terminal/background/stream-manager.ts +0 -286
- package/frontend/services/terminal/index.ts +0 -14
- package/frontend/services/terminal/persistence.service.ts +0 -260
- package/frontend/services/terminal/project.service.ts +0 -1004
- package/frontend/services/terminal/session.service.ts +0 -364
- package/frontend/services/terminal/terminal.service.ts +0 -379
- package/frontend/stores/core/app.svelte.ts +0 -296
- package/frontend/stores/core/files.svelte.ts +0 -87
- package/frontend/stores/core/presence.svelte.ts +0 -128
- package/frontend/stores/core/projects.svelte.ts +0 -325
- package/frontend/stores/core/sessions.svelte.ts +0 -452
- package/frontend/stores/features/auth.svelte.ts +0 -336
- package/frontend/stores/features/claude-accounts.svelte.ts +0 -58
- package/frontend/stores/features/models.svelte.ts +0 -89
- package/frontend/stores/features/settings.svelte.ts +0 -151
- package/frontend/stores/features/terminal.svelte.ts +0 -747
- package/frontend/stores/features/tunnel-config.svelte.ts +0 -205
- package/frontend/stores/features/tunnel.svelte.ts +0 -277
- package/frontend/stores/features/user.svelte.ts +0 -54
- package/frontend/stores/ui/chat-input.svelte.ts +0 -57
- package/frontend/stores/ui/chat-model.svelte.ts +0 -61
- package/frontend/stores/ui/connection.svelte.ts +0 -40
- package/frontend/stores/ui/dialog.svelte.ts +0 -59
- package/frontend/stores/ui/edit-mode.svelte.ts +0 -214
- package/frontend/stores/ui/notification.svelte.ts +0 -169
- package/frontend/stores/ui/settings-modal.svelte.ts +0 -116
- package/frontend/stores/ui/theme.svelte.ts +0 -179
- package/frontend/stores/ui/todo-panel.svelte.ts +0 -39
- package/frontend/stores/ui/update.svelte.ts +0 -159
- package/frontend/stores/ui/workspace.svelte.ts +0 -798
- package/frontend/utils/chat/date-separator.ts +0 -39
- package/frontend/utils/chat/message-grouper.ts +0 -329
- package/frontend/utils/chat/message-processor.ts +0 -169
- package/frontend/utils/chat/tool-handler.ts +0 -287
- package/frontend/utils/chat/virtual-scroll.svelte.ts +0 -142
- package/frontend/utils/click-outside.ts +0 -20
- package/frontend/utils/context-manager.ts +0 -55
- package/frontend/utils/file-icon-mappings.ts +0 -769
- package/frontend/utils/file-type.ts +0 -68
- package/frontend/utils/folder-icon-mappings.ts +0 -1030
- package/frontend/utils/git-status.ts +0 -68
- package/frontend/utils/native-ui.ts +0 -73
- package/frontend/utils/platform.ts +0 -113
- package/frontend/utils/port-check.ts +0 -65
- package/frontend/utils/preview-constants.ts +0 -45
- package/frontend/utils/terminal-formatter.ts +0 -207
- package/frontend/utils/theme.ts +0 -6
- package/frontend/utils/tree-visualizer.ts +0 -320
- package/frontend/utils/ws.ts +0 -90
- package/scripts/dev.ts +0 -46
- package/scripts/generate-icons.ts +0 -87
- package/svelte.config.js +0 -20
- package/vite.config.ts +0 -51
- /package/{static → dist}/audio/notification.ogg +0 -0
- /package/{static → dist}/favicon.svg +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin-ext.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-italic-latin.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin-ext.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans/dm-sans-normal-latin.woff2 +0 -0
- /package/{static → dist}/fonts/dm-sans.css +0 -0
- /package/{static → dist}/manifest.json +0 -0
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core Terminal Service (WebSocket Version)
|
|
3
|
-
* Handles terminal operations using WebSocket bi-directional communication
|
|
4
|
-
* Replaces SSE-based streaming with WebSocket events
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import type { TerminalLine, TerminalSession, TerminalCommand } from '$shared/types/terminal';
|
|
8
|
-
import { terminalSessionManager, type TerminalSessionState } from './session.service';
|
|
9
|
-
import { backgroundTerminalService } from './background';
|
|
10
|
-
import ws from '$frontend/utils/ws';
|
|
11
|
-
import { debug } from '$shared/utils/logger';
|
|
12
|
-
|
|
13
|
-
export interface TerminalConnectOptions {
|
|
14
|
-
sessionId: string;
|
|
15
|
-
workingDirectory?: string;
|
|
16
|
-
projectPath?: string;
|
|
17
|
-
projectId?: string;
|
|
18
|
-
terminalSize?: { cols: number; rows: number };
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface StreamingResponse {
|
|
22
|
-
type: 'output' | 'error' | 'directory' | 'exit' | 'complete' | 'clear-screen';
|
|
23
|
-
content?: string;
|
|
24
|
-
newDirectory?: string;
|
|
25
|
-
sessionId?: string;
|
|
26
|
-
projectId?: string;
|
|
27
|
-
timestamp?: string;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class TerminalService {
|
|
31
|
-
private resizeEndpointAvailable: boolean | null = true; // WebSocket always available
|
|
32
|
-
private activeListeners = new Map<string, Array<() => void>>();
|
|
33
|
-
private lastOutputSeq = new Map<string, number>();
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Connect to persistent PTY session with streaming output via WebSocket
|
|
37
|
-
*/
|
|
38
|
-
async connectToSession(
|
|
39
|
-
options: TerminalConnectOptions,
|
|
40
|
-
onData: (data: StreamingResponse) => void
|
|
41
|
-
): Promise<void> {
|
|
42
|
-
const { sessionId, workingDirectory, projectPath, projectId, terminalSize } = options;
|
|
43
|
-
|
|
44
|
-
debug.log('terminal', `🔌 Connecting to PTY session via WebSocket: ${sessionId}`);
|
|
45
|
-
|
|
46
|
-
// CRITICAL: Cleanup existing listeners BEFORE creating new ones
|
|
47
|
-
// This prevents duplicate event handlers when reconnecting to the same session
|
|
48
|
-
// (e.g., when switching between projects and coming back)
|
|
49
|
-
this.cleanupListeners(sessionId);
|
|
50
|
-
|
|
51
|
-
// Reset sequence tracking for fresh deduplication
|
|
52
|
-
this.lastOutputSeq.delete(sessionId);
|
|
53
|
-
|
|
54
|
-
// Get or create session state
|
|
55
|
-
const session = terminalSessionManager.getOrCreateSession(
|
|
56
|
-
sessionId,
|
|
57
|
-
projectId,
|
|
58
|
-
projectPath,
|
|
59
|
-
workingDirectory
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
// Create unique stream ID for this connection
|
|
63
|
-
const streamId = `${sessionId}-${Date.now()}`;
|
|
64
|
-
|
|
65
|
-
// Setup WebSocket listeners for this session
|
|
66
|
-
const listeners: Array<() => void> = [];
|
|
67
|
-
|
|
68
|
-
// Listen for ready event
|
|
69
|
-
const unsubReady = ws.on('terminal:ready', (data) => {
|
|
70
|
-
if (data.sessionId === sessionId) {
|
|
71
|
-
debug.log('terminal', `✅ PTY session ready: ${sessionId} (PID: ${data.pid})`);
|
|
72
|
-
// Update session state with stream ID
|
|
73
|
-
terminalSessionManager.updateSession(sessionId, {
|
|
74
|
-
streamId: data.streamId,
|
|
75
|
-
processId: data.pid,
|
|
76
|
-
isExecuting: true
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
listeners.push(unsubReady);
|
|
81
|
-
|
|
82
|
-
// Listen for output (with sequence-based deduplication)
|
|
83
|
-
const unsubOutput = ws.on('terminal:output', (data) => {
|
|
84
|
-
if (data.sessionId === sessionId) {
|
|
85
|
-
// Deduplicate: skip if we've already seen this sequence number
|
|
86
|
-
// Multiple WS connections in the same project room can deliver
|
|
87
|
-
// the same terminal:output event multiple times
|
|
88
|
-
if (data.seq !== undefined && data.seq !== null) {
|
|
89
|
-
const lastSeq = this.lastOutputSeq.get(sessionId) || 0;
|
|
90
|
-
if (data.seq <= lastSeq) return;
|
|
91
|
-
this.lastOutputSeq.set(sessionId, data.seq);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
onData({
|
|
95
|
-
type: 'output',
|
|
96
|
-
content: data.content,
|
|
97
|
-
sessionId: data.sessionId,
|
|
98
|
-
projectId: data.projectId,
|
|
99
|
-
timestamp: data.timestamp
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
listeners.push(unsubOutput);
|
|
104
|
-
|
|
105
|
-
// Listen for directory changes
|
|
106
|
-
const unsubDirectory = ws.on('terminal:directory', (data) => {
|
|
107
|
-
if (data.sessionId === sessionId) {
|
|
108
|
-
terminalSessionManager.updateWorkingDirectory(sessionId, data.newDirectory);
|
|
109
|
-
onData({
|
|
110
|
-
type: 'directory',
|
|
111
|
-
newDirectory: data.newDirectory,
|
|
112
|
-
sessionId: data.sessionId
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
});
|
|
116
|
-
listeners.push(unsubDirectory);
|
|
117
|
-
|
|
118
|
-
// Listen for exit
|
|
119
|
-
const unsubExit = ws.on('terminal:exit', (data) => {
|
|
120
|
-
if (data.sessionId === sessionId) {
|
|
121
|
-
debug.log('terminal', `🏁 PTY session exited: ${sessionId} (code: ${data.exitCode})`);
|
|
122
|
-
|
|
123
|
-
// Clear stream info
|
|
124
|
-
backgroundTerminalService.endStream(sessionId, true);
|
|
125
|
-
|
|
126
|
-
onData({
|
|
127
|
-
type: 'exit',
|
|
128
|
-
content: data.exitCode === 0 ? 'success' : 'error',
|
|
129
|
-
sessionId: data.sessionId
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// Cleanup listeners
|
|
133
|
-
this.cleanupListeners(sessionId);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
listeners.push(unsubExit);
|
|
137
|
-
|
|
138
|
-
// Listen for errors
|
|
139
|
-
const unsubError = ws.on('terminal:error', (data) => {
|
|
140
|
-
if (data.sessionId === sessionId) {
|
|
141
|
-
debug.error('terminal', `❌ PTY error for ${sessionId}:`, data.error);
|
|
142
|
-
onData({
|
|
143
|
-
type: 'error',
|
|
144
|
-
content: data.error,
|
|
145
|
-
sessionId: data.sessionId
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
});
|
|
149
|
-
listeners.push(unsubError);
|
|
150
|
-
|
|
151
|
-
// Store listeners for cleanup
|
|
152
|
-
this.activeListeners.set(sessionId, listeners);
|
|
153
|
-
|
|
154
|
-
// Create terminal session (now using HTTP pattern)
|
|
155
|
-
try {
|
|
156
|
-
const response = await ws.http('terminal:create-session', {
|
|
157
|
-
sessionId,
|
|
158
|
-
streamId,
|
|
159
|
-
workingDirectory: session.workingDirectory,
|
|
160
|
-
projectPath,
|
|
161
|
-
cols: terminalSize?.cols || 80,
|
|
162
|
-
rows: terminalSize?.rows || 24
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
debug.log('terminal', `✅ Terminal session created:`, response);
|
|
166
|
-
|
|
167
|
-
// Update session with response data
|
|
168
|
-
terminalSessionManager.updateSession(sessionId, {
|
|
169
|
-
streamId: response.streamId,
|
|
170
|
-
processId: response.pid,
|
|
171
|
-
isExecuting: true
|
|
172
|
-
});
|
|
173
|
-
} catch (error) {
|
|
174
|
-
debug.error('terminal', `❌ Failed to create terminal session:`, error);
|
|
175
|
-
// Cleanup listeners on error
|
|
176
|
-
this.cleanupListeners(sessionId);
|
|
177
|
-
throw error;
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Send Ctrl+C interrupt signal to a specific session
|
|
183
|
-
* Always sends the signal regardless of execution state for utility/accessibility
|
|
184
|
-
*/
|
|
185
|
-
async cancelCommand(sessionId: string): Promise<boolean> {
|
|
186
|
-
const session = terminalSessionManager.getSession(sessionId);
|
|
187
|
-
if (!session) {
|
|
188
|
-
return false;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
try {
|
|
192
|
-
// Step 1: Cancel client-side state (if executing)
|
|
193
|
-
if (session.isExecuting) {
|
|
194
|
-
terminalSessionManager.cancelExecution(sessionId);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
// Step 2: Always send Ctrl+C signal via WebSocket
|
|
198
|
-
// This is useful as a utility shortcut even when not executing
|
|
199
|
-
try {
|
|
200
|
-
const data = await ws.http('terminal:cancel', { sessionId }, 10000);
|
|
201
|
-
if (data.sessionId === sessionId) {
|
|
202
|
-
// Clear stream info only if was executing
|
|
203
|
-
if (session.isExecuting) {
|
|
204
|
-
backgroundTerminalService.endStream(sessionId, true);
|
|
205
|
-
}
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
return false;
|
|
209
|
-
} catch {
|
|
210
|
-
return false;
|
|
211
|
-
}
|
|
212
|
-
} catch (error) {
|
|
213
|
-
debug.error('terminal', 'Error sending Ctrl+C signal:', error);
|
|
214
|
-
return false;
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Clear headless terminal on backend (sync with frontend clear)
|
|
220
|
-
*/
|
|
221
|
-
async clearHeadlessTerminal(sessionId: string): Promise<void> {
|
|
222
|
-
try {
|
|
223
|
-
await ws.http('terminal:clear', { sessionId });
|
|
224
|
-
} catch {
|
|
225
|
-
// Silently handle - non-critical
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
/**
|
|
230
|
-
* Resize terminal for a specific session
|
|
231
|
-
*/
|
|
232
|
-
async resizeTerminal(sessionId: string, cols: number, rows: number): Promise<boolean> {
|
|
233
|
-
try {
|
|
234
|
-
debug.log('terminal', `🔧 Resizing terminal ${sessionId} to ${cols}x${rows}`);
|
|
235
|
-
|
|
236
|
-
// Send resize request via WebSocket HTTP
|
|
237
|
-
await ws.http('terminal:resize', { sessionId, cols, rows });
|
|
238
|
-
return true;
|
|
239
|
-
} catch (error) {
|
|
240
|
-
debug.error('terminal', 'Error resizing terminal:', error);
|
|
241
|
-
return false;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
/**
|
|
246
|
-
* Send input to terminal session
|
|
247
|
-
*/
|
|
248
|
-
sendInput(sessionId: string, data: string): void {
|
|
249
|
-
debug.log('terminal', `⌨️ Sending input to ${sessionId}:`, data);
|
|
250
|
-
ws.emit('terminal:input', { sessionId, data });
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
/**
|
|
254
|
-
* Kill terminal session completely
|
|
255
|
-
*/
|
|
256
|
-
async killSession(sessionId: string): Promise<boolean> {
|
|
257
|
-
try {
|
|
258
|
-
debug.log('terminal', `💀 Killing terminal session: ${sessionId}`);
|
|
259
|
-
|
|
260
|
-
// Cleanup listeners first
|
|
261
|
-
this.cleanupListeners(sessionId);
|
|
262
|
-
|
|
263
|
-
// Send kill request and wait for confirmation
|
|
264
|
-
try {
|
|
265
|
-
const data = await ws.http('terminal:kill-session', { sessionId }, 5000);
|
|
266
|
-
return data.sessionId === sessionId;
|
|
267
|
-
} catch {
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
} catch (error) {
|
|
271
|
-
debug.error('terminal', 'Error killing session:', error);
|
|
272
|
-
return false;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* Check shell availability
|
|
278
|
-
*/
|
|
279
|
-
async checkShellAvailability(): Promise<{
|
|
280
|
-
available: boolean;
|
|
281
|
-
path: string | null;
|
|
282
|
-
platform: string;
|
|
283
|
-
isWindows: boolean;
|
|
284
|
-
shellType: string;
|
|
285
|
-
}> {
|
|
286
|
-
try {
|
|
287
|
-
return await ws.http('terminal:check-shell', {}, 5000);
|
|
288
|
-
} catch {
|
|
289
|
-
return {
|
|
290
|
-
available: false,
|
|
291
|
-
path: null,
|
|
292
|
-
platform: 'unknown',
|
|
293
|
-
isWindows: false,
|
|
294
|
-
shellType: 'Unknown'
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
/**
|
|
300
|
-
* Get missed output for a session (serialized terminal state)
|
|
301
|
-
*/
|
|
302
|
-
async getMissedOutput(
|
|
303
|
-
sessionId: string,
|
|
304
|
-
streamId?: string
|
|
305
|
-
): Promise<{
|
|
306
|
-
success: boolean;
|
|
307
|
-
output: string;
|
|
308
|
-
status: string;
|
|
309
|
-
}> {
|
|
310
|
-
try {
|
|
311
|
-
const data = await ws.http('terminal:missed-output', { sessionId, streamId }, 5000);
|
|
312
|
-
if (data.sessionId === sessionId) {
|
|
313
|
-
return {
|
|
314
|
-
success: true,
|
|
315
|
-
output: data.output,
|
|
316
|
-
status: data.status
|
|
317
|
-
};
|
|
318
|
-
}
|
|
319
|
-
return {
|
|
320
|
-
success: false,
|
|
321
|
-
output: '',
|
|
322
|
-
status: 'invalid_session'
|
|
323
|
-
};
|
|
324
|
-
} catch {
|
|
325
|
-
return {
|
|
326
|
-
success: false,
|
|
327
|
-
output: '',
|
|
328
|
-
status: 'timeout'
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* List active PTY sessions for a project on the backend
|
|
335
|
-
* Used after browser refresh to discover existing sessions
|
|
336
|
-
*/
|
|
337
|
-
async listProjectSessions(projectId: string): Promise<Array<{
|
|
338
|
-
sessionId: string;
|
|
339
|
-
pid: number;
|
|
340
|
-
cwd: string;
|
|
341
|
-
createdAt: string;
|
|
342
|
-
lastActivityAt: string;
|
|
343
|
-
}>> {
|
|
344
|
-
try {
|
|
345
|
-
const data = await ws.http('terminal:list-sessions', { projectId }, 5000);
|
|
346
|
-
return data.sessions || [];
|
|
347
|
-
} catch {
|
|
348
|
-
return [];
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
/**
|
|
353
|
-
* Cleanup listeners for a session
|
|
354
|
-
*/
|
|
355
|
-
cleanupListeners(sessionId: string): void {
|
|
356
|
-
const listeners = this.activeListeners.get(sessionId);
|
|
357
|
-
if (listeners) {
|
|
358
|
-
listeners.forEach(unsub => unsub());
|
|
359
|
-
this.activeListeners.delete(sessionId);
|
|
360
|
-
this.lastOutputSeq.delete(sessionId);
|
|
361
|
-
debug.log('terminal', `🧹 Cleaned up listeners for ${sessionId}`);
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Cleanup all listeners (call on component unmount)
|
|
367
|
-
*/
|
|
368
|
-
cleanup(): void {
|
|
369
|
-
this.activeListeners.forEach((listeners, sessionId) => {
|
|
370
|
-
listeners.forEach(unsub => unsub());
|
|
371
|
-
});
|
|
372
|
-
this.activeListeners.clear();
|
|
373
|
-
this.lastOutputSeq.clear();
|
|
374
|
-
debug.log('terminal', '🧹 Cleaned up all terminal listeners');
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// Export singleton instance
|
|
379
|
-
export const terminalService = new TerminalService();
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
import ws from '$frontend/utils/ws';
|
|
2
|
-
import { debug } from '$shared/utils/logger';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Core Application Store
|
|
6
|
-
* Main app state: UI, navigation, loading, errors
|
|
7
|
-
*
|
|
8
|
-
* State persistence: lastView saved to server via user:save-state
|
|
9
|
-
* No localStorage usage for view state
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
interface PageInfo {
|
|
13
|
-
title: string;
|
|
14
|
-
description: string;
|
|
15
|
-
actions?: import('svelte').Snippet;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Per-session process state.
|
|
20
|
-
* Tracks loading/waiting/cancelling state for each chat session independently,
|
|
21
|
-
* enabling correct multi-session and multi-project support.
|
|
22
|
-
*/
|
|
23
|
-
export interface SessionProcessState {
|
|
24
|
-
isLoading: boolean;
|
|
25
|
-
isWaitingInput: boolean;
|
|
26
|
-
isRestoring: boolean;
|
|
27
|
-
isCancelling: boolean;
|
|
28
|
-
error: string | null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const DEFAULT_SESSION_STATE: SessionProcessState = {
|
|
32
|
-
isLoading: false,
|
|
33
|
-
isWaitingInput: false,
|
|
34
|
-
isRestoring: false,
|
|
35
|
-
isCancelling: false,
|
|
36
|
-
error: null,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
interface AppState {
|
|
40
|
-
// UI Navigation
|
|
41
|
-
currentView: string;
|
|
42
|
-
|
|
43
|
-
// Current session process state (convenience — synced from sessionStates for the active session)
|
|
44
|
-
isLoading: boolean;
|
|
45
|
-
isWaitingInput: boolean;
|
|
46
|
-
isRestoring: boolean;
|
|
47
|
-
isCancelling: boolean;
|
|
48
|
-
error: string | null;
|
|
49
|
-
|
|
50
|
-
// Per-session process states (source of truth for multi-session support)
|
|
51
|
-
sessionStates: Record<string, SessionProcessState>;
|
|
52
|
-
|
|
53
|
-
// Unread sessions — maps session ID → project ID for sessions with new activity
|
|
54
|
-
unreadSessions: Map<string, string>;
|
|
55
|
-
|
|
56
|
-
// Page Information
|
|
57
|
-
pageInfo: PageInfo;
|
|
58
|
-
|
|
59
|
-
// App Loading State
|
|
60
|
-
isAppLoading: boolean;
|
|
61
|
-
isAppInitialized: boolean;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
// Core app state using Svelte 5 runes
|
|
65
|
-
export const appState = $state<AppState>({
|
|
66
|
-
// UI Navigation
|
|
67
|
-
currentView: 'chat',
|
|
68
|
-
isLoading: false,
|
|
69
|
-
isWaitingInput: false,
|
|
70
|
-
isRestoring: false,
|
|
71
|
-
isCancelling: false,
|
|
72
|
-
error: null,
|
|
73
|
-
|
|
74
|
-
// Per-session process states
|
|
75
|
-
sessionStates: {},
|
|
76
|
-
|
|
77
|
-
// Unread sessions (sessionId → projectId)
|
|
78
|
-
unreadSessions: new Map<string, string>(),
|
|
79
|
-
|
|
80
|
-
// Page Information
|
|
81
|
-
pageInfo: {
|
|
82
|
-
title: 'Claude Code',
|
|
83
|
-
description: '',
|
|
84
|
-
actions: undefined
|
|
85
|
-
},
|
|
86
|
-
|
|
87
|
-
// App Loading State
|
|
88
|
-
isAppLoading: true,
|
|
89
|
-
isAppInitialized: false
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// ========================================
|
|
93
|
-
// PER-SESSION PROCESS STATE MANAGEMENT
|
|
94
|
-
// ========================================
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Get the process state for a specific session.
|
|
98
|
-
* Returns default (idle) state if the session has no entry.
|
|
99
|
-
*/
|
|
100
|
-
export function getSessionProcessState(sessionId: string): SessionProcessState {
|
|
101
|
-
return appState.sessionStates[sessionId] ?? DEFAULT_SESSION_STATE;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Update process state for a specific session in the per-session map.
|
|
106
|
-
* Does NOT touch global convenience flags — caller is responsible for that.
|
|
107
|
-
*/
|
|
108
|
-
export function updateSessionProcessState(
|
|
109
|
-
sessionId: string,
|
|
110
|
-
update: Partial<SessionProcessState>
|
|
111
|
-
): void {
|
|
112
|
-
if (!appState.sessionStates[sessionId]) {
|
|
113
|
-
appState.sessionStates[sessionId] = { ...DEFAULT_SESSION_STATE };
|
|
114
|
-
}
|
|
115
|
-
Object.assign(appState.sessionStates[sessionId], update);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Sync global convenience flags from a session's per-session state.
|
|
120
|
-
* Call when switching sessions to derive global state from the new session.
|
|
121
|
-
*/
|
|
122
|
-
export function syncGlobalStateFromSession(sessionId: string): void {
|
|
123
|
-
const state = appState.sessionStates[sessionId] ?? DEFAULT_SESSION_STATE;
|
|
124
|
-
appState.isLoading = state.isLoading;
|
|
125
|
-
appState.isWaitingInput = state.isWaitingInput;
|
|
126
|
-
appState.isRestoring = state.isRestoring;
|
|
127
|
-
appState.isCancelling = state.isCancelling;
|
|
128
|
-
appState.error = state.error;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Remove all app-level state for a deleted session
|
|
133
|
-
* (process state, unread status, etc.)
|
|
134
|
-
*/
|
|
135
|
-
export function clearSessionState(sessionId: string): void {
|
|
136
|
-
delete appState.sessionStates[sessionId];
|
|
137
|
-
|
|
138
|
-
if (appState.unreadSessions.has(sessionId)) {
|
|
139
|
-
const next = new Map(appState.unreadSessions);
|
|
140
|
-
next.delete(sessionId);
|
|
141
|
-
appState.unreadSessions = next;
|
|
142
|
-
persistUnreadSessions();
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// ========================================
|
|
147
|
-
// UNREAD SESSION MANAGEMENT
|
|
148
|
-
// ========================================
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Persist the current unread sessions Map to the server via user:save-state.
|
|
152
|
-
* Uses the same proven infrastructure as currentProjectId/lastView persistence.
|
|
153
|
-
* Debounced: only the last call within 500ms actually persists.
|
|
154
|
-
*/
|
|
155
|
-
let saveUnreadTimeout: ReturnType<typeof setTimeout> | null = null;
|
|
156
|
-
|
|
157
|
-
function persistUnreadSessions(): void {
|
|
158
|
-
if (saveUnreadTimeout) clearTimeout(saveUnreadTimeout);
|
|
159
|
-
saveUnreadTimeout = setTimeout(() => {
|
|
160
|
-
const serialized = Object.fromEntries(appState.unreadSessions);
|
|
161
|
-
debug.log('session', '[unread] Persisting to server:', serialized);
|
|
162
|
-
ws.http('user:save-state', { key: 'unreadSessions', value: serialized }).catch(err => {
|
|
163
|
-
debug.error('session', '[unread] Error persisting unread sessions:', err);
|
|
164
|
-
});
|
|
165
|
-
}, 500);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
/**
|
|
169
|
-
* Mark a session as unread (has new activity the user hasn't seen).
|
|
170
|
-
* Persists to backend so the state survives browser refresh.
|
|
171
|
-
*/
|
|
172
|
-
export function markSessionUnread(sessionId: string, projectId: string): void {
|
|
173
|
-
const next = new Map(appState.unreadSessions);
|
|
174
|
-
next.set(sessionId, projectId);
|
|
175
|
-
appState.unreadSessions = next;
|
|
176
|
-
|
|
177
|
-
// Persist to backend via user:save-state (proven infrastructure)
|
|
178
|
-
debug.log('session', `[unread] markSessionUnread: sessionId=${sessionId}, projectId=${projectId}`);
|
|
179
|
-
ws.emit('sessions:mark-unread', { sessionId, projectId });
|
|
180
|
-
persistUnreadSessions();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Mark a session as read (user has viewed it).
|
|
185
|
-
* Persists to backend so the state survives browser refresh.
|
|
186
|
-
*/
|
|
187
|
-
export function markSessionRead(sessionId: string): void {
|
|
188
|
-
if (appState.unreadSessions.has(sessionId)) {
|
|
189
|
-
const next = new Map(appState.unreadSessions);
|
|
190
|
-
next.delete(sessionId);
|
|
191
|
-
appState.unreadSessions = next;
|
|
192
|
-
|
|
193
|
-
// Persist to backend via user:save-state (proven infrastructure)
|
|
194
|
-
debug.log('session', `[unread] markSessionRead: sessionId=${sessionId}`);
|
|
195
|
-
ws.emit('sessions:mark-read', { sessionId });
|
|
196
|
-
persistUnreadSessions();
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Restore unread sessions from server state (called during initialization).
|
|
202
|
-
*/
|
|
203
|
-
export function restoreUnreadSessions(saved: Record<string, string> | null): void {
|
|
204
|
-
if (!saved || typeof saved !== 'object') return;
|
|
205
|
-
|
|
206
|
-
const next = new Map(appState.unreadSessions);
|
|
207
|
-
for (const [sessionId, projectId] of Object.entries(saved)) {
|
|
208
|
-
if (typeof sessionId === 'string' && typeof projectId === 'string') {
|
|
209
|
-
next.set(sessionId, projectId);
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
appState.unreadSessions = next;
|
|
213
|
-
debug.log('session', '[unread] Restored from server:', Object.fromEntries(appState.unreadSessions));
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
/**
|
|
217
|
-
* Check if a session is unread.
|
|
218
|
-
*/
|
|
219
|
-
export function isSessionUnread(sessionId: string): boolean {
|
|
220
|
-
return appState.unreadSessions.has(sessionId);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* Check if a project has any unread sessions.
|
|
225
|
-
* Optionally exclude a specific session (e.g. the currently viewed one).
|
|
226
|
-
*/
|
|
227
|
-
export function hasUnreadSessionsForProject(projectId: string, excludeSessionId?: string): boolean {
|
|
228
|
-
for (const [sId, pId] of appState.unreadSessions.entries()) {
|
|
229
|
-
if (pId === projectId && sId !== excludeSessionId) return true;
|
|
230
|
-
}
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// ========================================
|
|
235
|
-
// UI STATE MANAGEMENT
|
|
236
|
-
// ========================================
|
|
237
|
-
|
|
238
|
-
export function setLoading(loading: boolean) {
|
|
239
|
-
appState.isLoading = loading;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
export function setCurrentView(view: string) {
|
|
243
|
-
appState.currentView = view;
|
|
244
|
-
// Save current view to server (fire-and-forget)
|
|
245
|
-
ws.http('user:save-state', { key: 'lastView', value: view }).catch(err => {
|
|
246
|
-
debug.error('workspace', 'Error saving lastView to server:', err);
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
export function setPageInfo(title: string, description?: string, actions?: import('svelte').Snippet) {
|
|
251
|
-
appState.pageInfo.title = title;
|
|
252
|
-
appState.pageInfo.description = description || '';
|
|
253
|
-
appState.pageInfo.actions = actions;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
export function setError(error: string | null) {
|
|
257
|
-
appState.error = error;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
export function clearError() {
|
|
261
|
-
appState.error = null;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// App loading state management
|
|
265
|
-
export function setAppLoading(loading: boolean) {
|
|
266
|
-
appState.isAppLoading = loading;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
export function setAppInitialized() {
|
|
270
|
-
appState.isAppInitialized = true;
|
|
271
|
-
appState.isAppLoading = false;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Restore last view from server-provided state.
|
|
276
|
-
* Called during initialization with state from user:restore-state.
|
|
277
|
-
*/
|
|
278
|
-
export function restoreLastView(lastView?: string | null) {
|
|
279
|
-
if (lastView) {
|
|
280
|
-
const validViews = ['chat', 'files', 'terminal', 'history', 'settings'];
|
|
281
|
-
if (validViews.includes(lastView)) {
|
|
282
|
-
appState.currentView = lastView;
|
|
283
|
-
return lastView;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
return 'chat'; // Default fallback
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
// ========================================
|
|
290
|
-
// INITIALIZATION
|
|
291
|
-
// ========================================
|
|
292
|
-
|
|
293
|
-
export function initializeStore() {
|
|
294
|
-
// Initialize core app store
|
|
295
|
-
// Any initialization logic can be added here
|
|
296
|
-
}
|