Documentation
¶
Overview ¶
Package workspace provides a stateful domain session that owns the repository, graph, metamodel, and automation engine. It provides write-through operations that keep disk and in-memory state in sync, eliminating the dual-write pattern that consumers would otherwise duplicate.
Index ¶
- Variables
- func CountValidationsBySeverity(violations []ValidationViolation) (errors, warnings int)
- func EntityIDsFromViewResult(result *views.ViewResult) map[string]bool
- func IsValidationError(err error) bool
- func RewriteDocumentLinks(htmlContent, returnPath string) string
- type AnalysisSummary
- type AnalyzeOptions
- type AttachResult
- type AttachmentInfo
- type CardinalityViolation
- type ChangeEvent
- type ChangeOp
- type CreateOptions
- type CreateRelationOptions
- type CreateResult
- type DeleteResult
- type DocumentConfig
- type DocumentResult
- type DuplicateGroup
- type GCAttachmentsResult
- type GapResult
- type InitResult
- type MetamodelAccessor
- type MigrateDetection
- type MigrateFile
- type MigrateFileResult
- type MigrateResult
- type PathStep
- type PropertyError
- type RelationPropertyError
- type ScriptExecutor
- type TraceResult
- type UpdateResult
- type ValidateResult
- type ValidationError
- type ValidationFilter
- type ValidationViolation
- type WatchOptions
- type Workspace
- func Discover(startDir string, scriptExec ScriptExecutor) (*Workspace, error)
- func New(repo repository.Store, scriptExec ScriptExecutor) (*Workspace, error)
- func NewAfterInit(targetDir string) (*Workspace, error)
- func NewForTest(g *graph.Graph, meta *metamodel.Metamodel) *Workspace
- func NewWithGraph(repo repository.Store, meta *metamodel.Metamodel, g *graph.Graph, ...) *Workspace
- func (w *Workspace) AllEntities() []*model.Entity
- func (w *Workspace) AllRelations() []*model.Relation
- func (w *Workspace) AnalyzeAll(opts AnalyzeOptions) *AnalysisSummary
- func (w *Workspace) AttachFile(entityID, filePath, property string) (*AttachResult, error)
- func (w *Workspace) CheckCardinality(opts AnalyzeOptions) []CardinalityViolation
- func (w *Workspace) CleanupOrphanedTempFiles() (int, error)
- func (w *Workspace) Close() error
- func (w *Workspace) CreateEntity(entityType string, opts CreateOptions) (*model.Entity, *CreateResult, error)
- func (w *Workspace) CreateEntityLua(entityType, id string, props map[string]interface{}, content string) (*model.Entity, error)
- func (w *Workspace) CreateRelation(from, relType, to string, opts ...CreateRelationOptions) (*model.Relation, error)
- func (w *Workspace) CreateRelationLua(from, relType, to string) (*model.Relation, error)
- func (w *Workspace) DeleteEntity(entityType, id string, cascade bool) (*DeleteResult, error)
- func (w *Workspace) DeleteEntityLua(entityType, id string, cascade bool) error
- func (w *Workspace) DeleteRelation(from, relType, to string) error
- func (w *Workspace) DiscoverEntityTemplates(entityType string) ([]*markdown.EntityTemplate, error)
- func (w *Workspace) EntitiesByType(entityType string) []*model.Entity
- func (w *Workspace) EntityCount() int
- func (w *Workspace) EntityIDs() []string
- func (w *Workspace) ExecuteView(viewName, entryID string) (*views.ViewResult, error)
- func (w *Workspace) FS() storage.FS
- func (w *Workspace) FindDuplicates(opts AnalyzeOptions) []DuplicateGroup
- func (w *Workspace) FindGaps(opts AnalyzeOptions) []GapResult
- func (w *Workspace) FindOrphanedTempFiles() ([]string, error)
- func (w *Workspace) FindOrphans() []*model.Entity
- func (w *Workspace) FindOrphansWithScope(opts AnalyzeOptions) []*model.Entity
- func (w *Workspace) FindPath(from, to string) []PathStep
- func (w *Workspace) FormatEntity(entity *model.Entity, dryRun bool) (bool, error)
- func (w *Workspace) FormatRelation(relation *model.Relation, dryRun bool) (bool, error)
- func (w *Workspace) GCAttachments(dryRun bool) (*GCAttachmentsResult, error)
- func (w *Workspace) GenerateEntityTemplate(entityType, variant string, force bool) (bool, error)
- func (w *Workspace) GenerateID(entityType, prefix string) (string, error)
- func (w *Workspace) GenerateRelationTemplate(relationType string, force bool) (bool, error)
- func (w *Workspace) GetCachedDocument(entryID string, cfg DocumentConfig) *DocumentResult
- func (w *Workspace) GetEntity(id string) (*model.Entity, bool)
- func (w *Workspace) GetRelation(from, relType, to string) (*model.Relation, bool)
- func (w *Workspace) Graph() *graph.Graph
- func (w *Workspace) IncomingRelations(entityID string) []*model.Relation
- func (w *Workspace) ListAttachments(entityID string) ([]AttachmentInfo, error)
- func (w *Workspace) LoadViews() (*views.File, error)
- func (w *Workspace) Meta() *metamodel.Metamodel
- func (w *Workspace) OutgoingRelations(entityID string) []*model.Relation
- func (w *Workspace) Paths() *project.Context
- func (w *Workspace) PauseWatching()
- func (w *Workspace) RLock()
- func (w *Workspace) RUnlock()
- func (w *Workspace) ReadCacheFile(name string) ([]byte, error)
- func (w *Workspace) ReadProjectFile(name string) ([]byte, error)
- func (w *Workspace) Reload() (*model.SyncResult, error)
- func (w *Workspace) RenameEntity(entityType, oldID, newID string, dryRun bool) (*rename.Result, error)
- func (w *Workspace) RenderDocument(entryID string, cfg DocumentConfig) (*DocumentResult, error)
- func (w *Workspace) Repo() repository.Store
- func (w *Workspace) ResolveEntityType(typeName string) (string, *metamodel.EntityDef, error)
- func (w *Workspace) ResolveViewScope(viewName, entryID string) (map[string]bool, error)
- func (w *Workspace) ResumeWatching()
- func (w *Workspace) RunValidations(opts AnalyzeOptions) []ValidationViolation
- func (w *Workspace) RunValidationsFiltered(opts AnalyzeOptions, filters []ValidationFilter) []ValidationViolation
- func (w *Workspace) SaveCache() error
- func (w *Workspace) Search(words, phrases []string, limit int) ([]*model.Entity, []float64, error)
- func (w *Workspace) SearchSimple(query string, limit int) ([]*model.Entity, error)
- func (w *Workspace) StartWatching(opts WatchOptions) error
- func (w *Workspace) StopWatching()
- func (w *Workspace) Sync() (*model.SyncResult, error)
- func (w *Workspace) SyncLua() error
- func (w *Workspace) TraceFrom(entityID string, maxDepth int) *TraceResult
- func (w *Workspace) TraceTo(entityID string, maxDepth int) *TraceResult
- func (w *Workspace) UpdateEntity(entity, oldEntity *model.Entity) (*UpdateResult, error)
- func (w *Workspace) UpdateEntityLua(entity, oldEntity *model.Entity) error
- func (w *Workspace) UpdateRelation(from, relType, to string, opts CreateRelationOptions) (*model.Relation, error)
- func (w *Workspace) ValidateProperties(opts AnalyzeOptions) []PropertyError
- func (w *Workspace) ValidateRelationProperties() []RelationPropertyError
- func (w *Workspace) WriteCacheFile(name string, data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrHasRelations = fmt.Errorf("entity has relations; set cascade=true to delete")
ErrHasRelations is returned by DeleteEntity when cascade is false but the entity has relations.
Functions ¶
func CountValidationsBySeverity ¶
func CountValidationsBySeverity(violations []ValidationViolation) (errors, warnings int)
CountValidationsBySeverity returns counts of errors and warnings from violations.
func EntityIDsFromViewResult ¶
func EntityIDsFromViewResult(result *views.ViewResult) map[string]bool
EntityIDsFromViewResult extracts entity IDs from a view result.
func IsValidationError ¶
IsValidationError returns true if the error is a ValidationError.
func RewriteDocumentLinks ¶
RewriteDocumentLinks replaces edit:// and create:// URLs with actual form URLs. For edit links, the return URL includes the entity ID as a hash fragment for scroll preservation. For create links, query params are preserved and passed through to the form.
Types ¶
type AnalysisSummary ¶
type AnalysisSummary struct {
Orphans int
Duplicates int
Gaps int
Cardinality int
PropertyErrors int
ValidationErrors int
ValidationWarnings int
}
AnalysisSummary contains counts from all analysis types.
type AnalyzeOptions ¶
type AnalyzeOptions struct {
// Scope limits analysis to specific entity IDs. If nil, all entities are analyzed.
Scope map[string]bool
}
AnalyzeOptions configures analysis scope.
type AttachResult ¶
type AttachResult struct {
Path string
OriginalName string
Deduplicated bool // true if file already existed in store
}
AttachResult contains the outcome of attaching a file.
type AttachmentInfo ¶
type AttachmentInfo struct {
Property string
Path string
OriginalName string
ContentType string
Size int64
}
AttachmentInfo contains information about an attachment on an entity.
type CardinalityViolation ¶
type CardinalityViolation struct {
EntityID string
RelationType string
Constraint string // "min_outgoing", "max_outgoing", "min_incoming", "max_incoming"
Required int
Actual int
}
CardinalityViolation represents a cardinality constraint violation.
type ChangeEvent ¶
type ChangeEvent = repository.ChangeEvent
ChangeEvent is re-exported from repository so consumers don't need to import repository directly for watcher callback signatures.
type ChangeOp ¶
type ChangeOp = repository.ChangeOp
ChangeOp is re-exported from repository for the same reason as ChangeEvent.
type CreateOptions ¶
type CreateOptions struct {
ID string // empty = auto-generate
Prefix string // override default ID prefix (ignored when ID is set)
Properties map[string]interface{} // property values
Content string // markdown body
}
CreateOptions configures entity creation.
type CreateRelationOptions ¶
type CreateRelationOptions struct {
Properties map[string]interface{} // property values for the relation
Content string // markdown body content for the relation
}
CreateRelationOptions configures optional settings for relation creation.
type CreateResult ¶
type CreateResult struct {
AutomationWarnings []string
AutomationErrors []string
RelationsCreated []*model.Relation
EntitiesCreated []*model.Entity
}
CreateResult contains side-effects from entity creation.
type DeleteResult ¶
type DeleteResult struct {
RelationsDeleted int
}
DeleteResult contains info about what was deleted.
type DocumentConfig ¶
type DocumentConfig struct {
// View is the view name from views.yaml used to gather entities.
View string
// Command is the external render command. Placeholders:
// {id} - entry ID
// {id_lower} - lowercase entry ID
Command string
// Timeout is the command execution timeout. Defaults to 30s.
Timeout time.Duration
}
DocumentConfig defines how to render a document from an entry entity.
type DocumentResult ¶
type DocumentResult struct {
// HTML is the rendered HTML content.
HTML string
// ContentHash is the hash of source entities used for cache validation.
ContentHash string
// Entities contains all entities involved in the document (for dependency tracking).
Entities []*model.Entity
}
DocumentResult holds the result of rendering a document.
type DuplicateGroup ¶
DuplicateGroup represents entities with the same normalized title.
type GCAttachmentsResult ¶
type GCAttachmentsResult struct {
Removed []string // Paths that were (or would be) removed
Reclaimed int64 // Bytes reclaimed (or that would be reclaimed)
}
GCAttachmentsResult contains the outcome of garbage collecting attachments.
type InitResult ¶
InitResult contains information about what was created during initialization.
func Initialize ¶
func Initialize(targetDir string) (*InitResult, error)
Initialize creates a new rela project in the given directory. If targetDir is empty, it uses the current working directory. It creates the directory structure, writes a default metamodel, and optionally updates .gitignore.
func InitializeWithFS ¶
func InitializeWithFS(targetDir string, fs storage.FS) (*InitResult, error)
InitializeWithFS creates a new rela project using the provided filesystem. This is useful for testing.
type MetamodelAccessor ¶
type MetamodelAccessor interface {
HasEntityType(entityType string) bool
HasValidationRule(ruleName string) bool
}
MetamodelAccessor provides read-only access to metamodel for validation. This interface is used by the validate command to check filter values.
type MigrateDetection ¶
type MigrateDetection struct {
File MigrateFile
Migrations []migration.DetectionResult
}
MigrateDetection represents a detected migration for a file.
func DetectMigrations ¶
func DetectMigrations(startDir string) ([]MigrateDetection, error)
DetectMigrations checks for pending migrations in project files. If startDir is empty, it uses the current working directory.
func DetectMigrationsWithFS ¶
func DetectMigrationsWithFS(startDir string, fs storage.FS) ([]MigrateDetection, error)
DetectMigrationsWithFS checks for pending migrations using the provided filesystem.
type MigrateFile ¶
MigrateFile represents a file that can be migrated.
type MigrateFileResult ¶
type MigrateFileResult struct {
File MigrateFile
Results []migration.Result
Error error
}
MigrateFileResult contains the result for a single file.
type MigrateResult ¶
type MigrateResult struct {
FilesUpdated int
TotalMigrations int
FileResults []MigrateFileResult
}
MigrateResult contains the outcome of applying migrations.
func Migrate ¶
func Migrate(startDir string) (*MigrateResult, error)
Migrate applies pending migrations to project files. If startDir is empty, it uses the current working directory.
func MigrateWithFS ¶
func MigrateWithFS(startDir string, fs storage.FS) (*MigrateResult, error)
MigrateWithFS applies migrations using the provided filesystem.
type PropertyError ¶
type PropertyError struct {
EntityID string
EntityType string
Errors []*metamodel.ValidationError
}
PropertyError represents a property validation error.
type RelationPropertyError ¶
type RelationPropertyError struct {
RelationKey string // "from--type--to"
RelationType string
Errors []*metamodel.ValidationError
}
RelationPropertyError represents a relation property validation error.
type ScriptExecutor ¶
type ScriptExecutor interface {
// ExecuteCode runs inline script code with entity context.
ExecuteCode(code string, ctx metamodel.ScriptContext) error
// ExecuteFile runs a script file from the scripts/ directory.
ExecuteFile(path string, ctx metamodel.ScriptContext) error
}
ScriptExecutor runs scripts with entity context. This follows dependency inversion: workspace defines the interface it needs, script package implements it. This keeps workspace independent of specific script languages (Lua, etc.).
The executor is stateless - all context is passed at execution time via metamodel.ScriptContext. This avoids circular dependencies: workspace can be created with a script engine, and the engine receives workspace access only when executing scripts.
For production, pass script.NewEngine(). For tests, pass NopScriptExecutor.
var NopScriptExecutor ScriptExecutor = nopScriptExecutor{}
NopScriptExecutor is a no-op implementation of ScriptExecutor for tests that don't trigger Lua automations. It panics if actually called, making it obvious when a test unexpectedly triggers Lua execution.
type TraceResult ¶
type TraceResult = model.TraceResult
TraceResult is re-exported from model for consumers.
type UpdateResult ¶
type UpdateResult struct {
AutomationWarnings []string
AutomationErrors []string
RelationsCreated []*model.Relation
EntitiesCreated []*model.Entity
}
UpdateResult contains side-effects from entity update.
type ValidateResult ¶
type ValidateResult struct {
MetamodelValid bool
MetamodelError error
Metamodel *metamodel.Metamodel // nil if validation failed
DataEntryValid bool
DataEntryError error
DataEntrySkipped bool // true if file doesn't exist
}
ValidateResult contains the outcome of validating project configuration.
func Validate ¶
func Validate(startDir string) (*ValidateResult, error)
Validate validates project configuration files (metamodel.yaml, data-entry.yaml) without loading the full graph. Use this for the `rela validate` command. If startDir is empty, it uses the current working directory.
func ValidateWithFS ¶
func ValidateWithFS(startDir string, fs storage.FS) (*ValidateResult, error)
ValidateWithFS validates using the provided filesystem.
func (*ValidateResult) HasErrors ¶
func (r *ValidateResult) HasErrors() bool
HasErrors returns true if any validation failed.
type ValidationError ¶
type ValidationError struct {
Errors []*metamodel.ValidationError
}
ValidationError wraps multiple validation errors from the metamodel.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
type ValidationFilter ¶
type ValidationFilter struct {
RuleName string // Exact rule name match (empty = no filter)
EntityType string // Entity type filter (empty = no filter)
}
ValidationFilter specifies which validation rules to run.
type ValidationViolation ¶
type ValidationViolation = validation.Violation
ValidationViolation is re-exported from the validation package.
type WatchOptions ¶
type WatchOptions struct {
// ExtraFiles lists additional files to watch (e.g., data-entry.yaml).
ExtraFiles []string
// ExtraDirs lists additional directories to watch (e.g., metamodel/).
ExtraDirs []string
// OnReload is called after workspace has reloaded metamodel and graph.
// Consumers use this for side-effects (SSE broadcast, MCP notifications, etc.).
OnReload func(events []ChangeEvent)
}
WatchOptions configures the file watcher.
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace is a stateful domain session that ties together the repository (persistence), graph (in-memory query), metamodel (schema), and automation engine. All write operations go through Workspace so that disk and memory stay in sync.
func Discover ¶
func Discover(startDir string, scriptExec ScriptExecutor) (*Workspace, error)
Discover discovers a project from the given start directory and creates a workspace with the given script executor. If startDir is empty, it uses the current working directory.
For production use, pass script.NewEngine() for Lua support. For tests, pass NopScriptExecutor.
func New ¶
func New(repo repository.Store, scriptExec ScriptExecutor) (*Workspace, error)
New creates a workspace from a repository with a script executor. It loads the metamodel, initializes the graph (from cache or by syncing from disk), and sets up the automation engine.
For production use, pass script.NewEngine() for Lua support. For tests, pass NopScriptExecutor.
func NewAfterInit ¶
NewAfterInit creates a workspace for a newly initialized project. Use this after Initialize() when you need a workspace immediately. Uses NopScriptExecutor since newly initialized projects don't have Lua automations configured.
func NewForTest ¶
NewForTest creates a minimal workspace for testing. It has no repository, so write operations will panic. Use this for unit tests that only need to query the graph. It initializes a search index with all entities.
func NewWithGraph ¶
func NewWithGraph( repo repository.Store, meta *metamodel.Metamodel, g *graph.Graph, scriptExec ...ScriptExecutor, ) *Workspace
NewWithGraph creates a workspace with a pre-populated graph. Use this when the caller has already loaded the metamodel and synced the graph.
The optional scriptExec parameter enables Lua automation actions. If not provided, defaults to NopScriptExecutor (suitable for tests). Pass a script.Engine for production.
func (*Workspace) AllEntities ¶
AllEntities returns all entities in the workspace.
func (*Workspace) AllRelations ¶
AllRelations returns all relations in the workspace.
func (*Workspace) AnalyzeAll ¶
func (w *Workspace) AnalyzeAll(opts AnalyzeOptions) *AnalysisSummary
AnalyzeAll runs all analyses and returns a summary of counts.
func (*Workspace) AttachFile ¶
func (w *Workspace) AttachFile(entityID, filePath, property string) (*AttachResult, error)
AttachFile attaches a file to an entity's file property. If property is empty, it uses the first file-type property defined for the entity type. The file is stored in the content-addressable attachment store and the entity is updated.
func (*Workspace) CheckCardinality ¶
func (w *Workspace) CheckCardinality(opts AnalyzeOptions) []CardinalityViolation
CheckCardinality checks all cardinality constraints, filtered by scope.
func (*Workspace) CleanupOrphanedTempFiles ¶
CleanupOrphanedTempFiles removes leftover .new temp files.
func (*Workspace) CreateEntity ¶
func (w *Workspace) CreateEntity(entityType string, opts CreateOptions) (*model.Entity, *CreateResult, error)
CreateEntity generates an ID (unless provided), applies templates and defaults, validates, writes to disk, updates the graph, and runs automation.
func (*Workspace) CreateEntityLua ¶
func (w *Workspace) CreateEntityLua( entityType, id string, props map[string]interface{}, content string, ) (*model.Entity, error)
CreateEntityLua creates an entity and returns it without the result struct. This satisfies lua.WorkspaceInterface using primitive types to avoid import cycles.
func (*Workspace) CreateRelation ¶
func (w *Workspace) CreateRelation(from, relType, to string, opts ...CreateRelationOptions) (*model.Relation, error)
CreateRelation validates both endpoints exist, checks for duplicates, validates against the metamodel, writes to disk, and updates the graph.
func (*Workspace) CreateRelationLua ¶
CreateRelationLua creates a relation without options. This satisfies lua.WorkspaceInterface.
func (*Workspace) DeleteEntity ¶
func (w *Workspace) DeleteEntity(entityType, id string, cascade bool) (*DeleteResult, error)
DeleteEntity removes an entity and optionally cascades to its relations.
func (*Workspace) DeleteEntityLua ¶
DeleteEntityLua deletes an entity without returning the result struct. This satisfies lua.WorkspaceInterface.
func (*Workspace) DeleteRelation ¶
DeleteRelation removes a relation from disk and the graph.
func (*Workspace) DiscoverEntityTemplates ¶
func (w *Workspace) DiscoverEntityTemplates(entityType string) ([]*markdown.EntityTemplate, error)
DiscoverEntityTemplates returns all templates (including variants) for an entity type.
func (*Workspace) EntitiesByType ¶
EntitiesByType returns all entities of the given type.
func (*Workspace) EntityCount ¶
EntityCount returns the total number of entities.
func (*Workspace) ExecuteView ¶
func (w *Workspace) ExecuteView(viewName, entryID string) (*views.ViewResult, error)
ExecuteView executes a named view and returns the result. Returns an error if views.yaml cannot be loaded or the view doesn't exist.
func (*Workspace) FS ¶
FS returns the underlying filesystem for operations that need direct file access (e.g., attachment store, writing output files).
func (*Workspace) FindDuplicates ¶
func (w *Workspace) FindDuplicates(opts AnalyzeOptions) []DuplicateGroup
FindDuplicates returns groups of entities with similar titles, filtered by scope.
func (*Workspace) FindGaps ¶
func (w *Workspace) FindGaps(opts AnalyzeOptions) []GapResult
FindGaps returns gaps in ID sequences, filtered by scope. Excludes entity types with manual (string) IDs.
func (*Workspace) FindOrphanedTempFiles ¶
FindOrphanedTempFiles returns paths of leftover .new temp files.
func (*Workspace) FindOrphans ¶
FindOrphans returns entities with no incoming or outgoing relations.
func (*Workspace) FindOrphansWithScope ¶
func (w *Workspace) FindOrphansWithScope(opts AnalyzeOptions) []*model.Entity
FindOrphansWithScope returns entities with no relations, filtered by scope.
func (*Workspace) FormatEntity ¶
FormatEntity checks if an entity file needs formatting and optionally writes the formatted version. Returns true if the file was (or would be) modified.
func (*Workspace) FormatRelation ¶
FormatRelation checks if a relation file needs formatting and optionally writes the formatted version. Returns true if the file was (or would be) modified.
func (*Workspace) GCAttachments ¶
func (w *Workspace) GCAttachments(dryRun bool) (*GCAttachmentsResult, error)
GCAttachments removes unreferenced attachment files from the store. If dryRun is true, it returns what would be removed without actually removing.
func (*Workspace) GenerateEntityTemplate ¶
GenerateEntityTemplate generates a template file for the given entity type.
func (*Workspace) GenerateID ¶
GenerateID generates the next ID for the given entity type. If prefix is non-empty it is used instead of the default prefix from the metamodel.
func (*Workspace) GenerateRelationTemplate ¶
GenerateRelationTemplate generates a template file for the given relation type.
func (*Workspace) GetCachedDocument ¶
func (w *Workspace) GetCachedDocument(entryID string, cfg DocumentConfig) *DocumentResult
GetCachedDocument returns a cached document if available and still valid. Returns nil if the cache is missing, stale, or on any error.
func (*Workspace) GetRelation ¶
GetRelation returns a relation by its endpoints and type.
func (*Workspace) IncomingRelations ¶
IncomingRelations returns all relations pointing to the given entity.
func (*Workspace) ListAttachments ¶
func (w *Workspace) ListAttachments(entityID string) ([]AttachmentInfo, error)
ListAttachments returns all attachments for an entity.
func (*Workspace) OutgoingRelations ¶
OutgoingRelations returns all relations originating from the given entity.
func (*Workspace) PauseWatching ¶
func (w *Workspace) PauseWatching()
PauseWatching temporarily suppresses file change events.
func (*Workspace) RLock ¶
func (w *Workspace) RLock()
RLock acquires a read lock on the workspace. Consumers that need consistent reads across multiple graph queries (e.g., HTTP handlers) should hold this lock for the duration of the request.
func (*Workspace) ReadCacheFile ¶
ReadCacheFile reads a file from the .rela cache directory.
func (*Workspace) ReadProjectFile ¶
ReadProjectFile reads a file relative to the project root.
func (*Workspace) Reload ¶
func (w *Workspace) Reload() (*model.SyncResult, error)
Reload reloads the metamodel and re-syncs the graph from disk. This is called automatically by the file watcher but is also available for programmatic use (after migration, in tests, etc.).
func (*Workspace) RenameEntity ¶
func (w *Workspace) RenameEntity(entityType, oldID, newID string, dryRun bool) (*rename.Result, error)
RenameEntity renames an entity, updating all references in relations.
func (*Workspace) RenderDocument ¶
func (w *Workspace) RenderDocument(entryID string, cfg DocumentConfig) (*DocumentResult, error)
RenderDocument renders a document by executing the configured command. Uses singleflight to dedupe concurrent requests. Caches the result to disk.
func (*Workspace) Repo ¶
func (w *Workspace) Repo() repository.Store
Repo returns the underlying repository for low-level operations not wrapped by Workspace (e.g., FS access, Watch).
func (*Workspace) ResolveEntityType ¶
ResolveEntityType resolves a type name (alias, plural) to its canonical name and definition.
func (*Workspace) ResolveViewScope ¶
ResolveViewScope resolves a view and entry ID to a set of entity IDs. Returns nil if viewName is empty (no filtering).
func (*Workspace) ResumeWatching ¶
func (w *Workspace) ResumeWatching()
ResumeWatching re-enables file change events after PauseWatching.
func (*Workspace) RunValidations ¶
func (w *Workspace) RunValidations(opts AnalyzeOptions) []ValidationViolation
RunValidations executes all custom validation rules from the metamodel, filtered by scope.
func (*Workspace) RunValidationsFiltered ¶
func (w *Workspace) RunValidationsFiltered(opts AnalyzeOptions, filters []ValidationFilter) []ValidationViolation
RunValidationsFiltered executes custom validation rules matching the given filters. Multiple filters are combined with OR (union of matching rules). If a filter has both RuleName and EntityType empty, all rules match.
func (*Workspace) Search ¶
Search performs a full-text search and returns matching entities with scores. words are OR'd together with fuzzy matching; phrases must all match exactly.
func (*Workspace) SearchSimple ¶
SearchSimple performs a simple text search (convenience method).
func (*Workspace) StartWatching ¶
func (w *Workspace) StartWatching(opts WatchOptions) error
StartWatching begins watching for file changes. On each change the workspace reloads the metamodel, re-syncs the graph, saves the cache, and then calls OnReload.
func (*Workspace) StopWatching ¶
func (w *Workspace) StopWatching()
StopWatching stops the file watcher.
func (*Workspace) Sync ¶
func (w *Workspace) Sync() (*model.SyncResult, error)
Sync clears the graph and reloads all entities and relations from disk.
func (*Workspace) SyncLua ¶
SyncLua is a Lua-friendly wrapper for Sync that doesn't return the result. This satisfies lua.WorkspaceInterface without importing result types.
func (*Workspace) TraceFrom ¶
func (w *Workspace) TraceFrom(entityID string, maxDepth int) *TraceResult
TraceFrom traces all paths from the given entity (outgoing direction).
func (*Workspace) TraceTo ¶
func (w *Workspace) TraceTo(entityID string, maxDepth int) *TraceResult
TraceTo traces all paths to the given entity (incoming direction).
func (*Workspace) UpdateEntity ¶
func (w *Workspace) UpdateEntity(entity, oldEntity *model.Entity) (*UpdateResult, error)
UpdateEntity validates and writes an existing entity, runs automation, and updates the graph.
func (*Workspace) UpdateEntityLua ¶
UpdateEntityLua updates an entity without returning the result struct. This satisfies lua.WorkspaceInterface.
func (*Workspace) UpdateRelation ¶
func (w *Workspace) UpdateRelation(from, relType, to string, opts CreateRelationOptions) (*model.Relation, error)
UpdateRelation updates properties on an existing relation.
func (*Workspace) ValidateProperties ¶
func (w *Workspace) ValidateProperties(opts AnalyzeOptions) []PropertyError
ValidateProperties validates entity properties against the metamodel, filtered by scope.
func (*Workspace) ValidateRelationProperties ¶
func (w *Workspace) ValidateRelationProperties() []RelationPropertyError
ValidateRelationProperties validates relation properties against the metamodel.