compile

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: BSD-3-Clause Imports: 28 Imported by: 0 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 compile orchestrates ephemeral compile jobs. V0.3 wires real subprocesses for LaTeX (pdflatex) and Marp markdown (marp-cli) — both run on the host running loom-server, mounted on the project's working tree. V0.4 will dispatch to a weft-microvm with the weft-loom-texlive / weft-loom-marp OCI image instead, but the subprocess path stays as the dev-mode fallback when no agent is configured.

Each job creates a scratch dir under the project's working tree (<workingDir>/.weft-loom/<jobID>/) that holds the artifact + any auxiliary files (LaTeX .aux/.log etc.). The HTTP handler at /api/projects/{p}/compile/{id}/artifact serves the PDF out of that dir.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpandTemplate added in v0.4.0

func ExpandTemplate(src string, now time.Time) string

ExpandTemplate is the exported entry point. now is injected so tests can pin a deterministic timestamp.

Types

type Event

type Event struct {
	Kind         string `json:"kind"`
	Line         string `json:"line,omitempty"`
	Success      bool   `json:"success,omitempty"`
	Artifact     string `json:"artifact,omitempty"`
	ArtifactMIME string `json:"artifact_mime,omitempty"`
	DurationMs   int64  `json:"duration_ms,omitempty"`
	Message      string `json:"message,omitempty"`
}

Event is one streamed line during a compile job.

type JobSpec

type JobSpec struct {
	Project   string   `json:"-"`
	Language  string   `json:"language"`
	Entry     string   `json:"entry,omitempty"`
	ExtraArgs []string `json:"extra_args,omitempty"`
	// CommandOverride : verbatim shell command that REPLACES the
	// language's default when non-empty. Threaded from the
	// SettingsPanel UI : the user types `make build && ./out` once
	// + persists it as a per-language override, and every Run
	// dispatches that command instead of the built-in one.
	// Empty string preserves the existing behaviour.
	CommandOverride string `json:"command,omitempty"`
	// Engine : LaTeX engine binary the compiler invokes for the
	// `latex` language. One of `pdflatex` / `lualatex` / `xelatex` /
	// `gotex` (pure-Go, weft-loom-gotex image). Empty defaults to
	// `pdflatex`. Unknown values are normalised back to `pdflatex`
	// with a log line. Ignored for non-LaTeX languages.
	Engine string `json:"engine,omitempty"`
	// BibEngine : bibliography processor — `bibtex` or `biber`.
	// Empty defaults to `bibtex`. Only invoked when the LaTeX
	// scratch dir produced the matching trigger file (.aux with
	// \bibdata for bibtex, .bcf for biber).
	BibEngine string `json:"bib,omitempty"`
	// Identity is populated by Start() from the auth.Identity ; the
	// workspace dispatch path uses it to resolve the per-user VM.
	Identity string `json:"-"`
}

JobSpec is the request shape POSTed to /api/projects/<n>/compile.

type Service

type Service struct {

	// Workspaces : when non-nil + the user has a NATS-backed VM,
	// every compile job dispatches via Containers + ExecSession
	// instead of the host subprocess path. Same NATS subjects the
	// shell uses → unified observability + no special treatment
	// for texlive vs go vs pandoc.
	Workspaces WorkspaceResolver
	// contains filtered or unexported fields
}

Service starts jobs + serves their event streams + holds the artifact paths so the HTTP layer can stream them back.

func New

func New(store project.Store) *Service

func (*Service) Artifact added in v0.4.0

func (s *Service) Artifact(id string) (string, bool)

Artifact returns the absolute path of the artifact produced by job id, or empty + false if there isn't one.

func (*Service) Cancel added in v0.4.0

func (s *Service) Cancel(id string) bool

Cancel kills an in-flight compile job. Returns true when the jobID matched a still-running job ; false when the id is unknown or the job already finished. The artifact retention path keeps the registry entry alive for 30 min past completion so the SSE consumer can still download the PDF — we distinguish "still running" from "kept around for artifact retrieval" by peeking at the done channel (closed by the run goroutine's defer). The UI's red "Cancel" button hits the /compile/<id>/cancel endpoint which forwards here ; the per-language dispatchers receive ctx.Done() and surface a "cancelled" log line + bail.

func (*Service) Start

func (s *Service) Start(_ context.Context, ident auth.Identity, spec JobSpec) (string, error)

func (*Service) Stream

func (s *Service) Stream(_ context.Context, id string) (<-chan Event, error)

func (*Service) SyncTeXPath added in v0.4.0

func (s *Service) SyncTeXPath(id string) (string, bool)

SyncTeXPath returns the absolute path of the .synctex.gz file pdflatex produces alongside the PDF. Lives in the same scratch dir as the artifact ; same base name with .synctex.gz appended. Returns "" + false when the artifact is gone or no synctex file was produced (compile used a non-LaTeX path, or pdflatex aborted before writing the synctex stream).

type WorkspaceIdentity added in v0.4.0

type WorkspaceIdentity struct {
	Subject string
}

WorkspaceIdentity / WorkspaceVM mirror the workspace package's types in a trimmed-down form. Adapter lives in cmd/weft-loom.

type WorkspaceNATS added in v0.4.0

type WorkspaceNATS interface {
	Publish(subject string, data []byte) error
	Subscribe(subject string, cb func(subj string, data []byte)) (WorkspaceUnsub, error)
}

WorkspaceNATS is the publish/subscribe surface compile needs.

type WorkspaceResolver added in v0.4.0

type WorkspaceResolver interface {
	Ensure(ctx context.Context, ident WorkspaceIdentity) (*WorkspaceVM, error)
}

WorkspaceResolver is the trimmed-down view of workspace.Registry the compile service needs : "give me the user's VM". Kept narrow so unit tests stub it with a one-VM map and the compile package stays decoupled from internal/workspace's full surface.

type WorkspaceUnsub added in v0.4.0

type WorkspaceUnsub interface {
	Unsubscribe() error
}

type WorkspaceVM added in v0.4.0

type WorkspaceVM struct {
	VMID    string
	WorkDir string
	Conn    WorkspaceNATS
	Health  func() string
}

Jump to

Keyboard shortcuts

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