feat(auth): separate source control write permissions #9787
Mergedjuliusmarmingemerged 43 commits into
t3code/auth-environment-scopes fromrefs/pull/9787/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge changed the title
- packages/contracts/src/auth.ts line 119Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -114,3 +116,4 @@114116 AuthEnvironmentMaintainScope,115117 AuthTerminalOperateScope,116118 AuthReviewWriteScope,119+ AuthSourceControlWriteScope,
- apps/web/src/components/GitActionsControl.tsx line 1287OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1271,3 +1284,4 @@12711284 progressToastId,12721285 filePaths,12731286 }: RunGitActionWithToastInput) => {1287+ if (!canWriteSourceControl) return;apps/web/src/hooks/useThreadActions.ts line 334OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -322,4 +328,7 @@322328 const displayWorktreePath = orphanedWorktreePath323329 ? formatWorktreePathForDisplay(orphanedWorktreePath)324330 : null;325- const canDeleteWorktree = orphanedWorktreePath !== null && threadProject !== null;331+ const canDeleteWorktree =332+ orphanedWorktreePath !== null &&333+ threadProject !== null &&334+ readEnvironmentScope(threadRef.environmentId, AuthSourceControlWriteScope);
- apps/server/src/auth/RpcAuthorization.ts line 119OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -109,13 +110,10 @@109110 [WS_METHODS.subscribeVcsStatus]: AuthOrchestrationReadScope,110111 [WS_METHODS.subscribeResourceTelemetry]: AuthOrchestrationReadScope,111112 [WS_METHODS.vcsRefreshStatus]: AuthOrchestrationReadScope,112- [WS_METHODS.vcsPull]: AuthOrchestrationOperateScope,113- [WS_METHODS.gitRunStackedAction]: AuthOrchestrationOperateScope,114- [WS_METHODS.gitResolvePullRequest]: AuthOrchestrationOperateScope,115- [WS_METHODS.gitPreparePullRequestThread]: AuthOrchestrationOperateScope,113+ [WS_METHODS.vcsPull]: AuthSourceControlWriteScope,114+ [WS_METHODS.gitRunStackedAction]: AuthSourceControlWriteScope,115+ [WS_METHODS.gitResolvePullRequest]: AuthOrchestrationReadScope,116+ [WS_METHODS.gitPreparePullRequestThread]: AuthSourceControlWriteScope,116117 [WS_METHODS.vcsListRefs]: AuthOrchestrationReadScope,117- [WS_METHODS.vcsCreateWorktree]: AuthOrchestrationOperateScope,118- [WS_METHODS.vcsRemoveWorktree]: AuthOrchestrationOperateScope,119- [WS_METHODS.vcsCreateRef]: AuthOrchestrationOperateScope,120- [WS_METHODS.vcsSwitchRef]: AuthOrchestrationOperateScope,121- [WS_METHODS.vcsInit]: AuthOrchestrationOperateScope,118+ [WS_METHODS.vcsCreateWorktree]: AuthSourceControlWriteScope,119+ [WS_METHODS.vcsRemoveWorktree]: AuthSourceControlWriteScope,
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XL
- @@ -322,5 +332,7 @@322332 const displayWorktreePath = orphanedWorktreePath323333 ? formatWorktreePathForDisplay(orphanedWorktreePath)324334 : null;325- const canDeleteWorktree = orphanedWorktreePath !== null && threadProject !== null;326335 const localApi = readLocalApi();336+ let canDeleteWorktree = false;337+ if (orphanedWorktreePath !== null && threadProject !== null && localApi) {338+ const sessionResult = await loadSessionState(threadRef.environmentId);
- @@ -322,5 +332,9 @@322332 const displayWorktreePath = orphanedWorktreePath323333 ? formatWorktreePathForDisplay(orphanedWorktreePath)324334 : null;325- const canDeleteWorktree = orphanedWorktreePath !== null && threadProject !== null;326335 const localApi = readLocalApi();336+ let canDeleteWorktree = false;337+ if (orphanedWorktreePath !== null && threadProject !== null && localApi) {338+ const sessionResult = await loadSessionState(threadRef.environmentId);339+ if (sessionResult._tag === "Failure") {340+ return sessionResult;
- apps/mobile/src/features/projects/AddProjectScreen.tsx line 940OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -924,4 +936,5 @@924936 const [error, setError] = useState<string | null>(null);925937926938 const submitPath = useCallback(async () => {927- if (!environment || !remoteUrl || isBrowseNavigating || isSubmitting) return;939+ if (940+ !canWriteSourceControl ||
- apps/web/src/components/GitActionsControl.tsx line 1030OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1012,3 +1027,4 @@10121027 const activeServerThread = useThread(activeThreadRef, {10131028 waitForShell: activeDraftThread !== null,10141029 });1030+ const canChangeThreadBranch = canWriteSourceControl && (!activeServerThread || canOperateThread);
- apps/server/src/auth/RpcAuthorization.ts line 116OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -109,7 +110,7 @@109110 [WS_METHODS.subscribeVcsStatus]: AuthOrchestrationReadScope,110111 [WS_METHODS.subscribeResourceTelemetry]: AuthOrchestrationReadScope,111112 [WS_METHODS.vcsRefreshStatus]: AuthOrchestrationReadScope,112- [WS_METHODS.vcsPull]: AuthOrchestrationOperateScope,113- [WS_METHODS.gitRunStackedAction]: AuthOrchestrationOperateScope,114- [WS_METHODS.gitResolvePullRequest]: AuthOrchestrationOperateScope,115- [WS_METHODS.gitPreparePullRequestThread]: AuthOrchestrationOperateScope,113+ [WS_METHODS.vcsPull]: AuthSourceControlWriteScope,114+ [WS_METHODS.gitRunStackedAction]: AuthSourceControlWriteScope,115+ [WS_METHODS.gitResolvePullRequest]: AuthOrchestrationReadScope,116+ [WS_METHODS.gitPreparePullRequestThread]: AuthSourceControlWriteScope,apps/web/src/components/BranchToolbarBranchSelector.tsx line 685Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -696,3 +722,4 @@696722 index={index}697723 value={itemValue}698724 className="pe-1.5"725+ disabled={
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:XL
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
- apps/web/src/hooks/useThreadActions.ts line 462OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -426,7 +449,14 @@426- environmentId: threadRef.environmentId,427- input: {428- cwd: threadProject.workspaceRoot,429- path: orphanedWorktreePath,430- force: true,431- },432- });449+ const removeResult = readEnvironmentScope(450+ threadRef.environmentId,451+ AuthSourceControlWriteScope,452+ )453+ ? await removeWorktree({454+ environmentId: threadRef.environmentId,455+ input: {456+ cwd: threadProject.workspaceRoot,457+ path: orphanedWorktreePath,458+ force: true,459+ },460+ })461+ : AsyncResult.failure(462+ Cause.fail(new Error("This connection can no longer remove worktrees.")),apps/web/src/hooks/useThreadActions.ts lines 155 to 158OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -144,3 +152,7 @@144152 );145153 }146154155+function threadOperationFailure(target: ScopedThreadRef) {156+ return readEnvironmentScope(target.environmentId, AuthOrchestrationOperateScope)157+ ? null158+ : AsyncResult.failure(Cause.fail(new Error("This connection cannot change threads.")));
- apps/web/src/components/GitActionsControl.tsx line 1112Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -1009,6 +1024,6 @@10091024 ? store.getDraftThreadByRef(activeThreadRef)10101025 : null,10111026 );1012- const activeServerThread = useThread(activeThreadRef, {1013- waitForShell: activeDraftThread !== null,1014- });1027+ const activeServerThread = useThreadShell(activeThreadRef);1028+ const isLocalDraftThread = activeDraftThread !== null && activeServerThread === null;1029+ const canChangeThreadBranch = canWriteSourceControl && (isLocalDraftThread || canOperateThread);
- apps/mobile/src/features/threads/git/GitOverviewSheet.tsx line 307OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -274,4 +303,5 @@274303 <SheetListRow275304 icon="point.topleft.down.curvedto.point.bottomright.up"276305 title="Branches & worktrees"277- subtitle="Switch branch, create branch, or move to a worktree"306+ subtitle={307+ canWriteSourceControl
- apps/mobile/src/features/threads/git/GitBranchesSheet.tsx line 96OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -82,8 +88,9 @@8288 icon="plus"8389 label="Create & checkout"8490 tone="primary"85- disabled={busy || newBranchName.trim().length === 0}91+ disabled={!canChangeThreadBranch || busy || newBranchName.trim().length === 0}8692 onPress={() => {93+ if (!canChangeThreadBranch) return;8794 const branch = sanitizeFeatureBranchName(newBranchName.trim());8895 if (branch.length === 0) return;8996 void gitActions.onCreateSelectedThreadBranch(branch).then(() => {apps/web/src/components/Sidebar.tsx lines 3130 to 3130OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -3065,5 +3121,10 @@30653121 const clicked = await settlePromise(() =>30663122 api.contextMenu.show(30673123 [3068- ...(unpinMenuItem ? [unpinMenuItem] : []),3069- { id: "settle", label: `Settle (${count})` },3124+ ...(unpinMenuItem3125+ ? [{ ...unpinMenuItem, disabled: !canOperateThreads(pinnedSelectedThreads) }]3126+ : []),3127+ {3128+ id: "settle",3129+ label: `Settle (${count})`,3130+ disabled: !canOperateThreads(settlingThreads),
- apps/web/src/state/sourceControlActions.ts line 99Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -84,3 +93,8 @@84938594 const run = useCallback(8695 async (...args: TArgs) => {96+ if (97+ input.scope.environmentId === null ||98+ !readEnvironmentScope(input.scope.environmentId, AuthSourceControlWriteScope)99+ ) {100+ return AsyncResult.failure<never, EnvironmentAuthorizationError>(
- apps/mobile/src/features/projects/AddProjectScreen.tsx lines 692 to 702Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -581,4 +600,10 @@581600582601 return useCallback(583602 async (workspaceRoot: string) => {584- if (!environment || !canCreateProjectInEnvironment(environment.connectionState)) return;603+ if (604+ !environment ||605+ !canCreateProjectInEnvironment(environment.connectionState) ||606+ !readEnvironmentScope(environment.environmentId, AuthOrchestrationOperateScope)607+ ) {608+ return;609+ }apps/mobile/src/features/threads/git/GitCommitSheet.tsx line 63Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -53,5 +54,6 @@53545455 const runCommitAction = useCallback(5556 async (featureBranch: boolean) => {57+ if (!canWriteSourceControl || (featureBranch && !canChangeThreadBranch)) return;5658 const commitMessage = dialogCommitMessage.trim();5759 navigation.goBack();@@ -5419,3 +5418,4 @@54195418 });54205419 }, [activeBranchMismatchKey, showBranchMismatchBanner]);54215420 const handleSwitchCheckoutToThread = useCallback(async () => {5421+ if (!canWriteSourceControl) return;
- apps/web/src/components/Sidebar.tsx lines 1543 to 1544Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -1327,4 +1363,8 @@13271363 // Snooze is offered only where it can succeed: capability-gated and never13281364 // on blocked-on-you work or queued turns (the server rejects both).13291365 const showSnoozeButton =1330- props.snoozeSupported && canSnooze(thread, { now: new Date().toISOString() });1366+ canOperateThread &&1367+ props.snoozeSupported &&1368+ canSnooze(thread, { now: new Date().toISOString() });1369+ const showHoverActions =1370+ (canOperateThread && props.settlementSupported) || showSnoozeButton || hasUnsentDraft;
- @@ -2089,4 +2103,6 @@20892103 }2090210420912105 const rawDestination = (destinationPathInput ?? query).trim();2092- if (rawDestination.length === 0 || isRemoteProjectCloning) {2106+ if (2107+ !readEnvironmentScope(addProjectCloneFlow.environmentId, AuthSourceControlWriteScope) ||2108+ !readEnvironmentScope(addProjectCloneFlow.environmentId, AuthOrchestrationOperateScope) ||apps/web/src/state/sourceControlActions.ts lines 333 to 346Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -324,3 +347,17 @@324347 ),325348 );326349 }350+ if (351+ input.mode === "worktree" &&352+ input.threadId !== undefined &&353+ !readEnvironmentScope(target.environmentId, AuthOrchestrationOperateScope)354+ ) {355+ return AsyncResult.failure<never, EnvironmentAuthorizationError>(356+ Cause.fail(357+ new EnvironmentAuthorizationError({358+ requiredScope: AuthOrchestrationOperateScope,359+ message: "This connection cannot change threads.",360+ }),361+ ),362+ );363+ }
juliusmarminge added labelsmacroscope-review
juliusmarminge merged this2eda8ac
juliusmarminge closed this
Sign in to join this conversation.






macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed