Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions FORK.md

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ import { ComposerControl } from "./chat/ComposerControl";
import { MiddleTruncate } from "./ui/middle-truncate";
import { BranchPicker, BranchPickerRefItem } from "./BranchPicker";
import { stackedThreadToast, toastManager } from "./ui/toast";
import { useCanOperateThread } from "../j5/sharing/access";

export interface BranchToolbarBranchSelectorHandle {
open: () => void;
Expand Down Expand Up @@ -116,7 +117,7 @@ export function BranchToolbarBranchSelector({
}: BranchToolbarBranchSelectorProps) {
const composerFloatingLayerProps = useComposerMenuProps();
const canWriteSourceControl = useEnvironmentScope(environmentId, AuthSourceControlWriteScope);
const canOperateThread = useEnvironmentScope(environmentId, AuthOrchestrationOperateScope);
const canOperateThread = useCanOperateThread(environmentId, threadId);
const stopThreadSession = useAtomCommand(threadEnvironment.stopSession, "thread session stop");
const updateThreadMetadata = useAtomCommand(
threadEnvironment.updateMetadata,
Expand Down
61 changes: 49 additions & 12 deletions apps/web/src/components/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

import { useHighlightsPaletteItems } from "../j5/highlights/highlightsPalette";
import { useSharingPaletteItems } from "../j5/sharing/sharingPalette";
import { useCanAddProject, useCanStartIn } from "../j5/sharing/access";
import {
openableFromSearch,
startableMemberRef,
startableProjectPicker,
} from "../j5/sharing/startableProjects";
import { threadPullRequestLinkMode } from "@t3tools/client-runtime/thread-pull-request-compatibility";
import { visibleThreadPullRequests } from "@t3tools/shared/threadPullRequests";

Expand Down Expand Up @@ -914,6 +920,12 @@ function OpenCommandPaletteDialog(props: {
defaultProjectRef,
handleNewThread,
});
const canStartIn = useCanStartIn();
const startPicker = startableProjectPicker({
groups: projectGroups,
preferredProjectRef: contextualProjectRef,
canStartIn,
});
const projectPickerEntries = buildSidebarProjectPickerEntries({
groups: projectGroups,
preferredProjectRef: contextualProjectRef,
Expand Down Expand Up @@ -973,7 +985,7 @@ function OpenCommandPaletteDialog(props: {
}) ?? null;
const browseEnvironmentId =
sourcePicker?.environmentId ?? addProjectEnvironmentId ?? defaultAddProjectEnvironmentId;
const canCreateProject = useEnvironmentScope(browseEnvironmentId, AuthOrchestrationOperateScope);
const canCreateProject = useCanAddProject(browseEnvironmentId);
const browseEnvironment =
environments.find((environment) => environment.environmentId === browseEnvironmentId) ?? null;
const browseEnvironmentIsDesktopLocal =
Expand Down Expand Up @@ -1121,6 +1133,11 @@ function OpenCommandPaletteDialog(props: {
[browseNavigation],
);

const searchProjectKeysWithThreads = new Set(
threads.flatMap((thread) =>
thread.archivedAt === null ? [`${thread.environmentId}:${thread.projectId}`] : [],
),
);
const openProjectFromSearch = async (project: (typeof projects)[number]) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const groupedProjectKeys = group
Expand Down Expand Up @@ -1152,7 +1169,8 @@ function OpenCommandPaletteDialog(props: {
return;
}

await handleNewThread(scopeProjectRef(project.environmentId, project.id));
const startRef = startableMemberRef({ project, group, canStartIn });
if (startRef) await handleNewThread(startRef);
};

const projectSearchItems = buildProjectActionItems({
Expand Down Expand Up @@ -1189,17 +1207,30 @@ function OpenCommandPaletteDialog(props: {
},
icon: projectFaviconIcon,
runProject: openProjectFromSearch,
}).map((item, index) => {
// J5: a project with no thread to open and no checkout this person may start one in is shown
// but cannot be picked, as upstream shows a server that is not connected.
const project = pickerProjects[index];
const openable =
!project ||
openableFromSearch({
project,
group: projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`),
projectKeysWithThreads: searchProjectKeysWithThreads,
canStartIn,
});
return openable ? item : { ...item, disabled: true };
});

const projectThreadItems = (() => {
const isScratch = (project: CommandPaletteProject) =>
isScratchProject(project, scratchWorkspaceRootFor(project.environmentId));
const projectItems = enumerateCommandPaletteItems(
buildProjectActionItems({
projects: pickerProjects.filter((project) => !isScratch(project)),
projects: startPicker.projects.filter((project) => !isScratch(project)),
valuePrefix: "new-thread-in",
searchTerms: (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const group = startPicker.groupByTargetKey.get(`${project.environmentId}:${project.id}`);
const location = projectEnvironmentLocationById.get(project.environmentId);
return [
...(group?.memberProjects.flatMap((member) => [member.title, member.workspaceRoot]) ??
Expand Down Expand Up @@ -1232,7 +1263,7 @@ function OpenCommandPaletteDialog(props: {
},
icon: projectFaviconIcon,
runProject: async (project) => {
const group = projectGroupByTargetKey.get(`${project.environmentId}:${project.id}`);
const group = startPicker.groupByTargetKey.get(`${project.environmentId}:${project.id}`);
const contextualRefBelongsToGroup =
contextualProjectRef !== null &&
group?.memberProjectRefs.some(
Expand Down Expand Up @@ -1654,12 +1685,16 @@ function OpenCommandPaletteDialog(props: {
});
const highlightsPaletteItems = useHighlightsPaletteItems();
const actionItems: Array<CommandPaletteActionItem | CommandPaletteSubmenuItem> = [];
if (projects.length > 0) {
if (projects.length > 0 && projectThreadItems.length > 0) {
const activeProjectTitle =
projectPickerEntries.find((entry) => entry.isPreferred)?.group.displayName ??
(currentProjectId ? (projectTitleById.get(currentProjectId) ?? null) : null);

if (activeProjectTitle) {
if (
activeProjectTitle &&
contextualProjectRef !== null &&
canStartIn(contextualProjectRef.environmentId, contextualProjectRef.projectId)
) {
actionItems.push({
kind: "action",
value: "action:new-thread",
Expand Down Expand Up @@ -2395,6 +2430,7 @@ function OpenCommandPaletteDialog(props: {
newProjectFlow !== null &&
newProjectName.length > 0 &&
!isCreatingNewProject &&
canCreateProject &&
canCreateProjectInEnvironment(browseEnvironment?.connection.phase);

async function submitNewProject(): Promise<void> {
Expand Down Expand Up @@ -2894,10 +2930,7 @@ function OpenCommandPaletteDialog(props: {
addProjectCloneFlow?.environmentId ?? null,
AuthSourceControlWriteScope,
);
const canCreateClonedProject = useEnvironmentScope(
addProjectCloneFlow?.environmentId ?? null,
AuthOrchestrationOperateScope,
);
const canCreateClonedProject = useCanAddProject(addProjectCloneFlow?.environmentId ?? null);
const canCloneProject = canWriteSourceControl && canCreateClonedProject;
const isCloneDestinationStep = addProjectCloneFlow?.step === "confirm";
const canSubmitBrowsePath =
Expand Down Expand Up @@ -3232,7 +3265,11 @@ function OpenCommandPaletteDialog(props: {
<Kbd>{createShortcutLabel}</Kbd>
</KbdGroup>
</TooltipTrigger>
<TooltipPopup side="top">{`Create (${createShortcutLabel})`}</TooltipPopup>
<TooltipPopup side="top">
{canCreateProject
? `Create (${createShortcutLabel})`
: "This connection cannot add projects."}
</TooltipPopup>
</Tooltip>
) : addProjectCloneFlow?.step === "repository" ? (
<Tooltip>
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/components/GitActionsControl.lifecycle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ vi.mock("~/state/session", () => ({
readEnvironmentScope: (environmentId: unknown, scope: string) =>
(environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
}));
// J5 (case 73): the thread's level is J5's; these tests hold the session's permission alone.
vi.mock("~/j5/sharing/access", () => ({
useCanOperateThread: (environmentId: unknown) =>
(environmentId === "environment" ? state.scopes : state.primaryScopes).has(
"orchestration:operate",
),
}));
vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: { discovery: () => null } }));
Expand Down
7 changes: 7 additions & 0 deletions apps/web/src/components/GitActionsControl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ vi.mock("~/state/session", () => ({
readEnvironmentScope: (environmentId: unknown, scope: string) =>
(environmentId === "environment" ? state.scopes : state.primaryScopes).has(scope),
}));
// J5 (case 73): the thread's level is J5's; these tests hold the session's permission alone.
vi.mock("~/j5/sharing/access", () => ({
useCanOperateThread: (environmentId: unknown) =>
(environmentId === "environment" ? state.scopes : state.primaryScopes).has(
"orchestration:operate",
),
}));
vi.mock("~/state/use-atom-command", () => ({ useAtomCommand: (command: unknown) => command }));
vi.mock("~/state/server", () => ({ serverEnvironment: { configValueAtom: () => null } }));
vi.mock("~/state/sourceControl", () => ({ sourceControlEnvironment: {} }));
Expand Down
8 changes: 7 additions & 1 deletion apps/web/src/components/GitActionsControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ import {
} from "~/lib/sourceControlActions";
import { useThreadProjection, useThreadShell } from "~/state/entities";
import { readEnvironmentScope, useEnvironmentScope } from "~/state/session";
import { useCanOperateThread } from "~/j5/sharing/access";
import { useEnvironmentQuery } from "~/state/query";
import { serverEnvironment } from "~/state/server";
import { sourceControlEnvironment } from "~/state/sourceControl";
Expand Down Expand Up @@ -1004,6 +1005,10 @@ export default function GitActionsControl({
AuthSourceControlWriteScope,
);
const canOperateThread = useEnvironmentScope(activeEnvironmentId, AuthOrchestrationOperateScope);
const canOperateThisThread = useCanOperateThread(
activeEnvironmentId,
activeThreadRef?.threadId ?? null,
);
const serverConfig = useAtomValue(serverEnvironment.configValueAtom(activeEnvironmentId));
const openInPreferredEditor = useOpenInPreferredEditor(
activeEnvironmentId,
Expand All @@ -1028,7 +1033,8 @@ export default function GitActionsControl({
const activeServerThread =
activeServerThreadShell ?? activeServerThreadProjection?.projection.thread ?? null;
const isLocalDraftThread = activeDraftThread !== null && activeServerThread === null;
const canChangeThreadBranch = canWriteSourceControl && (isLocalDraftThread || canOperateThread);
const canChangeThreadBranch =
canWriteSourceControl && (isLocalDraftThread || canOperateThisThread);
const setDraftThreadContext = useComposerDraftStore((store) => store.setDraftThreadContext);
const [isCommitDialogOpen, setIsCommitDialogOpen] = useState(false);
const [dialogCommitMessage, setDialogCommitMessage] = useState("");
Expand Down
19 changes: 17 additions & 2 deletions apps/web/src/components/LegacySidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ import { useDesktopUpdateState } from "../state/desktopUpdate";

import { useThreadActions } from "../hooks/useThreadActions";
import { archiveWithPreflight } from "../j5/a2a/archiveFlow";
import { useCanStartInAny } from "../j5/sharing/access";
import { readCanStartThreadIn } from "../j5/sharing/startAccess";
import { projectEnvironment } from "../state/projects";
import { threadEnvironment, useEnvironmentThread } from "../state/threads";
import { useEnvironment, useEnvironments, usePrimaryEnvironmentId } from "../state/environments";
Expand Down Expand Up @@ -1174,6 +1176,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
isManualProjectSorting,
dragHandleProps,
} = props;
const canStartThreadHere = useCanStartInAny(project.memberProjects);
const environmentMachine = project.allRemoteMembersAreWsl
? "linux"
: project.allRemoteMembersAreDesktopLocal
Expand Down Expand Up @@ -2111,6 +2114,7 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
project.memberProjects.map((member) => ({
id: member.physicalProjectKey,
label: formatProjectMemberActionLabel(member, project.groupedProjectCount),
disabled: !readCanStartThreadIn(scopeProjectRef(member.environmentId, member.id)),
})),
{
x: event.clientX,
Expand Down Expand Up @@ -2328,7 +2332,15 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
const clicked = await api.contextMenu.show(
[
...(thread.branch
? [{ id: "new-thread-on-branch", label: `New thread on ${thread.branch}` }]
? [
{
id: "new-thread-on-branch",
label: `New thread on ${thread.branch}`,
disabled: !readCanStartThreadIn(
scopeProjectRef(thread.environmentId, thread.projectId),
),
},
]
: []),
{ id: "rename", label: "Rename thread", disabled: !canOperateThread },
{ id: "mark-unread", label: "Mark unread" },
Expand Down Expand Up @@ -2531,7 +2543,10 @@ const SidebarProjectItem = memo(function SidebarProjectItem(props: SidebarProjec
<Tooltip>
<TooltipTrigger
render={
<div className="pointer-events-none absolute top-[calc(50%+1px)] right-0.5 -translate-y-1/2 opacity-0 transition-opacity duration-150 max-sm:pointer-events-auto max-sm:opacity-100 group-hover/project-header:pointer-events-auto group-hover/project-header:opacity-100 group-focus-within/project-header:pointer-events-auto group-focus-within/project-header:opacity-100">
<div
hidden={!canStartThreadHere}
className="pointer-events-none absolute top-[calc(50%+1px)] right-0.5 -translate-y-1/2 opacity-0 transition-opacity duration-150 max-sm:pointer-events-auto max-sm:opacity-100 group-hover/project-header:pointer-events-auto group-hover/project-header:opacity-100 group-focus-within/project-header:pointer-events-auto group-focus-within/project-header:opacity-100"
>
<button
type="button"
aria-label={`Create new thread in ${project.displayName}`}
Expand Down
10 changes: 8 additions & 2 deletions apps/web/src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,9 @@ import type { EnvironmentProject } from "@t3tools/client-runtime/state/shell";
import { cn } from "~/lib/utils";
import { EnvironmentMachineIcon } from "./EnvironmentMachineIcon";
import { ProjectEnvironmentBadge } from "./ProjectEnvironmentBadge";
import { useIsNarrowEverywhere } from "../j5/sharing/access";
import { useCanStartInAny, useIsNarrowEverywhere } from "../j5/sharing/access";
import { buildWithSharingMenuItems, runSharingMenuAction } from "../j5/sharing/sharingMenu";
import { readStartableProjectRef } from "../j5/sharing/startableProjects";
import {
buildDraftActionMenuItems,
buildThreadActionMenuItems,
Expand Down Expand Up @@ -2716,6 +2717,7 @@ export default function Sidebar() {
const newThreadContext = useHandleNewThread();
const primaryEnvironmentId = usePrimaryEnvironmentId();
const isNarrowEverywhere = useIsNarrowEverywhere();
const canStartInAnyProject = useCanStartInAny(projects);
const clearSelection = useThreadSelectionStore((s) => s.clearSelection);
const setSelectionAnchor = useThreadSelectionStore((s) => s.setAnchor);
const toggleThreadSelection = useThreadSelectionStore((s) => s.toggleThread);
Expand Down Expand Up @@ -4497,6 +4499,10 @@ export default function Sidebar() {
activeThread: newThreadContext.activeThread ?? undefined,
defaultProjectRef: newThreadContext.defaultProjectRef,
handleNewThread: newThreadContext.handleNewThread,
}).then((started) => {
// J5: a project this person cannot start in hands a plain click to one they can.
const fallback = started || event?.shiftKey ? null : readStartableProjectRef(projectGroups);
if (fallback) void newThreadContext.handleNewThread(fallback);
});
return;
}
Expand Down Expand Up @@ -4645,7 +4651,7 @@ export default function Sidebar() {
}
onNewProject={openAddProjectCommandPalette}
onNewThread={handleNewThreadClick}
newThreadDisabled={projects.length === 0}
newThreadDisabled={!canStartInAnyProject}
newThreadShortcutLabel={newThreadShortcutLabel}
newThreadInProjectShortcutLabel={newThreadInProjectShortcutLabel}
showNewThreadInProjectHint={projectGroups.length > 1}
Expand Down
6 changes: 6 additions & 0 deletions apps/web/src/components/chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ThreadPeopleChip } from "../../j5/sharing/ThreadPeople";
import { useCanStartThreadIn } from "../../j5/sharing/access";
import {
AuthOrchestrationOperateScope,
type EnvironmentId,
Expand Down Expand Up @@ -83,6 +84,10 @@ export const ChatHeader = memo(function ChatHeader({
}: ChatHeaderProps) {
const activeProjectName = activeProject?.title;
const activeProjectCwd = activeProject?.workspaceRoot ?? null;
const canStartInProject = useCanStartThreadIn(
activeProject?.environmentId ?? null,
activeProject?.id ?? null,
);
const interfaceFont = useClientSettings((settings) => settings.fontFamilySans);
const breadcrumbContainerRef = useRef<HTMLDivElement>(null);
const [collapseParentTitle, setCollapseParentTitle] = useState(false);
Expand Down Expand Up @@ -299,6 +304,7 @@ export const ChatHeader = memo(function ChatHeader({
type="button"
aria-label={`New thread in ${activeProjectName}`}
onClick={onNewThreadInProject}
disabled={!canStartInProject}
className="inline-flex min-w-0 max-w-full cursor-pointer items-center gap-1.5 rounded-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
/>
}
Expand Down
7 changes: 6 additions & 1 deletion apps/web/src/components/chat/MessagesTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ import {
useSharedConversationEntries,
useSharedMessageAuthor,
} from "../../j5/sharing/sharedTimeline";
import { useCanForkThread } from "../../j5/sharing/access";
import { ThreadContextChip } from "../ThreadContextChip";
import {
participantIdsForThreadA2ADelivery,
Expand Down Expand Up @@ -2740,8 +2741,12 @@ function AssistantForkButton({
projectedItem,
capabilities: support.providerSession?.capabilities,
});
const canStartFork = useCanForkThread(
ctx.activeThreadEnvironmentId,
projectedItem.sourceThreadId,
);

if (!canFork || projectedItem.item.runId === null) return null;
if (!canFork || !canStartFork || projectedItem.item.runId === null) return null;
const runId = projectedItem.item.runId;

return (
Expand Down
Loading
Loading