web

package
v0.0.40 Latest Latest
Warning

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

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

Documentation

Overview

Package web hosts the HTMX-driven browser UI. Templates and assets are embedded at build time via //go:embed — no toolchain on either the contributor or the end-user side. PLAN-5 / C8.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssetsFS

func AssetsFS() (fs.FS, error)

AssetsFS returns the embedded assets/ subtree, suitable for serving via http.FileServer.

func FmtCost

func FmtCost(usd float64) string

FmtCost formats USD with four decimals. Numbers under $0.01 stay readable; rounded to 4dp is enough for sub-step granularity. The dashboard route (C7) aggregates to step / run / day with two decimals.

func FmtDuration

func FmtDuration(d time.Duration) string

FmtDuration is a small helper for stage-card Duration fields. Kept here so templates can call it via FuncMap if a future fragment needs it.

func MountAssets

func MountAssets(mux *http.ServeMux) error

MountAssets registers GET /assets/... on mux to serve the embedded assets/ subtree. PLAN-5 / C8.

Cache-Control: no-store on every response so browsers always re-fetch when the ape binary's embedded assets change. Without this, the OS-level Chrome / Firefox disk cache cheerfully keeps the prior run's styles.css / page.tmpl / app.js, even across hard-refresh in some cases. Embed-time assets cycle on every rebuild; conditional GET / ETag doesn't add real value here.

func MustTemplates

func MustTemplates() *template.Template

MustTemplates parses page.tmpl + fragments.tmpl. Panics on parse error — both files are embedded at compile time so a parse failure is a build bug, not a runtime concern.

func RenderAwaitPending

func RenderAwaitPending(t *template.Template) string

RenderAwaitPending / RenderAwaitResolved produce the decision-gate OOB swaps for the await-pending / await-resolved SSE events.

func RenderAwaitResolved

func RenderAwaitResolved(t *template.Template) string

func RenderConnected

func RenderConnected(t *template.Template) string

RenderConnected returns the OOB swap that flips the #status banner from 'connecting…' to 'connected'. Emitted by the hub on every new SSE subscriber so the page state is deterministic regardless of which htmx event names the browser fires. PLAN-5 / C8.

func RenderHookFragment

func RenderHookFragment(t *template.Template, hf HookFragment) string

RenderHookFragment turns a HookFragment into one row for the #hooks scrolling feed. PLAN-5 / C8.

func RenderHookLine

func RenderHookLine(t *template.Template, h HookLine) string

func RenderPage

func RenderPage(t *template.Template, d PageData) string

RenderPage returns the full HTML body for GET /.

func RenderPipelineInit

func RenderPipelineInit(t *template.Template) string

RenderPipelineInit emits the reset-and-scaffold fragment for fresh connections. PLAN-5 / C8 — `pipeline-init` event.

func RenderReplyLine

func RenderReplyLine(t *template.Template, r ReplyLine) string

func RenderStageCard

func RenderStageCard(t *template.Template, st *views.Stage) string

RenderStageCard returns the HTML fragment for a stage-card SSE event.

func RenderStatusBanner

func RenderStatusBanner(t *template.Template, s StatusBanner) string

Types

type HookFragment

type HookFragment struct {
	At        time.Time
	Event     string
	SessionID string
	AgentID   string
	Step      string
	// Payload is the raw hook envelope as forwarded by `ape notify`.
	// Shape varies by event; the renderer extracts tool name + a
	// short summary appropriate to the event kind.
	Payload []byte
	// ProjectRoot, when non-empty, is stripped from any
	// file-path-shaped summary so the feed shows relative paths
	// instead of absolute ones.
	ProjectRoot string
}

HookFragment is the orchestrator-facing input to the activity-feed renderer. It mirrors orchestrator.HookEvent but the web package declares it locally so internal/web stays import-free of orchestrator (the webRenderer adapter in apecmd bridges the two).

type HookLine

type HookLine struct {
	TS      string
	Event   string
	Tool    string
	Summary string
	// CSSClass selects an accent colour by event kind (tool / agent /
	// prompt / endturn). Optional.
	CSSClass string
}

HookLine is the typed input to the hook-line fragment.

type PageData

type PageData struct {
	Title    string
	Subtitle string
	// Mode is "pipeline" or "chat". Controls whether the
	// decision-gate / reply form renders (chat only).
	Mode string
	// Stages, when non-empty, seeds the #stages scaffold with
	// pending placeholders so the user sees every stage from the
	// first page load. Pipeline mode populates this from spec.Stages().
	Stages []StageSeed
}

PageData is the input for the page template.

type ReplyLine

type ReplyLine struct {
	StageTag string
	Content  string
}

ReplyLine is the typed input to the reply-line fragment.

type StageSeed

type StageSeed struct {
	Slug string
	Name string
}

StageSeed is one stage placeholder for the initial page scaffold. Slug must match the slug used by SSE stage-card fragments so later updates target the same id.

type StatusBanner

type StatusBanner struct {
	Class string // "connected" / "disconnected" / "" (default styling)
	Text  string
}

StatusBanner is the model for the status-banner template fragment rendered on the stopped / error / connected SSE events.

Directories

Path Synopsis
Package views holds the per-connection rolling state and stage view helpers used by the SSE renderer.
Package views holds the per-connection rolling state and stage view helpers used by the SSE renderer.

Jump to

Keyboard shortcuts

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