@okfit/core 0.13.5 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,22 @@
1
+ import { GlobPattern } from "@effected/glob";
2
+ import { EditDistance } from "@effected/source";
3
+ import { DateTime, Option, Result, Schema } from "effect";
1
4
  import { Actor } from "../Actor.js";
5
+ import { Concept } from "../Concept.js";
2
6
  import { Derive } from "../Derive.js";
3
7
  import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
8
+ import { generatedAtIsFuture, verificationBlockingRestamp } from "../GeneratedAtFuture.js";
9
+ import { Graph as Graph$1 } from "../Graph.js";
10
+ import { INTEGRITY_KEY } from "../Integrity.js";
11
+ import { OkfVersion } from "../OkfVersion.js";
12
+ import { Timestamp } from "../Timestamp.js";
13
+ import { isAbsent } from "./conceptDecode.js";
4
14
  import { frontmatterPathRange } from "./frontmatter.js";
5
- import { DateTime } from "effect";
6
- import { EditDistance } from "@effected/source";
15
+ import { tierOf } from "./tier.js";
7
16
 
8
17
  // src/internal/lintRules.ts
9
- const present = (raw, key) => Object.hasOwn(raw, key) && raw[key] !== null;
18
+ /** OKF 0.3 §11.2 rule 1: a key holding null, the empty string or the empty list is absent. */
19
+ const present = (raw, key) => Object.hasOwn(raw, key) && !isAbsent(raw[key]);
10
20
  const diagnostic = (file, code, severity, message, range) => Diagnostic.make({
11
21
  file,
12
22
  code,
@@ -28,13 +38,50 @@ const perConcept = (code, body) => rule(code, (context, severity) => [...context
28
38
  return diagnostic(concept.path, code, severity, message, frontmatterPathRange(concept.document, path));
29
39
  })));
30
40
  const configUnknownKey = rule("config-unknown-key", (context, severity) => Object.keys(context.config.extensions).map((key) => diagnostic("", "config-unknown-key", severity, `Unknown config key "${key}"`, void 0)));
41
+ /**
42
+ * The config's `okf_version` only fills a root index that declares none; once the index declares a different
43
+ * version the config value is stale. Both sides compare through `OkfVersion` when they parse, as raw strings otherwise.
44
+ */
45
+ const configOkfVersionStale = rule("config-okf-version-stale", (context, severity) => {
46
+ const configured = context.config.okf_version;
47
+ const declared = OkfVersion.declared(context.bundle);
48
+ if (configured === void 0 || Option.isNone(declared)) return [];
49
+ if (Option.match(Option.all([OkfVersion.parse(configured), OkfVersion.parse(declared.value)]), {
50
+ onNone: () => configured === declared.value,
51
+ onSome: ([a, b]) => OkfVersion.compare(a, b) === 0
52
+ })) return [];
53
+ const where = context.configPath === void 0 ? "in the config" : `in ${context.configPath}`;
54
+ const head = `okf_version ${where} is "${configured}", but the bundle-root index.md declares "${declared.value}"`;
55
+ const message = Option.isSome(OkfVersion.parse(declared.value)) ? `${head}; okfit reads the bundle as "${declared.value}" and uses the config value only for a root index that declares none. Set okf_version = "${declared.value}" ${where}, or remove it` : `${head}, which is not a <major>.<minor> version; correct the declaration in index.md, then set okf_version ${where} to the same value, or remove it`;
56
+ return [diagnostic("", "config-okf-version-stale", severity, message, void 0)];
57
+ });
58
+ /**
59
+ * #471: a `generated.at` later than now counts for no verification (OKF 0.3 §5.3) and `okfit verify` refuses it;
60
+ * `okfit sync` re-stamps it, except when a verification would then count (`verificationBlockingRestamp`).
61
+ */
62
+ const generatedAtFuture = perConcept("generated-at-future", (concept, context) => {
63
+ const at = concept.frontmatter.generated?.at;
64
+ const { now } = context;
65
+ if (at === void 0 || now === void 0 || !generatedAtIsFuture(at, now)) return [];
66
+ const head = `generated.at ${instant(at)} is more than 5 minutes later than now (${instant(now)}), so no verification can count yet (OKF 0.3 §5.3) and okfit verify refuses this concept`;
67
+ const blocking = verificationBlockingRestamp((concept.frontmatter.verified ?? []).map((entry) => entry.at), at, now);
68
+ return [{
69
+ message: Option.isSome(blocking) ? `${head}; okfit sync will not re-stamp it, because the verification dated ${instant(blocking.value)} would then count without a re-verification; a human must correct generated.at or that verification` : `${head}; run okfit sync, which re-stamps it`,
70
+ path: ["generated", "at"]
71
+ }];
72
+ });
31
73
  const unknownType = perConcept("unknown-type", (concept, context) => Object.hasOwn(context.config.types ?? {}, concept.frontmatter.type) ? [] : [{
32
74
  message: `Type "${concept.frontmatter.type}" is not declared in [types]`,
33
75
  path: ["type"]
34
76
  }]);
35
77
  const requiredKeyMissing = perConcept("required-key-missing", (concept, context) => {
36
78
  const declared = context.config.types?.[concept.frontmatter.type]?.required ?? [];
37
- return [.../* @__PURE__ */ new Set([...context.config.concepts?.required ?? [], ...declared])].filter((key) => !present(concept.frontmatter.raw, key)).map((key) => `Required key "${key}" is missing`);
79
+ const keys = [.../* @__PURE__ */ new Set([...context.config.concepts?.required ?? [], ...declared])];
80
+ const raw = concept.frontmatter.raw;
81
+ return keys.filter((key) => !present(raw, key)).map((key) => ({
82
+ message: `Required key "${key}" is ${Object.hasOwn(raw, key) ? "empty" : "missing"}`,
83
+ path: [key]
84
+ }));
38
85
  });
39
86
  const fieldValueUnknown = perConcept("field-value-unknown", (concept, context) => {
40
87
  const fields = context.config.types?.[concept.frontmatter.type]?.fields ?? {};
@@ -50,28 +97,93 @@ const fieldValueUnknown = perConcept("field-value-unknown", (concept, context) =
50
97
  return out;
51
98
  });
52
99
  const requireVerifiedUnmet = perConcept("require-verified-unmet", (concept, context) => context.config.types?.[concept.frontmatter.type]?.require_verified === true && concept.frontmatter.status !== "draft" && (concept.frontmatter.verified ?? []).length === 0 ? [{
53
- message: `Type "${concept.frontmatter.type}" requires a verified entry`,
100
+ message: Derive.status(concept.frontmatter) === "unknown" ? `Type "${concept.frontmatter.type}" requires a verified entry; status "${Derive.rawStatus(concept.frontmatter)}" is not draft, stable or deprecated, so set it first or verify with okfit verify --stable or --draft` : `Type "${concept.frontmatter.type}" requires a verified entry`,
54
101
  path: ["status"]
55
102
  }] : []);
56
- const statusMissing = perConcept("status-missing", (concept) => concept.frontmatter.status === void 0 && (concept.frontmatter.verified ?? []).length === 0 ? ["Concept has no status and no verified entry, so it reads as stable; set status: draft or stable explicitly"] : []);
103
+ const TIER_RANK = {
104
+ unverified: 0,
105
+ "machine-confirmed": 1,
106
+ "human-reviewed": 2
107
+ };
108
+ const instant = Schema.encodeSync(Timestamp);
109
+ const verifiedBeforeChange = perConcept("verified-before-change", (concept) => {
110
+ const frontmatter = concept.frontmatter;
111
+ const generatedAt = frontmatter.generated?.at;
112
+ const status = Derive.status(frontmatter);
113
+ if (generatedAt === void 0 || status === "draft" || status === "deprecated" || status === "unknown") return [];
114
+ const events = frontmatter.verified ?? [];
115
+ const all = tierOf(events);
116
+ const current = Derive.trustTier(frontmatter);
117
+ if (TIER_RANK[all] <= TIER_RANK[current]) return [];
118
+ const lost = events.map((entry, index) => ({
119
+ entry,
120
+ index
121
+ })).filter(({ entry }) => !Derive.isCurrent(frontmatter, entry.at));
122
+ const newest = (items) => items.reduce((best, item) => best === void 0 || DateTime.toEpochMillis(item.entry.at) > DateTime.toEpochMillis(best.entry.at) ? item : best, void 0);
123
+ const target = (all === "human-reviewed" ? newest(lost.filter(({ entry }) => Actor.isHuman(entry.by))) : void 0) ?? newest(lost);
124
+ if (target === void 0) return [];
125
+ return [{
126
+ message: `Verified by ${target.entry.by} at ${instant(target.entry.at)}, before the last change at ${instant(generatedAt)}; the trust tier is now ${current} (OKF 0.3 §5.3); re-run okfit verify`,
127
+ path: Concept.entryPath(frontmatter, "verified", target.index)
128
+ }];
129
+ });
130
+ const statusMissing = perConcept("status-missing", (concept) => concept.frontmatter.status === void 0 && Derive.rawStatus(concept.frontmatter) === void 0 && (concept.frontmatter.verified ?? []).length === 0 ? ["Concept has no status and no verified entry, so it reads as stable; set status: draft or stable explicitly"] : []);
131
+ /**
132
+ * R45/R46: an okfit opinion layered on the load diagnostics `frontmatter-missing` and `type-missing`
133
+ * (OKF 0.3 §3.2 allows such files). Silent when `[bundle] non_concepts` is absent; otherwise a typeless
134
+ * file no glob matches is reported, ranged like its load diagnostic. The load diagnostics are unchanged.
135
+ */
136
+ const nonConceptUnlisted = rule("non-concept-unlisted", (context, severity) => {
137
+ const globs = context.config.bundle?.non_concepts;
138
+ if (globs === void 0) return [];
139
+ const why = (code) => code === "frontmatter-missing" ? "no frontmatter" : "no type";
140
+ const patterns = globs.flatMap((glob) => {
141
+ const compiled = GlobPattern.compileResult(glob);
142
+ return Result.isSuccess(compiled) ? [compiled.success] : [];
143
+ });
144
+ return context.bundle.diagnostics.filter((d) => (d.code === "frontmatter-missing" || d.code === "type-missing") && !patterns.some((pattern) => pattern.matches(d.file))).map((d) => diagnostic(d.file, "non-concept-unlisted", severity, globs.length === 0 ? `${d.file} is not a concept (${why(d.code)}) and [bundle] non_concepts is empty, so it allows no non-concept file; add frontmatter with a type, move it out of the bundle, or add a glob that matches it to non_concepts` : `${d.file} is not a concept (${why(d.code)}) and matches no [bundle] non_concepts glob (${globs.join(", ")}); add frontmatter with a type, move it out of the bundle, or list it in non_concepts`, d.range));
145
+ });
57
146
  const generatedMissing = perConcept("generated-missing", (concept, context) => context.config.actors?.agent !== void 0 && !present(concept.frontmatter.raw, "generated") ? [`Concept has no generated block; okfit sync will create it from actors.agent (${context.config.actors.agent}) once the body is committed, or set generated.by by hand`] : []);
147
+ /**
148
+ * OKF 0.3 §10.3: an Attested Computation with neither a `computation` key nor an inline computation is not
149
+ * attestable. `computationBody` is already the bundle's declared reading (fenced block under 0.3, the depth-1
150
+ * section under 0.2), so a missing or blank body is the one condition. `runtime` is not required here:
151
+ * `computation-runtime-missing` reports that separately.
152
+ */
153
+ const computationMissing = rule("computation-missing", (context, severity) => [...context.bundle.concepts.values()].flatMap((concept) => {
154
+ const attested = concept.frontmatter.attested;
155
+ if (attested === void 0 || attested.computation !== void 0) return [];
156
+ const body = concept.computationBody;
157
+ if (Option.isSome(body) && body.value.trim() !== "") return [];
158
+ const heading = Option.orElse(concept.document.sectionByHeading("Computation", { depth: 1 }), () => concept.document.sectionByHeading("Computation"));
159
+ const range = Option.match(heading, {
160
+ onNone: () => frontmatterPathRange(concept.document, []),
161
+ onSome: ({ heading: node }) => DiagnosticRange.fromOffset(concept.document.source, node.position.start.offset, node.position.end.offset - node.position.start.offset)
162
+ });
163
+ const legacy = OkfVersion.legacyFallbacks(context.bundle);
164
+ const message = legacy && Option.isSome(heading) && Option.isNone(concept.document.sectionByHeading("Computation", { depth: 1 })) ? "This Attested Computation has no computation: under OKF 0.2 the Computation section must be a top-level heading, and this one is not, so it is not attestable; make it a top-level heading, or declare okf_version 0.3 and put the computation in one fenced block" : Option.isSome(heading) ? legacy ? "This Attested Computation has no computation: its top-level Computation section is empty, so it is not attestable; write the computation under it, or set computation to a file" : Option.isSome(body) ? "This Attested Computation has no computation: the first fenced code block in its Computation section is empty (OKF 0.3 §10.3), so it is not attestable; put the computation in that block, or set computation to a file" : "This Attested Computation has no computation: its Computation section holds no fenced code block (OKF 0.3 §10.3), so it is not attestable; put the computation in one fenced block, or set computation to a file" : legacy ? "This Attested Computation has no computation: it has no Computation section and no computation key, so it is not attestable; add a top-level Computation section that holds the computation, or set computation to a file" : "This Attested Computation has no computation: it has no Computation section and no computation key, so it is not attestable; add a Computation section with the computation in one fenced block, or set computation to a file";
165
+ return [diagnostic(concept.path, "computation-missing", severity, message, range)];
166
+ }));
58
167
  const actorPrefixUnknown = perConcept("actor-prefix-unknown", (concept) => {
59
- const candidates = [{
60
- by: concept.frontmatter.generated?.by,
61
- path: ["generated", "by"]
62
- }, ...(concept.frontmatter.verified ?? []).map((entry, index) => ({
63
- by: entry.by,
64
- path: [
65
- "verified",
66
- index,
67
- "by"
68
- ]
69
- }))];
168
+ const candidates = [
169
+ {
170
+ by: concept.frontmatter.generated?.by,
171
+ path: ["generated", "by"]
172
+ },
173
+ ...(concept.frontmatter.verified ?? []).map((entry, index) => ({
174
+ by: entry.by,
175
+ path: [...Concept.entryPath(concept.frontmatter, "verified", index), "by"]
176
+ })),
177
+ ...(concept.frontmatter.sources ?? []).map((entry, index) => ({
178
+ by: entry.author,
179
+ path: [...Concept.entryPath(concept.frontmatter, "sources", index), "author"]
180
+ }))
181
+ ];
70
182
  const out = [];
71
183
  for (const candidate of candidates) {
72
184
  if (candidate.by === void 0 || Actor.form(candidate.by) !== "other") continue;
73
185
  out.push({
74
- message: `Actor "${candidate.by}" uses an unknown prefix; expected human:<id>, process:<id>, or <producer>/<version>`,
186
+ message: `Actor "${candidate.by}" uses an unknown prefix; expected human:<id>, team:<id>, process:<id>, or <producer>/<version>`,
75
187
  path: candidate.path
76
188
  });
77
189
  }
@@ -79,11 +191,7 @@ const actorPrefixUnknown = perConcept("actor-prefix-unknown", (concept) => {
79
191
  });
80
192
  /** Every actor-valued frontmatter field of a concept, with the path that names it. */
81
193
  const actorsOf = (concept) => {
82
- const verifiedPath = (index) => Array.isArray(concept.frontmatter.raw.verified) ? [
83
- "verified",
84
- index,
85
- "by"
86
- ] : ["verified", "by"];
194
+ const verifiedPath = (index) => [...Concept.entryPath(concept.frontmatter, "verified", index), "by"];
87
195
  const binding = concept.frontmatter.integrity?.verified;
88
196
  return [
89
197
  ...concept.frontmatter.generated === void 0 ? [] : [{
@@ -97,7 +205,7 @@ const actorsOf = (concept) => {
97
205
  ...binding === void 0 ? [] : [{
98
206
  by: binding.by,
99
207
  path: [
100
- "integrity",
208
+ INTEGRITY_KEY,
101
209
  "verified",
102
210
  "by"
103
211
  ]
@@ -224,6 +332,20 @@ const brokenLinks = rule("broken-links", (context, severity) => {
224
332
  }
225
333
  return [...dangling, ...anchors];
226
334
  });
335
+ const supersededByOrphan = perConcept("superseded-by-orphan", (concept) => concept.frontmatter.superseded_by !== void 0 && Derive.status(concept.frontmatter) !== "deprecated" ? [{
336
+ message: `superseded_by is set but status is not deprecated; it has a meaning only with status: deprecated`,
337
+ path: ["superseded_by"]
338
+ }] : []);
339
+ const supersededByUnresolved = perConcept("superseded-by-unresolved", (concept, context) => {
340
+ const raw = concept.frontmatter.superseded_by;
341
+ if (raw === void 0 || Derive.status(concept.frontmatter) !== "deprecated") return [];
342
+ const resolved = Graph$1.resolve(context.bundle, concept.path, raw, "superseded_by");
343
+ const reason = resolved._tag === "node" ? resolved.kind === "missing" ? void 0 : resolved.kind === "file" ? "a file that is not a concept" : resolved.id === concept.id ? "the concept itself" : void 0 : resolved._tag === "self" ? "the concept itself" : "an external value";
344
+ return reason === void 0 ? [] : [{
345
+ message: `superseded_by "${raw}" resolves to ${reason}, not a replacement concept`,
346
+ path: ["superseded_by"]
347
+ }];
348
+ });
227
349
  const missingIndex = rule("missing-index", (context, severity) => Derive.indexDirectories(context.bundle).filter((dir) => !context.bundle.indexes.has(dir)).map((dir) => {
228
350
  const message = `Directory "${dir === "" ? "." : dir}" has no index.md`;
229
351
  return diagnostic(dir === "" ? "index.md" : `${dir}/index.md`, "missing-index", severity, message, void 0);
@@ -231,20 +353,27 @@ const missingIndex = rule("missing-index", (context, severity) => Derive.indexDi
231
353
  /** Fixed rule order (task-group decision 9). */
232
354
  const LINT_RULES = [
233
355
  configUnknownKey,
356
+ configOkfVersionStale,
234
357
  unknownType,
235
358
  requiredKeyMissing,
236
359
  fieldValueUnknown,
237
360
  requireVerifiedUnmet,
361
+ verifiedBeforeChange,
238
362
  statusMissing,
363
+ nonConceptUnlisted,
239
364
  generatedMissing,
365
+ computationMissing,
366
+ generatedAtFuture,
240
367
  actorPrefixUnknown,
241
368
  actorEmail,
242
369
  verifiedActorUnknown,
243
370
  footnoteSourceUnknown,
244
371
  footnoteUndefined,
245
372
  brokenLinks,
373
+ supersededByOrphan,
374
+ supersededByUnresolved,
246
375
  missingIndex,
247
376
  stale
248
377
  ];
249
378
 
250
- export { LINT_RULES, actorEmail, actorPrefixUnknown, brokenLinks, configUnknownKey, fieldValueUnknown, footnoteSourceUnknown, footnoteUndefined, generatedMissing, missingIndex, requireVerifiedUnmet, requiredKeyMissing, stale, statusMissing, unknownType, verifiedActorUnknown };
379
+ export { LINT_RULES, actorEmail, actorPrefixUnknown, brokenLinks, computationMissing, configOkfVersionStale, configUnknownKey, fieldValueUnknown, footnoteSourceUnknown, footnoteUndefined, generatedAtFuture, generatedMissing, missingIndex, nonConceptUnlisted, requireVerifiedUnmet, requiredKeyMissing, stale, statusMissing, supersededByOrphan, supersededByUnresolved, unknownType, verifiedActorUnknown, verifiedBeforeChange };
@@ -1,8 +1,9 @@
1
+ import { MarkdownParseOptions } from "@effected/markdown";
2
+ import { Option } from "effect";
1
3
  import { Diagnostic, DiagnosticRange } from "../Diagnostic.js";
2
4
  import { IndexDocument, IndexEntry, IndexSection } from "../IndexDocument.js";
3
5
  import { LogDocument, LogGroup, LogItem } from "../LogDocument.js";
4
- import { Option } from "effect";
5
- import { MarkdownParseOptions } from "@effected/markdown";
6
+ import { OkfVersion } from "../OkfVersion.js";
6
7
 
7
8
  // src/internal/reserved.ts
8
9
  /**
@@ -61,16 +62,39 @@ const parseIndex = (input) => {
61
62
  const { file, dir, document } = input;
62
63
  const text = document.source;
63
64
  const diagnostics = [];
64
- let okfVersion;
65
+ const metadata = {};
65
66
  const node = Option.getOrUndefined(document.frontmatter);
66
67
  if (node !== void 0 && Option.isSome(input.frontmatter)) {
67
68
  const raw = input.frontmatter.value;
68
69
  const record = raw !== null && typeof raw === "object" && !Array.isArray(raw) ? raw : void 0;
69
- const keys = record === void 0 ? [] : Object.keys(record);
70
- if (dir === "" && record !== void 0 && keys.length === 1 && typeof record.okf_version === "string") okfVersion = record.okf_version;
70
+ if (dir !== "") diagnostics.push(diagnostic(file, "index-frontmatter", "error", "index.md below the bundle root must not carry frontmatter", rangeOf(text, node.position)));
71
+ else if (raw === null) {} else if (record === void 0) diagnostics.push(diagnostic(file, "index-frontmatter", "error", "root index.md frontmatter must be a mapping", rangeOf(text, node.position)));
71
72
  else {
72
- const message = dir === "" ? "root index.md frontmatter may only carry a string \"okf_version\"" : "index.md below the bundle root must not carry frontmatter";
73
- diagnostics.push(diagnostic(file, "index-frontmatter", "error", message, rangeOf(text, node.position)));
73
+ metadata.metadata = record;
74
+ metadata.frontmatter = node.value;
75
+ const warn = (key, message) => {
76
+ diagnostics.push(diagnostic(file, "index-metadata-invalid", "warning", message, DiagnosticRange.forFrontmatterPath(document, [key]) ?? rangeOf(text, node.position)));
77
+ };
78
+ const version = record.okf_version;
79
+ if (typeof version === "string") {
80
+ if (version !== "") {
81
+ metadata.okfVersion = version;
82
+ if (Option.isNone(OkfVersion.parse(version))) warn("okf_version", `okf_version "${version}" is not a <major>.<minor> version`);
83
+ }
84
+ } else if (version !== null && version !== void 0) {
85
+ metadata.okfVersion = typeof version === "number" ? String(version) : JSON.stringify(version);
86
+ warn("okf_version", typeof version === "number" ? `okf_version ${String(version)} is an unquoted number; quote it as "<major>.<minor>"` : "okf_version must be a quoted <major>.<minor> string");
87
+ }
88
+ for (const key of [
89
+ "title",
90
+ "description",
91
+ "license"
92
+ ]) {
93
+ const value = record[key];
94
+ if (typeof value === "string") {
95
+ if (value !== "") metadata[key] = value;
96
+ } else if (value !== null && value !== void 0) warn(key, `${key} must be a string`);
97
+ }
74
98
  }
75
99
  }
76
100
  const sections = [];
@@ -115,9 +139,9 @@ const parseIndex = (input) => {
115
139
  sections
116
140
  };
117
141
  return {
118
- document: IndexDocument.make(okfVersion === void 0 ? fields : {
142
+ document: IndexDocument.make({
119
143
  ...fields,
120
- okfVersion
144
+ ...metadata
121
145
  }),
122
146
  diagnostics
123
147
  };
@@ -1,6 +1,6 @@
1
- import { Result } from "effect";
2
1
  import { Frontmatter, Heading, Link, List, ListItem, Markdown, Paragraph, Root, Text } from "@effected/markdown";
3
2
  import { Yaml } from "@effected/yaml";
3
+ import { Result } from "effect";
4
4
 
5
5
  // src/internal/templates.ts
6
6
  /** `* [Title](target) - description`, or without the tail when there is no description (D-36; spec §8). */
@@ -21,19 +21,41 @@ const sectionNodes = (section) => [Heading.make({
21
21
  bulletChar: "*",
22
22
  children: section.entries.map(entryNode)
23
23
  })];
24
+ /** True when `text` parses to a mapping with no own `okf_version` key; a parse failure or non-mapping counts as declaring one. */
25
+ const lacksOkfVersion = (text) => {
26
+ const parsed = Yaml.parseResult(text);
27
+ if (Result.isFailure(parsed)) return false;
28
+ const value = parsed.success;
29
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return false;
30
+ return !Object.hasOwn(value, "okf_version");
31
+ };
24
32
  /**
25
- * A whole `index.md`: root frontmatter carrying only `okf_version` when given (D-21), then each section.
33
+ * A whole `index.md`: root frontmatter, then each section.
34
+ *
35
+ * With `frontmatter` the existing block is emitted verbatim, and `okf_version` is prepended only when
36
+ * `okfVersion` is given and the block declares none (a declared version is never rewritten, D6). Without
37
+ * it the block carries only `okf_version` when given (D-21).
26
38
  *
27
39
  * Rendered by `@effected/markdown`'s emitter, so titles and descriptions are escaped only where markdown
28
40
  * would otherwise read them as syntax and round-trip to the original text (issue #72), and a target the
29
41
  * emitter cannot write bare (a space, for one) is written in angle brackets.
30
42
  */
31
- const indexDocument = (sections, okfVersion) => {
32
- const frontmatter = okfVersion === void 0 ? [] : [Frontmatter.make({
43
+ const indexDocument = (sections, options = {}) => {
44
+ const { okfVersion } = options;
45
+ const frontmatter = options.frontmatter?.replace(/\r\n?/g, "\n");
46
+ const metadata = frontmatter !== void 0 && frontmatter !== "" ? void 0 : options.metadata;
47
+ const fields = {
48
+ ...okfVersion === void 0 ? {} : { okf_version: okfVersion },
49
+ ...metadata?.title === void 0 ? {} : { title: metadata.title },
50
+ ...metadata?.description === void 0 ? {} : { description: metadata.description }
51
+ };
52
+ const versionLine = Object.keys(fields).length === 0 ? void 0 : Result.getOrThrow(Yaml.stringifyResult(fields)).replace(/\n$/, "");
53
+ const value = frontmatter === void 0 || frontmatter === "" ? versionLine : versionLine !== void 0 && lacksOkfVersion(frontmatter) ? `${versionLine}\n${frontmatter}` : frontmatter;
54
+ const block = value === void 0 ? [] : [Frontmatter.make({
33
55
  format: "yaml",
34
- value: Result.getOrThrow(Yaml.stringifyResult({ okf_version: okfVersion })).replace(/\n$/, "")
56
+ value
35
57
  })];
36
- const root = Root.make({ children: [...frontmatter, ...sections.flatMap(sectionNodes)] });
58
+ const root = Root.make({ children: [...block, ...sections.flatMap(sectionNodes)] });
37
59
  return Result.getOrThrow(Markdown.stringifyResult(root));
38
60
  };
39
61
  /** `## <date>`, a blank line, then one `* item` line per item (spec §9; S-32, MD022/MD032). */
@@ -0,0 +1,7 @@
1
+ import { Actor } from "../Actor.js";
2
+
3
+ // src/internal/tier.ts
4
+ /** The trust tier of a list of verification events (OKF 0.3 §5.3, §7): none is unverified, any `human:` is human-reviewed, else machine-confirmed. */
5
+ const tierOf = (events) => events.length === 0 ? "unverified" : events.some((entry) => Actor.isHuman(entry.by)) ? "human-reviewed" : "machine-confirmed";
6
+
7
+ export { tierOf };
package/internal/walk.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { GlobPattern, GlobPatternOptions } from "@effected/glob";
2
- import { Effect } from "effect";
3
2
  import { descend } from "@effected/walker";
3
+ import { Effect } from "effect";
4
4
 
5
5
  // src/internal/walk.ts
6
6
  /**
@@ -1,6 +1,6 @@
1
- import { toFileOffset } from "./position.js";
2
- import { Option, Result } from "effect";
3
1
  import { YamlDocument } from "@effected/yaml";
2
+ import { Option, Result } from "effect";
3
+ import { toFileOffset } from "./position.js";
4
4
 
5
5
  // src/internal/yamlPathSpan.ts
6
6
  const blockSpan = (node) => ({
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@okfit/core",
3
- "version": "0.13.5",
3
+ "version": "0.15.0",
4
4
  "private": false,
5
- "description": "Spec-level Open Knowledge Format (OKF) v0.2 schemas, bundle loading, graph, derivation, and validation for Effect.",
5
+ "description": "Spec-level Open Knowledge Format (OKF) v0.3 schemas, bundle loading, graph, derivation, and validation for Effect.",
6
6
  "keywords": [
7
7
  "okf",
8
8
  "open-knowledge-format",
@@ -40,7 +40,7 @@
40
40
  "@effected/config-file": "^0.29.0",
41
41
  "@effected/glob": "^0.23.0",
42
42
  "@effected/jsonc": "^0.25.0",
43
- "@effected/markdown": "^0.29.0",
43
+ "@effected/markdown": "^0.30.0",
44
44
  "@effected/schemastore": "^0.33.0",
45
45
  "@effected/source": "^0.5.0",
46
46
  "@effected/toml": "^0.20.0",