mirror of
https://github.com/stablyai/orca.git
synced 2026-10-08 00:02:38 +00:00
Enable three unicorn rules — one correctness, two performance — and fix every existing violation repo-wide so the rules pass as errors. prefer-number-properties (76 sites) - parseInt/parseFloat/NaN -> Number.* : safe aliases (autofixed). - isNaN -> Number.isNaN (12 sites, hand-converted): global isNaN coerces its argument, Number.isNaN does not. Verified every call site already passes a number (Number.parseInt results, number-typed fields, Date.getTime()), so the conversion is behavior-preserving today and guards against a future non-numeric argument silently coercing. prefer-array-find (26 sites) - .filter(pred)[0] -> .find(pred); .filter(pred).at(-1) / .pop() -> .findLast(pred). Drops the intermediate array and short-circuits. prefer-array-index-of (5 sites) - .findIndex(x => x === v) -> .indexOf(v). Verified: typecheck (node/cli/web) clean, 53 affected suites pass (1679 tests), oxlint clean repo-wide. mobile/ uses findLast safely (already ships ES2023 .toReversed()); config scripts and e2e helpers run on Node 24.
54 lines
1.8 KiB
TypeScript
54 lines
1.8 KiB
TypeScript
import { WORKTREE_ID_SEPARATOR } from './pty-session-id-format'
|
|
|
|
export { WORKTREE_ID_SEPARATOR } from './pty-session-id-format'
|
|
|
|
export type ParsedWorktreeId = {
|
|
repoId: string
|
|
worktreePath: string
|
|
}
|
|
|
|
export const FOLDER_WORKSPACE_INSTANCE_SEPARATOR = '::workspace:'
|
|
const FOLDER_WORKSPACE_INSTANCE_SUFFIX = new RegExp(
|
|
`${FOLDER_WORKSPACE_INSTANCE_SEPARATOR.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')}[0-9a-f-]{36}$`
|
|
)
|
|
|
|
export function getRepoIdFromWorktreeId(worktreeId: string): string {
|
|
const separatorIdx = worktreeId.indexOf(WORKTREE_ID_SEPARATOR)
|
|
return separatorIdx === -1 ? worktreeId : worktreeId.slice(0, separatorIdx)
|
|
}
|
|
|
|
export function splitWorktreeId(worktreeId: string): ParsedWorktreeId | null {
|
|
const separatorIdx = worktreeId.indexOf(WORKTREE_ID_SEPARATOR)
|
|
if (separatorIdx === -1) {
|
|
return null
|
|
}
|
|
return {
|
|
repoId: worktreeId.slice(0, separatorIdx),
|
|
worktreePath: worktreeId.slice(separatorIdx + WORKTREE_ID_SEPARATOR.length)
|
|
}
|
|
}
|
|
|
|
export function splitWorktreeIdForFilesystem(worktreeId: string): ParsedWorktreeId | null {
|
|
const parsed = splitWorktreeId(worktreeId)
|
|
if (!parsed) {
|
|
return null
|
|
}
|
|
return {
|
|
repoId: parsed.repoId,
|
|
// Why: folder projects can have multiple workspace sessions backed by the
|
|
// same directory. Their IDs carry a UUID suffix, but filesystem callers
|
|
// still need the real folder path as cwd/root.
|
|
worktreePath: parsed.worktreePath.replace(FOLDER_WORKSPACE_INSTANCE_SUFFIX, '')
|
|
}
|
|
}
|
|
|
|
export function getWorktreePathBasenameFromId(worktreeId: string): string | null {
|
|
const parsed = splitWorktreeIdForFilesystem(worktreeId)
|
|
const normalizedPath = parsed?.worktreePath.trim().replace(/[\\/]+$/g, '') ?? ''
|
|
if (!normalizedPath) {
|
|
return null
|
|
}
|
|
const basename = normalizedPath.split(/[\\/]/).findLast(Boolean)?.trim()
|
|
return basename || null
|
|
}
|