Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(desktop): add gfs drag session coordinator and move newName IPC chain
M5ed77183afbe
diff --git a/desktop-app/src/appService.ts b/desktop-app/src/appService.tsindex 795d72d6d..a7cb50486 100644--- a/desktop-app/src/appService.ts+++ b/desktop-app/src/appService.ts@@ -2803,15 +2803,17 @@ export class AppService {* Move a resource into a destination folder (PATCH newParentId). Move* authority is parent-relative (write+delete on the old parent, write on the* destination) and is enforced server-side; ifMatch pins the resource version.+ * An optional newName performs a combined rename+move in the same PATCH.*/async moveGfsResource(resourceId: string,destinationId: string,drive?: string,- ifMatch?: number+ ifMatch?: number,+ newName?: string) {return this.gfsClient.moveResource(- { resourceId, drive, destinationId, ifMatch },+ { resourceId, drive, destinationId, ifMatch, ...(newName !== undefined ? { newName } : {}) },this.requireSessionToken())}diff --git a/desktop-app/src/gfs/uriHandler.ts b/desktop-app/src/gfs/uriHandler.tsindex 84d1d606b..05ae76d21 100644--- a/desktop-app/src/gfs/uriHandler.ts+++ b/desktop-app/src/gfs/uriHandler.ts@@ -253,6 +253,8 @@ export interface GfsMoveInput {drive?: stringdestinationId: stringifMatch?: number+ /** Optional combined rename+move; the server requires `write` on the resource for it. */+ newName?: string}export interface GfsDeleteInput {@@ -382,6 +384,7 @@ async function moveGfsResource(q.set('drive', input.drive ?? DEFAULT_DRIVE)const body: Record<string, unknown> = { newParentId: input.destinationId }if (input.ifMatch !== undefined) body.ifMatch = input.ifMatch+ if (input.newName !== undefined) body.newName = input.newNameconst path = `/api/v1/me/gfs/resources/${encodeURIComponent(input.resourceId)}?${q.toString()}`const options = { body } as { token?: string; body?: unknown }options[TRANSPORT_TOKEN_FIELD] = sessiondiff --git a/desktop-app/src/ipc.ts b/desktop-app/src/ipc.tsindex 67038e6cd..c96f84180 100644--- a/desktop-app/src/ipc.ts+++ b/desktop-app/src/ipc.ts@@ -787,7 +787,13 @@ export function registerIpcHandlers(service: AppService): void {'gfs:moveResource',async (event,- payload: { resourceId: string; destinationId: string; drive?: string; ifMatch?: number }+ payload: {+ resourceId: string+ destinationId: string+ drive?: string+ ifMatch?: number+ newName?: string+ }) => {assertTrustedSender(event)const drive = payload?.drive ? sanitizeString(payload.drive) : undefined@@ -795,7 +801,8 @@ export function registerIpcHandlers(service: AppService): void {sanitizeString(payload?.resourceId),sanitizeString(payload?.destinationId),drive,- sanitizeOptionalInteger(payload?.ifMatch)+ sanitizeOptionalInteger(payload?.ifMatch),+ payload?.newName !== undefined ? sanitizeString(payload.newName) : undefined)})diff --git a/desktop-app/src/preload.ts b/desktop-app/src/preload.tsindex 5c54f57c4..2a89748cb 100644--- a/desktop-app/src/preload.ts+++ b/desktop-app/src/preload.ts@@ -206,8 +206,13 @@ const clerum = Object.freeze({getPathForFile: (file: File) => webUtils.getPathForFile(file),renameResource: (resourceId: string, newName: string, drive?: string, ifMatch?: number) =>ipcRenderer.invoke('gfs:renameResource', { resourceId, newName, drive, ifMatch }),- moveResource: (resourceId: string, destinationId: string, drive?: string, ifMatch?: number) =>- ipcRenderer.invoke('gfs:moveResource', { resourceId, destinationId, drive, ifMatch }),+ moveResource: (+ resourceId: string,+ destinationId: string,+ drive?: string,+ ifMatch?: number,+ newName?: string+ ) => ipcRenderer.invoke('gfs:moveResource', { resourceId, destinationId, drive, ifMatch, newName }),deleteResource: (resourceId: string, drive?: string, ifMatch?: number) =>ipcRenderer.invoke('gfs:deleteResource', { resourceId, drive, ifMatch }),grant: (diff --git a/desktop-app/src/renderer.d.ts b/desktop-app/src/renderer.d.tsindex 263188016..bae880706 100644--- a/desktop-app/src/renderer.d.ts+++ b/desktop-app/src/renderer.d.ts@@ -376,7 +376,8 @@ declare global {resourceId: string,destinationId: string,drive?: string,- ifMatch?: number+ ifMatch?: number,+ newName?: string) => Promise<{ resourceId: string; version: number }>deleteResource: (resourceId: string,diff --git a/desktop-app/ui/src/constants/gfsBrowser.ts b/desktop-app/ui/src/constants/gfsBrowser.tsindex 2e4f57a40..3f86d378a 100644--- a/desktop-app/ui/src/constants/gfsBrowser.ts+++ b/desktop-app/ui/src/constants/gfsBrowser.ts@@ -2,3 +2,21 @@ export const GFS_BREADCRUMB_MAX_DEPTH = 64/** Drive the desktop Files page browses (single-drive user plane today). */export const GFS_DRIVE_MAIN = 'main'++/** Internal EvenDrive drag payload type, shared by the Files page and the+ * sidebar file explorer. Carries the resourceId as an identity POINTER only:+ * handlers never derive authority or copy from payload data — the active+ * in-window drag descriptor is the source of identity (rev-2 §4). */+export const GFS_RESOURCE_DRAG_TYPE = 'application/x-evenfire-gfs-resource'++/** Hovering a collapsed folder for this long expands it through its existing+ * loader; canceled on leave/drop/drag end (rev-2 §4.1). */+export const FOLDER_HOVER_EXPAND_DELAY_MS = 600++/** A cold hover target is checked only after this dwell, so sweeping the tree+ * does not spend feature requests (rev-2 §4.1). */+export const DRAG_COLD_CHECK_DEBOUNCE_MS = 150++/** At most this many NEW cold destination checks per drag; beyond it targets+ * stay "checking" and receive a priority check on drop (rev-2 §4.1). */+export const DRAG_COLD_CHECK_BUDGET = 8diff --git a/desktop-app/ui/src/gfs/dragSession.tsx b/desktop-app/ui/src/gfs/dragSession.tsxnew file mode 100644index 000000000..198315317--- /dev/null+++ b/desktop-app/ui/src/gfs/dragSession.tsx@@ -0,0 +1,117 @@+import React, { createContext, useContext, useEffect, useMemo, useRef } from 'react'+import { useQuery } from '@tanstack/react-query'+import { useAuthContext } from '@contexts/AuthContext'+import { desktopQueryKeys } from '@hooks/domain/queryKeys'+import type { GfsDragSessionApi, GfsDragSource } from './dragSession.types'++/**+ * Per-session drag coordinator (rev-2 §4): exactly one active in-window+ * source, held in refs (dragover never re-renders the tree). The store is+ * bound to the live session scope and the SHARED access-state query, so a+ * logout, env/user/team switch or a definite lifecycle rejection clears the+ * drag. Payload identity is the in-window descriptor; generations only+ * discard stale async callbacks — they are not credentials or a wire registry.+ */+export class GfsDragSessionStore implements GfsDragSessionApi {+ private active: GfsDragSource | null = null+ private generation = 0+ private boundScope: string | null = null++ beginDrag(source: Omit<GfsDragSource, 'generation'>): boolean {+ if (this.active) return false+ this.generation += 1+ this.active = { ...source, generation: this.generation }+ this.boundScope = source.scope+ return true+ }++ endDrag(): void {+ this.active = null+ }++ activeSource(): GfsDragSource | null {+ return this.active+ }++ matchesScope(scope: string | null): boolean {+ return this.active !== null && scope !== null && this.boundScope === scope+ }++ invalidate(): void {+ this.active = null+ // Bump so in-flight callbacks captured against an older generation are+ // discarded by their owners (`source.generation !== activeSource()`).+ this.generation += 1+ }++ currentGeneration(): number {+ return this.generation+ }+}++const GfsDragSessionContext = createContext<GfsDragSessionApi | null>(null)++function sessionScopeOf(auth: {+ isAuthenticated: boolean+ me: { id: string; teamId: string | null } | null+ runtimeConfigState: { envKey: string } | null+}): string | null {+ const envKey = auth.runtimeConfigState?.envKey ?? ''+ return auth.isAuthenticated && auth.me+ ? `${envKey}:${auth.me.id}:${auth.me.teamId ?? ''}`+ : null+}++export function GfsDragSessionProvider({ children }: { children: React.ReactNode }) {+ const storeRef = useRef<GfsDragSessionStore | null>(null)+ if (!storeRef.current) storeRef.current = new GfsDragSessionStore()+ const store = storeRef.current++ const { isAuthenticated, me, runtimeConfigState } = useAuthContext()+ const scope = useMemo(+ () => sessionScopeOf({ isAuthenticated, me, runtimeConfigState }),+ [isAuthenticated, me, runtimeConfigState]+ )++ // Bind lifecycle: scope change or a revoked shared access state clears the+ // active drag. The access state is written by ANY controller mount's+ // fail-closed boundary via setQueryData; this is the same pure-subscription+ // pattern the controller uses (never fetches — a cold cache must not invent+ // a revocation, and 'active' is the safe default while nothing wrote yet).+ const accessStateQuery = useQuery({+ queryKey: desktopQueryKeys.gfsAccessState(scope ?? 'anonymous'),+ queryFn: () => 'active' as const,+ enabled: false,+ initialData: 'active' as const,+ gcTime: Infinity,+ staleTime: Infinity,+ })+ const accessState = accessStateQuery.data ?? 'active'++ useEffect(() => {+ if (scope === null || accessState === 'revoked') store.invalidate('authority')+ }, [accessState, scope, store])++ useEffect(() => () => store.invalidate('authority'), [store])++ const api = useMemo<GfsDragSessionApi>(+ () => ({+ beginDrag: source => {+ if (scope === null || accessState !== 'active') return false+ return store.beginDrag(source)+ },+ endDrag: () => store.endDrag(),+ activeSource: () => store.activeSource(),+ matchesScope: candidate => store.matchesScope(candidate),+ invalidate: reason => store.invalidate(reason),+ }),+ [accessState, scope, store]+ )++ return <GfsDragSessionContext.Provider value={api}>{children}</GfsDragSessionContext.Provider>+}++/** Returns the session-scoped drag coordinator, or null outside the provider. */+export function useGfsDragSession(): GfsDragSessionApi | null {+ return useContext(GfsDragSessionContext)+}diff --git a/desktop-app/ui/src/gfs/dragSession.types.ts b/desktop-app/ui/src/gfs/dragSession.types.tsnew file mode 100644index 000000000..674a79125--- /dev/null+++ b/desktop-app/ui/src/gfs/dragSession.types.ts@@ -0,0 +1,90 @@+import type {+ GfsDragAuthorityVerdict,+ GfsDragStructureVerdict,+} from '@clerum/gfs-interaction-policy'++/**+ * The one active in-window drag source, shared by the Files page and the+ * sidebar file explorer (rev-2 §4). `version` is the listing value at+ * dragstart — advisory only; the commit re-resolves before any PATCH. Missing+ * parent facts stay unknown (`parentKnown: false`), never invented root or+ * version-zero facts.+ */+export interface GfsDragSource {+ resourceId: string+ gfsUri: string+ drive: string+ kind: 'file' | 'directory'+ name: string+ /** Listing version at dragstart, when the row carried one. */+ version?: number+ parentKnown: boolean+ parentResourceId: string | null+ /** Loaded-tree ancestors of the source at dragstart (observation only). */+ knownAncestorIds: readonly string[]+ origin: 'files' | 'sidebar'+ /** env:user:team scope the drag started under. */+ scope: string+ /** Monotonic per-provider generation; discards stale async callbacks. */+ generation: number+}++/** Machine-readable denial codes; prose lives in each surface's UX matrix. */+export type GfsDropDenialReason =+ | 'self'+ | 'descendant'+ | 'same-parent'+ | 'root-source'+ | 'cross-drive'+ | 'root-target'+ | 'source-write'+ | 'source-delete'+ | 'destination-write'+ | 'source-location-unknown'+ | 'target-unavailable'+ | 'unavailable'+ | 'session-lost'++export interface GfsDropTargetFact {+ resourceId: string+ name: string+ kind: 'file' | 'directory'+ /** Loaded ancestors of the target, nearest-first (observation only). */+ ancestorIds: readonly string[]+}++export type GfsDropVerdict =+ | { state: 'checking' }+ | { state: 'allowed' }+ | { state: 'denied'; reason: GfsDropDenialReason }+ | { state: 'unavailable'; reason: 'rate-limit' | 'transport' | 'session' }++export interface GfsDropAdmission {+ allowed: true+ /** Numbered-name conflict retry is pre-approved (source write proved or the+ * folder confirmation opted in). */+ allowNumberedRename: boolean+ /** Suggested rename candidate when destination names are cached and taken. */+ suggestedName?: string+ structure: GfsDragStructureVerdict+ authority: GfsDragAuthorityVerdict+}++export interface GfsDropRejection {+ allowed: false+ reason: GfsDropDenialReason+ message?: string+}++export type GfsDropDecision = GfsDropAdmission | GfsDropRejection++/** Provider API (rev-2 §4): one ephemeral source per session; no registry,+ * no nonce MIME, no credentials. */+export interface GfsDragSessionApi {+ beginDrag(source: Omit<GfsDragSource, 'generation'>): boolean+ endDrag(): void+ activeSource(): GfsDragSource | null+ /** True while the stored source belongs to the caller's live scope. */+ matchesScope(scope: string | null): boolean+ invalidate(reason: 'authority' | 'scope-change'): void+}