ingest

package
v0.0.0-...-4db46fd Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: Apache-2.0 Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package ingest moves items captured outside Dibs (voice recordings, dictations) into Dibs as private draft ideas. A Source lists items since a time; the Ingester dedupes them against a Cursor file, applies a local submission budget, and submits each new one through a Sink (DibsSink, the Dibs MCP submit_idea tool).

Index

Constants

View Source
const (
	// DefaultServer is the public Dibs origin.
	DefaultServer = "https://dibs.hivecommons.dev"
	// EnvToken holds the hub bearer token (preferred over --token, which is
	// visible in the process list).
	EnvToken = "DIBS_TOKEN"
	// EnvServer overrides the default --server.
	EnvServer = "DIBS_URL"
)
View Source
const (
	// DefaultSinceDays bounds how far back the first run looks.
	DefaultSinceDays = 7
	// DefaultMaxPerHour and DefaultMaxPerDay match the intake budget per
	// identity (10/h, 30/24h).
	DefaultMaxPerHour = 10
	DefaultMaxPerDay  = 30
)

Variables

View Source
var ErrRateLimited = errors.New("dibs: rate limited (HTTP 429)")

ErrRateLimited reports that Dibs (or a proxy in front of it) answered 429; the batch stops and resumes on the next run.

Functions

func SplitList

func SplitList(s string) []string

SplitList splits a comma-separated flag value, dropping blanks.

Types

type Cursor

type Cursor struct {
	Newest    time.Time            `json:"newest,omitzero"`
	Seen      map[string]time.Time `json:"seen"`
	Submitted []time.Time          `json:"submitted,omitempty"`
}

Cursor is the persisted ingest state: which items were already submitted (dedupe on the source's id), the newest item time (the next listing starts there, minus Ingester.Overlap), and recent submission times (rate budget).

func LoadCursor

func LoadCursor(path string) (*Cursor, error)

LoadCursor reads path; a missing file is an empty cursor.

func (*Cursor) Save

func (c *Cursor) Save(path string) error

Save writes the cursor atomically (mode 0600), creating its directory.

type DibsSink

type DibsSink struct {
	// Endpoint is the Dibs MCP URL, e.g. https://dibs.hivecommons.dev/mcp.
	Endpoint string
	// Token is the hub bearer token. It is only ever sent in the
	// Authorization header, never logged.
	Token string
	// Transport defaults to http.DefaultTransport.
	Transport http.RoundTripper
}

DibsSink submits ideas with the Dibs MCP submit_idea tool (private draft owned by the token's identity).

func (*DibsSink) Submit

func (s *DibsSink) Submit(ctx context.Context, idea Idea) error

Submit implements Sink.

type Flags

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

Flags are the flags every `dibs ingest <source>` command shares.

func AddFlags

func AddFlags(fs *flag.FlagSet, source, unit, defaultTags string, getenv func(string) string) *Flags

AddFlags registers the shared flags on fs for `dibs ingest <source>`. unit names what the source lists (e.g. "recordings") in help text.

func (*Flags) Configure

func (f *Flags) Configure(in *Ingester, getenv func(string) string, stderr io.Writer) int

Configure validates the parsed shared flags and fills in the matching fields of in (Name, Sink, CursorPath, Tags, SinceDays, budgets, DryRun, Log). On a problem it explains it on stderr and returns the exit code (2 usage, 1 environment); 0 means in is ready.

func (*Flags) Interval

func (f *Flags) Interval() time.Duration

Interval is the parsed --interval.

type Idea

type Idea struct {
	Title       string
	Description string
	Tags        []string
}

Idea is what gets submitted to Dibs for one item.

type Ingester

type Ingester struct {
	// Name labels log lines, e.g. "plaud".
	Name string
	// Open returns the Source for one run; when nil, Source is used.
	Open   func(ctx context.Context) (Source, error)
	Source Source
	Sink   Sink
	// CursorPath is the JSON state file (see Cursor).
	CursorPath string
	// Tags replace the tags of every idea.
	Tags      []string
	SinceDays int
	// Overlap re-lists this far behind the cursor, for items that were not
	// ready (or not final) when they were first listed.
	Overlap    time.Duration
	MaxPerHour int
	MaxPerDay  int
	// MaxPerRun caps items handled in one run (0 = no cap).
	MaxPerRun int
	// DryRun builds and logs each idea without submitting it or advancing
	// the cursor.
	DryRun bool
	Log    *slog.Logger
	Now    func() time.Time
}

Ingester moves new items from a Source into Dibs.

func (*Ingester) Run

func (in *Ingester) Run(ctx context.Context, interval time.Duration) error

Run calls RunOnce, then every interval until ctx is done. With interval <= 0 it runs once and returns that run's error. In loop mode a failed run is logged and retried on the next tick.

func (*Ingester) RunOnce

func (in *Ingester) RunOnce(ctx context.Context) (Result, error)

RunOnce lists items since the cursor and submits each unseen one, oldest first. The cursor is saved after every submission, so a crash never resubmits. A 429 or an exhausted local budget stops the batch without error; the rest is picked up next run.

type Item

type Item interface {
	// ID is the source's stable id, used to dedupe across runs.
	ID() string
	// When is the item's capture time (zero if unknown).
	When() time.Time
	// Idea renders the idea; an error skips the item for this run only.
	Idea(ctx context.Context) (Idea, error)
}

Item is one candidate idea listed by a Source.

type Result

type Result struct {
	Submitted int
	Skipped   int
	// Planned counts ideas that a dry run would have submitted.
	Planned int
	// BudgetExhausted is set when the local --max-per-hour/--max-per-day
	// budget or the --max per-run cap stopped the batch.
	BudgetExhausted bool
	// RateLimited is set when Dibs answered HTTP 429.
	RateLimited bool
}

Result summarizes one run.

type Sink

type Sink interface {
	Submit(ctx context.Context, idea Idea) error
}

Sink submits one idea to Dibs.

type Source

type Source interface {
	List(ctx context.Context, since time.Time) ([]Item, error)
}

Source lists items captured at or after since. A Source that also implements io.Closer is closed at the end of each run.

type Watermarker

type Watermarker interface {
	Watermark() time.Time
}

Watermarker is an optional Source extension for sources that read and drop items that are not ideas (most Wispr Flow dictations). Watermark reports the newest capture time the last List call read, so the cursor moves past dropped items instead of re-reading them every run.

Jump to

Keyboard shortcuts

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