@@ -322,6 +322,33 @@ export const connectProjectById = (
322322 startTerminalSession ( context , runtime )
323323}
324324
325+ /**
326+ * Attaches an existing project SSH terminal session to the browser terminal list.
327+ *
328+ * @param projectId - Project identifier whose session should become selected.
329+ * @param projectKey - Project key used to resolve the terminal session API route.
330+ * @param projectDisplayName - Human-readable project name used in the attached-session message.
331+ * @param sessionId - Existing backend terminal session identifier to load and attach.
332+ * @param context - Browser action context used for selection, busy state, and terminal tab updates.
333+ * @returns Nothing; state changes are emitted through `context`.
334+ * @pure false
335+ * @effect BrowserActionContext and `loadProjectTerminalSession` Effect.
336+ * @invariant A terminal tab is added only after `loadProjectTerminalSession` succeeds.
337+ * @precondition `sessionId` names an existing terminal session for the resolved project key.
338+ * @postcondition On success, the project is selected and the loaded session is added to terminal tabs.
339+ * @complexity O(1) setup plus O(1) backend session load.
340+ * @throws Never
341+ */
342+ // CHANGE: document the existing-session attach shell contract
343+ // WHY: CodeRabbit review requires explicit side-effect and invariant metadata for exported TS functions
344+ // QUOTE(ТЗ): "Add a TSDoc comment block above the exported function attachProjectTerminalById"
345+ // REF: PR #342 CodeRabbit review
346+ // SOURCE: n/a
347+ // FORMAT THEOREM: resolvedProjectKey != null && load(sessionId) succeeds -> terminalTab(sessionId) is added
348+ // PURITY: SHELL
349+ // EFFECT: Effect<TerminalSession, string> via loadProjectTerminalSession plus BrowserActionContext mutations
350+ // INVARIANT: no terminal tab is added when project key resolution fails or session load fails
351+ // COMPLEXITY: O(1) setup plus O(1) backend session load
325352export const attachProjectTerminalById = (
326353 projectId : string ,
327354 projectKey : string ,
0 commit comments