mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-30 16:39:33 +01:00
feat(files): load directories on demand
This commit is contained in:
1 parent
5548c17c4a
commit
349d21f75e
16 files changed
+1681
-78
No files matched your search
@@ -905,6 +905,49 @@ already serves non-media text inert (`text/plain`, `nosniff`), so this just
|
||||
keeps the server from storing what it would serve or an agent could run, and
|
||||
html and svg are the ones deliberately kept out.
|
||||
|
||||
## Listing a directory (`GET /api/v1/sessions/:id/files?lazy=1`)
|
||||
|
||||
The Files panel opts into one-directory listings for local workspaces with
|
||||
`lazy=1`. Without `path`, the response lists immediate children of the selected
|
||||
root. Expanding a folder sends its returned `path` to the same endpoint.
|
||||
Directories omit `children` until the browser loads them. No descendant scan or
|
||||
shared depth/node budget is spent on a lazy listing.
|
||||
|
||||
For example, the panel starts with `?lazy=1&root=live-any`, then requests
|
||||
`?lazy=1&root=live-any&path=<returned-path>` to expand a folder. URL-encode the
|
||||
returned path; it is not necessarily relative to the selected root.
|
||||
|
||||
The success envelope contains `data.root`, `lazy: true`, `tree`, per-page
|
||||
`totalFiles`/`totalDirectories`, and `truncated`. Pages contain at most 500 entries,
|
||||
directories first and then names in ascending order. A non-final page includes
|
||||
an opaque `nextCursor`; pass it back as `cursor` with the same session, root,
|
||||
path and `showHidden` preference. A cursor is a continuation key, not a filesystem
|
||||
snapshot: changes before that key become visible on Refresh. Each request reads
|
||||
the named directory's entries and obtains file metadata only for its page.
|
||||
|
||||
`showHidden=true` adds dot-prefixed entries; the existing generated-directory
|
||||
exclusions remain. Requested folders retain workspace realpath confinement and
|
||||
bounded reachability probes. Missing folders return 404, non-directories 400,
|
||||
out-of-scope/excluded/hidden paths 403, and unavailable folders 422. Invalid or
|
||||
incompatible cursors return 400.
|
||||
|
||||
Symbolic links retain the existing file-row representation, so the browser does
|
||||
not expand directory links. Preview and download still use their existing path guards.
|
||||
|
||||
The existing `root=live`/`root=live-any` worktree rules and `worktree` metadata
|
||||
apply. Paths remain relative to `workingDir` for inside worktrees and absolute
|
||||
for followed outside worktrees. SSH sessions retain the existing listing behavior;
|
||||
this mode adds no remote filesystem capability.
|
||||
|
||||
Without `lazy=1`, recursive listing responses are unchanged. A valid `q` query
|
||||
uses the existing flat search response, including when `lazy=1` is present.
|
||||
Search retains its 5,000-entry scan budget, 1,000-match cap, depth limit (default
|
||||
5, maximum 10), and read ceiling. It reports `truncated: true` when a limit or an
|
||||
unreachable folder leaves the search incomplete. Existing `q` responses are unchanged.
|
||||
|
||||
The panel's filtering, search, pagination and retry controls are described in
|
||||
[Working With Files](wiki/Working-With-Files.md#the-file-viewer).
|
||||
|
||||
## Deleting a file (`DELETE /api/v1/sessions/:id/files?path=`)
|
||||
|
||||
The Files panel's delete button. `path` is what the listing gave the row: relative to the
|
||||
|
||||
@@ -824,6 +824,26 @@ Frontend `readmymind-ui.js`: header 🧠 marker-hidden (`btn-readmymind--hidden`
|
||||
|
||||
### Files panel search
|
||||
|
||||
The panel browses local workspaces through opt-in `lazy=1` directory pages (#759),
|
||||
documented in [Listing a directory](api-reference.md#listing-a-directory-get-apiv1sessionsidfileslazy1).
|
||||
Each request reads one directory, returns at most 500 entries and supplies `nextCursor`
|
||||
when more remain. Cursor scope includes the session, selected root, directory and hidden
|
||||
preference. Directories without `children` are unloaded; symbolic links keep their legacy
|
||||
file-row representation, so the browser does not expand directory links. Path confinement, bounded
|
||||
probes and the inside/outside worktree rules apply to every request.
|
||||
|
||||
The browser caches loaded pages in the current tree epoch. Owner, epoch, hidden preference,
|
||||
selected root and tree identity guard folder/page responses. Typing filters loaded entries
|
||||
without a request; Enter uses the existing workspace search, and clearing restores the tree.
|
||||
Expand All opens only loaded folders. Refresh retains visible expansion state; automatic
|
||||
restoration skips recorded load errors and hidden-off expansions before requesting pages.
|
||||
Hidden-path checks are relative to the listing root, so a worktree's dotted prefix does not
|
||||
hide its ordinary folders. Explicit Retry loads the failed folder/page; errors retain entries
|
||||
already loaded. Tests: `test/routes/file-routes-lazy.test.ts`, `test/file-browser-lazy.test.ts`
|
||||
and `test/mobile/file-browser.test.ts`.
|
||||
|
||||
The recursive listing and `q` search policies below remain unchanged for existing callers.
|
||||
|
||||
**Files panel search** (COD-236, the `q` param on `GET /api/sessions/:id/files`): `compileFileQuery()` (`utils/file-query.ts`, pure, no IO, so it unit-tests directly) compiles the query into a reusable predicate, which is what lets the server-side walk prune instead of streaming the whole tree.
|
||||
|
||||
⚠️ **A query turns that endpoint into a FLAT match list rather than a nested tree**, and the walk deliberately recurses past non-matching directories, since the whole point of searching is to reach a file whose ancestors do not match. An empty or whitespace-only query compiles to `null`, which is what keeps the default tree response byte-identical when no search is requested.
|
||||
|
||||
@@ -11,14 +11,38 @@ moved into ([Git Worktrees](Git-Worktrees#when-an-agent-moves-into-a-worktree)).
|
||||
button is on by default on a desktop and off on a phone. The setting is per device: switch it
|
||||
in **App Settings → Header & Panels** on the device you want it on.
|
||||
|
||||
The panel and its search list up to 5,000 files and folders per load, shallow levels first and
|
||||
taking turns between folders, so one huge folder cannot use up that limit before the ones after it,
|
||||
or the folders inside it, get a turn. They also stop opening folders after reading 250,000 entries,
|
||||
so a workspace with several enormous folders can still leave later ones unread. When a workspace is
|
||||
bigger than either limit the status line says `(truncated)`, and an expanded folder the scan did
|
||||
not finish shows **Not fully scanned** rather than looking empty. A folder that does not answer,
|
||||
such as a network mount that went away, is skipped rather than waited on and is marked the same way,
|
||||
so a search can miss what is inside it. The panel's Refresh button tries it again.
|
||||
For local workspaces, opening the panel lists the root's immediate files and folders.
|
||||
Expanding a folder loads its contents, without scanning the folders inside it. Each page holds
|
||||
up to 500 entries; **Load more** beneath a folder, or at the bottom of the root listing, adds
|
||||
the next page. A large subtree no longer uses up the listing budget for unrelated folders.
|
||||
Collapsing and reopening a loaded folder reuses its cached contents.
|
||||
|
||||
Use the search box as follows:
|
||||
|
||||
- **Type to filter loaded entries.** This makes no request and cannot find a file in a folder
|
||||
you have not loaded. Matching ignores case; `*` separates pieces that must appear in order.
|
||||
- **Press Enter to search the workspace**, including folders you have not opened, under the
|
||||
root the panel is showing. Click a folder in the results to load its ancestors and browse it.
|
||||
- **Clear the box to return to your tree**, with its expanded folders and loaded pages.
|
||||
|
||||
Workspace search keeps its existing limits: a 5,000-entry scan budget, up to 1,000 matches,
|
||||
and depth and read limits. A limit or an unreachable folder can leave the search incomplete.
|
||||
The status then says `(truncated)`; with no results the panel says **Search incomplete; no
|
||||
matches in scanned files**, rather than implying the whole workspace has no matches. You can
|
||||
still browse folders directly to reach files the search did not scan.
|
||||
|
||||
**Expand/Collapse All** opens folders whose contents are already loaded, or collapses them;
|
||||
it does not fetch every folder in the workspace. The show-hidden button adds dot-prefixed files and
|
||||
folders alongside ordinary entries and keeps the current filter or search and applicable
|
||||
expanded folders. Generated directories such as `.git`, `node_modules`, `dist` and `build`
|
||||
remain excluded.
|
||||
|
||||
**Refresh** clears the search and reloads the root and visible expanded folders, keeping
|
||||
their expansion state. Contents behind a collapsed folder load when you reopen it. If a
|
||||
folder or its next page fails to load, its error and **Retry loading** button appear there;
|
||||
entries already loaded stay visible. Retry acts on that folder or page, while Refresh
|
||||
reloads the visible tree. A failed load is never presented as an empty folder.
|
||||
If the initial root listing fails, use Refresh.
|
||||
|
||||
Each file row has a download arrow and a × that deletes the file after you confirm. Both show
|
||||
when you point at the row, and always on a touch screen. Delete removes one file at a time,
|
||||
|
||||
Reference in new issue
Block a user