Library API

Inspect every generation

buildGallerySnapshot is the offline, serializable view behind pixelkiln gallery: every lock entry with its plan state, outputs, quality record, lineage, and manifest intent, plus lock entries the manifest no longer declares. It is built from the same sources as buildPlan and contacts no provider.

import { buildGallerySnapshot, openProject, renderGallery, serveGallery } from "pixelkiln"

const project = await openProject("pixelkiln.manifest.json")
const { snapshot, media } = await buildGallerySnapshot(project)

for (const item of snapshot.items) {
  console.log(item.key, item.state, item.cost, item.costUnit, item.outputs.map((o) => o.sha256))
}

buildWorkspaceGallerySnapshot({ workspace, workspacePath }) does the same for every project a workspace catalog registers, namespacing item ids as project:style/asset and listing an unreadable project's error under snapshot.workspace.projects instead of throwing.

renderGallery(snapshot) returns the self-contained HTML page, and serveGallery({ load }) runs the localhost server; load is called again for every page load and /api/gallery.json request, and media is the exact allowlist of files the server will read. Output URLs inside the snapshot are only meaningful while that server runs.

Passing edit: createGalleryEditHandler({ manifestFor, reload, loadProject }) adds the one write route behind pixelkiln gallery --edit, which also carries the page's hand-edit actions (start-edit, detach-edit, save-edit); editor: createGalleryEditorHandlers() adds the in-browser editor beside it. applyManifestEdit(path, edit) is the underlying primitive: it patches the raw manifest JSON, preserves the file's indentation, refuses to write when the file's hash no longer matches expectedSha256 (ManifestDriftError), and validates the result through loadManifest and resolveSpecs before the rename (ManifestEditError). It never touches the lockfile or a provider.

createGenerateHandlers({ loadProject, providerFor, budget, reload }) is the generation side of pixelkiln gallery --budget: start validates a request against buildPlan and the session budget and runs submit, poll, and fetchAssets as a background job; status reports jobs and spend; review and applyReview host the pick sheet for a job's waiting keys. The sheet itself comes from prepareReview, which runPicker also uses: it gathers the candidate groups, the local files the sheet may load, and the apply step, without an HTTP server of its own.