Skip to content

Stacks (resolver)

This page is the API reference for phd.stacks: composing, resolving and storing stacks. How it behaves and why: Stack resolver. Import it as a module: import phd.stacks as stacks.

Summary

Functions

Member Purpose
resolve(source, *, allow_duplicates=False, replace=False, store_root=None) -> Stack fetch, assemble and store a stack (source: a stack.toml, a folder with one, a config/ folder, or a Manifest; a URL string is refused, use compose(name, version, base=url)); returns it loaded from the store with stack.store set
get(ref, *, store_root=None) -> Stack a stored stack by "name@version", or "name" for its latest version; StackNotFound if unknown or its folder is missing
list(*, store_root=None) -> list[StoreEntry] every stored stack, sorted by name then storage time
remove(*refs, store_root=None) -> None remove stored stacks; nothing is removed if any ref is unknown
prune(*, store_root=None) -> None delete .staging leftovers older than 1 hour whose resolve is no longer running, and index entries whose folder is gone
compose(name, version, *, description=None, harnesses=None, default_models=None, base=None, agent=None, base_hooks=True, skills=(), mcp=(), hooks=(), root=None) -> Manifest build a Manifest in code (same rules as stack.toml)
load_manifest(path) -> Manifest parse and validate a stack.toml

Types

Member Purpose
Manifest(name, version, description=None, harnesses=None, default_models=None, base=None, agent=None, base_hooks=True, skills=(), mcp=(), hooks=(), path=None) frozen dataclass: a parsed manifest; .ref is "name@version"
ComponentSource(source, replace=False, headers={}) frozen dataclass: one source (path or URL) with its replace flag and headers; .is_url
StoreEntry(ref, name, version, hash, created_at, manifest, path, requested) frozen dataclass: where a stack lives in the store; .reused is true when an identical stack under another ref was returned

Errors: StackInvalid, StackFetchError, StackConflict, StackNotFound (see Errors).

Full reference

Rendered from the docstrings (MkDocs site only).

resolve

resolve(source: str | Path | Manifest, *, allow_duplicates: bool = False, replace: bool = False, store_root: str | Path | None = None) -> Stack

Fetch, assemble and store a stack; return it (loaded from the store, stack.store set).

Parameters:

Name Type Description Default
source str | Path | Manifest

A stack.toml, a folder containing one, a plain config/ folder, or a Manifest from compose(...). A URL string is refused: pass it as compose(name, version, base=url).

required
allow_duplicates bool

Store a new entry even when an identical stack is stored under another ref.

False
replace bool

Overwrite a stored name@version that has different content.

False
store_root str | Path | None

Store directory (default $PHD_STACKS_ROOT or ~/.phd/stacks).

None

Raises:

Type Description
StackInvalid

Bad manifest (or a URL string as source), a name clash without replace = true, the assembled stack fails the Stack.load checks, or the store is busy or not writable.

StackFetchError

A source cannot be read or downloaded, or an archive is unusable/unsafe.

StackConflict

name@version is stored with different content and replace is False.

get

get(ref: str, *, store_root: str | Path | None = None) -> Stack

A stored stack: "name@version", or "name" for its latest version. Raises StackNotFound.

list

list(*, store_root: str | Path | None = None) -> builtins.list[StoreEntry]

Every stored stack, sorted by name then storage time.

remove

remove(*refs: str, store_root: str | Path | None = None) -> None

Remove stored stacks (name@version); nothing is removed if any ref is unknown.

prune

prune(*, store_root: str | Path | None = None) -> None

Delete leftover staging folders and index entries whose folder is gone.

A staging folder is left alone while the process that created it is running (or younger than 1 hour).

compose

compose(name: str, version: str, *, description: str | None = None, harnesses=None, default_models: dict[str, str] | None = None, base=None, agent=None, base_hooks: bool = True, skills=(), mcp=(), hooks=(), root: str | Path | None = None) -> Manifest

Build a Manifest in code; same fields and rules as stack.toml.

skills / mcp / hooks items are a source string (or path) or a dict {"source": ..., "replace": bool, "headers": {...}}. Relative paths resolve against root (default: the current working directory).

Example
m = compose("reviewer", "1.3.0", base="https://…/reviewer-1.2.0.tar.gz",
            skills=["~/.phd/skills/pytest-helpers"])

load_manifest

load_manifest(path: str | Path) -> Manifest

Parse and validate a stack.toml. Relative sources resolve against its directory.

Raises:

Type Description
StackInvalid

Unreadable file, invalid TOML, or an invalid / unknown key.

Manifest dataclass

Manifest(name: str, version: str, description: str | None = None, harnesses: tuple[str, ...] | None = None, default_models: dict[str, str] | None = None, base: ComponentSource | None = None, agent: ComponentSource | None = None, base_hooks: bool = True, skills: tuple[ComponentSource, ...] = (), mcp: tuple[ComponentSource, ...] = (), hooks: tuple[ComponentSource, ...] = (), path: Path | None = None)

A parsed stack manifest: what to fetch and how to assemble it.

Attributes mirror the stack.toml keys; path is the manifest file (or None for compose).

ref property

ref: str

"<name>@<version>".

ComponentSource dataclass

ComponentSource(source: str, replace: bool = False, headers: dict[str, str] = dict())

Where one component comes from.

Attributes:

Name Type Description
source str

An https:// URL (or http://localhost / http://127.0.0.1) or an absolute local path (relative paths are resolved when the manifest is parsed).

replace bool

Deliberately replace an existing component with the same name.

headers dict[str, str]

HTTP headers for this source; ${env:NAME} is expanded from the environment at fetch time. Never written to the store.

is_url property

is_url: bool

True for an http(s) URL, False for a local path.

StoreEntry dataclass

StoreEntry(ref: str, name: str, version: str, hash: str, created_at: str, manifest: str | None, path: Path, requested: str)

Where a stack lives in the PHD stack store (phd.stacks).

Attributes:

Name Type Description
ref str

"<name>@<version>" of the stored stack that is used.

name str

Stored stack name.

version str

Stored stack version.

hash str

Identity hash ("sha256:<hex>"): the content hash with stack.json's name, version and description left out.

created_at str

ISO-8601 time the entry was stored.

manifest str | None

Path of the manifest it was resolved from, or None.

path Path

The stored stack directory (<store>/<name>/<version>/config).

requested str

The name@version that was asked for. It differs from ref when an identical stack already stored under another ref was reused.

reused property

reused: bool

True when an identical stack stored under another ref was returned instead of storing a new one.


Next: Dispatcher · See also: Stack resolver, API overview