Documentation
¶
Overview ¶
Package candywalk is the SHARED entity-discovery walk over a charly repo: the superproject plus every box/<distro> submodule, reading every candy/ + box/ charly.yml and returning one Entity per top-level node. It is the ONE discovery abstraction (R3) both out-of-process generator plugins use — candy/plugin-docs (the docs site generator) and candy/plugin-marketplace (the harness/marketplace generator) — so the two never fork their own directory conventions.
Discovery is PURE FILESYSTEM walking + os.ReadFile — it never shells out to git, never runs charly commands. "Defined, not default-active": it returns every DEFINED entity (what an author wrote down), never the resolved/enabled set (the resolver's surfaces are wrong for a catalog — `charly box list boxes` resolves through main's import: closure and omits every debian.* and ubuntu.* box). Each repo (the superproject + each checked-out box/<distro> submodule) is walked as its own root and the results unioned; an uninitialised submodule (no charly.yml) is skipped.
The candy de-submodule cutover (Phases 1-2) moved every candy to a standalone kind-prefixed repo (layer-*, pod-*, vm-*, plugin-*). Phase 4 deletes the in-repo candy/ dirs, after which the local FS walk alone finds only the residual fixtures. CollectEntitiesRemote extends discovery with a REMOTE-REF-AWARE mode: it also collects every @github.com/opencharly/... ref from the walked files' require:/candy: lists, resolves each repo+tag via a CALLER-SUPPLIED resolver seam (out-of-process generators use spec/refs.DownloadRepo; an in-proc caller could supply the loader's EnsureRepoDownloaded), and walks each fetched repo's candy dir (or repo-root charly.yml for config candies) — fix-pointing until no new refs surface, the same transitive closure the runtime scan materialises. The seam keeps this kit import-free: candywalk itself still carries NO charly or sdk import — only the stdlib + yaml.v3.
The package carries only the CONTRACT module + the pure kit (github.com/opencharly/spec for ParseRemoteRef (F4.3), github.com/opencharly/sdk/kit for RepoLayoutDirs (F4.4)) — never charly, never a mechanism kit with registry/host coupling. It returns the raw per-node kind discriminator + value node; the caller owns the projection into its own types (the docs plugin decodes `candy:` into its candyView/boxView; the marketplace plugin decodes `skill:`/`hook:`/ `marketplace:` into the generated spec types).
Index ¶
Constants ¶
const ( // AgentsSkillsDir is the Agent-Skills standard location: what a candy's `skills:` list means // when it declares none. AgentsSkillsDir = ".agents/skills" // AgentsAgentsDir is the Agent-Skills standard location for sub-agent DEFINITIONS — the SIBLING // of AgentsSkillsDir, never a child of it. An `agent`-type node is authored at // <AgentsAgentsDir>/<name>.md: a sub-agent definition is not a skill, and a `skills:` list of // SKILL trees does not govern it (see the `skill` kind's own schema comment). AgentsAgentsDir = ".agents/agents" )
skillfile.go — the authored FILE sources: the ONE reader of a `skill:` node's prose.
A skill's body lives in the repository that owns it, not in its `skill:` entity:
<tree>/<name>/SKILL.md frontmatter (name + description) + the markdown body <tree>/<name>/references/<stem>.md no frontmatter, by contract
where <tree> is the tree the owning candy's `skills:` list declares (default AgentsSkillsDir) and <name> is the skill id: the DIRECTORY name, which the frontmatter `name` must agree with. The entity keeps the routing (family/owner/triggers/category); the file keeps the prose. The version of record is the github ref that fetched the repo — the marketplace refs list's pin, or a consumer's `candy:` list — so nothing here fetches anything.
An `agent`-type node is a SUB-AGENT DEFINITION, not a skill, so it has its own SHAPE at its own tree — ONE markdown file, with no entry directory and no split references:
<AgentsAgentsDir>/<name>.md frontmatter (name + description) + the markdown body
A candy's `skills:` list is a list of SKILL trees and does NOT govern that path, so a mixed repo — skills under a declared tree, agents under `.agents/agents` — is the legal shape, not a half-move. The two shapes differ ONLY in their paths: both go through the one parse (readAuthoredEntry), so a skill and an agent carrying the same bytes read back identically.
The shape read here is BOTH the marketplace corpus's (banner included) and the bare shape a repo authors after extraction: the generator's DO-NOT-EDIT marker is stripped either way. That is what makes the relocation's round trip exact — `extract` writes the bare file, the corpus emitter re-writes it with the banner, and the two read back to the same Content.
It lives in the shared kit, not in either generator, because BOTH need it (candy/plugin-marketplace and candy/plugin-docs) and R2 allows one implementation of one read. The docs projection's readSkill — fence split, two-key frontmatter, marker strip, stem-sorted references — is this function's prior art; it converges on this one.
WHICH shape a node's prose is filed in is decided HERE, by ShapeOf — never by a consumer comparing the raw `type:` string itself, and never by a consumer hard-coding one tree. ReadNodeBody is the ONE resolution that decision produces, and deploykit's label+validate collector calls it. The marketplace generator is the second consumer the rule exists for: it converts onto the same authority in its own PR (opencharly/plugin-marketplace), which is what makes the CORPUS and the GATE read one rule instead of two copies — until that PR lands, the generator's read and extract branches still carry their own `type:` comparison, so the two agree by having been written to the same contract, not yet by sharing the code. opencharly/sdk#456 is what a drift costs: the collector resolved the skills tree for every node, so each `type: agent` node reported "no body" for a body sitting exactly where the contract files it.
const UnifiedFileName = "charly.yml"
UnifiedFileName is the one entity filename (the project rulebook's "one filename charly.yml").
Variables ¶
This section is empty.
Functions ¶
func NodeBodyLocation ¶ added in v0.2026296.1141
NodeBodyLocation names, for a "no body" message, the file a node's shape is filed at under the repo root — derived from the SAME mapping ReadNodeBody dispatches on.
It exists so that the caller reporting a missing body cannot name the OTHER shape's path. That is not cosmetic: the defect this authority closes is a gate that told an author no SKILL.md existed under .agents/skills for a node whose contract files it at .agents/agents/<name>.md, so the author's obvious next move — move the file — could not have made it reachable.
`trees` is the owning candy's declared skill trees (nil ⇒ AgentsSkillsDir) and is ignored for an agent node. Several declared trees are named side by side, since any of them would satisfy the read.
func ReadSkillTree ¶ added in v0.2026288.1246
ReadSkillTree reads every skill one tree declares: every <treeDir>/<name>/SKILL.md, keyed by directory name. A directory without an entry file is not a skill and is skipped; a tree that does not exist at all is (empty, nil), because a repo that has not moved yet is a normal state and not an error.
Types ¶
type AgentFile ¶ added in v0.2026289.157
type AgentFile struct {
// Name is the resolved agent id — the `.md` file STEM, which the frontmatter `name` must agree
// with when it states one.
Name string
// Description is the frontmatter `description`: the sub-agent's dispatch keyword.
Description string
// Content is the markdown body VERBATIM — marker stripped, and deliberately NOT trimmed, for the
// same reason SkillFile.Content is: the corpus emitter writes TrimSuffix(content, "\n") + "\n".
Content string
}
AgentFile is the prose half of an `agent`-type skill node, read from its file.
It is a SEPARATE type from SkillFile on purpose: the agent shape has no `references/` half and no entry DIRECTORY, so carrying SkillFile's `References`/`Dir` fields here would be two fields that can only ever be nil/empty — a shape pretending to be another shape.
func ReadAgentFile ¶ added in v0.2026289.157
ReadAgentFile reads ONE sub-agent definition: <agentsDir>/<name>.md.
A missing file is (nil, nil), not an error — the same contract as ReadSkillFile's: whether an `agent` node MUST have a file is the caller's call, and the marketplace generator is the caller that hard-errors on a node with neither a file nor an in-line body, because publishing nothing there would silently drop a published sub-agent.
A consumer that starts from a `skill:` node and must find its body without already knowing the shape calls ReadNodeBody, which dispatches here for ShapeAgentFile.
type AuthoredBody ¶ added in v0.2026296.1141
type AuthoredBody struct {
// Shape is the layout the body was read from, kept for a caller that must report it.
Shape AuthoredShape
// Name is the resolved id: the SKILL.md directory name, or the `.md` file stem for an agent.
Name string
// Description is the frontmatter `description`.
Description string
// Content is the markdown body VERBATIM (marker stripped, never trimmed).
Content string
// References are the skill shape's stem-sorted `references/<stem>.md` files. Always nil for
// ShapeAgentFile.
References []SkillReferenceFile
}
AuthoredBody is ONE `skill:` node's prose, read from the file its repository owns, with both authored shapes projected onto a single value — so a consumer that publishes or labels the prose never branches on the shape.
The difference the shape still carries is visible here rather than hidden: an agent file has no `references/` half by construction, so its References are ALWAYS nil. That is also why SkillFile/AgentFile stay distinct types — this projection is where the two are allowed to converge, and only the consumer that must report per-shape detail should reach past it.
func ReadNodeBody ¶ added in v0.2026296.1141
func ReadNodeBody(base, name, nodeType string, trees []string) (*AuthoredBody, error)
ReadNodeBody reads ONE `skill:` node's prose from the repository that owns it, dispatching on the node's `type:` — the ONE authority for WHERE each authored shape lives:
ShapeSkillFiles <base>/<tree>/<name>/SKILL.md the first declared tree that holds it ShapeAgentFile <base>/AgentsAgentsDir/<name>.md
`trees` are the skill trees the owning candy declares; nil (or empty) means the standard AgentsSkillsDir, which is what a candy that declares no `skills:` list means. They are IGNORED for an agent node: a `skills:` list is a list of SKILL trees and does not govern a sub-agent definition, which is what makes a mixed repo the legal shape rather than a half-move.
(nil, nil) means "no file here" — whether that is legal is the caller's call, the same contract ReadSkillFile/ReadAgentFile carry: the marketplace generator hard-errors when the node also carries no in-line body, and deploykit's collector does the same, because publishing nothing there silently drops a published skill or sub-agent. Every other failure (an unreadable file, malformed frontmatter, an id disagreeing with the file it is filed under) is an error, because each would publish the wrong prose under the right name.
type AuthoredShape ¶ added in v0.2026296.1141
type AuthoredShape int
AuthoredShape is the FILE LAYOUT a `skill:` node's prose takes, selected by the node's `type:` discriminator. It is the ONE mapping from that discriminator to a layout: a consumer that must find a body (deploykit's collector) or write one (the marketplace's `extract`) asks ShapeOf, never the raw `type:` string, so the two shapes cannot drift between callers.
const ( // ShapeSkillFiles is <tree>/<name>/SKILL.md plus references/<stem>.md, where <tree> is the // owning candy's `skills:` list — AgentsSkillsDir when it declares none. ShapeSkillFiles AuthoredShape = iota // ShapeAgentFile is AgentsAgentsDir/<name>.md — ONE file, no entry directory, no references/. ShapeAgentFile )
func ShapeOf ¶ added in v0.2026296.1141
func ShapeOf(nodeType string) AuthoredShape
ShapeOf resolves a `skill:` node's authored shape from its `type:`. "agent" is a sub-agent DEFINITION's shape; everything else is a skill's, including the empty value the schema's `type?: *"skill" | "agent"` default pins it to.
type Entity ¶
type Entity struct {
Name string // the top-level node name (as authored)
Namespace string // "" for the superproject, else the box/<distro> submodule name
Dir string // directory holding this charly.yml, relative to the repo root
Kind string // the node's kind discriminator ("candy", "skill", "hook", "marketplace", …)
Value yaml.Node // the kind value body
SourceRoot string // absolute repo root ("" = local root; else the fetched remote cache dir)
}
Entity is one top-level node of a discovered charly.yml, regardless of kind. The value node is the node's kind value (the body under `<name>: {<kind>: …}`).
Value is a VALUE yaml.Node, not a pointer: yaml.v3's decode into `map[string]map[string]*yaml.Node` silently drops nested structs when the caller then Decodes the leaf (a plugin-fleet candy's `plugin:` block came back nil), while the value-node decode round-trips faithfully. The value-node form is what the original plugin-docs walk used.
SourceRoot is the ABSOLUTE path of the repo root this entity was read from: "" for a local superproject/box root (the caller knows the local root it passed in), or the fetched repo cache dir for a REMOTE entity from CollectEntitiesRemote. Schema reads and other per-entity file lookups must resolve relative to SourceRoot (when non-empty) rather than the local project root.
func CollectEntities ¶
CollectEntities reads every entity node across every repo root, for the two discovery directories the loader uses (candy/ and box/). Discovery is by directory convention (candy/<name>/charly.yml, box/<name>/charly.yml) — the same two the loader uses — so the result is exactly what an author has written down.
func CollectEntitiesRemote ¶ added in v0.2026237.1646
func CollectEntitiesRemote(roots []Root, resolve RemoteResolver) ([]Entity, error)
CollectEntitiesRemote extends CollectEntities with the candy de-submodule cutover's remote-ref-aware discovery (Phase 3): every @github.com/opencharly/... ref found in the walked files' require:/candy: lists is resolved through the caller-supplied seam and the fetched repo's own candy entities (candy/<name>/charly.yml or the repo-root charly.yml for config candies) are unioned into the result, TRANSITIVELY — a fetched repo's own require:/candy: lists may surface new refs, which are fetched in turn, until closure (the same fix-point the runtime scan materialises). Entity.SourceRoot carries the fetched repo dir for remote entities so schema reads resolve against the fetched tree, not the local project root.
func ReadEntityFile ¶
ReadEntityFile decodes one charly.yml into its top-level nodes. The file is a map of entity NAME to a single kind key (name-first shape); each (name, kind, value) triple is one Entity. A charly.yml that does not fit the name-first shape (a multi-doc bed, a template) is skipped rather than failing the whole discovery. Scalar top-level keys (the standalone repos' prepended `version: <calver>` schema header) are tolerated and ignored — they are not entities.
type RemoteResolver ¶ added in v0.2026237.1646
RemoteResolver resolves one remote candy ref to a LOCALLY FETCHED repo directory. It is the caller-supplied seam that keeps this kit import-free: an out-of-process generator supplies spec/refs.DownloadRepo (or a wrapper), an in-proc caller supplies the loader's EnsureRepoDownloaded. The returned dir must hold the fetched repo export (the same shape the runtime's repo cache produces) so the walker can read its candy/ + root charly.yml.
type Root ¶
type Root struct {
Namespace string // "" for the superproject, else the box/<distro> submodule name
Dir string // absolute path
}
Root is one project tree to walk: the superproject, or a box/<distro> submodule.
type SkillFile ¶ added in v0.2026288.1246
type SkillFile struct {
// Name is the resolved skill id — the directory name, which the frontmatter `name` must agree
// with when it states one.
Name string
// Dir is the directory the file was read from (equal to Name; kept separate so a caller that
// reports a mismatch can name both sides).
Dir string
// Description is the frontmatter `description`: the Skill-tool dispatch keyword, and the public
// subtitle when the corpus page is rendered.
Description string
// Content is the markdown body VERBATIM — marker stripped, and deliberately NOT trimmed. The
// corpus emitter writes TrimSuffix(content, "\n") + "\n", so returning the body as authored is
// exactly what makes read -> emit byte-identical.
Content string
// References are the skill's split files, stem-sorted so every consumer's output is deterministic.
References []SkillReferenceFile
}
SkillFile is the prose half of a `skill:` entity, read from its file.
func ReadSkillFile ¶ added in v0.2026288.1246
ReadSkillFile reads ONE skill's files: <treeDir>/<name>/SKILL.md, plus every <treeDir>/<name>/references/<stem>.md beside it.
A missing entry file is (nil, nil), not an error — whether a skill MUST have one is the caller's call: the marketplace generator hard-errors when an entity carries neither a body nor a file, because publishing nothing there would silently drop a published skill. Everything else is an error, because each case would otherwise publish the wrong skill under the right name: an unreadable file, malformed frontmatter, or a frontmatter `name` that disagrees with its directory.
A consumer that starts from a `skill:` node and must find its body without already knowing the shape calls ReadNodeBody, which dispatches here for ShapeSkillFiles.
type SkillReferenceFile ¶ added in v0.2026288.1246
type SkillReferenceFile struct {
Stem string // the file stem: references/<stem>.md
Content string // the file's markdown verbatim, marker stripped
}
SkillReferenceFile is one `references/<stem>.md` split file of a skill.