import type { ApiRoute } from '@mastra/core/server'; import type { FilesystemStorage } from '../storage/domains/filesystem/base.js'; import type { SourceControlSession } from '../storage/domains/source-control/base.js'; import type { RouteAuth } from './route.js'; /** * Server-side directory browser for the web project picker. * * The browser cannot read absolute filesystem paths (the File System Access API * only exposes a directory *name*), so the picker must ask the server — which * does have filesystem access — to enumerate directories. The result is real * absolute paths the user can select without typing. * * All access is confined to a configured `root` (default: the user's home * directory). Requests that try to escape the root via `..` or symlinks are * clamped back to the root. */ export interface DirectoryEntry { name: string; /** Absolute path to the entry. */ path: string; } export interface DirectoryListing { /** The allowed root; clients cannot browse above this. */ root: string; /** The absolute path that was listed. */ path: string; /** Parent directory path, or null when `path` is the root. */ parent: string | null; /** Subdirectories of `path` (directories only, sorted, hidden excluded). */ entries: DirectoryEntry[]; } export interface WorkspaceRenderedEntry { name: string; /** Path relative to the configured rendered root. */ path: string; type: 'file' | 'directory'; size: number; updatedAt: string; } export interface WorkspaceRenderedListing { /** The confined workspace/project root. */ workspacePath: string; /** Configured workspace-relative rendered root, e.g. `.artifacts`. */ root: string; /** The confined absolute path for the rendered root. */ rootPath: string; entries: WorkspaceRenderedEntry[]; } export interface WorkspaceFile { /** The confined workspace/project root. */ workspacePath: string; /** Workspace-relative file path. */ path: string; name: string; size: number; updatedAt: string; contentType: 'text' | 'unsupported'; content?: string; truncated?: boolean; } export interface WorkspaceFilesListing { /** The Factory session resource id. */ workspacePath: string; /** The agent thread whose terminal file list was captured. */ threadId: string; files: Array<{ path: string; }>; } export type WorkspaceChangeStatus = 'modified' | 'added' | 'deleted' | 'renamed' | 'copied' | 'untracked' | 'conflicted'; export interface WorkspaceChange { path: string; previousPath?: string; status: WorkspaceChangeStatus; additions?: number; deletions?: number; binary?: boolean; } export interface WorkspaceChanges { workspacePath: string; available: boolean; changes: WorkspaceChange[]; additions?: number; deletions?: number; } export interface WorkspaceDiff { workspacePath: string; path: string; patch: string; truncated: boolean; } export type ArtifactEntry = WorkspaceRenderedEntry; export interface ArtifactListing { /** The confined workspace/project root. */ rootPath: string; /** The workspace artifact directory. */ artifactsPath: string; entries: ArtifactEntry[]; } /** Resolve the browsable root, defaulting to the user's home directory. */ export declare function resolveFsRoot(root?: string): string; /** * List the directories inside `requestedPath`, confined to `root`. An absent or * out-of-root path is clamped to the root, so the worst a malicious client can * do is browse within the allowed root. */ export declare function listDirectory(root: string, requestedPath?: string): Promise; export declare function listWorkspaceRenderedPath(root: string, workspacePath: string, renderedRoot: string): Promise; export declare function readWorkspaceFile(root: string, workspacePath: string, path: string): Promise; export declare function listArtifacts(root: string, workspacePath: string): Promise; /** Dependencies for resolving a `workspacePath` that is a Factory session id. */ export interface SessionFsDeps { auth: RouteAuth; sessions: { getBySessionId(sessionId: string): Promise; }; filesystem: Pick; } export declare function listSessionFilesystemFiles(filesystem: Pick, session: SourceControlSession, threadId: string): Promise; /** List an approved rendered root inside a Factory session's sandbox workdir. */ export declare function listSessionRenderedPath(session: SourceControlSession, renderedRoot: string): Promise; /** Read a file inside a session's sandbox. Paths outside rendered roots require a persisted-file allowlist check in the route. */ export declare function readSessionWorkspaceFile(session: SourceControlSession, path: string, options?: { allowUnapprovedPath?: boolean; }): Promise; export declare function parseWorkspaceChanges(output: string): WorkspaceChange[]; export declare function parseWorkspaceChangeStats(output: string): Map; export declare function listSessionWorkspaceChanges(session: SourceControlSession): Promise; export declare function readSessionWorkspaceDiff(session: SourceControlSession, path: string, previousPath?: string): Promise; export interface ResolvedCodebase { /** * The resourceId the TUI would use for this path — derived identically so a * project opened in the terminal and in the web app resolve to the SAME * session (and therefore the same threads). */ resourceId: string; name: string; rootPath: string; gitUrl?: string; gitBranch?: string; } /** * Resolve a project path to the same resourceId the TUI uses. Mirrors * `createMastraCode`: detect the project, then apply any resourceId override * (MASTRA_RESOURCE_ID env var or `.mastracode/database.json`). This is the * shared continuity point — start in the TUI, continue on the web, same path * → same resourceId → same session. */ export declare function resolveCodebase(projectPath: string): ResolvedCodebase; /** * Build the web filesystem routes as Mastra `apiRoutes`: * - `GET /web/fs/list?path=...` — browse directories (confined to root) * - `GET /web/codebase/resolve?path=...` — TUI-compatible codebase resourceId */ export declare function buildFsRoutes(options?: { root?: string; sessionFs?: SessionFsDeps; }): ApiRoute[]; //# sourceMappingURL=fs.d.ts.map