Document Folder APIs and add local Visit Examples.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Konrad Neitzel
2026-08-27 22:00:02 +02:00
co-authored by Cursor
parent 9068d8ba8e
commit fa2f2e5f2c
5 changed files with 75 additions and 4 deletions
+8
View File
@@ -24,9 +24,13 @@ type Entry struct {
// Folder is flat storage for one Working Folder (basenames only).
type Folder interface {
// List returns first-level names in the Working Folder.
List() ([]Entry, error)
// Read returns the contents of a basename in the Working Folder.
Read(name string) ([]byte, error)
// Write creates or replaces a basename in the Working Folder.
Write(name string, data []byte) error
// Exists reports whether name is a non-directory file in the Working Folder.
Exists(name string) (bool, error)
}
@@ -133,6 +137,7 @@ func LocalFolder(dir string) Folder {
return localFolder{dir: dir}
}
// List implements Folder for a local directory.
func (f localFolder) List() ([]Entry, error) {
entries, err := os.ReadDir(f.dir)
if err != nil {
@@ -145,6 +150,7 @@ func (f localFolder) List() ([]Entry, error) {
return out, nil
}
// Read implements Folder for a local directory.
func (f localFolder) Read(name string) ([]byte, error) {
if err := RequireBasename(name); err != nil {
return nil, err
@@ -152,6 +158,7 @@ func (f localFolder) Read(name string) ([]byte, error) {
return os.ReadFile(filepath.Join(f.dir, name))
}
// Write implements Folder for a local directory.
func (f localFolder) Write(name string, data []byte) error {
if err := RequireBasename(name); err != nil {
return err
@@ -159,6 +166,7 @@ func (f localFolder) Write(name string, data []byte) error {
return os.WriteFile(filepath.Join(f.dir, name), data, 0o644)
}
// Exists implements Folder for a local directory.
func (f localFolder) Exists(name string) (bool, error) {
if err := RequireBasename(name); err != nil {
return false, err