-
Notifications
You must be signed in to change notification settings - Fork 661
[feat] Mention drive files in the composer with @ #6521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ashrafchowdury
wants to merge
5
commits into
release/v0.114.8
Choose a base branch
from
feat/composer-file-mentions-6139
base: release/v0.114.8
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b6cb716
refactor(frontend): drive the composer's trigger menus from one palet…
ashrafchowdury 7a292d7
feat(frontend): mention drive files in the composer with @
ashrafchowdury 02772e1
test(frontend): pin what an @ mention ships, and story its states
ashrafchowdury 9d6ead5
fix(frontend): group the file palette by scope, and line up its meta …
ashrafchowdury e6b4c2d
fix(frontend): close the gaps review found in the file palette
ashrafchowdury File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| /** | ||
| * Rows for the composer's `@` file palette, derived from a flat drive listing. | ||
| * | ||
| * Pure and React-free: the palette wants a short, flat, capped list per state, so it derives one | ||
| * directly rather than building the explorer's tree and flattening it back down. | ||
| */ | ||
| import {cleanPath, isListableDrivePath, type DriveRecentFile} from "@agenta/entities/drive" | ||
| import type {MountFile} from "@agenta/entities/session" | ||
|
|
||
| /** Enough rows to scroll through, few enough that a 12k-file drive never renders 12k of them. */ | ||
| export const FILE_PALETTE_ROW_CAP = 30 | ||
| export const FILE_PALETTE_RECENTS = 5 | ||
|
|
||
| export interface PaletteFileRow { | ||
| /** The presented drive path — what gets referenced, `agent-files/` fold included. */ | ||
| path: string | ||
| name: string | ||
| isFolder: boolean | ||
| size?: number | ||
| itemCount?: number | ||
| touchedAt?: number | ||
| } | ||
|
|
||
| const prefixFor = (cwd: string): string => { | ||
| const rel = cleanPath(cwd) | ||
| return rel ? `${rel}/` : "" | ||
| } | ||
|
|
||
| const basename = (path: string): string => path.split("/").pop() ?? path | ||
|
|
||
| /** Folders above files, then alphabetical — the order every drive surface lists in. */ | ||
| const byFolderThenName = (a: PaletteFileRow, b: PaletteFileRow): number => | ||
| Number(b.isFolder) - Number(a.isFolder) || a.name.localeCompare(b.name) | ||
|
|
||
| const rowFor = (file: MountFile, path: string, isFolder: boolean): PaletteFileRow => ({ | ||
| path, | ||
| name: basename(path), | ||
| isFolder, | ||
| size: isFolder ? undefined : (file.size ?? undefined), | ||
| itemCount: file.item_count ?? undefined, | ||
| }) | ||
|
|
||
| /** | ||
| * The immediate children of `cwd`. A listing may hold deeper entries (every loaded directory | ||
| * accumulates into one array), so a path that reaches further down contributes its next segment as | ||
| * an implied folder rather than a row of its own. | ||
| */ | ||
| export function browseRows(files: MountFile[], cwd: string): PaletteFileRow[] { | ||
| const prefix = prefixFor(cwd) | ||
| const rows = new Map<string, PaletteFileRow>() | ||
| for (const file of files) { | ||
| const rel = cleanPath(file.path) | ||
| if (!rel.startsWith(prefix)) continue | ||
| const rest = rel.slice(prefix.length) | ||
| if (!rest) continue | ||
| // Judge the LISTING entry, not the folder it implies: the bare `agent-files` marker is | ||
| // unlistable, but the agent files under it fold into a folder that very much is. | ||
| if (!isListableDrivePath(rel)) continue | ||
| const cut = rest.indexOf("/") | ||
| const path = cut < 0 ? rel : prefix + rest.slice(0, cut) | ||
| const isFolder = cut >= 0 || Boolean(file.is_folder) | ||
| // An implied folder must not inherit the descendant's size or count. | ||
| const existing = rows.get(path) | ||
| if (existing && (existing.isFolder || !isFolder)) continue | ||
| rows.set( | ||
| path, | ||
| cut < 0 ? rowFor(file, path, isFolder) : {path, name: basename(path), isFolder: true}, | ||
| ) | ||
| } | ||
| return [...rows.values()].sort(byFolderThenName) | ||
| } | ||
|
|
||
| /** | ||
| * Everything under `cwd` whose path contains `query`. Plain case-insensitive substring on the full | ||
| * path — the palette highlights the match by re-deriving it from the row's label, so a looser | ||
| * predicate here returns rows that come back matched but unhighlighted. | ||
| */ | ||
| export function searchRows( | ||
| files: MountFile[], | ||
| cwd: string, | ||
| query: string, | ||
| cap: number = FILE_PALETTE_ROW_CAP, | ||
| ): PaletteFileRow[] { | ||
| const q = query.trim().toLowerCase() | ||
| if (!q) return [] | ||
| const prefix = prefixFor(cwd) | ||
| const rows: PaletteFileRow[] = [] | ||
| for (const file of files) { | ||
| const rel = cleanPath(file.path) | ||
| if (!rel.startsWith(prefix) || !isListableDrivePath(rel)) continue | ||
| if (!rel.toLowerCase().includes(q)) continue | ||
| rows.push(rowFor(file, rel, Boolean(file.is_folder))) | ||
| } | ||
| return rows.sort(byFolderThenName).slice(0, cap) | ||
| } | ||
|
|
||
| /** The drive's most-recently-touched files, for the palette's opening list. */ | ||
| export function recentRows( | ||
| recents: DriveRecentFile[], | ||
| limit: number = FILE_PALETTE_RECENTS, | ||
| ): PaletteFileRow[] { | ||
| const rows: PaletteFileRow[] = [] | ||
| for (const file of recents) { | ||
| if (rows.length >= limit) break | ||
| const rel = cleanPath(file.path) | ||
| if (!isListableDrivePath(rel) || file.is_folder) continue | ||
| rows.push({...rowFor(file, rel, false), touchedAt: file.touchedAt}) | ||
| } | ||
| return rows | ||
| } | ||
|
|
||
| /** The directory a path sits in, as a presented drive path (`""` at the root). */ | ||
| export const parentPath = (path: string): string => { | ||
| const rel = cleanPath(path) | ||
| const cut = rel.lastIndexOf("/") | ||
| return cut < 0 ? "" : rel.slice(0, cut) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.