workspace

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package workspace confines filesystem access to a root directory.

Index

Constants

View Source
const Namespace = ".mivia"

Namespace is the tool-scoped directory mivia owns beneath a root. Under a workspace root it holds project control and runtime files; under the user's home directory it holds user-level config and env files.

It is deliberately tool-scoped. The generic name mivia used before this belongs to no tool in particular, so claiming it collided with every other agent that assumed the same convention and gave users no way to tell whose files were whose. The directory is ordinary workspace content, readable and writable through the normal file tools like any other path.

Nothing outside this file may name a namespace directory. Resolving through one place is what keeps the name changeable and keeps a second convention from growing back a call site at a time.

Variables

This section is empty.

Functions

func AgentsDir

func AgentsDir(root string) string

AgentsDir holds workspace agent definitions as <name>.md under .agents/agents/.

func AgentsPath

func AgentsPath(root string, elem ...string) string

AgentsPath joins elem beneath the project's .agents/ directory in root. Workspace skills live under .agents/skills/ so the development surface (skills, subagent roles, memories, rules, doctrines) stays together and is editable without touching the binary's own runtime namespace. The remaining runtime state (sessions, runs, worktrees, memory, hooks, policies, workflow definitions, agent role TOMLs) keeps living under Namespace.

func ContextStorePath

func ContextStorePath(root string) string

ContextStorePath holds the always-on durable context checkpoint database for a specific workspace root. Callers that need the default install-wide store should use GlobalContextStorePath instead; this stays root-scoped for callers (workflow runs) that require per-workspace isolation.

func GlobalContextStorePath

func GlobalContextStorePath(root string) string

GlobalContextStorePath is the default durable chat/session store shared by every workspace on the machine, so a fresh install already has one history instead of a separate database per project directory. Sessions stay isolated inside this shared file by workspace ID (contextWorkspaceID), the same mechanism that lets managed worktrees share a store safely. An unavailable home directory falls back to root-scoped ContextStorePath so the caller still gets a usable path.

func LongPath

func LongPath(path string) string

LongPath returns path with every Windows short (8.3) name component expanded to its long form. On platforms without short names it returns the path unchanged.

Windows path APIs and git resolve short names to their long form, so a canonicality check that compares a raw path with its resolved form would reject every short-name path as non-canonical even though it names the same directory. Both sides of such a comparison must use the same rendering, which is what LongPath provides.

func MemoryDBPath

func MemoryDBPath(root string) string

MemoryDBPath is the default project-scoped memory database (plan 68). A repo owner may point [memory] store_path at a tracked path instead and commit memories with the repository.

func NamespacePath

func NamespacePath(root string, elem ...string) string

NamespacePath joins elem beneath the namespace directory in root. An empty root resolves relative to the process working directory.

func OrgMemoryDBPath

func OrgMemoryDBPath() string

OrgMemoryDBPath is the user-level org-scoped memory database. An unavailable home directory yields an empty path so callers can disable the org store.

func SameExistingPath

func SameExistingPath(a, b string) (bool, error)

SameExistingPath reports whether two existing paths name the same file.

func SessionsDir

func SessionsDir(root string) string

SessionsDir holds persisted chat sessions.

func SkillsDir

func SkillsDir(root string) string

SkillsDir holds workspace skill definitions as <name>/SKILL.md. Skills live under the project's .agents/skills/ directory so the development surface is editable as ordinary workspace content and shares no path with the binary's own runtime namespace (.mivia).

func UserHomeDir

func UserHomeDir() (string, error)

UserHomeDir returns the user-home directory. HOME is a cross-platform override for tests and portable automation.

func UserSkillsDir

func UserSkillsDir() string

UserSkillsDir holds user-level skill definitions in the user's own .mivia home namespace (a sibling, not a child, of the project .agents/ surface). An unavailable home directory yields an empty path so callers can warn and continue without treating optional user customization as a startup failure.

func WorktreesDir

func WorktreesDir(repoRoot string) string

WorktreesDir holds git worktree checkouts managed by mivia.

Types

type Root

type Root struct {
	// Abs is the absolute, cleaned, symlink-evaluated root path.
	Abs string

	// LexicalAbs is the absolute, cleaned root path exactly as the caller
	// named it, BEFORE symlink evaluation; the blocklist's lexical check
	// derives workspace-relative names from it so an absolute path spelled
	// through a symlink alias of the root maps to the same relative name as
	// the direct spelling.
	LexicalAbs string

	// Unrestricted lifts the workspace escape check: file tools may resolve
	// paths anywhere on the filesystem, not only under Abs. Set only by the
	// operator-level `mivia chat --full-disk` flag (OpenFullDisk) - never by
	// workspace config, so a repository cannot grant itself full disk access.
	// The operator-invocation-only provenance is the security property; keep
	// it that way.
	Unrestricted bool
}

Root is a resolved workspace directory.

func Open

func Open(rootPath string) (*Root, error)

Open resolves rootPath (default ".") to an absolute workspace root.

func OpenFullDisk

func OpenFullDisk(rootPath string) (*Root, error)

OpenFullDisk resolves rootPath like Open but sets Unrestricted, allowing file tools to operate anywhere on the filesystem. Must only be called when the operator explicitly requested full disk access (e.g. --full-disk flag), never from workspace config.

func (*Root) LexicalRel

func (r *Root) LexicalRel(userPath string) (string, error)

LexicalRel returns the clean workspace-relative form of userPath without resolving symlinks. Rel reports where a request lands; LexicalRel reports the path the caller named, so a deny list can refuse a blocked name even when an in-workspace symlink would redirect the write elsewhere; a name that cannot be expressed as a workspace-relative path is an error and callers treat that as denied (fail closed).

func (*Root) Rel

func (r *Root) Rel(absPath string) string

Rel returns a path relative to the workspace for display.

func (*Root) Resolve

func (r *Root) Resolve(userPath string) (string, error)

Resolve maps a user path (relative or absolute) into the workspace. Rejects escapes via .. or symlinks outside the root.

Jump to

Keyboard shortcuts

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