feat(auth): separate filesystem read and write permissions #9788
Mergedjuliusmarmingemerged 40 commits into
t3code/auth-source-control-scope fromrefs/pull/9788/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
- apps/mobile/src/features/review/useReviewSections.ts line 55Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -30,7 +32,8 @@3032 }) {3133 const { environmentId, reviewCache, threadId } = input;3234 const enabled = input.enabled ?? true;35+ const canReadFiles = useEnvironmentScope(environmentId ?? null, AuthFilesystemReadScope);3336 const selectedThread = useSelectedThreadDetail();3437 const { selectedThreadCwd } = useSelectedThreadWorktree();3538 const diffPreview = useEnvironmentQuery(36- enabled && environmentId !== undefined && selectedThreadCwd !== null39+ canReadFiles && enabled && environmentId !== undefined && selectedThreadCwd !== null
juliusmarminge changed the title
- apps/mobile/src/features/threads/new-task-flow-provider.tsx line 507Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -378,5 +380,9 @@378380 // Default mode until the user picks one explicitly — same resolution web379381 // uses for new draft threads: per-project setting, then the repo's380382 // checked-in t3.json, then the server's configured default.383+ const canReadFiles = useEnvironmentScope(384+ selectedProject?.environmentId ?? null,385+ AuthFilesystemReadScope,386+ );381387 const t3ProjectFileQuery = useEnvironmentQuery(382- selectedProject !== null && selectedProject.workspaceRoot !== ""388+ canReadFiles && selectedProject !== null && selectedProject.workspaceRoot !== ""
- apps/web/src/components/DiffPanel.tsx line 268OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -259,4 +265,4 @@259265 { enabled: isGitRepo && selectedTurn !== undefined },260266 );261267 const primaryBranchDiffPreview = useEnvironmentQuery(262- selectedTurnId === null && activeThread && activeCwd268+ canReadFiles && selectedTurnId === null && activeThread && activeCwd
- @@ -1128,4 +1139,20 @@11281139 }),11291140 );11301141 })();1131- }, [absolutePath, createAssetUrl, cwd, environmentHttpBaseUrl, openPreview, threadRef]);1142+ }, [1143+ absolutePath,1144+ canReadFiles,1145+ createAssetUrl,1146+ cwd,1147+ environmentHttpBaseUrl,1148+ openPreview,1149+ threadRef,1150+ ]);1151+1152+ if (attachment === undefined && !canReadFiles) {1153+ return (1154+ <div className="p-4 text-sm text-muted-foreground">1155+ This connection cannot read host files.1156+ </div>1157+ );1158+ }
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
- @@ -1129,3 +1145,20 @@11291145 );11301146 })();1131- }, [absolutePath, createAssetUrl, cwd, environmentHttpBaseUrl, openPreview, threadRef]);1147+ }, [1148+ absolutePath,1149+ canReadFiles,1150+ createAssetUrl,1151+ cwd,1152+ environmentHttpBaseUrl,1153+ openPreview,1154+ threadRef,1155+ ]);1156+1157+ if (attachment === undefined && !canReadFiles) {1158+ if (fileAccessSession.data === null && fileAccessSession.error === null) {1159+ return (1160+ <div className="flex min-h-0 flex-1 items-center justify-center gap-2 text-sm text-muted-foreground">1161+ <LoaderCircle className="size-4 animate-spin" aria-hidden />1162+ Checking file access...1163+ </div>1164+ );
- @@ -14,2 +22,21 @@1422 import { createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";152324+export function resolveFilesystemReadAccess(input: {25+ readonly connection: Pick<EnvironmentConnectionPresentation, "phase" | "error"> | null;26+ readonly session: Pick<AuthSessionState, "authenticated" | "scopes"> | null;27+ readonly sessionError: string | null;28+}) {29+ if (input.sessionError !== null) {30+ return { canReadFiles: false, isPending: false, error: input.sessionError };31+ }32+ if (input.session === null) {33+ // An offline, unprepared environment cannot finish its session check.34+ const isPending =35+ input.connection?.phase === "connected" ||36+ input.connection?.phase === "connecting" ||37+ input.connection?.phase === "reconnecting";38+ return {39+ canReadFiles: false,40+ isPending,41+ error: isPending ? null : (input.connection?.error ?? "This environment is not connected."),42+ };
- apps/mobile/src/features/projects/AddProjectScreen.tsx line 803OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -791,3 +800,4 @@791800 return (792801 <>793802 <SectionTitle>Browse folders</SectionTitle>803+ {!canReadFiles ? <ErrorBanner message="This connection cannot browse host folders." /> : null}apps/mobile/src/features/threads/new-task-flow-provider.tsx line 422OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -403,3 +419,4 @@403419 explicitMode: selectedProjectDraft.workspaceSelection?.mode,404420 projectSetting: selectedProject?.defaultThreadEnvMode,405421 projectFilePending: t3ProjectFileQuery.isPending,422+ projectFilePermissionPending: fileAccessPending,
- apps/web/src/assets/assetUrls.ts line 33OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -20,9 +21,13 @@2021 environmentId: EnvironmentId | null,2122 resource: AssetResource | null,2223 ): AssetUrlState {24+ const canReadFiles = useEnvironmentScope(environmentId, AuthFilesystemReadScope);25+ const canReadResource =26+ canReadFiles || (resource?._tag !== "workspace-file" && resource?._tag !== "media-file");2327 const preparedConnection = usePreparedConnection(environmentId);2428 const result = useAtomValue(25- environmentId === null || resource === null29+ !canReadResource || environmentId === null || resource === null2630 ? EMPTY_ASSET_URL_ATOM2731 : assetEnvironment.createUrl({ environmentId, input: { resource } }),2832 );33+ if (!canReadResource) return { _tag: "Failure" };
- apps/mobile/src/features/review/useReviewSections.ts line 72OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -66,4 +69,4 @@6669 () =>6770 buildReviewSectionItems({6871 checkpoints: readyCheckpoints,69- gitSections: reviewCache.gitSections,72+ gitSections: canReadFiles ? reviewCache.gitSections : [],
- apps/mobile/src/features/review/useReviewSections.ts line 195OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -173,3 +193,3 @@173193174194 return {175195 error: diffPreview.error ?? activeTurnDiff.error ?? reviewCache.asyncState.error,
- apps/web/src/components/files/projectFilesQueryState.ts line 237OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -199,5 +233,5 @@199233 const optimisticFile = relativePath === null ? null : optimisticResult;200234201235 return {202- data: optimisticFile?.data ?? data,203- error: errorMessage(result),236+ data: canReadFiles ? (optimisticFile?.data ?? data) : null,237+ error: canReadFiles ? errorMessage(result) : "This connection cannot read host files.",
- apps/web/src/components/CommandPalette.tsx line 1010OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -997,4 +1001,10 @@9971001 : null,9981002 );9991003 const browseResult = browseQuery.data;1000- const isBrowsePending = browseQuery.isPending;1004+ const isBrowsePending = hasBrowseTarget && (browseAccess.isPending || browseQuery.isPending);1005+ const browseError =1006+ !hasBrowseTarget || browseAccess.isPending1007+ ? null1008+ : browseAccess.canReadFiles1009+ ? browseQuery.error1010+ : (browseAccess.error ?? "This connection cannot browse host folders.");
- @@ -288,8 +303,18 @@288- : null,303+ }304+ : null;305+ const result = useEnvironmentQuery(306+ canReadFiles && searchTarget !== null ? projectEnvironment.searchEntries(searchTarget) : null,289307 );308+ const hasTarget = searchTarget !== null;290309291310 return {292311 entries: result.data?.entries ?? [],293- error: result.error,312+ error:313+ !hasTarget || fileAccess.isPending314+ ? null315+ : canReadFiles316+ ? result.error317+ : (fileAccess.error ?? "This connection cannot search host files."),294318 isPending:295- !areProjectPathSearchTargetsEqual(normalizedTarget, debouncedTarget) || result.isPending,319+ !areProjectPathSearchTargetsEqual(normalizedTarget, debouncedTarget) ||320+ (hasTarget && (fileAccess.isPending || result.isPending)),
- apps/server/src/ws.ts lines 2468 to 2470OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2462,3 +2464,7 @@24622464 });24632465 }),24642466 { "rpc.aggregate": "workspace" },2467+ [2468+ input.resource._tag === "workspace-file" || input.resource._tag === "media-file"2469+ ? AuthFilesystemReadScope2470+ : AuthOrchestrationReadScope,apps/web/src/components/CommandPalette.tsx line 3006Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2212,3 +2223,4 @@22122223 const willCreateProjectPath =22132224 canSubmitBrowsePath &&22142225 !isBrowsePending &&2226+ browseAccessError === null &&
- apps/web/src/components/search/ProjectContentSearchDialog.test.tsx line 42OutdatedResolvedby juliusmarminge@@ -0,0 +22,21 @@22+ ),23+};24+25+vi.mock("~/hooks/useActiveProjectTarget", () => ({ useActiveProjectTarget: () => target }));26+vi.mock("~/hooks/useTheme", () => ({ useTheme: () => ({ resolvedTheme: "light" }) }));27+vi.mock("~/rightPanelStore", () => ({28+ useRightPanelStore: { getState: () => ({ openFile: state.openFile }) },29+}));30+vi.mock("~/state/session", () => ({ readEnvironmentScope: state.readScope }));31+vi.mock("~/state/queries", () => ({32+ useProjectContentSearch: ({ query }: { query: string }) => ({33+ canReadFiles: state.canReadFiles,34+ isCheckingAccess: state.isCheckingAccess,35+ error: state.error,36+ isPending: state.isCheckingAccess,37+ hasQuery: query.length > 0,38+ truncated: false,39+ invalidRegex: false,40+ matches:41+ state.canReadFiles && query.length > 042+ ? [{ path: "src/index.ts", lineNumber: 3, lineContent: "match", matchRanges: [] }]
juliusmarminge added labelsmacroscope-review
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
juliusmarminge merged this321c6f9
juliusmarminge closed this
Sign in to join this conversation.






Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result:
ca4ea2b· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.