Files
orca/src/shared/folder-workspaces.ts
T
NeilandOrca 73c5009b82 chore(dead-code): drop ~2k lines of unreachable exports and orphan modules (#12077)
* chore(dead-code): drop 2k lines of unreachable exports and orphan modules

Ran knip across every build entry (main, preload, renderer, popout, web,
cli, relay, workers, forked sidecars, config scripts) and removed what no
entry graph can reach.

- 11 orphan modules nothing imported, plus one test that only covered them
- 159 unused exports/types, with their now-dead helpers, imports and tests

Each candidate was verified against dynamic references before deletion.
42 knip hits were false positives and are kept: shared modules consumed by
the mobile/ workspace, the src/shared/plugins/** public API, vendored
shadcn primitives, and relay wire-protocol constants held for compatibility.

Adds knip.json + `pnpm audit:dead-code` so this stays measurable.

Verified: pnpm typecheck, pnpm lint, and 2081 tests across the 73 affected
test files all pass.

* chore(dead-code): move knip config under config/

Root-level additions are blocked by the root directory guard.

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Orca <help@stably.ai>
2026-08-02 00:33:57 -07:00

110 lines
3.9 KiB
TypeScript

import type { FolderWorkspace, ProjectGroup } from './types'
import { isTuiAgent } from './tui-agent-config'
import { normalizeStoredTaskSourceContext } from './task-source-context'
import { normalizeWorkspaceLinkedItem } from './workspace-linked-item'
import { isWorkspaceLinkedItemSourceContextMatch } from './workspace-linked-item-source-context'
export function normalizeFolderWorkspaceName(
name: string | null | undefined,
fallback = 'Untitled workspace'
): string {
const trimmed = typeof name === 'string' ? name.trim() : ''
return trimmed.length > 0 ? trimmed : fallback
}
export function normalizeFolderWorkspaces(
value: unknown,
projectGroups: readonly ProjectGroup[]
): FolderWorkspace[] {
if (!Array.isArray(value)) {
return []
}
const folderGroups = new Map<string, ProjectGroup>()
for (const group of projectGroups) {
if (group.parentPath) {
folderGroups.set(group.id, group)
}
}
const workspaces: FolderWorkspace[] = []
const seen = new Set<string>()
for (const candidate of value) {
if (!candidate || typeof candidate !== 'object') {
continue
}
const raw = candidate as Partial<FolderWorkspace>
if (
typeof raw.id !== 'string' ||
raw.id.trim().length === 0 ||
seen.has(raw.id) ||
typeof raw.projectGroupId !== 'string' ||
!folderGroups.has(raw.projectGroupId)
) {
continue
}
const group = folderGroups.get(raw.projectGroupId)
const folderPath =
typeof raw.folderPath === 'string' && raw.folderPath.trim().length > 0
? raw.folderPath
: group?.parentPath
if (!folderPath) {
continue
}
const now = Date.now()
const linkedTask = normalizeWorkspaceLinkedItem(raw.linkedTask)
const linkedTaskSourceContext = normalizeStoredTaskSourceContext(raw.linkedTaskSourceContext)
seen.add(raw.id)
workspaces.push({
id: raw.id,
projectGroupId: raw.projectGroupId,
name: normalizeFolderWorkspaceName(raw.name),
folderPath,
connectionId:
typeof raw.connectionId === 'string'
? raw.connectionId
: raw.connectionId === null
? null
: (group?.connectionId ?? null),
linkedTask,
linkedTaskSourceContext: isWorkspaceLinkedItemSourceContextMatch(
linkedTask,
linkedTaskSourceContext
)
? linkedTaskSourceContext
: null,
comment: typeof raw.comment === 'string' ? raw.comment : '',
isArchived: raw.isArchived === true,
isUnread: raw.isUnread === true,
isPinned: raw.isPinned === true,
sortOrder:
typeof raw.sortOrder === 'number' && Number.isFinite(raw.sortOrder) ? raw.sortOrder : now,
...(typeof raw.manualOrder === 'number' && Number.isFinite(raw.manualOrder)
? { manualOrder: raw.manualOrder }
: {}),
...(typeof raw.workspaceStatus === 'string' && raw.workspaceStatus.trim().length > 0
? { workspaceStatus: raw.workspaceStatus }
: {}),
...(isTuiAgent(raw.createdWithAgent) ? { createdWithAgent: raw.createdWithAgent } : {}),
...(raw.pendingFirstAgentMessageRename === true
? { pendingFirstAgentMessageRename: true }
: {}),
...(typeof raw.firstAgentMessageRenameError === 'string'
? { firstAgentMessageRenameError: raw.firstAgentMessageRenameError }
: raw.firstAgentMessageRenameError === null
? { firstAgentMessageRenameError: null }
: {}),
lastActivityAt:
typeof raw.lastActivityAt === 'number' && Number.isFinite(raw.lastActivityAt)
? raw.lastActivityAt
: 0,
createdAt:
typeof raw.createdAt === 'number' && Number.isFinite(raw.createdAt) ? raw.createdAt : now,
updatedAt:
typeof raw.updatedAt === 'number' && Number.isFinite(raw.updatedAt) ? raw.updatedAt : now
})
}
return workspaces.sort(
(left, right) => right.sortOrder - left.sortOrder || left.name.localeCompare(right.name)
)
}