project library

A Wayfinder project on disk: its bundles, Profile resolution and selection, validation from that selection, and the graph projection.

The wayfinder command and MCP server are a shell over this library. It needs dart:io and, on POSIX systems, dart:ffi for its file lock. It runs Git only through a GitRunner, downloads nothing else, and writes only wayfinder.lock, Profile skills, --fix output, its data directory, and wayfinder.json when a host's relock edits it. A host keeps all okf bundle I/O of one process on one isolate, because okf's bundle lock does not exclude isolates (ADR-0018). The resolver parses each Profile package on a short-lived isolate of its own, so a package whose rule tests stall fails rather than hangs.

Given a project root, discovery and binding read nothing above it; the command opts into its search of the working directory's ancestors with searchAncestors: true.

import 'dart:io';

import 'package:wayfinder/project.dart';

final project = await WayfinderProject.discover(Directory('/work/app'));
final resolver = WayfinderProfileResolver(
  dataDirectory: WayfinderDataDirectory.resolve(),
);
for (final bundle in project.bundles) {
  final result = await validateWithProfileSources(
    bundle.root,
    projectRoot: project.root,
    resolver: resolver,
  );
  print('${bundle.name}: ${result.gate.wireValue}');
}

Classes

GitProcess
A Git process a GitProcessStarter started for runGit.
GitResult
A finished Git command. stdout keeps Git's bytes, because a blob is not text; text decodes them as UTF-8.
KnowledgeMetadataFilter
Deterministic frontmatter eligibility, independent of retrieval scores. Values within each set use OR, except requiredTags, which uses AND. Different fields combine with AND. Identifiers are exact and case-sensitive; title/description containment is literal and case-insensitive.
LockedPackage
One package as wayfinder get pinned it. extendsId names another entry of the same lock, so the lock stays flat however deep a chain is.
MaterializedSkill
A Profile skill as get left it in the project.
ProfileBindingStatus
One binding of ProfileResolutionStatus: the Profile wayfinder.json names under id, for the bundles it appliesTo, and its state.
ProfileFetch
One Git fetch a resolution made into the Profile cache: git as the configuration or a package spells it, location as Git reached it (WayfinderProfileSource.locationOf), and the ref it was looking for, or null for the source's default branch.
ProfileLocalCopy
Whether a chain member's local copy is on this machine, as WayfinderProfileResolver.status finds it offline: the mirror of its source and its package file at the locked commit, both in the Profile cache.
ProfileLock
wayfinder.lock: every package a project's Profiles need, one revision per Profile id, keyed by id.
ProfileLockChange
What would change in wayfinder.lock, and why, when resolving cannot keep it as written: ProfileBindingStatus.lockChange offline, and ProfileLockChangeRequiredException.change once a locked-only plan refuses.
ProfileRelockResult
What WayfinderProfileResolver.relock wrote: the edited wayfinder.json and the lock for it, which pins the same packages.
ProfileResolutionPlan
What get would write, from WayfinderProfileResolver.plan. Planning fetches into the Profile cache when a ref must move but writes nothing in the project; WayfinderProfileResolver.apply writes it, and refuses when the configuration, lock or cache it read has changed since.
ProfileResolutionResult
ProfileResolutionStatus
Where every Profile of a project stands on this machine, from WayfinderProfileResolver.status: one ProfileBindingStatus per wayfinder.json binding, in id order.
ProfileSkillDirectory
One project directory that a Profile's skill installs into, under one of ProfileSkills.roots, and its state.
ProfileSkills
The project's copies of Profile skills. Each Profile owns the directory named by its id under each agent root, so no two Profiles share a write. Only a directory holding marker for the id its name claims is ever replaced or removed; any other directory belongs to the user.
ProjectBundle
A configured bundle: its folder name, its project-relative path, which prefixes citations, and its canonical root.
WayfinderCancellation
Asks a long operation to stop. An operation checks isCancelled between steps and stops a running child process when whenCancelled completes; it then throws WayfinderException.cancelled. Cancelling is not a rollback: what an operation already finished stays finished.
WayfinderCancellationController
A WayfinderCancellation its owner cancels by calling cancel.
WayfinderDataDirectory
Where Wayfinder keeps per-user state: Profile sources and their locks under profiles/, project locks under projects/, and the retrieval library's indexes. Everything there is derived and can be rebuilt.
WayfinderFileLock
An advisory exclusive lock on a file that holds across processes and across the isolates of one process.
WayfinderGraphResult
A bundle's graph, or the load findings that refused it.
WayfinderProfileResolver
Resolves Git Profile sources, persists their lock metadata, and selects a bundle's Profile from them.
WayfinderProject
A project and the bundles it configures. Discovery reads existing Profile application paths; it never fetches Profile sources.
WayfinderQuery
A deterministic, read-only selection of whole OKF concepts, not passages. JSON is the same contract used by saved definitions, CLI and MCP.
WayfinderQueryResult
Versioned table/group data; no source body is copied into the result.

Enums

ProfileBindingState
Where one wayfinder.json binding's Profile stands on this machine, as WayfinderProfileResolver.status reads it offline. Each state is what WayfinderProfileResolver.select does for the binding's bundles, and each but resolved is a reason it selects nothing.
ProfileFetchKind
How a resolution reached the network for a Profile source.
ProfileLockChangeKind
Why resolving would change wayfinder.lock: the kind of the project library's ProfileLockChange, and EngineDiagnostic.lockChange for a diagnostic that reports one.
ProfileSkillDirectoryState
Where one directory of a Profile skill stands, as ProfileSkills.inspect reads it from the marker: what get would do with it when it installs the locked revision.

Constants

wayfinderGitMaxOutputBytes → const int
The most stdout bytes runGit keeps by default, 64 MiB: far more than a Profile package or skill file, and a bound on what a hostile source can make it hold. A command that writes more is stopped.
wayfinderGitOptions → const List<String>
The configuration runGit puts before every command: no hooks from a template or global core.hooksPath, no filesystem monitor, and no ext:: transport, which runs an arbitrary command named by a source URL.
wayfinderGitRemoteSubcommands → const Set<String>
The Git subcommands that may reach a remote, and so may run SSH: runGit reads core.sshCommand before each.
wayfinderGitTimeout → const Duration
How long runGit lets a command run without writing any output before it stops the command. A clone that reports progress runs as long as it keeps reporting.
wayfinderGraphOutputs → const List<String>
Formats okf graph already emits. mermaid and DOT are text for a preview.
wayfinderLinkFields → const List<OkfLinkField>
The typed link fields Wayfinder projects beside okf's graph and follows in search: the engine's relationships key (guide §5.5).
wayfinderQueryColumns → const List<String>
Project query columns. Identity is always returned separately.
wayfinderQuerySortFields → const List<String>

Properties

wayfinderGraphInput → ObjectSchema
The graph query a host tool accepts, as JSON: optional types, path_prefixes and resolutions, the arguments of projectWayfinderGraph.
final
wayfinderQueryInput → ObjectSchema
Closed MCP/JSON input; semantic constraints are checked by the same query parser as Dart and CLI. Exactly one query or saved ID is required.
final

Functions

discoverWayfinderQueryBundles(Directory workingDirectory, {String? explicitPath, String? bundleName}) → Future<List<ProjectBundle>>
Selects exactly one explicit bundle, or the project's configured scope.
explicitBundlePrefix(Directory workingDirectory, String bundleRoot) → Future<String>
The citation prefix of an explicitly selected bundle bundleRoot when launched from workingDirectory: its path relative to the enclosing project, or to workingDirectory, with a trailing /; empty when the bundle is outside both.
gitMayReachRemote(List<String> arguments) → bool
Whether the Git command line arguments may reach a remote: its gitSubcommand is one of wayfinderGitRemoteSubcommands.
gitSubcommand(List<String> arguments) → String?
The subcommand of the Git command line arguments: its first argument that is neither a global option nor the value of one, such as clone in -c protocol.version=2 clone <url>. Null when it names none.
loadWayfinderSavedQuery(Directory workingDirectory, List<ProjectBundle> bundles, String id) → Future<WayfinderQuery>
Loads a local versioned query in the project that contains every selected bundle. Definitions can never select roots or execute code.
projectWayfinderGraph(String bundle, {Iterable<String> types = const [], Iterable<String> pathPrefixes = const [], Iterable<String> resolutions = const []}) → Future<WayfinderGraphResult>
The live projection of OkfGraph.fromBundle for bundle, filtered as okf graph filters it, plus each wayfinderLinkFields entry between the selected nodes (ADR-0012). Opens no index or model. Load findings refuse the graph, as okf graph does.
queryWayfinderBundles(List<ProjectBundle> bundles, WayfinderQuery query, {int offset = 0, int limit = 100, WayfinderCancellation? cancel}) → Future<WayfinderQueryResult>
Queries live files in bundles, refusing partial reads and observed edits. This is not a transactional filesystem snapshot. No index, model, Profile resolver, network service or computation executor is opened.
runGit(List<String> arguments, {String? workingDirectory, WayfinderCancellation? cancel, Map<String, String>? environment, Duration timeout = wayfinderGitTimeout, int maxOutputBytes = wayfinderGitMaxOutputBytes, GitProcessStarter start = startGitProcess}) → Future<GitResult>
The default GitRunner: runs Git with wayfinderGitOptions in wayfinderGitEnvironment of environment, by default the process's, with stdin closed. Before a command that may reach a remote, it reads core.sshCommand with one more hardened git config call (wayfinderConfiguredSshCommand), so the user's SSH command still runs in batch mode.
startGitProcess(String executable, List<String> arguments, {String? workingDirectory, required Map<String, String> environment}) → Future<GitProcess>
The default GitProcessStarter: Process.start without the parent's environment. Its GitProcess.kill stops the process and its children: taskkill /T /F on Windows, and pkill -KILL -P before the process itself on POSIX systems.
throwIfCancelled(WayfinderCancellation? cancel) → void
Throws WayfinderException.cancelled when cancel is cancelled, as an operation, or a host's GitRunner, does between steps.
validateWithProfileSources(String bundle, {String? configPath, String? projectRoot, required WayfinderProfileResolver resolver, bool fix = false}) → Future<ProfileValidationResult>
The validation the CLI and MCP server share: resolver's selection for bundle, then ProfileValidator.validate. When no Profile is selected, it first restores package files the cache lacks out of the existing Profile mirrors (WayfinderProfileResolver.restoreCachedPackages) and selects again, so a cache Wayfinder 0.2 wrote validates as it did. That runs git show through the resolver's runner and never fetches; with a complete cache, validation runs no Git. It writes nothing in the project beyond what fix writes in bundle. configPath and projectRoot bind bundle as WayfinderProfileResolver.select does.
wayfinderConfiguredSshCommand(List<String> arguments, {String? workingDirectory, required Map<String, String> environment, required Future<GitResult> run(List<String> arguments)}) → Future<String?>
core.sshCommand as the Git command arguments, run in workingDirectory, would see it, for wayfinderGitEnvironment's sshCommand; null when there is none to read.
wayfinderGitEnvironment(Map<String, String> environment, {String? sshCommand}) → Map<String, String>
environment without the GIT_* variables that would steer a command elsewhere, plus what keeps Git from waiting for a person: no terminal or credential-manager prompt, SSH in batch mode, and no Git LFS download.
wayfinderGraphResolutions() → List<String>
Stable OKF resolution wires accepted by --resolution and MCP.
wayfinderSshCommand(Map<String, String> environment, {String? configured}) → String?
The GIT_SSH_COMMAND under which Git runs the SSH command it would choose in environment: GIT_SSH_COMMAND, then configured, the core.sshCommand of Git's configuration as the command sees it, then GIT_SSH, then ssh. When that is OpenSSH, -o BatchMode=yes is added, so SSH never asks for a password or a host key; another SSH client, such as PuTTY's plink, runs unchanged. GIT_SSH_VARIANT decides whether a program is OpenSSH, and otherwise its name does.

Typedefs

GitProcessStarter = Future<GitProcess> Function(String executable, List<String> arguments, {required Map<String, String> environment, String? workingDirectory})
Starts executable with arguments for runGit, in workingDirectory, with exactly environment: runGit has already hardened it, so the starter adds nothing of the parent process's environment. A host's starter may add what its process layer adds to every process, such as a search path, and choose which git runs.
GitRunner = Future<GitResult> Function(List<String> arguments, {WayfinderCancellation? cancel, String? workingDirectory})
Runs git with arguments in workingDirectory. The resolver's only way to touch a repository, so a host can supply its own process layer and a test can prove which commands ran. A runner stops the command and throws WayfinderException.cancelled() when cancel fires.
ProfileFetchPolicy = bool Function(ProfileFetch fetch)
Whether a resolution may make fetch, asked just before it runs. A chain reaches each parent's source only once the child's package is read, so a plan asks about every source it reaches, including a parent in another repository that the configuration never names. Answer from what the person already approved: the source's mirror stays locked while the policy runs, so it must not wait for them. A refused fetch throws ProfileFetchRequiredException; ask then, and plan again.
ProfileSkillText = ({String text, bool truncated})
An installed SKILL.md, as ProfileSkills.read returns it. truncated is true when the file holds more than the read's maxBytes, so text is only its start, cut at a character boundary.
SkillFile = ({List<int> bytes, bool executable, String path})
One file of a Profile skill at its locked commit, by its POSIX path under the skill directory. executable is Git's 100755 mode, which a skill script needs to run directly.
SkillRevision = ({String commit, ProfileId id, String release})
The locked revision a Profile skill comes from, as its marker records it.

Exceptions / Errors

ProfileFetchRequiredException
fetch-required: resolving needs fetch, and the request is offline or its ProfileFetchPolicy refused it. Nothing was fetched for it; the fetches made before it stay in the Profile cache.
ProfileLockChangeRequiredException
lock-change-required: a locked-only plan (WayfinderProfileResolver.plan with lockedOnly) would change wayfinder.lock, so it was refused. change says what and why, as data; the message ends with its reason. Resolving the Profiles without lockedOnly writes the lock the project needs, which a person decides deliberately.
ProfileRelockFailedException
relock-failed: the file system refused to read or replace wayfinder.json or wayfinder.lock while WayfinderProfileResolver.relock ran. The message names the path and the operating system's reason.
ProfileResolutionBusyException
resolution-busy: another holder kept a lock that resolving needs. projectRoot names the project whose get lock another apply, resolve or adoption holds; source names the Profile source whose mirror another planner held for longer than the resolver waits (WayfinderProfileResolver.mirrorLockTimeout). Exactly one is set. Retrying once the holder finishes is the remedy.
ProfileSkillDirectoriesException
profile-unresolved: installing the locked Profile skills would replace what Wayfinder may not, so nothing was written. directories lists each refused directory: ProfileSkillDirectoryState.outside when its skill root resolves outside the project through a symbolic link, and ProfileSkillDirectoryState.unmarked when something is there without the Profile's marker. The message names the roots outside the project, or else the unmarked directories, and no remedy: moving them aside or pointing the roots inside the project is the host's to say. A plan with skills: false reports the same directories in ProfileResolutionPlan.skillDirectories instead.
WayfinderException
A failure a host can act on: code is a stable kebab-case identifier, and message a sentence that says what happened and names no command (ADR-0018). The command line prints it and adds what to run; a host words its own remedy from the code and, where one is typed, the exception's data.
WayfinderProfileResolutionException
A failure to resolve or select a Profile. diagnostic is how validation reports it when it finds no usable Profile; code is its value.
WayfinderQueryRefused
Source load findings refuse the entire result, rather than returning partial rows.