notesclient

package
v1.0.0-alpha.42 Latest Latest
Warning

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

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

Documentation

Overview

Package notesclient is the runtime-side client to the daemon's agent_notes table. Mirrors the legacy pkg/notes.Store API so the tool layer and PrepareStep renderer can swap stores for clients without changing call sites.

Configuration mirrors pkg/jobsclient: OTTERSD_URL + OTTERS_AGENT_TOKEN from the spawn env. The daemon scopes every call to the JWT's agent_ref, so the client never needs to know its own UUID — empty ref on the wire makes the daemon read it from the bearer token.

Index

Constants

View Source
const (
	EnvDaemonURL = "OTTERSD_URL"
	//nolint:gosec // G101: env var name, not a credential value
	EnvAgentToken = "OTTERS_AGENT_TOKEN"
)

Variables

View Source
var (
	ErrInvalidKey    = errors.New("invalid note key")
	ErrNoteTooLarge  = errors.New("note content exceeds size cap")
	ErrTooManyNotes  = errors.New("note count would exceed cap")
	ErrNoteNotFound  = errors.New("note not found")
	ErrNotConfigured = errors.New(
		"notesclient: OTTERSD_URL and OTTERS_AGENT_TOKEN must both be set",
	)
)

Sentinel errors. Returned with %w-wrapping so callers can errors.Is to render meaningful messages.

Functions

This section is empty.

Types

type Client

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

func New

func New(cfg Config) *Client

func (*Client) Close

func (c *Client) Close() error

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key string) error

Delete removes a note by key. Idempotent — no error when the key was never present.

func (*Client) Get

func (c *Client) Get(ctx context.Context, key string) (Note, error)

Get returns one note by key.

func (*Client) List

func (c *Client) List(ctx context.Context) ([]Note, error)

List mirrors notes.Store.List — every note ordered by most-recently-updated first. Body is omitted to keep payloads small; callers fetch the body via Get.

func (*Client) ListInContext

func (c *Client) ListInContext(ctx context.Context) ([]Note, error)

ListInContext mirrors notes.Store.ListInContext.

func (*Client) Save

func (c *Client) Save(ctx context.Context, key, content string, maxBytes, maxCount int) error

Save upserts a note. maxBytes / maxCount enforce quotas; pass the agent.yaml-configured values. The daemon returns FailedPrecondition for quota violations, mapped here to ErrNoteTooLarge / ErrTooManyNotes.

func (*Client) SetInContext

func (c *Client) SetInContext(ctx context.Context, key string, inContext bool) error

SetInContext flips a note's in_context flag.

type Config

type Config struct {
	URL   string
	Token string
}

func FromEnv

func FromEnv() (Config, bool)

type Fake

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

Fake is an in-memory implementation of the Store / NotesProvider surfaces used by the runtime's tool layer and PrepareStep callback. Test-only; production code uses *Client over gRPC.

func NewFake

func NewFake() *Fake

func (*Fake) Delete

func (f *Fake) Delete(_ context.Context, key string) error

func (*Fake) Get

func (f *Fake) Get(_ context.Context, key string) (notes.Note, error)

func (*Fake) List

func (f *Fake) List(_ context.Context) ([]notes.Note, error)

func (*Fake) ListInContext

func (f *Fake) ListInContext(_ context.Context) ([]notes.Note, error)

func (*Fake) Save

func (f *Fake) Save(_ context.Context, key, content string, maxBytes, maxCount int) error

func (*Fake) SetInContext

func (f *Fake) SetInContext(_ context.Context, key string, inContext bool) error

type Note

type Note = notes.Note

Note re-exports notes.Note so callers can write notesclient.Note without importing both packages. Same in-memory shape; same renderers; only the storage moved.

type Store

type Store interface {
	List(ctx context.Context) ([]notes.Note, error)
	ListInContext(ctx context.Context) ([]notes.Note, error)
	Get(ctx context.Context, key string) (notes.Note, error)
	Save(ctx context.Context, key, content string, maxBytes, maxCount int) error
	Delete(ctx context.Context, key string) error
	SetInContext(ctx context.Context, key string, inContext bool) error
}

Store is the interface BuildNotesTools / BuildNotesPrepareStep need from a notes backend. *Client satisfies it in production; *Fake satisfies it in tests.

Jump to

Keyboard shortcuts

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