adoption library
Programmatic adoption: bind a project to a Profile, lock and install it, and seed its knowledge bundle, as the adopt-knowledge-bundle skill describes (ADR-0020).
KnowledgeAdoption.plan reads the project and resolves the Profile the
package at the request's source declares, and writes nothing in the
project; the plan lists every file, Git fetch and conflict, and fetches
only what AdoptionRequest.allowFetch allows.
KnowledgeAdoption.apply writes wayfinder.json, wayfinder.lock, the
seeded bundle, the Profile skills and a .gitignore line, then the
host's own step, or nothing, while it holds the project's get lock,
then validates, reporting each step as it starts and ends. It never
writes AGENTS.md, CLAUDE.md, .mcp.json or hooks: the plan returns
the agent-instruction block as text. Like the rest of
package:wayfinder/project.dart, run it on the isolate that does the
process's okf bundle I/O (ADR-0018); only the Profile assessment may run
elsewhere, through a KnowledgeAssessor such as one that calls
KnowledgeAssessmentInput.assessWithin.
import 'dart:io';
import 'package:wayfinder/adoption.dart';
import 'package:wayfinder/project.dart';
Future<void> main() async {
final adoption = KnowledgeAdoption(
resolver: WayfinderProfileResolver(
dataDirectory: WayfinderDataDirectory.resolve(),
),
);
final plan = await adoption.plan(
AdoptionRequest(
projectRoot: Directory.current.path,
source: const AdoptionSource(
git: 'https://github.com/btwld/wayfinder',
path: 'profiles/bitwild',
),
),
);
for (final conflict in plan.conflicts) print(conflict);
if (!plan.applicable) return;
final result = await adoption.apply(plan);
print(result.validation?.gate.wireValue);
print(plan.agentInstructions);
}
Classes
- AdoptionConflict
- Something in the project that stops applying. Nothing is written while a plan has one; resolve it and plan again.
- AdoptionFile
- One file applying writes, by its project-relative POSIX path. sha256 and size describe the bytes the file holds once applied. content is the text adoption composes: the whole file, or for AdoptionFileAction.append the text appended. A skill file, copied from the Profile's locked commit, carries only its digest.
- AdoptionProfile
-
The Profile a plan binds: the source as
wayfinder.jsonwill name it, and the release and commit resolution locked. - AdoptionRequest
- What to adopt: the Profile package at source, applied to the bundle directory bundle of the project at projectRoot.
- AdoptionSeedConcept
- A concept to seed, as the whole Markdown document text at the bundle-relative path. Adoption writes it as given and never invents one: the host derives seed concepts from the repository's own code and documentation, as the Profile's adoption guidance names them, and confirms them with the person adopting.
- AdoptionSource
-
Where the Profile package comes from: path inside the Git repository
git, at ref. A null ref means the source's default branch, which
adoption pins in
wayfinder.jsonas the commit it resolves to, so the binding never moves until someone changes it. - AdoptionStepReport
- One step's report: the project-relative paths it wrote or removed.
- KnowledgeAdoption
-
Adopts a Profile in a project: binds it in
wayfinder.json, locks and installs it through resolver, seeds the bundle, and adds the.okf.lockline to.gitignore. plan writes nothing in the project; apply writes exactly what the plan lists, or nothing. - KnowledgeAdoptionPlan
- What KnowledgeAdoption.apply would write, from KnowledgeAdoption.plan. Planning wrote nothing in the project; it may have fetched the Profile source into the Profile cache, as fetches lists.
- KnowledgeAdoptionResult
- What KnowledgeAdoption.apply did.
- KnowledgeAssessment
- The verdicts KnowledgeAssessmentInput.assess reaches.
- KnowledgeAssessmentInput
- What a Profile assessment judges, all in memory: okf's load results and the selection they are judged with.
- KnowledgeSeeds
-
The generic adoption seed: the project binding, OKF's two root files, and
the agent-instruction blocks (guide ยง2.1). A Profile's adoption guidance
may word the first log entry and add instruction lines, and a host
passes any concept it names as a seed concept.
KnowledgeAdoptionwrites the files and returns the blocks. The adopt-knowledge-bundle skill'sSEEDING.mdshows the same text, and a test keeps the two equal.
Enums
- AdoptionBundleMode
- Whether adoption seeds the bundle or binds one that is already there.
- AdoptionFileAction
- What applying does to a planned file.
- AdoptionFileKind
- What a planned file is for.
- AdoptionStep
-
A step of
KnowledgeAdoption.apply, in the order it runs. - AdoptionStepOutcome
- Where a step stands: started while it runs, then how it ended.
Typedefs
-
KnowledgeAssessor
= Future<
KnowledgeAssessment> Function(KnowledgeAssessmentInput input, WayfinderCancellation? cancel) -
Runs a Profile assessment for
KnowledgeWriter.prepare, which calls it once per plan after okf's shared claim on the bundle is released, and forKnowledgeAdoption, which calls it once when planning and once for the bundle it adopted. Either gives it only what okf loaded or prepared in memory.
Exceptions / Errors
- AdoptionProfileConflictException
-
adoption-profile-conflict: the request named the Profile requested, and the package at its source declares declared. Planning stops before it resolves the Profile's chain, and nothing is written in the project. Plan again naming declared, or naming no Profile to take the one the package declares. - KnowledgeAdoptionException
-
Applying failed at a step and undid the steps before it, so the project
holds no partial bundle unless steps reports one
undo-failed. code is the cause's when it was a WayfinderException:adoption-conflictfor a plan with conflicts,adoption-invalidfor one another adoption's Profile cache planned,adoption-staleorresolution-stalefor one whose inputs changed,resolution-busywhile agetor another adoption holds the project,cancelled, andadoption-failedfor any other error.