Files
orca/src/shared/runtime-workspace-file-owner.ts
T
Jihwan KimandOrcaWin 5bd2f59d29 fix(runtime): open files from sibling workspaces (#11369)
* feat(runtime): match files to workspace owners

* fix(runtime): resolve terminal paths through sibling workspaces

* fix(editor): route restored sibling workspace files

* fix remote sibling file ownership routing

* fix(editor): migrate restored sibling file owners

* fix(editor): revalidate restored owner activation

* docs(review): record PR 11369 correction evidence

* fix(editor): reject collision before activation prep

* docs(review): record PR 11369 final correction

* fix(editor): retain projected reconciliation narrowing

* chore(review): keep verification artifacts out of PR

* fix(editor): harden restored owner migration

* fix(runtime): resolve workspace root terminal paths

---------

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
2026-08-03 21:41:58 -07:00

44 lines
1.2 KiB
TypeScript

import type { ExecutionHostId } from './execution-host'
import { normalizeRuntimePathForComparison, relativePathInsideRoot } from './cross-platform-path'
export type RuntimeWorkspaceFileRoot = {
workspaceId: string
rootPath: string
executionHostId: ExecutionHostId
}
export type RuntimeWorkspaceFileOwner = RuntimeWorkspaceFileRoot & {
relativePath: string
}
export function findRuntimeWorkspaceFileOwner(
roots: readonly RuntimeWorkspaceFileRoot[],
absolutePath: string,
executionHostId: ExecutionHostId
): RuntimeWorkspaceFileOwner | null {
let best: RuntimeWorkspaceFileOwner | null = null
let bestRootLength = -1
for (const root of roots) {
if (root.executionHostId !== executionHostId) {
continue
}
const relativePath = relativePathInsideRoot(root.rootPath, absolutePath)
if (relativePath === null) {
continue
}
const rootLength = normalizeRuntimePathForComparison(root.rootPath).length
if (
rootLength > bestRootLength ||
(rootLength === bestRootLength &&
best !== null &&
root.workspaceId.localeCompare(best.workspaceId) < 0)
) {
best = { ...root, relativePath }
bestRootLength = rootLength
}
}
return best
}