MCPcopy Create free account
hub / github.com/winfunc/opcode / loadTabs

Method loadTabs

src/services/tabPersistence.ts:101–172  ·  view source on GitHub ↗

* Load tabs from localStorage

()

Source from the content-addressed store, hash-verified

99 * Load tabs from localStorage
100 */
101 static loadTabs(): { tabs: Tab[], activeTabId: string | null } {
102 // Don't load if persistence is disabled
103 if (!this.isEnabled()) {
104 return { tabs: [], activeTabId: null };
105 }
106
107 try {
108 const savedTabsJson = localStorage.getItem(STORAGE_KEY);
109 const savedActiveTabId = localStorage.getItem(ACTIVE_TAB_KEY);
110
111 if (!savedTabsJson) {
112 return { tabs: [], activeTabId: null };
113 }
114
115 const serializedTabs: SerializedTab[] = JSON.parse(savedTabsJson);
116
117 // Deserialize tabs
118 const tabs: Tab[] = serializedTabs.map(serialized => ({
119 ...serialized,
120 createdAt: new Date(serialized.createdAt),
121 updatedAt: new Date(serialized.updatedAt),
122 sessionData: undefined, // Will be loaded when tab is activated
123 agentData: undefined, // Will be loaded when tab is activated
124 status: serialized.status === 'running' ? 'idle' : serialized.status // Ensure no running status
125 }));
126
127 // Validate and filter out any invalid tabs
128 const validTabs = tabs.filter(tab => {
129 // Basic validation
130 if (!tab.id || !tab.type || !tab.title) return false;
131
132 // Type-specific validation
133 switch (tab.type) {
134 case 'chat':
135 // Chat tabs without sessionId or projectPath might be invalid
136 // But we'll keep them as they might be new sessions
137 return true;
138 case 'agent':
139 // Agent tabs need an agentRunId
140 return !!tab.agentRunId;
141 case 'agent-execution':
142 // Agent execution tabs without agentData are invalid
143 // We'll filter these out as they can't be restored properly
144 return false;
145 case 'claude-file':
146 // Claude file tabs need a file ID
147 return !!tab.claudeFileId;
148 default:
149 // Other tab types (projects, agents, usage, etc.) are always valid
150 return true;
151 }
152 });
153
154 // Ensure proper ordering
155 const orderedTabs = validTabs
156 .sort((a, b) => a.order - b.order)
157 .map((tab, index) => ({ ...tab, order: index }));
158

Callers 1

loadTabsFunction · 0.80

Calls 1

isEnabledMethod · 0.95

Tested by

no test coverage detected