storage

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package storage holds the filesystem primitives used by every other agents subpackage: atomic JSON write, JSONL append/read/tail/truncate, directory scan, and identifier validation. No agents-domain logic lives here — only generic on-disk helpers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendJSONL

func AppendJSONL(path string, format, sessionID string, v any) error

AppendJSONL appends one JSON-encoded line to path. Creates the file (with header `_meta` line) if missing. Each call opens, writes, fsyncs, closes — safe for concurrent appenders within one process given each write is one syscall < PIPE_BUF on POSIX. Cross-process safety is not promised; agents owns its files.

func CountJSONLEntries

func CountJSONLEntries(path string) (int, error)

CountJSONLEntries returns how many non-meta lines exist in path.

func PathExists

func PathExists(path string) bool

PathExists reports whether path exists (file or dir).

func ReadJSON

func ReadJSON(path string, v any) error

ReadJSON loads a JSON file into v. Forwards os.ErrNotExist verbatim so callers can distinguish "missing" from "corrupt".

func ReadJSONL

func ReadJSONL(path string, emit func(line []byte) bool) error

ReadJSONL streams every non-meta line in path to emit. emit returns false to stop early. A missing file is treated as "no entries yet" (returns nil) — callers that care about the difference should stat the file themselves.

func ScanDirNames

func ScanDirNames(dir string) ([]string, error)

ScanDirNames returns the immediate sub-directory names of dir, sorted, with hidden (`.`-prefixed) entries skipped. Returns an empty slice if dir doesn't exist (treat as "nothing yet").

func TailJSONL

func TailJSONL(path string, n int, emit func(line []byte)) error

TailJSONL returns the last n non-meta lines via emit, in file order. Naive (full scan + ring buffer) but adequate for the modest line counts we expect per session (<10k).

func TruncateJSONL

func TruncateJSONL(path, format, sessionID string) error

TruncateJSONL clears the body of path while keeping a fresh `_meta` header. Used by session reset.

func ValidatePresetName

func ValidatePresetName(name string) error

ValidatePresetName mirrors workspace-name rules.

func ValidateSessionID

func ValidateSessionID(id string) error

ValidateSessionID accepts the dotted Slack thread_ts form in addition to the workspace-name charset. Leading dots and `..` are still rejected.

func ValidateWorkspaceName

func ValidateWorkspaceName(name string) error

ValidateWorkspaceName rejects names containing path separators, dots, or characters outside [A-Za-z0-9_-]. See agents-design.md §15.7.

func WriteJSON

func WriteJSON(path string, v any) error

WriteJSON writes v as indented JSON to path atomically: write to a tmp file in the same directory, fsync, then rename over path.

On POSIX `os.Rename` is atomic; on Windows it is also atomic when the target exists (and replaces it). Parent directories are created on demand.

Types

This section is empty.

Jump to

Keyboard shortcuts

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