Documentation
¶
Overview ¶
Package grimoire provides .grimoire project context file handling.
Index ¶
- Constants
- func GenerateTemplate(info *ProjectInfo, dir string) string
- func GrimoireMeta(dir string) string
- func Init(dir string) (string, error)
- func ResolveIncludes(g *Grimoire, baseDir string) error
- type GitSnapshot
- type Grimoire
- type GrimoireMetadata
- type GrimoireSource
- type HookEntry
- type IncludeRef
- type ProjectInfo
Constants ¶
const ( PriorityGlobal = 10 // ~/.celeste/grimoire.md PriorityProject = 20 // /repo-root/.grimoire PriorityFragment = 30 // /repo-root/.celeste/grimoire/*.md PriorityLocal = 40 // /repo-root/.grimoire.local )
Priority levels for grimoire sources (lowest to highest).
const MaxIncludeDepth = 3
MaxIncludeDepth is the maximum nesting depth for @include resolution.
const MaxSize = 25 * 1024 // 25KB
MaxSize is the maximum total grimoire context size in bytes.
Variables ¶
This section is empty.
Functions ¶
func GenerateTemplate ¶
func GenerateTemplate(info *ProjectInfo, dir string) string
GenerateTemplate creates a starter .grimoire file from project info.
func GrimoireMeta ¶ added in v1.8.3
GrimoireMeta returns a metadata header block for the grimoire file. Includes timestamp, git hash, and branch so staleness can be detected.
func Init ¶
Init creates a .grimoire file in the given directory. Returns the path to the created file, or error if one already exists.
func ResolveIncludes ¶
ResolveIncludes expands @./path and @~/path references in the Incantations section. It never returns an error for individual file failures; instead, it records errors on the individual IncludeRef entries.
Types ¶
type GitSnapshot ¶
type GitSnapshot struct {
Branch string
MainBranch string
Status string // short status output
RecentCommits string // last 5 commits oneline
UserName string
}
GitSnapshot captures the current git state for system prompt injection.
func CaptureGitSnapshot ¶
func CaptureGitSnapshot(workDir string) *GitSnapshot
CaptureGitSnapshot runs 5 git commands in parallel and returns the snapshot. Returns nil if not in a git repo. Truncates status to 2KB max.
func (*GitSnapshot) FormatForPrompt ¶
func (s *GitSnapshot) FormatForPrompt() string
FormatForPrompt formats the snapshot for system prompt injection.
type Grimoire ¶
type Grimoire struct {
Sources []string // file paths that contributed (ordered by priority)
Bindings []string // project facts (language, structure, commands)
Rituals []string // behavioral rules (always/never do)
Incantations []IncludeRef // @path includes with resolved content
Wards []string // protected areas
Hooks []HookEntry // pre/post tool execution commands
RawSections map[string]string // unparsed section content by heading
Meta GrimoireMetadata // embedded metadata (last updated, git hash, etc.)
}
Grimoire represents a fully resolved project context.
func Merge ¶
Merge combines multiple grimoires into one, preserving order. Later grimoires take precedence for RawSections keys.
func Parse ¶
Parse parses a .grimoire markdown file into a Grimoire struct. It splits on ## headings and maps content to known section types.
func (*Grimoire) StalenessInfo ¶ added in v1.8.3
StalenessInfo returns how stale the grimoire is relative to current git state. Returns a human-readable message, or "" if metadata is unavailable.
type GrimoireMetadata ¶ added in v1.8.3
type GrimoireMetadata struct {
LastUpdated time.Time
GitHash string
GitBranch string
GitCommitCount int
}
GrimoireMetadata holds the embedded metadata from the grimoire file.
type GrimoireSource ¶
GrimoireSource represents a discovered .grimoire file with its priority.
func Discover ¶
func Discover(startDir string) ([]GrimoireSource, error)
Discover walks upward from startDir to the filesystem root, collecting all .grimoire sources ordered by priority (lowest first).
type HookEntry ¶
type HookEntry struct {
Phase string // "PreToolUse" or "PostToolUse"
ToolName string // tool name pattern (e.g., "bash", "write_file")
Command string // shell command to execute
}
HookEntry represents a pre/post tool execution hook.
type IncludeRef ¶
type IncludeRef struct {
Path string // original @path from grimoire
Resolved string // absolute path after resolution
Content string // file content (empty if unresolved)
Error string // non-empty if resolution failed
}
IncludeRef represents an @include directive with its resolved content.
type ProjectInfo ¶
type ProjectInfo struct {
Language string
ModulePath string
TestCommand string
LintCommand string
BuildCommand string
EntryPoint string
Framework string
}
ProjectInfo holds detected project metadata.
func DetectProject ¶
func DetectProject(dir string) (*ProjectInfo, error)
DetectProject inspects the given directory and returns project information.