2026-07-16 18:13:34 +08:00
<!-- Generated by scripts/gen-website-api.ts — do not edit by hand. Run `pnpm run gen-website-api` to regenerate. -->
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
# ctx.fs
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
`FileSystem` (abstract seam) — provided by `@deepseek-ai/dsh-fs` .
2026-07-09 16:07:58 +08:00
2026-07-16 21:36:43 +08:00
Abstract filesystem provider. Targets must preserve identity across aliases; reads expose regular UTF-8 text or typed errors, listings are stable and content-free, and mutations are atomic. Optional guards add stale protection without changing the unguarded provider contract.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L80 )
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.fs.resolve(path, opts?)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
```ts website-api
2026-07-17 21:19:33 +08:00
abstract resolve(path: string, opts?: { cwd?: string; signal?: AbortSignal }): Promise<FsTarget>
2026-07-16 18:13:34 +08:00
` ``
Resolve a model/plugin-supplied path into a stable FsTarget. May perform I/O (a remote/sandboxed backend may need a round-trip to map a path to a stable identity), hence async even though the local backend only normalizes + realpaths.
- ` path` — the path to resolve; relative paths resolve against ` opts.cwd`.
2026-07-17 21:19:33 +08:00
- ` opts` — optional cwd override and cancellation signal.
2026-07-16 18:13:34 +08:00
**Returns** the stable target; the same file yields the same ` targetKey`.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L94)
2026-07-16 18:13:34 +08:00
### ctx.fs.stat(target, signal?)
` ``ts website-api
abstract stat(target: FsTarget, signal?: AbortSignal): Promise<FsInfo | undefined>
` ``
Return target metadata, or ` undefined` when the target does not exist.
- ` target` — the resolved target to stat.
- ` signal` — aborts the metadata round-trip.
**Returns** metadata only, never content; undefined for an absent target.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L102)
### ctx.fs.lstat(path, opts?, signal?)
` ``ts website-api
abstract lstat(path: string, opts?: { cwd?: string }, signal?: AbortSignal): Promise<FsPathInfo | undefined>
` ``
Return path metadata without following the final path component when it is a symbolic link. This is intentionally path-shaped, not target-shaped: resolve follows symlinks to produce the stable identity used by normal reads/writes, while ` lstat` lets a consumer reject the path itself before that follow happens.
` opts.cwd` follows resolve's cwd rules. ` undefined` means the path is absent.
- ` path` — the path to inspect; relative paths resolve against ` opts.cwd`.
- ` opts` — ` cwd` overrides the backend's default base for relative paths.
- ` signal` — aborts the metadata round-trip.
**Returns** metadata only, never content; undefined for an absent path.
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L118)
2026-07-16 18:13:34 +08:00
### ctx.fs.readText(target, signal?)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
abstract readText(target: FsTarget, signal?: AbortSignal): Promise<string>
` ``
Read the whole regular text file as a single decoded string.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` target` — the resolved target to read.
- ` signal` — aborts the read.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
**Returns** the full decoded UTF-8 content.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L126)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.fs.streamText(target, signal?)
` ``ts website-api
abstract streamText(target: FsTarget, signal?: AbortSignal): Promise<AsyncIterable<string>>
` ``
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
Stream the whole regular text file as decoded text chunks (same text semantics as readText, for large files). The backend owns cross-chunk UTF-8 decoding and binary rejection so the policy layer never touches raw bytes.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` target` — the resolved target to read.
- ` signal` — aborts the stream, including between chunks.
2026-07-09 16:07:58 +08:00
2026-07-16 21:15:44 +08:00
**Returns** the chunk iterable, decoded and validated like ` readText`.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L137)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.fs.listDir(target, signal?)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
abstract listDir(target: FsTarget, signal?: AbortSignal): Promise<FsDirEntry[]>
2026-07-09 16:07:58 +08:00
` ``
2026-07-16 18:13:34 +08:00
List direct children of a directory in stable name order. Returns resolved child targets plus cheap metadata only; never reads file contents.
- ` target` — the resolved directory target.
- ` signal` — aborts the listing.
**Returns** one entry per direct child, in stable name order.
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L146)
2026-07-16 18:13:34 +08:00
### ctx.fs.writeText(target, content, expected?, signal?)
` ``ts website-api
abstract writeText(target: FsTarget, content: string, expected?: FsWriteIntent, signal?: AbortSignal): Promise<FsWriteOutcome>
` ``
2026-07-16 21:36:43 +08:00
Atomically create or replace UTF-8 text. ` expected` guards intent and staleness; omission allows unconditional overwrite.
2026-07-16 18:13:34 +08:00
- ` target` — the resolved target to write.
- ` content` — the full new file content.
- ` expected` — the write intent guarding the write; omit for unconditional.
- ` signal` — aborts before the atomic rename takes effect.
**Returns** the outcome, including the version the write produced.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L157)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
### ctx.fs.editText(target, edit, expected?, signal?)
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
` ``ts website-api
abstract editText(target: FsTarget, edit: FsEditRequest, expected?: { version: FsVersion }, signal?: AbortSignal): Promise<FsEditOutcome>
2026-07-09 16:07:58 +08:00
` ``
2026-07-16 21:36:43 +08:00
Atomically edit literal text. When supplied, the version guard is checked before matching so stale content reports ` FS_STALE_VERSION`; omission edits the current content without a freshness precondition.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
- ` target` — the resolved target to edit.
- ` edit` — the literal search/replace request.
- ` expected` — the version guard; omit for an unconditional edit.
- ` signal` — aborts before the atomic rename takes effect.
2026-07-09 16:07:58 +08:00
2026-07-16 18:13:34 +08:00
**Returns ** the outcome, including the version the edit produced.
2026-07-09 16:07:58 +08:00
2026-07-17 21:19:33 +08:00
[Source ](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/fs/fs/src/index.ts#L169 )