Documentation
¶
Overview ¶
check.go — will this site build on memcode.ai? Answered here, before a push.
The local dev server renders in the browser; the hosted build pre-renders every route in Node (vite-react-ssg). Code that touches window at import time, a missing package, or a broken route works in the preview and fails the build. BuildCheck runs the same `npm run build` the builder runs and applies the same output rules, so the user finds out now, not after a push.
Package websites is the CLI's client for memcode.ai's Websites feature — AI-built static sites. list/pull/push/publish map onto the www /api/website endpoints, authenticated with the same bearer token the login flow mints (MEMCODE_API_TOKEN). Like the artifacts client, this talks to the WEB APP, not the inference gateway.
The local workflow is deliberately git-native: `pull` clones the site's repo bundle into ./<slug> (which carries MEMCODE.md + .memcode/, so plain `memcode` in that directory IS website mode), `push` bundles the repo back up and queues a server-side rebuild of the draft preview.
deps.go — what a site may depend on, decided the same way everywhere.
A site's packages come from two places:
- The kit: the template's own dependency set (React, Tailwind, motion, GSAP, fonts, 3D…). The hosted builder has it preinstalled, so a site that uses only the kit builds offline in seconds.
- Vetted additions: any other npm package that passes Vet — old enough to have survived a compromised release being noticed, widely used, a permissive license, no install scripts, not deprecated, a sane size. Additions install with --ignore-scripts here and on memcode.ai.
The local site worker adds packages through Add, a push runs Check before uploading, and the hosted builder runs the same Check (`memcode websites deps check`) before it installs anything. One policy, one implementation: a site that works locally builds when pushed, and nothing reaches the builder that this machine would have refused.
kitsync.go — sites follow the kit.
A site starts with the kit's exact versions pinned in its package.json. When memcode moves the kit (a security fix, a patch release), a site that still has the versions the kit gave it moves with the kit; a version the site's owner chose (`deps add pkg@x` for a kit package, an edit) stays where it is. The kit's history tells the two apart: every version the kit has ever pinned, with the epoch it shipped in.
Epochs are the compatibility gate. A kit change that can break a site's code (a major release with API changes) starts a new epoch, and a site whose kit packages are from an older epoch is not moved automatically: it needs a migration. Within an epoch, following the kit is safe by construction.
The local dev server syncs before it installs, and the hosted builder syncs before every build (`memcode websites deps sync`), so both land on the same versions.
local.go — local-first sites, the way git works: create a site on this machine, work on it with a local dev server, and decide later whether to push it to memcode.ai. A site made here does not exist on memcode.ai (no address, no slot) until its first push creates it there.
Local sites live in managed workspaces (~/.memcode/websites/<name>/source). The folder keeps its name after the first push, so a dev server running from it is never moved out from under; a site is found by scanning the workspaces' .memcode/website.json markers (remote sites pulled before this existed sit under their site id, and are found the same way).
workspace.go — the on-disk layout `memcode websites dev` works from.
Two modes, mirroring the revised architecture's LOCAL layer:
managed: ~/.memcode/websites/<site_id>/{source,assets,runtime}/ — used
when `dev` is given a slug with no local checkout. Mirrors
internal/plans's ~/.memcode/plans convention (user-level, not
per-repo, so it survives outside any git working tree).
explicit: <dir>/.memcode/{assets,runtime}/ — used when `dev` is pointed
at an existing pulled checkout. The caller MUST run
config.EnsureGitignore(dir) before writing here (that's what
keeps .memcode/assets and .memcode/runtime untracked and out of
`git bundle create --all`) — this package deliberately does not
import internal/config to avoid widening its dependency surface.
Neither mode ever touches draft/ or repo.bundle — those stay exactly as the Pull/Push flow already manages them.
Index ¶
- Constants
- Variables
- func ChangedFiles(dir, since string) []string
- func DesignPlan(dir string) string
- func Head(dir string) string
- func ManagedDir(siteID string) (string, error)
- func RenderList(sites []Site) string
- func SaveDesignPlan(dir, plan string) error
- func ShareCode(s string) string
- func Zip(dir, out string) (int, error)
- type APIError
- type Asset
- type Brief
- type Build
- type BuildReport
- type Client
- func (c *Client) Build(ctx context.Context, siteID, prompt, model string) (Build, error)
- func (c *Client) CatchUp(ctx context.Context, l LocalSite) (bool, error)
- func (c *Client) Checkpoint(dir, since, message string) (string, error)
- func (c *Client) Create(ctx context.Context, name, prompt, model string) (Site, error)
- func (c *Client) Delete(ctx context.Context, siteID string) error
- func (c *Client) DeleteAsset(ctx context.Context, siteID, name string) error
- func (c *Client) Edit(ctx context.Context, siteID string, edits []Edit, model string) (Build, error)
- func (c *Client) Get(ctx context.Context, siteID string) (Site, error)
- func (c *Client) GetBySlug(ctx context.Context, slug string) (Site, error)
- func (c *Client) InitLocal(ctx context.Context, name string) (LocalSite, error)
- func (c *Client) Kit(ctx context.Context) (Kit, error)
- func (c *Client) List(ctx context.Context) ([]Site, error)
- func (c *Client) ListAssets(ctx context.Context, siteID string) ([]Asset, error)
- func (c *Client) ListBuilds(ctx context.Context, siteID string) ([]Build, error)
- func (c *Client) MergeHosted(ctx context.Context, l LocalSite) error
- func (c *Client) Preview(ctx context.Context, siteID string) (string, error)
- func (c *Client) Publish(ctx context.Context, siteID string) (string, error)
- func (c *Client) Pull(ctx context.Context, slug, destDir string) (Site, error)
- func (c *Client) Push(ctx context.Context, dir string) (Site, error)
- func (c *Client) Resolve(ctx context.Context, slug string) (Site, error)
- func (c *Client) Share(ctx context.Context, siteID string, days int) (ShareLink, error)
- func (c *Client) ShareLinks(ctx context.Context, siteID string) ([]ShareLink, error)
- func (c *Client) SyncLocalKit(ctx context.Context, dir string) (KitPlan, error)
- func (c *Client) Unpublish(ctx context.Context, siteID string) error
- func (c *Client) Unshare(ctx context.Context, siteID, codeOrURL string) error
- func (c *Client) Update(ctx context.Context, siteID string, name, model *string) (Site, error)
- func (c *Client) UploadAsset(ctx context.Context, siteID, localPath, name string) (Asset, error)
- type Edit
- type ErrDependencies
- type Kit
- type KitHistory
- type KitMove
- type KitPlan
- type LocalSite
- type Meta
- type Registry
- type Request
- type ShareLink
- type Site
- type Verdict
- type Workspace
Constants ¶
const ( // MinPackageAge: a version must have been public this long. Compromised // releases are typically caught and pulled within days. MinPackageAge = 14 * 24 * time.Hour // MinWeeklyDownloads keeps additions to packages many people already run. MinWeeklyDownloads = 10000 // MaxUnpackedBytes bounds one package's published size. MaxUnpackedBytes = 30 << 20 )
Policy limits for a package outside the kit.
const KitHistoryFile = "memcode-kit.json"
KitHistoryFile sits next to the kit's package.json in the template. It is the template's, not the site's: scaffolding removes it from a new site.
const MaxSiteBytes int64 = 50 << 20
MaxSiteBytes is the hosted builder's cap on a site's built output.
Variables ¶
var ErrBehind = errors.New("memcode.ai has changes this copy doesn't have yet")
ErrBehind means memcode.ai has changes this working copy doesn't (made by a build on memcode.ai, or pushed from another copy). A push replaces the hosted repo wholesale, so pushing now would throw those changes away.
var ErrBuildsGated = errors.New("website building is in limited internal preview — this account can't build or push sites yet")
ErrBuildsGated is returned by Build/Edit/Push when the server's internal- preview gate (canSeeTestPlans) rejects the request: hosted building — an agent build, an inline edit, or a pushed-repo rebuild — is limited to internal accounts. There is no local fallback for these accounts (a site that was never built has no repo to pull), so callers report it plainly rather than retrying or suggesting a workaround.
var WorkerGuide string
WorkerGuide is what the local site worker is told about the project, how to work (see, plan, build, look again, check) and how to avoid a generic site. The hosted builder's doctrine and the dependency policy enforce the same stack rules, so local work stays publishable.
Functions ¶
func ChangedFiles ¶ added in v0.47.0
ChangedFiles lists the files that differ between commit since and HEAD.
func DesignPlan ¶ added in v0.47.2
DesignPlan is the worker's saved design plan for the site ("" if none).
func ManagedDir ¶ added in v0.40.0
ManagedDir returns ~/.memcode/websites/<site_id>, creating no directories.
func RenderList ¶
RenderList formats sites as an aligned table — shared by the cobra command and the TUI /websites slash handler.
func SaveDesignPlan ¶ added in v0.54.0
SaveDesignPlan records the worker's design plan for the site, replacing the previous one. It lives with memcode's state for the site, not in the site.
func ShareCode ¶ added in v0.43.0
ShareCode extracts the code from a share link or returns a bare code.
func Zip ¶ added in v0.42.0
Zip writes a shareable copy of the site at dir to out: the project's own files, with everything that is generated or machine-specific left out (node_modules, the build output, git internals, memcode's .memcode folder). In a git repo the file list is git's: tracked files plus new ones that aren't ignored, so the site's .gitignore decides. Returns the number of files written.
Types ¶
type APIError ¶ added in v0.41.0
APIError is a non-2xx response from memcode.ai: the HTTP status plus the server's {error} message. Kept typed so callers branch on the status, never on the wording of a message someone may later rephrase.
type Asset ¶ added in v0.40.0
type Asset struct {
Name string `json:"name"`
Size int64 `json:"size"`
URL string `json:"url,omitempty"`
}
Asset is one uploaded file in the site's durable assets/ prefix — a sibling of the build output, never touched by a rebuild.
type Brief ¶ added in v0.47.2
type Brief struct {
References []string `json:"references,omitempty"`
Requests []Request `json:"requests,omitempty"`
}
Brief is what a site has been asked to be: the references it should look like and the requests made of it, kept with the site (in its gitignored .memcode/) so a later session that says "pick up where we left off" or "make sure it's like the reference" still knows what that was. The worker's design plan sits beside it (site plan saves it).
type Build ¶ added in v0.41.0
type Build struct {
ID string `json:"id"`
Status string `json:"status"` // pending|running|completed|failed
Mode string `json:"mode"` // build|rebuild|edit
Prompt string `json:"prompt,omitempty"`
Summary string `json:"summary,omitempty"`
Error string `json:"error,omitempty"`
DateStarted string `json:"date_started,omitempty"`
DateCompleted string `json:"date_completed,omitempty"`
}
Build is one website_build row — a queued or finished build/edit run.
type BuildReport ¶ added in v0.47.0
type BuildReport struct {
OK bool
Pages int
Bytes int64
Problems []string // what must be fixed before the site will build/serve
Output string // the build's output tail, when it failed
}
BuildReport is the outcome of a local production build.
func BuildCheck ¶ added in v0.47.0
func BuildCheck(ctx context.Context, dir string) BuildReport
BuildCheck runs the site's production build into dist/ (gitignored) and checks what it produced.
func (BuildReport) Summary ¶ added in v0.47.0
func (r BuildReport) Summary() string
Summary describes the report in a few lines.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is an authenticated memcode.ai websites client.
func New ¶
New builds a client from the environment. Errors when the user has no token — the caller surfaces "run `memcode login`".
func (*Client) Build ¶ added in v0.41.0
Build queues a build for the site: a fresh build from a prompt (prompt non-empty) or a no-prompt rebuild of the current state. model may be empty to use the site's own pinned model. Returns ErrBuildsGated when the server's canSeeTestPlans gate rejects the request.
func (*Client) CatchUp ¶ added in v0.42.0
CatchUp brings a working copy up to date with memcode.ai when it has no changes of its own (a fast-forward). It reports whether anything changed; a copy with its own unpushed work is left alone.
func (*Client) Checkpoint ¶ added in v0.47.0
Checkpoint records a round of changes in a managed working copy as one commit, so each change has a diff the user can see and undo, and returns what changed since the commit `since` ("3 files changed, 120 insertions(+), 8 deletions(-)"), "" when nothing did. A checkout the user pulled themselves is left to their own git; its uncommitted changes are reported.
func (*Client) Create ¶ added in v0.41.0
Create makes a new site. At least one of name/prompt should be given — the server distills a short name from the prompt when name is empty. This does NOT queue a build; call Build afterward to produce content (internal accounts only — others get ErrBuildsGated).
func (*Client) Delete ¶ added in v0.40.0
Delete soft-deletes the site: it stops serving and disappears from the org.
func (*Client) DeleteAsset ¶ added in v0.40.0
DeleteAsset removes one uploaded asset by name.
func (*Client) Edit ¶ added in v0.41.0
func (c *Client) Edit(ctx context.Context, siteID string, edits []Edit, model string) (Build, error)
Edit queues an inline-edit build: verbatim find/replace edits applied by the builder without the agent, then a fast vite rebuild. Returns ErrBuildsGated when the server's canSeeTestPlans gate rejects the request.
func (*Client) Get ¶ added in v0.41.0
Get fetches one site by id (not slug), including its live URL. The detail route does NOT compute has_preview (only the list route does) — use GetBySlug when you need it.
func (*Client) GetBySlug ¶ added in v0.41.0
GetBySlug resolves a slug and returns the site's full detail. It merges the two routes' views: the detail route has every column (model, published_at, …) but not has_preview, which only the list route computes — so the list row's HasPreview is carried over instead of being reset to false.
func (*Client) InitLocal ¶ added in v0.42.0
InitLocal creates a site on this machine only: the starter template in a new managed workspace, as a git repository with one commit. Nothing is created on memcode.ai.
func (*Client) Kit ¶ added in v0.47.0
Kit returns the current template's dependency set, from the same template memcode.ai scaffolds new sites from (and bakes into the hosted builder).
func (*Client) ListAssets ¶ added in v0.40.0
ListAssets returns the site's durable uploaded assets.
func (*Client) ListBuilds ¶ added in v0.41.0
ListBuilds returns the site's build history, newest first.
func (*Client) MergeHosted ¶ added in v0.42.0
MergeHosted merges memcode.ai's changes into a managed working copy that has its own: local work is committed, then the hosted history merged in. A conflict is aborted, leaving the copy as it was, and reported as ErrBehind.
func (*Client) Preview ¶ added in v0.40.0
Preview mints a short-lived draft-preview URL: preview--{slug}.{apex}, carrying the token website-host's draft serving path checks. Mirrors the exact construction the web app's UI does from the same /preview-token response — there is no separate CLI auth scheme.
func (*Client) Publish ¶
Publish promotes the site's draft to its live URL. Returns the live URL when the server reports one.
func (*Client) Pull ¶
Pull clones the site's repo bundle into destDir (which must not exist) and writes the .memcode/website.json marker.
func (*Client) Push ¶
Push bundles the repo at dir and uploads it; the server rebuilds the draft preview from the pushed source. A site that exists only on this machine is created on memcode.ai by its first push, like pushing a new git repo. Pending changes in a managed working copy are committed first, so the push carries what the dev server shows.
func (*Client) Share ¶ added in v0.43.0
Share makes a share link for a site's draft, valid for days (0 = the server's default, a week).
func (*Client) ShareLinks ¶ added in v0.43.0
ShareLinks lists a site's share links that still work.
func (*Client) SyncLocalKit ¶ added in v0.48.0
SyncLocalKit moves a local site's kit packages to the current kit (see SyncKit) and, in a managed copy, commits the change on its own so it isn't mixed into the user's work.
func (*Client) Unshare ¶ added in v0.43.0
Unshare turns a share link off. It takes the code or the whole link.
func (*Client) Update ¶ added in v0.40.0
Update patches the site's name and/or model. Either pointer may be nil to leave that field untouched; at least one must be set.
func (*Client) UploadAsset ¶ added in v0.40.0
UploadAsset uploads the file at localPath, named by its own base name unless name is non-empty. The file goes straight to storage through a signed URL (no request-body limit in the way), then the server checks and adopts the stored object. A server without the signed flow gets the multipart upload instead.
type Edit ¶ added in v0.41.0
Edit is one verbatim find/replace applied by an edit-mode build, bypassing the agent for a fast, deterministic rebuild.
type ErrDependencies ¶ added in v0.47.0
type ErrDependencies struct{ Problems []Verdict }
ErrDependencies is a site whose package.json the policy refuses.
func (*ErrDependencies) Error ¶ added in v0.47.0
func (e *ErrDependencies) Error() string
type Kit ¶ added in v0.47.0
type Kit struct {
Dependencies map[string]string `json:"dependencies"`
DevDependencies map[string]string `json:"devDependencies"`
// History is the kit's version history (KitHistoryFile), when known.
History KitHistory `json:"-"`
}
Kit is the template's dependency set.
func BaselineKit ¶ added in v0.47.0
BaselineKit is the dependency set the site itself started from: package.json in its first commit. The fallback when the current template can't be read.
func ReadKit ¶ added in v0.47.0
ReadKit reads a kit from a package.json file, with the kit history beside it when there is one.
type KitHistory ¶ added in v0.48.0
type KitHistory struct {
Epoch int `json:"epoch"`
Versions map[string]map[string]int `json:"versions"`
}
KitHistory is every version the kit has pinned, by package, with the epoch each shipped in. Epoch is the kit's current epoch.
type KitMove ¶ added in v0.48.0
type KitMove struct {
Name string `json:"name"`
From string `json:"from"`
To string `json:"to"`
Dev bool `json:"dev,omitempty"`
}
KitMove is one package moving to the kit's version.
type KitPlan ¶ added in v0.48.0
type KitPlan struct {
Moves []KitMove `json:"moves"`
// Kept lists kit packages at a version the site's owner chose.
Kept []string `json:"kept,omitempty"`
// Migration lists kit packages from an older epoch. When it is non-empty,
// nothing moves.
Migration []string `json:"migration,omitempty"`
}
KitPlan is what syncing a site with the kit would do.
func PlanKitSync ¶ added in v0.48.0
PlanKitSync decides which of the site's packages follow the kit.
type LocalSite ¶ added in v0.42.0
type LocalSite struct {
Root string // the managed workspace root (~/.memcode/websites/<key>)
Source string // the site's repo working tree
Meta Meta
}
LocalSite is a site with a managed working copy on this machine.
func FindLocal ¶ added in v0.42.0
FindLocal finds a managed working copy by local name, local id, slug, or site id.
func (LocalSite) Label ¶ added in v0.42.0
Label is how the site is named to the user: its address once pushed, its local name before.
func (LocalSite) NeedsPush ¶ added in v0.42.0
NeedsPush reports whether memcode.ai is behind this working copy: never pushed, uncommitted changes, or commits since the last push.
type Meta ¶
type Meta struct {
SiteID string `json:"site_id,omitempty"` // empty until a local-only site is first pushed
Slug string `json:"slug,omitempty"`
// A site created on this machine (InitLocal) before it exists on memcode.ai.
LocalID string `json:"local_id,omitempty"`
Name string `json:"name,omitempty"`
// PushedHead is the commit the last push uploaded: a working copy whose
// HEAD differs, or that has uncommitted changes, has something to push.
PushedHead string `json:"pushed_head,omitempty"`
}
Meta is the .memcode/website.json marker written at pull time.
type Registry ¶ added in v0.47.0
type Registry struct {
BaseURL string // registry, e.g. https://registry.npmjs.org
DownloadsURL string // downloads API, e.g. https://api.npmjs.org/downloads/point/last-week
HTTP *http.Client
Now func() time.Time
}
Registry reads package facts from npm.
func NewRegistry ¶ added in v0.47.0
func NewRegistry() *Registry
NewRegistry returns a registry client for the public npm registry.
type ShareLink ¶ added in v0.43.0
type ShareLink struct {
}
ShareLink is a short link to a site's draft preview (memcode.ai/p/{code}). Anyone with it can view the draft until it expires or is turned off; it never shows or changes the live site.
type Site ¶
type Site struct {
ID string `json:"id"`
Name string `json:"name"`
Slug string `json:"slug"`
Status string `json:"status"`
Model string `json:"model,omitempty"`
HasPreview bool `json:"has_preview,omitempty"` // list route: a completed build exists to show
PublishedAt string `json:"published_at,omitempty"` // non-empty once Publish has run
LiveURL string `json:"url,omitempty"` // www list route emits `url` (siteUrl(slug))
}
Site is one website, as the www API reports it.
type Verdict ¶ added in v0.47.0
type Verdict struct {
Name string `json:"name"`
Version string `json:"version"`
Kit bool `json:"kit,omitempty"`
OK bool `json:"ok"`
Reason string `json:"reason,omitempty"` // why not, when !OK
License string `json:"license,omitempty"`
Downloads int `json:"weekly_downloads,omitempty"`
Published time.Time `json:"published,omitzero"`
}
Verdict is the policy's answer for one package.
func Add ¶ added in v0.47.0
Add installs one package into the site at dir: a kit package at the kit's version, anything else only when Vet passes. Installs never run package scripts, exactly as on memcode.ai.
func Check ¶ added in v0.47.0
Check judges every dependency of the site at dir against kit and the policy. It returns one verdict per dependency outside the kit (the kit is fine by definition) plus any devDependency change, which is never allowed: the build toolchain is the template's.
type Workspace ¶ added in v0.40.0
type Workspace struct {
Root string // managed: ManagedDir(siteID); explicit: the checkout dir itself
Managed bool
SourceDir string // the site's repo working tree (== Root for explicit mode)
AssetsDir string // asset cache, fully refreshed on every `dev` run
RuntimeDir string // generated, untracked dev-server config override
}
Workspace is the resolved {source, assets, runtime} layout `dev` works from, whichever mode produced it.
func ExplicitWorkspace ¶ added in v0.40.0
ExplicitWorkspace resolves (and creates .memcode/assets + .memcode/runtime for) the workspace rooted at an existing checkout dir. Callers MUST call config.EnsureGitignore(dir) first — see the package doc comment.
func ManagedWorkspace ¶ added in v0.40.0
ManagedWorkspace resolves (and creates assets/ + runtime/ for) the managed workspace for siteID. source/ is created separately, only when the caller actually clones into it (see Workspace.SourceDir, populated on demand).
func (Workspace) SourceExists ¶ added in v0.40.0
SourceExists reports whether SourceDir already holds a cloned repo (a non-empty directory) — the signal `dev` uses to decide whether to Pull.