From 604d71ca79834f7056c1fda862981ae0355a4841 Mon Sep 17 00:00:00 2001 From: Callum Alpass Date: Tue, 3 Nov 2026 22:22:23 +1100 Subject: [PATCH] Wrap the server's folder listing, ignored files, file reads and workspace file assets --- src/client/session.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/client/session.ts b/src/client/session.ts index 68578b1..8c25cfe 100644 --- a/src/client/session.ts +++ b/src/client/session.ts @@ -42,6 +42,8 @@ import { type ModelSelection, type OrchestrationMessageContext, type ProjectEntry, + type ProjectIgnoredFile, + type ProjectReadFileResult, type RuntimeMode, type TerminalAttachStreamEvent, type TerminalSummary, @@ -783,6 +785,32 @@ export class T3Session { return result.entries; } + /** One folder of `cwd` (its root for ""), as the web's file explorer lists it a folder at a time. */ + async listEntries(cwd: string, directoryPath: string): Promise { + const result = await Effect.runPromise(this.requireConnection().rpc[WS_METHODS.projectsListEntries]({ cwd, directoryPath })); + return result.entries; + } + + /** Untracked files git ignores under `cwd`; wholly ignored folders are left out. */ + async listIgnoredFiles(cwd: string): Promise { + const result = await Effect.runPromise(this.requireConnection().rpc[WS_METHODS.projectsListIgnoredFiles]({ cwd })); + return result.files; + } + + /** A workspace file's text; binary files fail with failure `binary_file`. */ + readFile(cwd: string, relativePath: string): Promise { + return Effect.runPromise(this.requireConnection().rpc[WS_METHODS.projectsReadFile]({ cwd, relativePath })); + } + + /** A workspace file from the server, through an asset URL as the web's previews fetch it: its bytes, or only its size from the headers. */ + async fetchWorkspaceFile(threadId: ThreadId, path: string): Promise { + const { rpc, target } = this.requireConnection(); + const minted = await Effect.runPromise(rpc[WS_METHODS.assetsCreateUrl]({ resource: { _tag: "workspace-file", threadId, path } })); + const response = await fetch(new URL(minted.relativeUrl, target.httpBaseUrl)); + if (!response.ok) throw new Error(`File request failed (${response.status})`); + return response; + } + /** Pull requests for a scope, as the web's list and the composer's `#` menu read them. */ async pullRequestsList(input: PullRequestListInput): Promise { return Effect.runPromise(this.requireConnection().rpc[WS_METHODS.pullRequestsList](input));