No JSDoc comment in source yet.
API
@Component()
export class WorkspaceFilesService implements WorkspaceFiles {
async statExisting(workspace: string, rels: string[]): Promise<string[]>;
async statExistingWithMtime(workspace: string, rels: string[]): Promise<WorkspaceFileStat[]>;
async list(workspace: string, rel: string): Promise<WorkspaceFilesResponse>;
async resolvePath(workspace: string, rel: string): Promise<string>;
async read(workspace: string, rel: string, options?: WorkspaceFileReadOptions): Promise<WorkspaceFileContent>;
async write(workspace: string, rel: string, data: Buffer, ifVersion?: string): Promise<string>;
async create(workspace: string, rel: string, kind: "file" | "dir"): Promise<void>;
async move(workspace: string, from: string, to: string, ifVersion?: string): Promise<void>;
async remove(workspace: string, rel: string, ifVersion?: string): Promise<void>;
async search(workspace: string, q: string): Promise<WorkspaceSearchResponse>;
}Dependencies & Wiring
Extracted from class decoratorsMethods (10)
statExisting
async statExisting(workspace: string, rels: string[]): Promise<string[]>Batch existence check (a message's file card lists only files that actually exist): each item goes through the same containment resolution as reading (resolveRead); out-of-bounds, resolution failure, missing Workspace, or an irregular file are all treated as non-existent — the card scenario only asks "can this be opened", and throwing a 4xx would only add frontend branches while leaking containment details. Returns the deduplicated existing items in input order.
stringstring[]Promise<string[]>statExistingWithMtime
async statExistingWithMtime(workspace: string, rels: string[]): Promise<WorkspaceFileStat[]>The same check, with each file's modification time — for the caller that has to tell a file this run wrote from one that was already sitting in the Workspace (the messaging bridge sends only the former). Statting is what the check already does, so the time costs nothing extra.
stringstring[]Promise<WorkspaceFileStat[]>list
async list(workspace: string, rel: string): Promise<WorkspaceFilesResponse>List a directory: dirs come first, each group sorted by name. Entries whose canonical target leaves the Workspace are omitted, so listing cannot expose metadata for an out-of-bounds symlink.
stringstringPromise<WorkspaceFilesResponse>resolvePath
async resolvePath(workspace: string, rel: string): Promise<string>The canonical absolute path of an existing entry, for the caller that hands the path to
something other than this process's own IO (the desktop "show in folder", which passes it
to the machine's file manager). Resolution is the read path's, so a .. and a symlink
pointing out of the Workspace are refused here exactly as they are for a read, and a path
that is not there at all is a 404 rather than a path the OS is asked to open.
stringstringPromise<string>read
async read(workspace: string, rel: string, options?: WorkspaceFileReadOptions): Promise<WorkspaceFileContent>Read a file (preview/download): IO on the canonical path (resolveRead has already eliminated symlink escapes).
The stat below runs before the bytes are read, and that order is load-bearing now that it also mints the version marker: a rewrite landing in between tags fresh bytes with the older marker, so the worst case is one needless conflict on the next write. Read-then-stat would fail the other way — old bytes carrying the new marker, which is exactly the write the precondition exists to refuse.
stringstringWorkspaceFileReadOptionsPromise<WorkspaceFileContent>write
async write(workspace: string, rel: string, data: Buffer, ifVersion?: string): Promise<string>Write a file (upload, overwriting a same-named one). If the parent directory is missing, it's automatically created under sandbox checks (preserving directory structure for folder uploads); the final segment is opened with O_NOFOLLOW, refusing to follow a symlink to write outside the Workspace (together with resolveWriteParent's canonical-parent check, this blocks sandbox escapes).
ifVersion is the write precondition: the marker the caller got from its read, which
the file must still carry. It is compared on the open handle — a handle names an
inode, so what is stat'd is exactly what is about to be truncated, with no window in
between. A caller that passes none read no version and gets the unconditional
create-or-overwrite an upload wants: the field's absence, not some sentinel value, is
what separates "first write of a file that isn't there" from "the file I read has
changed". With a marker the file must already exist, so O_CREAT is left out — a
missing file is a change like any other (ENOENT → the same 409), and a refused write
must not leave an empty file behind.
Resolves to the version the write produced, read as soon as the bytes are down: the marker the caller's next conditional write of this file carries. Reading it back with a second request instead would adopt a rewrite landing between the two as the caller's own, and the next save would silently overwrite it.
stringstringBufferstringPromise<string>create
async create(workspace: string, rel: string, kind: "file" | "dir"): Promise<void>Create one empty file or one folder at rel (the Files panel's New menu), refusing anything
already there.
Missing parents are created the way a write creates them (resolveWriteParent), so a
symlinked ancestor pointing out of the Workspace is caught by the write path's own checks.
The entry itself is made by the primitive that fails rather than replaces: O_CREAT | O_EXCL for a file — which on POSIX also refuses a symlink at the final segment instead of
following it (Windows gets an lstat first, below) — and a non-recursive mkdir for a folder.
Either way an occupied path is 409 target_exists with nothing written, and on POSIX there
is no check-then-act window to lose to the Agent writing the same path. A folder the server
may not write in is 403 dir_write_denied.
stringstring"file" | "dir"Promise<void>move
async move(workspace: string, from: string, to: string, ifVersion?: string): Promise<void>Move or rename one Workspace file or folder.
A file is resolved as a mutable entry (canonical parent, O_NOFOLLOW on the final segment,
version marker read off the open handle); the destination is resolved as a write, so its
parent is created when missing under the same checks an upload runs. An occupied
destination is a 409 rather than an overwrite — see targetExists — and a move onto
the file's own path is a 400 rather than a success that did nothing.
A folder moves whole, and without a precondition: it has no single version marker, and
one sent for it is a 400 rather than a check that silently never ran. See
moveFolder for the two destinations it refuses.
stringstringstringstringPromise<void>remove
async remove(workspace: string, rel: string, ifVersion?: string): Promise<void>Delete one Workspace file. Files only, for the same reason move is: a directory
carries no version marker, so nothing can protect a recursive delete from removing work
the Agent did after the panel last looked.
ifVersion is optional in the wire shape — the service will delete unconditionally
without it — but the Files panel always sends the marker its read returned, so a file the
Agent rewrote under the user's cursor is a 409 rather than a lost file.
stringstringstringPromise<void>search
async search(workspace: string, q: string): Promise<WorkspaceSearchResponse>Search the whole Workspace: case-insensitive substring match on an entry's name, not on its path, so typing a directory the file happens to sit under does not turn every file under it into a hit.
Breadth-first from the Workspace root*, and that is load-bearing rather than an implementation detail: shallow matches are found first, so hitting a cap degrades the result into "the most relevant hits" instead of "whatever happened to be in the first directory the walk descended into". The sort keeps the same order the walk produced.
Entries whose canonical path leaves the Workspace are skipped exactly as list
skips them, and every directory is entered at most once by canonical path, so a symlink
pointing back up cannot spin the walk in a cycle.
stringstringPromise<WorkspaceSearchResponse>