exp

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package exp implements the export of completed chapters.

Symmetric with imp/: pure local IO, no LLM dependency, no change to store state. An export may run concurrently with the Engine (read-only access to Progress plus the chapter finals), so it is a cross-cutting capability.

TXT and EPUB are supported today.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Deps

type Deps struct {
	Store *store.Store
}

Deps are the dependencies Run needs. Only store; exporting needs no LLM, prompt or bundle.

type Format

type Format string

Format identifies the export format.

const (
	// FormatTXT is plain text output.
	FormatTXT Format = "txt"
	// FormatEPUB is a standard EPUB 3 container (zip + xhtml).
	FormatEPUB Format = "epub"
)

type Options

type Options struct {
	// An empty Format is inferred from the OutPath suffix (.txt -> TXT, .epub -> EPUB);
	// when OutPath is empty too, it falls back to FormatTXT. SDK callers can set it explicitly to skip inference.
	Format Format

	// OutPath is the output file path; empty means {novelDir}/{BookMetadata.Title}.{ext}.
	OutPath string

	// From / To is the chapter range, inclusive at both ends. 0 means "from chapter 1" / "to the last chapter".
	// Unfinished chapters inside the range are skipped and written to Result.Skipped, which is not an error.
	From, To int

	// Overwrite says whether an existing file is replaced; the default refuses.
	Overwrite bool
}

Options controls export behaviour. The zero value means "export the whole book to the default path, erroring when the file exists".

Layout: 《book title》 -> volume separator -> chapter body (the title is wrapped in CJK book-title marks). Two kinds of creative blueprint, holding backstage metadata such as target readers / core appeal / writing taboos, meant for the author and the engine rather than as a reader's preface); and arc separators (from a reader's point of view an arc is an over-fine internal structure). The book title and the volume separators are always kept.

type Result

type Result struct {
	// Path is the file path actually written (absolute, or the relative path the caller passed).
	Path string
	// Chapters is the number of chapters actually written.
	Chapters int
	// Bytes is the file size in bytes (UTF-8).
	Bytes int
	// Skipped lists the chapter numbers that were in the requested range but unfinished.
	Skipped []int
}

Result is the summary of one successful export.

func Run

func Run(ctx context.Context, deps Deps, opts Options) (*Result, error)

Run performs one export. It returns synchronously, with a small amount of IO (local file reads and writes).

Failure semantics:

  • invalid deps/opts -> a config error returned immediately
  • no completed chapter at all -> an error is returned (so the caller is left in no doubt)
  • a chapters/{ch}.md missing inside the range -> an error is returned (progress disagreeing with the filesystem is a fact-layer bug and the user should see it)
  • the output path already exists and Overwrite was not given -> an error is returned

Skipped covers chapters that are in range but not finished yet (the user passed to=100 but only wrote up to 80).

Jump to

Keyboard shortcuts

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