paths

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package paths provides canonical helpers for:

  • Converting between vault-relative markdown file paths (e.g. "objects/people/freya.md") and Raven object IDs (e.g. "people/freya")
  • Validating paths are within the vault (security)
  • Parsing embedded object IDs (e.g. "file#section")

It also centralizes directory-root handling (objects/pages roots) so that parsing, CLI operations, watching, and resolution stay consistent.

Index

Constants

View Source
const AgentInstructionsFilename = "AGENTS.md"

AgentInstructionsFilename is the vault agent instructions filename.

View Source
const MDExtension = ".md"

MDExtension is the markdown file extension.

View Source
const SchemaFilename = "schema.yaml"

SchemaFilename is the vault schema filename.

Variables

View Source
var ErrPathOutsideVault = errors.New("path is outside vault")

ErrPathOutsideVault is returned when a path is outside the vault.

Functions

func AgentInstructionsPath

func AgentInstructionsPath(vaultPath string) string

AgentInstructionsPath returns the absolute path to AGENTS.md in a vault.

func CandidateFilePaths

func CandidateFilePaths(ref, objectsRoot, pagesRoot string) []string

CandidateFilePaths returns vault-relative markdown paths to try for a reference.

It always includes the "literal" interpretation (ref + ".md" after stripping any ".md" suffix), plus rooted interpretations if roots are configured.

func EnsureMDExtension

func EnsureMDExtension(p string) string

EnsureMDExtension adds .md extension if not already present.

func FilePathToObjectID

func FilePathToObjectID(filePath, objectsRoot, pagesRoot string) string

FilePathToObjectID converts a vault-relative file path to an object ID.

It: - strips a trailing ".md" - normalizes path separators - strips the configured objects/pages root prefixes (objects first, then pages)

func HasMDExtension

func HasMDExtension(p string) bool

HasMDExtension returns true if the path ends with .md.

func IsProtectedRelPath

func IsProtectedRelPath(relPath string, extraPrefixes []string) bool

IsProtectedRelPath returns true if relPath (vault-relative) is protected.

extraPrefixes are additional user-configured protected prefixes (vault-relative). They are treated as directory prefixes (normalized with NormalizeDirRoot).

func NormalizeDirRoot

func NormalizeDirRoot(root string) string

NormalizeDirRoot normalizes a directory root to have: - no leading slash - exactly one trailing slash (unless empty)

Examples: - "/objects/" -> "objects/" - "objects" -> "objects/" - "" -> ""

func ObjectIDToFilePath

func ObjectIDToFilePath(objectID, typeName, objectsRoot, pagesRoot string) string

ObjectIDToFilePath converts an object ID to a vault-relative markdown file path.

If roots are configured, typeName is used to decide whether to prefix with pagesRoot or objectsRoot: - typeName == "" or "page" -> pagesRoot (falls back to objectsRoot if pagesRoot is empty) - otherwise -> objectsRoot

If the objectID already includes a configured root prefix, this function will not add another prefix.

func ParseEmbeddedID

func ParseEmbeddedID(id string) (fileID, fragment string, isEmbedded bool)

ParseEmbeddedID parses an object ID that may contain an embedded fragment. For IDs like "file#section", it returns (fileID, fragment, true). For IDs without a fragment, it returns (id, "", false).

This is the canonical function for parsing embedded object IDs. Use this instead of manually calling strings.SplitN(id, "#", 2).

func SchemaPath

func SchemaPath(vaultPath string) string

SchemaPath returns the absolute path to schema.yaml in a vault.

func ShortNameFromID

func ShortNameFromID(id string) string

ShortNameFromID extracts the short name from an object ID. For "people/freya" -> "freya" For "daily/2025-02-01#standup" -> "standup"

func TrimMDExtension

func TrimMDExtension(p string) string

TrimMDExtension removes the .md extension if present.

func ValidateWithinVault

func ValidateWithinVault(vaultPath, targetPath string) error

ValidateWithinVault checks that a target path is within the vault directory. Returns an error if the path would escape the vault (security check).

This function: - Resolves both paths to absolute paths - Evaluates symlinks for security - Handles paths that don't exist yet by checking parent directories

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL