Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

refactor(control-ui): consume shared inherited-access policy

M7c9b852dacc0
diff --git a/control-ui/components/gfsInheritedAccess.ts b/control-ui/components/gfsInheritedAccess.ts
index 968673ec8..00f11d9c9 100644
--- a/control-ui/components/gfsInheritedAccess.ts
+++ b/control-ui/components/gfsInheritedAccess.ts
@@ -1,3 +1,4 @@
+import { gfsAncestorPathsOf } from '@clerum/gfs-interaction-policy'
import {
type GfsResourceByPathView,
getGfsGrants,
@@ -16,20 +17,21 @@ export { planInheritedRoleChange, strongestInheritedSource } from './gfsInherite
* resource's canonical path and keeping the rows that apply to descendants
* (grants with inherit=true, shares with includeDescendants=true — the same
* rule the server's allow() evaluation uses). Rows are merged per subject
- * through the pure merge core (`gfsInheritedAccessMerge.ts`, property tested
- * in R1-M4); EVERY contributing ancestor folder is kept as an editable source
- * (with the grant/share ids to mutate), so a confirmed removal revokes all of
- * them and a confirmed downgrade lowers each one above the target role
- * (R1-H1). If any required ancestor or ACL read fails, the derivation fails
- * visibly instead of returning a result that looks complete.
+ * through the shared pure merge core (`@clerum/gfs-interaction-policy`,
+ * property tested there and in R1-M4); EVERY contributing ancestor folder is
+ * kept as an editable source (with the grant/share ids to mutate), so a
+ * confirmed removal revokes all of them and a confirmed downgrade lowers
+ * each one above the target role (R1-H1). If any required ancestor or ACL
+ * read fails, the derivation fails visibly instead of returning a result
+ * that looks complete.
*/
/**
* Walk semantics (R1-M1, unified with the desktop walk in
* desktop-app/ui/src/gfs/inheritedAccess.ts):
- * - BOUNDED in depth: at most GFS_INHERITED_WALK_MAX_DEPTH ancestors are
- * visited (the desktop rid-chain walk bounds itself with the same number
- * via GFS_BREADCRUMB_MAX_DEPTH).
+ * - BOUNDED in depth: at most 64 ancestors are visited (the shared policy's
+ * GFS_INHERITED_WALK_MAX_DEPTH; the desktop rid-chain walk bounds itself
+ * with the same number via GFS_BREADCRUMB_MAX_DEPTH).
* - COMPLETE or FAILED: every ancestor path must resolve to a directory and
* both ACL lists must load. Any failure throws the same derivation error as
* Desktop, so the UI cannot mistake partial data for no inherited access.
@@ -37,21 +39,10 @@ export { planInheritedRoleChange, strongestInheritedSource } from './gfsInherite
* parent resource IDs. The traversal differs, but the failure contract is
* shared.
*/
-const GFS_INHERITED_WALK_MAX_DEPTH = 64
/** `/docs/report.md` → `['/docs', '/']` (nearest ancestor first, depth-capped). */
export function gfsAncestorPaths(path: string): string[] {
- const segments = (path.startsWith('/') ? path : `/${path}`)
- .split('/')
- .filter(segment => segment.length > 0)
- if (segments.length === 0) return []
- const ancestors: string[] = []
- for (let count = segments.length - 1; count > 0; count -= 1) {
- ancestors.push(`/${segments.slice(0, count).join('/')}`)
- }
- ancestors.push('/')
- // Nearest-first cap, mirroring the desktop rid-chain walk's bound.
- return ancestors.slice(0, GFS_INHERITED_WALK_MAX_DEPTH)
+ return gfsAncestorPathsOf(path)
}
interface InheritingRow {
diff --git a/control-ui/components/gfsInheritedAccessMerge.ts b/control-ui/components/gfsInheritedAccessMerge.ts
index 1244ea765..c86065762 100644
--- a/control-ui/components/gfsInheritedAccessMerge.ts
+++ b/control-ui/components/gfsInheritedAccessMerge.ts
@@ -1,41 +1,58 @@
-import type { GfsSubjectInput } from '@lib/api'
+import {
+ gfsRoleRank,
+ gfsSubjectKeyOf,
+ isEditorGfsPermissions,
+ mergeGfsInheritedAccessItem as mergeInheritedAccessPolicy,
+ strongestGfsInheritedSource,
+} from '@clerum/gfs-interaction-policy'
+import type {
+ GfsInheritedAccessItem as PolicyInheritedAccessItem,
+ GfsInheritedAccessSource as PolicyInheritedAccessSource,
+} from '@clerum/gfs-interaction-policy'
import type { GfsInheritedAccessItem, GfsInheritedAccessSource } from './GfsGrantPanel.types'
/**
- * Pure merge core for the client-side inherited-access derivation (R1-M4).
- * No network — everything here is a function of its inputs, which is what
- * the fast-check property suite in
- * `__tests__/gfsInheritedAccessMerge.prop.test.ts` relies on: merge
- * idempotency, no source dropped, effective role = strongest of sources,
- * and a total role order.
+ * Control UI adapter over the shared inherited-access policy
+ * (`@clerum/gfs-interaction-policy`), which owns the pure merge/planner
+ * semantics (property tested there). This module keeps the app's historical
+ * export surface and contribution shape stable: Control UI walkers hand over
+ * rows pre-filtered to inheriting grants and descendant-covering shares, so
+ * every translated contribution carries inherit/includeDescendants=true and
+ * the same row ids the legacy core recorded.
*/
/** Stable per-subject merge key. Mirrors the panel's direct-row subject key. */
export function inheritedSubjectKey(subject: { type: string; id?: string }): string {
- return `${subject.type}:${subject.id ?? ''}`
+ return gfsSubjectKeyOf(subject)
}
/** Editor-strength rows (write/delete/manage_acl) outrank read-only rows. */
-export function isEditorPermissions(permissions: string[]): boolean {
- return permissions.some(permission => ['write', 'delete', 'manage_acl'].includes(permission))
-}
+export const isEditorPermissions = isEditorGfsPermissions
/** Total role order over permission sets: Read (0) < Editor (1). */
-export function roleRank(permissions: string[]): number {
- return isEditorPermissions(permissions) ? 1 : 0
+export const roleRank = gfsRoleRank
+
+/** One inheriting row on an ancestor folder, carrying its mutable row ids. */
+export interface InheritedAccessContribution {
+ subject: { type: string; id?: string }
+ permissions: string[]
+ grantId: string | null
+ shareIds: string[]
+}
+
+/** The ancestor folder a contribution was collected from. */
+export interface InheritedAccessFolder {
+ resourceId: string
+ name: string
}
/** The strongest contributing folder: editor beats read, nearest among equals. */
export function strongestInheritedSource(
sources: GfsInheritedAccessSource[]
): GfsInheritedAccessSource | null {
- return sources.reduce<GfsInheritedAccessSource | null>(
- (strongest, source) =>
- strongest === null || roleRank(strongest.permissions) < roleRank(source.permissions)
- ? source
- : strongest,
- null
- )
+ return strongestGfsInheritedSource(
+ sources as PolicyInheritedAccessSource[]
+ ) as GfsInheritedAccessSource | null
}
/**
@@ -46,85 +63,77 @@ export function strongestInheritedSource(
* - upgrade: the single strongest source (nearest among equals) — the
* effective role is the strongest across sources, so one raise is enough;
* - no-op (target equals the effective role): none.
+ *
+ * Kept flat and order-preserving (the app's established contract): the
+ * richer grant-vs-share split planner remains available from the shared
+ * package for the scoped per-source edit work.
*/
export function planInheritedRoleChange(
item: Pick<GfsInheritedAccessItem, 'permissions' | 'sources'>,
targetRoleIsEditor: boolean
): GfsInheritedAccessSource[] {
- const effectiveIsEditor = isEditorPermissions(item.permissions)
+ const effectiveIsEditor = isEditorGfsPermissions(item.permissions)
if (targetRoleIsEditor === effectiveIsEditor) return []
if (!targetRoleIsEditor) {
- // Downgrade: lower every editor source down to Read.
- return item.sources.filter(source => isEditorPermissions(source.permissions))
+ return item.sources.filter(source => isEditorGfsPermissions(source.permissions))
}
- // Upgrade: raise the strongest source (nearest among equals) to Editor.
const strongest = strongestInheritedSource(item.sources)
return strongest ? [strongest] : []
}
-/** One inheriting row on an ancestor folder, carrying its mutable row ids. */
-export interface InheritedAccessContribution {
- subject: { type: string; id?: string }
- permissions: string[]
- grantId: string | null
- shareIds: string[]
-}
-
-/** The ancestor folder a contribution was collected from. */
-export interface InheritedAccessFolder {
- resourceId: string
- name: string
-}
-
/**
* Folds one inheriting row into a subject's derived access item (creating it
- * on first sight). Pure: never mutates its inputs. EVERY contributing folder
- * is kept as an editable source (R1-H1); a grant and a share for one subject
- * on the same folder consolidate into one source (unioned permissions and
- * row ids) so a confirmed edit mutates them together.
+ * on first sight) through the shared pure core. A contribution with ids for
+ * both row kinds (legacy generators produce them) translates into one grant
+ * fold plus one fold per share id; an id-less contribution folds permissions
+ * only, exactly like the legacy core.
*/
export function mergeInheritedAccessItem(
current: GfsInheritedAccessItem | null,
contribution: InheritedAccessContribution,
folder: InheritedAccessFolder
): GfsInheritedAccessItem {
- if (current === null) {
- return {
- subject: contribution.subject as GfsSubjectInput,
- permissions: [...contribution.permissions],
- inheritedFrom: [folder.name],
- sources: [
- {
- resourceId: folder.resourceId,
- name: folder.name,
- permissions: [...contribution.permissions],
- grantId: contribution.grantId,
- shareIds: [...contribution.shareIds],
- },
- ],
- }
+ let folded = current as unknown as PolicyInheritedAccessItem | null
+ if (contribution.grantId !== null && contribution.grantId !== '') {
+ folded = mergeInheritedAccessPolicy(
+ folded,
+ {
+ subject: contribution.subject,
+ permissions: contribution.permissions,
+ rowKind: 'grant',
+ rowId: contribution.grantId,
+ inherit: true,
+ },
+ folder
+ )
}
- const next: GfsInheritedAccessItem = {
- ...current,
- permissions: [...new Set([...current.permissions, ...contribution.permissions])],
- inheritedFrom: current.inheritedFrom.includes(folder.name)
- ? [...current.inheritedFrom]
- : [...current.inheritedFrom, folder.name],
- sources: current.sources.map(source => ({ ...source, shareIds: [...source.shareIds] })),
+ for (const shareId of contribution.shareIds) {
+ folded = mergeInheritedAccessPolicy(
+ folded,
+ {
+ subject: contribution.subject,
+ permissions: contribution.permissions,
+ rowKind: 'share',
+ rowId: shareId,
+ includeDescendants: true,
+ },
+ folder
+ )
}
- const sameFolder = next.sources.find(source => source.resourceId === folder.resourceId)
- if (sameFolder) {
- sameFolder.permissions = [...new Set([...sameFolder.permissions, ...contribution.permissions])]
- sameFolder.grantId = sameFolder.grantId ?? contribution.grantId
- sameFolder.shareIds = [...new Set([...sameFolder.shareIds, ...contribution.shareIds])]
- } else {
- next.sources.push({
- resourceId: folder.resourceId,
- name: folder.name,
- permissions: [...contribution.permissions],
- grantId: contribution.grantId,
- shareIds: [...contribution.shareIds],
- })
+ if (
+ (contribution.grantId === null || contribution.grantId === '') &&
+ contribution.shareIds.length === 0
+ ) {
+ folded = mergeInheritedAccessPolicy(
+ folded,
+ {
+ subject: contribution.subject,
+ permissions: contribution.permissions,
+ rowKind: 'grant',
+ rowId: null,
+ },
+ folder
+ )
}
- return next
+ return folded as unknown as GfsInheritedAccessItem
}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 89df19642..191082cb1 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.729",
+ "version": "0.1.730",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.729",
+ "version": "0.1.730",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index a23f3ab42..86b2a5f69 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.729",
+ "version": "0.1.730",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",