Documentation
¶
Overview ¶
Package configroot resolves PiG's config root, the directory PiG keeps its settings, documentation bundle and state under. It is a leaf package so that code the coding agent imports (the system prompt builder) and the coding agent itself name one directory through one implementation.
The policy is the same in the host and in every extension SDK (Go, Python, Rust, Node): PIG_HOME, else XDG_CONFIG_HOME/pig, else ~/.pig. An empty variable falls through to the next choice. A leading ~ or ~/ expands to the home directory. Any other value stays literal. When the home directory is needed and cannot be found, resolution fails; it never yields a relative path. Pi-sharing mode (PIG_USE_PI_DIRS=1) moves only the agent and project directories (D2), so nothing here reads it.
Index ¶
- func Dir() string
- func DocsDir() (string, bool)
- func DocsPresent() bool
- func ExpandHome(path string) (string, error)
- func ExpandTilde(path string) string
- func RegisterDocsBundle(name func() (string, error))
- func Resolve() (string, error)
- func SetDocsPresent(present bool)
- func SetDocsWriter(write func())
- func WriteDocs()
- type UnresolvedError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Dir ¶
func Dir() string
Dir is Resolve for a caller that has no way to report a failure. It panics with an *UnresolvedError instead of returning a path relative to the working directory; the pig command reports that panic as an error and exits.
func DocsDir ¶
DocsDir is the absolute directory of this binary's documentation bundle under the config root, and false when the binary embeds none. Pi's config.ts getDocsPath is resolve(join(<package dir>, "docs")); PiG has no installed package directory, so its bundle lives under the config root (D22). A relative PIG_HOME resolves against the working directory, as Node's resolve does.
func DocsPresent ¶
func DocsPresent() bool
DocsPresent reports whether text may name DocsDir and the pages in it: the binary embeds a bundle and startup did not fail to write it.
func ExpandHome ¶
ExpandHome expands a leading ~ or ~/ in path and returns an error when the home directory is needed and unavailable. A path with no leading ~ ("~user", a ~ elsewhere, an absolute or relative path) is returned unchanged and needs no home directory.
func ExpandTilde ¶
ExpandTilde expands a leading ~ in a filesystem path, as upstream expandTildePath (utils/paths.ts normalizePath) does. It has no error result: when os.UserHomeDir fails, the home directory is the empty string. Node's os.homedir() instead falls back to the passwd database and throws when that fails too. A PiG-owned root uses ExpandHome instead, which reports the failure.
func RegisterDocsBundle ¶
RegisterDocsBundle names, under <config root>/docs, the directory of the documentation bundle this binary embeds. internal/pigdocs registers it; a Binary that strips docs links no pigdocs and registers none. pig additive (D22): each build's bundle has its own content-addressed directory, so builds that share a config root never rewrite each other's.
func Resolve ¶
Resolve is the config root: PIG_HOME, else XDG_CONFIG_HOME/pig, else ~/.pig. An empty variable is ignored and a leading ~ in either is expanded. It returns an error, never a relative path, when the home directory is needed and cannot be found.
func SetDocsPresent ¶
func SetDocsPresent(present bool)
SetDocsPresent records whether DocsDir holds this build's documentation bundle. Startup sets it once, after it tries to write the bundle; until then a registered bundle counts as present. pig additive (D22): Pi's package docs exist wherever Pi runs. PiG's bundle exists only once written, so no text may name it after a failed write.
func SetDocsWriter ¶
func SetDocsWriter(write func())
SetDocsWriter registers write as the function that writes the bundle startup deferred; it must update SetDocsPresent when the write fails. pig additive (D22): PiG writes its bundle before the first reader, not at every start.
Types ¶
type UnresolvedError ¶
type UnresolvedError struct{ Err error }
UnresolvedError is the value Dir panics with. The pig command recovers it, prints the message and exits 1.
func (*UnresolvedError) Error ¶
func (e *UnresolvedError) Error() string
func (*UnresolvedError) Unwrap ¶
func (e *UnresolvedError) Unwrap() error