vfs

package
v0.5.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 39 Imported by: 0

Documentation

Overview

Package vfs is Tacklr's virtual filesystem: session mounts, path I/O, and content IR.

Public surface (hosts)

  • Tree / At / Union / OpenVFS — host builds one /workspace tree per turn (agent-visible). Union merges Opens at one alias. Package workspace gives the agent its tools, skills and overflow on that tree.
  • MountSession — path I/O, ReadText / WriteDocument, ReadLines
  • ContentRev / ContentHash — session-visible content identity (for tools)
  • SessionAuth + TokenHolder + Binding — session-scoped user-owned credentials (never on MountSpec)
  • GitRepo + GitToken / GitSSHKey — git clone onto worker disk; the agent runs git itself
  • MountSpec — durable mount description (checkpoint-safe; one record per /workspace/<name>)
  • WorkspacePoint — /workspace (the only top-level mount)
  • Provider / Open / S3API / DriveAPI / GraphAPI — custom backends (Blob uses S3API). Hosts construct default backends from this package (Local, S3, Blob, Drive, Graph, Git). NewGoogleDrive, NewGoogleDocs, NewGoogleSheets and NewMicrosoftGraph call the Google and Graph REST APIs over net/http. The S3 and Azure Blob SDK adapters are in packages vfs/awss3 and vfs/azureblob, so this package does not link those SDKs.
  • File, FileInfo, DirEntry — I/O types (File is Close+Stat; io.Reader / io.ReaderAt / io.Writer via comma-ok). FileInfo.Version changes when the content changes (ETag, md5Checksum, cTag, or local size+mtime+inode). Read handles stream on every backend; remote ReadAt uses range requests with read-ahead.
  • Document / Textual / Structured / TextDocument — content IR
  • Block / StyleMeta / Span / FindBlock / BlockReplaceSpan — structured view
  • ContentRegistry + Codec + TextCodec + IdentityCodec — each MountSession's codecs (MountSession.Codecs): TextCodec, the mounted backends' own types (Drive's Google Docs and Sheets), and what the host adds with OpenVFS.WithCodecs (vfs/adapters has Word and Excel). Nothing registers a codec on import; a second codec for a type returns ErrAlreadyRegistered
  • DetectMediaType, size-cap constants, sentinel errors (including ErrAuthExpired, ErrAmbiguous, ErrPermission, ErrAlreadyRegistered)

Providers own IR translation and persist immediately on WriteDocument. MountSession routes; it does not encode or hold a dirty document cache.

Optimistic edit policy lives in harness tools (read, write) that wrap ReadText / TextDocument / WriteDocument. ContentRev is the stable token those tools pass — not a large MountSession surface.

This package never imports brain; knowledge is not a mount. Optional artifact indexing lives in package vfsindex (imports both). Package vfs/fuse shows a MountSession on the host kernel; host tools there read ReadText (provider IR plaintext). This package does not ship a grep tool.

Hosts should not need anything else. Host paths and bucket details stay inside providers. MountSession only keeps the mount map and routes paths.

Path I/O

Absolute virtual paths only, via MountSession:

Stat, Open, ReadFile, WriteFile, ReadDir, Remove, MkdirAll
File is Close + Stat. Read / ReadAt / Write are optional (comma-ok).
The only mount point is /workspace.

Read-only mounts reject mutating ops with ErrReadOnly. Local paths are jailed under the provider root (including symlink evaluation). S3 and Azure Blob use key prefixes and delimiter listing for virtual directories (MinIO/AWS/Azurite).

Content IR

Raw ops stay byte-oriented. Content access:

// Progressive page (large files OK; EOF/NextStart for paging)
file := ms.Route(ctx, "/workspace/work/main.go")
win, err := file.ReadLines(ctx, 1, 51)
// win.Rev.Hash is the session-visible content identity when available

// Full IR for edit; the provider persists WriteDocument
text, err := file.ReadText(ctx) // Textual
rev := vfs.ContentRev{Path: text.Path(), Hash: vfs.ContentHash(text.Text())}
_ = text.SetLine(2, "changed")
_ = file.WriteDocument(ctx, text)
_ = rev // tools compare expected rev before WriteDocument

Longer guide: docs/workspace.md in the repo root.

Index

Constants

View Source
const (
	AccountOrganization = "organization"
	AccountPersonal     = "personal"
)

Microsoft account kinds for Graph / ParamAccount. Organization (SharePoint / OneDrive for Business) is the default.

View Source
const (
	BlockKindPreamble  = "preamble"
	BlockKindHeading   = "heading"
	BlockKindParagraph = "paragraph"
	BlockKindListItem  = "list_item"
	BlockKindTable     = "table"
	BlockKindImage     = "image"
	BlockKindSheet     = "sheet"
)

Block kind vocabulary (stable for tools and brain props). Grow carefully.

View Source
const (
	MarkBold   = "bold"
	MarkItalic = "italic"
	MarkStrike = "strike"
	MarkHref   = "href"
)
View Source
const DefaultTokenRefreshSkew = time.Minute

DefaultTokenRefreshSkew refreshes a short-lived token before its hard expiry.

View Source
const (

	// MaxDocsExportBytes is the Drive files.export limit.
	MaxDocsExportBytes = 10 << 20
)
View Source
const MaxLineBytes = 1 << 20 // 1 MiB

MaxLineBytes caps a single line when streaming (ReadLines) or scanning.

View Source
const MaxLineScanBytes = 64 << 20 // 64 MiB

MaxLineScanBytes caps how many bytes a single streaming ReadLines call may read from the start of a file (or from a seek point later). Distinct from MaxReadFileBytes (full IR materialize).

View Source
const MaxLinesPerWindow = 500

MaxLinesPerWindow caps how many lines one ReadLines call may return.

View Source
const MaxReadFileBytes = 32 << 20 // 32 MiB

MaxReadFileBytes caps full-file reads and writes.

View Source
const (

	// MaxSheetCells is the hard cap on loaded cells in one workbook.
	MaxSheetCells = 200_000
)

Variables

View Source
var (
	ErrInvalidPath  = errors.New("vfs: invalid path")
	ErrNotMounted   = errors.New("vfs: not mounted")
	ErrNotSupported = errors.New("vfs: not supported")
	ErrReadOnly     = errors.New("vfs: read-only mount")
	ErrNotExist     = errors.New("vfs: not found")
	ErrNotDir       = errors.New("vfs: not a directory")
	ErrIsDir        = errors.New("vfs: is a directory")
	ErrExist        = errors.New("vfs: already exists")
	ErrAuthExpired  = errors.New("vfs: auth expired")
	ErrAmbiguous    = errors.New("vfs: ambiguous path")
	ErrPermission   = errors.New("vfs: permission denied")

	// Content IR
	ErrNoCodec = errors.New("vfs: no codec for media type")
	// ErrAlreadyRegistered is returned when Register is called for a media type
	// that already has a codec. First registration wins.
	ErrAlreadyRegistered = errors.New("vfs: media type already registered")
	ErrNotTextual        = errors.New("vfs: not a textual document")
	ErrLineOutOfRange    = errors.New("vfs: line out of range")
	// ErrUnknownBlock is a block_id (heading, block, sheet) the file does not have.
	ErrUnknownBlock = errors.New("vfs: unknown block_id")
	// ErrInvalidA1 is a cell or range address that is not A1 notation.
	ErrInvalidA1   = errors.New("vfs: invalid A1 address")
	ErrInvalidUTF8 = errors.New("vfs: invalid utf-8")
	ErrInvalidLine = errors.New("vfs: line contains newline")
	ErrLineTooLong = errors.New("vfs: line too long")
	ErrTooLarge    = errors.New("vfs: file too large")
	// ErrProjected is returned when a line/HTML/SetText mutation is applied to a
	// projected spreadsheet. Docs/Word accept HTML line and full-content writes.
	ErrProjected = errors.New("that write is not supported on this file type")
	// ErrConflict is a provider-level compare-and-swap failure.
	// Apply retries Docs/Word persist once; leftover conflict becomes ErrInvalidWrite.
	ErrConflict = errors.New("the file changed on the server since it was last read")
	// ErrStaleContent is tool/host optimistic concurrency (expected hash ≠ current).
	ErrStaleContent = errors.New("the file changed since last read")
	// ErrInvalidWrite is a persist that cannot apply (bad insert location, etc.).
	// Never wrap provider SDK errors in this; the agent should retry the write.
	ErrInvalidWrite = errors.New("the document was not saved; read it and write the HTML again")
	// ErrUseHTML is a non-HTML full replace on an existing Docs/Word path.
	ErrUseHTML = errors.New("write HTML, not plain text")
	// ErrEmptyReplace is HTML or blocks that decoded to no headings, paragraphs, lists, or tables.
	ErrEmptyReplace = errors.New("that HTML had no headings, paragraphs, lists, or tables; put the text in <p> or <h1> tags")
	// ErrTabIDRequired is a replace on a multi-tab Doc/Word file without tab_id.
	ErrTabIDRequired = errors.New("this document has more than one tab; pass tab_id for the tab you want to replace")
)

Sentinel errors for mount-table and path I/O outcomes. Prefer bare sentinels or a single plain "vfs: …" message — never wrap sentinels in sentinels.

Functions

func BindingByName

func BindingByName(binds []mount.Binding, name string) (mount.Binding, bool)

BindingByName returns the bind whose alias or provider matches name.

func BlockReplaceSpan

func BlockReplaceSpan(b Block, includeHeading bool) (start, end int, err error)

BlockReplaceSpan returns half-open 1-based lines to replace for a block. For headings, includeHeading false skips the heading line (body only).

func CleanPath

func CleanPath(s string) (string, error)

CleanPath requires an absolute virtual path with no backslash or NUL. It returns path.Clean(s).

func ContentHash

func ContentHash(body string) string

ContentHash returns hex SHA-256 of body.

func ContentToken

func ContentToken(t Textual) string

ContentToken is the single rev helper. Used by ContentRev, lineWindowFromDoc, readStructured, loadMatching, and stage. IR uses the representation fingerprint so HTML reproject does not change the token.

func DetectMediaType

func DetectMediaType(virtualPath string, sample []byte) string

DetectMediaType is a helper for providers filling FileInfo.MediaType. OpenDocument does not call this — it trusts the provider.

Order:

  1. Well-known extension map (source code and text formats)
  2. If sample is non-empty: http.DetectContentType (+ UTF-8 text fallback)
  3. application/octet-stream

func EncodeHTMLBlocks

func EncodeHTMLBlocks(blocks []Block) string

EncodeHTMLBlocks writes pretty HTML: one heading, paragraph, list item, or table per line. Color style is emitted only when stored on the IR.

func EncodeTextual

func EncodeTextual(t Textual) ([]byte, error)

EncodeTextual returns UTF-8 bytes for a Textual document. Backend providers call this when their native form is a file or object. MountSession does not encode.

func ExcelARGB

func ExcelARGB(s string) string

ExcelARGB is the 8-digit AARRGGBB form used by Office XML.

func FormatA1

func FormatA1(row, col int) string

FormatA1 is the 1-based cell address (A1, B2, AA10).

func FormatInline

func FormatInline(runs []Run) string

FormatInline is the canonical agent spelling. Italic is always _text_.

func FormatRGB

func FormatRGB(r, g, b uint8) string

FormatRGB writes #rrggbb.

func HexColor

func HexColor(s string) string

HexColor normalizes a CSS/Office color to #rrggbb. Empty if not hex.

func IsTextLike

func IsTextLike(mediaType string) bool

IsTextLike reports whether mediaType is treated as text for IR/index routing.

func ParseA1

func ParseA1(s string) (r1, c1, r2, c2 int, err error)

ParseA1 parses A1 or A1:C3 (1-based inclusive).

func ParseRGB

func ParseRGB(s string) (r, g, b uint8, ok bool)

ParseRGB reads #rrggbb or #aarrggbb / rrggbb / aarrggbb.

func PlainInline

func PlainInline(s string) string

PlainInline is Block.Text with mark delimiters removed.

func Slugify

func Slugify(s string) string

Slugify lowers, keeps alnum, collapses other runs to '-', and trims dashes.

func SplitSheetAddr

func SplitSheetAddr(blockID string) (sheet, a1 string)

SplitSheetAddr splits block_id into sheet key and optional A1 (Sheet!B2).

Types

type ApplyResult

type ApplyResult struct {
	Path         string
	Rev          string
	LineCount    int
	Replacements int
	Outline      []Block
}

ApplyResult is the post-write identity of the document.

func (ApplyResult) String

func (r ApplyResult) String() string

type Block

type Block struct {
	ID    string
	Kind  string
	Text  string
	Runs  []Run
	Style StyleMeta
}

Block is a structural unit (heading region, paragraph, …). For Markdown, blocks are a projected view over the textual body (not a second body).

Text is what tools show the agent. On RichDocument, inline marks in Text are **bold**, _italic_ (also *italic* on input), ~~strike~~, and [label](url). kind/level carry structure — do not put # or - lists in Text. Runs is the decoded form; callers set Text and leave Runs empty.

func DecodeHTMLBlocks

func DecodeHTMLBlocks(data []byte) ([]Block, error)

DecodeHTMLBlocks maps pretty HTML to Block IR (headings, paragraphs, lists, tables, marks, existing images). It does not assign stable block IDs.

func FindBlock

func FindBlock(blocks []Block, idOrPath string) (Block, bool)

FindBlock looks up by ID or Style.Attributes["heading_path"] (exact).

func (Block) PlainText

func (b Block) PlainText() string

type BlockCodec

type BlockCodec struct {
	Types      []string
	Normalizer BlockNormalizer
}

BlockCodec adapts a BlockNormalizer to the VFS codec registry. Decode yields a RichDocument. Encode writes native bytes (DOCX, …). Not an IdentityCodec — FUSE is EROFS; persist via WriteDocument.

func (BlockCodec) Create

func (c BlockCodec) Create(path, mediaType string, mut Mutation) (Document, error)

Create lifts plaintext or blocks into a rich checkout.

func (BlockCodec) Decode

func (c BlockCodec) Decode(ctx context.Context, path, mediaType string, data []byte) (Document, error)

func (BlockCodec) Encode

func (c BlockCodec) Encode(ctx context.Context, doc Document) ([]byte, error)

func (BlockCodec) MediaTypes

func (c BlockCodec) MediaTypes() []string

type BlockNormalizer

type BlockNormalizer interface {
	DecodeBlocks(ctx context.Context, path, mediaType string, data []byte) ([]Block, error)
	EncodeBlocks(ctx context.Context, blocks []Block) ([]byte, error)
}

BlockNormalizer converts a source format to and from []Block.

type Cell

type Cell struct {
	Input  string
	Value  string
	Format CellFormat
}

Cell is one grid value. Input is what the agent writes ("Acme", "42", "=A1+1"). Value is the provider's formatted/computed text; empty when unknown. Zero Format means unspecified (do not send on write).

func (Cell) Display

func (c Cell) Display() string

Display is the agent-visible cell: formula if present, else formatted value.

type CellBorder

type CellBorder struct {
	Style string `json:"style,omitempty"`
	Color string `json:"color,omitempty"`
	Edges string `json:"edges,omitempty"`
}

CellBorder is one named-style bag. Empty Edges means all four sides.

type CellFormat

type CellFormat struct {
	Number    string      `json:"number,omitempty"`
	Bold      bool        `json:"bold,omitempty"`
	Italic    bool        `json:"italic,omitempty"`
	Strike    bool        `json:"strike,omitempty"`
	Underline bool        `json:"underline,omitempty"`
	Fill      string      `json:"fill,omitempty"`
	Color     string      `json:"color,omitempty"`
	Align     string      `json:"align,omitempty"`
	VAlign    string      `json:"valign,omitempty"`
	Wrap      string      `json:"wrap,omitempty"`
	Border    *CellBorder `json:"border,omitempty"`
	// contains filtered or unexported fields
}

CellFormat is the stored portable bag on a cell (absolute state). Mutation uses FormatPatch so agents can clear fields (bold=false).

func (*CellFormat) ApplyPatch

func (f *CellFormat) ApplyPatch(p FormatPatch)

ApplyPatch writes each set field, including false and empty.

func (CellFormat) IsZero

func (f CellFormat) IsZero() bool

IsZero reports whether no format fields are set (do not send on write).

func (*CellFormat) Normalize

func (f *CellFormat) Normalize()

Normalize maps align, valign, wrap, and border style onto the portable bag.

func (*CellFormat) Overlay

func (f *CellFormat) Overlay(src CellFormat)

Overlay copies src fields that are known or non-zero onto f.

func (CellFormat) String

func (f CellFormat) String() string

String is the tool format bag: number=$#,##0.00,bold,border=thin:bottom

type Codec

type Codec interface {
	MediaTypes() []string
	Decode(ctx context.Context, path, mediaType string, data []byte) (Document, error)
}

Codec decodes raw bytes into a Document IR. mediaType is chosen by the caller (typically DetectMediaType); codecs must not re-sniff.

type ContentRegistry

type ContentRegistry struct {
	// contains filtered or unexported fields
}

ContentRegistry maps media types to the codecs a MountSession reads and writes documents with. It is immutable: NewContentRegistry builds one, and a host adds codecs to its tree with OpenVFS.WithCodecs.

func NewContentRegistry

func NewContentRegistry(codecs ...Codec) (*ContentRegistry, error)

NewContentRegistry returns TextCodec for the text types plus codecs. Two codecs for one media type is ErrAlreadyRegistered.

func (*ContentRegistry) Decode

func (r *ContentRegistry) Decode(ctx context.Context, path, mediaType string, data []byte) (Document, error)

Decode looks up a codec for mediaType and decodes data.

func (*ContentRegistry) Encode added in v0.5.0

func (r *ContentRegistry) Encode(ctx context.Context, doc Document) ([]byte, error)

Encode is doc as the bytes its codec stores, or its text when the codec does not encode.

func (*ContentRegistry) HasStructure added in v0.5.0

func (r *ContentRegistry) HasStructure(mediaType string) bool

HasStructure reports whether documents of mediaType expose a block tree (Structured.Blocks): Markdown headings, or a projected rich or grid codec.

func (*ContentRegistry) Identity added in v0.5.0

func (r *ContentRegistry) Identity(mediaType string) bool

Identity reports whether mediaType's stored bytes are its text: an IdentityCodec owns it, so raw byte writes (FUSE, shell) are safe.

func (*ContentRegistry) Lookup

func (r *ContentRegistry) Lookup(mediaType string) (Codec, bool)

Lookup returns the codec bound to mediaType, if any.

func (*ContentRegistry) Projected added in v0.5.0

func (r *ContentRegistry) Projected(mediaType string) bool

Projected reports whether mediaType has a rich or grid codec. Projected bodies are not raw-byte writes (FUSE, shell); identity/text bodies are.

type ContentRev

type ContentRev struct {
	Path string
	Hash string
}

ContentRev identifies session-visible file content for optimistic concurrency. Hash is hex SHA-256 of the UTF-8 body (same policy as vfsindex content_hash). vfs does not enforce edits; harness tools compare expected Hash before write.

type Creator

type Creator interface {
	Create(path, mediaType string, mut Mutation) (Document, error)
}

Creator builds a new document from a create-mode Mutation. Codecs that own a representation (blocks, grid) implement this. MountSession looks up the codec by media type; it does not switch on vendors.

type DirEntry

type DirEntry struct {
	Name  string
	IsDir bool
	// Type is the file mode bits (same as fs.DirEntry.Type).
	Type fs.FileMode
}

DirEntry is a single directory entry.

type DocTab

type DocTab struct {
	ID    string
	Title string
	Index int
}

DocTab is one document tab (Docs includeTabsContent).

type DocsAPI

type DocsAPI interface {
	Get(ctx context.Context, documentID string) (DocsSnapshot, error)
	BatchUpdate(ctx context.Context, documentID string, req DocsBatch) (DocsBatchResult, error)
}

DocsAPI is the Docs subset used by the provider.

func NewGoogleDocs

func NewGoogleDocs(holder *TokenHolder, base string, httpClient *http.Client) DocsAPI

NewGoogleDocs returns a DocsAPI that authenticates with holder (required). base is the API root ("" for Google's); httpClient nil is http.DefaultClient.

type DocsBatch

type DocsBatch struct {
	RequiredRevisionID string
	TabID              string
	Requests           []DocsRequest
}

DocsBatch is one documents.batchUpdate call.

type DocsBatchResult

type DocsBatchResult struct {
	RevisionID string
}

DocsBatchResult is writeControl.requiredRevisionId after apply.

type DocsBullets added in v0.5.0

type DocsBullets struct {
	Range        DocsRange
	BulletPreset string
}

DocsBullets makes the paragraphs in Range a list with BulletPreset.

type DocsCell

type DocsCell struct {
	Row, Col             int
	StartIndex, EndIndex int
	Text                 string
}

DocsCell is one table cell's first paragraph.

type DocsCodec

type DocsCodec struct{}

DocsCodec decodes Google Docs HTML (unzipped export or canonical projection) into *RichDocument. It does not implement IdentityCodec.

func (DocsCodec) Create

func (DocsCodec) Create(path, mediaType string, mut Mutation) (Document, error)

Create lifts plaintext or blocks into a rich checkout.

func (DocsCodec) Decode

func (DocsCodec) Decode(ctx context.Context, virtualPath, mediaType string, data []byte) (Document, error)

Decode requires valid UTF-8 and rejects payloads larger than MaxReadFileBytes.

func (DocsCodec) MediaTypes

func (DocsCodec) MediaTypes() []string

MediaTypes implements Codec.

type DocsInsertTable added in v0.5.0

type DocsInsertTable struct {
	Location      DocsLocation
	Rows, Columns int
}

DocsInsertTable inserts an empty Rows × Columns table at Location.

type DocsInsertText added in v0.5.0

type DocsInsertText struct {
	Location DocsLocation
	Text     string
}

DocsInsertText inserts Text at Location.

type DocsListProps

type DocsListProps struct {
	GlyphTypes []string
}

DocsListProps is list metadata from documents.get: the glyph type of each nesting level ("" where the level has none).

type DocsLocation added in v0.5.0

type DocsLocation struct {
	Index int
	TabID string
}

DocsLocation is one Docs body index of one tab. An empty TabID is the batch's tab.

type DocsParagraphStyle added in v0.5.0

type DocsParagraphStyle struct {
	Range          DocsRange
	NamedStyleType string
}

DocsParagraphStyle sets the named style (NORMAL_TEXT, HEADING_1, …) of the paragraphs in Range.

type DocsRange added in v0.5.0

type DocsRange struct {
	StartIndex, EndIndex int
	TabID                string
}

DocsRange is the Docs body indexes [StartIndex, EndIndex) of one tab. An empty TabID is the batch's tab.

type DocsRequest

type DocsRequest struct {
	DeleteContentRange     *DocsRange
	InsertText             *DocsInsertText
	UpdateParagraphStyle   *DocsParagraphStyle
	CreateParagraphBullets *DocsBullets
	InsertTable            *DocsInsertTable
	UpdateTextStyle        *DocsTextStyle
}

DocsRequest is one batchUpdate request. Exactly one field is set; the field names are the Docs API request names.

type DocsSnapshot

type DocsSnapshot struct {
	DocumentID string
	RevisionID string
	Title      string
	Tabs       []DocTab
	Body       []DocsSpan
	Lists      map[string]DocsListProps
}

DocsSnapshot is the checkout used to build IR and persistHint.

type DocsSpan

type DocsSpan struct {
	TabID      string
	StartIndex int
	EndIndex   int
	Kind       string
	ObjectID   string
	Level      int
	NamedStyle string
	ListID     string
	Nesting    int
	Text       string
	Cells      []DocsCell
}

DocsSpan is one IR-mapped (or structural) span from a tab body.

type DocsTextStyle added in v0.5.0

type DocsTextStyle struct {
	Range                       DocsRange
	Bold, Italic, Strikethrough bool
	Link                        string
}

DocsTextStyle sets bold, italic, strikethrough and the link of the text in Range. An empty Link removes the link.

type Document

type Document interface {
	Path() string
	MediaType() string
}

Document is the general content IR. Codecs produce Document values that are independent of storage backends (local, S3, Drive, …).

Path is always a virtual path — never a host filesystem path or bucket key.

type DriveAPI

type DriveAPI interface {
	GetMeta(ctx context.Context, fileID string) (DriveMeta, error)
	// GetMedia opens n bytes of the file's content from off. n < 0 reads to
	// the end; n is never 0.
	GetMedia(ctx context.Context, fileID string, off, n int64) (io.ReadCloser, error)
	List(ctx context.Context, folderID string) ([]DriveMeta, error)
	Export(ctx context.Context, fileID, mimeType string) (io.ReadCloser, int64, error)
	PutMedia(ctx context.Context, fileID, mediaMIME string, r io.Reader, size int64) (DriveMeta, error)
	Create(ctx context.Context, parentID, name, metadataMIME, mediaMIME string, r io.Reader, size int64) (DriveMeta, error)
	Trash(ctx context.Context, fileID string) error
	Mkdir(ctx context.Context, parentID, name string) (DriveMeta, error)
}

DriveAPI is the Drive subset used by the provider. Hosts pass NewGoogleDrive.

func NewGoogleDrive

func NewGoogleDrive(holder *TokenHolder, base string, httpClient *http.Client) DriveAPI

NewGoogleDrive returns a DriveAPI that authenticates with holder (required). base is the API root ("" for Google's); httpClient nil is http.DefaultClient. Call it from OpenVFS when a drive bind arrives, then pass the result to Drive.

type DriveFinder added in v0.5.0

type DriveFinder interface {
	Find(ctx context.Context, folderID, name string) ([]DriveMeta, error)
}

DriveFinder is a DriveAPI that can list only the children of folderID with one name (a Drive query), so a path resolves without listing whole folders. The provider uses it when the DriveAPI has it.

type DriveMeta

type DriveMeta struct {
	ID         string
	Name       string
	MimeType   string
	Size       int64
	ModTime    time.Time
	Version    string
	MD5        string // content checksum; empty for folders and Google-native files
	IsDir      bool
	TargetID   string
	TargetMime string
}

DriveMeta is one Drive file or folder (IDs stay inside the provider).

type Encoder

type Encoder interface {
	Encode(ctx context.Context, doc Document) ([]byte, error)
}

Encoder is the optional write side of a Codec. Rich document codecs use it to encode the edited canonical projection back to source bytes.

type File

type File interface {
	io.Closer
	Stat() (FileInfo, error)
}

File is an open handle. Close and Stat always work.

Extra capabilities are optional interfaces — comma-ok, not dummy methods:

r, ok := f.(io.Reader)   // sequential read
ra, ok := f.(io.ReaderAt) // offset read (FUSE)
w, ok := f.(io.Writer)    // sequential write

type FileInfo

type FileInfo struct {
	Name      string
	Size      int64
	Mode      fs.FileMode
	ModTime   time.Time
	IsDir     bool
	MediaType string
	// Version changes whenever the file's content changes (an ETag, a
	// content tag, or size+mtime+inode on disk). Empty when the backend
	// cannot tell; callers then read the content to detect a change.
	Version string
}

FileInfo describes a file or directory (agent-safe: no host paths).

MediaType is the provider's classification of a file (never a host path). Empty on directories. On files, providers must set it: a concrete type (text/markdown, image/png, …) or application/octet-stream when unknown. OpenDocument does not sniff; it only looks up a codec for this value.

type FormatPatch

type FormatPatch struct {
	Number    *string     `json:"number,omitempty"`
	Bold      *bool       `json:"bold,omitempty"`
	Italic    *bool       `json:"italic,omitempty"`
	Strike    *bool       `json:"strike,omitempty"`
	Underline *bool       `json:"underline,omitempty"`
	Fill      *string     `json:"fill,omitempty"`
	Color     *string     `json:"color,omitempty"`
	Align     *string     `json:"align,omitempty"`
	VAlign    *string     `json:"valign,omitempty"`
	Wrap      *string     `json:"wrap,omitempty"`
	Border    *CellBorder `json:"border,omitempty"`
}

FormatPatch is an explicit format write. Nil pointer = leave; set pointer = write (including false / empty). Zero Border clears the border.

type GitCredential added in v0.4.2

type GitCredential interface {
	// contains filtered or unexported methods
}

GitCredential is a service-account credential for cloning one git remote. Only GitToken and GitSSHKey make one. It reaches the clone through the git process environment and temp files that are removed after the clone, so it never lands in the checkout's .git/config, a Binding or a checkpoint.

func GitSSHKey added in v0.4.2

func GitSSHKey(privateKeyPEM, knownHosts []byte) GitCredential

GitSSHKey authenticates SSH remotes with an unencrypted deploy key. The SSH user comes from the URL (git@host:org/repo.git). knownHosts holds known_hosts lines; the server key must match one of them, so there is no trust-on-first-use.

func GitToken added in v0.4.2

func GitToken(user string, token func(ctx context.Context) (string, error)) GitCredential

GitToken authenticates HTTPS remotes with basic auth. user is the name the git host expects with a token ("x-access-token" on GitHub, "oauth2" on GitLab). token is called once for each clone, so the host can rotate it.

type GitRepo added in v0.4.2

type GitRepo struct {
	// URL is the remote (https://…, ssh://… or user@host:path).
	URL string
	// Auth is the service-account credential for the clone. Nil reaches
	// public remotes only.
	Auth GitCredential
	// Ref is the branch or tag to check out. Empty uses the remote HEAD.
	Ref string
	// Depth limits clone history (0 = full history).
	Depth int
	// Dir is the host directory that holds checkouts on worker disk. Each
	// session gets Dir/<sessionID>/<member name>.
	Dir string
}

GitRepo configures one git remote as a host-owned mount.

type GraphAPI

type GraphAPI interface {
	// ResolveRoot is the drive and folder a binding opens: driveID, else the
	// drive of siteID, else the user's own drive (/me/drive). An empty
	// itemID is the drive root. It fails when the item is not a folder.
	ResolveRoot(ctx context.Context, driveID, itemID, siteID string) (driveIDOut, itemIDOut string, err error)
	GetItem(ctx context.Context, driveID, itemID string) (GraphItem, error)
	GetByPath(ctx context.Context, driveID, itemID, rel string) (GraphItem, error)
	ListChildren(ctx context.Context, driveID, itemID string) ([]GraphItem, error)
	// GetContent opens n bytes of the item's content from off. n < 0 reads
	// to the end; n is never 0.
	GetContent(ctx context.Context, driveID, itemID string, off, n int64) (io.ReadCloser, error)
	PutContent(ctx context.Context, driveID, itemID, name, parentID string, r io.Reader, size int64) (GraphItem, error)
	CreateFolder(ctx context.Context, driveID, parentID, name string) (GraphItem, error)
	Delete(ctx context.Context, driveID, itemID string) error
}

GraphAPI is the OneDrive/SharePoint subset the provider uses. NewMicrosoftGraph implements it over the Graph REST API (no Microsoft SDK).

func NewMicrosoftGraph added in v0.5.0

func NewMicrosoftGraph(holder *TokenHolder, base string, httpClient *http.Client) GraphAPI

NewMicrosoftGraph returns a GraphAPI that authenticates with holder (required). base is the API root, ending in "/" ("" for the public Graph endpoint; set it for a national cloud or a proxy); httpClient nil is http.DefaultClient. Pass the result to Graph.

type GraphItem added in v0.5.0

type GraphItem struct {
	ID, Name, Mime, ParentID string
	Size                     int64
	IsDir                    bool
	LastModified             time.Time
	CTag                     string // changes only when the content changes
}

GraphItem is one Graph file or folder (IDs stay inside the provider).

type Grid

type Grid interface {
	Sheets() []Sheet
	NamedRanges() []NamedRange
	Cell(key, a1 string) (Cell, error)
	ReadRows(key string, start, end int) (Sheet, []string, error)
	ReadCell(key, a1 string) (string, error)
	ReadRangeTSV(key, a1 string) (string, error)
}

Grid is the spreadsheet representation of a Document (Sheets / Excel).

func AsGrid

func AsGrid(doc Document) (Grid, bool)

AsGrid reports whether doc is represented as a spreadsheet grid.

type IR

type IR struct {
	// contains filtered or unexported fields
}

ir is the one document checkout. Codecs pick a body (text, blocks, or grid). MountSession and tools see Path, MediaType, Textual, Structured, and optional AsGrid / AsRich — not backends or concrete file types.

func NewRichDocument

func NewRichDocument(path, mediaType string, blocks []Block) *IR

func NewTabularDocument

func NewTabularDocument(path, mediaType string, sheets []Sheet, named []NamedRange) (*IR, error)

NewTabularDocument builds a grid checkout, trims trailing empty rows/cols, and rejects grids larger than MaxSheetCells.

func NewTextDocument

func NewTextDocument(path, mediaType, encoding, text string) *IR

NewTextDocument builds a plaintext checkout (identity body).

func (*IR) Blocks

func (d *IR) Blocks() []Block

func (*IR) ContentFingerprint

func (d *IR) ContentFingerprint() string

func (*IR) Encoding

func (d *IR) Encoding() string

func (*IR) Line

func (d *IR) Line(n int) (string, error)

func (*IR) LineCount

func (d *IR) LineCount() int

func (*IR) Lines

func (d *IR) Lines(start, end int) ([]string, error)

func (*IR) MediaType

func (d *IR) MediaType() string

func (*IR) Path

func (d *IR) Path() string

func (*IR) ReplaceLines

func (d *IR) ReplaceLines(start, end int, replacement []string) error

func (*IR) SetLine

func (d *IR) SetLine(n int, line string) error

func (*IR) SetText

func (d *IR) SetText(text string) error

func (*IR) Text

func (d *IR) Text() string

type IdentityCodec

type IdentityCodec interface {
	Codec
	Identity()
}

IdentityCodec is a Codec whose persist form is the UTF-8 payload itself (no container). TextCodec implements it. Office/cloud codecs (Word, Notion, Google Docs) must not — FUSE then returns EROFS and the write tool uses WriteDocument. Register those codecs under their native media types; do not steal text/markdown.

type LineWindow

type LineWindow struct {
	Path      string
	Start     int
	End       int
	Lines     []string
	Returned  int
	EOF       bool
	NextStart int
	Rev       ContentRev
}

LineWindow is one progressive page of lines from a virtual path.

Start/End are the half-open 1-based range requested (End may be clamped by MaxLinesPerWindow). EOF is true when the file ended at or before the last returned line. NextStart is Start+Returned (useful when !EOF for paging).

Rev is set when the window is served from a full textual body (cheap hash). Stream reads leave Rev empty; callers use ContentRev when needed.

type Member

type Member struct {
	// contains filtered or unexported fields
}

Member is one /workspace/<name> backend.

func At

func At(name string, open Open) Member

At names a backend under /workspace. name is the first path segment (/workspace/scratch/…).

func (Member) NotIndexed added in v0.5.0

func (m Member) NotIndexed() Member

NotIndexed makes index_file refuse this member's files.

func (Member) ReadOnly

func (m Member) ReadOnly() Member

ReadOnly marks a host-owned member read-only. User-owned members use Binding.Writable instead.

type MemorySheets

type MemorySheets struct {
	// contains filtered or unexported fields
}

MemorySheets is an in-memory SheetsAPI. Tests and local harnesses use it instead of the Google service.

func NewMemorySheets

func NewMemorySheets() *MemorySheets

NewMemorySheets returns an empty in-memory workbook store.

func (*MemorySheets) BatchUpdate

func (m *MemorySheets) BatchUpdate(ctx context.Context, spreadsheetID string, req SheetsBatch) error

func (*MemorySheets) BatchUpdateValues

func (m *MemorySheets) BatchUpdateValues(ctx context.Context, spreadsheetID string, req SheetsValuesBatch) error

func (*MemorySheets) Get

func (m *MemorySheets) Get(ctx context.Context, spreadsheetID string) (SheetsSnapshot, error)

func (*MemorySheets) Seed

func (m *MemorySheets) Seed(id string, snap SheetsSnapshot)

Seed replaces the snapshot for id (deep-copied).

type MountSession

type MountSession struct {
	// contains filtered or unexported fields
}

MountSession groups providers for one session. Route returns the provider for a path. The provider reads, writes, and returns the error. Tree creates the session and mounts /workspace. The agent harness only borrows the pointer.

func NewMountSession

func NewMountSession(sessionID string) (*MountSession, error)

NewMountSession binds a session id. Hosts use Tree.

func (*MountSession) Apply

func (ms *MountSession) Apply(ctx context.Context, virtualPath string, mut Mutation) (ApplyResult, error)

Apply persists one mutation. Empty Rev uses the harness lastRev or a live read.

func (*MountSession) Codecs added in v0.5.0

func (m *MountSession) Codecs() *ContentRegistry

Codecs is the registry the session reads and writes documents with.

func (*MountSession) ContentRev

func (m *MountSession) ContentRev(ctx context.Context, virtualPath string) (ContentRev, error)

ContentRev hashes the session-visible body: ReadText when textual (same bytes FUSE and the read tool show), otherwise ReadFile.

func (*MountSession) Route added in v0.4.0

func (m *MountSession) Route(ctx context.Context, virtualPath string) Route

Route returns the provider mounted at virtualPath. A failed lookup is stored on Route and returned by the file methods.

func (*MountSession) SpecAt

func (m *MountSession) SpecAt(virtualPath string) (MountSpec, error)

SpecAt returns the MountSpec for the backend that owns virtualPath. Clone is safe to retain; no secrets.

func (*MountSession) Specs

func (m *MountSession) Specs() []MountSpec

Specs returns the durable mount records (checkpoint-safe; no host paths or secrets).

func (*MountSession) WriteDocument

func (m *MountSession) WriteDocument(ctx context.Context, doc Document) error

WriteDocument asks the provider for the document path to translate IR and persist.

type MountSpec

type MountSpec struct {
	Point    string            `json:"point"`
	Profile  string            `json:"profile"`
	ReadOnly bool              `json:"readOnly,omitempty"`
	Params   map[string]string `json:"params,omitempty"`
	// NotIndexed makes index_file refuse files on this mount.
	NotIndexed bool `json:"notIndexed,omitempty"`
}

MountSpec is the durable, secret-free description of a mount. Safe to JSON into session checkpoints. Never store credentials here.

type Mutation

type Mutation struct {
	Rev            string
	Content        *string
	Old            *string
	New            *string
	ReplaceAll     bool
	Start, End     *int
	Lines          []string
	Body           *string
	BlockID        string
	IncludeHeading bool
	Blocks         []Block
	TabID          string
	MediaType      string
	Format         *FormatPatch
}

Mutation is one write against a virtual path. Addresses are replace-whole (Content) or replace-span (line Start/End, or BlockID including Sheet!A1). Old/New finds a span; Blocks is create/replace of structured IR on Apply.

type NamedRange

type NamedRange struct {
	Name, SheetID, A1 string
}

NamedRange is a workbook named range.

type Open

type Open func(ctx context.Context, sessionID string, b mount.Binding) (Provider, error)

Open opens a Provider. Close over clients in the function. Binding carries this turn's user token and params (folderId, subpath, …). A nil Provider and nil error means skip (no token for a user-scoped backend).

func Blob

func Blob(client S3API, defaultContainer string) Open

Blob opens Azure Blob providers that share one S3API client (HTTP pool). The object model matches S3: a container is the bucket, blob names are keys, and delimiter "/" listing gives virtual directories.

func Drive

func Drive(api DriveAPI, holder *TokenHolder) Open

Drive opens a Google Drive folder. api is required (NewGoogleDrive). holder is the token holder api authenticates with, so a near-expiry or rejected token refreshes there; nil uses the binding's token without refresh. folderId and writable come from this turn's Binding.

func DriveWith

func DriveWith(api DriveAPI, docs DocsAPI, sheets SheetsAPI, holder *TokenHolder) Open

DriveWith is Drive plus Docs/Sheets clients for native Google files.

func Git added in v0.4.2

func Git(repo GitRepo) Open

Git clones a remote onto local disk with the git CLI and mounts the working tree like Local: writes go to the checkout on disk. The agent runs every git command (status, commit, push, …) itself through run_command, so the environment needs git, and pushing needs credentials the environment gives the shell. The clone credential is not kept.

The first open for a session clones; later opens on the same worker reuse the checkout as the agent left it. A checkout lives on worker disk only: work that is not pushed is lost when a session moves to another worker.

vfs.Tree(vfs.At("api", vfs.Git(api)), vfs.At("docs", vfs.Git(docs)).ReadOnly())

func Graph

func Graph(api GraphAPI, holder *TokenHolder, account string) Open

Graph opens OneDrive / SharePoint. api is a NewMicrosoftGraph result or another GraphAPI.

func Local

func Local(base string) Open

Local opens providers under a fixed jail. Params: "subpath" (optional), "session_scoped=true" (optional: the session's own directory, as SessionLocal gives). The jail stays in the closure; providers never expose host roots.

func S3

func S3(client S3API, defaultBucket string) Open

S3 opens providers that share one S3API client (HTTP pool). defaultBucket is used when the spec omits params["bucket"].

func SessionLocal added in v0.5.0

func SessionLocal(base string) Open

SessionLocal is Local where each session gets its own directory under base, so no session sees another's files. A child session (a specialist or a job) gets a directory of its own too.

func Union

func Union(opens ...Open) Open

Union merges backends into one read-only Open. Skill packs use Tree(At("skills", Union(...))) when skills live on the workspace.

type OpenVFS

type OpenVFS func(ctx context.Context, sessionID string, req Request) (*MountSession, error)

OpenVFS builds a turn-scoped MountSession. Nil OpenVFS means no VFS.

func Tree

func Tree(members ...Member) OpenVFS

Tree mounts every member under /workspace — the only top-level mount. Hosts omit user-cloud members they did not construct from this turn's bind.

func (OpenVFS) WithCodecs added in v0.5.0

func (o OpenVFS) WithCodecs(codecs ...Codec) OpenVFS

WithCodecs opens the tree with codecs added to the text codec and the codecs of the mounted backends' own types, for example vfs/adapters' Word and Excel:

vfs.Tree(members...).WithCodecs(adapters.Codecs()...)

Only the codecs a host names are linked into its binary.

type Provider

type Provider interface {
	Validate(ctx context.Context) error

	Stat(ctx context.Context, name string) (FileInfo, error)
	OpenFile(ctx context.Context, name string, flag int, perm fs.FileMode) (File, error)
	ReadDir(ctx context.Context, name string) ([]DirEntry, error)
	Remove(ctx context.Context, name string) error
	MkdirAll(ctx context.Context, name string, perm fs.FileMode) error
}

Provider is a backend attached at a virtual mount point.

One interface covers mount validation and path I/O relative to the provider root. Paths use slash-separated relative names ("" = root). Backends that do not support I/O yet return ErrNotSupported from I/O methods.

Treat provider values as immutable after a successful FS.Mount.

func NewLocalProvider

func NewLocalProvider(dir string) (Provider, error)

NewLocalProvider returns a Provider rooted at a canonical absolute directory.

type Request

type Request struct {
	Bindings []mount.Binding
}

Request is this turn's user-owned bind list (tokens + params). Host-owned At members ignore it. User-owned backends (Drive, Graph) match Binding params["name"] to the At name.

type Rich

type Rich interface {
	Tabs() []DocTab
	Blocks() []Block
	ReplaceBlock(id, text string, includeHeading bool) error
	SetBlocks(blocks []Block)
}

Rich is the block-tree representation of a Document (Docs / Word).

func AsRich

func AsRich(doc Document) (Rich, bool)

AsRich reports whether doc is represented as a block tree (Docs / Word).

type Route added in v0.4.0

type Route struct {
	Provider Provider
	Spec     MountSpec
	Point    string
	Rel      string
	// contains filtered or unexported fields
}

Route is the provider for one virtual path. MountSession only chooses it. The provider does the file work and returns its own errors.

func (Route) MkdirAll added in v0.4.0

func (r Route) MkdirAll(ctx context.Context) error

func (Route) Open added in v0.4.0

func (r Route) Open(ctx context.Context) (File, error)

func (Route) OpenDocument added in v0.4.0

func (r Route) OpenDocument(ctx context.Context) (Document, error)

OpenDocument decodes the file with the session's codecs.

func (Route) ReadDir added in v0.4.0

func (r Route) ReadDir(ctx context.Context) ([]DirEntry, error)

func (Route) ReadFile added in v0.4.0

func (r Route) ReadFile(ctx context.Context) ([]byte, error)

func (Route) ReadLines added in v0.4.0

func (r Route) ReadLines(ctx context.Context, start, end int) (LineWindow, error)

ReadLines streams virtualPath and returns a line window for the half-open 1-based range [start, end).

Large files are allowed: unlike ReadFile/ReadText there is no full-object size reject. Only MaxLineScanBytes (bytes read this call), MaxLineBytes (per line), and MaxLinesPerWindow apply.

If the file ends before end, the available lines are returned with EOF=true (not ErrLineOutOfRange). ErrLineOutOfRange only when start is past EOF.

func (Route) ReadText added in v0.4.0

func (r Route) ReadText(ctx context.Context) (Textual, error)

func (Route) Remove added in v0.4.0

func (r Route) Remove(ctx context.Context) error

func (Route) Stat added in v0.4.0

func (r Route) Stat(ctx context.Context) (FileInfo, error)

func (Route) WriteDocument added in v0.4.0

func (r Route) WriteDocument(ctx context.Context, doc Document) error

func (Route) WriteFile added in v0.4.0

func (r Route) WriteFile(ctx context.Context, data []byte) error

type Run

type Run struct {
	Text  string
	Marks map[string]string
}

Run is one contiguous marked slice of a block. Marks keys are MarkBold, MarkItalic, MarkStrike, MarkHref. Agents never send Runs; they write markdown in Block.Text (**bold**, _italic_, ~~strike~~, [label](url)).

func ParseInline

func ParseInline(s string) []Run

ParseInline turns the agent markdown subset into runs.

type S3API

type S3API interface {
	Head(ctx context.Context, bucket, key string) (S3Object, error)
	// Get opens n bytes of the object from off. n < 0 reads to the end; n is
	// never 0.
	Get(ctx context.Context, bucket, key string, off, n int64) (io.ReadCloser, error)
	Put(ctx context.Context, bucket, key string, body io.Reader, size int64) error
	Delete(ctx context.Context, bucket, key string) error
	// List returns object keys and "directory" prefixes under prefix (delimiter "/").
	// prefix should end with "/" when listing a directory, or be the full key prefix.
	List(ctx context.Context, bucket, prefix string) (keys []string, dirs []string, err error)
}

S3API is the subset of an S3-compatible API used by the S3 provider. Hosts pass awss3.API{Client: c} (package vfs/awss3) or their own adapter.

type S3Object added in v0.5.0

type S3Object struct {
	Size        int64
	ModTime     time.Time
	ContentType string // empty if unknown
	// ETag changes whenever the object's content changes.
	ETag string
}

S3Object is the metadata Head returns for one object.

type SessionAuth

type SessionAuth struct {
	// contains filtered or unexported fields
}

SessionAuth is the in-memory store of user-owned backend credentials. Tokens live on TokenHolder only; Binding.Auth is not the live copy.

func NewSessionAuth

func NewSessionAuth() *SessionAuth

NewSessionAuth returns an empty store.

func (*SessionAuth) Bind

func (s *SessionAuth) Bind(sessionID string, b mount.Binding) error

Bind records a folder mount and its access token. Cloud binds attach under /workspace/<alias>. A second bind to the same alias replaces it. A new token for the same provider updates the shared holder.

func (*SessionAuth) Bindings

func (s *SessionAuth) Bindings(sessionID string) []mount.Binding

Bindings returns a copy of the session bindings (no tokens).

func (*SessionAuth) Clear

func (s *SessionAuth) Clear(sessionID string)

Clear drops every binding and token for the session.

func (*SessionAuth) Credential

func (s *SessionAuth) Credential(sessionID, provider string) (mount.Credential, bool)

Credential returns the current credential for provider, or false.

func (*SessionAuth) HasBindings

func (s *SessionAuth) HasBindings(sessionID string) bool

HasBindings reports whether the session has at least one user-owned binding.

func (*SessionAuth) Holder

func (s *SessionAuth) Holder(sessionID, provider string) *TokenHolder

Holder returns the shared token holder, or nil.

func (*SessionAuth) Refresh

func (s *SessionAuth) Refresh(sessionID, provider string, c mount.Credential) error

Refresh replaces the access token for provider on the session.

func (*SessionAuth) Unbind

func (s *SessionAuth) Unbind(sessionID, point string) error

Unbind removes the binding for alias. point may be leftover "/contracts" or the alias itself. The provider token is dropped when no binding remains for that provider. Unbind("/workspace") is invalid — pass the alias.

func (*SessionAuth) UnbindProvider

func (s *SessionAuth) UnbindProvider(sessionID, provider string) error

UnbindProvider removes every binding for provider on the session.

type Sheet

type Sheet struct {
	ID    string
	Title string
	Index int
	Rows  int
	Cols  int
	Cells [][]Cell
	// contains filtered or unexported fields
}

Sheet is one used rectangle. Cells[r][c] is 0-based; agent rows/cols are 1-based.

func WithMerge

func WithMerge(sh Sheet, startRow, startCol, endRow, endCol int) Sheet

WithMerge records a 0-based half-open merge rectangle from a provider checkout.

func (Sheet) MergeBounds added in v0.3.4

func (sh Sheet) MergeBounds() [][4]int

MergeBounds is 0-based half-open [r1,c1,r2,c2) rectangles from checkout.

type SheetNormalizer

type SheetNormalizer interface {
	DecodeSheets(ctx context.Context, path, mediaType string, data []byte) ([]Sheet, []NamedRange, error)
	EncodeSheets(ctx context.Context, sheets []Sheet, named []NamedRange) ([]byte, error)
}

SheetNormalizer converts a workbook format to and from []Sheet.

type SheetsAPI

type SheetsAPI interface {
	Get(ctx context.Context, spreadsheetID string) (SheetsSnapshot, error)
	BatchUpdateValues(ctx context.Context, spreadsheetID string, req SheetsValuesBatch) error
	BatchUpdate(ctx context.Context, spreadsheetID string, req SheetsBatch) error
}

SheetsAPI is the Sheets subset used by the provider. MemorySheets is the in-memory implementation; NewGoogleSheets talks to the service.

func NewGoogleSheets

func NewGoogleSheets(holder *TokenHolder, base string, httpClient *http.Client) SheetsAPI

NewGoogleSheets returns a SheetsAPI that authenticates with holder (required). base is the API root ("" for Google's); httpClient nil is http.DefaultClient.

type SheetsBatch

type SheetsBatch struct {
	Requests []SheetsRepeatCell
}

SheetsBatch is one spreadsheets.batchUpdate (repeatCell userEnteredFormat).

type SheetsCodec

type SheetsCodec struct{}

SheetsCodec is the default-registry codec for Google Sheets HTML export.

func (SheetsCodec) Create

func (SheetsCodec) Create(path, mediaType string, mut Mutation) (Document, error)

func (SheetsCodec) Decode

func (SheetsCodec) Decode(ctx context.Context, virtualPath, mediaType string, data []byte) (Document, error)

func (SheetsCodec) MediaTypes

func (SheetsCodec) MediaTypes() []string

type SheetsHTML

type SheetsHTML struct{}

SheetsHTML decodes Google Sheets HTML ZIP export (Drive RO).

func (SheetsHTML) DecodeSheets

func (SheetsHTML) DecodeSheets(_ context.Context, _, _ string, data []byte) ([]Sheet, []NamedRange, error)

func (SheetsHTML) EncodeSheets

func (SheetsHTML) EncodeSheets(context.Context, []Sheet, []NamedRange) ([]byte, error)

type SheetsRepeatCell

type SheetsRepeatCell struct {
	SheetID            int64
	StartRow, StartCol int // 0-based inclusive
	EndRow, EndCol     int // 0-based exclusive
	Format             CellFormat
}

SheetsRepeatCell is one repeatCell of a format bag.

type SheetsSnapshot

type SheetsSnapshot struct {
	SpreadsheetID string
	RevisionID    string
	Sheets        []Sheet
	Named         []NamedRange
}

SheetsSnapshot is the checkout used to build TabularDocument.

type SheetsValueRange

type SheetsValueRange struct {
	Range  string
	Values [][]string
}

SheetsValueRange is one A1 range of string cells (USER_ENTERED).

type SheetsValuesBatch

type SheetsValuesBatch struct {
	Data []SheetsValueRange
}

SheetsValuesBatch is one spreadsheets.values.batchUpdate call.

type Span

type Span struct {
	StartLine int
	EndLine   int
}

Span is a line-based content address (1-based half-open).

type Structured

type Structured interface {
	Document
	Blocks() []Block
}

Structured is optional for documents with a block tree (Markdown headings, Word, Google Docs, …). Callers use Blocks(); empty means no structure.

type StyleMeta

type StyleMeta struct {
	Kind       string
	Level      int
	Span       Span
	Attributes map[string]string
}

StyleMeta is optional presentation/structure for rich documents.

type TabularCodec

type TabularCodec struct {
	Types      []string
	Normalizer SheetNormalizer
}

TabularCodec adapts a SheetNormalizer to the VFS codec registry. Decode yields a grid checkout. Encode writes native bytes (xlsx, …).

func (TabularCodec) Create

func (c TabularCodec) Create(virtualPath, mediaType string, mut Mutation) (Document, error)

func (TabularCodec) Decode

func (c TabularCodec) Decode(ctx context.Context, virtualPath, mediaType string, data []byte) (Document, error)

func (TabularCodec) Encode

func (c TabularCodec) Encode(ctx context.Context, doc Document) ([]byte, error)

func (TabularCodec) MediaTypes

func (c TabularCodec) MediaTypes() []string

type TextCodec

type TextCodec struct{}

TextCodec decodes UTF-8 text and text-like media types into *TextDocument. Identity: persist form is the UTF-8 payload (no container).

func (TextCodec) Decode

func (TextCodec) Decode(ctx context.Context, path, mediaType string, data []byte) (Document, error)

Decode builds a TextDocument from data. mediaType is the caller's detection result.

data is taken over as the document body (no extra content copy). Callers must not mutate data after Decode returns.

func (TextCodec) Identity

func (TextCodec) Identity()

Identity marks TextCodec as an IdentityCodec. FUSE may accept kernel writes.

func (TextCodec) MediaTypes

func (TextCodec) MediaTypes() []string

MediaTypes is the set of extension-map types this codec claims at registration.

type Textual

type Textual interface {
	Document
	Encoding() string
	Text() string
	LineCount() int
	Line(n int) (string, error)
	Lines(start, end int) ([]string, error)
	SetText(text string) error
	SetLine(n int, line string) error
	ReplaceLines(start, end int, replacement []string) error
}

Textual is document content that has a plaintext form (source, Markdown, Engrams, Word, Google Docs). Images and other binaries do not implement it — callers use a comma-ok assert.

Text() is that plaintext (FUSE / encode). Line numbers are 1-based. Lines(start, end) is half-open [start, end). SetText / SetLine / ReplaceLines mutate this value; persist with WriteDocument. SetText on Docs/Word applies HTML then SetBlocks; spreadsheets return ErrProjected.

type TokenHolder

type TokenHolder struct {
	// contains filtered or unexported fields
}

TokenHolder is the live access token for one (session, provider). All folder mounts for that pair share the same holder. Refresh updates every mount.

func NewTokenHolder

func NewTokenHolder(c mount.Credential) *TokenHolder

NewTokenHolder returns a holder with the initial credential.

func (*TokenHolder) Current

func (h *TokenHolder) Current() mount.Credential

Current returns a copy of the credential. Token is present; callers must not log it.

func (*TokenHolder) EnsureValid

func (h *TokenHolder) EnsureValid(ctx context.Context) error

EnsureValid proactively refreshes a token that is expired or near expiry. A zero ExpiresAt selects reactive refresh after a provider 401.

func (*TokenHolder) RefreshIfCurrent

func (h *TokenHolder) RefreshIfCurrent(ctx context.Context, staleToken string) error

RefreshIfCurrent refreshes only when staleToken is still installed. Parallel callers that observed the same rejected token wait for one shared refresh.

func (*TokenHolder) RefreshOnce

func (h *TokenHolder) RefreshOnce(ctx context.Context) error

RefreshOnce calls the refresh func once and stores the new token. Returns ErrAuthExpired when no refresh func is set or the client fails.

func (*TokenHolder) Set

func (h *TokenHolder) Set(c mount.Credential)

Set replaces the current credential.

func (*TokenHolder) SetRefresh

func (h *TokenHolder) SetRefresh(fn TokenRefreshFunc)

SetRefresh installs the optional client token callback used after a 401.

type TokenRefreshFunc

type TokenRefreshFunc func(ctx context.Context) (mount.Credential, error)

TokenRefreshFunc fetches a new access token (IdP or host callback).

Directories

Path Synopsis
Package adapters contains source-format codecs for rich text documents.
Package adapters contains source-format codecs for rich text documents.
Package awss3 connects the vfs S3 provider to the AWS SDK v2 S3 client:
Package awss3 connects the vfs S3 provider to the AWS SDK v2 S3 client:
Package azureblob connects the vfs Blob provider to the Azure Blob SDK:
Package azureblob connects the vfs Blob provider to the Azure Blob SDK:
Package fuse shows a vfs.MountSession as a directory on the host kernel, so host processes (run_command) see the session's virtual tree.
Package fuse shows a vfs.MountSession as a directory on the host kernel, so host processes (run_command) see the session's virtual tree.
internal
httprange
Package httprange is the HTTP Range handling the vfs SDK adapters share: n bytes from off, where n < 0 reads to the end and n is never 0.
Package httprange is the HTTP Range handling the vfs SDK adapters share: n bytes from off, where n < 0 reads to the end and n is never 0.
vfstest
Package vfstest is the contract every built-in vfs backend must meet.
Package vfstest is the contract every built-in vfs backend must meet.
Package mount is how a host names a cloud folder for a session to mount: the binding, its credential, and the parameter names providers read.
Package mount is how a host names a cloud folder for a session to mount: the binding, its credential, and the parameter names providers read.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL