Documentation
¶
Index ¶
- Constants
- func EstimateTokens(content string) int
- func Excerpt(body string, maxTokens int) string
- func HasPrincipleSection(body string) bool
- func PrefixExcerpt(body string, maxTokens int) string
- type ContextItem
- type ContextPackConfig
- type ContextPackResult
- type ContextPackTarget
- type OmittedNote
- type PinnedConfig
- type PinnedItem
- type PinnedResult
- type PinnedVault
- type RecallConfig
- type RecallEdge
- type RecallNode
- type RecallResult
- type ReciteConfig
- type ReciteItem
- type ReciteResult
- type RelatedConfig
- type RelatedItem
- type RelatedResult
- type Seed
- type SummarizeConfig
- type SummarizeResult
- type SummarizeSource
Constants ¶
const ( PriorityExplicitRelation = 0 // frontmatter related_ids, parent_id, source_ids PriorityExplicitLink = 1 // wikilinks, markdown links, embeds PriorityMediumConfidence = 2 // inferred edges with medium confidence PriorityLowConfidence = 3 // inferred edges below medium )
Priority tier constants for edgePriority. Lower value = higher priority (closer to the target in the context-pack ranking).
The numeric values also appear in the distance-weighted ranking formula (distance*10 + priority), so the gaps between tiers encode the relative cost of "one edge further away" vs "one tier weaker confidence". Don't renumber without updating the distance formula.
const EdgeTypeSearchHit = "search_hit"
EdgeTypeSearchHit marks a context item that entered the pack as a seed (a relevant search hit), not by an edge from the target.
const SessionPinnedBudget = 1500
SessionPinnedBudget is the token ceiling a session start spends on notes marked pinned. doctor warns against this same number, and the session-start hooks default to it. One constant, so the warning and the hook cannot drift.
const SessionPinnedExcerpt = 400
SessionPinnedExcerpt is how many tokens of a long pinned note the session-start hook shows. The hook's VAULTMIND_PINNED_EXCERPT default is this number. The command's own --excerpt default stays 0, the whole body.
Variables ¶
This section is empty.
Functions ¶
func EstimateTokens ¶
EstimateTokens estimates the number of LLM tokens for the given content. Uses the heuristic of 4 characters per token with ceiling division.
func Excerpt ¶ added in v0.7.0
Excerpt returns the most decision-relevant part of a note body, within maxTokens.
WHY THIS EXISTS. The packer includes bodies all-or-nothing (`if bodyTokens <= *remaining`), so a note larger than the leftover budget contributes nothing at all and the pack reports "3 items, 0 with bodies" — items present, content absent. Measured on the identity vault, whose median note is ~1,084 tokens against a 900-token hook budget, that is the common case rather than the edge case.
An excerpt always fits, so it turns "no body" into "the part that matters".
It prefers the Principle section because of how arcs are written: the first paragraph is the Trigger — story setup — and the rule an agent could act on is several sections down. Injecting the lead hands over the anecdote and withholds the lesson.
func HasPrincipleSection ¶ added in v0.10.10
HasPrincipleSection reports whether Excerpt prefers a non-empty Principle section. Query-aware ask excerpts preserve this same recognition rule.
func PrefixExcerpt ¶ added in v0.10.18
PrefixExcerpt returns the opening of a pinned note, including headings, lists and code. It keeps whole lines when possible and includes any closing code fence in the token cost, so an excerpt cannot swallow the next note.
Types ¶
type ContextItem ¶
type ContextItem struct {
ID string `json:"id"`
EdgeType string `json:"edge_type"`
Confidence string `json:"confidence"`
Frontmatter map[string]interface{} `json:"frontmatter"`
BodyIncluded bool `json:"body_included"`
// BodyExcerpted marks Body as the note's most decision-relevant passage
// rather than its whole text. It is recorded rather than inferred because
// "the agent got the note" and "the agent got the gist" are different facts,
// and a metric that cannot tell them apart reports the second as the first.
BodyExcerpted bool `json:"body_excerpted,omitempty"`
Body string `json:"body,omitempty"`
// ShownBefore marks a note whose body this conversation already received
// recently. It degrades to its title — never dropped, so an agent that lost
// the earlier copy to compaction still sees the note exists.
ShownBefore bool `json:"shown_before,omitempty"`
// BodyOmittedBudget records a non-empty body excluded by the token budget.
// Empty or unavailable bodies must never be described as budget losses.
BodyOmittedBudget bool `json:"body_omitted_budget,omitempty"`
// BodyRawUnfilled is true when body_raw IS NULL. See ContextPackTarget.
BodyRawUnfilled bool `json:"-"`
// AnswersGap is the recorded question this note closed. Present only when
// this item's body was delivered and the note was not already shown.
AnswersGap *index.GapCredit `json:"answers_gap,omitempty"`
}
ContextItem holds context metadata for a single related note.
type ContextPackConfig ¶
type ContextPackConfig struct {
Input string
Budget int // token budget
Depth int // BFS traversal depth; 0 or 1 = direct neighbors only (default)
MaxItems int // max context items to return; 0 = unlimited (default, backward-compat)
Slim bool // reduce context item frontmatter to {type, title, status} only
ActivationScores map[string]float64 // optional activation scores keyed by note ID
// ExcerptTokens caps a per-item excerpt used when a whole body will not fit
// the remaining budget. 0 (default) keeps the released all-or-nothing
// behaviour, where such an item contributes no text at all.
//
// Without this, a pack can honestly report "3 items" while handing the agent
// nothing but titles — which is what a 900-token hook budget does against a
// vault whose median note is larger than the budget.
ExcerptTokens int
// Seeds are notes the caller already judged relevant — ask passes the
// search hits after the first that clear the weak band. They are packed
// ahead of every graph neighbour, in the order given, because a note that
// matched the question outranks one that is merely linked to the answer.
Seeds []Seed
// IncludeDrafts lets a status:draft note be a context item. Off by default,
// the same switch as ranking. The note the caller named is the target and
// is packed either way.
IncludeDrafts bool
}
ContextPackConfig holds parameters for a ContextPack operation.
type ContextPackResult ¶
type ContextPackResult struct {
TargetID string `json:"target_id"`
BudgetTokens int `json:"budget_tokens"`
UsedTokens int `json:"used_tokens"`
BudgetExhausted bool `json:"budget_exhausted"`
Truncated bool `json:"truncated"`
Target *ContextPackTarget `json:"target"`
Context []ContextItem `json:"context"`
}
ContextPackResult is the full output of a ContextPack operation.
func ContextPack ¶
func ContextPack(resolver *graph.Resolver, db *index.DB, cfg ContextPackConfig) (*ContextPackResult, error)
ContextPack resolves the input, loads the target note, and fills a token budget with the target body and related note frontmatter in priority order.
type ContextPackTarget ¶
type ContextPackTarget struct {
ID string `json:"id"`
Frontmatter map[string]interface{} `json:"frontmatter"`
// BodyExcerpted marks Body as the note's decision-bearing passage rather
// than its whole text — same meaning as on ContextItem, and needed here for
// the same reason: a renderer that cannot tell the difference will truncate
// an already-bounded excerpt a second time.
BodyExcerpted bool `json:"body_excerpted,omitempty"`
// BodyCutToBudget is set only when the packer byte-sliced Body to fit the
// budget. It is not BodyExcerpted (a chosen passage) and not the pack's
// Truncated flag (also set when the body is empty or there is no room).
// The ask header reads it so a cut body is not called "delivered in full".
BodyCutToBudget bool `json:"body_cut_to_budget,omitempty"`
Body string `json:"body,omitempty"`
// ShownBefore marks a note whose body this conversation already received
// recently; it is sent as its title alone. See ContextItem.ShownBefore.
ShownBefore bool `json:"shown_before,omitempty"`
// BodyOmittedBudget records a non-empty body excluded by the token budget.
// Empty or unavailable bodies must never be described as budget losses.
BodyOmittedBudget bool `json:"body_omitted_budget,omitempty"`
// BodyRawUnfilled is true when body_raw IS NULL. The ask footer suggests
// re-indexing only then; a stored empty body is not unfilled.
BodyRawUnfilled bool `json:"-"`
// AnswersGap is the recorded question this note closed. It is present only
// when the text line is: the body was delivered, and the note was not
// already shown. A draft or a gap never carries it.
AnswersGap *index.GapCredit `json:"answers_gap,omitempty"`
}
ContextPackTarget holds the fully-loaded target note.
type OmittedNote ¶ added in v0.10.16
type OmittedNote struct {
ID string `json:"id"`
Title string `json:"title"`
Vault string `json:"vault,omitempty"`
}
OmittedNote is a pinned note the caller can see but did not receive. An id alone is not enough: the session needs the title to know what to unpin, and the vault when more than one was read.
type PinnedConfig ¶ added in v0.10.16
PinnedConfig bounds the pinned set. Budget 0 is unbounded. ExcerptTokens 0 is the whole body. Both match arc recite.
type PinnedItem ¶ added in v0.10.16
type PinnedItem struct {
ID string `json:"id"`
Title string `json:"title"`
Excerpt string `json:"excerpt"`
Tokens int `json:"tokens"`
Vault string `json:"vault,omitempty"`
}
PinnedItem is one pinned note that fit. Vault is the path it was read from.
type PinnedResult ¶ added in v0.10.16
type PinnedResult struct {
Total int `json:"total"`
Items []PinnedItem `json:"items"`
Omitted []OmittedNote `json:"omitted,omitempty"`
Tokens int `json:"tokens"`
Budget int `json:"budget"`
}
PinnedResult is every pinned note that fit, plus the names of those that did not.
func Pinned ¶ added in v0.10.16
func Pinned(db *index.DB, cfg PinnedConfig) (*PinnedResult, error)
Pinned loads every note marked pinned: true in one vault, ordered by id.
Drafts and gaps are included when they are pinned. Pinning is explicit. A note the index names and the store cannot load is named with an empty title, the same way recite counts a missing arc, rather than skipped.
func PinnedVaults ¶ added in v0.10.16
func PinnedVaults(vaults []PinnedVault, cfg PinnedConfig) (*PinnedResult, error)
PinnedVaults loads pinned notes from each vault in order, notes by id within a vault, spending one budget across all of them.
type PinnedVault ¶ added in v0.10.16
PinnedVault is one index and the vault name its notes are tagged with. Vaults are read in the order given. One budget covers every vault.
type RecallConfig ¶
type RecallConfig struct {
Input string
Depth int
MinConfidence string
MaxNodes int
// IncludeDrafts lets a status:draft note be a neighbor. Off by default.
// The note the caller named stays the start of the traversal.
IncludeDrafts bool
}
RecallConfig holds parameters for a Recall operation.
type RecallEdge ¶
type RecallEdge struct {
SourceID string `json:"source_id"`
TargetID string `json:"target_id"`
EdgeType string `json:"edge_type"`
Confidence string `json:"confidence"`
}
RecallEdge describes a directed edge between two nodes in the result.
type RecallNode ¶
type RecallNode struct {
ID string `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
Distance int `json:"distance"`
EdgeFromParent *graph.TraverseEdge `json:"edge_from_parent,omitempty"`
Frontmatter map[string]interface{} `json:"frontmatter"`
}
RecallNode is an enriched graph node returned by Recall.
type RecallResult ¶
type RecallResult struct {
TargetID string `json:"target_id"`
Depth int `json:"depth"`
MaxNodes int `json:"max_nodes"`
MaxNodesReached bool `json:"max_nodes_reached"`
Nodes []RecallNode `json:"nodes"`
Edges []RecallEdge `json:"edges"`
}
RecallResult is the full output of a Recall operation.
func Recall ¶
func Recall(resolver *graph.Resolver, db *index.DB, cfg RecallConfig) (*RecallResult, error)
Recall resolves the input entity and returns an enriched subgraph neighbourhood. It resolves the input via the resolver, traverses the graph using BFS, and enriches each traversal node with type, title, and frontmatter from the database.
type ReciteConfig ¶ added in v0.8.0
type ReciteConfig struct {
// Type is the note type to enumerate ("arc").
Type string
// Budget is the total token ceiling. 0 means unbounded.
Budget int
// ExcerptTokens caps each note's contribution. 0 means whole bodies.
ExcerptTokens int
// IncludeDrafts recites a status:draft note. Off by default: a draft arc
// is a proposal, not identity, until its status changes.
IncludeDrafts bool
}
ReciteConfig selects the layer and bounds it.
type ReciteItem ¶ added in v0.8.0
type ReciteItem struct {
ID string `json:"id"`
Title string `json:"title"`
Excerpt string `json:"excerpt"`
Tokens int `json:"tokens"`
}
ReciteItem is one note rendered for recitation.
type ReciteResult ¶ added in v0.8.0
type ReciteResult struct {
Type string `json:"type"`
Total int `json:"total"`
Items []ReciteItem `json:"items"`
Omitted int `json:"omitted"`
OmittedIDs []string `json:"omitted_ids,omitempty"`
Tokens int `json:"tokens"`
Budget int `json:"budget"`
}
ReciteResult is the whole layer, plus an explicit account of what did not fit.
Omitted and OmittedIDs exist because a bulk loader that silently drops the tail is the same defect this feature fixes, wearing different clothes: the caller cannot tell "you have 27 arcs and here they are" from "you have 27 arcs and here are 9". Whoever reads this must be able to see the difference.
func Recite ¶ added in v0.8.0
func Recite(db *index.DB, cfg ReciteConfig) (*ReciteResult, error)
Recite returns every note of cfg.Type, ordered by id, excerpted and bounded.
Ordering is by id rather than by rank or mtime: an identity layer that arrives in a different order each session is a different thing arriving each session, and nothing downstream could be compared run to run.
func (*ReciteResult) Truncated ¶ added in v0.8.0
func (r *ReciteResult) Truncated() bool
Truncated reports whether the budget forced anything out.
type RelatedConfig ¶
type RelatedConfig struct {
Input string
Mode string // "mixed", "explicit", or "inferred"
// IncludeDrafts lets a status:draft note be listed. Off by default.
// The note the caller named is the target and is not filtered.
IncludeDrafts bool
}
RelatedConfig holds parameters for a Related operation.
type RelatedItem ¶
type RelatedItem struct {
ID string `json:"id"`
Type string `json:"type"`
Title string `json:"title"`
EdgeType string `json:"edge_type"`
Confidence string `json:"confidence"`
Origin string `json:"origin"`
Score float64 `json:"score,omitempty"`
}
RelatedItem is a single related note returned by Related.
type RelatedResult ¶
type RelatedResult struct {
TargetID string `json:"target_id"`
Mode string `json:"mode"`
Related []RelatedItem `json:"related"`
}
RelatedResult is the full output of a Related operation.
func Related ¶
func Related(resolver *graph.Resolver, db *index.DB, cfg RelatedConfig) (*RelatedResult, error)
Related resolves the input entity and returns directly connected notes, filtered by the given mode ("mixed", "explicit", or "inferred").
type Seed ¶ added in v0.9.11
Seed is a note to pack as context regardless of its graph distance from the target. Confidence is the caller's relevance band for it, carried through to the item so the reader can see why it is there.
type SummarizeConfig ¶
type SummarizeConfig struct {
NoteIDs []string
IncludeBody bool
MaxBodyLen int // max chars per note body (0 = full)
}
SummarizeConfig controls which notes to load and how much body text to include.
type SummarizeResult ¶
type SummarizeResult struct {
Sources []SummarizeSource `json:"sources"`
NoteCount int `json:"note_count"`
NotFound []string `json:"not_found,omitempty"`
}
SummarizeResult is the assembled output for agent consumption.
func Summarize ¶
func Summarize(db *index.DB, cfg SummarizeConfig) (*SummarizeResult, error)
Summarize loads frontmatter and optional body excerpts from the requested notes. It does not call an LLM — it assembles raw material for agent-driven synthesis.