cli

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package cli is lore's driving adapter: it translates cobra commands into use case calls and renders results. stdout carries data (human text, or JSON with --json); logs and errors go to stderr. It holds no business logic and imports no storage/provider adapters — the composition root wires those into Deps.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExitCode

func ExitCode(err error) int

ExitCode maps a command error to a lore exit code: 0 ok, 1 runtime, 2 usage, 3 not found, 4 invariant violation.

func ImportQueryabilityNote added in v1.0.0

func ImportQueryabilityNote(local domain.EmbeddingSpace, model string, dims int) (string, bool)

ImportQueryabilityNote returns a stderr note, and true, when the local configured embedder (local) cannot query a just-imported collection because it serves a different embedding space than the one the collection is pinned to (model/dims). It returns ok=false when the spaces match, or when the local space is unknown (zero) — in which case there is nothing useful to say.

func NewRootCommand

func NewRootCommand(build Builder, version, defaultConfigPath string, out, errOut io.Writer) *cobra.Command

NewRootCommand builds the lore command tree, writing data to out and errors to errOut. The build function is invoked once before any subcommand runs to produce the dependencies the commands share. Errors returned from Execute map to process exit codes via ExitCode.

Types

type Builder

type Builder func(context.Context, GlobalOptions) (Deps, error)

Builder constructs the runtime dependencies from the resolved global options. The composition root provides it; the root command invokes it once, in PersistentPreRunE — after global flags are parsed — so --config can redirect configuration loading before anything is wired.

type Deps

type Deps struct {
	Catalog *app.Catalog
	Ingest  *app.Ingestor
	Sync    *app.Syncer
	Query   *app.Querier
	Ask     *app.Asker
	// Retriever composes retrieval (hybrid/rerank/mmr/recency/cap) for query/ask;
	// the one source of truth shared with the eval harness and the MCP server.
	Retriever *app.Retriever
	// Rerank is nil when no rerank provider is configured; commands that need it
	// (rerank, query/ask --rerank) report a usage error in that case.
	Rerank *app.Reranker
	Remove *app.Remover
	// Replay re-runs an ask manifest to verify the answer reproduces (lore replay).
	Replay *app.Replayer
	// Tokens counts tokens for --budget token-bounded retrieval (query/ask).
	Tokens app.TokenCounter
	// Export and Import move a collection to/from a single portable artifact file.
	Export *app.Exporter
	Import *app.Importer
	// Verify checks an answer's faithfulness (ask --verify); Eval runs an eval set
	// (lore eval). Both may be nil if the runtime was built without them.
	Verify *app.Checker
	Eval   *app.Evaluator
	// Index is the vector index, exposed read-only for the mcp server's
	// collection_status chunk count. Other commands reach vectors via use cases.
	Index app.VectorIndex
	// Log is lore's configured logger (stderr), handed to the long-running mcp
	// server so it honors --log-level/--log-format; nil is tolerated.
	Log *slog.Logger
	// RetrievalHybrid is the configured default for hybrid retrieval; it sets the
	// default value of query/ask --hybrid (overridable per command).
	RetrievalHybrid bool
	// ChatModel is the configured chat model name, recorded in an ask manifest's
	// generation identity. Empty is tolerated (manifest records what it knows).
	ChatModel string
	// EmbedSpace is the configured embedder's space (model + dimensions). Import
	// compares it against an artifact's pinned space to warn when the local
	// embedder cannot query the imported collection. Zero means "unknown".
	EmbedSpace domain.EmbeddingSpace
}

Deps are the use cases the commands invoke, wired by the composition root.

type GlobalOptions

type GlobalOptions struct {
	ConfigPath string // --config; empty means the default location
	LogLevel   string // --log-level; empty means unset
	LogFormat  string // --log-format; empty means unset
	Verbose    bool   // -v/--verbose
	NoCache    bool   // --no-cache; bypass the answer cache for this run
}

GlobalOptions are the resolved global flags the composition root needs to build the runtime: which config file to read and how to log. The Builder turns these into Deps.

Jump to

Keyboard shortcuts

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