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 ¶
- func AppendJSONL(path string, format, sessionID string, v any) error
- func CountJSONLEntries(path string) (int, error)
- func PathExists(path string) bool
- func ReadJSON(path string, v any) error
- func ReadJSONL(path string, emit func(line []byte) bool) error
- func ScanDirNames(dir string) ([]string, error)
- func TailJSONL(path string, n int, emit func(line []byte)) error
- func TruncateJSONL(path, format, sessionID string) error
- func ValidatePresetName(name string) error
- func ValidateSessionID(id string) error
- func ValidateWorkspaceName(name string) error
- func WriteJSON(path string, v any) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendJSONL ¶
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 ¶
CountJSONLEntries returns how many non-meta lines exist in path.
func PathExists ¶
PathExists reports whether path exists (file or dir).
func ReadJSON ¶
ReadJSON loads a JSON file into v. Forwards os.ErrNotExist verbatim so callers can distinguish "missing" from "corrupt".
func ReadJSONL ¶
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 ¶
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 ¶
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 ¶
TruncateJSONL clears the body of path while keeping a fresh `_meta` header. Used by session reset.
func ValidatePresetName ¶
ValidatePresetName mirrors workspace-name rules.
func ValidateSessionID ¶
ValidateSessionID accepts the dotted Slack thread_ts form in addition to the workspace-name charset. Leading dots and `..` are still rejected.
func ValidateWorkspaceName ¶
ValidateWorkspaceName rejects names containing path separators, dots, or characters outside [A-Za-z0-9_-]. See agents-design.md §15.7.
Types ¶
This section is empty.