ingest

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 31 Imported by: 0

Documentation

Overview

Package ingest orchestrates multi-source content ingestion into knowledge base topics, handling frontmatter assembly, raw file writes, and operation log entries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExistingYouTubeVideoIDs added in v0.0.10

func ExistingYouTubeVideoIDs(vaultPath, topicRef string) (map[string]struct{}, error)

ExistingYouTubeVideoIDs returns the set of YouTube video IDs already ingested under the topic's raw/youtube directory. It powers resumable channel ingestion by reading each raw document's video_id frontmatter field and the id embedded in its source_url. A missing raw/youtube directory yields an empty set.

func Ingest

func Ingest(ctx context.Context, options Options) (models.IngestResult, error)

Ingest validates the target topic, optionally converts the source, writes the raw markdown document, and appends a log entry. With options.Session it runs the source through a one-item Run instead (gates, classify, link).

func ModeLines added in v0.0.11

func ModeLines(s *session.Session, force bool) []string

ModeLines states the mode of every gate for the run summary.

func NewBatchID added in v0.0.11

func NewBatchID(command string, now time.Time) string

NewBatchID returns the default ingest batch name `<command>-<YYYY-MM-DD>-<6 hex run id>` (spec §4.4). The date is taken in UTC, matching the `scraped` stamp.

func WouldBePath added in v0.0.11

func WouldBePath(kind models.SourceKind, title string) string

WouldBePath returns the topic-relative path a source of kind titled title would get before uniqueness suffixes (for collected_on_purpose_paths matching before fetch).

Types

type GateOptions added in v0.0.11

type GateOptions struct {
	// Force skips gates 1–6 (the source is written as kept); classify and
	// link still run.
	Force bool
	// Refetch performs the one fresh stage-4 scrape of a URL source (nil for
	// other sources).
	Refetch func(ctx context.Context) (*firecrawl.ScrapeResult, error)
	// RequestedURL is the URL the fetch was asked for; FinalURL and
	// StatusCode are what the fetcher reported.
	RequestedURL string
	FinalURL     string
	StatusCode   int
	// SiteName is the site name the fetcher reported (Firecrawl
	// ogSiteName), for the "title equals the site name" quality rule.
	SiteName string
	// PlatformID is the `youtube:<id>` / `instagram:<shortcode>` identity.
	PlatformID string
	// Prefetch is the stage-2 verdict of a bulk item (nil for single
	// sources and rescued items).
	Prefetch *gate.PrefetchDecision
}

GateOptions are the per-source gate inputs of a decision-backed ingest.

type Options

type Options struct {
	VaultPath        string
	Topic            string
	SourceKind       models.SourceKind
	SourcePath       string
	SourceURL        string
	Title            string
	Markdown         string
	ExtraFrontmatter map[string]any
	ConvertOptions   map[string]any
	Registry         Registry
	ScrapedAt        time.Time
	// Batch names the ingest run (spec §4.4) and is written as ingest_batch.
	// Bulk runs pass the same value for every item. Empty omits the key.
	Batch string
	// Query is what produced the item (search query, channel URL, bookmark
	// label or file name) and is written as ingest_query. Empty omits the key.
	Query string
	// Session, when set, runs the decision-backed path for this one source:
	// gates (spec §7), owned-key writes, quarantine, then classify and link,
	// with one log.md run entry. Without it Ingest writes the source as
	// before (codebase ingest never uses a session).
	Session *session.Session
	// Gate carries the per-source gate inputs of the decision-backed path.
	Gate GateOptions
}

Options configures a single-source ingest run.

type Registry

type Registry interface {
	Convert(ctx context.Context, input models.ConvertInput) (*models.ConvertResult, error)
}

Registry converts file-backed inputs into markdown content.

type Result added in v0.0.11

type Result struct {
	models.IngestResult
	Triage       string   `json:"triage,omitempty"`
	TriageReason string   `json:"triage_reason,omitempty"`
	Quality      string   `json:"quality,omitempty"`
	DuplicateOf  string   `json:"duplicate_of,omitempty"`
	Shadow       []string `json:"shadow,omitempty"`
	Supersedes   []string `json:"supersedes,omitempty"`
	Refetched    bool     `json:"refetched,omitempty"`
	ReviewItem   string   `json:"review_item,omitempty"`
	Undecided    []string `json:"undecided,omitempty"`
	// Excluded reports that the source matches decisions.exclude: it was
	// written without any decision call and is left out of classify and
	// link; Note says so.
	Excluded bool   `json:"excluded,omitempty"`
	Note     string `json:"note,omitempty"`
}

Result is the outcome of one gated source: the classic ingest result plus what the gates decided. FilePath is empty for skipped sources and points into raw/_quarantine/ for quarantined ones.

type Run added in v0.0.11

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

Run is one decision-backed ingest run over a topic (spec §7): every source goes through the gates, is written with its triage and provenance through the owned-key writer, quarantined through internal/refs when a gate says so, and classified and linked at Finish. Sources of one run are processed one at a time.

func NewRun added in v0.0.11

func NewRun(s *session.Session, opts RunOptions) *Run

NewRun starts a run on a session.

func (*Run) Finish added in v0.0.11

func (r *Run) Finish(ctx context.Context) (Summary, error)

Finish classifies and links the sources written by the run (spec §7 stage 7), then appends one log.md entry for the run with the kept/review/quarantined/skipped counts and the cost. The error is fatal only; the summary is returned with what was done.

func (*Run) Ingest added in v0.0.11

func (r *Run) Ingest(ctx context.Context, options Options) (Result, error)

Ingest runs one fetched source through gates 1 and 3–6 (stage 2 already ran for bulk items; options.Gate.Prefetch carries its verdict), writes it with provenance and triage through the owned-key writer, quarantines it through internal/refs when the outcome says so, and queues a `gate` review item for the review band and gate quarantines. Classification and linking of the written sources happen in Finish.

func (*Run) MarkRescued added in v0.0.11

func (r *Run) MarkRescued(row gate.SkippedRow) error

MarkRescued records that a skipped item was ingested.

func (*Run) Precheck added in v0.0.11

func (r *Run) Precheck(sourceURL, title string, kind models.SourceKind) (Result, bool, error)

Precheck is stage 1 before fetching: a source whose URL or platform id already exists in the topic (quarantined sources included) is skipped and reported, so no transcript, STT or scrape is paid for it. It returns the skip result and true; false means fetch. Force and shadow never skip.

func (*Run) Prefetch added in v0.0.11

func (r *Run) Prefetch(ctx context.Context, items []gate.Item) ([]gate.PrefetchDecision, error)

Prefetch is stage 2 over bulk items (see gate.Prefetch). Skipped items are counted and logged; the caller fetches the rest.

func (*Run) Session added in v0.0.11

func (r *Run) Session() *session.Session

Session returns the run's session.

func (*Run) Skipped added in v0.0.11

func (r *Run) Skipped(id string) (gate.SkippedRow, error)

Skipped returns the skipped.jsonl row of a skipped id (for --rescue).

func (*Run) Tally added in v0.0.11

func (r *Run) Tally() gate.Tally

Tally returns the run's counts so far.

type RunOptions added in v0.0.11

type RunOptions struct {
	// Command names the ingest subcommand ("url", "channel", ...).
	Command string
	// Batch and Query are the run provenance (ingest_batch, ingest_query);
	// per-source Options.Batch/Query override them.
	Batch string
	Query string
	// Force skips gates 1–6 for every source of the run.
	Force bool
}

RunOptions configures a decision-backed ingest run.

type Summary added in v0.0.11

type Summary struct {
	Tally gate.Tally `json:"tally"`
	// Modes names the gate mode per gate.
	Modes []string `json:"modes"`
	// Classify and Link are the reports of the in-run classification and
	// linking of the written sources (nil when nothing was written).
	Classify *classify.Report `json:"classify,omitempty"`
	Link     *link.Report     `json:"link,omitempty"`
	CostUSD  float64          `json:"cost_usd"`
	// Folders are the source counts per raw/ folder after the run, set when
	// the run quarantined a source (spec §7.1: the agent updates prose
	// counts from them).
	Folders []scope.FolderCount `json:"folders,omitempty"`
}

Summary is what a finished run reports.

func (Summary) Lines added in v0.0.11

func (sum Summary) Lines() []string

Lines renders the summary for the terminal (the caller appends the session's decisions summary).

Jump to

Keyboard shortcuts

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