authoring library

Profile-aware writes to a knowledge bundle: prepare one change, judge the candidate with okf and the selected Profile in memory, then commit exactly what was judged.

KnowledgeWriter.prepare maps a KnowledgeChange onto okf's change set, regenerates only the indexes whose generated text the change alters, records the caller's log entry, and validates the candidate as wayfinder validate would after the commit. It writes nothing. KnowledgeWriter.commit writes the plan under okf's bundle lock, or refuses one that okf rejects, that adds a Profile error, or whose bundle, configuration or lock changed since. It needs dart:io; a host runs it on the isolate that does its other okf bundle I/O (ADR-0018), and may run the Profile assessment elsewhere through a KnowledgeAssessor. ADR-0019 records these decisions.

import 'package:okf/okf.dart';
import 'package:wayfinder/authoring.dart';
import 'package:wayfinder/project.dart';

Future<void> link(String bundle) async {
  final writer = KnowledgeWriter(
    resolver: WayfinderProfileResolver(
      dataDirectory: WayfinderDataDirectory.resolve(),
    ),
  );
  final plan = await writer.prepare(
    bundle,
    LinkConcepts(
      source: OkfConceptId('reporting/include-pdf-annotations'),
      relationship: KnowledgeRelationship.toConcept(
        relationship: 'related-to',
        target: OkfConceptId('ways-of-working/relationship-labels'),
      ),
    ),
    stamp: const KnowledgeStamp.generated(by: 'claude-code/opus-5'),
    logEntry: KnowledgeLog.none,
  );
  if (plan.committable) await writer.commit(plan);
}

Classes

CreateConcept
Creates the concept id from frontmatter and body.
DeprecateConcept
Sets the status of the concept id to deprecated and appends relationships to its relationships field, such as one that names its replacement. note goes into okf's lifecycle log entry.
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.
KnowledgeChange
One write to a knowledge bundle, which KnowledgeWriter.prepare maps onto okf's change set.
KnowledgeCommitResult
What a commit wrote, in path order.
KnowledgeContentLog
Records log only when the write creates a concept or changes its content, its body, title, description or type (changesConceptContent), exactly when the write records generated, and nothing otherwise: a link, a deprecation, an update of other fields such as status, a verification alone, and RegenerateIndexes record no entry.
KnowledgeFileDiff
One file a commit writes: its bundle-relative path, the text the bundle holds (before, null for a new file), and the text it writes.
KnowledgeLog
What a write records in the bundle's root log.md.
KnowledgeLogEntries
Several entries the caller authored for one write, such as Bitwild's Area created and Creation for a concept in a new directory. Each is written exactly as given, as a KnowledgeLogEntry is, under the writer's one date heading, in the order given.
KnowledgeLogEntry
An entry the caller authored, written exactly as given: the line * **<action>**: <description> under the writer's date heading, newest first. A Profile's skill names its lead words, such as Bitwild's Creation, Update and Deprecation.
KnowledgeProjectFiles
The project files a write's Profile selection came from, which KnowledgeWriter.commit checks under okf's exclusive bundle lock: each absolute path with the SHA-256 of the bytes it held, or null for a file that was absent.
KnowledgeRelationship
One entry of a concept's relationships field.
KnowledgeStamp
Who makes a write, and whether they also confirm the concept against its sources (OKF 0.2 §5.2).
KnowledgeWritePlan
A prepared write: the bundle as it stands, the candidate it would become, and the verdict that decides whether KnowledgeWriter.commit writes it.
KnowledgeWriter
The one write path for a knowledge bundle: prepare builds the candidate a change describes and judges it, commit writes exactly what was judged.
LinkConcepts
Appends relationship to the relationships field of source (guide §5.5), unless an entry with the same name and resource is there already.
RegenerateIndexes
The repair: writes each file the selected Profile's fixable rules generate whose text differs, exactly what wayfinder validate --fix writes, and changes no concept.
UpdateConcept
Changes the concept id. Each frontmatter entry replaces that key, and a null value removes it; keys it does not name stay as they are. body, when given, replaces the body.

Functions

changesConceptContent(OkfDocument? before, OkfDocument after) → bool
Whether after changes the content of the concept before: its body, title, description or type, the content a generated stamp dates (OKF 0.2 §5.2). before is null for a concept a write creates, whose content is always new.

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 for KnowledgeAdoption, 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

KnowledgeChangeException
A change that cannot be described against the bundle, so there is no candidate to judge. code is bundle-missing, concept-exists, concept-not-found, change-invalid, log-unwritable, or fix-not-applied for a RegenerateIndexes with no fixable rule to run.
KnowledgeStaleWriteException
write-stale: the bundle, or a project file its selection came from (KnowledgeWritePlan.projectFiles), changed after prepare. Prepare again.
KnowledgeWriteFailedException
write-failed: the file system refused the write, such as a bundle the process may not write, a .okf.lock that is not a regular file, or a file that cannot be read or replaced. The message names the path and the operating system's reason.
KnowledgeWriteRefusedException
write-refused: commit was given a plan that is not KnowledgeWritePlan.committable. Nothing was written.