Files
kandev/apps/web/components/workspace-source-picker/executor-capabilities.ts
T
Carlos Florêncio bc218dfbbe feat: add workspace sources from files panel (#1900)
* feat: add workspace sources from files panel

* fix: preserve worktree identity during recovery

* feat: unify workspace source actions

* fix: validate recovered workspace repositories

* fix: harden workspace source filesystem boundaries

* test: split workspace repository chip coverage

* fix: restrict repository rescan recovery paths

* fix: stabilize workspace source CI checks

* test: canonicalize workspace source paths

* test: align workspace source container paths

* fix: populate direct workspace repository names

* test: preserve git fixture rewrites across restarts

* test: isolate backend git fixture config

* fix: resume remote workspace executions before creation

* fix: preserve ssh agent identity during resume

* fix: preserve SSH workspace across backend restart

* fix: simplify workspace actions trigger

* fix: refine add workspace repositories UX

* docs: narrow workspace source UX updates

* fix: avoid phantom turn on session resume

* test(web): normalize workspace source request headers

* feat(web): streamline workspace source picker

* docs: remove trailing spaces from workspace source plan

* fix: prevent resume status from creating phantom turns

* fix(web): stabilize workspace source attachment

* refactor(web): extract workspace source store contract

* fix: avoid phantom turns on idle agent resume

* fix: address backend static analysis findings

* fix: preserve agentctl readiness status value

* fix: preserve resume messages without active turns

* fix: resume agents from promoted workspace root

* chore: merge origin/main into feature/add-new-repo-folder-d97

* feat(web): explain workspace source consequences

* test(websocket): count session activity subscription
2026-07-25 21:29:53 +01:00

66 lines
2.3 KiB
TypeScript

import type { ExecutorType } from "@/lib/types/http";
type SavedRepositoryIdentity = {
remote_url?: string;
provider?: string;
provider_repo_id?: string;
provider_host?: string;
provider_owner?: string;
provider_name?: string;
};
export function getWorkspaceSourceCapabilities(
executorType: ExecutorType | string | null | undefined,
): {
canAddFolders: boolean;
canChooseCheckoutBranch: boolean;
requiresCloneableLocalRepository: boolean;
} {
const usesLiveCheckout = executorType === "local" || executorType === "local_pc";
const requiresClone =
executorType === "local_docker" ||
executorType === "remote_docker" ||
executorType === "ssh" ||
executorType === "sprites";
return {
canAddFolders: usesLiveCheckout || executorType === "worktree",
canChooseCheckoutBranch: !usesLiveCheckout,
requiresCloneableLocalRepository: requiresClone,
};
}
/** Mirrors the backend remoteRepositoryLocator eligibility check. */
export function hasCloneableSavedRepository(repository: SavedRepositoryIdentity): boolean {
return hasSafeRemoteURL(repository.remote_url) || hasProviderRepositoryLocator(repository);
}
function hasProviderRepositoryLocator(repository: SavedRepositoryIdentity): boolean {
const provider = repository.provider?.trim().toLowerCase();
if (!provider || !repository.provider_owner?.trim() || !repository.provider_name?.trim()) {
return false;
}
if (provider === "gitlab" && !repository.provider_host?.trim()) return false;
return provider === "github" || provider === "gitlab" || provider === "bitbucket";
}
function hasSafeRemoteURL(remoteURL: string | undefined): boolean {
const locator = remoteURL?.trim() ?? "";
if (!locator || locator.startsWith("/") || locator.startsWith("file:")) return false;
if (locator.startsWith("git@")) return true;
try {
const parsed = new URL(locator);
return Boolean(parsed.host) && ["https:", "http:", "ssh:", "git:"].includes(parsed.protocol);
} catch {
return false;
}
}
export function canChooseCheckoutBranchForSource(
sourceType: "saved_repository" | "local_repository" | "remote_repository" | "folder",
executorType: ExecutorType | string | null | undefined,
): boolean {
return (
sourceType !== "folder" && getWorkspaceSourceCapabilities(executorType).canChooseCheckoutBranch
);
}